README.md 3.91 KB
Newer Older
hustccc's avatar
hustccc committed
# XV6-RISCV On K210
hustccc's avatar
hustccc committed
Run xv6-riscv on k210 board  
陆思彤's avatar
陆思彤 committed
[English](./README.md) | [中文](./README_cn.md)   
hustccc's avatar
hustccc committed

```
 (`-')           (`-')                   <-.(`-')                            
 (OO )_.->      _(OO )                    __( OO)                            
 (_| \_)--.,--.(_/,-.\  ,--.    (`-')    '-'. ,--.  .----.   .--.   .----.   
 \  `.'  / \   \ / (_/ /  .'    ( OO).-> |  .'   / \_,-.  | /_  |  /  ..  \  
  \    .')  \   /   / .  / -.  (,------. |      /)    .' .'  |  | |  /  \  . 
  .'    \  _ \     /_)'  .-. \  `------' |  .   '   .'  /_   |  | '  \  /  ' 
 /  .'.  \ \-'\   /   \  `-' /           |  |\   \ |      |  |  |  \  `'  /  
`--'   '--'    `-'     `----'            `--' '--' `------'  `--'   `---''   
```

陆思彤's avatar
陆思彤 committed
![run-k210](./img/xv6-k210_run.gif)  
hustccc's avatar
hustccc committed

hustccc's avatar
hustccc committed
## Dependencies
hustccc's avatar
hustccc committed
+ `k210 board` or `qemu-system-riscv64`
hustccc's avatar
hustccc committed
+ RISC-V Toolchain: [riscv-gnu-toolchain](https://github.com/riscv/riscv-gnu-toolchain.git)
hustccc's avatar
hustccc committed

hustccc's avatar
hustccc committed
## Installation
hustccc's avatar
hustccc committed
```bash
陆思彤's avatar
陆思彤 committed
git clone https://github.com/HUST-OS/xv6-k210
hustccc's avatar
hustccc committed
```
hustccc's avatar
hustccc committed

陆思彤's avatar
陆思彤 committed
## Run on k210 board
hustccc's avatar
hustccc committed
First you need to connect your k210 board to your PC.  
陆思彤's avatar
陆思彤 committed
And check the `USB serial port` (In my situation it will be `ttyUSB0`):  
hustccc's avatar
hustccc committed
```bash
ls /dev/ | grep USB
```
陆思彤's avatar
陆思彤 committed
Build the kernel and user programs:
hustccc's avatar
hustccc committed
```bash
cd xv6-k210
make build
```
陆思彤's avatar
陆思彤 committed
Instead of the original file system, xv6-k210 runs with FAT32. You might need an SD card with FAT32 format.  
陆思彤's avatar
陆思彤 committed
Your SD card should NOT keep a partition table. To start `shell` and other user programs, you need to copy them into your SD card.  
First, connect and mount your SD card (SD card reader required).
陆思彤's avatar
陆思彤 committed
```bash
陆思彤's avatar
陆思彤 committed
ls /dev/ # To check your SD device
mount <your SD device name> <mount point>
make sdcard dst="SD card mount point"
umount <mount point>
陆思彤's avatar
陆思彤 committed
```
陆思彤's avatar
陆思彤 committed
Then, insert the SD card to your k210 board and run:
hustccc's avatar
hustccc committed
```bash
hustccc's avatar
hustccc committed
make run
```
Sometimes you should change the `USB serial port`:  
```bash
make run k210-serialport=`Your-USB-port`(default by ttyUSB0)
hustccc's avatar
hustccc committed
```
hustccc's avatar
hustccc committed
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#)  
hustccc's avatar
hustccc committed

hustccc's avatar
hustccc committed
## Run on qemu-system-riscv64
陆思彤's avatar
陆思彤 committed
First, make sure `qemu-system-riscv64` is installed on your system.  
陆思彤's avatar
陆思彤 committed
Second, make a disk image file with FAT32 file system.
陆思彤's avatar
陆思彤 committed
```bash
陆思彤's avatar
陆思彤 committed
make fs
hustccc's avatar
hustccc committed
```
陆思彤's avatar
陆思彤 committed
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.
hustccc's avatar
hustccc committed

陆思彤's avatar
陆思彤 committed
Finally, start running.
hustccc's avatar
hustccc committed
```bash
陆思彤's avatar
陆思彤 committed
make run platform=qemu
hustccc's avatar
hustccc committed
```

陆思彤's avatar
陆思彤 committed
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:
陆思彤's avatar
陆思彤 committed

- Ctrl-H -- backspace  
- Ctrl-U -- kill a line  
- Ctrl-D -- end of file (EOF)  
- Ctrl-P -- print process list  
hustccc's avatar
hustccc committed

陆思彤's avatar
陆思彤 committed
## 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)).

hustccc's avatar
hustccc committed
## 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
Artyom Liu's avatar
Artyom Liu committed
- [x] Process management
陆思彤's avatar
陆思彤 committed
- [x] File system
- [x] User program
- [X] Steady keyboard input(k210)
hustccc's avatar
hustccc committed

hustccc's avatar
hustccc committed
## TODO
See Issues.
hustccc's avatar
hustccc committed