Porting XV6 on K210!

Overview

XV6-RISCV On K210

Run xv6-riscv on k210 board
English 中文

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

run-k210

Dependencies

Installation

git clone https://github.com/HUST-OS/xv6-k210

Build

First you need to connect your k210 board to your PC.
And check the USB serial port:

ls /dev/ | grep USB

In my situation it will be ttyUSB0

cd xv6-k210
make build

Run on k210 board

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, then copy them to the root of your SD card. Or you can directly run the command as below with your SD card connected.

Warning: this will format your SD card and clean your original data!

make sdcard sd="your SD card device's path"

To run on k210:

make run

Sometimes you should change the USB serial port:

make run k210-serialport=`Your-USB-port`(default by ttyUSB0)

Ps: Most of the k210-port in Linux is ttyUSB0, if you use Windows or Mac OS, this doc may help you: maixpy-doc

Run on qemu-system-riscv64

First, make sure qemu-system-riscv64 is installed on your system.
Second, make a disk image file with FAT32 file system.

make fs

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.

Finally, start running.

make run platform=qemu

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:

  • Ctrl-H -- backspace
  • Ctrl-U -- kill a line
  • Ctrl-D -- end of file (EOF)
  • Ctrl-P -- print process list

Progress

  • Multicore boot
  • Bare-metal printf
  • Memory alloc
  • Page Table
  • Timer interrupt
  • S mode extern interrupt
  • Receive uarths message
  • SD card driver
  • Process management
  • File system
  • User program
  • Steady keyboard input(k210)

TODO

Keyboard input on k210 platform.

Comments
  • K210 无法进行 SD 卡读取

    K210 无法进行 SD 卡读取

    K210 无法进行 SD 卡读取

    • 描述

      参考此 repo 实现的 SD 卡读写程序,在 sdcard_write_sector() 函数中出现 sdcard: invalid response token 错误。

    • 错误信息

      sdcard: invalid response token

    • 截图

      截屏2021-05-29 下午9.44.30

    • 复现

      clone https://gitlab.eduxiji.net/PTRNULL/simplekernel_oscomp_2021.git,按照 RUN.md 中的描述运行(K210)即可观察到。

    • diff

      代码位于 https://gitlab.eduxiji.net/PTRNULL/simplekernel_oscomp_2021/-/blob/master/src/drv/sdcard/sdcard.c

      1. 修改了数据类型

        uint8 -> uint8_t

        uint16 -> uint16_t

        uint32 -> uint32_t

        uint64 -> uint64_t

      2. 注释了锁相关代码

        注释了 static struct sleeplock sdcard_lock 相关定义,以及依赖它的函数。

    opened by MRNIU 6
  • ROM regions overlapping when running on qemu

    ROM regions overlapping when running on qemu

    When I tried to run the kernel on qemu, as a result, I got this error message below.

    qemu-system-riscv64: Some ROM regions are overlapping
    These ROM regions might have been loaded by direct user request or by default.
    They could be BIOS/firmware images, a guest kernel, initrd or some other file loaded into guest memory.
    Check whether you intended to load all this guest code, and whether it has been built to load to the correct addresses.
    
    The following two regions overlap (in the memory address space):
      ./bootloader/SBI/sbi-qemu ELF program header segment 0 (addresses 0x0000000080000000 - 0x00000000800193e8)
      fdt (addresses 0x0000000080000000 - 0x0000000080100000)
    make: *** [Makefile:152: run] Error 1
    

    It seems that there are some errors with the booting phase. Can you help me fix it? Thanks. Below are some of my compliling system informations.

    ..............                                     ********@kali 
                ..,;:ccc,.                             ------------- 
              ......''';lxO.                           OS: Kali GNU/Linux Rolling x86_64 
    .....''''..........,:ld;                           Host: VMware Virtual Platform None 
               .';;;:::;,,.x,                          Kernel: 5.16.0-kali5-amd64 
          ..'''.            0Xxoc:,.  ...              Uptime: 6 mins 
      ....                ,ONkc;,;cokOdc',.            Packages: 2991 (dpkg) 
     .                   OMo           ':ddo.          Shell: zsh 5.8.1 
                        dMc               :OO;         Resolution: 1718x900 
                        0M.                 .:o.       DE: Xfce 4.16 
                        ;Wd                            WM: Xfwm4 
                         ;XO,                          WM Theme: Kali-Dark 
                           ,d0Odlc;,..                 Theme: Kali-Dark [GTK2/3] 
                               ..',;:cdOOd::,.         Icons: Flat-Remix-Blue-Dark [GTK2/3] 
                                        .:d;.':;.      Terminal: qterminal 
                                           'd,  .'     Terminal Font: FiraCode 10 
                                             ;l   ..   CPU: Intel i7-9750H (8) @ 2.592GHz 
                                              .o       GPU: 00:0f.0 VMware SVGA II Adapter 
                                                c      Memory: 649MiB / 11940MiB 
                                                .'
                                                 .                             
                                                                               
    
    qemu-riscv64 version 5.0.0
    Copyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers
    
    QEMU emulator version 6.2.0 (Debian 1:6.2+dfsg-2)
    Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
    
    rustc 1.61.0-nightly (1bfe40d11 2022-03-18)
    
    riscv64-unknown-elf-gcc (gca312387ab1) 10.2.0
    Copyright (C) 2020 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
    opened by TianyiFranklinWang 4
  • 关于proc页表的合并

    关于proc页表的合并

    既然proc的kpagetable既有用户地址空间和内核地址空间,这样显得pagetable就多余了,在限制用户地址空间小于0x80000000的前提下,删除pagetable也能正常工作?这样每个进程的pagetable的0,1项对应用户地址空间的映射,后面的项对应内核空间的映射。只保留一个页表的话可以简化vm.c的代码?

    opened by ckf104 4
  • tf卡启动失败

    tf卡启动失败

    启动失败,提示不是fat32 然后我打印了tf卡的前512 可以看到后面有0x55 0xaa,但是前面的内容好像完全错了,我以为是我tf卡格式化有问题,然后我导出了tf卡前512 发现是对的,没有问题,有fat32标识,然后我以为是硬件pin脚不一致导致的,我对照了一下官方的,是这样的 但是这个工程中初始化是写在fpioa.c,是这样的 多了一个32号pin脚不明白是为什么(完全不懂硬件) 而且在初始化的时候片选是3,但是在这里片选却是7 但是我改成我想的样子后,连本来能读取的都读取不了,所以很困惑到底发生了什么,希望能帮忙解惑!

    opened by t812206236 2
  • 对fat32.c中eput函数实现的疑问

    对fat32.c中eput函数实现的疑问

    main主分支的eput函数实现是这样的

    void eput(struct dirent *entry)
    {
        acquire(&ecache.lock);
        if (entry != &root && entry->valid != 0 && entry->ref == 1) {
            // ref == 1 means no other process can have entry locked,
            // so this acquiresleep() won't block (or deadlock).
            acquiresleep(&entry->lock);
            entry->next->prev = entry->prev;
            entry->prev->next = entry->next;
            entry->next = root.next;
            entry->prev = &root;
            root.next->prev = entry;
            root.next = entry;
            release(&ecache.lock);
            if (entry->valid == -1) {       // this means some one has called eremove()
                etrunc(entry);
            } else {
                elock(entry->parent);        // 为什么不在此之前释放entry->lock ?
                eupdate(entry);
                eunlock(entry->parent);
            }
            releasesleep(&entry->lock);
    
            // Once entry->ref decreases down to 0, we can't guarantee the entry->parent field remains unchanged.
            // Because eget() may take the entry away and write it.
            struct dirent *eparent = entry->parent;
            acquire(&ecache.lock);
            entry->ref--;
            release(&ecache.lock);  // 在查看entry->ref == 0 之前释放是否安全?
            if (entry->ref == 0) {    
                eput(eparent);
            }
            return;
        }
        entry->ref--;
        release(&ecache.lock);
    }
    

    在函数第二次释放ecache.lock后才查看enrty->ref == 0 是否安全(原文件694行)? 设想进程B执行entry->ref--之后,ref变为0,释放了ecache.lock锁之后,另一个进程A调用eget函数尝试获取一个目录块,恰好eget选中了这个刚释放的目录块,此时ref=1,因此进程B不再执行eput(eparent)便返回,这样会导致eparent的ref计数出现问题?

    opened by ckf104 1
  • Segmentation fault (core dumped)

    Segmentation fault (core dumped)

    运行make sdcard、 $ make sdcard sd=/dev/sdc flashing into sd card... 524288+0 records in 524288+0 records out 268435456 bytes (268 MB, 256 MiB) copied, 0.974044 s, 276 MB/s

    连接板子,make run, $ make run 0+1 records in 0+1 records out 53335 bytes (53 kB, 52 KiB) copied, 0.00043795 s, 122 MB/s Segmentation fault (core dumped) make: *** [Makefile:148: run] Error 139

    opened by china-zyy 1
  • kernel\trap.c  kerneltrap函数内 152行判断语句的问题

    kernel\trap.c kerneltrap函数内 152行判断语句的问题

    原句是:
    if((sstatus & SSTATUS_SPP) == 0) panic("kerneltrap: not from supervisor mode");

    问题:(sstatus & SSTATUS_SPP) = 0 不是意味着sstatus第8位是0么?0意味着是用户态,说明中断是来自用户态,那么为什么要panic? 谢谢!

    opened by leo-frank 0
  • 向调度器引入任务的概念

    向调度器引入任务的概念

    在与@AtomHeartCoder讨论之后,我们认为可以在调度器中引入任务(Task)支持。任务控制块的一个草稿如下

    struct task {
    	struct list _node;                   // 与链表有关的域
    	struct proc *process;            // 指向自己的进程控制块
    	enum task_status status;     // 当前任务的运行状态
            int tid;                                   // 类似于PID,当前任务的ID
    	struct context context;          // 上下文,用于调度
    	struct trapframe *tf;              // 用于中断时保护现场
    }
    

    任务基于进程,不同的任务之间可能属于同一个进程。而一个进程控制块中主要是包含了当前进程的地址空间信息(页表和segment链表),属于同一个进程的任务共享这些信息,所以在调度器在这些任务之间进行调度时就不需要刷新TLB,这可以进一步地加快调度的速度。

    enhancement 
    opened by retrhelo 0
  • 重写SPI通信代码

    重写SPI通信代码

    一方面,Kendryte提供的spi.c对于xv6-k210的应用场景来说过于庞杂。原本的代码中考虑了很多在xv6-k210中大概率不会被用到的情况。另一方面,我们也希望通过重写spi.c来彻底消化SD卡驱动的协议栈。最后,我们还希望能够在新的代码中使用kmemalloc.c提供的动态内存分配功能。 但考虑到现有的spi.c模块其实跑得还挺好的,也许这项工作尚不太急?(笑

    opened by retrhelo 1
Releases(v0.1.0)
  • v0.1.0(Mar 23, 2021)

    第一个能在 k210 上运行 Shell 的版本,支持 Fat32 文件系统。
    nightly 版本,在 k210 平台上还存在一些比较神奇的 bug。

    Source code(tar.gz)
    Source code(zip)
Owner
无相之风-华中科技大学系统能力竞赛战队
null
MetaHook (https://github.com/nagist/metahook) porting for SvEngine (GoldSrc engine modified by Sven-Coop)

MetaHookSv This is a porting of MetaHook (https://github.com/nagist/metahook) for SvEngine (GoldSrc engine modified by Sven-Coop Team), mainly to keep

hzqst 65 Dec 16, 2022
Hobbyist Operating System targeting x86_64 systems. Includes userspace, Virtual File System, An InitFS (tarfs), Lua port, easy porting, a decent LibC and LibM, and a shell that supports: piping, file redirection, and more.

SynnixOS Epic Hobby OS targeting x86_64 CPUs, it includes some hacked together functionality for most essential OSs although, with interactivity via Q

RaidTheWeb 42 Oct 28, 2022
PillowResize library is a C++ porting of the resize method from the Pillow python library.

Pillow Resize Table of Contents Description Compilation Installation Usage Description PillowResize library is a C++ porting of the resize method from

Zuru Tech 47 Nov 17, 2022
After a few loose attempts at porting Source-games; here comes my first real one!

StanleyParable-Vita After a few loose attempts at porting Source-games; here comes my first real one! (For anyone who wonders what happened to the HL2

Sleppo04 4 Sep 21, 2021
Porting RT-Thread for Gowin GW1NSR-4C Soc GCC version

Porting RT-Thread for Gowin GW1NSR-4C Soc GCC version Hello everyone, this project based on RT-THREAD NANO 3.1.5 and GOWIN GW1NSR-4C Soc chip. The com

Ray 3 Apr 23, 2022
Porting example code from Windows 1.0 to 11

== Porting a Windows 1.0 16-bit to 32-bit (and 64-bit) Systems == This is the code documenting the changes requiring to port a Windows 1.0 application

Michael Casadevall 63 Dec 3, 2022
A LVGL porting for Cortex-M55 running on an Arm official FPGA prototyping development board called MPS3 (AN547)

A LVGL porting for Cortex-M55 running on an Arm official FPGA prototyping development board called MPS3 (AN547), see Figure 1. It is also possible to run the project template on an emulator called Corstone-300-FVP, which is free.

Gabriel Wang 7 Dec 7, 2022
Operating system project - implementing scheduling algorithms and some system calls for XV6 OS

About XV6 xv6 is a modern reimplementation of Sixth Edition Unix in ANSI C for multiprocessor x86 and RISC-V systems.

Amirhossein Rajabpour 22 Dec 22, 2022
Operating system project - implementing scheduling algorithms and some system calls for XV6 OS

About XV6 xv6 is a modern reimplementation of Sixth Edition Unix in ANSI C for multiprocessor x86 and RISC-V systems. It was created for pedagogical p

Amirhossein Rajabpour 22 Dec 22, 2022
Implementation of System V shared memory (a type of inter process communication) in xv6 operating system.

NOTE: we have stopped maintaining the x86 version of xv6, and switched our efforts to the RISC-V version (https://github.com/mit-pdos/xv6-riscv.git)

Viraj Jadhav 5 Feb 21, 2022
Implementation of mmap system call in xv6

NOTE: we have stopped maintaining the x86 version of xv6, and switched our efforts to the RISC-V version (https://github.com/mit-pdos/xv6-riscv.git)

Rohit Chaudhari 6 May 18, 2021
Port of MIT's xv6 OS to the Nezha RISC-V board with Allwinner D1 SoC

xv6 is a re-implementation of Dennis Ritchie's and Ken Thompson's Unix Version 6 (v6). xv6 loosely follows the structure and style of v6, but is impl

Michael Engel 62 Dec 12, 2022
xv6 kernel implementation, Operating systems project

XV6 implementation xv6 is a re-implementation of Dennis Ritchie's and Ken Thompson's Unix Version 6 (v6). xv6 loosely follows the structure and style

mirko 0 Nov 1, 2022
XV6 Labs - for Operating System

XV6 Labs - for Operating System Source: https://pdos.csail.mit.edu/6.828/2021/xv6.html Lab 1 Utilities Including some user-space programs sleep.c Noth

LanFear 1 Nov 5, 2021
Code for Kernel-Level thread Support for xv6

xv6 is a re-implementation of Dennis Ritchie's and Ken Thompson's Unix Version 6 (v6). xv6 loosely follows the structure and style of v6, but is impl

Shivaji Reddy 1 Nov 20, 2021
xv6 port to aarch64 virt board

xv6 is a re-implementation of Dennis Ritchie's and Ken Thompson's Unix Version 6 (v6). xv6 loosely follows the structure and style of v6, but is impl

mkei 7 Oct 18, 2022