Booting FreeBSD on the RISC-V VisionFive2

The VisionFive 2 is a RISC-V based single board computer from Starfive integrating their JH7110 SoC. The board is available from Waveshare on its own or with some handy components to get you started.

The SoC is pitched to be a competitor to the RaspberryPi 4 in specs and along with oodles of interfaces it has a raspberrypi compatible 40 pin header exposing pins for io.

The SoC is also in the Star64 and PinetabV from Pine64 (I didn't know that the StarFive was for sale until checking when writing this).

StarFive is a Chinese integrator using IP blocks from SiFive and so it integrates cores and peripherals from the HiFive Unleashed board.

I picked one of these up to play with FreeBSD/RISC-V on a computer with a real MMU. Before doing anything I wanted to be sure that I could get Linux to boot on the board. I sort of followed the instructions from the [Waveshare wiki page][wavesharewiki], ignoring the Windows GUI tools and using dd and cu to write the image and connect to serial.

With an SD card image with their published I powered up the board and tried to connect. The wiki instructions highlight that you need to break into the boot loader during boot and manually load segments from the SD card. I tried this for about an hour or two with 3 different images (the 69 image took 40 minutes to write to the SD card), but I didn't have any luck.

Giving up I just let the u-boot run and got a booting Debian system immediately:

U-Boot 2021.10 (Feb 12 2023 - 18:15:33 +0800), Build: jenkins-VF2_515_Branch_SDK_Release-24

CPU:   rv64imacu
Model: StarFive VisionFive V2
DRAM:  8 GiB
MMC:   sdio0@16010000: 0, sdio1@16020000: 1
Loading Environment from SPIFlash... SF: Detected gd25lq128 with page size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

StarFive EEPROM format v2

--------EEPROM INFO--------
Vendor : StarFive Technology Co., Ltd.
Product full SN: VF7110B1-2253-D008E000-00004015
data version: 0x2
PCB revision: 0xb2
BOM revision: A
Ethernet MAC0 address: 6c:cf:39:00:42:ba
Ethernet MAC1 address: 6c:cf:39:00:42:bb
--------EEPROM INFO--------

In:    serial@10000000
Out:   serial@10000000
Err:   serial@10000000
Model: StarFive VisionFive V2
Net:   eth0: ethernet@16030000, eth1: ethernet@16040000
switch to partitions #0, OK
mmc1 is current device
found device 1
bootmode flash device 1
385 bytes read in 6 ms (62.5 KiB/s)
Importing environment from mmc1 ...
Can't set block device
Hit any key to stop autoboot:  0
Can't set block device
libfdt fdt_check_header(): FDT_ERR_BADMAGIC
Retrieving file: /boot/extlinux/extlinux.conf
Can't set block device
Error reading config file
StarFive #
StarFive #
U-Boot SPL 2021.10 (Feb 12 2023 - 18:15:33 +0800)
DDR version: dc2e84f0.
Trying to boot from SPI

OpenSBI v1.2
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : StarFive VisionFive V2
Platform Features         : medeleg
Platform HART Count       : 5
Platform IPI Device       : aclint-mswi
Platform Timer Device     : aclint-mtimer @ 4000000Hz
Platform Console Device   : uart8250
Platform HSM Device       : jh7110-hsm
Platform PMU Device       : ---
Platform Reboot Device    : pm-reset
Platform Shutdown Device  : pm-reset
Firmware Base             : 0x40000000
Firmware Size             : 292 KB
Runtime SBI Version       : 1.0

Domain0 Name              : root
Domain0 Boot HART         : 1
Domain0 HARTs             : 0*,1*,2*,3*,4*
Domain0 Region00          : 0x0000000002000000-0x000000000200ffff (I)
Domain0 Region01          : 0x0000000040000000-0x000000004007ffff ()
Domain0 Region02          : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address      : 0x0000000040200000
Domain0 Next Arg1         : 0x0000000042200000
Domain0 Next Mode         : S-mode
Domain0 SysReset          : yes

Boot HART ID              : 1
Boot HART Domain          : root
Boot HART Priv Version    : v1.11
Boot HART Base ISA        : rv64imafdcbx
Boot HART ISA Extensions  : none
Boot HART PMP Count       : 8
Boot HART PMP Granularity : 4096
Boot HART PMP Address Bits: 34
Boot HART MHPM Count      : 2
Boot HART MIDELEG         : 0x0000000000000222
Boot HART MEDELEG         : 0x000000000000b109


U-Boot 2021.10 (Feb 12 2023 - 18:15:33 +0800), Build: jenkins-VF2_515_Branch_SDK_Release-24

CPU:   rv64imacu
Model: StarFive VisionFive V2
DRAM:  8 GiB
MMC:   sdio0@16010000: 0, sdio1@16020000: 1
Loading Environment from SPIFlash... SF: Detected gd25lq128 with page size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

StarFive EEPROM format v2

--------EEPROM INFO--------
Vendor : StarFive Technology Co., Ltd.
Product full SN: VF7110B1-2253-D008E000-00004015
data version: 0x2
PCB revision: 0xb2
BOM revision: A
Ethernet MAC0 address: 6c:cf:39:00:42:ba
Ethernet MAC1 address: 6c:cf:39:00:42:bb
--------EEPROM INFO--------

In:    serial@10000000
Out:   serial@10000000
Err:   serial@10000000
Model: StarFive VisionFive V2
Net:   eth0: ethernet@16030000, eth1: ethernet@16040000
switch to partitions #0, OK
mmc1 is current device
found device 1
bootmode flash device 1
Can't set block device
Failed to load '/boot/uEnv.txt'
Hit any key to stop autoboot:  0
Can't set block device
Importing environment from mmc1 ...
## Warning: Input data exceeds 1048576 bytes - truncated
## Info: input data size = 1048578 = 0x100002
385 bytes read in 6 ms (62.5 KiB/s)
## Warning: defaulting to text format
## Error: "boot2" not defined
47546 bytes read in 13 ms (3.5 MiB/s)
47546 bytes written in 563 ms (82 KiB/s)
Retrieving file: /boot/extlinux/extlinux.conf
823 bytes read in 10 ms (80.1 KiB/s)
U-Boot menu
1:  Debian GNU/Linux bookworm/sid 5.15.0-starfive
2:  Debian GNU/Linux bookworm/sid 5.15.0-starfive (rescue target)
Enter choice: 1:    Debian GNU/Linux bookworm/sid 5.15.0-starfive
Retrieving file: /boot/initrd.img-5.15.0-starfive
9684953 bytes read in 421 ms (21.9 MiB/s)
Retrieving file: /boot/vmlinuz-5.15.0-starfive
8015200 bytes read in 348 ms (22 MiB/s)
append: root=/dev/mmcblk1p3 rw console=tty0 console=ttyS0,115200 earlycon rootwait stmmaceth=chain_mode:1 selinux=0
Retrieving file: /boot/dtbs/starfive/jh7110-visionfive-v2.dtb
47546 bytes read in 13 ms (3.5 MiB/s)
   Uncompressing Kernel Image
Moving Image from 0x44000000 to 0x40200000, end=41767000
## Flattened Device Tree blob at 48000000
   Booting using the fdt blob at 0x48000000
   Using Device Tree in place at 0000000048000000, end 000000004800e9b9

Starting kernel ...

clk u5_dw_i2c_clk_core already disabled
clk u5_dw_i2c_clk_apb already disabled
[    0.000000] Linux version 5.15.0-starfive (sw_buildbot@mdcsw02) (riscv64-unknown-linux-gnu-gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.35) #1 SMP Mon Dec 19 07:56:37 EST 2022
[    0.000000] OF: fdt: Ignoring memory range 0x40000000 - 0x40200000
[    0.000000] Machine model: StarFive VisionFive V2
[    0.000000] earlycon: uart0 at MMIO32 0x0000000010000000 (options '115200')
[    0.000000] printk: bootconsole [uart0] enabled
[    0.000000] efi: UEFI not found.
[    0.000000] Reserved memory: created CMA memory pool at 0x0000000080000000, size 512 MiB
[    0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000040200000-0x00000000ffffffff]
[    0.000000]   Normal   [mem 0x0000000100000000-0x000000023fffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000040200000-0x00000000c010ffff]
[    0.000000]   node   0: [mem 0x00000000c0110000-0x00000000c01fffff]
[    0.000000]   node   0: [mem 0x00000000c0200000-0x000000023fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000040200000-0x000000023fffffff]
[    0.000000] SBI specification v1.0 detected
[    0.000000] SBI implementation ID=0x1 Version=0x10002
[    0.000000] SBI TIME extension detected
[    0.000000] SBI IPI extension detected
[    0.000000] SBI RFENCE extension detected
[    0.000000] SBI SRST extension detected
[    0.000000] SBI v0.2 HSM extension detected
[    0.000000] CPU with hartid=0 is not available
[    0.000000] CPU with hartid=0 is not available
[    0.000000] riscv: ISA extensions acdfim
[    0.000000] riscv: ELF capabilities acdfim
[    0.000000] percpu: Embedded 17 pages/cpu s31528 r8192 d29912 u69632
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 2067975
[    0.000000] Kernel command line: root=/dev/mmcblk1p3 rw console=tty0 console=ttyS0,115200 earlycon rootwait stmmaceth=chain_mode:1 selinux=0
[    0.000000] Unknown command line parameters: stmmaceth=chain_mode:1 selinux=0
[    0.000000] Dentry cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.000000] Inode-cache hash table entries: 524288 (order: 10, 4194304 bytes, linear)
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] software IO TLB: mapped [mem 0x00000000fbfff000-0x00000000fffff000] (64MB)
[    0.000000] Memory: 7582168K/8386560K available (9884K kernel code, 4982K rwdata, 4096K rodata, 2191K init, 401K bss, 280104K reserved, 524288K cma-reserved)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] rcu: Hierarchical RCU implementation.
[    0.000000] rcu:     RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.
[    0.000000] rcu:     RCU debug extended QS entry/exit.
[    0.000000]  Tracing variant of Tasks RCU enabled.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000] CPU with hartid=0 is not available
[    0.000000] riscv-intc: unable to find hart id for /cpus/cpu@0/interrupt-controller
[    0.000000] riscv-intc: 64 local interrupts mapped
[    0.000000] plic: plic@c000000: mapped 136 interrupts with 4 handlers for 9 contexts.
[    0.000000] random: get_random_bytes called from start_kernel+0x4d0/0x6e2 with crng_init=0
[    0.000000] riscv_timer_init_dt: Registering clocksource cpuid [0] hartid [1]
[    0.000000] clocksource: riscv_clocksource: mask: 0xffffffffffffffff max_cycles: 0x1d854df40, max_idle_ns: 881590404240 ns
[    0.000001] sched_clock: 64 bits at 4MHz, resolution 250ns, wraps every 2199023255500ns
[    0.009005] clocksource: timer@13050000.ch0: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[    0.020330] clocksource: timer@13050000.ch1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[    0.031662] clocksource: timer@13050000.ch2: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[    0.042988] clocksource: timer@13050000.ch3: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[    0.054477] Console: colour dummy device 80x25
[    0.060704] printk: console [tty0] enabled
[    0.065259] Calibrating delay loop (skipped), value calculated using timer frequency.. 8.00 BogoMIPS (lpj=40000)
[    0.076482] pid_max: default: 32768 minimum: 301
[    0.081782] Mount-cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
[    0.090298] Mountpoint-cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
[    0.100574] ASID allocator disabled
[    0.104515] rcu: Hierarchical SRCU implementation.
[    0.109965] EFI services will not be available.
[    0.115349] smp: Bringing up secondary CPUs ...
[    0.121954] smp: Brought up 1 node, 4 CPUs
[    0.128390] devtmpfs: initialized
[    0.139598] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.150460] futex hash table entries: 1024 (order: 4, 65536 bytes, linear)
[    0.171957] pinctrl core: initialized pinctrl subsystem
[    0.178604] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.185824] cpuidle: using governor menu
[    0.212080] platform soc:dsi-output: Fixing up cyclic dependency with 29400000.dc8200
[    0.221266] platform 295d0000.mipi: Fixing up cyclic dependency with soc:dsi-output
[    0.230103] platform 29590000.hdmi: Fixing up cyclic dependency with 29400000.dc8200
[    0.250583] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[    0.257968] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[    0.268496] vgaarb: loaded
[    0.271719] SCSI subsystem initialized
[    0.276289] usbcore: registered new interface driver usbfs
[    0.282365] usbcore: registered new interface driver hub
[    0.288257] usbcore: registered new device driver usb
[    0.294100] mc: Linux media interface: v0.10
[    0.298849] videodev: Linux video capture interface: v2.00
[    0.305076] Advanced Linux Sound Architecture Driver Initialized.
[    0.312174] Bluetooth: Core ver 2.22
[    0.316137] NET: Registered PF_BLUETOOTH protocol family
[    0.321995] Bluetooth: HCI device and connection manager initialized
[    0.328993] Bluetooth: HCI socket layer initialized
[    0.334376] Bluetooth: L2CAP socket layer initialized
[    0.339947] Bluetooth: SCO socket layer initialized
[    0.345655] clocksource: Switched to clocksource riscv_clocksource
[    0.359945] NET: Registered PF_INET protocol family
[    0.366328] IP idents hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.382150] tcp_listen_portaddr_hash hash table entries: 4096 (order: 5, 163840 bytes, linear)
[    0.391902] TCP established hash table entries: 65536 (order: 7, 524288 bytes, linear)
[    0.401467] TCP bind hash table entries: 65536 (order: 9, 2097152 bytes, linear)
[    0.411645] TCP: Hash tables configured (established 65536 bind 65536)
[    0.419151] UDP hash table entries: 4096 (order: 6, 393216 bytes, linear)
[    0.427156] UDP-Lite hash table entries: 4096 (order: 6, 393216 bytes, linear)
[    0.435832] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.442719] RPC: Registered named UNIX socket transport module.
[    0.449269] RPC: Registered udp transport module.
[    0.454444] RPC: Registered tcp transport module.
[    0.459629] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.467439] PCI: CLS 0 bytes, default 64
[    0.472432] Initialise system trusted keyrings
[    0.477573] workingset: timestamp_bits=62 max_order=21 bucket_order=0
[    0.477763] Unpacking initramfs...
[    0.490491] NFS: Registering the id_resolver key type
[    0.496101] Key type id_resolver registered
[    0.500717] Key type id_legacy registered
[    0.505234] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.512649] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.520870] ntfs: driver 2.1.32 [Flags: R/W].
[    0.525964] jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
[    0.533157] fuse: init (API version 7.34)
[    0.577419] NET: Registered PF_ALG protocol family
[    0.582730] Key type asymmetric registered
[    0.587294] Asymmetric key parser 'x509' registered
[    0.592771] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 249)
[    0.600969] io scheduler mq-deadline registered
[    0.605983] io scheduler kyber registered
[    0.712788] clk-starfive-jh7110 13020000.clock-controller: starfive JH7110 clkgen init successfully.
[    0.724053] L2CACHE: DataError @ 0x00000000.08040140
[    0.729629] L2CACHE: DataFail @ 0x00000000.0804006C
[    0.735093] L2CACHE: No. of Banks in the cache: 8
[    0.740308] L2CACHE: No. of ways per bank: 16
[    0.745115] L2CACHE: Sets per bank: 256
[    0.749369] L2CACHE: Bytes per cache block: 64
[    0.754279] L2CACHE: Index of the largest way enabled: 15
[    0.760564] jh7110-pmu 17030000.power-controller: registered 8 power domains
[    0.828245] Serial: 8250/16550 driver, 6 ports, IRQ sharing disabled
[    0.838268] @@#########################@@
[    0.880540] @@ dev ptr:ffffffe0bff00000/1500/1
[    0.885723] PVR_K:  1: Read BVNC 36.50.54.182 from HW device registers
[    0.893003] PVR_K:  1: RGX Device registered BVNC 36.50.54.182 with 1 core in the system
[    0.903216] [drm] Initialized pvr 1.17.6210866 20170530 for 18000000.gpu on minor 0
[    0.924159] loop: module loaded
[    0.930154] spi-nor spi0.0: gd25lq128d (16384 Kbytes)
[    1.191214] Freeing initrd memory: 9456K
[    1.212281] 3 fixed-partitions partitions found on MTD device 13010000.spi.0
[    1.220111] Creating 3 MTD partitions on "13010000.spi.0":
[    1.226190] 0x000000000000-0x000000020000 : "spl"
[    1.233161] 0x000000100000-0x000000400000 : "uboot"
[    1.240125] 0x000000f00000-0x000001000000 : "data"
[    1.248093] libphy: Fixed MDIO Bus: probed
[    1.254081] CAN device driver interface
[    1.258941] starfive-eth-plat 16030000.ethernet: force_sf_dma_mode is ignored if force_thresh_dma_mode is set.
[    1.270362] starfive-eth-plat 16030000.ethernet: User ID: 0x41, Synopsys ID: 0x52
[    1.278643] starfive-eth-plat 16030000.ethernet:     DWMAC4/5
[    1.284695] starfive-eth-plat 16030000.ethernet: DMA HW capability register supported
[    1.293336] starfive-eth-plat 16030000.ethernet: RX Checksum Offload Engine supported
[    1.301978] starfive-eth-plat 16030000.ethernet: Wake-Up On Lan supported
[    1.309464] starfive-eth-plat 16030000.ethernet: TSO supported
[    1.315906] starfive-eth-plat 16030000.ethernet: Enable RX Mitigation via HW Watchdog Timer
[    1.325125] starfive-eth-plat 16030000.ethernet: Enabled Flow TC (entries=1)
[    1.332900] starfive-eth-plat 16030000.ethernet: TSO feature enabled
[    1.339913] starfive-eth-plat 16030000.ethernet: Using 40 bits DMA width
[    1.598015] libphy: stmmac: probed
[    1.601791] YT8531 Gigabit Ethernet stmmac-0:00: attached PHY driver (mii_bus:phy_addr=stmmac-0:00, irq=POLL)
[    1.612755] YT8531 Gigabit Ethernet stmmac-0:01: attached PHY driver (mii_bus:phy_addr=stmmac-0:01, irq=POLL)
[    1.624914] starfive-eth-plat 16040000.ethernet: force_sf_dma_mode is ignored if force_thresh_dma_mode is set.
[    1.636328] starfive-eth-plat 16040000.ethernet: User ID: 0x41, Synopsys ID: 0x52
[    1.644586] starfive-eth-plat 16040000.ethernet:     DWMAC4/5
[    1.650657] starfive-eth-plat 16040000.ethernet: DMA HW capability register supported
[    1.659300] starfive-eth-plat 16040000.ethernet: RX Checksum Offload Engine supported
[    1.667947] starfive-eth-plat 16040000.ethernet: Wake-Up On Lan supported
[    1.675420] starfive-eth-plat 16040000.ethernet: TSO supported
[    1.681863] starfive-eth-plat 16040000.ethernet: Enable RX Mitigation via HW Watchdog Timer
[    1.691113] starfive-eth-plat 16040000.ethernet: Enabled Flow TC (entries=1)
[    1.698891] starfive-eth-plat 16040000.ethernet: TSO feature enabled
[    1.705903] starfive-eth-plat 16040000.ethernet: Using 40 bits DMA width
[    1.962922] libphy: stmmac: probed
[    1.966737] YT8531 Gigabit Ethernet stmmac-1:00: attached PHY driver (mii_bus:phy_addr=stmmac-1:00, irq=POLL)
[    1.977684] YT8531 Gigabit Ethernet stmmac-1:01: attached PHY driver (mii_bus:phy_addr=stmmac-1:01, irq=POLL)
[    1.990177] Intel(R) Wireless WiFi driver for Linux
[    1.997530] cdns3-starfive 10210000.usbdrd: usb mode 2 2.0 probe success
[    2.005728] usbcore: registered new interface driver uas
[    2.011632] usbcore: registered new interface driver usb-storage
[    2.035993] starfive-rtc 17040000.rtc: registered as rtc0
[    2.041959] starfive-rtc 17040000.rtc: setting system clock to 2001-01-01T00:00:00 UTC (978307200)
[    2.052010] i2c_dev: i2c /dev entries driver
[    2.056986] usbcore: registered new interface driver uvcvideo
[    2.064494] starfive-wdt 13070000.wdog: Heartbeat: timeout=15, count/2=180000000 (0aba9500)
[    2.074249] Bluetooth: HCI UART driver ver 2.3
[    2.079178] Bluetooth: HCI UART protocol H4 registered
[    2.085056] starfive-cpufreq soc:starfive,jh7110-cpufreq: Failed to get regulator for cpu!
[    2.094201] starfive-cpufreq soc:starfive,jh7110-cpufreq: Failed to init starfive cpu dvfs info
[    2.104367] sdhci: Secure Digital Host Controller Interface driver
[    2.111207] sdhci: Copyright(c) Pierre Ossman
[    2.116050] Synopsys Designware Multimedia Card Interface Driver
[    2.122972] sdhci-pltfm: SDHCI platform and OF driver helper
[    2.130039] jh7110-sec 16000000.crypto: Unable to request sec_m dma channel in DMA channel
[    2.139189] jh7110-sec 16000000.crypto: Cannot initial dma chan
[    2.146014] usbcore: registered new interface driver usbhid
[    2.152166] usbhid: USB HID core driver
[    2.156657] usbcore: registered new interface driver snd-usb-audio
[    2.172080] NET: Registered PF_PACKET protocol family
[    2.177724] can: controller area network core
[    2.182629] NET: Registered PF_CAN protocol family
[    2.187939] can: raw protocol
[    2.191215] can: broadcast manager protocol
[    2.195856] can: netlink gateway - max_hops=1
[    2.200998] Bluetooth: RFCOMM TTY layer initialized
[    2.206424] Bluetooth: RFCOMM socket layer initialized
[    2.212118] Bluetooth: RFCOMM ver 1.11
[    2.216311] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    2.222169] Bluetooth: BNEP filters: protocol multicast
[    2.227956] Bluetooth: BNEP socket layer initialized
[    2.233611] 9pnet: Installing 9P2000 support
[    2.238405] Key type dns_resolver registered
[    2.243868] Loading compiled-in X.509 certificates
[    2.285477] starfive_jh7110-pinctrl 13040000.gpio: SiFive GPIO chip registered 64 GPIOs
[    2.295094] starfive_jh7110-pinctrl 17020000.gpio: SiFive GPIO chip registered 4 GPIOs
[    2.304078] pl08xdmac 16008000.sec_dma: initialized 8 virtual memcpy channels
[    2.311992] pl08xdmac 16008000.sec_dma: initialized 16 virtual slave channels
[    2.321510] debugfs: Directory '16008000.sec_dma' with parent 'dmaengine' already present!
[    2.330687] pl08xdmac 16008000.sec_dma: DMA: PL080 rev0 at 0x16008000 irq 23
[    2.338771] ssp-pl022 10060000.spi: ARM PL022 driver for StarFive SoC platform, device ID: 0x00041022
[    2.348977] ssp-pl022 10060000.spi: mapped registers from 0x0000000010060000 to (____ptrval____)
[    2.359120] ssp-pl022 10060000.spi: Requested frequency: 10000000 Hz is unsupported,select by default 8250000 Hz
[    2.370741] ssp-pl022 10060000.spi: will use autosuspend for runtime pm, delay 100ms
[    2.380629] i2c 2-0045: Fixing up cyclic dependency with 295d0000.mipi
[    2.388122] seeed_panel 2-0045: Unknown Atmel firmware revision: 0x00
[    2.395431] i2c 2-0019: Fixing up cyclic dependency with 295d0000.mipi
[    2.404073] at24 5-0050: supply vcc not found, using dummy regulator
[    2.411894] at24 5-0050: 512 byte 24c04 EEPROM, writable, 16 bytes/write
[    2.421270] axp15060-regulator 5-0036: Register mipi_0p9 done! vol range:900 ~ 900 mV
[    2.431418] axp15060-regulator 5-0036: Register hdmi_1p8 done! vol range:1800 ~ 1800 mV
[    2.441765] axp15060-regulator 5-0036: Register hdmi_0p9 done! vol range:900 ~ 900 mV
[    2.451931] axp15060-regulator 5-0036: Register cpu_vdd done! vol range:500 ~ 1540 mV
[    2.461375] i2c 6-0010: Fixing up cyclic dependency with 19800000.vin_sysctl
[    2.469570] imx219 6-0010: supply VANA not found, using dummy regulator
[    2.477029] imx219 6-0010: supply VDIG not found, using dummy regulator
[    2.484377] imx219 6-0010: supply VDDL not found, using dummy regulator
[    2.499168] imx219 6-0010: failed to read chip id 219
[    2.504953] imx219: probe of 6-0010 failed with error -5
[    2.513417] pcie_plda 2b000000.pcie: host bridge /soc/pcie@2B000000 ranges:
[    2.521191] pcie_plda 2b000000.pcie:      MEM 0x0030000000..0x0037ffffff -> 0x0030000000
[    2.530144] pcie_plda 2b000000.pcie:      MEM 0x0900000000..0x093fffffff -> 0x0900000000
[    2.539130] ATR entry: 0x0940000000 -> 0x0000000000 [0x0010000000] (param: 0x000001)
[    2.547698] ATR entry: 0x0030000000 -> 0x0030000000 [0x0008000000] (param: 0x000000)
[    2.556265] ATR entry: 0x0900000000 -> 0x0900000000 [0x0040000000] (param: 0x000000)
[    2.905756] pcie_plda 2b000000.pcie: Port link up.
[    2.911202] pcie_plda 2b000000.pcie: PCI host bridge to bus 0000:00
[    2.918138] pci_bus 0000:00: root bus resource [bus 00-ff]
[    2.924191] pci_bus 0000:00: root bus resource [mem 0x30000000-0x37ffffff]
[    2.931793] pci_bus 0000:00: root bus resource [mem 0x900000000-0x93fffffff pref]
[    2.940084] pci 0000:00:00.0: [1556:1111] type 01 class 0x060400
[    2.946728] pci 0000:00:00.0: reg 0x10: [mem 0x00000000-0xffffffff 64bit pref]
[    2.954755] pci 0000:00:00.0: supports D1 D2
[    2.959479] pci 0000:00:00.0: PME# supported from D0 D1 D2 D3hot D3cold
[    2.970356] pci 0000:00:00.0: bridge configuration invalid ([bus 00-00]), reconfiguring
[    2.979343] pci 0000:01:00.0: [1106:3483] type 00 class 0x0c0330
[    2.986000] pci 0000:01:00.0: reg 0x10: [mem 0x00000000-0x00000fff 64bit]
[    2.993564] pci 0000:01:00.0: PME# supported from D0 D3cold
[    3.003108] pci_bus 0000:01: busn_res: [bus 01-ff] end is updated to 01
[    3.010448] pci 0000:00:00.0: BAR 0: no space for [mem size 0x100000000 64bit pref]
[    3.018918] pci 0000:00:00.0: BAR 0: failed to assign [mem size 0x100000000 64bit pref]
[    3.027773] pci 0000:00:00.0: BAR 8: assigned [mem 0x30000000-0x300fffff]
[    3.035257] pci 0000:01:00.0: BAR 0: assigned [mem 0x30000000-0x30000fff 64bit]
[    3.043349] pci 0000:00:00.0: PCI bridge to [bus 01]
[    3.048836] pci 0000:00:00.0:   bridge window [mem 0x30000000-0x300fffff]
[    3.056432] pci 0000:00:00.0: enabling device (0000 -> 0002)
[    3.062673] pci 0000:01:00.0: enabling device (0000 -> 0002)
[    3.068956] pci 0000:01:00.0: quirk_usb_early_handoff+0x0/0x9d4 took 12239 usecs
[    3.077348] xhci_hcd 0000:01:00.0: xHCI Host Controller
[    3.083132] xhci_hcd 0000:01:00.0: new USB bus registered, assigned bus number 1
[    3.091725] xhci_hcd 0000:01:00.0: hcc params 0x002841eb hci version 0x100 quirks 0x0000040000000890
[    3.101883] pcie_plda 2b000000.pcie: msi#0 address_hi 0x0 address_lo 0x190
[    3.109864] xhci_hcd 0000:01:00.0: xHCI Host Controller
[    3.115640] xhci_hcd 0000:01:00.0: new USB bus registered, assigned bus number 2
[    3.123831] xhci_hcd 0000:01:00.0: Host supports USB 3.0 SuperSpeed
[    3.131508] hub 1-0:1.0: USB hub found
[    3.135704] hub 1-0:1.0: 1 port detected
[    3.141068] hub 2-0:1.0: USB hub found
[    3.145241] hub 2-0:1.0: 4 ports detected
[    3.152489] pcie_plda 2c000000.pcie: host bridge /soc/pcie@2C000000 ranges:
[    3.160247] pcie_plda 2c000000.pcie:      MEM 0x0038000000..0x003fffffff -> 0x0038000000
[    3.169208] pcie_plda 2c000000.pcie:      MEM 0x0980000000..0x09bfffffff -> 0x0980000000
[    3.178197] ATR entry: 0x09c0000000 -> 0x0000000000 [0x0010000000] (param: 0x000001)
[    3.186760] ATR entry: 0x0038000000 -> 0x0038000000 [0x0008000000] (param: 0x000000)
[    3.195309] ATR entry: 0x0980000000 -> 0x0980000000 [0x0040000000] (param: 0x000000)
[    3.355708] usb usb2-port2: over-current condition
[    3.455731] usb 1-1: new high-speed USB device number 2 using xhci_hcd
[    3.515736] usb usb2-port4: over-current condition
[    3.625932] pcie_plda 2c000000.pcie: Port link down, exit.
[    3.645690] clk-starfive-jh7110-vout 295c0000.clock-controller: starfive JH7110 clk_vout init successfully.
[    3.666898] hub 1-1:1.0: USB hub found
[    3.668071] clk-starfive-jh7110-isp 19810000.clock-controller: starfive JH7110 clk_isp init successfully.
done.
Begin: Mounting root file system ... Begin: Running /scripts/local-top ... done.
Begin: Running /scripts/local-premount ... done.
Warning: fsck not present, so skipping root file system
[    7.114158] EXT4-fs (mmcblk1p3): mounted filesystem with ordered data mode. Opts: (null). Quota mode: disabled.
done.
Begin: Running /scripts/local-bottom ... done.
Begin: Running /scripts/init-bottom ... done.
[    7.883228] systemd[1]: System time before build time, advancing clock.
[    7.980379] systemd[1]: systemd 251.2-5 running in system mode (+PAM +AUDIT +SELINUX +APPARMOR +IMA +SMACK +SECCOMP +GCRYPT -GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY -P11KIT -QRENCODE +TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD -BPF_FRAMEWORK -XKBCOMMON +UTMP +SYSVINIT default-hierarchy=unified)
[    8.012496] systemd[1]: Detected architecture riscv64.

Welcome to D[    8.020576] systemd[1]: Hostname set to <starfive>.
ebian GNU/Linux bookworm/sid!

With that working it was time to try FreeBSD. A little searching unearthed a forums post showing a success opensbi->u-boot->loader process, but almost immediate failure once the kernel started. The forums post used a stock 13 image to boot which made it look like getting to a partially booting kernel wouldn't require too much extra work even if there was an immediate boot issue to fix.

The Debian boot process initially recommended manually picking up the kernel and device tree images to boot. A little googling pulled up a git repo with a script and instructions on how to boot . With that magic I grabbed a current snapshot and tried to reproduce the failing boot.

U-Boot SPL 2021.10 (Feb 12 2023 - 18:15:33 +0800)
DDR version: dc2e84f0.
Trying to boot from SPI

OpenSBI v1.2
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : StarFive VisionFive V2
Platform Features         : medeleg
Platform HART Count       : 5
Platform IPI Device       : aclint-mswi
Platform Timer Device     : aclint-mtimer @ 4000000Hz
Platform Console Device   : uart8250
Platform HSM Device       : jh7110-hsm
Platform PMU Device       : ---
Platform Reboot Device    : pm-reset
Platform Shutdown Device  : pm-reset
Firmware Base             : 0x40000000
Firmware Size             : 292 KB
Runtime SBI Version       : 1.0

Domain0 Name              : root
Domain0 Boot HART         : 1
Domain0 HARTs             : 0*,1*,2*,3*,4*
Domain0 Region00          : 0x0000000002000000-0x000000000200ffff (I)
Domain0 Region01          : 0x0000000040000000-0x000000004007ffff ()
Domain0 Region02          : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Loading kernel...
/boot/kernel/kernel text=0x5c324c text=0x182fa4 data=0xf5508 data=0x2dc4+0x264a4c 0x8+0x1ffc5c0+0x8+0xfb1fc/
Loading configured modules...
/boot/kernel/umodem.ko text=0x2080 text=0x1280 data=0x6f0+0x4 0x8+0x71b8+0x8+0xdcc
loading required module 'ucom'
/boot/kernel/ucom.ko text=0x2618 text=0x2d28 data=0x960+0x858 0x8+0xfae0+0x8+0x1492
can't find '/etc/hostid'
can't find '/boot/entropy'

Hit [Enter] to boot immediately, or any other key for command prompt.
Booting [/boot/kernel/kernel]...               
Using DTB provided by EFI at 0x47ef2000.
Kernel entry at 0xf680002e...
Kernel args: (null)
clk u5_dw_i2c_clk_core already disabled
clk u5_dw_i2c_clk_apb already disabled
---<<BOOT>>---
GDB: no debug ports present
KDB: debugger backends: ddb
KDB: current backend: ddb
Copyright (c) 1992-2023 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
    The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 14.0-CURRENT #0 main-n263139-baef3a5b585f: Thu May 25 06:56:04 UTC 2023
    root@releng1.nyi.freebsd.org:/usr/obj/usr/src/riscv.riscv64/sys/GENERIC riscv
FreeBSD clang version 15.0.7 (https://github.com/llvm/llvm-project.git llvmorg-15.0.7-0-g8dfdcc7b7bf6)
WARNING: WITNESS option enabled, expect reduced performance.
VT: init without driver.
SBI: OpenSBI v1.2
SBI Specification Version: 1.0
CPU 0  : Vendor=SiFive Core=6/7/P200/X200-Series Processor (Hart 1)
  marchid=0x8000000000000007, mimpid=0x4210427
  MMU: 0x1<Sv39>
  ISA: 0x112d<Atomic,Compressed,Double,Float,Mult/Div>
real memory  = 4294967296 (4096 MB)
avail memory = 4122566656 (3931 MB)
sbi_trap_error: hart0: trap handler failed (error -2)
sbi_trap_error: hart0: mcause=0x0000000000000005 mtval=0x0000000040048060
sbi_trap_error: hart0: mepc=0x0000000040004cac mstatus=0x0000000200001800
sbi_trap_error: hart0: ra=0x0000000040009ee2 sp=0x0000000040047f10
sbi_trap_error: hart0: gp=0x0000000000000000 tp=0x0000000040048000
sbi_trap_error: hart0: s0=0x0000000040047f20 s1=0x0000000040048000
sbi_trap_error: hart0: a0=0x0000000040048060 a1=0x0000000000000002
sbi_trap_error: hart0: a2=0x0000000000000000 a3=0x0000000000000019
sbi_trap_error: hart0: a4=0x0000000000000001 a5=0x0000000040048060
sbi_trap_error: hart0: a6=0x00000000400480a8 a7=0x0000000000000004
sbi_trap_error: hart0: s2=0x00000000400241a8 s3=0x0000000000000000
sbi_trap_error: hart0: s4=0x0000000000000000 s5=0x0000000040029000
sbi_trap_error: hart0: s6=0x0000000040029020 s7=0x0000000000000000
sbi_trap_error: hart0: s8=0x000000000000001c s9=0x0000000040035ab0
sbi_trap_error: hart0: s10=0x0000000000000000 s11=0x0000000000000000
sbi_trap_error: hart0: t0=0x0000000000000000 t1=0x0000000000000000
sbi_trap_error: hart0: t2=0x0000000000000000 t3=0x0000000000002000
sbi_trap_error: hart0: t4=0x0000000000000000 t5=0x0000000000000000
sbi_trap_error: hart0: t6=0x0000000000000000

Cool, I can reproduce the failure. I love it when that happens.

The git repo I got the u-boot commands from was adding a memory disk image to the boot process and showed a system log of the host getting all the way up to single user (without any device specific devices discovered). Digging into their script they pull down a different device tree blob and use that with their manual u-boot boot.

There was a follow up post by Jess (jrtc27@) linking to a issue with the device tree blob . I guess her suggestions were merged into the visionfive2 tree and they have yet to make it through Linux and into FreeBSD.

We need an updated DTB.

Loading kernel...
/boot/kernel/kernel text=0x5c324c text=0x182fa4 data=0xf5508 data=0x2dc4+0x264a4c 0x8+0x1ffc5c0+0x8+0xfb1fc/
Loading configured modules...
can't find '/boot/entropy'
/boot/kernel/umodem.ko text=0x2080 text=0x1280 data=0x6f0+0x4 0x8+0x71b8+0x8+0xdcc
loading required module 'ucom'
/boot/kernel/ucom.ko text=0x2618 text=0x2d28 data=0x960+0x858 0x8+0xfae0+0x8+0x1492
can't find '/etc/hostid'

Hit [Enter] to boot immediately, or any other key for command prompt.
Booting [/boot/kernel/kernel]...               
Using DTB provided by EFI at 0x47f00000.
Kernel entry at 0xf680002e...
Kernel args: (null)
clk u5_dw_i2c_clk_core already disabled
clk u5_dw_i2c_clk_apb already disabled
---<<BOOT>>---
GDB: no debug ports present
KDB: debugger backends: ddb
KDB: current backend: ddb
Copyright (c) 1992-2023 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
    The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 14.0-CURRENT #0 main-n263139-baef3a5b585f: Thu May 25 06:56:04 UTC 2023
    root@releng1.nyi.freebsd.org:/usr/obj/usr/src/riscv.riscv64/sys/GENERIC riscv
FreeBSD clang version 15.0.7 (https://github.com/llvm/llvm-project.git llvmorg-15.0.7-0-g8dfdcc7b7bf6)
WARNING: WITNESS option enabled, expect reduced performance.
VT: init without driver.
SBI: OpenSBI v1.2
SBI Specification Version: 1.0
CPU 0  : Vendor=SiFive Core=6/7/P200/X200-Series Processor (Hart 1)
  marchid=0x8000000000000007, mimpid=0x4210427
  MMU: 0x1<Sv39>
  ISA: 0x112d<Atomic,Compressed,Double,Float,Mult/Div>
real memory  = 4294967296 (4096 MB)
avail memory = 4121706496 (3930 MB)
FreeBSD/SMP: Multiprocessor System Detected: 4 CPUs
CPU 1  : Vendor=SiFive Core=6/7/P200/X200-Series Processor (Hart 2)
CPU 2  : Vendor=SiFive Core=6/7/P200/X200-Series Processor (Hart 3)
CPU 3  : Vendor=SiFive Core=6/7/P200/X200-Series Processor (Hart 4)
arc4random: WARNING: initial seeding bypassed the cryptographic random device because it was not yet seeded and the knob 'bypass_before_seeding' was enabled.
random: entropy device external interface
kbd0 at kbdmux0
ofwbus0: <Open Firmware Device Tree>
clk_fixed0: <Fixed clock> on ofwbus0
clk_fixed1: <Fixed clock> on ofwbus0
clk_fixed2: <Fixed clock> on ofwbus0
clk_fixed3: <Fixed clock> on ofwbus0
clk_fixed4: <Fixed clock> on ofwbus0
clk_fixed5: <Fixed clock> on ofwbus0
clk_fixed6: <Fixed clock> on ofwbus0
clk_fixed7: <Fixed clock> on ofwbus0
clk_fixed8: <Fixed clock> on ofwbus0
clk_fixed9: <Fixed clock> on ofwbus0
clk_fixed10: <Fixed clock> on ofwbus0
clk_fixed11: <Fixed clock> on ofwbus0
clk_fixed12: <Fixed clock> on ofwbus0
clk_fixed13: <Fixed clock> on ofwbus0
clk_fixed14: <Fixed clock> on ofwbus0
clk_fixed15: <Fixed clock> on ofwbus0
clk_fixed16: <Fixed clock> on ofwbus0
clk_fixed17: <Fixed clock> on ofwbus0
clk_fixed18: <Fixed clock> on ofwbus0
clk_fixed19: <Fixed clock> on ofwbus0
simplebus0: <Flattened device tree simple bus> on ofwbus0
plic0: <RISC-V PLIC> mem 0xc000000-0xfffffff irq 14,15,16,17,18,19,20,21,22 on simplebus0
timer0: <RISC-V Timer>
Timecounter "RISC-V Timecounter" frequency 4000000 Hz quality 1000
Event timer "RISC-V Eventtimer" frequency 4000000 Hz quality 1000
rcons0: <RISC-V console>
cpulist0: <Open Firmware CPU Group> on ofwbus0
cpu0: <Open Firmware CPU> on cpulist0
Timecounters tick every 1.000 msec
usb_needs_explore_all: no devclass
Release APs
WARNING: WITNESS option enabled, expect reduced performance.
Trying to mount root from ufs:/dev/ufs/rootfs [rw]...
mountroot: waiting for device /dev/ufs/rootfs...
random: unblocking device.
Mounting from ufs:/dev/ufs/rootfs failed with error 19.

Loader variables:
  vfs.root.mountfrom=ufs:/dev/ufs/rootfs
  vfs.root.mountfrom.options=rw

Manual root filesystem specification:
  <fstype>:<device> [options]
      Mount <device> using filesystem <fstype>
      and with the specified (optional) option list.

    eg. ufs:/dev/da0s1a
    zfs:zroot/ROOT/default
    cd9660:/dev/cd0 ro
      (which is equivalent to: mount -t cd9660 -o ro /dev/cd0 /)

  ?               List valid disk boot devices
  .               Yield 1 second (for background tasks)
  <empty line>    Abort manual input

mountroot>

Cool that works, but it is a very annoying way to boot. Can we fix it?

StarFive # printenv
baudrate=115200
boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr}
boot_efi_binary=load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} efi/boot/bootriscv64.efi; if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r};else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi
boot_efi_bootmgr=if fdt addr ${fdt_addr_r}; then bootefi bootmgr ${fdt_addr_r};else bootefi bootmgr;fi
boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}${boot_syslinux_conf}
boot_prefixes=/ /boot/
boot_script_dhcp=boot.scr.uimg
boot_scripts=boot.scr.uimg boot.scr
boot_syslinux_conf=extlinux/extlinux.conf
boot_targets=mmc0 dhcp
bootargs=console=ttyS0,115200  debug rootwait  earlycon=sbi
bootcmd=run load_vf2_env;run importbootenv;run load_distro_uenv;run boot2;run distro_bootcmd
bootcmd_dhcp=devtype=dhcp; if dhcp ${scriptaddr} ${boot_script_dhcp}; then source ${scriptaddr}; fi;setenv efi_fdtfile ${fdtfile}; setenv efi_old_vci ${bootp_vci};setenv efi_old_arch ${bootp_arch};setenv bootp_vci PXEClient:Arch:00027:UNDI:003000;setenv bootp_arch 0x1b;if dhcp ${kernel_addr_r}; then tftpboot ${fdt_addr_r} dtb/${efi_fdtfile};if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r}; else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi;fi;setenv bootp_vci ${efi_old_vci};setenv bootp_arch ${efi_old_arch};setenv efi_fdtfile;setenv efi_old_arch;setenv efi_old_vci;
bootcmd_distro=run fdt_loaddtb; run fdt_sizecheck; run set_fdt_distro; sysboot mmc ${fatbootpart} fat c0000000 ${bootdir}/${boot_syslinux_conf};
bootcmd_mmc0=devnum=0; run mmc_boot
bootdelay=2
bootdir=/boot
bootenv=uEnv.txt
bootmode=flash
bootpart=1:3
chip_vision=B
chipa_gmac_set=fdt set /soc/ethernet@16030000/ethernet-phy@0 tx_inverted_10 <0x0>;fdt set /soc/ethernet@16030000/ethernet-phy@0 tx_inverted_100 <0x0>;fdt set /soc/ethernet@16030000/ethernet-phy@0 tx_inverted_1000 <0x0>;fdt set /soc/ethernet@16030000/ethernet-phy@0 tx_delay_sel <0x9>;fdt set /soc/ethernet@16040000/ethernet-phy@1 tx_inverted_10 <0x0>;fdt set /soc/ethernet@16040000/ethernet-phy@1 tx_inverted_100 <0x0>;fdt set /soc/ethernet@16040000/ethernet-phy@1 tx_inverted_1000 <0x0>;fdt set /soc/ethernet@16040000/ethernet-phy@1 tx_delay_sel <0x9>
chipa_set=if test ${chip_vision} = A; then run chipa_gmac_set;fi;
chipa_set_linux=fdt addr ${fdt_addr_r};run visionfive2_mem_set;run chipa_set;
chipa_set_linux_force=fdt addr ${fdt_addr_r};run visionfive2_mem_set;run chipa_gmac_set;
chipa_set_uboot=fdt addr ${uboot_fdt_addr};run chipa_set;
chipa_set_uboot_force=fdt addr ${uboot_fdt_addr};run chipa_gmac_set;
devnum=1
distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done
distroloadaddr=0xb0000000
efi_dtb_prefixes=/ /dtb/ /dtb/current/
eth0addr=6c:cf:39:00:42:ba
eth1addr=6c:cf:39:00:42:bb
ethaddr=6c:cf:39:00:42:ba
ext4bootenv=ext4load mmc ${bootpart} ${loadaddr} ${bootdir}/${bootenv}
fatbootpart=1:2
fdt_addr_r=0x46000000
fdt_high=0xffffffffffffffff
fdt_loaddtb=fatload mmc ${fatbootpart} ${fdt_addr_r} ${bootdir}/dtbs/${fdtfile}; fdt addr ${fdt_addr_r};
fdt_sizecheck=fatsize mmc ${fatbootpart} ${bootdir}/dtbs/${fdtfile};
fdtaddr=fffc5dd0
fdtcontroladdr=fffc5dd0
fdtfile=starfive/starfive_visionfive2.dtb
importbootenv=echo Importing environment from mmc${devnum} ...; env import -t ${loadaddr} ${filesize}
initrd_high=0xffffffffffffffff
ipaddr=192.168.120.230
kernel_addr_r=0x40200000
load_distro_uenv=fatload mmc ${fatbootpart} ${distroloadaddr} ${bootdir}/${bootenv}; env import ${distroloadaddr} 17c;
load_efi_dtb=load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} ${prefix}${efi_fdtfile}
load_vf2_env=fatload mmc ${bootpart} ${loadaddr} ${testenv}
loadaddr=0xa0000000
loadbootenv=fatload mmc ${bootpart} ${loadaddr} ${bootenv}
memory_addr=40000000
memory_size=200000000
mmc_boot=if mmc dev ${devnum}; then devtype=mmc; run scan_dev_for_boot_part; fi
mmcbootenv=run scan_mmc_dev; setenv bootpart ${devnum}:${mmcpart}; if mmc rescan; then run loadbootenv && run importbootenv; run ext4bootenv && run importbootenv; if test -n $uenvcmd; then echo Running uenvcmd ...; run uenvcmd; fi; fi
mmcpart=3
netmask=255.255.255.0
partitions=name=loader1,start=17K,size=1M,type=${type_guid_gpt_loader1};name=loader2,size=4MB,type=${type_guid_gpt_loader2};name=system,size=-,bootable,type=${type_guid_gpt_system};
preboot=run chipa_set_uboot;run mmcbootenv
pxefile_addr_r=0x45900000
ramdisk_addr_r=0x46100000
scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${distro_bootpart}...; for prefix in ${boot_prefixes}; do run scan_dev_for_extlinux; run scan_dev_for_scripts; done;run scan_dev_for_efi;
scan_dev_for_boot_part=part list ${devtype} ${devnum} -bootable devplist; env exists devplist || setenv devplist 1; for distro_bootpart in ${devplist}; do if fstype ${devtype} ${devnum}:${distro_bootpart} bootfstype; then run scan_dev_for_boot; fi; done; setenv devplist
scan_dev_for_efi=setenv efi_fdtfile ${fdtfile}; for prefix in ${efi_dtb_prefixes}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${efi_fdtfile}; then run load_efi_dtb; fi;done;run boot_efi_bootmgr;if test -e ${devtype} ${devnum}:${distro_bootpart} efi/boot/bootriscv64.efi; then echo Found EFI removable media binary efi/boot/bootriscv64.efi; run boot_efi_binary; echo EFI LOAD FAILED: continuing...; fi; setenv efi_fdtfile
scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${boot_syslinux_conf}; then echo Found ${prefix}${boot_syslinux_conf}; run boot_extlinux; echo SCRIPT FAILED: continuing...; fi
scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${script}; then echo Found U-Boot script ${prefix}${script}; run boot_a_script; echo SCRIPT FAILED: continuing...; fi; done
scan_mmc_dev=if test ${bootmode} = flash; then if mmc dev ${devnum}; then echo found device ${devnum};else setenv devnum 0;mmc dev 0;fi; fi; echo bootmode ${bootmode} device ${devnum};
scan_sf_for_scripts=${devtype} read ${scriptaddr} ${script_offset_f} ${script_size_f}; source ${scriptaddr}; echo SCRIPT FAILED: continuing...
script_offset_f=0x1fff000
script_size_f=0x1000
scriptaddr=0x43900000
serial#=VF7110B1-2253-D008E000-00004015
set_fdt_distro=if test ${chip_vision} = A; then if test ${memory_size} = 200000000; then run chipa_gmac_set;run visionfive2_mem_set;fatwrite mmc ${fatbootpart} ${fdt_addr_r} ${bootdir}/dtbs/${fdtfile} ${filesize};else run chipa_gmac_set;run visionfive2_mem_set;fatwrite mmc ${fatbootpart} ${fdt_addr_r} ${bootdir}/dtbs/${fdtfile} ${filesize};fi;else run visionfive2_mem_set;fatwrite mmc ${fatbootpart} ${fdt_addr_r} ${bootdir}/dtbs/${fdtfile} ${filesize};fi;
sf_boot=if sf probe ${busnum}; then devtype=sf; run scan_sf_for_scripts; fi
stderr=serial@10000000
stdin=serial@10000000
stdout=serial@10000000
testenv=vf2_uEnv.txt
type_guid_gpt_loader1=5B193300-FC78-40CD-8002-E86C45580B47
type_guid_gpt_loader2=2E54B353-1271-4842-806F-E436D6AF6985
type_guid_gpt_system=0FC63DAF-8483-4772-8E79-3D69D8477DE4
uboot_fdt_addr=0xfffc5dd0
ver=U-Boot 2021.10 (Feb 12 2023 - 18:15:33 +0800)
visionfive2_mem_set=fdt memory ${memory_addr} ${memory_size};

Environment size: 7216/65532 bytes

From the u-boot environment we can find the DTB file u-boot is passing on to the EFI loader. If we move our DTB to be in that location on disk we should be able to boot automatically.

fdtfile=starfive/starfive_visionfive2.dtb

With the working DTB in the correct place we can boot the FreeBSD image from power on without any manual intervention. We fail at mount root because we are missing drivers for any sort of storage medium, eMMC or SD (both are on a SDIO controller), USB or NVMe. We don't have any drivers for this board yet, the stuff detected in the dmesg above is devices in the DTB which exist elsewhere and so have FreeBSD drivers.

To get past mount root (without using a memory disk) we need to have a storage driver, so lets pull up the docs and write one!

Much angered reading and intense searching later

It looks like there isn't useful documentation available for a driver writer. There are open source drivers on their way into the Linux Kernel, but the Software TRM is a high level overview, the software developer guides explain how to use interfaces from Linux and everything else is a useless summary.

From searching I found that Haiku is booting and running on the VisionFive2 . They have drivers for the PCIe controller giving them USB and NVMe and graphics on the frame buffer because u-boot is kind enough to set it up. As far as I can tell (I hope I'm wrong), they PCIe controller driver has been cribbed from the Linux Kernel.

While writing drivers from others source is possible, it is a bit hairy going from the GPL to BSD licenses and it is terribly annoying when you hit issues to not have documentation.

I can't see FreeBSD supporting the VisionFive2 without there being proper open documentation to write drivers from.