255 Commits

Author SHA1 Message Date
8f1ff5c374 Update cmd/mkinitfs/main.go 2025-10-04 20:50:34 +00:00
Clayton Craft
15c95f6b13 Add support for hooks-cleanup
The pmOS initramfs will execute scripts in this dir, so let's add a way
to install them in the archive!
2.7.0
2025-09-12 15:40:01 -07:00
Clayton Craft
bab4be1a89 misc/getfiles: fix zst fallback
The previous symlink recursion fix broke the fallback for zst by
returning early.

Fixes 7a07a16ecb

Part-of: https://gitlab.postmarketos.org/postmarketOS/postmarketos-mkinitfs/-/merge_requests/67
[ci:skip-build]: already built successfully in CI
2.6.4
2025-08-04 17:37:25 -07:00
Pablo Correa Gómez
1428f27b4a gitlab-ci: don't run CI-tron on tags
Fixes #49

Part-of: https://gitlab.postmarketos.org/postmarketOS/postmarketos-mkinitfs/-/merge_requests/66
[ci:skip-build]: already built successfully in CI
2025-08-04 17:36:01 -07:00
Clayton Craft
f6e4773507 misc/getfiles: add tests for getFile
This adds some tests for getFile, one of which would have caught
the recent recursion issue and other will hopefully catch future
regressions.

Part-of: https://gitlab.postmarketos.org/postmarketOS/postmarketos-mkinitfs/-/merge_requests/65

[ci:skip-build]: already built successfully in CI
2.6.3
2025-08-04 09:23:05 -07:00
Clayton Craft
7a07a16ecb misc/getfiles: fix infinite recursion loop when given a symlink
This fixes an infinite recursion loop in getFile caused by:

1) `os.Stat(file)` resolves a symlink so that `fileInfo.isDir()` returns True
2) `filepath.Walk()` starts iterating on the root directory (in this case the symlink)
3) `filepath.Walk()` uses `os.Lstat` internally, which does NOT dereference the symlink
4) in the walk func, `f.isDir()` returns False, and the walk func calls `getFile()` on it
5) goto 1

fixes #47

Part-of: https://gitlab.postmarketos.org/postmarketOS/postmarketos-mkinitfs/-/merge_requests/65
2025-08-04 09:23:00 -07:00
Clayton Craft
4f6af31a7a archive: don't create a symlink for /usr/sbin
Fixes this warning when running on a merged /usr system:

   addSymlink: failed to get symlink target for: /usr/sbin

Part-of: https://gitlab.postmarketos.org/postmarketOS/postmarketos-mkinitfs/-/merge_requests/64
[ci:skip-build]: already built successfully in CI
2025-08-03 22:44:35 -07:00
Pablo Correa Gómez
39ee6752fd ci: build aarch64 mkinitfs to use in ci-tron testing
Else mkinitfs fails:
https://gitlab.postmarketos.org/postmarketOS/postmarketos-mkinitfs/-/jobs/1395713
to run x86_64 binary on aarch64

Part-of: https://gitlab.postmarketos.org/postmarketOS/postmarketos-mkinitfs/-/merge_requests/63
[ci:skip-build]: already built successfully in CI
2025-07-25 12:40:23 +02:00
Martin Roukala (né Peres)
0edee0afbd ci: test the generated artifacts in qemu runners
Part-of: https://gitlab.postmarketos.org/postmarketOS/postmarketos-mkinitfs/-/merge_requests/63
2025-07-25 12:09:01 +02:00
Pablo Correa Gómez
95edf678f4 ci: upload test report to CI
To make it possible, tweak a bit the Makefile

Part-of: https://gitlab.postmarketos.org/postmarketOS/postmarketos-mkinitfs/-/merge_requests/63
2025-06-16 18:31:13 +02:00
Pablo Correa Gómez
be6a6da417 ci: migrate from deprecated "only" keyword to "rules"
In the process, removed the unused "lint" stage and a massive comment
that is no longer useful. The rules should be self-explanatory

Part-of: https://gitlab.postmarketos.org/postmarketOS/postmarketos-mkinitfs/-/merge_requests/63
2025-06-06 16:40:15 +02:00
Clayton Craft
4e771ab96f osutil: mergeusr: don't rewrite /usr/sbin to /usr/bin (MR 58)
Alpine TSC decided to keep /usr/sbin for now, so let's not break paths
to stuff under /usr/sbin in the meantime.
2.6.2
2024-11-13 09:21:59 -08:00
Clayton Craft
4d7dd79bcf deviceinfo: test that inline-comments work (MR 57)
see: https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/5766
2024-11-13 00:49:34 -08:00
Clayton Craft
d63e600614 add compile-time flag to disable Go GC (MR 56)
I hate this, but it's the only good way I could find to allow working around this ugly QEMU bug:
https://gitlab.com/qemu-project/qemu/-/issues/2560
2.6.1
2024-09-28 08:32:53 -07:00
Clayton Craft
741c0553d5 Allow including initramfs-extra files in the initramfs (MR 48)
This uses a "deviceinfo_create_initfs_extra" to allow including
initramfs-extra files in the initramfs and skip creating a separate
initramfs-extra archive when it's set to "false".
If this variable is unset, mkinitfs uses a default value of "false".
2.6.0
2024-09-27 12:13:24 -07:00
Clayton Craft
cd97df108a filelist: trim whitespace from lines read from files (MR 55)
Fixes issues with leading/trailing whitespaces really messing with mkinitfs
2.5.1
2024-07-11 14:18:55 -07:00
Arnav Singh
1fed057a82 doc: fix spelling typo 2024-06-25 11:26:10 -07:00
Caleb Connolly
5efdb9f170 archive: add /usr/sbin symlinks for UsrMerge (MR 53)
[ci:skip-build]: already built successfully in CI
2024-06-18 23:59:34 +02:00
Clayton Craft
81de8b438d archive,hookfiles: convert paths to usr-merge when necessary (MR 39)
Co-authored-by: Caleb Connolly <caleb@postmarketos.org>
2.5.0
2024-05-29 15:29:41 -07:00
Caleb Connolly
af9a0f0ca5 archive: create symlinks for /bin, /sbin, /lib (MR 39) 2024-05-29 15:29:35 -07:00
Clayton Craft
014563fdbc osutil: add function to detect merged /usr systems (MR 39)
This is very crude, but in lieu of an actual spec for usr merge or some
standard way to detect whether it's done, this will have to do for now.
We can and should improve it later!
2024-05-29 15:29:35 -07:00
Caleb Connolly
83282187c2 archive: split out and rework symlink handling (MR 39)
There were some subtle bugs when handling symlinks to directories, and
other usrmerge bits. Rework the symlink handling to deal with this
properly and produce a sane ramdisk on usrmerge systems.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
Co-authored-by: Clayton Craft <clayton@craftyguy.net>
2024-05-29 15:29:35 -07:00
Caleb Connolly
eda4f3ba22 filelist/modules: try /usr/lib/modules (MR 39)
This is the path used on usrmerge distros, try it first as /lib/modules
will implicitly follow the /lib symlink.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2024-05-29 15:29:35 -07:00
Caleb Connolly
866d37b85d archive: improve error messages (MR 39)
Improve errors when writing out the cpio archive fails.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2024-05-29 15:29:35 -07:00
Clayton Craft
1334fdfa26 deviceinfo: replace implementation with mvdan/sh (MR 52)
This library has a convenient "source file" method designed for sourcing
shell envs and returning values set in them. deviceinfo's syntax every
where else seems to be "whatever sh can 'source'", so using this library
seems a lot nicer than trying to implement a parser/interpreter here
(and almost certainly missing corner cases, functionality, etc)

[ci:skip-build]: already built successfully in CI
2024-05-15 16:11:17 -07:00
Clayton Craft
56db822b88 deviceinfo: implement stringer (MR 52) 2024-05-15 16:11:17 -07:00
Clayton Craft
631d6078c2 misc/getfiles: add systemd lib dir to search paths (MR 51)
fixes #41
2024-05-15 16:07:43 -07:00
Clayton Craft
e5f14d70a6 doc: add archive compression formats/levels (MR 50)
fixes #28
2024-03-20 10:08:18 -07:00
Stefan Hansson
dd5cdeace5 misc: Also check for .zst-compressed variants of files (MR 49)
Initially I thought of breaking off the Stat + error check call into its
own function as to reduce repetition, but given that it's only useful in
this situation where it only happens twice anyway, I'm not sure it
actually would reduce complexity.

Additionally, this means that .zst-compressed variants of files will be
searched for in all contexts where this function is used. I'm not sure
this is desirable.

Tested and works with arrow-db820c. I didn't test it on actual hardware,
but I verified that the firmware ended up in the initramfs via
$ pmbootstrap initfs ls. I choose this device because it uses firmware
from linux-firmware and also needs said firmware present in the
initramfs.

Closes https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/39
2.4.0
2024-03-14 12:01:48 -07:00
Clayton Craft
1a99953aa2 bootdeploy: fallback to vmlinuz* kernels when zboot is set (MR 47)
Some kernel packages (e.g. linux-lts in Alpine) don't ship linux.efi, so
this needs to fallback to "vmlinuz" or else it won't be able to find a
kernel for boot-deploy.
2.3.1
2024-01-29 15:32:25 -08:00
Clayton Craft
e2f4e6254f modules: fix issue with some module extensions being ignored in dirs (MR 46)
There are several valid extensions that kernel modules can have, and the
list I had here was not complete... this meant that mkinitfs would fail
to include modules with extensions like ".ko.gz" when searching
directories.

This makes the check for a "valid" module file name a lot simpler,
allowing any file with ".ko" in the file name. While it's possible for a
non-module file to have ".ko" somewhere in the file name, it seems
unlikely if it's in the kernel modules directory... and this is an OK
compromise for now.
2024-01-29 10:16:28 -08:00
Clayton Craft
2efeb4510d doc: add new deviceinfo var for sd-boot (MR 44) 2.3.0 2024-01-26 11:12:12 -08:00
Caleb Connolly
f0b3c1d992 bootdeploy: support zboot kernel image (MR 44)
As we move towards UEFI on more devices, we want to use systemd-boot and
kernel images built with CONFIG_ZBOOT. However, these images aren't
compatible with existing Android bootloaders. As a result, we must
install both the old vmlinuz image for old bootloaders, and the fancy
new self-extracting EFI image.

When using systemd_boot, use linux.efi as the kernel file name instead
of globbing on vmlinuz*.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
2024-01-26 11:12:11 -08:00
Caleb Connolly
98bdb23f01 deviceinfo: parse GenerateSystemdBoot option (MR 44)
This will be used to adjust behaviour when using systemd boot

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
2024-01-26 11:06:37 -08:00
Clayton Craft
6618e564ad doc: drop unused deviceinfo_mesa_driver (MR 45)
Yay, one less deviceinfo var!
2024-01-26 11:05:23 -08:00
Clayton Craft
6df75d5682 deviceinfo: clean up unused MesaDriver (MR 45)
This deviceinfo var is no longer used in mkinitfs (see previous
commits).
2024-01-26 11:05:17 -08:00
Clayton Craft
9475572811 filelist/osksdl: drop module / support for osk-sdl (MR 42)
This removes code specific to installing osk-sdl in the initramfs
archive. osk-sdl has been deprecated / removed from postmarketOS for FDE
unlocking (in favor of using the app "unl0kr"), and other distros should
consider doing the same.
2023-11-24 18:13:26 -08:00
Pablo Correa Gómez
2b467eb77f Do not support loading modules from "deviceinfo_modules_initfs" (MR 38)
This variable will dissappear from the deviceinfo at some point:
https://gitlab.com/postmarketOS/pmaports/-/merge_requests/4169
so after it does, it would not make much sense to keep its use around
2023-11-24 18:01:24 -08:00
Clayton Craft
d77e1cd11d filelist/osk-sdl: add deprecation warning
Co-authored-by: Oliver Smith <ollieparanoid@postmarketos.org>
2.2.2
2023-10-12 23:26:16 -07:00
Clayton Craft
2ec78bfcfc mkinitfs: print error when failure to rm tmp dir, and make it non-fatal (MR 40)
This prints the error when the work dir can't be removed. This also
changes mkinitfs so that it does't fail in this situation.

The reasoning for this change in behavior is that mkinitfs returning
non-zero will signal to the caller that there's potentially a problem
with configuring boot-related stuff on their system, and a failure to rm
the work dir is just noise. If the cause of that failure is a deeper
problem, the log message should help figure it out.

fixes #35
2.2.1
2023-08-24 17:13:15 -07:00
Clayton Craft
fedf55b573 filelist/*: support comment lines starting with # (MR 41) 2023-08-24 17:11:47 -07:00
Clayton Craft
30681d2f0a filelist/*: skip empty lines (MR 41)
fixes #36
2023-08-24 17:11:22 -07:00
Clayton Craft
74de5f9798 mkinitfs: handle errors from archive.AddItems (MR 41) 2023-08-24 17:10:12 -07:00
Pablo Correa Gómez
2f4937c52d deviceinfo: add tests for ReadDeviceinfo (MR 37) 2.2 2023-06-18 10:18:15 -07:00
Pablo Correa Gómez
b1e44d8ec2 main: read /usr/share/deviceinfo/deviceinfo in addition to /etc/deviceinfo (MR 37)
Relates https://gitlab.com/postmarketOS/pmaports/-/issues/1836

The error checking for the detection of both files is not ideal, but there
are no obvious better solutions. For now, we want to avoid requiring one
by default, since it allows this change to be forward compatible so not
all MRs related to /usr/share have to go in at once. I followed the same
pattern as in boot-deploy!29 although there we check for "deviceinfo_arch"
to make sure that at least one of those files is complete.

The other alternative would be to add an Arch field to DeviceInfo struct,
and use it to check that at least one of the files was complete, and
ignore any errors if it exists. Since this is not ideal either, keep the
double test, and let's take care of fixes once one of them is compulsory.
2023-06-18 10:18:14 -07:00
Pablo Correa Gómez
c87b926a53 Move logic to check if deviceinfo file exists to pkgs/deviceinfo (MR 37)
This is mostly a preparatory commit to later be able to read the
deviceinfo from multiple places. It has a bit better encapsulation,
and makes the functions methods, so that they can update deviceinfo
file in-place.
2023-06-18 10:18:14 -07:00
Pablo Correa Gómez
b2cdfe9da4 main: return if unexpected error happens checking for deviceinfo file (MR 37) 2023-06-18 10:18:12 -07:00
Gabriel Marcano
a15c02f3aa archive: support using lz4 legacy (MR 36)
fixes: https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/27
2023-04-10 17:45:59 -07:00
Clayton Craft
0054fde90d cmd/mkinitfs: Exclude initramfs files from initramfs-extra (MR 34)
When testing on pmOS with qemu/x86_64, this results in some nice
reduction in size of the initramfs-extra (gzip'd, default compression):

Before:
        /mkinitfs # ls -la /boot/initramfs-extra
        -rw-r--r--    1 root     root       3544429 Mar 19 23:06 /boot/initramfs-extra

After:
        /mkinitfs # ls -la /boot/initramfs-extra
        -rw-r--r--    1 root     root       2234020 Mar 19 23:08 /boot/initramfs-extra

Fixes #23
2023-04-06 22:21:27 -07:00
Clayton Craft
dceef20121 cmd/mkinitfs: unroll generateArchive (MR 34)
There's some repetition that's added by unrolling this, but it will
allow passing the main initramfs archive's filelister to
archive.AddItemsExclude when generating the initramfs-extra.

I looked at several ways to implement this, this seems like least
terrible thing to do... The runner-up was to return a FileList from
archive.AddItems, and pass that around... Eww.
2023-04-06 22:21:27 -07:00