cwt-vf2 / archlinux-image-vf2

Build script to create Arch Linux image for VisionFive 2
MIT License
32 stars 0 forks source link

EFI boot manager: Cannot load any image #13

Closed PinkFreud closed 2 hours ago

PinkFreud commented 1 week ago

I'm having trouble trying to boot cwt22.1 on my 4GB VisionFive2.

I have the dietpi installation on the eMMC board, with standard (non-starfive) uboot installed to flash, so as was suggested in #12 , I configured the dip switches to boot from sd card.

This gives me the following:

starfive_7110_pcie pcie@2b000000: Starfive PCIe bus probed.
starfive_7110_pcie pcie@2c000000: Starfive PCIe bus probed.
In:    serial@10000000
Out:   serial@10000000
Err:   serial@10000000
Net:   eth0: ethernet@16030000, eth1: ethernet@16040000
The address of the fdt is invalid (NULL).
Hit any key to stop autoboot:  0
Trying to boot from mmc1 ...
switch to partitions #0, OK
mmc1 is current device
Scanning mmc 1:3 ...
Found U-Boot environment file /uEnv.txt
339 bytes read in 1 ms (331.1 KiB/s)
Trying to load device tree from mmc1 partition 3 ...
54960 bytes read in 6 ms (8.7 MiB/s)
Working FDT set to 48000000
Updating device tree /dtbs/starfive/jh7110-starfive-visionfive-2-v1.3b.dtb on mmc1 partition 3 ...
Updating device tree for 1500 MHz CPU speed ...
libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND
libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND
libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND
libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND
Updating device tree for 1.04V CPU voltage ...
54960 bytes written in 39 ms (1.3 MiB/s)
Found /extlinux/extlinux.conf
Unknown command 'sysboot' - try 'help'
SCRIPT FAILED: continuing ...
Working FDT set to 48000000
Loading Boot0000 'mmc 1' failed
Loading Boot0001 'mmc 0' failed
EFI boot manager: Cannot load any image

What am I missing here?

cwt commented 1 week ago

Could you show me the u-boot log from the beginning?

PinkFreud commented 1 week ago

Sorry about that! See attached.

visionfive2-arch-cwt22.1-boot.txt

cwt commented 1 week ago

What if you remove the eMMC and try booting from the SD card again?

PinkFreud commented 1 week ago

I've removed the eMMC and tried to boot off sd only, but it still fails. The only difference between boot output is this:

Earlier boot, w/ eMMC:

Updating device tree for 1.04V CPU voltage ...
54960 bytes written in 26 ms (2 MiB/s)
Found /extlinux/extlinux.conf
Unknown command 'sysboot' - try 'help'
SCRIPT FAILED: continuing ...
Working FDT set to 48000000
Loading Boot0000 'mmc 1' failed
Loading Boot0001 'mmc 0' failed
EFI boot manager: Cannot load any image
Trying to boot from usb0 ...

Second boot, with eMMC removed:

Updating device tree for 1.04V CPU voltage ...
54960 bytes written in 37 ms (1.4 MiB/s)
Found /extlinux/extlinux.conf
Unknown command 'sysboot' - try 'help'
SCRIPT FAILED: continuing ...
Working FDT set to 48000000
Card did not respond to voltage select! : -110
Loading Boot0000 'mmc 1' failed
EFI boot manager: Cannot load any image
Trying to boot from usb0 ...
cwt commented 1 week ago

This is my SD mode booting on VF2 v1.2A.

--------EEPROM INFO--------                                                                                                                                               

starfive_7110_pcie pcie@2b000000: Starfive PCIe bus probed.                                                                                                               
starfive_7110_pcie pcie@2c000000: Starfive PCIe bus probed.                                                                                                               
In:    serial@10000000                                                                                                                                                    
Out:   serial@10000000                                                                                                                                                    
Err:   serial@10000000                                                                                                                                                    
Net:   eth0: ethernet@16030000, eth1: ethernet@16040000                                                                                                                   
starting USB...                                                                                                                                                           
Bus xhci_pci: Register 5000420 NbrPorts 5                                            
Starting the controller                                                                                                                                                   
USB XHCI 1.00                                                                                                                                                             
scanning bus xhci_pci for devices... 2 USB Device(s) found                                                                                                                
       scanning usb for storage devices... 0 Storage Device(s) found                                                                                                      
Working FDT set to ff72f9b0                                                                                                                                               
Hit any key to stop autoboot:  0                                                     
Card did not respond to voltage select! : -110
** Booting bootflow 'mmc@16020000.bootdev.part_3' with extlinux
1:      Arch Linux
Retrieving file: /vmlinuz
Retrieving file: /initramfs-linux.img
append: root="LABEL=VF2" rw console=tty1 console=ttyS0,115200 earlycon rootwait stmmaceth=chain_mode:1 selinux=0 rootflags=defaults,discard=async,compress=lzo,user_subvol
_rm_allowed,subvol=@
Retrieving file: /dtbs/starfive/jh7110-starfive-visionfive-2-v1.2a.dtb
   Uncompressing Kernel Image to 0
## Flattened Device Tree blob at 46000000
   Booting using the fdt blob at 0x46000000
Working FDT set to 46000000
   Loading Ramdisk to fdf69000, end fe716c86 ... OK
   Loading Device Tree to 00000000fdf58000, end 00000000fdf6852e ... OK
Working FDT set to fdf58000

Starting kernel ...

Please notes the difference:

It's true that the mainline u-boot with its starfive_visionfive2_defconfig doesn't support sysboot command, but my extlinux.conf also doesn't execute that command.

You can check by compare my extlinux.conf with your extlinux.conf.

So I think you are using difference u-boot, or something had overwritten the u-boot partition and extlinux.conf on your SD card.

BTW, please ensure that you set the dip-switch to SD mode; the upper switch to the right side, and lower switch to the left side.

+-------------------+
|     1  0          |
|  +--------+       |
|  | [  |#] |RGPIP_1|
|  | [#|  ] |RGPIO_0|
|  +--------+       |
+-------------------+
cwt commented 1 week ago

visionfive2-arch-cwt22.1-boot.txt

U-Boot SPL 2024.04 (May 23 2024 - 05:13:07 +0000)

From the first line of your u-boot log, the date and time are indeed my u-boot package. Could you compare your extlinux.conf as I said in previous comment, and also compare your uEnv.txt with my uEnv.txt?

PinkFreud commented 1 week ago

Yes, I had the dip switches set correctly. uEnv.txt and extlinx.conf should be exactly from your image, as I just wrote your image to my sd card without any modifications.

If I change both dip switches back to 0, to enable booting from QSPI flash, I see the following output. Note the much older uboot that I have installed on here - I apparently haven't updated it in some time. This time, it successfully boots dietpi's current 6.1.97 kernel off of the eMMC.

visionfive2-dietpi-qspi-boot.txt

PinkFreud commented 1 week ago

I've also done a recursive grep for 'sysboot' over dietpi's /boot and the files on partition 3 on your image - I don't see it appearing anywhere. This is certainly weird.

PinkFreud commented 1 week ago

This gets a bit more interesting. Having exhausted my other options, I checked the qspi flash:

# for mtd in /dev/mtd?ro; do echo $mtd:; strings $mtd | grep sysboot; done
/dev/mtd0ro:
/dev/mtd1ro:
boot_extlinux=sysboot "${devtype}" "${devnum}:${bootpart}" any "${scriptaddr}" "${prefix}extlinux/extlinux.conf"
/dev/mtd2ro:
bootcmd_distro=run load_distro_uenv; run fdt_loaddtb; run fdt_sizecheck; run set_fdt_distro; sysboot ${bootdev} ${devnum}:${bootpart} fat ${scriptaddr} /${boot_syslinux_conf}; 
boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}${boot_syslinux_conf}
sysboot
/dev/mtd3ro:

It appears your uboot on the sd card is actually reading from flash for some reason.

cwt commented 1 week ago

I don't know why it reads that environment variable from mtd, which it shouldn't (or maybe it should? It may load the u-boot environment from the mtd name uboot-env?). However, since you can now boot DietPi and your U-Boot on the flash seems too old, you may consider flashing my latest U-Boot via flashcp, if that command is available on DietPi.

$ mkdir arch_u-boot
$ cd arch_u-boot
$ wget https://github.com/cwt-vf2/u-boot-starfive-vf2/releases/download/2024.07-1/u-boot-starfive-vf2-2024.07-1-riscv64.pkg.tar.zst
$ zstdcat u-boot-starfive-vf2-2024.07-1-riscv64.pkg.tar.zst | tar xvf -
.BUILDINFO
.MTREE
.PKGINFO
usr/
usr/share/
usr/share/u-boot-starfive-vf2/
usr/share/u-boot-starfive-vf2/u-boot-spl.bin.normal.out
usr/share/u-boot-starfive-vf2/u-boot.itb

You must check the MTD size and name to make sure that they are correct.

$ cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 00080000 00001000 "spl"
mtd1: 00010000 00001000 "uboot-env"
mtd2: 00400000 00001000 "uboot"
mtd3: 00a00000 00001000 "reserved-data"

And then flash u-boot-spl.bin.normal.out to mtd partition name "spl", and u-boot.itb to mtd partition name "uboot".

$ pwd 
/tmp/arch_u-boot
$ sudo flashcp -v usr/share/u-boot-starfive-vf2/u-boot-spl.bin.normal.out /dev/mtd0
$ sudo flashcp -v usr/share/u-boot-starfive-vf2/u-boot.itb /dev/mtd2

Please note that StarFive has rearranged and resized MTD partitions sometime in the past. Pay close attention to the size and name, and then choose the correct device to be flashed. If the SPL size is not equal to 00080000 or the U-Boot size is not equal to 00400000, then you may strongly consider following the standard TFTP method as in the official document, and make your board able to boot the latest Debian image first.

cwt commented 1 week ago

Hmm, maybe I will consider rebuilding my U-Boot package and adding support for the sysboot command.

Update: The new package with sysboot enabled is here: https://github.com/cwt-vf2/u-boot-starfive-vf2/releases/tag/2024.07-2

PinkFreud commented 1 week ago

I don't know why it reads that environment variable from mtd, which it shouldn't (or maybe it should? It may load the u-boot environment from the mtd name uboot-env?). However, since you can now boot DietPi and your U-Boot on the flash seems too old, you may consider flashing my latest U-Boot via flashcp, if that command is available on DietPi.

DIetPi is just a stripped-down Debian, which largely uses Debian's repos, so flashcp is certainly available, if not installed by default. I've already installed mtd-utils (which contains flashcp) on the dietpi image on here.

It looks like I have some digging through the documentation to do, though:

dev:    size   erasesize  name
mtd0: 00040000 00001000 "spl"
mtd1: 00010000 00001000 "uboot-env"
mtd2: 00300000 00001000 "uboot"
mtd3: 00100000 00001000 "data"

I'll get this updated in the next day or so and report back here whether I was able to get your Arch image booting.

Thanks!

PinkFreud commented 1 week ago

Hmmm. The latest official release from StarFive is 5.12.0: https://github.com/starfive-tech/VisionFive2/releases/

The u-boot image contained there is still 2021.10, with a newer build date (my installed image: U-Boot 2021.10 (Oct 31 2023 - 19:41:27 +0800), 5.12.0: U-Boot 2021.10 (May 09 2024 - 22:42:02 +0800)

the StarFive docs you mentioned only explain how to flash spl and u-boot through flashcp or tftp, not modify the partition size. Further, the example mtd layout they give at https://doc-en.rvspace.org/VisionFive2/Quick_Start_Guide/VisionFive2_SDK_QSG/spl_new.html matches my partition layout, while yours differs.

Do I need to further resize my mtd partitions for your image? If so, how?

cwt commented 1 week ago

It was explained in a lengthy forum thread. https://forum.rvspace.org/t/flashcp-dev-mtd0-2-11-5/2490

As I said, StarFive had resized and rearranged the mtd partitions. Somehow, their documents didn't follow suit. I wish I had a better explanation, but the mtd thing is a long story.

cwt commented 1 week ago

FYI: The MTD partition sizes and names are defined in the kernel source, specifically in the device tree. My kernel was rebuilt from StarFive's latest release, and I didn't modify the device tree. So the MTD partitions I showed you match what StarFive defined.

PinkFreud commented 1 week ago

Ahh hah, I didn't realize that. I'm guessing dietpi is using an older SF mtd config in their kernels, then.

PinkFreud commented 4 days ago

Hmm, maybe I will consider rebuilding my U-Boot package and adding support for the sysboot command.

Update: The new package with sysboot enabled is here: https://github.com/cwt-vf2/u-boot-starfive-vf2/releases/tag/2024.07-2

I was able to boot the sd image from the sdk w/o issue, but your Arch image continued to throw the same error until I installed your updated u-boot package w/ sysboot enabled and wrote the images to partitions 1 and 2 on the sd card.

Trying to boot from mmc1 ...
switch to partitions #0, OK
mmc1 is current device
Scanning mmc 1:3 ...
Found U-Boot environment file /uEnv.txt
339 bytes read in 1 ms (331.1 KiB/s)
Found /extlinux/extlinux.conf
Retrieving file: /extlinux/extlinux.conf
1:      Arch Linux
Retrieving file: /vmlinuz
Retrieving file: /initramfs-linux.img
append: root="LABEL=VF2" rw console=tty1 console=ttyS0,115200 earlycon rootwait stmmaceth=chain_mode:1 selinux=0 rootflags=defaults,discard=async,compress=
lzo,user_subvol_rm_allowed,subvol=@
Retrieving file: /dtbs/starfive/jh7110-visionfive-v2.dtb
Skipping fdtdir /dtbs/ for failure retrieving dts
   Uncompressing Kernel Image to 0
Moving Image from 0x44000000 to 0x40200000, end=41c03000
## Flattened Device Tree blob at ff72d9b0
   Booting using the fdt blob at 0xff72d9b0
Working FDT set to ff72d9b0
   Using Device Tree in place at 00000000ff72d9b0, end 00000000ff738dcf
Working FDT set to ff72d9b0

Starting kernel ...

[    0.000000] Linux version 6.6.20-cwt-5.12.0-3 (cwt@VF2-B) (gcc (GCC) 14.1.1 20240522, GNU ld (GNU Binutils) 2.42.0) #1 SMP PREEMPT_DYNAMIC Mon May 27 18:59:29 +07 2024
...
[    1.641119] Key type .fscrypt registered
[    1.645484] Key type fscrypt-provisioning registered
[    1.654024] Btrfs loaded, zoned=yes, fsverity=no
[    1.659257] AppArmor: AppArmor sha1 policy hashing enabled

It gets that far, and then hangs - or if not hung, there's simply no more output on the console.

This is certainly a lot further than this image has managed on my board so far! If you have any ideas, let me know, otherwise I'll keep poking at it to see if I can convince it to do something slightly more useful.

cwt commented 4 days ago
Retrieving file: /dtbs/starfive/jh7110-visionfive-v2.dtb
Skipping fdtdir /dtbs/ for failure retrieving dts

That is the reason why it stopped. For the board model 1.2A it should load jh7110-starfive-visionfive-2-v1.2a.dtb.

Could you check if this line existed in your uEnv.txt:

# Fix wrong fdtfile name
fdtfile=starfive/jh7110-visionfive-v2.dtb

With the new StarFive image and also my image, you must comment it out or delete it. Another alternative method is copying jh7110-starfive-visionfive-2-v1.2a.dtb to jh7110-visionfive-v2.dtb.

PinkFreud commented 4 hours ago

Sorry about that - it's been a busy few days.

The uEnv.txt I'm using is from your latest image - as such, it doesn't contain that line:

fdt_high=0xffffffffffffffff
initrd_high=0xffffffffffffffff
kernel_addr_r=0x44000000
kernel_comp_addr_r=0x90000000
kernel_comp_size=0x10000000
fdt_addr_r=0x48000000
ramdisk_addr_r=0x48100000
# Move distro to first boot to speed up booting
boot_targets=distro mmc0 dhcp 
# Fix missing bootcmd
bootcmd=run load_distro_uenv;run bootcmd_distro

These two lines:

Found U-Boot environment file /uEnv.txt
339 bytes read in 1 ms (331.1 KiB/s)

tells me we're looking at the right uEnv on the sd card, as that's the size of your uEnv.txt.

I can try renaming the dtb to -v2.dtb to see if it loads, however.

PinkFreud commented 4 hours ago

Yep, it looks like my wayward mtd strikes again:

[root@ArchVF2 user]# cat /dev/mtd1 | strings | grep -- -v2
fdtfile=starfive/jh7110-visionfive-v2.dtb

I'll need to find a way to clear those settings out of mtd1.

PinkFreud commented 2 hours ago

Fixed that last issue, at least. From within u-boot:

StarFive # env print fdtfile
fdtfile=starfive/jh7110-visionfive-v2.dtb
StarFive # env default fdtfile
StarFive # env print fdtfile
## Error: "fdtfile" not defined
StarFive # env save
Saving Environment to SPIFlash... Erasing SPI flash...Writing to SPI flash...done
OK
StarFive # reset
resetting ...

U-Boot SPL 2024.07 (Sep 10 2024 - 06:00:07 +0000)
DDR version: dc2e84f0.
Trying to boot from MMC2
...
Hit any key to stop autoboot:  0
StarFive # env print fdtfile
fdtfile=starfive/jh7110-starfive-visionfive-2-v1.3b.dtb

Anyway, thank you for your help! Arch is booting at long last on here.