-
Notifications
You must be signed in to change notification settings - Fork 0
Linux shenanigans
This page documents how to compile and run the Linux kernel on IRVE and LETC.
To compile the Linux kernel for a RISC-V platform, you need to install a toolchain.
We use https://github.com/riscv-collab/riscv-gnu-toolchain. Unlike with RVSW software, for the kernel we can't use the Newlib version of the toolchain, otherwise you will get dynamic linking errors pertaining to "vDSO" (used to speed up certain system calls).
However, you must have both toolchains installed simultaneously so you can compile both compile the kernel/userspace programs and bare metal software!
So first follow the instructions here to install the Newlib toolchain, and then the ones below to install the glibc one!
-
Do
git clone https://github.com/riscv-collab/riscv-gnu-toolchain.git
-
cd
into the directory that was cloned -
Do
./configure --prefix=/path/to/non/conflicting/prefix/dir --with-arch=rv32ima --with-abi=ilp32
-
Do
make linux -j <number of threads here>
to actually compile and install the toolchain (not justmake
as that will give you the Newlib version). -
Ensure all of the
riscv32-unknown-linux-gnu-
tools, contained within thebin
subdirectory of your prefix, are in yourPATH
. Theriscv32-unknown-elf-
tools are the Newlib variants, and must be in yourPATH
as well!
With that we are ready to proceed!
The repo https://github.com/angry-goose-initiative/build-linux contains helper thingamabobs to aid in compiling the Linux kernel.
-
Do
git clone https://github.com/angry-goose-initiative/build-linux.git
-
cd
into the directory that was cloned
You're now set to automatically build either the S-Mode/MMU or M-Mode/NOMMU kernels for either IRVE or LETC!
Sure! Skip all of this second-toolchain-automated-compilation nonsense by downloading the kernel image file attached to our IRVE 1.0.0 release
Put any additional files you want to access in the booted environment under initramfs/contents/
.
You'll see that there is already a directory structure there that looks similar to a regular Linux file system.
After doing this and following the common steps, do make kernel/irve-mmu/arch/riscv/boot/Image
. Add -j <# of threads>
to speed up the process!
This will fetch the required git modules, and also build busybox
if it hasn't been built already, which provides command line tools.
It will also build IRVE again in inception mode so you can run IRVE in IRVE! :)
Then the kernel will be compiled, with initramfs contents taken from initramfs/contents/
!
You'll likely be interested in
build-linux/kernel/irve-mmu/arch/riscv/boot/Image
and
build-linux/kernel/irve-mmu/vmlinux
After following the common steps, do make kernel/irve-nommu/arch/riscv/boot/Image
. Add -j <# of threads>
to speed up the process!
After a bit of waiting the results will be in build-linux/kernel/irve-nommu
. You'll likely be interested in
build-linux/kernel/irve-nommu/arch/riscv/boot/Image
and
build-linux/kernel/irve-nommu/vmlinux
Note that unlike the S-Mode kernel, at the moment no initramfs is present, so this isn't that useful except to watch the kernel boot (and then panic due to there not being a root filesystem).
We have scripts in the irve
repo to simplify this!
IMPORTANT: You must compile IRVE in Release mode with cmake -DCMAKE_BUILD_TYPE=Release ..
instead of just cmake ..
. Things will work in debug mode, however it will take minutes for the kernel to boot and there will be constant verbose debug messages.
Assuming you've already compiled IRVE with RVSW software (this means you will need the Newlib RISC-V toolchain as well), from the root of that repo do one of the following:
./scripts/irve_smode_linux.sh path/to/linux/arch/riscv/boot/Image
With any luck you should see the OGSBI
RVSW bootloader and SBI implementation run, followed by kernel messages!
You then should be dropped into a shell prompt where you can begin to mess around with things!
To step through the kernel with GDB, do
./scripts/irvegdb_smode_linux.sh path/to/linux/arch/riscv/boot/Image path/to/linux/vmlinux
The raw binary Image
is loaded by IRVE, and the symbol-containing vmlinux
provides debugging symbols to GDB. Execution should pause at 0x80000000, the entry point of the kernel (before it enables paging).
./scripts/irve_mmode_linux.sh path/to/linux/arch/riscv/boot/Image
With any luck you should see the nommulinux
RVSW bootloader run, followed by kernel messages!
To step through the kernel with GDB, do
./scripts/irvegdb_mmode_linux.sh path/to/linux/arch/riscv/boot/Image path/to/linux/vmlinux
The raw binary Image
is loaded by IRVE, and the symbol-containing vmlinux
provides debugging symbols to GDB. Execution should pause at 0x80000000, the entry point of the kernel.
TODO
TODO
-
Do
git clone https://github.com/angry-goose-initiative/linux
. This is our modified fork of the Linux kernel used by AGI projects. -
Do
git switch <branch name>
to switch to the version of our kernel you are interested in. This is likely one ofirve-mmu
,irve-nommu
,letc-mmu
, orletc-nommu
. -
Choose a Linux config file from the
build-linux
repo underbuild-linux/kernel/config/
and copy it to.config
in the root of thelinux
repo. -
Optionally tweak the config yourself with
make ARCH=riscv CROSS_COMPILE=riscv32-unknown-linux-gnu- xconfig
to use the graphical Qt interface (what I prefer). You can substitute this withmenuconfig
or other config options if you prefer/don't have Qt libraries installed. -
To actually cross-compile the kernel, do
make ARCH=riscv CROSS_COMPILE=riscv32-unknown-linux-gnu- all -j <number of threads here>
- Quickstart: Running Hello World on IRVE
- Setting up the RISC‐V Toolchain
- Setting up LETC in Vivado & Vitis
- Simulating LETC
- Synthesizing LETC
- Linux shenanigans
- Creating a Test Program
- Using GDB with IRVE
- Cross Compiling Manually
- General EEI Info
- Exceptions and Interrupts
- Memory Map
- Virtual Memory
- PMA & PMP
- Control Status Registers (CSRs)