[记录贴]kernel学习

我要成为kernel高手.jpg
非教程 仅记录经验 欢迎讨论

资源:

主要参考了这家的教程
以及白嫖的JH7110板子(x

Boot JH7110

U-Boot

首先清空掉之前的配置…
git clean -fdx
根据Obtaining the source切换到需要的版本
git checkout v2024.01-rc6
根据Build with gcc编译…

mkdir build
make O=./build V=1 starfive_visionfive2_defconfig
make O=./build CROSS_COMPILE=riscv64-linux-gnu- -j$(nproc)

报错

Image 'itb' is missing external blobs and is non-functional: opensbi  
  
/binman/itb/fit/images/opensbi/opensbi (fw_dynamic.bin):  
  See the documentation for your board. The OpenSBI git repo is at  
  https://github.com/riscv/opensbi.git  
  You may need to build fw_dynamic.bin first and re-build u-boot with  
  OPENSBI=/path/to/fw_dynamic.bin  
  
Some images are invalid

https://github.com/riscv/opensbi.git把opensbi拉下来…
编译opensbi
根据U-Boot board specific doc构建

export CROSS_COMPILE=riscv64-linux-gnu-
make PLATFORM=generic FW_TEXT_START=0x40000000 FW_OPTIONS=0 -j$(nproc)

这里make的行为会直接把生成的东西塞进build…不用指定O=了
回去重新构建U-Boot

export opensbi_dir=$(pwd)
cd ../u-boot
make O=./build OPENSBI=$opensbi_dir/build/platform/generic/firmware/fw_dynamic.bin -j$(nproc)

这一行为会生成SPL(spl/u-boot-spl.bin.normal.out)与包含OpenSBI与U-Boot的FIT image(u-boot.itb)
写入新的SPL和U-Boot看看默认行为先
recovery tool写入flash…
走xmodem写入jh7110-recovery-20221205.bin, 写入编译的spl和u-boot

启动看看默认行为

Hit any key to stop autoboot:  0    
Flags not supported: enable CONFIG_BOOTSTD_FULL  
bootflow - Boot flows  
  
Usage:  
bootflow scan - boot first available bootflow  
  
StarFive # env  
env - environment handling commands  
  
Usage:  
env default [-f] -a - [forcibly] reset default environment  
env default [-f] var [...] - [forcibly] reset variable(s) to their default values  
env delete [-f] var [...] - [forcibly] delete variable(s)  
env edit name - edit environment variable  
env exists name - tests for existence of variable  
env export [-t | -b | -c] [-s size] addr [var ...] - export environment  
env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import environment  
env print [-a | name ...] - print environment  
env run var [...] - run commands in an environment variable  
env save - save environment  
env set [-f] name [arg ...]  
  
StarFive # env print  
arch=riscv  
baudrate=115200  
board=visionfive2  
board_name=visionfive2  
bootargs=console=ttyS0,115200 debug rootwait earlycon=sbi  
bootcmd=bootflow scan -lb  
bootdelay=2  
cpu=jh7110  
eth1addr=6c:cf:39:00:4e:77  
ethaddr=6c:cf:39:00:4e:76  
fdt_addr_r=0x46000000  
fdtcontroladdr=ff72d9b0  
fdtfile=starfive/jh7110-starfive-visionfive-2-v1.3b.dtb  
fdtoverlay_addr_r=0x45800000  
kernel_addr_r=0x40200000  
kernel_comp_addr_r=0x88000000  
kernel_comp_size=0x4000000  
loadaddr=0x82000000  
pxefile_addr_r=0x45900000  
ramdisk_addr_r=0x46100000  
scriptaddr=0x43900000  
serial#=VF7110B1-2310-D004E000-00001284  
stderr=serial@10000000  
stdin=serial@10000000  
stdout=serial@10000000  
vendor=starfive  
  
Environment size: 660/65532 bytes  
StarFive #

可见默认bootcmd即bootflow scan -lb, 但默认配置未启用CONFIG_BOOTSTD_FULL
先尝试编译个kernel image手动启动一下

cd linux
git clean -fdx
git checkout JH7110_VisionFive2_upstream
mkdir build
export CROSS_COMPILE=riscv64-linux-gnu-

嵌入式平台的默认配置会位于arch/<arch>/configs/下。

$ ls arch/riscv/configs/ | grep star  
starfive_visionfive2_defconfig

目前vf2的默认配置还没进mainline kernel支持,这里用的是starfive-tech自家仓库的kernel.

make O=./build ARCH=riscv starfive_visionfive2_defconfig

总之先不动menuconfig,把默认行为的内核弄出来再说…
make O=./build ARCH=riscv -j$(nproc)
根据bootlin的教程ppt,kernel编译生成内容主要有

  • arch/<arch>/boot/Image, 未压缩的image,可启动
  • arch/<arch>/boot/Image, 压缩image,可启动,rv下为Image.gz
  • arch/<arch>/boot/dts/*.dtb, 编译后的Device Tree Blobs
  • 所有的kernel module, 分布在kernel source tree各处,各个.ko(kernel object)文件
  • vmlinux, raw 未压缩ELF格式kernel image,debug用
mmc list 列出所有mmc dev
mmc dev 1 切到设别1(此处为sd卡)
mmc part
Partition Map for MMC device 1  --   Partition Type: EFI  
  
Part    Start LBA       End LBA         Name  
       Attributes  
       Type GUID  
       Partition GUID  
 1     0x00000800      0x001007ff      ""  
       attrs:  0x0000000000000000  
       type:   c12a7328-f81f-11d2-ba4b-00a0c93ec93b  
               (system)  
       guid:   f512e4f7-8d07-486b-be1d-c181a03ee848  
 2     0x00100800      0x076f47ff      ""  
       attrs:  0x0000000000000000  
       type:   0fc63daf-8483-4772-8e79-3d69d8477de4  
               (linux)  
       guid:   d0f1e6f6-501c-4bce-b3c3-553dc8404ba8

ls mmc <dev>:<partition>
ls mmc 1:1
StarFive # ls mmc 1:1  
21838848   Image  
   33886   jh7110-starfive-visionfive-2-v1.2a.dtb  
   34271   jh7110-starfive-visionfive-2-v1.3b.dtb  
  
3 file(s), 0 dir(s)

常规启动流程:把image 和DTB加载进内存并启动。rv64可以使用booti指令启动。
总之先用load指令加载进内存。加载进内存的地址参考了u-boot doc Image locations

StarFive # load mmc 1:1 $kernel_addr_r Image.gz  
6910934 bytes read in 423 ms (15.6 MiB/s)  
StarFive # load mmc 1:1 $fdt_addr_r jh7110-starfive-visionfive-2-v1.3b.dtb  
43142 bytes read in 6 ms (6.9 MiB/s)

根据bootlin教程ppt尝试启动内核,使用指令boot[z|i] <kernelAddr> - <dtbAddr> ,中间的- 表明没有initramfs ,initramfs什么作用后面再查…

StarFive # booti $kernel_addr_r - $fdt_addr_r  
  Uncompressing Kernel Image  
## Flattened Device Tree blob at 46000000  
  Booting using the fdt blob at 0x46000000  
Working FDT set to 46000000  
  Loading Device Tree to 00000000fe714000, end 00000000fe721885 ... OK  
Working FDT set to fe714000  
  
Starting kernel ...  
  
Linux version 6.6.0-g076ede06c00a (unclebiglu@ublvlc) (riscv64-linux-gnu-gcc (GCC) 13.2.1 20230728 (Red Hat Cross 13.2.1-1), GNU ld 4  
Machine model: StarFive VisionFive 2 v1.3B  
SBI specification v2.0 detected  
SBI implementation ID=0x1 Version=0x10004  
SBI TIME extension detected  
SBI IPI extension detected  
SBI RFENCE extension detected  
efi: UEFI not found.  
Reserved memory: created CMA memory pool at 0x0000000070000000, size 512 MiB  
OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool  
OF: reserved mem: 0x0000000070000000..0x000000008fffffff (524288 KiB) map reusable linux,cma  
OF: reserved mem: 0x0000000040000000..0x000000004003ffff (256 KiB) nomap non-reusable mmode_resv1@40000000  
OF: reserved mem: 0x0000000040040000..0x000000004005ffff (128 KiB) nomap non-reusable mmode_resv0@40040000  
Zone ranges:  
 DMA32    [mem 0x0000000040000000-0x00000000ffffffff]  
 Normal   [mem 0x0000000100000000-0x000000013fffffff]  
Movable zone start for each node  
Early memory node ranges  
 node   0: [mem 0x0000000040000000-0x000000004005ffff]  
 node   0: [mem 0x0000000040060000-0x000000013fffffff]  
Initmem setup node 0 [mem 0x0000000040000000-0x000000013fffffff]  
SBI HSM extension detected  
CPU with hartid=0 is not available  
Falling back to deprecated "riscv,isa"  
riscv: base ISA extensions acdfim  
riscv: ELF capabilities acdfim  
percpu: Embedded 18 pages/cpu s34472 r8192 d31064 u73728  
pcpu-alloc: s34472 r8192 d31064 u73728 alloc=18*4096  
pcpu-alloc: [0] 0 [0] 1 [0] 2 [0] 3    
Kernel command line: console=ttyS0,115200 debug rootwait earlycon=sbi  
Dentry cache hash table entries: 524288 (order: 10, 4194304 bytes, linear)  
Inode-cache hash table entries: 262144 (order: 9, 2097152 bytes, linear)  
Built 1 zonelists, mobility grouping on.  Total pages: 1034240  
mem auto-init: stack:all(zero), heap alloc:off, heap free:off  
software IO TLB: area num 4.  
software IO TLB: mapped [mem 0x00000000fa714000-0x00000000fe714000] (64MB)  
Memory: 3516748K/4194304K available (8662K kernel code, 4798K rwdata, 4096K rodata, 2190K init, 333K bss, 153268K reserved, 524288K )  
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1  
rcu: Hierarchical RCU implementation.  
rcu:    RCU restricting CPUs from NR_CPUS=64 to nr_cpu_ids=4.  
rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.  
rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4  
NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0  
riscv-intc: unable to find hart id for /cpus/cpu@0/interrupt-controller  
riscv-intc: 64 local interrupts mapped  
plic: interrupt-controller@c000000: mapped 136 interrupts with 4 handlers for 9 contexts.  
riscv: providing IPIs using SBI IPI extension  
rcu: srcu_init: Setting srcu_struct sizes based on contention.  
clocksource: riscv_clocksource: mask: 0xffffffffffffffff max_cycles: 0x1d854df40, max_idle_ns: 881590404240 ns  
sched_clock: 64 bits at 4MHz, resolution 250ns, wraps every 2199023255500ns  
Calibrating delay loop (skipped), value calculated using timer frequency.. 8.00 BogoMIPS (lpj=16000)  
pid_max: default: 32768 minimum: 301  
Mount-cache hash table entries: 8192 (order: 4, 65536 bytes, linear)  
Mountpoint-cache hash table entries: 8192 (order: 4, 65536 bytes, linear)  
CPU node for /cpus/cpu@0 exist but the possible cpu range is :0-3  
ASID allocator disabled (0 bits)  
rcu: Hierarchical SRCU implementation.  
rcu:    Max phase no-delay instances is 1000.  
EFI services will not be available.  
smp: Bringing up secondary CPUs ...  
cpu1: Ratio of byte access time to unaligned word access is 0.01, unaligned accesses are slow  
cpu2: Ratio of byte access time to unaligned word access is 0.01, unaligned accesses are slow  
cpu3: Ratio of byte access time to unaligned word access is 0.01, unaligned accesses are slow  
smp: Brought up 1 node, 4 CPUs  
devtmpfs: initialized  
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns  
futex hash table entries: 1024 (order: 4, 65536 bytes, linear)  
pinctrl core: initialized pinctrl subsystem  
NET: Registered PF_NETLINK/PF_ROUTE protocol family  
DMA: preallocated 512 KiB GFP_KERNEL pool for atomic allocations  
DMA: preallocated 512 KiB GFP_KERNEL|GFP_DMA32 pool for atomic allocations  
thermal_sys: Registered thermal governor 'step_wise'  
cpuidle: using governor menu  
cpu0: Ratio of byte access time to unaligned word access is 0.01, unaligned accesses are slow  
platform soc: Fixed dependency cycle(s) with /soc/interrupt-controller@c000000  
platform 19840000.isp: Fixed dependency cycle(s) with /soc/csi@19800000/ports/port@1/endpoint  
platform 29400000.lcd-controller: Fixed dependency cycle(s) with /dsi_encoder/ports/port@0/endpoint@0  
platform 29590000.hdmi: Fixed dependency cycle(s) with /soc/lcd-controller@29400000/ports/port@0/endpoint@0  
raid6: skipped pq benchmark and selected int64x8  
raid6: using intx1 recovery algorithm  
SCSI subsystem initialized  
usbcore: registered new interface driver usbfs  
usbcore: registered new interface driver hub  
usbcore: registered new device driver usb  
mc: Linux media interface: v0.10  
videodev: Linux video capture interface: v2.00  
Advanced Linux Sound Architecture Driver Initialized.  
vgaarb: loaded  
clocksource: Switched to clocksource riscv_clocksource  
NET: Registered PF_INET protocol family  
IP idents hash table entries: 65536 (order: 7, 524288 bytes, linear)  
tcp_listen_portaddr_hash hash table entries: 2048 (order: 3, 32768 bytes, linear)  
Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)  
TCP established hash table entries: 32768 (order: 6, 262144 bytes, linear)  
TCP bind hash table entries: 32768 (order: 8, 1048576 bytes, linear)  
TCP: Hash tables configured (established 32768 bind 32768)  
UDP hash table entries: 2048 (order: 4, 65536 bytes, linear)  
UDP-Lite hash table entries: 2048 (order: 4, 65536 bytes, linear)  
NET: Registered PF_UNIX/PF_LOCAL protocol family  
RPC: Registered named UNIX socket transport module.  
RPC: Registered udp transport module.  
RPC: Registered tcp transport module.  
RPC: Registered tcp-with-tls transport module.  
RPC: Registered tcp NFSv4.1 backchannel transport module.  
PCI: CLS 0 bytes, default 64  
workingset: timestamp_bits=62 max_order=20 bucket_order=0  
NFS: Registering the id_resolver key type  
Key type id_resolver registered  
Key type id_legacy registered  
nfs4filelayout_init: NFSv4 File Layout Driver Registering...  
nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...  
ntfs: driver 2.1.32 [Flags: R/W].  
jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.  
xor: measuring software checksum speed  
  8regs           :  2343 MB/sec  
  8regs_prefetch  :  2338 MB/sec  
  32regs          :  2345 MB/sec  
  32regs_prefetch :  2338 MB/sec  
xor: using function: 32regs (2345 MB/sec)  
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)  
io scheduler bfq registered  
CCACHE: 8 banks, 16 ways, sets/bank=256, bytes/block=64  
CCACHE: Index of the largest way enabled: 15  
Serial: 8250/16550 driver, 6 ports, IRQ sharing disabled  
random: crng init done  
loop: module loaded  
zram: Added device: zram0  
spi-nor spi0.0: gd25lq128d (16384 Kbytes)  
4 fixed-partitions partitions found on MTD device 13010000.spi.0  
Creating 4 MTD partitions on "13010000.spi.0":  
0x000000000000-0x000000080000 : "spl"  
0x0000000f0000-0x000000100000 : "uboot-env"  
0x000000100000-0x000000500000 : "uboot"  
0x000000600000-0x000001000000 : "reserved-data"  
starfive-dwmac 16030000.ethernet: User ID: 0x41, Synopsys ID: 0x52  
starfive-dwmac 16030000.ethernet:       DWMAC4/5  
starfive-dwmac 16030000.ethernet: DMA HW capability register supported  
starfive-dwmac 16030000.ethernet: RX Checksum Offload Engine supported  
starfive-dwmac 16030000.ethernet: Wake-Up On Lan supported  
starfive-dwmac 16030000.ethernet: TSO supported  
starfive-dwmac 16030000.ethernet: Enable RX Mitigation via HW Watchdog Timer  
starfive-dwmac 16030000.ethernet: Enabled L3L4 Flow TC (entries=1)  
starfive-dwmac 16030000.ethernet: Enabled RFS Flow TC (entries=10)  
starfive-dwmac 16030000.ethernet: TSO feature enabled  
starfive-dwmac 16030000.ethernet: Using 40/40 bits DMA host/device width  
starfive-dwmac 16040000.ethernet: User ID: 0x41, Synopsys ID: 0x52  
starfive-dwmac 16040000.ethernet:       DWMAC4/5  
starfive-dwmac 16040000.ethernet: DMA HW capability register supported  
starfive-dwmac 16040000.ethernet: RX Checksum Offload Engine supported  
starfive-dwmac 16040000.ethernet: Wake-Up On Lan supported  
starfive-dwmac 16040000.ethernet: TSO supported  
starfive-dwmac 16040000.ethernet: Enable RX Mitigation via HW Watchdog Timer  
starfive-dwmac 16040000.ethernet: Enabled L3L4 Flow TC (entries=1)  
starfive-dwmac 16040000.ethernet: Enabled RFS Flow TC (entries=10)  
starfive-dwmac 16040000.ethernet: TSO feature enabled  
starfive-dwmac 16040000.ethernet: Using 40/40 bits DMA host/device width  
usbcore: registered new interface driver uas  
usbcore: registered new interface driver usb-storage  
i2c_dev: i2c /dev entries driver  
sdhci: Secure Digital Host Controller Interface driver  
sdhci: Copyright(c) Pierre Ossman  
Synopsys Designware Multimedia Card Interface Driver  
sdhci-pltfm: SDHCI platform and OF driver helper  
clocksource: jh7110-timer.ch0: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns  
clocksource: jh7110-timer.ch1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns  
clocksource: jh7110-timer.ch2: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns  
clocksource: jh7110-timer.ch3: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns  
usbcore: registered new interface driver usbhid  
usbhid: USB HID core driver  
riscv-pmu-sbi: SBI PMU extension is available  
riscv-pmu-sbi: 16 firmware and 4 hardware counters  
riscv-pmu-sbi: Perf sampling/filtering is not supported as sscof extension is not available  
NET: Registered PF_INET6 protocol family  
Segment Routing with IPv6  
In-situ OAM (IOAM) with IPv6  
NET: Registered PF_PACKET protocol family  
Key type dns_resolver registered  
Btrfs loaded, zoned=no, fsverity=no  
pl08xdmac 16008000.dma-controller: initialized 8 virtual memcpy channels  
pl08xdmac 16008000.dma-controller: initialized 16 virtual slave channels  
debugfs: Directory '16008000.dma-controller' with parent 'dmaengine' already present!  
pl08xdmac 16008000.dma-controller: DMA: PL080 rev0 at 0x16008000 irq 30  
gpio gpiochip0: Static allocation of GPIO base is deprecated, use dynamic allocation.  
starfive-jh7110-sys-pinctrl 13040000.pinctrl: StarFive GPIO chip registered 64 GPIOs  
gpio gpiochip1: Static allocation of GPIO base is deprecated, use dynamic allocation.  
starfive-jh7110-aon-pinctrl 17020000.pinctrl: StarFive GPIO chip registered 4 GPIOs  
pcie-starfive 940000000.pcie: host bridge /soc/pcie@940000000 ranges:  
pcie-starfive 940000000.pcie:      MEM 0x0030000000..0x0037ffffff -> 0x0030000000  
pcie-starfive 940000000.pcie:      MEM 0x0900000000..0x093fffffff -> 0x0900000000  
pcie-starfive 940000000.pcie: port link up  
pcie-starfive 940000000.pcie: PCI host bridge to bus 0000:00  
pci_bus 0000:00: root bus resource [bus 00-ff]  
pci_bus 0000:00: root bus resource [mem 0x30000000-0x37ffffff]  
pci_bus 0000:00: root bus resource [mem 0x900000000-0x93fffffff pref]  
pci 0000:00:00.0: [1556:1111] type 01 class 0x060400  
pci 0000:00:00.0: supports D1 D2  
pci 0000:00:00.0: PME# supported from D0 D1 D2 D3hot D3cold  
pci 0000:01:00.0: [1106:3483] type 00 class 0x0c0330  
pci 0000:01:00.0: reg 0x10: [mem 0x00000000-0x00000fff 64bit]  
pci 0000:01:00.0: PME# supported from D0 D3cold  
pci_bus 0000:01: busn_res: [bus 01-ff] end is updated to 01  
pci 0000:00:00.0: BAR 8: assigned [mem 0x30000000-0x300fffff]  
pci 0000:01:00.0: BAR 0: assigned [mem 0x30000000-0x30000fff 64bit]  
pci 0000:00:00.0: PCI bridge to [bus 01]  
pci 0000:00:00.0:   bridge window [mem 0x30000000-0x300fffff]  
pcieport 0000:00:00.0: PME: Signaling with IRQ 46  
pci 0000:01:00.0: enabling device (0000 -> 0002)  
xhci_hcd 0000:01:00.0: xHCI Host Controller  
xhci_hcd 0000:01:00.0: new USB bus registered, assigned bus number 1  
xhci_hcd 0000:01:00.0: hcc params 0x002841eb hci version 0x100 quirks 0x0000000000000890  
xhci_hcd 0000:01:00.0: xHCI Host Controller  
xhci_hcd 0000:01:00.0: new USB bus registered, assigned bus number 2  
xhci_hcd 0000:01:00.0: Host supports USB 3.0 SuperSpeed  
hub 1-0:1.0: USB hub found  
hub 1-0:1.0: 1 port detected  
hub 2-0:1.0: USB hub found  
hub 2-0:1.0: 4 ports detected  
pcie-starfive 9c0000000.pcie: host bridge /soc/pcie@9c0000000 ranges:  
pcie-starfive 9c0000000.pcie:      MEM 0x0038000000..0x003fffffff -> 0x0038000000  
pcie-starfive 9c0000000.pcie:      MEM 0x0980000000..0x09bfffffff -> 0x0980000000  
usb 1-1: new high-speed USB device number 2 using xhci_hcd  
usb usb2-port2: over-current condition  
hub 1-1:1.0: USB hub found  
hub 1-1:1.0: 4 ports detected  
pcie-starfive 9c0000000.pcie: port link down  
pcie-starfive 9c0000000.pcie: PCI host bridge to bus 0001:00  
pci_bus 0001:00: root bus resource [bus 00-ff]  
pci_bus 0001:00: root bus resource [mem 0x38000000-0x3fffffff]  
pci_bus 0001:00: root bus resource [mem 0x980000000-0x9bfffffff pref]  
pci 0001:00:00.0: [1556:1111] type 01 class 0x060400  
pci 0001:00:00.0: supports D1 D2  
pci 0001:00:00.0: PME# supported from D0 D1 D2 D3hot D3cold  
pci_bus 0001:01: busn_res: [bus 01-ff] end is updated to 01  
pci 0001:00:00.0: PCI bridge to [bus 01]  
pcieport 0001:00:00.0: PME: Signaling with IRQ 61  
dw_axi_dmac_platform 16050000.dma-controller: DesignWare AXI DMA Controller, 4 channels  
printk: console [ttyS0] disabled  
10000000.serial: ttyS0 at MMIO 0x10000000 (irq = 62, base_baud = 1500000) is a 16550A  
printk: console [ttyS0] enabled  
dwmmc_starfive 16020000.mmc: IDMAC supports 32-bit address mode.  
dwmmc_starfive 16020000.mmc: Using internal DMA controller.  
dwmmc_starfive 16020000.mmc: Version ID is 290a  
dwmmc_starfive 16020000.mmc: DW MMC controller at irq 69,32 bit host data width,32 deep fifo  
mmc_host mmc1: card is polling.  
mmc_host mmc1: Bus speed (slot 0) = 45511111Hz (slot req 400000Hz, actual 399220HZ div = 57)  
designware-i2s: probe of 100e0000.i2s failed with error -110  
mmc_host mmc1: Bus speed (slot 0) = 45511111Hz (slot req 50000000Hz, actual 45511111HZ div = 0)  
mmc1: new high speed SDXC card at address aaaa  
mmcblk1: mmc1:aaaa SD64G 59.5 GiB  
mmcblk1: p1 p2  
designware-i2s: probe of 120b0000.i2s failed with error -110  
designware-i2s: probe of 120c0000.i2s failed with error -110  
ssp-pl022 10060000.spi: ARM PL022 driver, device ID: 0x00041022  
ssp-pl022 10060000.spi: mapped registers from 0x0000000010060000 to 00000000b872ca6c  
axp20x-i2c 5-0036: AXP20x variant AXP15060 found  
axp20x-i2c 5-0036: AXP20X driver loaded  
i2c 6-0010: Fixed dependency cycle(s) with /soc/csi@19800000/ports/port@0/endpoint  
imx219 6-0010: failed to read chip id 219  
imx219: probe of 6-0010 failed with error -5  
starfive-dphy-rx 19820000.phy: supply mipi_0p9 not found, using dummy regulator  
cdns-csi2rx 19800000.csi: Probed CSI2RX with 2/4 lanes, 4 streams, external D-PHY  
dwmmc_starfive 16010000.mmc: IDMAC supports 32-bit address mode.  
dwmmc_starfive 16010000.mmc: Using internal DMA controller.  
dwmmc_starfive 16010000.mmc: Version ID is 290a  
dwmmc_starfive 16010000.mmc: DW MMC controller at irq 91,32 bit host data width,32 deep fifo  
mmc_host mmc0: card is non-removable.  
clk: Disabling unused clocks  
starfive-hdmi 29590000.hdmi: [drm:starfive_hdmi_probe] registered Starfive HDMI I2C bus driver success  
verisilicon display-subsystem: bound 29400000.lcd-controller (ops 0xffffffff80e85398)  
verisilicon display-subsystem: bound 29590000.hdmi (ops 0xffffffff80e86178)  
verisilicon display-subsystem: bound dsi_encoder (ops 0xffffffff80e85f70)  
[drm] Initialized verisilicon 1.0.0 20230516 for display-subsystem on minor 0  
ALSA device list:  
 #0: StarFive-PWMDAC-Sound-Card  
mmc_host mmc0: Bus speed (slot 0) = 45511111Hz (slot req 400000Hz, actual 399220HZ div = 57)  
Waiting for root device ...  
/dev/root: Can't open blockdev  
VFS: Cannot open root device "" or unknown-block(0,0): error -6  
Please append a correct "root=" boot option; here are the available partitions:  
b300        62367744 mmcblk1    
driver: mmcblk  
 b301          524288 mmcblk1p1 f512e4f7-8d07-486b-be1d-c181a03ee848  
  
 b302        61841408 mmcblk1p2 d0f1e6f6-501c-4bce-b3c3-553dc8404ba8  
  
List of all bdev filesystems:  
ext3  
ext2  
ext4  
vfat  
msdos  
exfat  
ntfs  
btrfs  
  
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)  
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.6.0-g076ede06c00a #1  
Hardware name: StarFive VisionFive 2 v1.3B (DT)  
Call Trace:  
[<ffffffff8000551e>] dump_backtrace+0x1c/0x24  
[<ffffffff8085b11a>] show_stack+0x2c/0x38  
[<ffffffff8086f5b0>] dump_stack_lvl+0x3c/0x54  
[<ffffffff8086f5dc>] dump_stack+0x14/0x1c  
[<ffffffff8085b3d6>] panic+0xf2/0x28a  
[<ffffffff80a01506>] mount_root_generic+0x1f0/0x284  
[<ffffffff80a01782>] mount_root+0x1e8/0x204  
[<ffffffff80a01992>] prepare_namespace+0x1f4/0x23a  
[<ffffffff80a00f94>] kernel_init_freeable+0x1fe/0x218  
[<ffffffff80870cca>] kernel_init+0x1e/0x112  
[<ffffffff800034a2>] ret_from_fork+0xa/0x1c  
SMP: stopping secondary CPUs  
---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]---

panic了,报错是unable to mount root fs on unknown block(0,0).
之后要怎么弄呢。

/dev/root: Can't open blockdev  
VFS: Cannot open root device "" or unknown-block(0,0): error -6  
Please append a correct "root=" boot option; here are the available partitions:  
b300        62367744 mmcblk1    
driver: mmcblk  
 b301          524288 mmcblk1p1 f512e4f7-8d07-486b-be1d-c181a03ee848  
  
 b302        61841408 mmcblk1p2 d0f1e6f6-501c-4bce-b3c3-553dc8404ba8  
  
List of all bdev filesystems:  
ext3  
ext2  
ext4  
vfat  
msdos  
exfat  
ntfs  
btrfs  
  
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)  
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.6.0-g076ede06c00a #1  
Hardware name: StarFive VisionFive 2 v1.3B (DT)  
Call Trace:  

根据这一小段判断需要给root=的kernel command line, U-Boot用bootargs环境变量放这个。尝试env set env save写进去
随便猜了个写法,没起…看一眼host机这玩意怎么配的…

$ cat /proc/cmdline    
BOOT_IMAGE=(hd1,gpt2)/vmlinuz-6.8.6-200.fc39.x86_64 root=UUID=207c2120-5b6c-4445-a787-b9fa903215c7 ro rhgb quiet

传了个UUID进去,那这里暂时也这么用试试
还是没起。去抄了一下腐竹作业,参考stackexchange, 使用PARTUUID试试

env set bootargs console=ttyS0,115200 debug rootwait earlycon=sbi root=PARTUUID=d0f1e6f6-501c-4bce-b3c3-553dc8404ba8

哦顺便试下env save

StarFive # env save  
Saving Environment to SPIFlash... Erasing SPI flash...Writing to SPI flash...done  
OK

尝试booti启动下,报错变了

...
starfive-hdmi 29590000.hdmi: [drm:starfive_hdmi_probe] registered Starfive HDMI I2C bus driver success  
verisilicon display-subsystem: bound 29400000.lcd-controller (ops 0xffffffff80e85398)  
verisilicon display-subsystem: bound 29590000.hdmi (ops 0xffffffff80e86178)  
verisilicon display-subsystem: bound dsi_encoder (ops 0xffffffff80e85f70)  
[drm] Initialized verisilicon 1.0.0 20230516 for display-subsystem on minor 0  
ALSA device list:  
 #0: StarFive-PWMDAC-Sound-Card  
mmc_host mmc0: Bus speed (slot 0) = 45511111Hz (slot req 400000Hz, actual 399220HZ div = 57)  
mmc_host mmc0: Bus speed (slot 0) = 45511111Hz (slot req 300000Hz, actual 299415HZ div = 76)  
EXT4-fs (mmcblk1p2): orphan cleanup on readonly fs  
EXT4-fs (mmcblk1p2): mounted filesystem 05352b53-42ba-4c67-91e3-89726adf48c5 ro with ordered data mode. Quota mode: disabled.  
VFS: Mounted root (ext4 filesystem) readonly on device 179:2.  
devtmpfs: error mounting -2  
Freeing unused kernel image (initmem) memory: 2188K  
Checked W+X mappings: passed, no W+X pages found  
rodata_test: all tests were successful  
Run /sbin/init as init process  
 with arguments:  
   /sbin/init  
 with environment:  
   HOME=/  
   TERM=linux  
Run /etc/init as init process  
 with arguments:  
   /etc/init  
 with environment:  
   HOME=/  
   TERM=linux  
Run /bin/init as init process  
 with arguments:  
   /bin/init  
 with environment:  
   HOME=/  
   TERM=linux  
Run /bin/sh as init process  
 with arguments:  
   /bin/sh  
 with environment:  
   HOME=/  
   TERM=linux  
Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst.  
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.6.0-g076ede06c00a #1  
Hardware name: StarFive VisionFive 2 v1.3B (DT)  
Call Trace:  
[<ffffffff8000551e>] dump_backtrace+0x1c/0x24  
[<ffffffff8085b11a>] show_stack+0x2c/0x38  
[<ffffffff8086f5b0>] dump_stack_lvl+0x3c/0x54  
[<ffffffff8086f5dc>] dump_stack+0x14/0x1c  
[<ffffffff8085b3d6>] panic+0xf2/0x28a  
[<ffffffff80870dbe>] _cpu_down+0x0/0x3d2  
[<ffffffff800034a2>] ret_from_fork+0xa/0x1c  
SMP: stopping secondary CPUs  
---[ end Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/admin-guide-

可能有用的参考文档睡醒再看…

VFS: Mounted root (ext4 filesystem) readonly on device 179:2.  
devtmpfs: error mounting -2  
Freeing unused kernel image (initmem) memory: 2188K  
Checked W+X mappings: passed, no W+X pages found 

怎么挂不上呢
醒了 查查rootfs是啥
似乎混淆了kernel与rootfs…以为根目录那一套东西是kernel里面自带的,但看起来不是。bootlin教程里启动kernel使用了nfs在本机做了一套rootfs, 嵌入式设备走网络挂载上去。这里姑且就抄一下作业…
参考VF1debian配置文档

sudo dnf install qemu-user-static
sudo dnf install qemu-user-binfmt
sudo dnf install debian-keyring
sudo dnf install systemd-container
sudo debootstrap --arch=riscv64 unstable /tmp/riscv-chroot https://deb.debian.org/debian

# 类似于chroot进去...
sudo systemd-nspawn -D /tmp/riscv-chroot/ -M debian --bind-ro=/etc/resolv.conf
adduser <user>
apt install sudo
usermod -aG sudo <user>

ctrl D退出来,挂载sd卡,sudo cp -a /tmp/riscv-chroot/* /mnt/ 复制进sd卡,再走之前的手动启动流程就进系统了。