Skip to content

Instantly share code, notes, and snippets.

@DoctorWkt
Last active May 20, 2019 14:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DoctorWkt/64851cb4e86721999f554dbd3769ea68 to your computer and use it in GitHub Desktop.
Save DoctorWkt/64851cb4e86721999f554dbd3769ea68 to your computer and use it in GitHub Desktop.
Building a RISC-V Debian Environment on a Debian/Ubuntu System

Building a RISC-V Debian Environment on a Debian/Ubuntu System

Here is how you can set up a simulated RISC-V Debian environment on an existing Debian or Ubuntu system (as at November 2018). You will probably have to apt-get some extra packages along the way.

Firstly, make a new empty directory and set the TOP environment variable to be the full pathname of this directory:

mkdir Z
cd Z
export TOP=`pwd`

Now clone the lowRISC qemu and debian-riscv64 repositories:

git clone https://github.com/lowRISC/qemu.git
git clone -b refresh-v0.6 https://github.com/lowRISC/debian-riscv64

Go into the qemu directory and build the user-mode version of qemu:

cd qemu
./configure --static --disable-system --target-list=riscv64-linux-user
make

You should get:

-rwxr-xr-x 1 wkt wkt 15407056 Nov  9 09:40 riscv64-linux-user/qemu-riscv64

Go into the debian-riscv64 directory and tell the system to use the qemu user-mode simulator as the interpreter for any RISC-V binaries:

cd ../debian-riscv64
sudo update-binfmts --import work/qemu-riscv64

Ignore the message that says that no executable /usr/bin/qemu-riscv64-static can be found. We will be chrooting into the simulated RISC-V environment, so the path to the qemu binary refers to the location inside the chroot environment.

These next few lines come from $TOP/debian-riscv64/work/makefile.inc, so perhaps read this file to see if there are any changes.

Fetch the GPG keys from the Ubuntu keyserver, and then run a script to fetch the base Debian packages and install them into the chroot directory, which will be $TOP/debian-riscv64/work/debian-riscv64-chroot:

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 06AED62430CB581C 8B48AD6246925553 7638D0442B90D010 04EE7237B7D453EC
sh work/mybootstrap.sh

Your RISC-V Debian environment is now ready to use. However, if you want, you can clean up the qemu build and remove the Debian package files that were installed:

cd ../qemu; make clean; cd ..
sudo rm debian-riscv64/work/debian-riscv64-chroot/var/cache/apt/archives/*.deb

Now, start a bash shell in the chrooted RISC-V Debian environment:

sudo chroot debian-riscv64/work/debian-riscv64-chroot /bin/bash
# uname -a; cat /etc/debian_version 
Linux 4.15.0 #160-Ubuntu SMP Wed Aug 15 14:58:00 UTC 2018 riscv64 GNU/Linux
buster/sid

Once you are in, you will need to configure the locale in your enviromnent:

apt-get install locales
dpkg-reconfigure locales

You might also want to install some more packages:

apt-get install build-essential vim-tiny

Simply exit from the bash shell to leave the chrooted RISC-V Debian environment.

@jrrk
Copy link

jrrk commented May 20, 2019

You might need to mount /proc and/or /dev in the chroot to do non-trivial work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment