├── .gitmodules ├── .travis.yml ├── README.md ├── build-rv32ima.sh ├── build-spike-only.sh ├── build-spike-pk.sh ├── build.common ├── build.log ├── build.sh ├── doc ├── busybox-menuconfig.png ├── linux-boot.png └── linux-menuconfig.png └── regression.sh /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "riscv-isa-sim"] 2 | path = riscv-isa-sim 3 | url = https://github.com/riscv/riscv-isa-sim.git 4 | [submodule "riscv-pk"] 5 | path = riscv-pk 6 | url = https://github.com/riscv/riscv-pk.git 7 | [submodule "riscv-opcodes"] 8 | path = riscv-opcodes 9 | url = https://github.com/riscv/riscv-opcodes.git 10 | [submodule "riscv-tests"] 11 | path = riscv-tests 12 | url = https://github.com/riscv/riscv-tests.git 13 | [submodule "riscv-openocd"] 14 | path = riscv-openocd 15 | url = https://github.com/riscv/riscv-openocd.git 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | # run on new infrastructure 3 | sudo: false 4 | cache: apt 5 | # required packages to install 6 | addons: 7 | apt: 8 | sources: 9 | - ubuntu-toolchain-r-test 10 | packages: 11 | - gcc-4.8 12 | - g++-4.8 13 | - gperf 14 | - autoconf 15 | - automake 16 | - autotools-dev 17 | - libmpc-dev 18 | - libmpfr-dev 19 | - libgmp-dev 20 | - gawk 21 | - build-essential 22 | - bison 23 | - flex 24 | - texinfo 25 | - help2man 26 | - python-pexpect 27 | - libusb-1.0-0-dev 28 | - device-tree-compiler 29 | 30 | env: 31 | global: 32 | - RISCV="/home/travis/riscv_install" 33 | - MAKEFLAGS="-j2" 34 | - PATH="$TRAVIS_BUILD_DIR/.build/riscv64-unknown-elf/buildtools/bin:$PATH" 35 | - PATH="/home/travis/riscv_install/bin:$PATH" 36 | - CROSSTOOL_VERSION=1.24.0-rc3 37 | 38 | before_install: 39 | # make install destination 40 | - mkdir -p $RISCV 41 | # don't forget to clone riscv-tests/env 42 | - cd riscv-tests 43 | - git submodule update --init 44 | - cd .. 45 | # openocd also needs submodules 46 | - cd riscv-openocd 47 | - git submodule update --init 48 | - cd .. 49 | - unset CC CXX 50 | 51 | # extra time duing long builds 52 | install: travis_wait 53 | 54 | # pexpect ends up in /usr/lib/python2.7/dist-packages, which is not part of the 55 | # default python path. 56 | script: 57 | - mkdir ~/src 58 | - curl http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-$CROSSTOOL_VERSION.tar.xz | tar -xJp 59 | - cd crosstool-ng-$CROSSTOOL_VERSION; ./configure --prefix=$RISCV; cd .. 60 | - make -C crosstool-ng-$CROSSTOOL_VERSION 61 | - make -C crosstool-ng-$CROSSTOOL_VERSION install 62 | - ct-ng riscv64-unknown-elf 63 | - echo CT_CC_GCC_USE_GRAPHITE=n >> .config 64 | - echo CT_ISL_NEEDED=n >> .config 65 | - echo CT_ISL=n >> .config 66 | - echo CT_MULTILIB=n >> .config 67 | # Newlib download fails periodically, so retry the build a few times. 68 | - travis_wait 100 ct-ng build || travis_wait 100 ct-ng build || travis_wait 100 ct-ng build 69 | - which riscv64-unknown-elf-gcc 70 | # Work around toolchain path issues 71 | - cp .build/riscv64-unknown-elf/build/build-libc/riscv64-unknown-elf/libgloss/riscv/crt0.o .build/riscv64-unknown-elf/buildtools/lib/gcc/riscv64-unknown-elf/8.3.0 72 | - cp -r .build/src/newlib-3.1.0.20181231/newlib/libc/include .build/riscv64-unknown-elf/buildtools/lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/include 73 | - cp .build/riscv64-unknown-elf/build/build-libc/riscv64-unknown-elf/newlib/libm.a .build/riscv64-unknown-elf/buildtools/lib/gcc/riscv64-unknown-elf/8.3.0 74 | - cp .build/riscv64-unknown-elf/build/build-libc/riscv64-unknown-elf/newlib/libc.a .build/riscv64-unknown-elf/buildtools/lib/gcc/riscv64-unknown-elf/8.3.0 75 | - cp .build/riscv64-unknown-elf/build/build-libc/riscv64-unknown-elf/libgloss/riscv/libgloss.a .build/riscv64-unknown-elf/buildtools/lib/gcc/riscv64-unknown-elf/8.3.0 76 | # Remove new autotools from path 77 | - rm -f .build/riscv64-unknown-elf/buildtools/bin/automake* 78 | - rm -f .build/riscv64-unknown-elf/buildtools/bin/aclocal* 79 | # Actually build this repo 80 | - ./build.sh 81 | # Put compiler in expected place for debug tests 82 | - ln -s $TRAVIS_BUILD_DIR/.build/riscv64-unknown-elf/buildtools/bin/riscv64-unknown-elf-gcc $RISCV/bin 83 | - ln -s $TRAVIS_BUILD_DIR/.build/riscv64-unknown-elf/build/build-gdb-cross/gdb/gdb $RISCV/bin/riscv64-unknown-elf-gdb 84 | # Run debug tests. Currently we expect 11 failures. 85 | - PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/dist-packages make -C riscv-tests/build debug-check | grep "11 tests returned fail" 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | riscv-tools [![Build Status](https://travis-ci.org/riscv/riscv-tools.svg?branch=master)](https://travis-ci.org/riscv/riscv-tools) 2 | =========================================================================== 3 | 4 | This repository houses a set of RISC-V simulators and other tools, 5 | including the following projects: 6 | 7 | * [Spike](https://github.com/riscv/riscv-isa-sim/), the ISA simulator 8 | * [riscv-tests](https://github.com/riscv/riscv-tests/), a battery of 9 | ISA-level tests 10 | * [riscv-opcodes](https://github.com/riscv/riscv-opcodes/), the 11 | enumeration of all RISC-V opcodes executable by the simulator 12 | * [riscv-pk](https://github.com/riscv/riscv-pk/), which contains `bbl`, 13 | a boot loader for Linux and similar OS kernels, and `pk`, a proxy kernel that 14 | services system calls for a target-machine application by forwarding them to 15 | the host machine 16 | 17 | Several RISC-V tools that were previously maintained through this 18 | repository have since been upstreamed to their parent projects and are 19 | no longer included here. Your favorite software distribution should 20 | already have packages for these upstream tools, but if it doesn't then 21 | here are a handful of my favorites: 22 | 23 | * Your favorite software distribution may already have packages that 24 | include a RISC-V cross compiler, which is probably the fastest way to 25 | get started. As of writing this README (March, 2019) I can trivially 26 | find packages for ALT Linux, Arch Linux, Debian, Fedora, FreeBSD, 27 | Mageia, OpenMandriva, openSUSE, and Ubuntu. 28 | [pkgs.org](https://pkgs.org/) appears to be a good place to find an up 29 | to date list, just search for "riscv". 30 | * [crosstool-ng](http://crosstool-ng.github.io/docs/) can build RISC-V 31 | cross compilers of various flavors. 32 | * The [RISC-V Port of 33 | OpenEmbedded](https://github.com/riscv/meta-riscv#quick-start) 34 | builds a cross compiler, Linux kernel, and enough of userspace to do 35 | many interesting things. 36 | * [buildroot](https://github.com/buildroot/buildroot) is a lighter 37 | weight cross compiled Linux distribution. 38 | 39 | This repository uses crosstool-ng to configure a `riscv64-unknown-elf` 40 | toolchain. 41 | 42 | # Quickstart 43 | 44 | $ git submodule update --init --recursive 45 | $ export RISCV=/path/to/install/riscv/toolchain 46 | $ ./build.sh 47 | 48 | 49 | Ubuntu packages needed: 50 | 51 | $ sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev libusb-1.0-0-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev device-tree-compiler pkg-config libexpat-dev 52 | 53 | Fedora packages needed: 54 | 55 | $ sudo dnf install autoconf automake @development-tools curl dtc libmpc-devel mpfr-devel gmp-devel libusb-devel gawk gcc-c++ bison flex texinfo gperf libtool patchutils bc zlib-devel expat-devel 56 | 57 | _Note:_ This requires a compiler with C++11 support (e.g. GCC >= 4.8). 58 | To use a compiler different than the default, use: 59 | 60 | $ CC=gcc-5 CXX=g++-5 ./build.sh 61 | 62 | _Note for OS X:_ We recommend using [Homebrew](https://brew.sh) to install the dependencies (`libusb dtc gawk gnu-sed gmp mpfr libmpc isl wget automake md5sha1sum`) or even to install the tools [directly](https://github.com/riscv/homebrew-riscv). This repo will build with Apple's command-line developer tools (clang) in addition to gcc. 63 | -------------------------------------------------------------------------------- /build-rv32ima.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # Script to build RISC-V ISA simulator, proxy kernel, and GNU toolchain. 4 | # Tools will be installed to $RISCV. 5 | 6 | . build.common 7 | 8 | echo "Starting RISC-V Toolchain build process" 9 | 10 | build_project riscv-isa-sim --prefix=$RISCV --with-isa=rv32ima 11 | CC= CXX= build_project riscv-pk --prefix=$RISCV --host=riscv32-unknown-elf 12 | build_project riscv-openocd --prefix=$RISCV --enable-remote-bitbang --disable-werror 13 | 14 | echo -e "\\nRISC-V Toolchain installation completed!" 15 | -------------------------------------------------------------------------------- /build-spike-only.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # Script to build RISC-V ISA simulator, proxy kernel, and GNU toolchain. 4 | 5 | . build.common 6 | 7 | echo "Starting RISC-V Toolchain build process" 8 | 9 | build_project riscv-isa-sim --prefix=$RISCV 10 | 11 | echo -e "\\nRISC-V Toolchain installation completed!" 12 | -------------------------------------------------------------------------------- /build-spike-pk.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # Script to build RISC-V ISA simulator, proxy kernel, and GNU toolchain. 4 | # Tools will be installed to $RISCV. 5 | 6 | . build.common 7 | 8 | if [ ! `which riscv64-unknown-elf-gcc` ] 9 | then 10 | echo "riscv64-unknown-elf-gcc doesn't appear to be installed; use the full-on build.sh" 11 | exit 1 12 | fi 13 | 14 | echo "Starting RISC-V Toolchain build process" 15 | 16 | build_project riscv-isa-sim --prefix=$RISCV 17 | CC= CXX= build_project riscv-pk --prefix=$RISCV --host=riscv64-unknown-elf 18 | 19 | echo -e "\\nRISC-V Toolchain installation completed!" 20 | -------------------------------------------------------------------------------- /build.common: -------------------------------------------------------------------------------- 1 | # Script to build RISC-V ISA simulator, proxy kernel, and GNU toolchain. 2 | # Tools will be installed to $RISCV. 3 | 4 | if [ "x$RISCV" = "x" ] 5 | then 6 | echo "Please set the RISCV environment variable to your preferred install path." 7 | exit 1 8 | fi 9 | 10 | # Use gmake instead of make if it exists. 11 | MAKE=`command -v gmake || command -v make` 12 | 13 | PATH="$RISCV/bin:$PATH" 14 | #GCC_VERSION=`gcc -v 2>&1 | tail -1 | awk '{print $3}'` 15 | 16 | set -e 17 | 18 | function build_project { 19 | PROJECT="$1" 20 | shift 21 | echo 22 | if [ -e "$PROJECT/build" ] 23 | then 24 | echo "Removing existing $PROJECT/build directory" 25 | rm -rf "$PROJECT/build" 26 | fi 27 | if [ ! -e "$PROJECT/configure" ] 28 | then 29 | ( 30 | cd "$PROJECT" 31 | find . -iname configure.ac | sed s/configure.ac/m4/ | xargs mkdir -p 32 | autoreconf -i 33 | ) 34 | fi 35 | mkdir -p "$PROJECT/build" 36 | cd "$PROJECT/build" 37 | echo "Configuring project $PROJECT" 38 | ../configure $* > build.log 39 | echo "Building project $PROJECT" 40 | $MAKE >> build.log 41 | echo "Installing project $PROJECT" 42 | $MAKE install >> build.log 43 | cd - > /dev/null 44 | } 45 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # Script to build RISC-V ISA simulator, proxy kernel, and GNU toolchain. 4 | # Tools will be installed to $RISCV. 5 | 6 | . build.common 7 | 8 | echo "Starting RISC-V Toolchain build process" 9 | 10 | check_version() { 11 | $1 --version | awk "NR==1 {if (\$NF>$2) {exit 0} exit 1}" || ( 12 | echo $3 requires at least version $2 of $1. Aborting. 13 | exit 1 14 | ) 15 | } 16 | 17 | check_version automake 1.14 "OpenOCD build" 18 | check_version autoconf 2.64 "OpenOCD build" 19 | build_project riscv-openocd --prefix=$RISCV --enable-remote-bitbang --enable-jtag_vpi --disable-werror 20 | 21 | build_project riscv-isa-sim --prefix=$RISCV 22 | CC= CXX= build_project riscv-pk --prefix=$RISCV --host=riscv64-unknown-elf 23 | build_project riscv-tests --prefix=$RISCV/riscv64-unknown-elf 24 | 25 | echo -e "\\nRISC-V Toolchain installation completed!" 26 | -------------------------------------------------------------------------------- /doc/busybox-menuconfig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riscv-software-src/riscv-tools/26190623292f82a0f001bdcba40cfa98786e8819/doc/busybox-menuconfig.png -------------------------------------------------------------------------------- /doc/linux-boot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riscv-software-src/riscv-tools/26190623292f82a0f001bdcba40cfa98786e8819/doc/linux-boot.png -------------------------------------------------------------------------------- /doc/linux-menuconfig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riscv-software-src/riscv-tools/26190623292f82a0f001bdcba40cfa98786e8819/doc/linux-menuconfig.png -------------------------------------------------------------------------------- /regression.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # Script to build RISC-V tools and then test (some of) them. 4 | 5 | set -ex 6 | 7 | echo "Starting RISC-V Toolchain Regression" 8 | 9 | # build the tools 10 | export base_dir=${PWD} 11 | mkdir -p regression_install 12 | export RISCV=${base_dir}/regression_install 13 | ./build.sh 14 | 15 | # test the tools 16 | export PATH="$RISCV/bin:$PATH" 17 | make -C ${base_dir}/riscv-tests/isa/ run 18 | make -C ${base_dir}/riscv-tests/benchmarks/ run riscv 19 | make -C ${base_dir}/riscv-tests/debug/ all-tests 20 | 21 | # test the pk 22 | echo -e '#include \n int main(void) { printf("Hello world!\\n"); return 0; }' > hello.c 23 | riscv64-unknown-elf-gcc -o hello hello.c 24 | spike pk hello 25 | 26 | # test glibc+pk 27 | rm -rf ${base_dir}/riscv-gnu-toolchain/build 28 | mkdir ${base_dir}/riscv-gnu-toolchain/build 29 | cd ${base_dir}/riscv-gnu-toolchain/build 30 | ../configure --prefix=$RISCV 31 | make linux 32 | cd ${base_dir}; rm hello 33 | riscv64-unknown-linux-gnu-gcc -static -Wl,-Ttext-segment,0x10000 -o hello hello.c 34 | spike pk hello 35 | 36 | 37 | echo -e "\\nRISC-V Toolchain regression completed!" 38 | --------------------------------------------------------------------------------