cwt-vf2 / archlinux-image-vf2

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

cwt22.1: ERROR: Did not find a cmdline Flattened Device Tree #12

Closed gustad closed 3 months ago

gustad commented 3 months ago

This is my first attempt on booting arch on my VisionFive2. I'm able to run Deboan just fine.

First I downloaded and wrote the cwt22.1.img to a sdcard on my gentoo x86-64 desktop:

# zstd -qdcfT6 /net/pangea/media/binaries/linux/ArchLinux-VF2_6.6_v5.12.0-cwt22.1.img.zst | sha256sum -
0c77a3434be2243a682d969cc05a0f45eec7c86d846ca151920dee6f3046d4a3  -
# zstd -qdcfT6 /net/pangea/media/binaries/linux/ArchLinux-VF2_6.6_v5.12.0-cwt22.1.img.zst | dd obs=4K status=progress of=/dev/sdb
2305282048 bytes (2.3 GB, 2.1 GiB) copied, 10 s, 231 MB/s
4608000+0 records in
576000+0 records out
2359296000 bytes (2.4 GB, 2.2 GiB) copied, 58.3142 s, 40.5 MB/s
# blkid /dev/sdb*
/dev/sdb: PTUUID="2cff7c62-34c8-485c-af53-fe1e3e33dfe6" PTTYPE="gpt"
/dev/sdb1: PARTUUID="047553a1-52bf-44ae-9b1c-5799c8f983c4"
/dev/sdb2: PARTUUID="8a6f69f4-1dbc-44f8-b09a-d137c5daef27"
/dev/sdb3: SEC_TYPE="msdos" LABEL_FATBOOT="EFI" LABEL="EFI" UUID="B499-7423" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="c70c2422-0be5-4fba-94f1-862fc3c2b2e8"
/dev/sdb4: LABEL="VF2" UUID="ebae72a8-818f-49fd-81fe-b9773a145b9c" UUID_SUB="14be3e72-61e4-43de-b641-b7f3c134d04c" BLOCK_SIZE="4096" TYPE="btrfs" PARTUUID="5d72690a-f8f0-4321-847e-24cb16433a71"

Then inserted the sdcard into my VisionFive2 and booted. Is this u-boot recent enough? If not, where can I find a more recent one?

U-Boot 2021.10 (Feb 28 2023 - 21:44:53 +0800), Build: jenkins-VF2_515_Branch_SDK_Release-31

riscv64-buildroot-linux-gnu-gcc.br_real (Buildroot VF2_515_v2.11.0) 10.3.0
GNU ld (GNU Binutils) 2.36.1

Then I checked the mmc and the partition id's and they are the same as on my desktop:

StarFive # mmcinfo
Device: sdio1@16020000
Manufacturer ID: 3
OEM: 5344
Name: SD64G 
Bus Speed: 50000000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 59.4 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
StarFive # mmc part

Partition Map for MMC device 1  --   Partition Type: EFI

Part    Start LBA       End LBA         Name
        Attributes
        Type GUID
        Partition GUID
  1     0x00001000      0x00001fff      ""
        attrs:  0x0000000000000000
        type:   2e54b353-1271-4842-806f-e436d6af6985
        guid:   047553a1-52bf-44ae-9b1c-5799c8f983c4
  2     0x00002000      0x00003fff      ""
        attrs:  0x0000000000000000
        type:   5b193300-fc78-40cd-8002-e86c45580b47
        guid:   8a6f69f4-1dbc-44f8-b09a-d137c5daef27
  3     0x00004000      0x00035fff      ""
        attrs:  0x0000000000000000
        type:   c12a7328-f81f-11d2-ba4b-00a0c93ec93b
        type:   system
        guid:   c70c2422-0be5-4fba-94f1-862fc3c2b2e8
  4     0x00036000      0x004647ff      ""
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        type:   linux
        guid:   5d72690a-f8f0-4321-847e-24cb16433a71

However, when I boot I get ERROR: Did not find a cmdline Flattened Device Tree:

StarFive # boot
339 bytes read in 4 ms (82 KiB/s)
## Warning: defaulting to text format
339 bytes read in 7 ms (46.9 KiB/s)
libfdt fdt_check_header(): FDT_ERR_BADMAGIC
339 bytes written in 17 ms (18.6 KiB/s)
Retrieving file: /extlinux/extlinux.conf
520 bytes read in 7 ms (72.3 KiB/s)
1:      Arch Linux
Retrieving file: /initramfs-linux.img
8051846 bytes read in 344 ms (22.3 MiB/s)
Retrieving file: /vmlinuz
9960971 bytes read in 423 ms (22.5 MiB/s)
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/starfive_visionfive2.dtb
339 bytes read in 7 ms (46.9 KiB/s)
   Uncompressing Kernel Image
Moving Image from 0x44000000 to 0x40200000, end=41c03000
ERROR: Did not find a cmdline Flattened Device Tree
Could not find a valid device tree

I also tried to import the env as binary, but I still get the libfdt fdt_check_header(): FDT_ERR_BADMAGIC and ERROR: Did not find a cmdline Flattened Device Tree:

StarFive # env import -b ${distroloadaddr} 200
StarFive # printenv bootcmd
bootcmd=run load_distro_uenv;run bootcmd_distro
StarFive # run bootcmd_distro 
339 bytes read in 7 ms (46.9 KiB/s)
libfdt fdt_check_header(): FDT_ERR_BADMAGIC
339 bytes written in 18 ms (17.6 KiB/s)
Retrieving file: /extlinux/extlinux.conf
520 bytes read in 6 ms (84 KiB/s)
1:      Arch Linux
Retrieving file: /initramfs-linux.img
8051846 bytes read in 344 ms (22.3 MiB/s)
Retrieving file: /vmlinuz
9960971 bytes read in 423 ms (22.5 MiB/s)
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/starfive_visionfive2.dtb
339 bytes read in 7 ms (46.9 KiB/s)
   Uncompressing Kernel Image
Moving Image from 0x44000000 to 0x40200000, end=41c03000
ERROR: Did not find a cmdline Flattened Device Tree
Could not find a valid device tree

Is there a specific bootcmd which has to be used in order to boot the image (i.e. are the partition numbers wrong?), or do I simply need a more recent u-boot?

cwt commented 3 months ago

I guess you are boot from the onboard u-boot, please set DIP switches to boot from SD (0-1), it will load the u-boot directly from SD first and second partitions, then flash the mainline u-boot which is already included in the image, please follow the following instruction to flash onboard firmware:

$ sudo pacman -U /root/pkgs/u-boot-starfive-vf2-2024.04-1-riscv64.pkg.tar.zst
$ cat /proc/mtd  # please always check your mtd partition
$ 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

Then you can set the DIP switches to Flash (0-0) Screenshot from 2024-07-17 09-36-06

gustad commented 3 months ago

it will load the u-boot directly from SD first and second partitions

Ah, thanks! I was not aware of that it used it's own u-boot and environment

After writing the mentioned u-boot on to the sdcard I now get:

StarFive # version
U-Boot 2024.04 (May 23 2024 - 05:13:07 +0000)
StarFive # printenv bootcmd 
bootcmd=bootflow scan

And I'm able to log in:

[root@ArchVF2 ~]# uname -a
Linux ArchVF2 6.6.20-cwt-5.12.0-3 #1 SMP PREEMPT_DYNAMIC Mon May 27 18:59:29 +07 2024 riscv64 GNU/Linux
[root@ArchVF2 ~]# cat /etc/os-release 
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://gitlab.archlinux.org/groups/archlinux/-/issues"
PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
LOGO=archlinux-logo