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
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".
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!
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>
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>
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
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
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.
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.
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>
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.
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
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.
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.
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
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.