nuttx: regression of `rv-virt` kernel builds

On Ubuntu 22.04 with qemu-system-riscv64/32 (version: 6.2+dfsg-2ubuntu6.16) targets and gcc-riscv64-unknown-elf toolchain (GCC 10.2) and latest master branch.

  • The build from rv-virt/nsh and rv-virt/nsh64 can boot.
  • The build from both rv-virt/knsh32 and rv-virt/knsh64 can’t boot. The ABC string is invibsile from console.

The command line to run nuttx qemu-system-riscv64 -M virt,aclint=on -semihosting -nographic -bios nuttx and it has been working well until I pulled latest master. Looks like this booting mode no longer works after patch #12178.

By using qemu-system-riscv64 -M virt,aclint=on -semihosting -nographic -kernel nuttx to run nuttx with default OpenSBI (v0.9) for rv64, got the exception riscv_exception: EXCEPTION: Illegal instruction. MCAUSE: 0000000000000002, EPC: 000000008020902c, MTVAL: 0000000014d79073.

The call stack looks like:

(gdb) bt
#0  0x000000008020902c in riscv_write_stime (value=18446744073709551615) at /home/yf/Projects/Nuttx/nuttx/arch/risc-v/src/common/riscv_mtimer.c:135
#1  riscv_mtimer_set_mtimecmp (value=18446744073709551615, priv=0x804072c0) at /home/yf/Projects/Nuttx/nuttx/arch/risc-v/src/common/riscv_mtimer.c:156
#2  riscv_mtimer_initialize (mtime=mtime@entry=33603576, mtimecmp=mtimecmp@entry=33570816, irq=irq@entry=21, freq=freq@entry=10000000) at /home/yf/Projects/Nuttx/nuttx/arch/risc-v/src/common/riscv_mtimer.c:349
#3  0x0000000080208a3e in up_timer_initialize () at /home/yf/Projects/Nuttx/nuttx/arch/risc-v/src/qemu-rv/qemu_rv_timerisr.c:67
#4  0x0000000080204670 in clock_initialize () at /home/yf/Projects/Nuttx/nuttx/sched/clock/clock_initialize.c:212
#5  0x00000000802049d8 in nx_start () at /home/yf/Projects/Nuttx/nuttx/sched/init/nx_start.c:671
#6  0x00000000802006e6 in qemu_rv_start (mhartid=<optimized out>, dtb=<optimized out>) at /home/yf/Projects/Nuttx/nuttx/arch/risc-v/src/qemu-rv/qemu_rv_start.c:180
#7  0x000000008020004a in _stext () at /home/yf/Projects/Nuttx/nuttx/arch/risc-v/src/qemu-rv/qemu_rv_head.S:74

maybe the RV_SSTC extension is unavailable in QEMU 6.2 shipped with Ubuntu 22.04?

Haven’t tried -kernel nuttx for rv32 as the default firmware seems lacking in qemu-system-data package on Ubuntu 22.04.

About this issue

  • Original URL
  • State: closed
  • Created 2 months ago
  • Reactions: 1
  • Comments: 22 (22 by maintainers)

Commits related to this issue

Most upvoted comments

@lupyuen and @inochisa, I checked with QEMU 6.2 and OpenSBI v1.0-3ubuntu1 here, it works well. So saying v1.0 in docs should be fine.

@lupyuen and @inochisa thanks for all the information!

Here I tried opensbi 1.3-1ubuntu0.22.04.2 got via apt instalal opensbi with QEMU 6.2 on Ubuntu 22.04, usleep works now with patch #12279. I don’t have other opensbi versions at hand to try but it looks like QEMU 6.2 is fine now.

So it is good that we finally can support the Ubuntu stock QEMU v6.2 this way: qemu-system-riscv64 -M virt,aclint=on -semihosting -kernel nuttx -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_dynamic.bin

@inochisa Sorry I goofed.

@yf13 usleep works OK with ARCH_RV_EXT_SSTC=N, rv-virt:knsh64, QEMU 7.0.0 and OpenSBI v1.0.

Could you update to OpenSBI v1.0? I have a hunch that OpenSBI v0.9 might be buggy, we probably shouldn’t use it? Thanks!

https://gist.github.com/lupyuen/da195386a4873c572aa26961e4c81d79

→ qemu-system-riscv64 --version
QEMU emulator version 7.0.0
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers

→ qemu-system-riscv64 -nographic -semihosting -M virt,aclint=on -cpu rv64 -kernel nuttx
OpenSBI v1.0
NuttShell (NSH)
nsh> usleep 5
nsh> ostest
...
ostest_main: Exiting with status -1
nsh>

@inochisa Sorry ARCH_RV_EXT_SSTC=N failed to build with rv-virt:knsh64. Did I miss something?

https://gist.github.com/lupyuen/749f8235603781c29a351c066cd2fcf9

$ git clone https://github.com/inochisa/nuttx --branch qemu-s-mode
$ git clone https://github.com/apache/nuttx-apps apps
$ cd nuttx && ./tools/configure.sh rv-virt:knsh64
$ make menuconfig
## Disable ARCH_RV_EXT_SSTC
$ grep SSTC .config

$ make

./chip/qemu_rv_start.c:54:4: error: #error "Target requires kernel in S-mode, enable CONFIG_ARCH_USE_S_MODE"
   54 | #  error "Target requires kernel in S-mode, enable CONFIG_ARCH_USE_S_MODE"
      |    ^~~~~
ERROR: riscv64-unknown-elf-gcc failed: 1
       command: riscv64-unknown-elf-gcc -MT ./qemu_rv_start.o  -M '-fno-common' '-Wall' '-Wstrict-prototypes' '-Wshadow' '-Wundef' '-Wno-attributes' '-Wno-unknown-pragmas' '-Wno-psabi' '-Os' '-fno-strict-aliasing' '-fomit-frame-pointer' '-ffunction-sections' '-fdata-sections' '-nostdlib' '-g' '-mcmodel=medany' '-march=rv64imafdc' '-mabi=lp64d' '-isystem' '/private/tmp/qemu-s-mode/nuttx/include' '-D__NuttX__' '-D__KERNEL__' '-pipe' '-I' '/private/tmp/qemu-s-mode/nuttx/arch/risc-v/src/chip' '-I' '/private/tmp/qemu-s-mode/nuttx/arch/risc-v/src/common' '-I' '/private/tmp/qemu-s-mode/nuttx/sched' ./chip/qemu_rv_start.c
make[2]: *** [/private/tmp/qemu-s-mode/nuttx/tools/Config.mk:230: qemu_rv_start.ddc] Error 1
make[1]: *** [Makefile:233: .depend] Error 2
make: *** [tools/Unix.mk:620: pass2dep] Error 2

I think you disable CONFIG_ARCH_USE_S_MODE by mistake…

grep should give

$ cat .config | grep SSTC
# CONFIG_ARCH_RV_EXT_SSTC is not set

@inochisa Do you mean that if ARCH_RV_EXT_SSTC=N, then usleep works OK on rv-virt:knsh64?

Yes.

If so, I will test ARCH_RV_EXT_SSTC=N with usleep on my old version of QEMU. Thanks

This worth a try. Thanks.

Tested OK on QEMU 7.2.9: https://gist.github.com/lupyuen/b2520054b5ecc12a2f33909aaa46121c

@inochisa Could you update the NuttX Doc to say that QEMU 7.2.9 or later is required, to support RISC-V "Sstc" Extension. Thank you so much!

Good, In addition, I will add some comments for users want to use its own OpenSBI.