Build Berkeley boot loader

What is this for ?

The RISCV specification defines (optionally) three main modes of operation: user, supervisor, and machine mode. Some documents also refer to a hypervisor mode, which may or may not be necessary. Some of the differences are:

  • User mode: the mode which runs the users programs and the lowest privilege level.
    1. No direct access to I/O or privileged instructions or kernel memory or other processes.
    2. Memory management unit always on under Linux.
  • Supervisor mode: the mode that the majority of the Linux kernel or other O/S runs.
    1. Access to most privileged instructions and I/O via ioremap function.
    2. Memory management unit may be on or off.
  • Machine mode: Bare-metal / First-stage boot loader and BBL runs in this mode.
    1. Memory management off.
    2. No memory protection.
  • Hypervisor mode: Might be supported in future, would be used to support virtualisation such as Xen hypervisor.

A simple summary of BBL is that it is the executable of last-resort when neither user-mode nor Linux cannot handle an operation. Currently it handles:

  1. Any illegal instructions that the RISCV processor is not equipped to handle directly in hardware.
  2. Initiation and responding to timer interrupts.
  3. Handling unaligned memory accesses (deprecated because it slows things a great deal).
  4. Chain loading and initial console access when Linux is booting, to simplify the first-stage boot loader.

The ariane version of lowRISC incorporates a UART which is software compatible with the ns16750, this enables BBL to be build directly from upstream sources. This will happen automatically with the Makefile dependencies, but should you wish to build manually it can be done as follows:

mkdir -p riscv-pk/build
cd riscv-pk/build
export RISCV=/opt/riscv
export PATH=$(RISCV)/bin:$PATH
../configure --host=riscv64-unknown-elf --enable-print-device-tree --with-payload=../../linux-5.3.8-lowrisc/vmlinux
make
riscv64-unknown-elf-strip bbl

The optional use of the strip command minimises the download size for use with Ethernet or MMC/SD-Card loading.

Next step: