Commit graph

55 commits

Author SHA1 Message Date
Caleb Connolly
709768214c
postmarketos-initramfs: check if UDC is configured before clearing (MR 5000)
This fixes the annoying "sh: write error" and "Couldn't write to clear
UDC" messages that happen on every single boot.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:35:04 -07:00
Caleb Connolly
75613d9f69
postmarketos-initramfs: make CONFIGFS global (MR 5000)
This variable is being used in more places, just make it global.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:35:04 -07:00
Caleb Connolly
95b22138c4
postmarketos-initramfs: log to kernel ringbuffer (MR 5000)
Rework logging to always log the initramfs output to the kernel
ringbuffer and deprecate PMOS_NO_OUTPUT_REDIRECT in favour of following
the kernel loglevel.

I know it seems silly to use syslogd for this, but it's necessary to
buffer writes to /dev/kmsg per-line if we want to correctly set the log
level, and "tee" does not do this (it will write multiple lines at once,
resulting in "<14>" prints in the ringbuffer). The main advantage to
this is that we won't have kernel logs cut in half by initramfs logs
anymore, everything will be nicely line buffered!

The previous logging solution of multiple "tail" commands would actually
fail to log up to the last few lines before a crash due to how tail
works (it polls the file and buffers lines).

I attempted something like this before, but I stopped after running into
ratelimiting issues. These are now resolved by configuring the
printk_devkmsg sysctl.

Dropping PMOS_NO_OUTPUT_REDIRECT:

The general motivations behind PMOS_NO_OUTPUT_REDIRECT was to avoid
cluttering up the console with initramfs logs when they aren't wanted;
this is now handled instead by the kernels logging facility. We log to
the ringbuffer at LOGLEVEL_INFO, so if "quiet" is specified on the
cmdline (or the loglevel is otherwise set above info) then initramfs
logs will also not be shown.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:35:04 -07:00
Caleb Connolly
6c799ac4f6
postmarketos-initramfs: fork -minimal variant (MR 5000)
We plan to make a lot of changes to the initramfs which will require
incresaing the size. There are some devices that have literally no free
space for this, so make a -minimal initramfs fork that can continue to
support those while we update the regular initramfs.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-18 12:34:59 -07:00
SSD
086078ded7
main/postmarketos-initramfs: fix stowaway (MR 5206)
I have noticed a bug. Because is some cases, uuid for the boot partition is set, it won't reach logic for the stowaway.

[ci:skip-build]: already built successfully in CI
2024-06-06 11:12:48 +02:00
mae
61133a23ae
main/msm-fb-refresher: move cleanup from initramfs into msm-fb-refresher (MR 5191)
[ci:skip-build]: already built successfully in CI
2024-06-04 20:46:50 +02:00
mae
25ad7892a1
main/postmarketos-mkinitfs-hook-debug-shell: Cleanup debug-shell telnet server (MR 5191)
Moved the cleanup code from initramfs
2024-06-04 20:46:50 +02:00
mae
ebd351c346
main/postmarketos-initramfs: Allow packages to define cleanup hooks (MR 5191) 2024-06-04 18:44:34 +00:00
Pablo Correa Gómez
28e58a9cda
main/postmarketos-initramfs: update comment on why we mount /boot (MR 5089) 2024-05-16 12:02:37 +02:00
Pablo Correa Gómez
bb6d7a05b3
main/postmarketos-initramfs: add options for charset to mount vfat /boot (MR 5089)
This charset is the default and the recommended value, since boot fat
partitions should be case insensitive. linux-lts and linux-edge in
alpine use "utf-8", that might change, but add the options regardless,
so we can be safe

Fixes https://gitlab.com/postmarketOS/pmaports/-/issues/2782
2024-05-16 12:02:37 +02:00
Pablo Correa Gómez
efc7ad99e4
main/postmarketos-initramfs: add some sane mount options to /boot (MR 5089)
We won't want executables, suid executables, devices. We neither want
symbolic links in fat partitions. These have been taken from
systemd (Ref #2782)
2024-05-16 12:02:37 +02:00
SSD
089d7cc987
main/postmarketos-initramfs: stowaway rootfs (MR 4386)
[ci:skip-build]: already built successfully in CI
2024-05-09 08:32:23 -07:00
Clayton Craft
d1ad0d8713
main/postmarketos-initramfs: add crc32_generic module for F2FS (MR 4973)
Apparently f2fs has a soft dependency on this driver, so if it's =m in
the kernel then let's make sure it's always in the initramfs since f2fs
is a supported filesystem.

Fixes https://gitlab.com/postmarketOS/pmaports/-/issues/2711
[ci:skip-build]: already built successfully in CI
2024-04-18 14:44:55 +02:00
Raymond Hackley
10eb68fe05
main/postmarketos-initramfs: add USB booting support (MR 4947)
How to boot from USB drives:
1. Make sure the extcon has OTG support and included in initramfs
2. Make sure the PMIC supports the power to OTG devices, and included in initramfs. Otherwise, a hub with external power supply is required.
3. Make sure module `usb-storage` is enabled in initramfs
4. `pmbootstrap install --sdcard=/dev/<usb_drive>`
    - postmarketOS/pmbootstrap@942ee20789 is required to ignore sdcard check. Thanks @ollieparanoid for the patch.
5. `pmbootstrap flasher flash_kernel`
6. Insert the USB drive to OTG and boot

[ci:skip-build]: already built successfully in CI
2024-03-19 09:28:32 +00:00
Arnav Singh
b0226839d4
main/postmarketos-initramfs: fix starting unudhcpd when no UDC configured (MR 4907)
Reading the `ifname` of a gadget that has not been configured with a UDC
succeeds with the content `(unnamed net_device)` instead of failing.
So we need to explicitly check that a UDC was configured before we read
the interface name.

Ref: #2648
2024-03-11 13:53:17 -07:00
Caleb Connolly
a65dc9b4c0
postmarketos-initramfs: bigger log image size (MR 4880)
Sometimes, there can be more than 10M of stuff collected for logging,
which breaks things.. bump the size to 32M which should still be small
enough for low end / old devices.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-03-10 16:10:13 +00:00
xtex
160c63f12c
main/postmarketos-initramfs: allow redirect logs to pmsg device (MR 4800)
/dev/pmsg0 may be created by pstore driver. When it is available,
write logs into it so logs can be recovered through pstore after
a failed boot. This is useful for devices without console or hard
to get console.
2024-02-16 09:39:37 -08:00
Caleb Connolly
070ae7566d
main/postmarketos-initramfs: depend on mdev-conf (MR 4807)
we need this, i think it was pulled in via some dependency before.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2024-02-07 22:41:29 +01:00
Clayton Craft
d3ed7fe428
main/postmarketos-initramfs: don't fallback looking for /boot when given uuid or path (MR 4775)
fixes #2562

[ci:skip-build] already built successfully in CI
2024-02-06 14:24:35 -08:00
Clayton Craft
2adefeb206
main/postmarketos-initramfs: tweak msg when boot or root not found (4775) 2024-02-06 14:24:15 -08:00
Anton Bambura
d2dec46275
main/postmarketos-initramfs: wait for boot partition (MR 4775)
Some devices take time to initialize storage, e.g. Qualcomm laptops
using ADSP need to load firmware firstly, and initramfs script does
not always manage to mount boot partition in time.

Unfortunately, there is no reliable way to reproduce the issue, but
this patch should fix cases like this.
2024-02-06 14:21:15 -08:00
Arnav Singh
2a0fab1a77
main/postmarketos-initramfs: support reading USB network UDC name from deviceinfo (MR 4750)
Before this change the script assumed that the device has only one UDC.
However it is possible for a device to have multiple UDCs, in which case
the deviceinfo is the appropriate place to specify which one should be used.
This change adds an optional deviceinfo variable `deviceinfo_usb_network_udc`
to specify the UDC that should be used.

Also, before this change the script assumed the USB network interface name is
"usb0". But other gadget drivers like `g_cdc` can claim USB interfaces
before the initramfs script gets around to creating one for USB networking,
so the interface might be "usb1" or something else. The configfs gadget itself
can provide the actual interface name, so this change makes the script
use that.
2024-01-23 12:21:24 -08:00
Caleb Connolly
57744b984e
postmarketos-initramfs: export logs on boot failure (MR 4646)
Currently, when postmarketOS fails to boot up, retrieving any
information necessary to root cause the issue is non-trivial, requiring
building a custom initramfs with debug-shell enabled and then manually
copying out data.

Let's improve the situation by exporting logs automatically on boot
failure. This is safer than just exposing a root shell but still
provides a whole lot of useful info that should make duplicating and
triaging issues much easier for developers.

This commit implements the functionality and includes some generally
useful data. We then generate a README and expose files for each command/log
as well as an archive that can be easily attached to a GitLab issue.

To help with triaging, also record the version of the postmarketos-initramfs
package and hash the init.sh and init_functions.sh files.

For testing purposes, you can trigger the log recovery mode on-time by
creating an empty file named ".pmos_export_logs" in the /boot partition.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2024-01-05 17:29:45 +00:00
Caleb Connolly
241ade087f
postmarketos-initramfs: always save logs (MR 4646)
Always write logs to the ramdisk, adjust setup_log() to spawn "tail" to
pipe the log to the console device when PMOS_NO_OUTPUT_REDIRECT is set.

This is necessary to ensure that the initramfs logs can be extracted on
a failed boot.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2024-01-05 16:36:18 +00:00
Luca Weiss
2a4320e16e
main/postmarketos-mkinitfs: use NCM instead of RNDIS (MR 3670)
As described in [0] let's switch away from RNDIS and use NCM instead.

Since we cannot force all kernels to switch at the same time, let's keep
a fallback to RNDIS in the setup function.

We can also remove usb_f_rndis from modprobe as the module gets loaded
automatically when needed, but instead we need to load libcomposite
manually so that $configfs/usb_gadget gets created.

[0] https://gitlab.com/postmarketOS/pmaports/-/issues/1797

[ci:skip-build] already built successfully in CI
2023-11-20 16:33:57 -08:00
Ion Agorria
5626781fca
main/postmarketos-initramfs: Separate code into setup_usb_configfs_udc (MR 4450)
This method is called from setup_usb_network_configfs and debug shell's
setup_usb_storage.sh
2023-11-19 10:27:41 -08:00
Clayton Craft
c9c4b492e4
main/postmarketos-initramfs: show OS version on splash screen (MR 4470)
This shows the OS version (from /etc/os-release), e.g. "edge", on the splash
screen. os-release is a tiny text file, adding it to the initramfs doesn't seem
too bad, and having this information on the splash screen can be helpful.

Note that this uses "VERSION" and not "PRETTY_NAME" from the os-release file,
since the splash already shows "postmarketOS" (and the pretty name includes
that too), it seemed redundant and took up valuable display space.

[ci:skip-build]: already built successfully in CI
2023-11-02 08:44:47 +01:00
Caleb Connolly
69832ab121
postmarketos-initramfs: support running in CI (MR 4420)
Enable using the postmarketOS initramfs for boot-testing devices, in
this scenario we don't care about some components like the splash, mdev,
or subpartitions, instead we want to run full udev (to load all devices)
and then run hooks. The ci hook will deadloop after running tests.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2023-10-31 19:53:22 +00:00
Caleb Connolly
78762563c2
postmarketos-initramfs: use blkid (MR 4487)
Explicitly pull in the blkid package (we already added it to
00-initramfs-base.files), and replace uses of busybox findfs. Full fat
blkid supports PARTLABEL (so the /dev/disk/by-partlabel symlinks will
work consistently now), and has some nice optimisations that make the
lookup times a lot faster than busybox findfs.

[ci:skip-build]: already built successfully in CI
2023-10-23 08:10:56 +02:00
Caleb Connolly
5c6f2dd0d9
postmarketos-initramfs: fix partition cmdline priority (MR 4487)
The "pmos_[br]oot(_uuid)?" kernel cmdline args can be used to specify
how to mount the root and boot partitions. During a previous rework, the
behaviour of these was made inconsistent (becoming dependent on the
order they were specified on the cmdline).

Undo the previous "optimisation" by splitting them back out into two
FOR loops, where the _uuid variants take precedence.
2023-10-23 08:10:50 +02:00
Pablo Correa Gómez
bdaf8ef02f
main/postmarketos-initramfs: support comments in modules.load file (MR 4490)
[ci:skip-build]: already built successfully in CI
2023-10-18 15:08:21 +00:00
Pablo Correa Gómez
34e2a3ddad
main/postmarketos-initramfs: add new deviceinfo path to initramfs (MR 4283)
Reorder alphabetically while in the process, and depend on the first
mkinitfs and devicepkg-utils that implemented deviceinfo in /usr/share
2023-09-25 09:20:32 +02:00
Clayton Craft
9198a2ad6e
main/postmarketos-initramfs: upgrade to 2.0.0 (MR 4204)
Updates this package's checksums for files modified in this patch
series, and bumps the pkgver
2023-09-08 17:14:59 +02:00
Clayton Craft
20e4eb495d
main/postmarketos-initramfs: hide cryptsetup not found error (MR 4204)
Hides this error when FDE is *not* enabled, and ultimately skips the
block of logic for detecting the luks partition:
        /init: line 437: cryptsetup: not found

This error has confused some users in the past, who were reporting
issues with the initramfs.

There's probably a minor speedup on non-FDE systems as well from
bailing early.
2023-09-07 20:33:56 +01:00
Clayton Craft
cfed09ca36
main/postmarketos-initramfs: overwrite dest when extracting initramfs-extra (MR 4204)
If a file exists in the initramfs at runtime, cpio won't overwrite it
by default when extracting the initramfs-extra archive. This adds the -u
option to cpio, to overwrite any existing files in the destination.

This is meant to fix issues where the -extra archive has an app that is
meant to replace a busybox app, busybox --install creates it in the
initramfs and gzip will skip it since it's newer than what is in the
archive.
2023-09-07 20:33:56 +01:00
Caleb Connolly
9fb29079cd
main/postmarketos-initramfs: get to splash faster (MR 4204)
With full-fat mdev supporting by-partlabel lookups, there is a small
delay during startup. As mdev and dynamic partitions aren't actually
needed for the framebuffer device, move show_splash earlier.

Furthermore, slightly rework setup_framebuffer to not dump the verbose
message about waiting for the framebuffer unless the framebuffer isn't
found.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2023-09-07 20:33:56 +01:00
Clayton Craft
97727c59cb
main/postmarketos-initramfs: use only one method to resize the root partition (MR 4204)
This removes the possibility that multiple resize root partition methods
could be invoked. I'm not sure how likely this is in practice, but it
seems like we should avoid the possiblity altogether.

This also adds some more helpful printing to stdout when the partition
resize is skipped / not done.
2023-09-07 20:33:56 +01:00
Caleb Connolly
6f44124c1b
main/postmarketos-initramfs: fixup device-mapper paths (MR 4204)
findfs might produce a block device path like /dev/dm-3, these can
change across boots and devices. Make things more readable and
consistent by mapping from the /dev/dm-* path to the equivalent
/dev/mapper/xyz path. Combined with invoking kpartx from a
/dev/disk/by-partlabel/abc symlink, this results in the final block
device having a name like /dev/mapper/userdata2 on an Android device.

Whilst this is just nicer to work with, this will be especially useful for
the upcoming ondev2 postmarketOS installer to make device-specific
configuration and detection easier.
2023-09-07 20:33:56 +01:00
Caleb Connolly
89fba12fbb
main/postmarketos-initramfs: optimise find_*_partition (MR 4204)
Save the root/boot partition paths once found, and optimise a few loops.

Additionally, fall-back to other search methods when the pmos_boot or
pmos_uuid_boot cmdline args are set but fail.

Co-authored-by: Clayton Craft <clayton@craftyguy.net>
2023-09-07 20:33:55 +01:00
Caleb Connolly
e0fcfb74e2
main/postmarketos-initramfs: use mdev properly (MR 4204)
Drop in mdev.conf and the /lib/mdev/persistent-storage script, these
cause /dev/disk/by-* to be populated in the ramdisk, making it
possible to do look up partition by-label and by-partlabel for free,
compared to findfs which can take some time.

As a first optimisation based on this, check for some partitions using
these paths and prioritise them when looking for subpartitions. Drop the
first find_boot_partition call as it doesn't really save time over the
call in the while loop.

The mdev config also handles setting up /dev/null, /dev/random, etc, so
these don't have to be done manually.
2023-09-07 20:33:55 +01:00
Clayton Craft
7c79667fe0
main/postmarketos-initramfs: move init.sh to initramfs-specific dir (MR 4204)
These files aren't owned by mkinitfs, or used to configure mkinitfs, so
I think it makes sense that they belong in a dir specific to this
package instead of cluttering up mkinitfs's config dirs.
2023-09-07 20:33:55 +01:00
Caleb Connolly
73e05bf16d
main/postmarketos-initramfs: silence pbsplash (MR 4204) 2023-09-07 20:33:55 +01:00
Luca Weiss
5f820deefc
main/postmarketos-initramfs: switch_root with /dev (MR 3230) (MR 4204)
Mount /dev (and /run) in initramfs so util-linux switch_root can move
the mounts over to the new sysroot before changing root.
BusyBox switch_root doesn't even attempt to move anything so use
util-linux's switch_root for this.

Explicitly disable tests too...
2023-09-07 20:33:55 +01:00
bademux
80fff9242a
main/postmarketos-initramfs: support custom IP addresses for USB net (MR 3349)
[ci:skip-build] already built successfully in CI
2023-08-23 13:06:15 -07:00
Johannes Marbach
202b6e9435
main/postmarketos-initramfs: wait for splash to exit before unlocking (MR 3952)
[ci:skip-build]: already built successfully in CI
2023-08-08 09:36:17 +02:00
Pablo Correa Gómez
9839303dca
main/postmarketos-initramfs: stop using removed deviceinfo_modules_initfs (MR 4169)
The modules are now managed exclusively through the
/lib/modules/initramfs.load files
2023-08-04 08:27:44 +02:00
Steven Davies
1e4c8238c3
postmarketos-initramfs: Handle rootfsopts= on kernel cmdline (MR 4288)
This also removes redundant code and handles mount failure/no filesystem
separately.

fixes #2242
2023-08-02 11:33:47 -07:00
Pablo Correa Gómez
38ce112cdf
main/postmarketos-initramfs: load modules also from /lib/modules/initramfs.load (MR 4193)
Make it possible to load modules from the file installed by devicepkg-dev,
that will be there when extra modules are needed. This is coded in a
backwards-compatible way, so that it can be independent of the main modules
MR.

The code changes create a new function which takes a list of modules
and possibly a file (that should contain a list of modules too). The
idea is to be able to support also loading modules for initramfs-extra
in the future, and having a similar file would be more convenient than
extracting all the modules each time. In addition, the "[ -d /lib/modules]"
check has been removed. If there's no modules directory, as all
modules might be built-in, modprobe will fail, but that will not be
fatal. This will most likely only exclusively happen in some android
downstream kernel, so it should not be a big concern.
2023-07-10 11:07:51 -07:00
Luca Weiss
87ef850e88
main/postmarketos-initramfs: remove telnetd from initramfs (MR 4237)
This appears to be an ancient leftover from the telnet-based FDE
unlocking mechanism that has been present many many years ago.

But since this was removed a while ago, it's time to also finally remove
telnetd from the initramfs.
2023-07-08 19:06:29 +02:00
Newbyte
881dbc6a22
main/postmarketos-initramfs: use source_deviceinfo from devicepkg-utils (MR 4129)
See https://gitlab.com/postmarketOS/pmaports/-/issues/2086
2023-06-03 17:44:24 +02:00