RISC-VのLinuxブート環境を構築したので、次にこれをRTL環境で実行している。
Spikeのシミュレーション環境を見ると、OpenSBIによってブート処理が始まった後、Linuxカーネルを0x8020_0000に展開してからブート処理がスタートするようだ。
カーネルイメージは非常に大きいので、これまでのELFファイルのように外部から1バイトずつ流し込んでいては非常に時間がかかる。
カーネルのイメージファイルをhexに変換して、それを$readmemhで読み込むことでイメージファイルのロードを高速化する。
# 512ビット幅のhexファイルに変換する。 ../../dts/bin2hex.py --bit-width 512 Image image_w64.hex
initial begin if (msrh_conf_pkg::ICACHE_DATA_W == 128) begin $readmemh ("../../../tests/linux/image_w16.hex", r_ram); end else if (msrh_conf_pkg::ICACHE_DATA_W == 256) begin $readmemh ("../../../tests/linux/image_w32.hex", r_ram); end else if (msrh_conf_pkg::ICACHE_DATA_W == 512) begin $readmemh ("../../../tests/linux/image_w64.hex", r_ram); end end
あとはひたすらRTLシミュレーションを流していく。Atomic命令周りに複数のバグがあったが、それを修正していくと少しずつブートが進みだしている。 引き続きデバッグを進めていく。
OpenSBI v0.9
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : ucbbar,spike-bare
Platform Features : timer,mfdeleg
Platform HART Count : 1
Firmware Base : 0x80000000
Firmware Size : 100 KB
Runtime SBI Version : 0.2
Domain0 Name : root
Domain0 Boot HART : 0
Domain0 HARTs : 0*
Domain0 Region00 : 0x0000000080000000-0x000000008001ffff ()
Domain0 Region01 : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address : 0x0000000080200000
Domain0 Next Arg1 : 0x0000000082200000
Domain0 Next Mode : S-mode
Domain0 SysReset : yes
Boot HART ID : 0
Boot HART Domain : root
Boot HART ISA : rv64imacsu
Boot HART Features : scounteren,mcounteren
Boot HART PMP Count : 16
Boot HART PMP Granularity : 4
Boot HART PMP Address Bits: 54
Boot HART MHPM Count : 0
Boot HART MHPM Count : 0
Boot HART MIDELEG : 0x0000000000000222
Boot HART MEDELEG : 0x000000000000b109
[ 0.000000] Linux version 5.10.0 (root@buildkitsandbox) (riscv64-buildroot-linux-gnu-gcc.br_real (Buildroot 2022.08-353-geedd93f010) 11.3.0, GNU ld (GNU Binutils) 2.38) #2 SMP Tue Oct 4 03:10:27 UTC 2022
[ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
[ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
[ 0.000000] printk: bootconsole [sbi0] enabled
[ 0.000000] efi: UEFI not found.
[ 0.000000] Zone ranges:
[ 0.000000] DMA32 [mem 0x0000000080200000-0x00000000ffffffff]
[ 0.000000] Normal empty
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000080200000-0x00000000ffffffff]
[ 0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x00000000ffffffff]
