Giter Club home page Giter Club logo

zephyr-riscv's Introduction

Zephyr port to riscv32 architecture

The Zephyr Project is a small, scalable real-time operating system for use on resource-constrained systems supporting multiple architectures.

RISC-V is an open-source instruction set architecture.

This repository provides a port of Zephyr for the riscv32 architecture. Following the zephyr architecture, the port has been splitted into three parts:

  • riscv32 architecture support
  • riscv32-based SOC support
  • riscv32 board support

riscv32 architecture support is a generic riscv port for handling boot, interrupts/exceptions/fault and context-switching.

The riscv32-based SOC support accounts for SOC-specific:

  • system layout
  • interrupt handling
  • bit manipulation operations
  • atomic operations
  • peripheral/bus support, such as, timer, uart, gpio, i2c, spi, etc

The riscv32 board support characterizes the configuration of a given riscv32-based SOC for a particular board. For example, zedboard_pulpino is a configuration of the pulpino-soc for the zedboard.

zephyr-riscv currently handles the following SOCs:

  • riscv32-qemu, supporting the sifive machine model
  • pulpino
  • SiFive Freedom E310

The riscv32 port has successfully been merged into the Zephyr Project master repository at https://gerrit.zephyrproject.org and shall be released in Zephyr 1.7. The SiFive FE310 SOC port is available only in the zephyr-riscv github repository for the time being.

The riscv toolchain (gcc, binutils, gdb) and riscv-qemu have successfully been merged into the zephyr SDK and has been released in the 0.9 SDK version. Latest 0.9.1 SDK binary can be obtained from the following link:

https://github.com/zephyrproject-rtos/meta-zephyr-sdk/releases/download/0.9.1/zephyr-sdk-0.9.1-setup.run

Installing the zephyr-SDK

The zephyr-0.9.1-sdk is installed as follows:

$ chmod +x zephyr-sdk-0.9.1-setup.run
$ sudo ./zephyr-sdk-0.9.1-setup.run

After installation, the zephyr-SDK shall be found in /opt/zephyr-sdk (if the default target directory for the SDK has been chosen during the installation process).

Getting the zephyr-riscv sources

Since riscv support is now available in the Zephyr Project master repository, you can either get the zephyr sources from the from the zephyr-riscv github repository or from Zephyr Project master repository as follows:

Github repository

$ git clone https://github.com/fractalclone/zephyr-riscv.git
$ cd zephyr-riscv

Zephyr Project master repository

$ git clone https://gerrit.zephyrproject.org/r/zephyr zephyr-riscv
$ cd zephyr-riscv

Setting zephyr build environment

Within the zephyr-riscv directory, setup the zephyr environment variables as follows:

$ source zephyr-env.sh

Settings to compile zephyr using the zephyr-sdk

To compile zephyr using the zephyr-sdk, export the following environment variables:

$ export ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk
$ export ZEPHYR_GCC_VARIANT=zephyr

Settings to compile zephyr using an external riscv-gnu-toolchain

If you want to use an external riscv-gnu-toolchain, this can be done by exporting the following environment variables:

$ export RISCV32_TOOLCHAIN_PATH=/path/to/riscv-toolchain
$ export ZEPHYR_GCC_VARIANT=riscv32

Compiling zephyr-riscv for the qemu_riscv32 board

Compile and run the philosophers sample app for the qemu_riscv32 board using the zephyr-sdk

$ cd samples/philosophers
$ make BOARD=qemu_riscv32 run

The command shall compile and run the philosophers application using the qemu-system-riscv32 found in the zephyr-sdk.

To exit qemu, press Ctrl-a x

Compile only the philosophers sample app for the qemu_riscv32 board

$ cd samples/philosophers
$ make BOARD=qemu_riscv32

Once compiled, the zephyr.elf file shall be found at outdir/qemu_riscv32/zephyr.elf

Running 'zephyr.elf' using an external qemu-system-riscv32

Within the philosophers directory:

$ /path/to/qemu-system-riscv32 -kernel outdir/qemu_riscv32/zephyr.elf -m 32 -machine sifive -nographic

To exit qemu, press Ctrl-a x

Compiling zephyr-riscv for the zedboard_pulpino board

Compiling the zephyr for pulpino will require either:

The zephyr-sdk-0.9.1 has a patch that allows the pulpino-specific code to be compiled with the latest riscv-gnu-toolchain. Using an unpatched generic riscv-gnu-toolchain won't work. This is due to the fact that the eret opcode required by pulpino has been removed in the latest riscv-gnu-toolchain.

It is also to be noted that, within the latest riscv-gnu-toolchain, the wfi opcode encoding has changed from 0x10200073 to 0x10500073. However, pulpino only understands 0x10200073 and will generate an illegal instruction fault when trying to execute 0x10500073. Moreover, 0x10200073 is now used to encode the sret opcode. For this reason, the port of zephyr to riscv32 architecture comprises a CONFIG_RISCV_GENERIC_TOOLCHAIN config variable, which when set, will replace wfi by sret within the pulpino-specific code.

Compiling a sample app for the zedboard_pulpino board using the zephyr-sdk

Assuming that the zephyr-sdk environment variables have already been set, compiling the philosophers sample app is performed as follows within the philosophers directory:

$ make BOARD=zedboard_pulpino

After compilation, the zephyr.s19 file required by pulpino will be found at outdir/zedboard_pulpino/zephyr.s19

Within the philosophers directory, convert the zephyr.s19 to a spi_stim.txt file using the utility found at https://github.com/fractalclone/riscv-binaries/blob/master/pulpino/s19toslm.py as follows:

$ /path/to/s19toslm.py outdir/zedboard_pulpino/zephyr.s19

The spi_stim.txt will be generated inside the philosophers directory.

Follow the instructions given at https://github.com/pulp-platform/pulpino/tree/master/fpga to setup the zedboard for running the pulpino core.

Once you have a zedboard running linux and the pulpino fpga bitstream, transfer the spi_stim.txt file as well as the spiload application to the zedboard. (a precompiled version of the spiload app can be obtained at https://github.com/fractalclone/riscv-binaries/blob/master/pulpino/spiload)

Once copied, use the spiload application to load the spi_stim.txt firmware to the pulpino core as follows:

$ ./spiload -t10000 spi_stim.txt

You can also test the samples/basic/disco_fever, samples/basic/blinky, samples/basic/button and samples/basic/disco apps for pulpino.

Compiling a sample app for the zedboard_pulpino board using the pulpino-specific toolchain

To compile a sample app for the zedboard_pulpino board using the pulpino-specific toolchain, one must first add the following CONFIG_RISCV_GENERIC_TOOLCHAIN=n in the prj.conf file found within the sample app directory. This shall allow zephyr to account for pulpino-specific opcodes, like bit-manipulation, and prevent the replacement of wfi by sret. Example, within the philosophers directory:

Add the CONFIG_RISCV_GENERIC_TOOLCHAIN=n to the prj.conf file, if not already set

$ echo "CONFIG_RISCV_GENERIC_TOOLCHAIN=n" >> prj.conf

Configure zephyr to use the pulpino-specific toolchain by exporting the following environment variables:

$ export RISCV32_TOOLCHAIN_PATH=/path/to/ri5cy_gnu_toolchain/install
$ export ZEPHYR_GCC_VARIANT=riscv32

Compile the philosophers application for the zedboard_pulpino board

make BOARD=zedboard_pulpino

Compiling zephyr-riscv for the arty_fe310 board

Assuming that the zephyr-sdk environment variables have already been set, compiling the philosophers sample app for the arty_fe310 board is performed as follows within the philosophers directory:

$ make BOARD=arty_fe310

After compilation, the zephyr.elf binary will be found at outdir/arty_fe310/zephyr.elf

Loading the zephyr.elf binary on the arty board

The following assumes that you already have an arty fpga board (https://reference.digilentinc.com/reference/programmable-logic/arty/start) running the SiFive FE310 SOC. If not, register yourself to the sifive developer's website (https://dev.sifive.com) to get the SiFive FE310 FPGA bitstream for the arty board and get info about how to:

To load the zephyr.elf image on the arty board you will require:

  • the Sifive freedom-e-sdk available at https://github.com/sifive/freedom-e-sdk. More specifically, the openocd tool available within the freedom-e-sdk.
  • the olimex ARM-USB-TINY JTAG to flash the zephyr.elf image on the arty board.

Once you've compiled the tools available in the freedom-e-sdk, the openocd binary will be found at /path/to/freedom-e-sdk/toolchain/bin/openocd

To flash the zephyr.elf on the arty board do the following:

  • ensure that the olimex ARM-USB-TINY JTAG is connected to your PC and the arty board
  • ensure that the arty board is powered on
  • extend the PATH variable with the freedom-e-sdk/toolchain/bin directory as follows:
    export PATH=/path/to/freedom-e-sdk/toolchain/bin:$PATH
  • load the zephyr.elf using the freedom-e-sdk utility script openocd_upload.sh as follows:

Assuming that you are in the philosophers directory

/path/to/freedom-e-sdk/bsp/tools/openocd_upload.sh \
outdir/arty_fe310/zephyr.elf \
/path/to/freedom-e-sdk/bsp/env/freedom-e300-arty/openocd.cfg

Upon successful load, you should see the philosophers application running in the arty board UART console. You can also test the samples/basic/disco_fever (to increase or decrease LEDS blink speed, press respectively BTN0 or BTN1 on the arty board), samples/basic/blinky, samples/basic/button (press BTN0 on arty board), samples/basic/disco and samples/shell apps for the arty_fe310 board.

zephyr-riscv's People

Contributors

1010101001010101 avatar ajstephens avatar benwrs avatar bliu11-intel avatar carlescufi avatar cjordan44 avatar cvinayak avatar dbkinder avatar dcpleung avatar dkalowsk avatar dkorovki avatar erwango avatar finikorg avatar fractalclone avatar galak avatar inaky-intc avatar jmcruzal avatar jmnlcruz avatar jukkar avatar lpereira avatar maureenhelm avatar mshawcroft avatar nashif avatar pfalcon avatar ramesh-thomas avatar srodrig1 avatar vcgomes avatar vudentz avatar wrspetermitsis avatar xpuarli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

zephyr-riscv's Issues

Macro SYS_CLOCK_HW_CYCLES_TO_NS broken

Calling the macro SYS_CLOCK_HW_CYCLES_TO_NS() defined in include/sys_clock.h breaks the build for me.
Can't even see the Zephyr booting message anymore.
Platform is a SiFive Arty FE310 development board.

I assume that casting to u64_t in SYS_CLOCK_HW_CYCLES_TO_NS64() isn't a good idea on RISCV32.

Version of Zephyr OS: 1.8.99
Version of Zephyr SDK: 0.9.1

Rtos port to risc-v

Hello,

I'm trying to port another rtos to risc-v and I'm following your instructions by porting Zephyr to see if this can be done in a similar fashion.

Is it possible to push another small rtos (other than zephyr, similarly) with rocket cores to a zedboard by using Vivado to generate another boot.bin ? Will I only need the .elf file of my rtos or does it require other files ?

Could you please tell me what sort of files I can work with similarly and what files should I be able to provide of my rtos ? I'm assuming the .elf of my rtos shouldn't only be sufficient ?

Thank you very much.

run in user mode

Hi,

Is there a way to run zephyr only in user/machine mode ?
We dont want to run in supervisor mode.

Please let me know

regards,
sathya

hifive1: Exception cause Load address misaligned

I am trying to get the samples/net/dhcpv4_client/ working on hifive1 board, using the branch provided by @palmer-dabbelt .

I use the following for the prj_hifive1.conf file (copied from arduino 101 disabled a few things for debugging):

CONFIG_NETWORKING=y
CONFIG_NET_IPV6=n
CONFIG_NET_IPV4=y
CONFIG_NET_ARP=y
CONFIG_NET_UDP=y
CONFIG_NET_DHCPV4=y
CONFIG_NET_BUF=y
CONFIG_NET_NBUF_RX_COUNT=4
CONFIG_NET_NBUF_TX_COUNT=4
CONFIG_NET_NBUF_RX_DATA_COUNT=5
CONFIG_NET_NBUF_TX_DATA_COUNT=5
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1

CONFIG_NET_LOG=y
CONFIG_SYS_LOG=y
CONFIG_SYS_LOG_SHOW_COLOR=y
CONFIG_NET_DEBUG_CORE=y
CONFIG_NET_DEBUG_IF=y
CONFIG_NET_DEBUG_DHCPV4=y
CONFIG_NET_DEBUG_ARP=y
CONFIG_NET_DEBUG_L2_ETHERNET=y
CONFIG_NET_DEBUG_IPV4=y
CONFIG_NET_DEBUG_ICMPV4=y
CONFIG_NET_DEBUG_UDP=y
CONFIG_NET_RX_STACK_SIZE=2048

CONFIG_NET_L2_ETHERNET=y

CONFIG_SPI=y
CONFIG_SPI_CS_GPIO=y
CONFIG_SPI_1_CS_GPIO_PORT="GPIO_0"
CONFIG_SPI_1_CS_GPIO_PIN=0

CONFIG_SYS_LOG_ETHERNET_LEVEL=1
CONFIG_ETH_ENC28J60=n
CONFIG_ETH_ENC28J60_0=n
CONFIG_ETH_ENC28J60_0_SPI_PORT_NAME="SPI_1"
CONFIG_ETH_ENC28J60_0_SPI_BUS_FREQ=2
CONFIG_ETH_ENC28J60_0_MAC3=0x0a
CONFIG_ETH_ENC28J60_0_MAC4=0x0b
CONFIG_ETH_ENC28J60_0_MAC5=0x0c

CONFIG_NET_MGMT=y
CONFIG_NET_MGMT_EVENT=y

Compiling the code with the current zephyr SDK and uploading it onto the board
using the freedom-e-sdk works fine.

However, when opening ttyUSB1 with screen I get the following error:

***** BOOTING ZEPHYR OS v1.7.99 *****
[dhcpv4] [INF] main: In main
[dhcpv4] [INF] main_thread: Run dhcpv4 client
Exception cause Load address misaligned (4)
Current thread ID = 0x80003070
Faulting instruction address = 0x20404e18
  ra: 0x2040520c  gp: 0x67e09182  tp: 0x20400260  t0: 0x1800
  t1: 0x20400780  t2: 0x0  t3: 0x2547316e  t4: 0x20408468
  t5: 0x9d040577  t6: 0x177fe4b9  a0: 0x80000144  a1: 0x1
  a2: 0x0  a3: 0x80003414  a4: 0x0  a5: 0x3b9aca0d
  a6: 0x8120d47e  a7: 0x67e09182
Fatal fault in thread! Aborting.

Disassembling the code shows:

20404e0c <prepare_message>:
20404e0c:       00852783                lw      a5,8(a0)
20404e10:       fd010113                addi    sp,sp,-48
20404e14:       02112623                sw      ra,44(sp)
20404e18:       0087a783                lw      a5,8(a5)
20404e1c:       02812423                sw      s0,40(sp)
20404e20:       02912223                sw      s1,36(sp)
20404e24:       03212023                sw      s2,32(sp)
20404e28:       01312e23                sw      s3,28(sp)
20404e2c:       01412c23                sw      s4,24(sp)
20404e30:       01512a23                sw      s5,20(sp)
20404e34:       00058a93                mv      s5,a1
20404e38:       00000593                li      a1,0
20404e3c:       00060a13                mv      s4,a2
20404e40:       00050913                mv      s2,a0
20404e44:       000780e7                jalr    a5
20404e48:       fff00593                li      a1,-1
20404e4c:       bd9fd0ef                jal     20402a24 <net_nbuf_get_reserve_tx>

The function prepare_message is in subsys/net/ip/dhcpv4.c

I found an old and closed bug in JIRA, just linking it here for reference as it sounded similiar:
https://jira.zephyrproject.org/browse/ZEP-955

Not sure how to proceed at this point. Appreciate any hints / advice.

blink_led for zedboard

Hello,

The README states that the blink_led programs is for the arduino board. Make BOARD=zedboard_pulpino gives errors. Is it possible to run the blink led tests for the zedboard ?

Thank you !

ERROR: glib-2.22 gthread-2.0 is required to compile QEMU

Hello,

The configure gives the following error.


alpha@alpha-VirtualBox:~/zephyr/riscv-gnu-toolchain/riscv-qemu$ ./configure --target-list=riscv64-softmmu,riscv32-softmmu --prefix=/opt/riscv

ERROR: glib-2.22 gthread-2.0 is required to compile QEMU

I have build-essential, libc6-dev and when I install apt-get install libglib2.0-dev zlib1g-dev, I get the broken packages error.
Could you please tell me what I'm missing ?

Thank you

Compilation Error

When i am trying to clone riscv-qemu & riscv-gnu-toolchain during the make -j my entire system get hanged . Also how to transfer spi_stim.txt file from PC to zedboard. Kindly share before ssh how to configure PC and Zedboard.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.