rauc / rauc

Safe and secure software updates for embedded Linux
https://rauc.io
GNU Lesser General Public License v2.1
819 stars 200 forks source link

buildroot + u-boot + rauc + rpi4-64: Failed getting primary slot #785

Closed fguerzoni closed 2 years ago

fguerzoni commented 2 years ago

Hi, this is a kind of help request to make Rauc-1.5.1 work with:

buildroot-2021.08
uboot-2021.7

I managed to make the rpi4 gpu run uboot as the kernel and then let uboot start the real kernel with the following result:

# uname -a
Linux buildroot 5.10.46-v8 #1 SMP PREEMPT Wed Oct 20 07:31:43 CEST 2021 aarch64 GNU/Linux

Then I decided to add Rauc on the target, so I modified buildroot configs to have:

# fdisk -l
Disk /dev/mmcblk0: 60 GB, 64021856256 bytes, 125042688 sectors
1953792 cylinders, 4 heads, 16 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device       Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/mmcblk0p1 *  0,0,2       4,20,17              1      65536      65536 32.0M  c Win95 FAT32 (LBA)
/dev/mmcblk0p2    4,20,18     19,96,14         65537     311296     245760  120M 83 Linux
/dev/mmcblk0p3    19,96,15    34,172,11       311297     557056     245760  120M 83 Linux

and

# cat /etc/rauc/system.conf 
[system]
compatible=RaspberryPi4
bootloader=uboot

[keyring]
path=/etc/rauc/dev.cert.pem

[slot.bootloader.0]
device=/dev/mmcblk0p1
type=vfat

[slot.rootfs.0]
device=/dev/mmcblk0p2
type=ext4
bootname=A

[slot.rootfs.1]
device=/dev/mmcblk0p3
type=ext4
bootname=B

But I still cannot solve the following issue:

# rauc status

(rauc:265): rauc-WARNING **: 00:56:04.272: Failed getting primary slot: Failed getting primary slot: fw_printenv failed with exit code: 1

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

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

=== Slot States ===
  [bootloader.0] (/dev/mmcblk0p1, vfat, inactive)

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

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

fw_printenv has been built and it's availble on the target:

# fw_printenv --version
Compiled with U-Boot 2021.07
# fw_printenv --help
Usage: fw_printenv [OPTIONS]... [VARIABLE]...
Print variables from U-Boot environment

 -h, --help           print this help.
 -v, --version        display version
 -c, --config         configuration file, default:/etc/fw_env.config
 -n, --noheader       do not repeat variable name in output
 -l, --lock           lock node, default:/var/lock

Comparing against a working yocto+uboot+rauc build I noticed that I'm missing the /etc/fw_env.config file containing: /boot/uboot.env 0x0000 0x4000 but adding it does not change/solve the issue.

What I'm missing? Thanks and regards

ejoerns commented 2 years ago

@fguerzoni Did you configure U-Boot to actually handle the boot partition selection (with scripting) based on the variables RAUC uses? And does it pass the booted slot as commandline parameter?

You can read more about this here:

https://rauc.readthedocs.io/en/latest/integration.html#id5

or have a look / use the example layer:

https://github.com/rauc/meta-rauc-community/tree/master/meta-rauc-raspberrypi

Regards, Enrico

fguerzoni commented 2 years ago

Thank you very much for the quick reply. I forgot to mention the boot.txt from which the boot.scr is generated. I followed the example you reported with (slight) modifications: boot.txt When booting I can read from the console: Found valid RAUC slot A so I think the boot selection script is working

ejoerns commented 2 years ago

@fguerzoni When you run fw_printenv on the target, does it print the variables set by your script and expected by RAUC? (BOOT_A_LEFT, BOOT_ORDER, etc.)

When it does not, are you sure that both the U-Boot and the system use the same location for reading/storing the U-Boot env?

fguerzoni commented 2 years ago

That's the point! fw_printenv on the target prints: Cannot parse config file '/etc/fw_env.config': No such file or directory

while printenv on uboot returns:

BOOT_A_LEFT=1
BOOT_B_LEFT=3
BOOT_DEV=mmc 0:2
BOOT_ORDER=A B
arch=arm
baudrate=115200
board=rpi
board_name=4 Model B
board_rev=0x11
...

So I have to fix this. Thank you

fguerzoni commented 2 years ago

Setting properly the /etc/fw_env.config file to: /boot/uboot.env 0x0000 0x4000 makes the fw_printenv access the stored uboot environment.

Then the rauc status command runs fine:

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

=== Bootloader ===
Activated: rootfs.0 (A)

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

x [rootfs.0] (/dev/mmcblk0p2, ext4, booted)
        bootname: A
        boot status: good

Thanks for the support

Sourabh1107 commented 2 years ago

Hi @fguerzoni , I am also working on integrating RAUC with Buildroot. I had few doubts regarding this. How did you modify the Kconfig to enable the flags as mentioned in RAUC documentation? Can you please let me know if there are any dependencies to be taken care of?

fguerzoni commented 2 years ago

Hi @Sourabh1107, I think rauc-buildroot integration is very good because when you choose rauc in the Target Packages menu all its dependencies are automatically checked. There are many other tweaks that depend on what you really want to build. Anyway here's my current .config file where you can find for reference all the configs I set for buildroot, u-boot and the kernel. .config.txt Regards

Sourabh1107 commented 2 years ago

Hello @fguerzoni Thanks for the quick response. Its good to know that the dependencies are automatically checked. I have also enables the similar setup for RAUC in .config file. But what about these settings for Kernel? [https://rauc.readthedocs.io/en/latest/integration.html#kernel-configuration]. I am bit confused on how to edit kernel config(Kconfig).

fguerzoni commented 2 years ago

Actually it's quite easy: make linux-menuconfig and eventually make uboot-menuconfig because uboot must point to the same kernel version. please read the docs because this is described pretty well