xv6-k210/README.md

128 lines
4.0 KiB
Markdown
Raw Normal View History

2020-10-21 19:18:46 +08:00
# XV6-RISCV On K210
2020-11-24 18:35:55 +08:00
Run xv6-riscv on k210 board
2021-04-15 23:50:56 +08:00
[English](./README.md) | [中文](./README_cn.md)
2020-11-24 18:35:55 +08:00
```
(`-') (`-') <-.(`-')
(OO )_.-> _(OO ) __( OO)
(_| \_)--.,--.(_/,-.\ ,--. (`-') '-'. ,--. .----. .--. .----.
\ `.' / \ \ / (_/ / .' ( OO).-> | .' / \_,-. | /_ | / .. \
\ .') \ / / . / -. (,------. | /) .' .' | | | / \ .
.' \ _ \ /_)' .-. \ `------' | . ' .' /_ | | ' \ / '
/ .'. \ \-'\ / \ `-' / | |\ \ | | | | \ `' /
`--' '--' `-' `----' `--' '--' `------' `--' `---''
```
2021-03-05 23:25:01 +08:00
![run-k210](./img/xv6-k210_run.gif)
2020-10-19 00:53:22 +08:00
2020-10-21 19:18:46 +08:00
## Dependencies
2020-12-13 07:05:52 +08:00
+ `k210 board` or `qemu-system-riscv64`
2020-12-13 18:33:18 +08:00
+ RISC-V Toolchain: [riscv-gnu-toolchain](https://github.com/riscv/riscv-gnu-toolchain.git)
2020-10-19 00:53:22 +08:00
2020-10-21 19:18:46 +08:00
## Installation
2020-11-07 03:13:59 +08:00
```bash
git clone https://github.com/HUST-OS/xv6-k210
2020-11-07 03:13:59 +08:00
```
2020-10-19 00:53:22 +08:00
2020-10-21 19:18:46 +08:00
## Build
2020-10-22 03:54:05 +08:00
First you need to connect your k210 board to your PC.
2020-12-13 07:05:52 +08:00
And check the `USB serial port`:
2020-11-07 03:12:44 +08:00
```bash
ls /dev/ | grep USB
```
2020-11-04 06:43:08 +08:00
In my situation it will be `ttyUSB0`
2020-10-22 03:54:05 +08:00
2020-11-07 03:12:44 +08:00
```bash
cd xv6-k210
make build
```
2020-10-19 00:53:22 +08:00
2020-12-13 07:05:52 +08:00
## Run on k210 board
2021-03-05 23:25:01 +08:00
Instead of the original file system, xv6-k210 runs with FAT32. You might need an SD card with FAT32 format.
To start `shell`, you need to rename the "_init" and "_sh" in the "/xv6-user" to "init" and "sh" after building,
2021-04-15 23:50:56 +08:00
then copy them to the root of your SD card.
Also, you can copy other programs start with "\_".
2021-03-09 16:02:02 +08:00
Or you can directly run the command as below with your SD card connected to your PC (SD card reader required).
Warning: this will format your SD card and clean your original data!
```bash
make sdcard sd="your SD card device's path"
```
2021-03-05 23:25:01 +08:00
To run on k210:
2020-11-07 03:12:44 +08:00
```bash
2020-12-13 07:05:52 +08:00
make run
```
Sometimes you should change the `USB serial port`:
```bash
make run k210-serialport=`Your-USB-port`(default by ttyUSB0)
2020-11-07 03:12:44 +08:00
```
2020-10-23 08:00:43 +08:00
Ps: Most of the k210-port in Linux is ttyUSB0, if you use Windows or Mac OS, this doc
may help you: [maixpy-doc](https://maixpy.sipeed.com/zh/get_started/env_install_driver.html#)
2020-10-19 00:53:22 +08:00
2020-12-13 07:05:52 +08:00
## Run on qemu-system-riscv64
2021-03-05 23:25:01 +08:00
First, make sure `qemu-system-riscv64` is installed on your system.
Second, make a disk image file with FAT32 file system.
2021-03-05 23:25:01 +08:00
```bash
make fs
2020-12-13 07:05:52 +08:00
```
It will generate a disk image file `fs.img`, and compile some user programs like `shell` then copy them into the `fs.img`.
As long as the `fs.img` exists, you don't need to do this every time before running, unless you want to update it.
2021-01-15 23:34:38 +08:00
2021-03-05 23:25:01 +08:00
Finally, start running.
2021-01-15 23:34:38 +08:00
```bash
2021-03-05 23:25:01 +08:00
make run platform=qemu
2021-01-15 23:34:38 +08:00
```
2021-03-05 23:25:01 +08:00
Ps: Press Ctrl + A then X to quit qemu.
## About shell
The shell commands are user programs, too. Those program should be put in a "/bin" directory in your SD card or the `fs.img`.
Now we support a few useful commands, such as `cd`, `ls`, `cat` and so on.
In addition, `shell` supports some shortcut keys as below:
2021-01-16 22:49:36 +08:00
- Ctrl-H -- backspace
- Ctrl-U -- kill a line
- Ctrl-D -- end of file (EOF)
- Ctrl-P -- print process list
2020-12-13 07:05:52 +08:00
2021-04-15 23:50:56 +08:00
## Add my programs on xv6-k210
1. Make a new C source file in `xv6-user/` like `myprog.c`, and put your codes;
2. You can include `user.h` to use the functions declared in it, such as `open`, `gets` and `printf`;
3. Add a line "`$U/_myprog\`" in `Makefile` as below:
```Makefile
UPROGS=\
$U/_init\
$U/_sh\
$U/_cat\
...
$U/_myprog\ # Don't ignore the leading '_'
```
4. Then make:
```bash
make userprogs
```
Now you might see `_myprog` in `xv6-user/` if no error detected. Finally you need to copy it into your SD (see [here](#run-on-k210-board))
or FS image (see [here](#run-on-qemu-system-riscv64)).
2020-11-07 03:12:44 +08:00
## Progress
- [x] Multicore boot
- [x] Bare-metal printf
- [x] Memory alloc
- [x] Page Table
- [x] Timer interrupt
- [x] S mode extern interrupt
- [x] Receive uarths message
- [x] SD card driver
2020-11-17 20:46:11 +08:00
- [x] Process management
2021-03-05 23:25:01 +08:00
- [x] File system
- [x] User program
2021-04-15 23:50:56 +08:00
- [X] Steady keyboard input(k210)
2020-11-02 20:20:31 +08:00
2020-10-21 19:18:46 +08:00
## TODO
2021-05-05 10:55:02 +08:00
Fix the bugs of U-mode exception on k210.
2021-01-15 23:34:38 +08:00