Skip to content

Commit 0b99199

Browse files
author
ipacman
committed
Add more formal support for VF2 board using config options in param.h. Update the README files with detail on how to configure.
1 parent 58fc284 commit 0b99199

File tree

9 files changed

+6714
-6632
lines changed

9 files changed

+6714
-6632
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ OBJS += \
3939
ifeq ($(runtime_config), sbi)
4040
OBJS += \
4141
$K/sbi.o \
42-
$K/ram_disk.o
42+
$K/ram_disk.o \
43+
$K/sbi_uart.o
4344
else
4445
OBJS += \
4546
$K/plic.o \
@@ -177,7 +178,7 @@ fs.img: mkfs/mkfs README $(UPROGS)
177178
clean:
178179
rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \
179180
*/*.o */*.d */*.asm */*.sym \
180-
$U/initcode $U/initcode.out $K/kernel fs.img \
181+
$U/initcode $U/initcode.out $K/kernel $K/kernel.bin fs.img \
181182
mkfs/mkfs .gdbinit \
182183
$U/usys.S \
183184
$(UPROGS)

README-opensbi-unmatched.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,34 @@
22

33
This branch captures changes made to support a sifive-unmatched board running opensbi (its default configuration).
44

5-
The code also appears to run unmodified on StarFive Vision 5 2 (v1.30 board). See additional notes on that in
6-
README-opensbi-vision5-2.md.
5+
The code can run on StarFive VisionFive 2 (v1.30 board). See additional notes on that in README-opensbi-vision5-2.md and select the desired configuration option in param.h as further described below.
76

87
The default xv6 release supports machine mode (only) so this would not run on unmatched without replacing its Uboot-SPL
98

10-
While that may be a useful exercise, this approach allows a user to run/debug a stock/unmodified unmatched board
11-
or (hopefully) any board that runs uboot (with sbi).
9+
While that may be a useful exercise, this approach allows a user to run xv6 using the platform distributed uboot without change.
1210

1311
The other problem with messing with the SPL is it contains all the board (e.g. DDR ram) initialization code. So, effectively,
14-
what we are doing here is interrupting Linux boot by pressing a key while it is in uboot and loading this image
15-
instead of Linux. Either run in RISCV supervisor mode and make use of the memory resident sbi that uboot and Linux uses.
12+
what we are doing here is interrupting Linux boot by pressing a key while it is in uboot and loading this image instead of Linux.
1613

17-
The modifications are fairly minor with a define selection in Makefile and a corresponding one in param.h.
14+
Both xv6 and Linux run in supervisor mode and have no direct access to RISCV machine mode.
1815

19-
- RUNTIME_SBI -- enables branch specific changes relating to OpenSBI
16+
The modifications (from distribution xv6) are fairly minor with a define selection in Makefile and a corresponding one in param.h:
17+
```
18+
RUNTIME_SBI -- enables branch specific changes relating to the OpenSBI port
19+
```
2020

2121
# Quick Start
2222

23-
Interrupt the Unmatched boot process by pressing a key on the USB UART debug terminal while it is in Uboot. This starts
23+
Prior to make, in param.h, select BOARD_UNMATCHED and deselect BOARD_VF2 for the Unmatched version.
24+
```
25+
#define BOARD_UNMATCHED
26+
//#define BOARD_VF2
27+
```
28+
In param.h, optionally select POLL_UART0_DIRECT to poll UART0 for console receive characters within xv6 (rather than use SBI for console polling). Either option works on the Unmatched board but it does make a difference on the VF2 board depending on its SBI version.
29+
30+
For convenience, the v0.2 release contains both "pure SBI" and "Uart0 direct" binaries (and elf files in case using Jtag). See the README file in the release for additional comments.
31+
32+
To run, interrupt the Unmatched boot process by pressing a key on the USB UART debug terminal while it is in Uboot. This starts
2433
the uboot command interface where it is possible to load and run a binary file (the xv6 kernel binary given as a release or
2534
produced via recompile of the source code).
2635

@@ -99,7 +108,7 @@ done in this version.
99108

100109
Here I list stuff that I have not yet resolved
101110

102-
## An oddity with SMP
111+
## A possible oddity with SMP
103112

104113
This version launches all 4 U74 cores (Harts) and they seem functional. But I'm not yet sure if there is a problem. I would have expected
105114
the cores to be at a "wfi" instruction awaiting an interrupt (keypress or timer) when idle. I believe the initial core
@@ -115,6 +124,7 @@ are cleverly written with expected results (including for faults).
115124

116125
I've met my match with the failure of one particular test on unmatched: sbrkmuch() within usertests.c. This test runs fine:
117126

127+
- on the VF2 board
118128
- occasionally (unmodified). Run the test a few times in a row from the command prompt.
119129
- when run standalone (via command line parameter to just run sbrkmuch).
120130
- when its moved or called differently from its original version.

README-opensbi-vision5-2.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
# Notes about this branch and StarFive Vision 5 (2) or VF2 board
22

3-
The exact same binary as released for the unmatched appears to run on this board. Very little testing has been done so far but I wanted to note the following:
3+
Prior to make, in param.h, select BOARD_VF2 and deselect BOARD_UNMATCHED for the VF2 version.
4+
```
5+
//#define BOARD_UNMATCHED
6+
#define BOARD_VF2
7+
```
8+
In param.h, also select POLL_UART0_DIRECT to poll UART0 for console receive characters within xv6 (rather than use SBI for console polling).
9+
10+
Early versions of VF2 firmware supported pure SBI but this option sidesteps the issue by talking directly to the UART for console receive characters.
411

5-
- The usertests issues described in the unmatched README either do not happen or happen with less frequency. In other words, the problem with sbrkmuch() has not yet been observed.
6-
- Its possible/likely that the interrupt rate is different on this board and therefore an adjustment is needed to 'TIMERINTCNT' in param.h.
7-
- To date, I've only tried loading the code with Jtag. But I have no reason to believe that the uboot binary load/run will not work. Issue is my VF2 board is not as well controlled as the version on the unmatched board.
12+
For convenience, the v0.2 release contains both "pure SBI" and "Uart0 direct" binaries (and elf files in case using Jtag). See the README file in the release for additional comments.
13+
14+
- The usertests issues described in the unmatched README do not happen on VF2 board.
15+
- Selecting BOARD_VF2 adjusts the timer interrupt rate to compensate for observed higher timer clock frequency.
816
- I'm using a different Jtag adapter for the VF2 board since I didnt want to move the Jlink EDU (old version) off of the unmatched yet. I'm specifically using an FTDI FT2232H-56Q minimodule. I'll include a working Jtag config that I'm using in the Jtag directory.
917

10-
## Errata (hopefully temporary)
18+
## Errata
1119

12-
While trying to verify that the binary (non-Jtag) xv6 kernel.bin file runs, I managed to boot my SD card into Linux, transfer the kernel.bin file to the
13-
SD card and attempt to boot it from next uboot startup.
20+
As described above, the 'pure sbi' VF2 configuration does not process console keyboard input correctly with recent board firmare.
1421

1522
While it boots, there is something wrong with the keyboard input -- I get an SBI error with each keypress:
1623

@@ -28,18 +35,15 @@ This one works fine:
2835
U-Boot SPL 2021.10 (Feb 12 2023 - 18:15:33 +0800)
2936
```
3037

31-
Versus the newer version:
32-
This one reports the aforementioned error.
38+
The newer version reports the aforementioned error.
3339

3440
```
3541
U-Boot SPL 2021.10 (Sep 19 2024 - 15:43:53 +0800)
3642
```
3743

38-
I'll try to figure out what is different. Also, the interrupt rate is faster, so in test code I changed TIMERINTCNT to 400000 (not checked in) to reduce the interrupt rate to approximately 10x per second.
39-
40-
Finally, the VF2 board has a different DDR memory map from siFive unmatched board but its kernel.bin load address (0x80400000) is still within valid space with plenty of headroom. The code really should be recompiled for something around 0x40xxxxxx where xxxxxx leaves room for SBI that loads at 0x40000000.
44+
The VF2 board has a different DDR memory map from siFive unmatched board but its kernel.bin load address (0x80400000) is still within valid space with plenty of headroom. The code really should be recompiled for something around 0x40xxxxxx where xxxxxx leaves room for SBI that loads at 0x40000000.
4145

42-
I dont know why, but it took a long time to find the memory map published, it was in the JH7110 "Technical Reference Manual"
46+
I dont know why, but it took a long time to locate the VF2 memory map. It is in the JH7110 "Technical Reference Manual"
4347

4448
```
4549
https://doc-en.rvspace.org/JH7110/TRM/JH7110_TRM/system_memory_map.html

kernel/defs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ void virtio_disk_intr(void);
189189
void ram_disk_init(void);
190190
void ram_disk_rw(struct buf*, int write);
191191

192+
// sbi_uart.c
193+
void sbi_poll_uart0(void);
194+
192195
// start.c
193196
void timerinit(void);
194197

kernel/memlayout.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
// PHYSTOP -- end RAM used by the kernel
1919

2020
// qemu puts UART registers here in physical memory.
21+
#include "param.h"
2122

22-
#ifdef RUNTIME_SBI
23+
#ifdef BOARD_UNMATCHED
2324
#define UART0 0x10010000L
2425
#define UART0_IRQ 32
2526
#else

kernel/param.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,26 @@
2222
#define MAXPATH 128 // maximum file path name
2323
#define USERSTACK 1 // user stack pages
2424
#define BSIZE 1024 // block size
25+
26+
// SBI default uses API for console input. However
27+
// POLL_UART0_DIRECT is needed on VF2 board due to SBI bug (polls Uart register directly)
28+
// The scheme also works on UNMATCHED board, but select proper BOARD to remap hardware
29+
30+
#define POLL_UART0_DIRECT
31+
32+
// Choose either BOARD_VF2 or BOARD_UNMATCHED but not both else #error
33+
//#define BOARD_UNMATCHED
34+
#define BOARD_VF2
35+
36+
// The following enforces either-or seletion of board (else redefined error)
37+
#ifdef BOARD_VF2
38+
#define TIMERINTCNT 400000 // counter increment until next interrupt -- JH7110
39+
#endif
40+
41+
#ifdef BOARD_UNMATCHED
2542
#define TIMERINTCNT 100000 // counter increment until next interrupt
43+
#endif
44+
2645
#else
2746
#define NPROC 64 // maximum number of processes
2847
#define NCPU 8 // maximum number of CPUs

0 commit comments

Comments
 (0)