cveilleux / mender-espressobin

0 stars 1 forks source link

u-boot: Set correct default env vars #2

Open cveilleux opened 2 years ago

cveilleux commented 2 years ago

The produced u-boot binary does not have the correct default environment vars.

In order to boot it is required to access the u-boot shell and enter the following commands:

run mender_setup
env set fdt_addr_r 0x6f00000
env set kernel_addr_r 0x7000000
env set bootargs rootwait
env set mender_boot_part_name /dev/mmcblk1p2
env set mender_kernel_root /dev/mmcblk1p2
env set mender_kernel_root_name /dev/mmcblk1p2
env set mender_uboot_root_name /dev/mmcblk1p2
setenv bootargs root=${mender_kernel_root} ${bootargs}

load ${mender_uboot_root} ${fdt_addr_r} /boot/${mender_dtb_name}
load ${mender_uboot_root} ${kernel_addr_r} /boot/${mender_kernel_name}
${mender_boot_kernel_type} ${kernel_addr_r} - ${fdt_addr_r}

These are notes from an old experiment. YMMV.

This should be automated somehow.

niftic commented 2 years ago

On the ESPRESSObin v7, the initial u-boot environment variables, as shown by the printenv command, are the following:

altbootcmd=run mender_altbootcmd; run bootcmd
arch=arm
baudrate=115200
board=mvebu_armada-37xx
board_name=mvebu_armada-37xx
bootcmd=run mender_setup; setenv bootargs root=${mender_kernel_root} rootwait ${bootargs}; if test "${fdt_addr_r}" != ""; then load ${mender_uboot_root} ${fdt_addr_r} /boot/${mender_dtb_name}; fi; load ${mender_uboot_root} ${kernel_addr_r} /boot/${mender_kernel_name}; ${mender_boot_kernel_type} ${kernel_addr_r} - ${fdt_addr_r}; run mender_try_to_recover
bootcount=1
bootdelay=2
bootlimit=1
cpu=armv8
fdt_addr_r=0x4f00000
fdtcontroladdr=3f61d480
kernel_addr_r=0x5000000
mender_altbootcmd=if test ${mender_boot_part} = 2; then setenv mender_boot_part 3; setenv mender_boot_part_hex 3; else setenv mender_boot_part 2; setenv mender_boot_part_hex 2; fi; setenv upgrade_available 0; saveenv; run mender_setup    
mender_boot_kernel_type=booti
mender_boot_part=2
mender_boot_part_hex=2
mender_check_saveenv_canary=1
mender_dtb_name=armada-3720-espressobin-v7-emmc.dtb
mender_kernel_name=Image
mender_saveenv_canary=1
mender_setup=if test "${mender_saveenv_canary}" != "1"; then setenv mender_saveenv_canary 1; saveenv; fi; if test "${mender_pre_setup_commands}" != ""; then run mender_pre_setup_commands; fi; if test "${mender_systemd_machine_id}" != ""; then setenv bootargs "systemd.machine_id=${mender_systemd_machine_id} ${bootargs}"; fi; setenv mender_kernel_root /dev/mmcblk0p${mender_boot_part}; if test ${mender_boot_part} = 2; then setenv mender_boot_part_name /dev/mmcblk0p2; else setenv mender_boot_part_name /dev/mmcblk0p3; fi; setenv mender_kernel_root_name ${mender_boot_part_name}; setenv mender_uboot_root mmc 0:${mender_boot_part_hex}; setenv mender_uboot_root_name ${mender_boot_part_name}; setenv expand_bootargs "setenv bootargs \\"${bootargs}\\""; run expand_bootargs; setenv expand_bootargs; if test "${mender_post_setup_commands}" != ""; then run mender_post_setup_commands; fi
mender_try_to_recover=if test ${upgrade_available} = 1; then reset; fi
mender_uboot_boot=mmc 0:1
mender_uboot_dev=0
mender_uboot_if=mmc
soc=mvebu
stderr=serial@12000
stdin=serial@12000
stdout=serial@12000
upgrade_available=0
vendor=Marvell

The bootcmd variable, which gets called on boot, already contains some of the commands required. After a few tries, I found that only the 2 commands related to the address space are necessary for a successful boot.

env set fdt_addr_r 0x6f00000
env set kernel_addr_r 0x7000000
boot

In order to automate this, we should try to indicate the correct addresses at compilation time. I found a patch, located in sources/meta-mender-espressobin/recipes-bsp/u-boot/patches-espressobin/0003-Added-fdt_addr_r-and-kernel_addr_r-to-CONFIG_EXTRA_E.patch, which sets those 2 variables to the values we see in the boot environment. I changed the patched values to yours, rebuilt the images, flashed the updated bootloader and now my device boots successfully without any intervention on the command line.

+#define CONFIG_EXTRA_ENV_SETTINGS  "fdt_addr_r=0x6f00000\0"        \
+                                   "kernel_addr_r=0x7000000"

We can now see the updated addresses with printenv in the u-boot command line or by using strings on the flash image.

strings build/tmp/deploy/images/espressobin-v7/flash-image.bin | grep -E "(fdt|kernel)_addr_r="

I didn't submit a merge request to your meta-mender-espressobin repo yet because I'm not sure if modifying a patch is the right way to go. Let me know if you see a more modular alternative.

cveilleux commented 2 years ago

Thank you. I will update the patch soon. Good to know that it is finally booting.