cdsteinkuehler / br2rauc

Buildroot + RAUC
Other
52 stars 18 forks source link

cmdline.txt is ignored? #1

Closed BubuOT closed 2 years ago

BubuOT commented 2 years ago

Hi! First of all: Thanks for publishing this. I started setting up a cm4 buildroot project with updating via rauc pretty much exactly 3 weeks after you published this and this saved me sooo many hours of research :).

I've encountered one thing that confuses me a bit now though:

The only thing that the custom cmdline.txt from this project is used for seems to be checking for the presence of fw_dtb. Regardless of that being present or not we boot the kernel with the default_bootargs from the uboot script (and these seem to be persisted into the env, so aren't update-able).

Should we instead be copying the full fw_cmdline into bootargs? This would again couple the bootfs where the cmdline.txt resides with the rootfs, where the kernel (and ideally dtb) lives though. So maybe a better option would be shipping (a copy of) cmdline.txt in the rootfs and have uboot read it from there and use that instead of default_bootargs?

Happy to hear your thoughts on this.

(What I actually wanted to add to the cmdline was: cgroup_enable=memory cgroup_memory=1, so having a way to ship updates for bootargs during the livetime of the device seems like a sensible thing to plan for.)

cdsteinkuehler commented 2 years ago

Great point. Actually, if you define fw_dtb, the kernel is booted with the firmware modified device-tree which includes the contents of cmdline.txt and various other firmware modifications to the kernel command line. However as you point out, any changes to cmdline.txt will be ignored when booting without the fw_dtb setting.

The question is what to do about this. One option would be to update default_bootargs (using fw_setenv) when installing a new rootfs, but that generally breaks the "fall back to last known good version" logic, since there's only one boot environment.

I think the proper answer is to pull (at least some of) the kernel command line from the rootfs partition with the kernel and device tree. This ought to be fairly straight-forward via U-Boot scripting, but it might be a bit until I can get to addressing this. Pull requests welcome!

Random thoughts:

if [ -r <rootfs>/boot/cmdline.txt ] ; then read and append to command line ; fi
if [ -r <rootfs>/boot/cmdforce.txt ] ; then read and replace command line ; fi

Which is better? Support both? NOTE: "command line" is really the device-tree node "/chosen/bootargs" and can be set as desired in the dtb file in the rootfs, but perhaps it is more elegant to allow somewhat more traditional updating/modification of the kernel command line without needing to recompile the whole device-tree?

BubuOT commented 2 years ago

Actually, if you define fw_dtb, the kernel is booted with the firmware modified device-tree which includes the contents of cmdline.txt and various other firmware modifications to the kernel command line.

I don't think this is currently happening? At least I haven't seen it working (and I'm still using fw_dtb right now), Mh, quick google search turned up this, which says, this is kernel config option (or uboot? I can't currently find it either way, it might all be 10 years outdated by now :-/), which cmdline gets priority:

https://stackoverflow.com/a/48814885

Here's the mailing list discussion via archive.org referenced in that SO post: https://web.archive.org/web/20190906083353/https://lists.linaro.org/pipermail/linaro-dev/2011-February/002853.html

I'll see if I can find a general solution for this which I can submit here. :)

cdsteinkuehler commented 2 years ago

Thanks for the link, my understanding was also incomplete. :-)

Note that the RPi firmware also manipulates the boot arguments (updated in the FW modified device-tree) with things like video= settings. I haven't decided if it's potentially useful to try and merge in the firmware cmdline modifications or just ignore them. There's a bit of a reference on the RPi forums as to what mods the Firmware makes to the device-tree (and bootargs) in this thread: https://forums.raspberrypi.com/viewtopic.php?t=329799

cdsteinkuehler commented 2 years ago

This issue of ignoring cmdline.txt should be fixed by commit f03938245a66c63e194baa29e4202ce5e967ed4b, which appends the rauc kernel arguments to the firmware supplied kernel command line when using the firmware loaded device-tree.

The issue with not being able to alter command line parameters via the rootfs (which is safer to update than the boot loader) is fixed in the following commit aa8f99f4a50c37e08a89b7c4a4b77ed9fac006a3, which loads environment variables from a /boot/uEnv.txt file (if present on the appropriate rootfs partition) and uses bootargs_force and bootargs_extra to allow overriding (_force) or extending (_extra) the default bootargs in the environment.

Next I plan to add support for a rescue partition, which will be booted if a GPIO pin is pulled low during boot (the trigger can be easily changed by editing the u-boot.ush script) and expand the image to apx. 4 GB (see updated ToDo list in the latest README commit ece3d585a580aa52b442e04ee751690fd6f9b162).