Starfive Visionfive Yocto Failed to boot

I have a Starfive Visionfive V1 board and try to configure an image with mender-core and u-boot.

I use Yocto kirkstone branch with

I make the setup depending on the manual-u-boot-integration Manual U-Boot integration | Mender documentation

Yocto bitbake my image without error and I get a sdimg.

I change the file starfive-jh7100.h and some other files and get a patch:

diff --git a/configs/starfive_jh7100_visionfive_smode_defconfig b/configs/starfive_jh7100_visionfive_smode_defconfig
index 4d49db8990..c73de1552f 100644
--- a/configs/starfive_jh7100_visionfive_smode_defconfig
+++ b/configs/starfive_jh7100_visionfive_smode_defconfig
@@ -4,7 +4,6 @@ CONFIG_SYS_MALLOC_F_LEN=0x3000
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_SYS_MEMTEST_START=0x80000000
 CONFIG_SYS_MEMTEST_END=0x200000000
-CONFIG_ENV_SIZE=0x1f000
 CONFIG_ENV_SECT_SIZE=0x1000
 # CONFIG_DM_GPIO is not set
 CONFIG_DEFAULT_DEVICE_TREE="jh7100-visionfive"
@@ -109,7 +108,6 @@ CONFIG_CMD_FS_UUID=y
 CONFIG_CMD_DIAG=y
 CONFIG_CMD_LOG=y
 CONFIG_ENV_OVERWRITE=y
-CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_ENV_SECT_SIZE_AUTO=y
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
 CONFIG_VERSION_VARIABLE=y
@@ -161,3 +159,39 @@ CONFIG_FS_CRAMFS=y
 CONFIG_ERRNO_STR=y
 # CONFIG_GENERATE_SMBIOS_TABLE is not set
 CONFIG_UNIT_TEST=y
+CONFIG_BMP_24BPP=y
+CONFIG_DM_VIDEO=y
+CONFIG_ENV_SIZE=0x20000
+CONFIG_ENV_OFFSET=0x800000
+CONFIG_ENV_OFFSET_REDUND=0x1000000
+CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
+CONFIG_MMC=y
+CONFIG_SYS_MMC_ENV_DEV=0
+CONFIG_SYS_MMC_ENV_PART=0
+# CONFIG_ENV_IS_NOWHERE is not set
+# CONFIG_ENV_IS_IN_EEPROM is not set
+# CONFIG_ENV_IS_IN_FAT is not set
+# CONFIG_ENV_IS_IN_EXT4 is not set
+# CONFIG_ENV_IS_IN_FLASH is not set
+# CONFIG_ENV_IS_IN_NAND is not set
+# CONFIG_ENV_IS_IN_NVRAM is not set
+# CONFIG_ENV_IS_IN_ONENAND is not set
+# CONFIG_ENV_IS_IN_REMOTE is not set
+# CONFIG_ENV_IS_IN_SPI_FLASH is not set
+# CONFIG_ENV_IS_IN_UBI is not set
+CONFIG_ENV_IS_IN_MMC=y
+CONFIG_CMD_EXT4=y
+CONFIG_CMD_FS_GENERIC=y
+# CONFIG_BOOTCOUNT_BOOTLIMIT is not set
+# CONFIG_BOOTCOUNT_GENERIC is not set
+# CONFIG_BOOTCOUNT_EXT is not set
+# CONFIG_BOOTCOUNT_AM33XX is not set
+# CONFIG_BOOTCOUNT_AM33XX_NVMEM is not set
+# CONFIG_BOOTCOUNT_RAM is not set
+# CONFIG_BOOTCOUNT_I2C is not set
+# CONFIG_BOOTCOUNT_AT91 is not set
+# CONFIG_BOOTCOUNT_MEM is not set
+# CONFIG_BOOTCOUNT_ALEN is not set
+CONFIG_BOOTCOUNT_LIMIT=y
+CONFIG_BOOTCOUNT_ENV=y
+# CONFIG_BOOTCOMMAND is not set
diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h
index 3f724aa10f..ac47d91dc5 100644
--- a/include/config_distro_bootcmd.h
+++ b/include/config_distro_bootcmd.h
@@ -499,7 +499,6 @@
 		"done\0"
 
 #ifndef CONFIG_BOOTCOMMAND
-#define CONFIG_BOOTCOMMAND "run distro_bootcmd"
 #endif
 
 #endif  /* _CONFIG_CMD_DISTRO_BOOTCMD_H */
diff --git a/include/configs/starfive-jh7100.h b/include/configs/starfive-jh7100.h
index 44ac15b9e5..582d5ce799 100644
--- a/include/configs/starfive-jh7100.h
+++ b/include/configs/starfive-jh7100.h
@@ -57,30 +57,22 @@
 
 #define STARLIGHT_FEDORA_BOOTENV \
 	"bootdir=/boot\0" \
-	"bootenv=uEnv.txt\0" \
-	"mmcdev=0\0" \
-	"mmcpart=3\0"
-
-#define STARLIGHT_TEST_BOOTENV \
-	"testpart=0:1\0" \
-	"testenv=u74_uEnv.txt\0" \
-	"mmcsetup=mmc part\0" \
-	"fdtsetup=fdt addr ${fdtcontroladdr}\0" \
-	"fatenv=fatload mmc ${testpart} ${loadaddr} ${testenv};" \
-		"env import -t ${loadaddr} ${filesize}\0"
+	"bootenv=uEnv.txt\0"
 
 #define CONFIG_EXTRA_ENV_SETTINGS \
+	MENDER_ENV_SETTINGS \
 	STARLIGHT_FEDORA_BOOTENV \
-	"loadaddr=0xa0000000\0" \
-	STARLIGHT_TEST_BOOTENV \
-	"loadbootenv=fatload mmc ${mmcdev} ${loadaddr} ${bootenv}\0" \
-	"ext4bootenv=ext4load mmc ${bootpart} ${loadaddr} ${bootdir}/${bootenv}\0" \
-	"importbootenv=echo Importing environment from mmc${mmcdev} ...; " \
+	"kernel_addr_r=0xa0000000\0" \
+	"loadbootenv=fatload ${mender_uboot_boot} ${loadaddr} ${bootenv}\0" \
+	"ext4bootenv=ext4load ${mender_uboot_root} ${loadaddr} ${bootdir}/${bootenv}\0" \
+	"loadfdt=ext4load ${mender_uboot_root} ${fdtaddr} ${bootdir}/${fdtfile}\0" \
+	"importbootenv=echo Importing environment from mmc mender_uboot_dev ${mender_uboot_dev} ...; " \
 		"env import -t ${loadaddr} ${filesize}\0" \
-	"mmcbootenv=setenv bootpart ${mmcdev}:${mmcpart}; " \
-		"mmc dev ${mmcdev}; " \
+	"mmcbootenv=setenv bootpart ${mender_uboot_root}; " \
+		"mmc dev ${mender_uboot_dev}; " \
+		"setenv devnum ${mender_uboot_dev}; " \
 		"if mmc rescan; then " \
-			"run loadbootenv && run importbootenv; " \
+			"run loadbootenv && run importbootenv && run loadfdt; " \
 			"run ext4bootenv && run importbootenv; " \
 			"if test -n $uenvcmd; then " \
 				"echo Running uenvcmd ...; " \
diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt
index b9c1c61e13..657ca09a73 100644
--- a/scripts/config_whitelist.txt
+++ b/scripts/config_whitelist.txt
@@ -1205,6 +1205,13 @@ CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE
 CONFIG_SSE2
 CONFIG_STACKBASE
 CONFIG_STANDALONE_LOAD_ADDR
+CONFIG_STARFIVE_EEPROM_ATOM1_PSTR
+CONFIG_STARFIVE_EEPROM_ATOM1_PSTR_SIZE
+CONFIG_STARFIVE_EEPROM_ATOM1_SN_OFFSET
+CONFIG_STARFIVE_EEPROM_ATOM1_VSTR
+CONFIG_STARFIVE_EEPROM_ATOM1_VSTR_SIZE
+CONFIG_STARFIVE_EEPROM_HATS_SIZE_MAX
+CONFIG_STARFIVE_EEPROM_WP_OFFSET
 CONFIG_STATIC_BOARD_REV
 CONFIG_STD_DEVICES_SETTINGS
 CONFIG_SXNI855T

If I boot the board from the SDCard I get the following error:

U-Boot 2022.01-rc4-VisionFive-g0c08d335c5 (Dec 30 2021 - 08:30:15 +0800)StarFive

CPU:   rv64imafdc
Model: StarFive VisionFive V1
DRAM:  8 GiB
MMC:   mmc@10000000: 0, mmc@10010000: 1
Loading Environment from SPIFlash... cadence_spi spi@11860000: Can't get reset: -524
SF: Detected gd25lq128 with page size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

StarFive EEPROM format v1

--------EEPROM INFO--------
Vendor : StarFive Technology Co., Ltd.
Product full SN: VF7100A1-2204-D008E000-000000F7
data version: 0x1
PCB revision: 0x1
BOM revision: A
Ethernet MAC address: 6c:cf:39:00:00:f6
--------EEPROM INFO--------

In:    serial@12440000
Out:   serial@12440000
Err:   serial@12440000
Net:   dwmac.10020000
MMC CD is 0x0, force to True.
MMC CD is 0x0, force to True.
switch to partitions #0, OK
mmc0 is current device
MMC CD is 0x0, force to True.
MMC CD is 0x0, force to True.
654 bytes read in 20 ms (31.3 KiB/s)
Importing environment from mmc0 ...
Failed to load '/boot/uEnv.txt'
Autoboot in 2 seconds
** Bad device specification 0x84000000 boot/Image **
Couldn't find partition 0x84000000 boot/Image.gz
Can't set block device
** Bad device specification 0x88000000 boot/jh7100-starfive-visionfive-v1 **
Couldn't find partition 0x88000000 boot/jh7100-starfive-visionfive-v1.dtb
Can't set block device
Bad Linux RISCV Image magic!

Can someone give me any hints to solve the problem?

Some additions to the origin post.
After doing some testing and research it seems to be, that the patch of the file starfive-jh7100.h is not applied?
If I type ‘printenv testenv’ in the u-boot prompt, I get ‘testenv=u74_uEnv.txt’ which I removed in the patch.

Also ‘printenv loadbootenv’ shows

loadbootenv=fatload mmc ${mmcdev} ${loadaddr} ${bootenv}

and not

loadbootenv=fatload ${mender_uboot_dev} ${loadaddr} ${bootenv}

as changed in the patch.

Hi @walterp,

Thanks for reaching out! I am (somewhat) also working on the RISC-V integrations, so I’m very interested. Concerning the patch application:

  • where did you make those changes?
  • did you format them out into a .patch file and add it to SRC_URI of the u-boot recipe, usually through a .bbappend?
  • alternatively, you can do devtool modify for the time of development, and build from an extracted source tree.

I guess that your modifications are right, just not picked up due to the Yocto build flow.

Greetz,
Josef

Hi @TheYoctoJester
I’m doing the following sequences:

  • clone the Starfive u-boot repository mentioned above
  • create the mender_auto_configured.patch and apply it to the Starfive u-boot repository
  • add my custom configurations in starfive-jh7100.h in the section CONFIG_EXTRA_ENV_SETTINGS
  • create a patch file and add this patch file to my u-boot-visionfive_%.bbappend

The patch seems to be set in the WORKDIR/git/include/configs/starfive-jh7100.h file.

But if I boot with the flashed SD-Card I can’t see the changed environment settings in the U-Boot prompt.
Kindly regards
Walter

Its a long shot, as I don’t know the Starfive board, but - are you sure that the u-boot from the SD card is used? Some boards always use the internal one first, and the log supports this theory:

U-Boot 2022.01-rc4-VisionFive-g0c08d335c5 (Dec 30 2021 - 08:30:15 +0800)StarFive

At least presuming that your build box is not set to Dec 30 2021 right now.

Yes, you are right. The U-boot is on the SoC and can be updated via serial console and xmodem.

@walterp so does it work now? If not, what is missing? If yes, can I encourage you to submit the board integration to meta-mender-community, respectively share the steps here? In case polishing the content is too time consuming, then I can help with that.

Greetz,
Josef

Not yet. A short interim result of what I’m doing.

MACHINE_ESSENTIAL_EXTRA_RDEPENDS:append = " kernel-image kernel-devicetree"
IMAGE_BOOT_FILES:append = " uEnv.txt"
  • bitbake myimage
  • flash SD-card

Now I get the following message
Failed to load '/boot/uEnv.txt'
but the board begins to boot the kernel and the device tree but hang after a few seconds.

I think, it’s because of missing the uEnv.txt file in the rootfs partitions in the ‘boot’ directory.

All efforts to install ‘uEnv.txt’ failed so far.

I solved the problem with the Failed to load '/boot/uEnv.txt' with a custom recipe ‘u-boot-env’. In this recipe I copied the file ‘uEnv_visionfive.txt’ file to the boot directory in the rootfs.
Now the system boots correct.

Unfortunately the mender variables, e.g. mender_uboot_root, are not recognized and ‘root=/dev//mmcblk0p2’ is hard coded.

How can I use the mender variables in the uEnv.txt file in the boot directory?