Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port to milkv duo and lpi4a #2

Open
wants to merge 1 commit into
base: riscv
Choose a base branch
from

Conversation

xhackerustc
Copy link

xv6 ports to real riscv platforms 18:56:52 [57/9793]

port xv6 to Sophgo CV1800B platforms such as Milkv Duo, Sophgo SG00X platforms
such as Milkv-duo256, milkv Duo-S and T-HEAD TH1520 platforms such as Sipeed
Lichee Pi 4A. While Milkv Duo holds the highest priority porting effort.

Currently, peripherals such as uart, gpio, adc, pwm, i2c and spi are well
supported for milkv duo. Qemu and TH1520 only support uart. I also wrote
some userspace tools to demo the peripherals usage. Check below.

Build for milkv duo:

./build_for_milkv_duo.sh

the built img will be duo-imgtools/milkv-duo_sdcard.img, then burn it
to tf card on PC:
dd if=milkv-duo_sdcard.img of=/dev/sdX (take care "sdX" must be the
tfcard appeared on your PC, you have been warned!)

*gpio demo:
$ ./blink 5 //will link 5 loops

*adc demo:
ADC1 is used. Connect GP26 to GND
$ ./adc
$ adc raw: 0

then connect GP26 to 3v3(out).
$ ./adc
$ adc raw: 4095

*pwm demo:
PWM6 is used for demo. Connect a Light Emitting Diode(don't forget
proper resistance, I use a 100 ohm) to GP5, another peer connects to GND.
$ ./pwm 1000000 900000
$ ./pwm 1000000 800000
$ ./pwm 1000000 600000
$ ./pwm 1000000 500000
$ ./pwm 1000000 300000
$ ./pwm 1000000 200000
$ ./pwm 1000000 100000
and so on. The Diode light changes each time you modify the duty cycles...

*i2c demo: 18:56:52 [16/9793]
I2C0 is used for demo. I used max30102 sensor for demo. If you use different
I2C device, check the device manual for read and write details.
Connect GP0 to its SCL pin and GP1 to its SDA pin, don't forget GND and
VCC(connect to 3V3(out)
$ ./i2c 0x57 0xff
$ 0x15
$ ./i2c 0x57 0x21 1
$ ./i2c 0x57 0x1f
0xF
$ ./i2c 0x57 0x20
0x3
The integer temperature is 15, frac temperature is 0x3, so the tempearture
is about 15.19 centigrade. (plz check max30102 TRM for details)

*spi demo:
SPI2 is used for demo. I will demo external spi loop back test, this is
simliar as the spidev_test under linux. The demo will print the received
contents.
$ ./spi
$ 0 0 0 0 0 0 0 0 ...
Then connect GP7 and GP8
$ ./spi
$ 1 2 3 4 5 6 7 8 ...

Build for qemu:

git checkout kernel/config.h
make
make kernel/kernel.bin

Build for TH1520:

cp kernel/config.h.th1520 kernel/config.h
make
make kernel/kernel.bin

Build for SG200X:
Just replace the fip.bin then build as milkv duo ;)

@sunmin89
Copy link

sunmin89 commented Mar 6, 2024

你好, 在验证期间遇到一些问题:

  1. 对工具链版本有要求吗?比如:Xuantie-900-gcc-elf-newlib-x86_64-V2.6.1
  2. 对 genimage 有要求吗?比如:duo-buildroot-sdk-Duo-V1.0.7/buildroot-2021.05/output/milkv-duo_musl_riscv64/host/bin/genimage
  3. 进入系统报错,可否分析原因或者直接提供更细的编译说明
    这是 uart1 打印的开机 log
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2024.03.05 12:28:16 =~=~=~=~=~=~=~=~=~=~=~=
C.SCS/0/0.WD.URPL.SDI/25000000/6000000.BS/SD.PS.SD/0x0/0x1000/0x1000/0.PE.BS.SD/0x1000/0xba00/0xba00/0.BE.J.
FSBL Jb28g9:gf2df47913:2024-02-29T16:35:38+08:00
st_on_reason=d0000
st_off_reason=0
P2S/0x1000/0x3bc0da00.
SD/0xca00/0x1000/0x1000/0.P2E.
DPS/0xda00/0x2000.
SD/0xda00/0x2000/0x2000/0.DPE.
DDR init.
ddr_param[0]=0x78075562.
pkg_type=3
D3_1_4
DDR2-512M-QFN68
Data rate=1333.
DDR BIST PASS
PLLS.
PLLE.
C2S/0xfa00/0x83f40000/0x3600.
SD/0xfa00/0x3600/0x3600/0.RSC.
C2RET.:
 
[M1S.3/400x217350]0P0r/e0 xs8y0s0t0e0m0 0i0n/i0tx 1dbo0n0e0
.

RT: [1.346595]CVIRTOS Build Date:Feb 29 2024  (Time :16:35:37) 
RT: [1.352598]Post system init done
RT: [1.355913]create cvi task
RT: [1.358740][cvi_spinlock_init] succeess
RT: [1.362633]prvCmdQuRunTask run
SD/0x13000/0x1b000/0x1b000/0.ME.
L2/0x2e000.
SD/0x2e000/0x200/0x200/0.L2/0x414d3342/0xcafebfd8/0x80200000/0x23000/0x23000
COMP/1.
SD/0x2e000/0x23000/0x23000/0.DCP/0x80200020/0x1000000/0x81500020/0x23000/1.
DCP/0x4a307/0.
Loader_2nd loaded.
Use internal 32k
Jump to monitor at 0x80000000.
OPENSBI: next_addr=0x80200020 arg1=0x80080000
OpenSBI v0.9
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : Milk-V Duo
Platform Features         : mfdeleg
Platform HART Count       : 1
Platform IPI Device       : clint
Platform Timer Device     : clint
Platform Console Device   : uart8250
Platform HSM Device       : ---
Platform SysReset Device  : ---
Firmware Base             : 0x80000000
Firmware Size             : 132 KB
Runtime SBI Version       : 0.3

Domain0 Name              : root
Domain0 Boot HART         : 0
Domain0 HARTs             : 0*
Domain0 Region00          : 0x0000000074000000-0x000000007400ffff (I)
Domain0 Region01          : 0x0000000080000000-0x000000008003ffff ()
Domain0 Region02          : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address      : 0x0000000080200020
Domain0 Next Arg1         : 0x0000000080080000
Domain0 Next Mode         : S-mode
Domain0 SysReset          : yes

Boot HART ID              : 0
Boot HART Domain          : root
Boot HART ISA             : rv64imafdcvsux
Boot HART Features        : scounteren,mcounteren,time
Boot HART PMP Count       : 16
Boot HART PMP Granularity : 4096
Boot HART PMP Address Bits: 38
Boot HART MHPM Count      : 8
Boot HART MHPM Count      : 8
Boot HART MIDELEG         : 0x0000000000000222
Boot HART MEDELEG         : 0x000000000000b109


U-Boot 2021.10 (Feb 29 2024 - 16:53:07 +0800)cvitek_cv180x

DRAM:  63.3 MiB
gd->relocaddr=0x83ef8000. offset=0x3cf8000
MMC:   cv-sd@4310000: 0
Loading Environment from <NULL>... OK
In:    serial
Out:   serial
Err:   serial
Net:   
Warning: ethernet@4070000 (eth0) using random MAC address - 9e:7e:2c:22:b9:33
eth0: ethernet@4070000
Hit any key to stop autoboot:  1  0 
Boot from SD ...
switch to partitions #0, OK
mmc0 is current device
1578445 bytes read in 93 ms (16.2 MiB/s)
## Loading kernel from FIT Image at 81400000 ...
   Using 'config-cv1800b_milkv_duo_sd' configuration
   Trying 'kernel-1' kernel subimage
   Verifying Hash Integrity ... crc32+ OK
## Loading fdt from FIT Image at 81400000 ...
   Using 'config-cv1800b_milkv_duo_sd' configuration
   Trying 'fdt-1' fdt subimage
   Verifying Hash Integrity ... sha256+ OK
   Booting using the fdt blob at 0x8158015c
   Loading Kernel Image
   Decompressing 1572864 bytes used 2ms
   Loading Device Tree to 00000000836ac000, end 00000000836aff73 ... OK

Starting kernel ...


xv6 kernel is booting

SBI specification v0.3 detected
SBI TIME extension detected
SBI IPI extension detected
SBI RFNC extension detected
SBI HSM extension detected

usertrap(): unexpected scause 0xd pid=1
            sepc=0 stval=0x505050505
panic: init exiting

@xhackerustc
Copy link
Author

你好, 在验证期间遇到一些问题:

你好,

此img由同一份源码在最新的debian unstableg系统中编译而得。

  • 从源码编译,能出镜像,但是进入无法进入 shell 命令行
  1. 对工具链版本有要求吗?比如:Xuantie-900-gcc-elf-newlib-x86_64-V2.6.1

目前工具链等只测过debian unstable更新到最新后再apt-get install riscv64-linux-gnu-gcc genimage

  1. 对 genimage 有要求吗?比如:duo-buildroot-sdk-Duo-V1.0.7/buildroot-2021.05/output/milkv-duo_musl_riscv64/host/bin/genimage

建议测试发行版系统自带

  1. 进入系统报错,可否分析原因或者直接提供更细的编译说明
    这是 uart1 打印的开机 log

这个问题大概率由于所用工具链产生img大小不够优化,开发时为加速开发把FSSIZE改小,可以尝试如上一样的编译环境(debian unstable最新)和如下的补丁恢复默认的FSSIZE:

diff --git a/kernel/param.h b/kernel/param.h
index f7757af..eeb7962 100644
--- a/kernel/param.h
+++ b/kernel/param.h
@@ -9,7 +9,7 @@
 #define MAXOPBLOCKS  10  // max # of blocks any FS op writes
 #define LOGSIZE      (MAXOPBLOCKS*3)  // max data blocks in on-disk log
 #define NBUF         (MAXOPBLOCKS*3)  // size of disk block cache
-#define FSSIZE       1500  // size of file system in blocks
+#define FSSIZE       2000  // size of file system in blocks
 #define MAXPATH      128   // maximum file path name
 #ifndef INTERVAL
 #define INTERVAL     1000000UL

@xhackerustc
Copy link
Author

PS: 为了通用性,本porting理论上不依赖toolchain,但只测过发行版中apt安装的toolchain和genimage,各toolchain生成img大小有差异,而改动过的FSSIZE恰好卡线,不妨打上上述补丁恢复默认img大小再编译测试

@xhackerustc
Copy link
Author

研究了下比较奇怪,目前FSSIZE是有空间的足够, 故而上面的补丁不用测试。我测试用的gcc版本如下, 能否用同样的gcc版本测试下呢?

$ riscv64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=riscv64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc-cross/riscv64-linux-gnu/13/lto-wrapper
Target: riscv64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 13.2.0-12' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --without-target-system-zlib --enable-multiarch --disable-werror --disable-multilib --with-arch=rv64gc --with-abi=lp64d --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=riscv64-linux-gnu --program-prefix=riscv64-linux-gnu- --includedir=/usr/riscv64-linux-gnu/include
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Debian 13.2.0-12)

@xhackerustc
Copy link
Author

非常奇怪,刚本地测试了duo sdk自带的toolchain和genimage,debian的gcc12都不能重现你的这个问题,包括FSSIZE=1500, FSSIZE=2000等各种组合都不能重现,checking。。。

@xhackerustc
Copy link
Author

发现问题:我本地开发仓库打补丁到rvspoc仓库时有个改动missing,麻烦试下如下改动:

$ git diff kernel/trampoline.S
diff --git a/kernel/trampoline.S b/kernel/trampoline.S
index bf5851b..8c76b7f 100644
--- a/kernel/trampoline.S
+++ b/kernel/trampoline.S
@@ -147,6 +147,7 @@ userret:
        # restore user a0
         ld a0, 112(a0)

+        fence.i
         # return to user mode and user pc.
         # usertrapret() set up sstatus and sepc.
         sret

1 similar comment
@xhackerustc
Copy link
Author

发现问题:我本地开发仓库打补丁到rvspoc仓库时有个改动missing,麻烦试下如下改动:

$ git diff kernel/trampoline.S
diff --git a/kernel/trampoline.S b/kernel/trampoline.S
index bf5851b..8c76b7f 100644
--- a/kernel/trampoline.S
+++ b/kernel/trampoline.S
@@ -147,6 +147,7 @@ userret:
        # restore user a0
         ld a0, 112(a0)

+        fence.i
         # return to user mode and user pc.
         # usertrapret() set up sstatus and sepc.
         sret

@sunmin89
Copy link

sunmin89 commented Mar 7, 2024

这个问题大概率由于所用工具链产生img大小不够优化,开发时为加速开发把FSSIZE改小,可以尝试如上一样的编译环境(debian unstable最新)和如下的补丁恢复默认的FSSIZE:

感谢,恢复默认的 FSSIZE 之后,我遇到的问题解决了

@sunmin89
Copy link

sunmin89 commented Mar 7, 2024

发现问题:我本地开发仓库打补丁到rvspoc仓库时有个改动missing,麻烦试下如下改动:

$ git diff kernel/trampoline.S
diff --git a/kernel/trampoline.S b/kernel/trampoline.S
index bf5851b..8c76b7f 100644
--- a/kernel/trampoline.S
+++ b/kernel/trampoline.S
@@ -147,6 +147,7 @@ userret:
        # restore user a0
         ld a0, 112(a0)

+        fence.i
         # return to user mode and user pc.
         # usertrapret() set up sstatus and sepc.
         sret

好的,我这边加上了,遇到的问题也解决了

@shiptux
Copy link

shiptux commented Mar 26, 2024

尊敬的参赛选手,您好。
本次锦标赛您所提交的 PR 初步复测结果如 https://github.com/plctlab/rvspoc/blob/main/Results/Verifications/P2308/README.md 所示。如有任何异议请回复本条评论。如确认无误请回复 “确认无误”,感谢您的配合。

@xhackerustc
Copy link
Author

验证结果表格内容确认无误。不过下面的验证步骤有些编辑原因比如把adc log放在启动log中,adc下面的写的是pwm的输出 ;)

shiptux added a commit to shiptux/rvspoc that referenced this pull request Mar 27, 2024
shiptux added a commit to rv2036/rvspoc that referenced this pull request Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants