Pi3 USB boot support

I figured that the lines loading the fdt in u-boot had to be commented out, and that the kernel had to be passed the address of the fdt as fdt_addr instead of fdt_addr_r.

Now i’m stuck on fw_printenv not being able to find the right u-boot env, thus falling back to a default env and mender not accepting remote updates. I found a few threads that mention these issues, but i did not find an answer for the case of usb booting:

Here’s my fw_printenv output:

Warning: Bad CRC, using default environment
bootargs=
bootcmd=
bootdelay=2
baudrate=115200
arch=sandbox
cpu=sandbox
board=sandbox
board_name=sandbox
stdin=serial,cros-ec-keyb,usbkbd
stdout=serial,vidconsole
stderr=serial,vidconsole
ethaddr=00:00:11:22:33:44
eth1addr=00:00:11:22:33:45
eth3addr=00:00:11:22:33:46
eth5addr=00:00:11:22:33:47
ipaddr=1.2.3.4
host_boot=if host dev ${devnum}; then setenv devtype host; run scan_dev_for_boot_part; fi
boot_net_pci_enum=pci enum
boot_net_usb_start=usb start
usb_boot=usb start; if usb dev ${devnum}; then setenv devtype usb; run scan_dev_for_boot_part; fi
boot_prefixes=/ /boot/
boot_scripts=boot.scr.uimg boot.scr
boot_script_dhcp=boot.scr.uimg
boot_targets=host1 host0 
boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}extlinux/extlinux.conf
scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}extlinux/extlinux.conf; then echo Found ${prefix}extlinux/extlinux.conf; run boot_extlinux; echo SCRIPT FAILED: continuing...; fi
boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr}
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
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;
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
bootcmd_host1=setenv devnum 1; run host_boot
bootcmd_host0=setenv devnum 0; run host_boot
distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done
bootm_size=0x10000000
kernel_addr_r=0x1000000
fdt_addr_r=0xc00000
ramdisk_addr_r=0x2000000
scriptaddr=0x1000
pxefile_addr_r=0x2000
# systemctl status mender-client
● mender-client.service - Mender OTA update service
   Loaded: loaded (/lib/systemd/system/mender-client.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2021-06-11 18:13:10 CEST; 2 days ago
  Process: 967 ExecStart=/usr/bin/mender daemon (code=exited, status=1/FAILURE)
 Main PID: 967 (code=exited, status=1/FAILURE)

juin 11 18:13:10 cosmyx-nova systemd[1]: Started Mender OTA update service.
juin 11 18:13:10 cosmyx-nova mender[967]: time="2021-06-11T18:13:10+02:00" level=info msg="Loaded configuration file: /etc/mender/mender.conf"
juin 11 18:13:10 cosmyx-nova mender[967]: time="2021-06-11T18:13:10+02:00" level=error msg="Failed to read the current active partition: No match between boot and root partitions.: exit status 1"
juin 11 18:13:10 cosmyx-nova mender[967]: time="2021-06-11T18:13:10+02:00" level=error msg="mkdir /var/lib/mender: file exists"
juin 11 18:13:10 cosmyx-nova mender[967]: time="2021-06-11T18:13:10+02:00" level=error msg="Failed to read the current active partition: No match between boot and root partitions.: exit status 1"
juin 11 18:13:10 cosmyx-nova mender[967]: time="2021-06-11T18:13:10+02:00" level=error msg="mkdir /var/lib/mender: file exists"
juin 11 18:13:10 cosmyx-nova systemd[1]: mender-client.service: Main process exited, code=exited, status=1/FAILURE
juin 11 18:13:10 cosmyx-nova systemd[1]: mender-client.service: Failed with result 'exit-code'.

config_mender_defines.h

/* BB variables. */
#define MENDER_STORAGE_DEVICE_BASE "/dev/sda"
#define MENDER_UBOOT_ENV_STORAGE_DEVICE_OFFSET_1 0x400000
#define MENDER_UBOOT_ENV_STORAGE_DEVICE_OFFSET_2 0x800000
#define MENDER_ROOTFS_PART_A_NAME "/dev/sda2"
#define MENDER_ROOTFS_PART_B_NAME "/dev/sda3"

/* For sanity checks. */
#define MENDER_BOOTENV_SIZE 0x4000
# cat /etc/fw_env.config 
/dev/sda    0x400000    0x4000
/dev/sda    0x800000    0x4000

partition alignment:

sfdisk ${DEVICE} << EOF
label: dos
unit: sectors

start=       24576, size=      524288,   type=c, bootable
start=      548864, size=      31457280, type=83
start=    32006144, size=      31457280, type=83
start=    63463424, size=      53767984, type=83
EOF

Any direction i could be looking into ?