Pi3 USB boot support

adding

CONFIG_ENV_OFFSET=0x400000
CONFIG_ENV_OFFSET_REDUND=0x800000

did not change the .config file, so i guess they’re ignored if they’re not with

CONFIG_ENV_IS_IN_MMC=y
CONFIG_ENV_OFFSET=0x400000
CONFIG_ENV_OFFSET_REDUND=0x800000

that yields the following .config

$ cat .config | grep CONFIG_ENV | grep -v "# "
CONFIG_ENV_SIZE=0x4000
CONFIG_ENV_OFFSET=0x400000
CONFIG_ENV_OFFSET_REDUND=0x800000
CONFIG_ENV_VARS_UBOOT_CONFIG=y
CONFIG_ENV_SUPPORT=y
CONFIG_ENV_IS_IN_FAT=y
CONFIG_ENV_IS_IN_MMC=y
CONFIG_ENV_FAT_INTERFACE="usb"
CONFIG_ENV_FAT_DEVICE_AND_PART="0:1"
CONFIG_ENV_FAT_FILE="uboot.env"
CONFIG_ENV_FAT_FILE_REDUND="uboot-redund.env"
CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y

Which surprisingly boots over USB, contrary to the previous post i had made earlier where these lines disabled USB detection in u-boot. The resulting booted environment then still does not seem to be correct and shows Warning: Bad CRC, using default environment.

EDIT

Investigating further, I seem to understand that CONFIG_ENV_IS_IN_FAT means to write env in the boot partition’s uboot.env and uboot-redund.env, whereas CONFIG_ENV_IS_IN_MMC means to write at the device block level with offsets, and originally for mmcblk* type devices, but somewhat overused for USB devices.

I found that a uboot-redund.env file has been created on by boot partition, but not a uboot.env file, that’s quite strange. Then modifying /etc/fw_env.config:

# cat /etc/fw_env.config 
/boot/u-boot/uboot-redund.env  0x0000     0x4000

the file is taken into account as i’ve made path mistakes that resulted in fw_printenv mentioning the file does not exist, so it does for /boot/u-boot/uboot.env as it has not been created. However the output of fw_printenv still mentions Bad CRC, using default environment.

EDIT

I found this thread to be quite informative. I think u-boot should not need to write the env to a raw device and writing to a file should be sufficient, and that works for us to write in the boot partition for now. However i can’t figure out why the env file is not getting written and why the CRC is wrong.

From the u-boot console, run mender_setup works without issues, and is supposed to write the config using saveenv. Even manually executing saveenv, does not create uboot.env on the boot partition. uboot-rendund.env is written but the CRC is incorrect. I don’t understand how that happens…

EDIT

I’ve just tested to double-check. Removed /boot/u-boot/uboot-redund.env, reboot, the file has been re-created by u-boot on startup, and the CRC is still incorrect. How is it possible that u-boot writes a file with an incorrect CRC?

EDIT

I could not find a resolution for this. To allow the device to boot, i’ve copied the output of printenv in u-boot prompt to a uEnv.txt files and executed mkenvimage to create a properly CRC checked file in the boot partition, which fw_printenv can read so that mender-client can connect. However i’m pretty sure this will not allow switching partitions from mender, as u-boot does not seem to be able to write this file. I summed up the issue here.