rauc / meta-rauc-community

Yocto/OpenEmbedded meta layer with examples for integration of RAUC, the embedded Linux A/B update framework
MIT License
48 stars 52 forks source link

U-boot script variables not saving to environment properly #33

Closed MitchGaines closed 2 years ago

MitchGaines commented 2 years ago

Hi team,

I have a bit of an issue I'm hitting encompassing u-boot, rauc, and my raspberrypi board that I was hoping someone here could potentially assist me with. I'm using meta-rauc-raspberrypi as is for the RPi Compute Module 4 running dunfell. When I run rauc status, I get the following:

:~$ rauc status

(rauc:1527): rauc-WARNING **: 17:52:05.386: Failed getting primary slot: Failed getting primary slot: Unable to find primary boot slot

=== System Info ===
Compatible:  RaspberryPi4
Variant:     
Booted from: rootfs.0 (A)

=== Bootloader ===
Activated: (null) ((null))

=== Slot States ===
o [rootfs.1] (/dev/mmcblk0p3, ext4, inactive)
    bootname: B
    boot status: bad

o [rootfs.0] (/dev/mmcblk0p2, ext4, booted)
    bootname: A
    mounted: /
    boot status: bad

As a result, it obviously doesn't work. Not sure when this problem was introduced on my development system, so I'm having some trouble tracking it down.

Fundamentally, the issue seems to be because the BOOT_ORDER variable doesn't seem to be saving to my uboot.env. When I manually set that via fw_setenv, rauc corrects itself. But, if I reboot, that variable doesn't stick. Below is what I get when I run fw_printenv:

BOOT_A_LEFT=3
arch=arm
baudrate=115200
board=rpi
board_name=rpi
boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr}
boot_efi_binary=if fdt addr ${fdt_addr_r}; then bootefi bootmgr ${fdt_addr_r};else bootefi bootmgr ${fdtcontroladdr};fi;load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} efi/boot/bootaa64.efi; if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r};else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi
boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}${boot_syslinux_conf}
boot_net_usb_start=usb start
boot_prefixes=/ /boot/
boot_script_dhcp=boot.scr.uimg
boot_scripts=boot.scr.uimg boot.scr
boot_syslinux_conf=extlinux/extlinux.conf
boot_targets=mmc0 mmc1 usb0 pxe dhcp 
bootcmd=run distro_bootcmd
bootcmd_dhcp=run boot_net_usb_start; if dhcp ${scriptaddr} ${boot_script_dhcp}; then source ${scriptaddr}; fi;setenv efi_fdtfile ${fdtfile}; setenv efi_old_vci ${bootp_vci};setenv efi_old_arch ${bootp_arch};setenv bootp_vci PXEClient:Arch:00011:UNDI:003000;setenv bootp_arch 0xb;if dhcp ${kernel_addr_r}; then tftpboot ${fdt_addr_r} dtb/${efi_fdtfile};if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r}; else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi;fi;setenv bootp_vci ${efi_old_vci};setenv bootp_arch ${efi_old_arch};setenv efi_fdtfile;setenv efi_old_arch;setenv efi_old_vci;
bootcmd_mmc0=devnum=0; run mmc_boot
bootcmd_mmc1=devnum=1; run mmc_boot
bootcmd_pxe=run boot_net_usb_start; dhcp; if pxe get; then pxe boot; fi
bootcmd_usb0=devnum=0; run usb_boot
bootdelay=2
cpu=armv8
dhcpuboot=usb start; dhcp u-boot.uimg; bootm
distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done
efi_dtb_prefixes=/ /dtb/ /dtb/current/
fdt_addr_r=0x02600000
fdt_high=ffffffffffffffff
initrd_high=ffffffffffffffff
kernel_addr_r=0x00080000
load_efi_dtb=load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} ${prefix}${efi_fdtfile}
loadaddr=0x00200000
mmc_boot=if mmc dev ${devnum}; then devtype=mmc; run scan_dev_for_boot_part; fi
preboot=usb start
pxefile_addr_r=0x02500000
ramdisk_addr_r=0x02700000
scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${distro_bootpart}...; for prefix in ${boot_prefixes}; do run scan_dev_for_extlinux; run scan_dev_for_scripts; done;run scan_dev_for_efi;
scan_dev_for_boot_part=part list ${devtype} ${devnum} -bootable devplist; env exists devplist || setenv devplist 1; for distro_bootpart in ${devplist}; do if fstype ${devtype} ${devnum}:${distro_bootpart} bootfstype; then run scan_dev_for_boot; fi; done; setenv devplist
scan_dev_for_efi=setenv efi_fdtfile ${fdtfile}; for prefix in ${efi_dtb_prefixes}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${efi_fdtfile}; then run load_efi_dtb; fi;done;if test -e ${devtype} ${devnum}:${distro_bootpart} efi/boot/bootaa64.efi; then echo Found EFI removable media binary efi/boot/bootaa64.efi; run boot_efi_binary; echo EFI LOAD FAILED: continuing...; fi; setenv efi_fdtfile
scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${boot_syslinux_conf}; then echo Found ${prefix}${boot_syslinux_conf}; run boot_extlinux; echo SCRIPT FAILED: continuing...; fi
scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${script}; then echo Found U-Boot script ${prefix}${script}; run boot_a_script; echo SCRIPT FAILED: continuing...; fi; done
scriptaddr=0x02400000
soc=bcm283x
stderr=serial,vidconsole
stdin=serial,usbkbd
stdout=serial,vidconsole
usb_boot=usb start; if usb dev ${devnum}; then devtype=usb; run scan_dev_for_boot_part; fi
vendor=raspberrypi

Here's my u-boot debug output:

U-Boot 2020.01 (Jan 06 2020 - 20:56:31 +0000)

DRAM:  2 GiB
RPI Compute Module 4 (0xb03140)
MMC:   mmcnr@7e300000: 1, emmc2@7e340000: 0
Loading Environment from FAT... *** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   No ethernet found.
starting USB...
No working controllers found
Hit any key to stop autoboot:  0
switch to partitions #0, OK
mmc0(part 0) is current device
Scanning mmc 0:1...
Found U-Boot script /boot.scr
1383 bytes read in 11 ms (122.1 KiB/s)
## Executing script at 02400000
Found valid RAUC slot A
Saving Environment to FAT... OK
16724480 bytes read in 1400 ms (11.4 MiB/s)
## Flattened Device Tree blob at 2eff4000
   Booting using the fdt blob at 0x2eff4000
   Using Device Tree in place at 000000002eff4000, end 000000002f002f22

Starting kernel ...

A thing to note, I recently downgraded my u-boot version from 2022.01 for unrelated reasons and needed to apply a patch to uboot to support the CM4 board. Below is the patch I created.

diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
index e367ba3092..36c1b710da 100644
--- a/board/raspberrypi/rpi/rpi.c
+++ b/board/raspberrypi/rpi/rpi.c
@@ -157,6 +157,21 @@ static const struct rpi_model rpi_models_new_scheme[] = {
        DTB_DIR "bcm2711-rpi-4-b.dtb",
        true,
    },
+   [0x12] = {
+       "Zero 2 W",
+       DTB_DIR "bcm2837-rpi-zero-2.dtb",
+       false,
+   },
+   [0x13] = {
+       "400",
+       DTB_DIR "bcm2711-rpi-400.dtb",
+       true,
+   },
+   [0x14] = {
+       "Compute Module 4",
+       DTB_DIR "bcm2711-rpi-cm4.dtb",
+       true,
+   },
 };

Logically, this move seems like the smoking gun, but I'm not sure why. Not sure if anyone here has hit this error before or has some insight. It seems a little odd that the BOOT_A_LEFT variable would stick, but the others wouldn't. When I take a look at the uboot.env file, it seems to be consistent with what fw_printenv prints out. Also, the Loading Environment from FAT... *** Warning - bad CRC, using default environment error when u-boot loads seems to also indicate other issues with my environment.

Would appreciate any help on this. Thanks

MitchGaines commented 2 years ago

I'm actually going to close this issue I think because its a weird set of circumstances that are a bit beyond the scope of this project. Further, I was trying to hack some things together to make them function. Ultimately, I was able to move back up to u-boot 2022.01 which resolved my rauc issues.

leon-anavi commented 2 years ago

Hi @MitchGaines,

Thank you for sharing your experience and the note about u-boot 2022.01 and congrats for figuring it out. The feedback might be useful to someone else in a similar situation using CM4.

Thanks, Leon