Skip to content

Latest commit

 

History

History
140 lines (107 loc) · 2.75 KB

ex_standalone.adoc

File metadata and controls

140 lines (107 loc) · 2.75 KB

Build and run examples for single thread (Standalone mode with QEMU)

Build device side runtime

Run cmake to configure this project.

$ cmake ./ -G Ninja -B build \
  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
  -DCMAKE_INSTALL_PREFIX=./test/sysroot/ \
  -DARCH=riscv \
  -DCROSS_COMPILE=riscv64-unknown-elf- \
  -DCC=gcc \
  -DDEFCONF=riscv_qemu_virt_64_xip

Build and install runtime libraries to sysroot.

$ ninja -C build install

Build device side application

$ cd test

$ make USE_NEWLIB=y

You can use USE_SYSROOT option to specify sysroot (includes runtime libraries) if you have installed runtime into other directory.

$ cd test

$ make USE_SYSROOT=/path_to/sysroot

If build is succeeded, some application binaries (includes "hello") are generated in current directory.

Run device side application

$ qemu-system-riscv64 \
  -machine virt \
  -kernel hello \
  -bios none \
  -net none \
  -nographic \
  -chardev stdio,id=con,mux=on \
  -serial chardev:con \
  -mon chardev=con,mode=readline \
  -smp 4 \
  -s

hello world!
good bye world!

Build and run examples for multithread (Standalone mode with QEMU)

Build device side runtime

Run cmake to configure this project. Threre are some differences from single thread config:

  • Change configs of runtime

    • CONFIG_USE_LIBC (n → y)

    • CONFIG_USE_NEWLIB (y → n)

  • Change options of cmake

    • CROSS_COMPILE (riscv64-unknown-elf- → riscv64-unknown-linux-musl-)

$ cmake ./ -G Ninja -B build \
  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
  -DCMAKE_INSTALL_PREFIX=./test/sysroot/ \
  -DARCH=riscv \
  -DCROSS_COMPILE=riscv64-unknown-linux-musl- \
  -DCC=gcc \
  -DDEFCONF=riscv_qemu_virt_64_xip

Build and install runtime libraries to sysroot.

$ ninja -C build install

Build device side application

Threre are some differences from single thread config:

  • Change environment variables

    • USE_NEWLIB (y → not defined)

    • USE_MUSL (not defined → y)

$ mkdir build

$ make USE_MUSL=y

Also you can use USE_SYSROOT option to specify sysroot. If build is succeeded, some application binaries (includes "hello") are generated in current directory.

Run device side application

$ qemu-system-riscv64 \
  -machine virt \
  -kernel pthread \
  -bios none \
  -net none \
  -nographic \
  -chardev stdio,id=con,mux=on \
  -serial chardev:con \
  -mon chardev=con,mode=readline \
  -smp 4 \
  -s

main: test pthread
0: pid:1, tid:4
0: -------- step1-1 main + 1threads start
1: ---- thread step1 arg:1 0x8041ae78, pid:1, tid:6
0: ---- thread step1 arg:11 0x80407dc8, pid:1, tid:4
...