u-boot setup Mender
We are using the Yocto Kirkstone branch for development. We assume that you already have a working development environment installed and set up your environment as described in VisionFive - Mender - Yocto - Part 1 and in VisionFive - Mender - Yocto - Part 2.
u-boot VisionFive board
The VisionFive RISC-V SBC use two bootloader - a secondBoot and u-boot. The mechanisms how this works are described in VisionFive SBC Quick Start Guide.
Handling these requirements means that
- we have to patch u-boot from https://github.com/starfive-tech/u-boot with settings for mender
- we have to bitbake u-boot with yocto
- we have to compile u-boot manually for upload with second stage bootloader
Patching u-boot
First, clone u-boot derivative from starfive-tech to get a code base to work with.
git clone -b JH7100_upstream https://github.com/starfive-tech/u-boot.git
Mender auto-configured patch
meta-mender-core in Yocto tries to patch u-boot automatically for Mender needs if 'MENDER_UBOOT_AUTO_CONFIGURE = "1"' is set. In most cases, this scenario doesn't work because of adjustments of the board manufacturers.
But the autoconfigured patch of Mender is a good starting point to adjust u-boot for VisionFive SOC with Mender client.
To get the autoconfigured patch, you have to bitbake u-boot with MENDER_UBOOT_AUTO_CONFIGURE = "1" setting:
bitbake u-boot-visionfive
A patch file named 'mender_auto_configured.patch' is created in the directory 'your-build-directory/tmp/work/starfive_visionfive_jh7100-poky-linux/u-boot-visionfive/1_v2022.03-r0'.
Apply patch to cloned u-boot
Next, we apply this mender_auto_configured.patch to the cloned u-boot repository from starfive-tech.
cd u-boot-starfive
git apply path-to-patch/mender_auto_configured.patch
Customize u-boot-starfive
u-boot needs to know the Mender variables to get the correct information from which partition the SOC should boot after deploying an artifact with the Mender server.
So we have to customize the file 'u-boot-starfive/include/configs/starfive-jh7100.h' to get the Mender variables and manage from which partition to boot:
#define STARLIGHT_FEDORA_BOOTENV \
"bootdir=/boot\0" \
"bootenv2=uEnv.txt\0" \
"bootenv3=uEnv3.txt\0" \
"mmcdev=0\0" \
"mmcpart=2\0"
#define CONFIG_EXTRA_ENV_SETTINGS \
MENDER_ENV_SETTINGS \
STARLIGHT_FEDORA_BOOTENV \
"loadaddr=0xa0000000\0" \
"loadbootenv=fatload ${mender_uboot_boot} ${loadaddr} ${bootenv}\0" \
"ext4bootenv2=ext4load ${mender_uboot_root} ${loadaddr} ${bootdir}/${bootenv2}\0" \
"ext4bootenv3=ext4load ${mender_uboot_root} ${loadaddr} ${bootdir}/${bootenv3}\0" \
"importbootenv=echo Importing environment from mmc mender_uboot_dev ${mender_uboot_boot} ...; " \
"env import -t ${loadaddr} ${filesize}\0" \
"mmcbootenv=run mender_setup; " \
"echo mender_kernel_root_name ${mender_kernel_root_name} ...; " \
"echo mender_boot_part_name ${mender_boot_part_name} ...; " \
"setenv bootpart ${mender_uboot_root}; " \
"mmc dev ${mender_uboot_dev}; " \
"if mmc rescan; then " \
"run loadbootenv && run importbootenv; " \
"if test ${mender_kernel_root_name} = /dev/mmcblk0p2; then " \
"run ext4bootenv2 && run importbootenv; " \
"fi; " \
"if test ${mender_kernel_root_name} = /dev/mmcblk0p3; then " \
"run ext4bootenv3 && run importbootenv; " \
"fi; " \
"if test -n $uenvcmd; then " \
"echo Running uenvcmd ...; " \
"run uenvcmd; " \
"fi; " \
"fi\0" \
"fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" \
BOOTENV \
BOOTENV_SF
Test '${mender_kernel_root_name}' is the point and then decide which uEnv-file is taken to load the kernel.
After this, create a complete patch from u-boot for using it in Yocto:
git diff --patch > ~/Documents/Yocto/meta-interelectronix-visionfive/recipes-bsp/u-boot/files/0004-u-boot.patch
Include this patch in Yocto in 'u-boot-visionfive_%.bbappend':
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI:append = " \
file://0004-u-boot.patch \
"
bitbake u-boot
In 'u-boot-visionfive_%.bbappend' change MENDER_UBOOT_AUTO_CONFIGURE = "1" to MENDER_UBOOT_AUTO_CONFIGURE = "0".
Now you can bitbake u-boot without the autoconfigure function of mender and with the custom patches:
bitbake u-boot-visionfive
Compile u-boot for upload with second stage bootloader
Now you can compile u-boot in the directory 'VisionFive-build/tmp/work/starfive_visionfive_jh7100-poky-linux/u-boot-visionfive/1_v2022.03-r0/git', which contains the patches added with 'bitbake u-boot-visionfive'.
- How to compile u-boot for VisionFive SOC is described under Compiling u-boot and Kernel
- How to upload u-boot for VisionFive SOC is described under Appendix B: Updating Firmware and u-boot
bitbake Yocto Linux
bitbake Yocto Linux with included Mender client:
bitbake vision-five-image-mender
Flash the Linux image to the SD card and boot the VisionFive SOC. If all works well, the device appears as a pending device in Mender server GUI.
Under 'DEVICES', you can accept and include it to manage deployments of later software updates for this device.
See how to create an artifact for Mender in VisionFive - Mender - Yocto - Part 4.
Copyright License
Copyright © 2022 Interelectronix e.K.
This Project source code is licensed under the GPL-3.0 license.
Part 1 of a series of articles, how to set up a Yocto environment to create a Yocto Linux with the integration of a Mender client.
Part 2 of a series of articles, how to set up a Yocto environment to create a Yocto Linux with the integration of a Mender client.
Part 4 of a series of articles, how to set up a Yocto environment to create a Yocto Linux with the integration of a Mender client.