FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

RISC-V向けLinuxをビルドしてSpikeで動かす

暫く前だが、RISC-V向けLinuxがリリースされていた。

ucb-bar/riscv-linux · GitHub

早速ビルドして使ってみよう!

もうRISC-V向けのコンパイラとかはビルドして持っているので、本当に、上記のgithubに書いてあることを愚直にやっていけば良い。

最終的に、Linuxのビルドディレクトリにvmlinuxが完成する。さて、これをどうするんだ?(Linuxのビルドが分かっていない)

spike +disk=path/to/root.img vmlinux

root.imgの意味が分かっていなかったのだが、調べてみるとLinuxのディスクイメージっぽいね。カーネルとハードディスクは別物で、ファイルシステムだけ別にイメージを用意するという訳か。 なるほど。

という訳で、早速作ってみる。参考にするのは

The Linux/RISC-V Installation Manual

いやあ、何でも揃っていて幸せだ(笑)

が、どうやら失敗したらしい?(詳細をログに取っていなかった...)ので、spike (RISC-Vの命令セットシミュレータ)で実行しても、 なんだかうまく行かない。

↓なんとなく起動したの図。ところがディスクを読もうとしてコケる。

$ spike +disk=root.bin ../linux-3.14.29/vmlinux
warning: only got 2664431616 bytes of target mem (wanted 4294967296)
[    0.000000] Linux version 3.14.29-g21869dd (masayuki@ubuntu) (gcc version 4.9.2 (GCC) ) #1 Fri Feb 6 04:26:21 JST 2015
[    0.000000] Detected 0x9ed00000 bytes of physical memory
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x00000000-0x77ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x00000000-0x77ffffff]
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 244080
[    0.000000] Kernel command line: root=/dev/htifblk0
[    0.000000] PID hash table entries: 4096 (order: 2, 32768 bytes)
[    0.000000] Dentry cache hash table entries: 262144 (order: 8, 2097152 bytes)
[    0.000000] Inode-cache hash table entries: 131072 (order: 7, 1048576 bytes)
[    0.000000] Sorting __ex_table...
[    0.000000] Memory: 1946936K/1966080K available (1711K kernel code, 133K rwdata, 360K rodata, 65K init, 241K bss, 19144K reserved)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS:8
[    0.150000] Calibrating delay using timer specific routine.. 200.56 BogoMIPS (lpj=1002835)
[    0.150000] pid_max: default: 32768 minimum: 301
[    0.150000] Mount-cache hash table entries: 4096 (order: 2, 32768 bytes)
[    0.150000] Mountpoint-cache hash table entries: 4096 (order: 2, 32768 bytes)
[    0.150000] devtmpfs: initialized
[    0.150000] NET: Registered protocol family 16
[    0.150000] bio: create slab <bio-0> at 0
[    0.150000] Switched to clocksource riscv_clocksource
[    0.160000] NET: Registered protocol family 2
[    0.160000] TCP established hash table entries: 16384 (order: 4, 131072 bytes)
[    0.160000] TCP bind hash table entries: 16384 (order: 4, 131072 bytes)
[    0.160000] TCP: Hash tables configured (established 16384 bind 16384)
[    0.160000] TCP: reno registered
[    0.160000] UDP hash table entries: 1024 (order: 2, 32768 bytes)
[    0.160000] UDP-Lite hash table entries: 1024 (order: 2, 32768 bytes)
[    0.160000] NET: Registered protocol family 1
[    0.160000] futex hash table entries: 256 (order: -1, 6144 bytes)
[    0.160000] io scheduler noop registered
[    0.160000] io scheduler cfq registered (default)
[    0.220000] htifcon htif1: detected console
[    0.220000] console [htifcon0] enabled
[    0.220000] htifblk htif2: detected disk
[    0.220000] htifblk htif2: added htifblk0
[    0.220000] TCP: cubic registered
[    0.230000] VFS: Mounted root (ext2 filesystem) readonly on device 254:0.
[    0.230000] devtmpfs: mounted
[    0.230000] Freeing unused kernel memory: 64K (ffffffff80002000 - ffffffff80012000)
init: can't open '/': Function not implemented

うーん。だんだん面倒になってきたので、root.binを直接ダウンロードして確かめてみることにする。 ちなみにデフォルトで作られているroot.binは、

Getting Started - RISC-V

にリンクが張られている。便利!

spike +disk=./root.bin ../linux-3.14.29/vmlinux
warning: only got 2202009600 bytes of target mem (wanted 4294967296)
[    0.000000] Linux version 3.14.29-g21869dd (masayuki@ubuntu) (gcc version 4.9.2 (GCC) ) #1 Fri Feb 6 04:26:21 JST 2015
[    0.000000] Detected 0x83400000 bytes of physical memory
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x00000000-0x77ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x00000000-0x77ffffff]
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 244080
[    0.000000] Kernel command line: root=/dev/htifblk0
[    0.000000] PID hash table entries: 4096 (order: 2, 32768 bytes)
[    0.000000] Dentry cache hash table entries: 262144 (order: 8, 2097152 bytes)
[    0.000000] Inode-cache hash table entries: 131072 (order: 7, 1048576 bytes)
[    0.000000] Sorting __ex_table...
[    0.000000] Memory: 1946936K/1966080K available (1711K kernel code, 133K rwdata, 360K rodata, 65K init, 241K bss, 19144K reserved)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS:8
[    0.150000] Calibrating delay using timer specific routine.. 200.56 BogoMIPS (lpj=1002835)
[    0.150000] pid_max: default: 32768 minimum: 301
[    0.150000] Mount-cache hash table entries: 4096 (order: 2, 32768 bytes)
[    0.150000] Mountpoint-cache hash table entries: 4096 (order: 2, 32768 bytes)
[    0.150000] devtmpfs: initialized
[    0.150000] NET: Registered protocol family 16
[    0.150000] bio: create slab <bio-0> at 0
[    0.150000] Switched to clocksource riscv_clocksource
[    0.160000] NET: Registered protocol family 2
[    0.160000] TCP established hash table entries: 16384 (order: 4, 131072 bytes)
[    0.160000] TCP bind hash table entries: 16384 (order: 4, 131072 bytes)
[    0.160000] TCP: Hash tables configured (established 16384 bind 16384)
[    0.160000] TCP: reno registered
[    0.160000] UDP hash table entries: 1024 (order: 2, 32768 bytes)
[    0.160000] UDP-Lite hash table entries: 1024 (order: 2, 32768 bytes)
[    0.160000] NET: Registered protocol family 1
[    0.160000] futex hash table entries: 256 (order: -1, 6144 bytes)
[    0.160000] io scheduler noop registered
[    0.160000] io scheduler cfq registered (default)
[    0.220000] htifcon htif1: detected console
[    0.220000] console [htifcon0] enabled
[    0.220000] htifblk htif2: detected disk
[    0.220000] htifblk htif2: added htifblk0
[    0.220000] TCP: cubic registered
[    0.230000] VFS: Mounted root (ext2 filesystem) readonly on device 254:0.
[    0.230000] devtmpfs: mounted
[    0.230000] Freeing unused kernel memory: 64K (ffffffff80002000 - ffffffff80012000)
/sbin/init: error while loading shared libraries: libc.so.6: cannot open shared object file: Error 38
[    0.240000] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00007f00
[    0.240000]
[    0.240000] CPU: 0 PID: 1 Comm: init Not tainted 3.14.29-g21869dd #1
[    0.240000] Call Trace:
[    0.240000] [<ffffffff80013e74>] walk_stackframe+0x0/0xcc
[    0.240000] [<ffffffff801b9ea8>] panic+0xb4/0x1c4
[    0.240000] [<ffffffff800189bc>] do_exit+0x730/0x734
[    0.240000] [<ffffffff80018a34>] do_group_exit+0x38/0x98
[    0.240000] [<ffffffff80018a90>] do_group_exit+0x94/0x98
[    0.240000] [<ffffffff80018aac>] SyS_exit_group+0x18/0x1c
[    0.240000] [<ffffffff800834a4>] SyS_readv+0xc4/0xc8
[    0.240000] [<ffffffff80012fbc>] handle_syscall+0x30/0x34

あれれ、今度はlibc.so.6が無いと言われてしまった。。。とりあえず今日はここまで。 例によって、root.binをmount下ら中が見えるかな??