Skip to content

Commit c63ab6c

Browse files
committed
Document the new "sifive" board, and how to compile a compatible kernel
1 parent 6998eeb commit c63ab6c

File tree

2 files changed

+76
-9
lines changed

2 files changed

+76
-9
lines changed

README.md

+72-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Prerequisites:
4343
Jump to Method 1 if you want full-system simulation, or Method 2a/b for linux-user
4444
mode.
4545

46-
### Method 1 \(Full-System Simulation\):
46+
### Method 1a \(Full-System Simulation using the Spike board\):
4747

4848
####Step 1: Build QEMU
4949

@@ -85,9 +85,79 @@ and then hit `ctrl-a x`. Otherwise, the root filesystem will likely be corrupted
8585
Support for other HTIF-based devices has been removed from [riscv-linux]; as a
8686
result, QEMU no longer supports them either.
8787

88+
### Method 1b \(Full-System Simulation compatible with the SiFive U500 SDK \):
89+
90+
(this is very incomplete, and is based mostly on software reverse engineering)
91+
92+
#### Step 1: Build QEMU
93+
94+
(The same QEMU build supports both boards.)
95+
96+
$ git clone https://github.com/riscv/riscv-qemu
97+
$ cd riscv-qemu
98+
$ git submodule update --init pixman
99+
$ ./configure --target-list=riscv64-softmmu,riscv32-softmmu [--prefix=INSTALL_LOCATION]
100+
$ make
101+
$ [make install] # if you supplied prefix above
102+
103+
#### Step 2: Compile the boot image
104+
105+
The following packages are used above and beyond what is in a minimal Fedora 24 image:
106+
107+
```
108+
dnf install @buildsys-build git wget texinfo bison flex bc python perl-Thread-Queue vim-common
109+
```
110+
111+
Download the SDK (this is tested for rev f3a86d9664d821408318602d7f99e6aaf1e2cb4b):
112+
113+
```
114+
git clone --recursive https://github.com/sifive/freedom-u-sdk
115+
```
116+
117+
Patch to allow the image to boot on emulated hardware that supports floating point, apply this in the `riscv-pk` directory:
118+
119+
```
120+
diff --git a/Makefile.in b/Makefile.in
121+
index f885b30..8babada 100644
122+
--- a/Makefile.in
123+
+++ b/Makefile.in
124+
@@ -84,7 +84,7 @@ VPATH := $(addprefix $(src_dir)/, $(sprojs_enabled))
125+
# - CXXFLAGS : flags for C++ compiler (eg. -Wall,-g,-O3)
126+
127+
CC := @CC@
128+
-CFLAGS := @CFLAGS@ $(CFLAGS) -DBBL_PAYLOAD=\"$(bbl_payload)\" -msoft-float
129+
+CFLAGS := @CFLAGS@ $(CFLAGS) -DBBL_PAYLOAD=\"$(bbl_payload)\"
130+
COMPILE := $(CC) -MMD -MP $(CFLAGS) \
131+
$(sprojs_include)
132+
# Linker
133+
```
134+
135+
Build:
136+
137+
```
138+
make -j4
139+
```
140+
141+
(This step took roughly 20 minutes and created 9.3G of files.)
142+
143+
#### Step 3: Run QEMU
144+
145+
To boot Linux (assuming you are in the `riscv-qemu` directory):
146+
147+
$ ./riscv64-softmmu/qemu-system-riscv64 -kernel freedom-u-sdk/work/riscv-pk/bbl -nographic -machine sifive
148+
149+
Notes about arguments:
150+
* `-kernel bblvmlinuxinitramfs_dynamic`: This is the path to the binary to run. In this case, it contains the bbl bootloader, vmlinux, and an initramfs containing busybox.
151+
152+
Useful optional arguments:
153+
* `-m 2048M`: Set size of memory, in this example, 2048 MB
154+
155+
<!--**IMPORTANT**: To cleanly exit this system, you must enter `halt` at the prompt
156+
and then hit `ctrl-a x`. Otherwise, the root filesystem will likely be corrupted.-->
157+
88158
### Method 2a \(Fedora 24 Userland with User Mode Simulation, Recommended\):
89159

90-
To avoid having to build the RISC-V toolchain and programs yourself, use Stefan O'Rear's [RISC-V Fedora Docker Image](https://hub.docker.com/r/sorear/fedora-riscv-wip/) to obtain a Fedora 24 Userland for RISC-V, packaged with riscv-qemu.
160+
To avoid having to build the RISC-V toolchain and programs yourself, use Stefan O'Rear's [RISC-V Fedora Docker Image](https://hub.docker.com/r/sorear/fedora-riscv-wip/) to obtain a Fedora 25 Userland for RISC-V, packaged with riscv-qemu.
91161

92162
### Method 2b \(Manual User Mode Simulation\):
93163

hw/riscv/sifive_board.c

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
/*
2-
* QEMU RISC-V Generic Board Support
2+
* QEMU RISC-V SiFive U500 SDK Compatible Board
33
*
44
* Author: Sagar Karandikar, [email protected]
55
*
66
* This provides a RISC-V Board with the following devices:
77
*
8-
* 0) HTIF Test Pass/Fail Reporting (no syscall proxy)
9-
* 1) HTIF Console
10-
*
11-
* These are created by htif_mm_init below.
8+
* 0) UART comptible with that expected by the SiFive U500 SDK
129
*
1310
* This board currently uses a hardcoded devicetree that indicates one hart.
1411
*
@@ -52,7 +49,7 @@
5249
#include "qemu/error-report.h"
5350
#include "sysemu/block-backend.h"
5451

55-
#define TYPE_RISCV_SIFIVE_BOARD "riscv"
52+
#define TYPE_RISCV_SIFIVE_BOARD "sifive_board"
5653
#define RISCV_SIFIVE_BOARD(obj) OBJECT_CHECK(BoardState, (obj), TYPE_RISCV_SIFIVE_BOARD)
5754

5855
typedef struct {
@@ -265,7 +262,7 @@ static const TypeInfo riscv_sifive_board_device = {
265262

266263
static void riscv_sifive_board_machine_init(MachineClass *mc)
267264
{
268-
mc->desc = "RISC-V SiFive Dev Kit Board (Incomplete)";
265+
mc->desc = "RISC-V Board compatible with SiFive U500 SDK (incomplete)";
269266
mc->init = riscv_sifive_board_init;
270267
mc->max_cpus = 1;
271268
}

0 commit comments

Comments
 (0)