SlideShare a Scribd company logo
1 of 33
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 1/6/2020
An Introduction to RISC-V
Boot Flow
Atish Patra <Atish.Patra@wdc.com>
Anup Patel <Anup.Patel@wdc.com>
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 2
Outline
• Common embedded boot flow
• Current RISC-V boot flow
• OpenSBI Project
• Tutorials
• Current Status
• Future work
• Tutorials
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 3
Prerequisite
• Download the presentation
• Needs a Linux machine (Any distro will do)
• Linux Kernel source code build environment setup (optional)
• Instructions for Ubuntu
shorturl.at/clITU
sudo apt-get install git build-essential kernel-package fakeroot libncurses5-dev libssl-
dev bison flex
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 4
Getting started..
• Create a working directory
• Download cross-compiling toolchain
– https://toolchains.bootlin.com/releases_riscv64.html
• Download pre-built images
– https://wdc.box.com/s/ihywc2xap5m4mflyngjtndf0sy62zha3
• Clone OpenSBI
• Clone U-Boot
shorturl.at/clITU
git clone https://github.com/riscv/opensbi.git
mkdir summit_demo; cd summit_demo
git clone https://github.com/u-boot/u-boot.git ; git checkout v2019.10
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 5
Common boot flow
Commonly used multiple boot stages model
ROM LOADER RUNTIME BOOTLOADER OS
Loads
Jumps
• Runs from On-Chip
ROM
• Uses On-Chip SRAM
• SOC power-up and
clock setup
• DDR initialization
• Loads RUNTIME and
BOOTLOADER
• Examples:
• BIOS/UEFI
• U-Boot SPL
• Coreboot
• Runs from On-Chip SRAM or
DDR
• SOC security setup
• Runtime services as-per
specifications
• Examples:
• ATF
• BIOS/UEFI
• Runs from DDR
• Typically open-source
• Filesystem support
• Network booting
• Boot configuration
• Examples:
• U-Boot
• GRUB
• LinuxBoot
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6
Common boot flow in ARM64
Commonly used multiple boot stages model
ROM
Coreboot/U-Boot
SPL/ ATF BL2
ATF BL31 U-Boot OS
Loads
Jumps
Falcon mode in U-Boot
ARM64
specific
*ATF (ARM TRUSTED FIRMWARE)
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 7
RISC-V Upstream Boot Flow
Follows commonly used multiple boot stages model
• For HiFive Unleashed hardware (only Linux capable RISC-V platform available)
• Follows a standard boot flow
• Uses U-Boot as the last stage boot loader
• U-Boot binary as the payload to OpenSBI
• FSBL is SiFive specific and will be replaced by Coreboot/U-Boot SPL
• OpenSBI is a RISC-V specific runtime service provider
Linux
(S-mode)
(OS)
ZSBL
(M-mode)
(ROM)
FSBL
(M-mode)
(LOADER)
OpenSBI
(M-mode)
(RUNTIME)
U-Boot
(S-mode)
(BOOTLOADER)
Loads
Jumps
RISC-V
specific
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 8
RISC-V boot flow development timeline
OpenSBI
v0.1
release
U-Boot
SMP
support
U-Boot
MMC
support
U-Boot SPL
Coreboot
Legacy
Feb 18
Jan 19
Mar 19
July 19
Jul 19
Aug 19
EDK2
Oct 19
U-Boot
support for
Unleashed
Feb 19Grub
support
Nov 18
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 9
What is SBI ?
• SBI is the RISC-V Supervisor Binary Interface
– System call style calling convention between Supervisor (S-mode OS) and Supervisor
Execution Environment (SEE)
• SEE can be:
– A M-mode RUNTIME firmware for OS/Hypervisor running in HS-mode
– A HS-mode Hypervisor for Guest OS running in VS-mode
• SBI calls help:
– Reduce duplicate platform code across OSes (Linux, FreeBSD, etc)
– Provide common drivers for an OS which can be shared by multiple platforms
– Provide an interface for direct access to hardware resources (M-mode only resources)
• Specifications being drafted by the Unix Platform Specification Working group
– Currently, SBI v0.1 in-use and SBI v0.2 in draft stage
– https://github.com/riscv/riscv-sbi-doc
SEE (M-Mode)
SBI
OS (S-Mode)
ABI ABI
App1 App2
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 10
What is OpenSBI ?
• OpenSBI is an open-source implementation of the RISC-V Supervisor Binary Interface
(SBI) specifications
– Licensed under the terms of the BSD-2 clause license
– Helps to avoid SBI implementation fragmentation
– Maintained by the community
• Aimed at providing RUNTIME services in M-mode
– Typically used in boot stage following ROM/LOADER
• Provides support for reference platforms
– Generic simple drivers included for M-mode to operate
 PLIC, CLINT, UART 8250
– Other platforms can reuse the common code and add needed drivers
• Source
– https://github.com/riscv/opensbi
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 11
Key Features
• Layered structure to accommodate various use cases
– Generic SBI library with platform abstraction
• Typically used with external firmware and bootloader
– EDK2 (UEFI implementation), Secure boot working group
– Platform specific library
• Similar to core library but including platform specific drivers
– Platform specific reference firmware
• Three different types of RUNTIME firmware
• Wide range of hardware features supported
– RV32 and RV64
– Hypervisor support
– Misaligned load/store handling
– Missing CSR emulation
– Protects firmware using PMP support
Platform Specific
Reference Firmware
Platform Specific
Library
SBI Library
OpenSBI Layers
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 12
Platform support
• SiFive HiFive Unleashed
• Andes AE350
• Ariane FPGA SOC
• Kendryte K210
• QEMU virt machines (32-bit/64-bit)
• OmniXtend
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 13
Tutorial
• Working setup
• Extract toolchain and add it to the environment path
• Change the permission of qemu binary
• Set environment variable CROSS_COMPILE and ARCH
Setup details
chmod a+x qemu-system-riscv64
export ARCH=riscv; export CROSS_COMPILE=riscv64-linux-
tar –xvf riscv64--glibc--bleeding-edge-2018.11-1.tar.bz2
export PATH=$PATH:riscv64--glibc--bleeding-edge-2018.11-1/bin/
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 14
Tutorial-I
• Compile OpenSBI
• Run it in Qemu
Boot Linux in Qemu as a payload to OpenSBI
cd opensbi; make PLATFORM=qemu/virt FW_PAYLOAD_PATH=../linux_Image; cd ..
./qemu-system-riscv64 -M virt -m 256M -nographic 
-kernel opensbi/build/platform/qemu/virt/firmware/fw_payload.elf 
-drive file=linux_rootfs.img,format=raw,id=hd0 
-device virtio-blk-device,drive=hd0 
-append "root=/dev/vda rw console=ttyS0"
Linux kernel
imageVirt machine
in Qemu
OpenSBI
image
Linux rootfs
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 15
Adding Support for New Platforms
• To add support for a new <xyz> platform
1. Create directory named <xyz> under /platform directory
2. Create platform configuration file <xyz>/config.mk
 config.mk will provide compiler flags, select common drivers, and select firmware options
 platform/template/config.mk can be used as reference for creating config.mk
3. Create platform objects file <xyz>/objects.mk for listing platform-specific objects to be compiled
 platform/template/objects.mk can be used as reference for creating objects.mk
4. Create platform source file <xyz>/platform.c providing “struct sbi_platform” instance
 platform/template/platform.c can be used as reference for creating platform.c
• The <xyz> platform support directory can also placed outside OpenSBI sources
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 16
Reference Firmwares
• OpenSBI provides several types of reference firmware, all platform-specific
– FW_PAYLOAD
• Firmware with the next booting stage as a payload
• Default firmware being used in Linux capable RISC-V hardware
– FW_JUMP
• Firmware with fixed jump address to the next booting stage
• Default method for QEMU
– FW_DYNAMIC
• Firmware with dynamic information on the next booting stage
• U-Boot SPL/Coreboot is using FW_DYNAMIC
• SOC Vendors may choose:
– Use one of OpenSBI reference firmwares as their M-mode RUNTIME firmware
– Build M-mode RUNTIME firmware from scratch with OpenSBI as library
– Extend existing M-mode firmwares (U-Boot_M_mode/EDK2) with OpenSBI as library
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 17
U-Boot
• Most commonly used in embedded systems
• Used as a last stage boot loader
• Support
– many ISAs (x86, ARM, AARCH64, RISC-V, ARC..)
– Peripherals (UART, SPI, I2C, ethernet, SD, USB..)
– Multiple file systems
– Various network protocols
• Can load images from network, file system, removable devices
• Easy command line interface for management
• Lot of customization
– U-Boot SPL (a redacted version of U-Boot used as first stage boot loader)
– Falcon mode (for fast booting)
An universal boot loader
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 18
Tutorial - II
• Compile U-Boot
• Compile OpenSBI
• Run it in Qemu
Boot Linux in Qemu using U-Boot proper
cd opensbi; make PLATFORM=qemu/virt; cd ..
virt machine in Qemu
./qemu-system-riscv64 -M virt -smp 4 -m 256M -nographic 
-bios opensbi/build/platform/qemu/virt/firmware/fw_jump.elf 
-kernel u-boot/u-boot.bin -device loader,file=linux_Image,addr=0x84000000 
-drive file=linux_rootfs.img,format=raw,id=hd0 
-device virtio-blk-device,drive=hd0
OpenSBI firmware
(fw_jump)
Kernel address
expected by U-
boot
cd u-boot; make qemu-riscv64_smode_defconfig; make; cd ..
No payload!!
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 19
Tutorial - II
• At U-Boot prompt
Boot Linux in Qemu using U-Boot proper
=>setenv bootargs "root=/dev/vda rw console=ttyS0 earlycon=sbi"
=>cp.l ${fdtcontroladdr} ${fdt_addr_r} 0x10000
=>booti ${kernel_addr_r} - ${fdt_addr_r}
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 20
Boot flow using OpenSBI dynamic firmware
• OpenSBI firmware with dynamic information about the next booting
stage
• Coreboot support available on both hardware & QEMU
• U-Boot SPL available for QEMU and Andes AE350
• HiFive Unleashed U-Boot SPL support not available yet
Passed via ‘a2’ register
Linux
(S-mode)
(OS)
ZSBL
(M-mode)
(ROM)
U-Boot SPL/
Coreboot
(M-mode)
OpenSBI
(M-mode)
(RUNTIME)
U-Boot
(S-mode)
(BOOTLOADER)
Loads
Jumps
Proprietary
Open
Source
RISC-V
specific
struct
fw_dynamic_info
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 21
cd opensbi; make PLATFORM=qemu/virt; cd ..
Tutorial - III
• Compile OpenSBI
• Compile U-Boot SPL
• Run it in Qemu
Boot Linux in Qemu using U-Boot SPL
cd u-boot; export OPENSBI=../opensbi/build/platform/qemu/virt/firmware/fw_dynamic.bin;
ARCH=riscv CROSS_COMPILE=riscv64-linux- make qemu-riscv64_spl_defconfig
ARCH=riscv CROSS_COMPILE=riscv64-linux- make; cd ..
No payload!!
./qemu-system-riscv64 -nographic -machine virt -m 2G -bios u-boot/spl/u-boot-spl 
-kernel u-boot/u-boot.itb -device loader,file=linux_Image,addr=0x86000000 
-drive file=linux_rootfs.img,format=raw,id=hd0 
-device virtio-blk-device,drive=hd0
U-Boot SPL binary
FIT image
(OpenSBI + U-Boot
proper
Path to OpenSBI
dynamic firmware
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 22
Tutorial - III
• At U-Boot prompt
Boot Linux in Qemu using U-Boot proper
=>cp.b 0x86000000 ${kernel_addr_r} 0x1000000
=>setenv bootargs "root=/dev/vda rw console=ttyS0 earlycon=sbi"
=>cp.l ${fdtcontroladdr} ${fdt_addr_r} 0x10000
=>booti ${kernel_addr_r} - ${fdt_addr_r}
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 23
Boot flow using OpenSBI as a library
• OpenSBI as a part of external firmware source
code
• Must configure program stack and scratch
space for OpenSBI
• Same GCC target option for external firmware
and OpenSBI
• Currently EDK2 integration with OpenSBI
– HPE leading this effort
– Available in EDK2 mailing list for U540 on Xilinx VC707
FPGA
– OpenSBI built with EDK2 build environment
– OpenSBI used as library in Pre-EFI Initialization (PEI)
phase
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 24
Constraints on using OpenSBI as a Library
• Same GCC target options (i.e. -march, -mabi, and -mcmodel) need to be used for the
external firmware and OpenSBI sources
• External firmware must create per-HART non-overlapping:
– Program Stack
– OpenSBI scratch space (i.e. struct sbi_scratch instance with extra space above)
• Two constraints in calling any OpenSBI functions from external firmware:
– MSCRATCH CSR of calling HART must be set to its own OpenSBI scratch space
– SP register (i.e. the stack pointer) of calling HART must be set to its own stack
• External firmware must also ensure that:
– Interrupts are disabled in the MSTATUS and MIE CSRs when calling sbi_init()
– sbi_init() is called for each HART that is powered-up at boot-time or in response to a CPU hotplug event
– sbi_trap_handler() is called for M-mode interrupts and M-mode traps
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 25
Current status
• OpenSBI
– Actively developed and maintained
– Version 0.5 released
– Default in Buildroot, Yocto/OpenEmbedded and
the QEMU “BIOS”
– Fedora/Debian provides images available with
OpenSBI binary
• U-Boot
– U-Boot-2019.10 release has full support HiFive
Unleashed S-mode
– Boot via network/MMC supported
– FIT image support
– EFI support for RISC-V available
• Grub
– RISC-V support available upstream
• Linux Kernel
– Upstream kernel boots in QEMU
– Device tree hosted in Kernel
– v5.3 kernel works with OpenSBI+U-Boot
on HiFive Unleashed
Rapid progress: traditional full boot support expected by year end
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 26
Future boot support
• EFI stub support in Linux kernel for full UEFI support in progress
– Enterprise class boot environment
• U-Boot SPL support for HiFive Unleashed
• SMP support in coreboot
• EDK2 project upstreaming (in progress)
• Oreboot (Coreboot written in Rust)
• LinuxBoot ?
• Other bootloaders ?
Toward a stable and easy to use boot ecosystem
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 27
Ongoing work
• SBI specifications
– SBI v0.2 specification
– Hart state management extension in SBI
– Legacy SBI extension replacement in SBI
• OpenSBI
– Sequential cpu boot via CPU hotplug
– Support other M-mode boot loader such as
Coreboot/U-Boot SPL
– Hypervisor support when specification changes
– More platforms support
• Need hardware !
• Linux kernel
– SBI v0.2 implementation (patches are under
review)
– EFI stub in Linux kernel (work in progress)
– SBI legacy extension replacements
– Sequential booting
– CPU hotplug
Toward a stable and easy to use boot ecosystem
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 28
Acknowledgements
• U-Boot
– Lukas Auler
– Bin Meng
– Anup Patel
• Coreboot
– Ron Minnich
– Jonathan Neuschäfer
– Patrick Rudolph
– Philip Hug
• EDK2
– Abner Chang
• And others
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 29
Thank you!!
• Q&A ?
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 1/6/2020
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 31
Backup
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 32
EDK2 implementation details
• OpenSBI used as library
• Open Source EDK2 (UEFI implementation) OpenSBI integration
– HPE leading this effort
– Available in EDK2 staging area for U540 on Xilinx VC707 FPGA
– OpenSBI built with EDK2 build environment
Passed via ‘a2’ register
ZSBL
(M-mode)
(ROM)
Bootloader
(Grub/U-
Boot)
Loads
Jumps
Open
Source
RISC-V
specific
EDK2
FSBL
(M-mode)
(ROM)
Linux
(S-Mode)
OS
SEC
phase
PEI phase
(M-Mode)
DXE phase
(S-Mode)
BDS phase
(S-Mode)
EDK2 OpenSBI DXE Driver
(S-Mode)
OpenSBI library
(M-Mode)
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 33
Reference
• SBI
– https://github.com/riscv/riscv-sbi-doc
• EDK2
– https://edk2.groups.io/g/devel/message/46479?p=,,,20,0,0,0::Created,,riscv,20,2,0,33047245

More Related Content

What's hot

I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24Varun Mahajan
 
Yocto Project introduction
Yocto Project introductionYocto Project introduction
Yocto Project introductionYi-Hsiu Hsu
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013Wave Digitech
 
Introduction to yocto
Introduction to yoctoIntroduction to yocto
Introduction to yoctoAlex Gonzalez
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBshimosawa
 
Bootloaders (U-Boot)
Bootloaders (U-Boot) Bootloaders (U-Boot)
Bootloaders (U-Boot) Omkar Rane
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)shimosawa
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux SystemJian-Hong Pan
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device driversHoucheng Lin
 
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)Linaro
 
Project ACRN expose and pass through platform hidden PCIe devices to SOS
Project ACRN expose and pass through platform hidden PCIe devices to SOSProject ACRN expose and pass through platform hidden PCIe devices to SOS
Project ACRN expose and pass through platform hidden PCIe devices to SOSProject ACRN
 
RISC-V software state of the union
RISC-V software state of the unionRISC-V software state of the union
RISC-V software state of the unionRISC-V International
 

What's hot (20)

Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Embedded Operating System - Linux
Embedded Operating System - LinuxEmbedded Operating System - Linux
Embedded Operating System - Linux
 
Introduction to Modern U-Boot
Introduction to Modern U-BootIntroduction to Modern U-Boot
Introduction to Modern U-Boot
 
I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24
 
Yocto Project introduction
Yocto Project introductionYocto Project introduction
Yocto Project introduction
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
Introduction to yocto
Introduction to yoctoIntroduction to yocto
Introduction to yocto
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
 
Bootloaders (U-Boot)
Bootloaders (U-Boot) Bootloaders (U-Boot)
Bootloaders (U-Boot)
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux System
 
DPDK In Depth
DPDK In DepthDPDK In Depth
DPDK In Depth
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
 
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
 
Qemu
QemuQemu
Qemu
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
Project ACRN expose and pass through platform hidden PCIe devices to SOS
Project ACRN expose and pass through platform hidden PCIe devices to SOSProject ACRN expose and pass through platform hidden PCIe devices to SOS
Project ACRN expose and pass through platform hidden PCIe devices to SOS
 
I2c drivers
I2c driversI2c drivers
I2c drivers
 
RISC-V software state of the union
RISC-V software state of the unionRISC-V software state of the union
RISC-V software state of the union
 
Qemu Pcie
Qemu PcieQemu Pcie
Qemu Pcie
 

Similar to An Introduction to RISC-V bootflow

The role of_open_source_firmware_in_risc-v
The role of_open_source_firmware_in_risc-vThe role of_open_source_firmware_in_risc-v
The role of_open_source_firmware_in_risc-vAtish Patra
 
"Building Complete Embedded Vision Systems on Linux—From Camera to Display," ...
"Building Complete Embedded Vision Systems on Linux—From Camera to Display," ..."Building Complete Embedded Vision Systems on Linux—From Camera to Display," ...
"Building Complete Embedded Vision Systems on Linux—From Camera to Display," ...Edge AI and Vision Alliance
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)RuggedBoardGroup
 
Embedded Fest 2019. Wei Fu. Linux on RISC-V--Fedora and Firmware in practice
Embedded Fest 2019. Wei Fu. Linux on RISC-V--Fedora and Firmware in practiceEmbedded Fest 2019. Wei Fu. Linux on RISC-V--Fedora and Firmware in practice
Embedded Fest 2019. Wei Fu. Linux on RISC-V--Fedora and Firmware in practiceEmbeddedFest
 
FOSDEM_2019_Buildroot_RISCV.pdf
FOSDEM_2019_Buildroot_RISCV.pdfFOSDEM_2019_Buildroot_RISCV.pdf
FOSDEM_2019_Buildroot_RISCV.pdfssuser30e7d2
 
UplinQ - ubuntu linux on the qualcomm® snapdragon™ 600 processor
UplinQ - ubuntu linux on the qualcomm® snapdragon™ 600 processorUplinQ - ubuntu linux on the qualcomm® snapdragon™ 600 processor
UplinQ - ubuntu linux on the qualcomm® snapdragon™ 600 processorSatya Harish
 
Fedora on risc-v_tokyo_30_sep_2019_v4
Fedora on risc-v_tokyo_30_sep_2019_v4Fedora on risc-v_tokyo_30_sep_2019_v4
Fedora on risc-v_tokyo_30_sep_2019_v4Wei Fu
 
Building PoC ready ODM Platforms with Arm SystemReady v5.2.pdf
Building PoC ready ODM Platforms with Arm SystemReady v5.2.pdfBuilding PoC ready ODM Platforms with Arm SystemReady v5.2.pdf
Building PoC ready ODM Platforms with Arm SystemReady v5.2.pdfPaul Yang
 
Rasperry Pi and TI CC2650 IPv6 border router
Rasperry Pi and TI CC2650 IPv6 border routerRasperry Pi and TI CC2650 IPv6 border router
Rasperry Pi and TI CC2650 IPv6 border routerNikolaos Monios
 
XPDS14: Xen 4.5 Roadmap - Konrad Wilk, Oracle
XPDS14: Xen 4.5 Roadmap - Konrad Wilk, OracleXPDS14: Xen 4.5 Roadmap - Konrad Wilk, Oracle
XPDS14: Xen 4.5 Roadmap - Konrad Wilk, OracleThe Linux Foundation
 
A Tour of Open Source on the Mainframe
A Tour of Open Source on the MainframeA Tour of Open Source on the Mainframe
A Tour of Open Source on the MainframeAll Things Open
 
How to run Linux on RISC-V (FOSS North 2020)
How to run Linux on RISC-V (FOSS North 2020)How to run Linux on RISC-V (FOSS North 2020)
How to run Linux on RISC-V (FOSS North 2020)Drew Fustini
 
OSDC 2014: Nat Morris - Open Network Install Environment
OSDC 2014: Nat Morris - Open Network Install EnvironmentOSDC 2014: Nat Morris - Open Network Install Environment
OSDC 2014: Nat Morris - Open Network Install EnvironmentNETWAYS
 
20111011 bigbluebutton
20111011 bigbluebutton20111011 bigbluebutton
20111011 bigbluebuttonhs1250
 
Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)
Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)
Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)Drew Fustini
 

Similar to An Introduction to RISC-V bootflow (20)

The role of_open_source_firmware_in_risc-v
The role of_open_source_firmware_in_risc-vThe role of_open_source_firmware_in_risc-v
The role of_open_source_firmware_in_risc-v
 
"Building Complete Embedded Vision Systems on Linux—From Camera to Display," ...
"Building Complete Embedded Vision Systems on Linux—From Camera to Display," ..."Building Complete Embedded Vision Systems on Linux—From Camera to Display," ...
"Building Complete Embedded Vision Systems on Linux—From Camera to Display," ...
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
 
Embedded Fest 2019. Wei Fu. Linux on RISC-V--Fedora and Firmware in practice
Embedded Fest 2019. Wei Fu. Linux on RISC-V--Fedora and Firmware in practiceEmbedded Fest 2019. Wei Fu. Linux on RISC-V--Fedora and Firmware in practice
Embedded Fest 2019. Wei Fu. Linux on RISC-V--Fedora and Firmware in practice
 
FOSDEM_2019_Buildroot_RISCV.pdf
FOSDEM_2019_Buildroot_RISCV.pdfFOSDEM_2019_Buildroot_RISCV.pdf
FOSDEM_2019_Buildroot_RISCV.pdf
 
Slimline Open Firmware
Slimline Open FirmwareSlimline Open Firmware
Slimline Open Firmware
 
oSSN19 - openSUSE on ARM
oSSN19 - openSUSE on ARMoSSN19 - openSUSE on ARM
oSSN19 - openSUSE on ARM
 
UplinQ - ubuntu linux on the qualcomm® snapdragon™ 600 processor
UplinQ - ubuntu linux on the qualcomm® snapdragon™ 600 processorUplinQ - ubuntu linux on the qualcomm® snapdragon™ 600 processor
UplinQ - ubuntu linux on the qualcomm® snapdragon™ 600 processor
 
oSC19 openSUSE on ARM
oSC19 openSUSE on ARMoSC19 openSUSE on ARM
oSC19 openSUSE on ARM
 
Fedora on risc-v_tokyo_30_sep_2019_v4
Fedora on risc-v_tokyo_30_sep_2019_v4Fedora on risc-v_tokyo_30_sep_2019_v4
Fedora on risc-v_tokyo_30_sep_2019_v4
 
Building PoC ready ODM Platforms with Arm SystemReady v5.2.pdf
Building PoC ready ODM Platforms with Arm SystemReady v5.2.pdfBuilding PoC ready ODM Platforms with Arm SystemReady v5.2.pdf
Building PoC ready ODM Platforms with Arm SystemReady v5.2.pdf
 
UEFI presentation
UEFI presentationUEFI presentation
UEFI presentation
 
Building
BuildingBuilding
Building
 
Rasperry Pi and TI CC2650 IPv6 border router
Rasperry Pi and TI CC2650 IPv6 border routerRasperry Pi and TI CC2650 IPv6 border router
Rasperry Pi and TI CC2650 IPv6 border router
 
XPDS14: Xen 4.5 Roadmap - Konrad Wilk, Oracle
XPDS14: Xen 4.5 Roadmap - Konrad Wilk, OracleXPDS14: Xen 4.5 Roadmap - Konrad Wilk, Oracle
XPDS14: Xen 4.5 Roadmap - Konrad Wilk, Oracle
 
A Tour of Open Source on the Mainframe
A Tour of Open Source on the MainframeA Tour of Open Source on the Mainframe
A Tour of Open Source on the Mainframe
 
How to run Linux on RISC-V (FOSS North 2020)
How to run Linux on RISC-V (FOSS North 2020)How to run Linux on RISC-V (FOSS North 2020)
How to run Linux on RISC-V (FOSS North 2020)
 
OSDC 2014: Nat Morris - Open Network Install Environment
OSDC 2014: Nat Morris - Open Network Install EnvironmentOSDC 2014: Nat Morris - Open Network Install Environment
OSDC 2014: Nat Morris - Open Network Install Environment
 
20111011 bigbluebutton
20111011 bigbluebutton20111011 bigbluebutton
20111011 bigbluebutton
 
Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)
Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)
Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)
 

Recently uploaded

A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfICS
 
Sourcing Success - How to Find a Clothing Manufacturer
Sourcing Success - How to Find a Clothing ManufacturerSourcing Success - How to Find a Clothing Manufacturer
Sourcing Success - How to Find a Clothing ManufacturerWave PLM
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationElement34
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfWSO2
 
Reinforcement Learning – a Rewards Based Approach to Machine Learning - Marko...
Reinforcement Learning – a Rewards Based Approach to Machine Learning - Marko...Reinforcement Learning – a Rewards Based Approach to Machine Learning - Marko...
Reinforcement Learning – a Rewards Based Approach to Machine Learning - Marko...Marko Lohert
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAShane Coughlan
 
Malaysia E-Invoice digital signature docpptx
Malaysia E-Invoice digital signature docpptxMalaysia E-Invoice digital signature docpptx
Malaysia E-Invoice digital signature docpptxMok TH
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...naitiksharma1124
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMarkus Moeller
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationWave PLM
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfsteffenkarlsson2
 
Jax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined DeckJax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined DeckMarc Lester
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Henry Schreiner
 
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionThe Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionWave PLM
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfDeskTrack
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Chirag Panchal
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignNeo4j
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Andrea Goulet
 
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...CloudMetic
 

Recently uploaded (20)

A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
Sourcing Success - How to Find a Clothing Manufacturer
Sourcing Success - How to Find a Clothing ManufacturerSourcing Success - How to Find a Clothing Manufacturer
Sourcing Success - How to Find a Clothing Manufacturer
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
Reinforcement Learning – a Rewards Based Approach to Machine Learning - Marko...
Reinforcement Learning – a Rewards Based Approach to Machine Learning - Marko...Reinforcement Learning – a Rewards Based Approach to Machine Learning - Marko...
Reinforcement Learning – a Rewards Based Approach to Machine Learning - Marko...
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Malaysia E-Invoice digital signature docpptx
Malaysia E-Invoice digital signature docpptxMalaysia E-Invoice digital signature docpptx
Malaysia E-Invoice digital signature docpptx
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 
Jax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined DeckJax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined Deck
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionThe Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion Production
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
 

An Introduction to RISC-V bootflow

  • 1. © 2019 Western Digital Corporation or its affiliates. All rights reserved. 1/6/2020 An Introduction to RISC-V Boot Flow Atish Patra <Atish.Patra@wdc.com> Anup Patel <Anup.Patel@wdc.com>
  • 2. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 2 Outline • Common embedded boot flow • Current RISC-V boot flow • OpenSBI Project • Tutorials • Current Status • Future work • Tutorials
  • 3. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 3 Prerequisite • Download the presentation • Needs a Linux machine (Any distro will do) • Linux Kernel source code build environment setup (optional) • Instructions for Ubuntu shorturl.at/clITU sudo apt-get install git build-essential kernel-package fakeroot libncurses5-dev libssl- dev bison flex
  • 4. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 4 Getting started.. • Create a working directory • Download cross-compiling toolchain – https://toolchains.bootlin.com/releases_riscv64.html • Download pre-built images – https://wdc.box.com/s/ihywc2xap5m4mflyngjtndf0sy62zha3 • Clone OpenSBI • Clone U-Boot shorturl.at/clITU git clone https://github.com/riscv/opensbi.git mkdir summit_demo; cd summit_demo git clone https://github.com/u-boot/u-boot.git ; git checkout v2019.10
  • 5. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 5 Common boot flow Commonly used multiple boot stages model ROM LOADER RUNTIME BOOTLOADER OS Loads Jumps • Runs from On-Chip ROM • Uses On-Chip SRAM • SOC power-up and clock setup • DDR initialization • Loads RUNTIME and BOOTLOADER • Examples: • BIOS/UEFI • U-Boot SPL • Coreboot • Runs from On-Chip SRAM or DDR • SOC security setup • Runtime services as-per specifications • Examples: • ATF • BIOS/UEFI • Runs from DDR • Typically open-source • Filesystem support • Network booting • Boot configuration • Examples: • U-Boot • GRUB • LinuxBoot
  • 6. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6 Common boot flow in ARM64 Commonly used multiple boot stages model ROM Coreboot/U-Boot SPL/ ATF BL2 ATF BL31 U-Boot OS Loads Jumps Falcon mode in U-Boot ARM64 specific *ATF (ARM TRUSTED FIRMWARE)
  • 7. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 7 RISC-V Upstream Boot Flow Follows commonly used multiple boot stages model • For HiFive Unleashed hardware (only Linux capable RISC-V platform available) • Follows a standard boot flow • Uses U-Boot as the last stage boot loader • U-Boot binary as the payload to OpenSBI • FSBL is SiFive specific and will be replaced by Coreboot/U-Boot SPL • OpenSBI is a RISC-V specific runtime service provider Linux (S-mode) (OS) ZSBL (M-mode) (ROM) FSBL (M-mode) (LOADER) OpenSBI (M-mode) (RUNTIME) U-Boot (S-mode) (BOOTLOADER) Loads Jumps RISC-V specific
  • 8. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 8 RISC-V boot flow development timeline OpenSBI v0.1 release U-Boot SMP support U-Boot MMC support U-Boot SPL Coreboot Legacy Feb 18 Jan 19 Mar 19 July 19 Jul 19 Aug 19 EDK2 Oct 19 U-Boot support for Unleashed Feb 19Grub support Nov 18
  • 9. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 9 What is SBI ? • SBI is the RISC-V Supervisor Binary Interface – System call style calling convention between Supervisor (S-mode OS) and Supervisor Execution Environment (SEE) • SEE can be: – A M-mode RUNTIME firmware for OS/Hypervisor running in HS-mode – A HS-mode Hypervisor for Guest OS running in VS-mode • SBI calls help: – Reduce duplicate platform code across OSes (Linux, FreeBSD, etc) – Provide common drivers for an OS which can be shared by multiple platforms – Provide an interface for direct access to hardware resources (M-mode only resources) • Specifications being drafted by the Unix Platform Specification Working group – Currently, SBI v0.1 in-use and SBI v0.2 in draft stage – https://github.com/riscv/riscv-sbi-doc SEE (M-Mode) SBI OS (S-Mode) ABI ABI App1 App2
  • 10. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 10 What is OpenSBI ? • OpenSBI is an open-source implementation of the RISC-V Supervisor Binary Interface (SBI) specifications – Licensed under the terms of the BSD-2 clause license – Helps to avoid SBI implementation fragmentation – Maintained by the community • Aimed at providing RUNTIME services in M-mode – Typically used in boot stage following ROM/LOADER • Provides support for reference platforms – Generic simple drivers included for M-mode to operate  PLIC, CLINT, UART 8250 – Other platforms can reuse the common code and add needed drivers • Source – https://github.com/riscv/opensbi
  • 11. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 11 Key Features • Layered structure to accommodate various use cases – Generic SBI library with platform abstraction • Typically used with external firmware and bootloader – EDK2 (UEFI implementation), Secure boot working group – Platform specific library • Similar to core library but including platform specific drivers – Platform specific reference firmware • Three different types of RUNTIME firmware • Wide range of hardware features supported – RV32 and RV64 – Hypervisor support – Misaligned load/store handling – Missing CSR emulation – Protects firmware using PMP support Platform Specific Reference Firmware Platform Specific Library SBI Library OpenSBI Layers
  • 12. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 12 Platform support • SiFive HiFive Unleashed • Andes AE350 • Ariane FPGA SOC • Kendryte K210 • QEMU virt machines (32-bit/64-bit) • OmniXtend
  • 13. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 13 Tutorial • Working setup • Extract toolchain and add it to the environment path • Change the permission of qemu binary • Set environment variable CROSS_COMPILE and ARCH Setup details chmod a+x qemu-system-riscv64 export ARCH=riscv; export CROSS_COMPILE=riscv64-linux- tar –xvf riscv64--glibc--bleeding-edge-2018.11-1.tar.bz2 export PATH=$PATH:riscv64--glibc--bleeding-edge-2018.11-1/bin/
  • 14. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 14 Tutorial-I • Compile OpenSBI • Run it in Qemu Boot Linux in Qemu as a payload to OpenSBI cd opensbi; make PLATFORM=qemu/virt FW_PAYLOAD_PATH=../linux_Image; cd .. ./qemu-system-riscv64 -M virt -m 256M -nographic -kernel opensbi/build/platform/qemu/virt/firmware/fw_payload.elf -drive file=linux_rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -append "root=/dev/vda rw console=ttyS0" Linux kernel imageVirt machine in Qemu OpenSBI image Linux rootfs
  • 15. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 15 Adding Support for New Platforms • To add support for a new <xyz> platform 1. Create directory named <xyz> under /platform directory 2. Create platform configuration file <xyz>/config.mk  config.mk will provide compiler flags, select common drivers, and select firmware options  platform/template/config.mk can be used as reference for creating config.mk 3. Create platform objects file <xyz>/objects.mk for listing platform-specific objects to be compiled  platform/template/objects.mk can be used as reference for creating objects.mk 4. Create platform source file <xyz>/platform.c providing “struct sbi_platform” instance  platform/template/platform.c can be used as reference for creating platform.c • The <xyz> platform support directory can also placed outside OpenSBI sources
  • 16. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 16 Reference Firmwares • OpenSBI provides several types of reference firmware, all platform-specific – FW_PAYLOAD • Firmware with the next booting stage as a payload • Default firmware being used in Linux capable RISC-V hardware – FW_JUMP • Firmware with fixed jump address to the next booting stage • Default method for QEMU – FW_DYNAMIC • Firmware with dynamic information on the next booting stage • U-Boot SPL/Coreboot is using FW_DYNAMIC • SOC Vendors may choose: – Use one of OpenSBI reference firmwares as their M-mode RUNTIME firmware – Build M-mode RUNTIME firmware from scratch with OpenSBI as library – Extend existing M-mode firmwares (U-Boot_M_mode/EDK2) with OpenSBI as library
  • 17. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 17 U-Boot • Most commonly used in embedded systems • Used as a last stage boot loader • Support – many ISAs (x86, ARM, AARCH64, RISC-V, ARC..) – Peripherals (UART, SPI, I2C, ethernet, SD, USB..) – Multiple file systems – Various network protocols • Can load images from network, file system, removable devices • Easy command line interface for management • Lot of customization – U-Boot SPL (a redacted version of U-Boot used as first stage boot loader) – Falcon mode (for fast booting) An universal boot loader
  • 18. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 18 Tutorial - II • Compile U-Boot • Compile OpenSBI • Run it in Qemu Boot Linux in Qemu using U-Boot proper cd opensbi; make PLATFORM=qemu/virt; cd .. virt machine in Qemu ./qemu-system-riscv64 -M virt -smp 4 -m 256M -nographic -bios opensbi/build/platform/qemu/virt/firmware/fw_jump.elf -kernel u-boot/u-boot.bin -device loader,file=linux_Image,addr=0x84000000 -drive file=linux_rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 OpenSBI firmware (fw_jump) Kernel address expected by U- boot cd u-boot; make qemu-riscv64_smode_defconfig; make; cd .. No payload!!
  • 19. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 19 Tutorial - II • At U-Boot prompt Boot Linux in Qemu using U-Boot proper =>setenv bootargs "root=/dev/vda rw console=ttyS0 earlycon=sbi" =>cp.l ${fdtcontroladdr} ${fdt_addr_r} 0x10000 =>booti ${kernel_addr_r} - ${fdt_addr_r}
  • 20. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 20 Boot flow using OpenSBI dynamic firmware • OpenSBI firmware with dynamic information about the next booting stage • Coreboot support available on both hardware & QEMU • U-Boot SPL available for QEMU and Andes AE350 • HiFive Unleashed U-Boot SPL support not available yet Passed via ‘a2’ register Linux (S-mode) (OS) ZSBL (M-mode) (ROM) U-Boot SPL/ Coreboot (M-mode) OpenSBI (M-mode) (RUNTIME) U-Boot (S-mode) (BOOTLOADER) Loads Jumps Proprietary Open Source RISC-V specific struct fw_dynamic_info
  • 21. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 21 cd opensbi; make PLATFORM=qemu/virt; cd .. Tutorial - III • Compile OpenSBI • Compile U-Boot SPL • Run it in Qemu Boot Linux in Qemu using U-Boot SPL cd u-boot; export OPENSBI=../opensbi/build/platform/qemu/virt/firmware/fw_dynamic.bin; ARCH=riscv CROSS_COMPILE=riscv64-linux- make qemu-riscv64_spl_defconfig ARCH=riscv CROSS_COMPILE=riscv64-linux- make; cd .. No payload!! ./qemu-system-riscv64 -nographic -machine virt -m 2G -bios u-boot/spl/u-boot-spl -kernel u-boot/u-boot.itb -device loader,file=linux_Image,addr=0x86000000 -drive file=linux_rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 U-Boot SPL binary FIT image (OpenSBI + U-Boot proper Path to OpenSBI dynamic firmware
  • 22. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 22 Tutorial - III • At U-Boot prompt Boot Linux in Qemu using U-Boot proper =>cp.b 0x86000000 ${kernel_addr_r} 0x1000000 =>setenv bootargs "root=/dev/vda rw console=ttyS0 earlycon=sbi" =>cp.l ${fdtcontroladdr} ${fdt_addr_r} 0x10000 =>booti ${kernel_addr_r} - ${fdt_addr_r}
  • 23. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 23 Boot flow using OpenSBI as a library • OpenSBI as a part of external firmware source code • Must configure program stack and scratch space for OpenSBI • Same GCC target option for external firmware and OpenSBI • Currently EDK2 integration with OpenSBI – HPE leading this effort – Available in EDK2 mailing list for U540 on Xilinx VC707 FPGA – OpenSBI built with EDK2 build environment – OpenSBI used as library in Pre-EFI Initialization (PEI) phase
  • 24. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 24 Constraints on using OpenSBI as a Library • Same GCC target options (i.e. -march, -mabi, and -mcmodel) need to be used for the external firmware and OpenSBI sources • External firmware must create per-HART non-overlapping: – Program Stack – OpenSBI scratch space (i.e. struct sbi_scratch instance with extra space above) • Two constraints in calling any OpenSBI functions from external firmware: – MSCRATCH CSR of calling HART must be set to its own OpenSBI scratch space – SP register (i.e. the stack pointer) of calling HART must be set to its own stack • External firmware must also ensure that: – Interrupts are disabled in the MSTATUS and MIE CSRs when calling sbi_init() – sbi_init() is called for each HART that is powered-up at boot-time or in response to a CPU hotplug event – sbi_trap_handler() is called for M-mode interrupts and M-mode traps
  • 25. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 25 Current status • OpenSBI – Actively developed and maintained – Version 0.5 released – Default in Buildroot, Yocto/OpenEmbedded and the QEMU “BIOS” – Fedora/Debian provides images available with OpenSBI binary • U-Boot – U-Boot-2019.10 release has full support HiFive Unleashed S-mode – Boot via network/MMC supported – FIT image support – EFI support for RISC-V available • Grub – RISC-V support available upstream • Linux Kernel – Upstream kernel boots in QEMU – Device tree hosted in Kernel – v5.3 kernel works with OpenSBI+U-Boot on HiFive Unleashed Rapid progress: traditional full boot support expected by year end
  • 26. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 26 Future boot support • EFI stub support in Linux kernel for full UEFI support in progress – Enterprise class boot environment • U-Boot SPL support for HiFive Unleashed • SMP support in coreboot • EDK2 project upstreaming (in progress) • Oreboot (Coreboot written in Rust) • LinuxBoot ? • Other bootloaders ? Toward a stable and easy to use boot ecosystem
  • 27. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 27 Ongoing work • SBI specifications – SBI v0.2 specification – Hart state management extension in SBI – Legacy SBI extension replacement in SBI • OpenSBI – Sequential cpu boot via CPU hotplug – Support other M-mode boot loader such as Coreboot/U-Boot SPL – Hypervisor support when specification changes – More platforms support • Need hardware ! • Linux kernel – SBI v0.2 implementation (patches are under review) – EFI stub in Linux kernel (work in progress) – SBI legacy extension replacements – Sequential booting – CPU hotplug Toward a stable and easy to use boot ecosystem
  • 28. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 28 Acknowledgements • U-Boot – Lukas Auler – Bin Meng – Anup Patel • Coreboot – Ron Minnich – Jonathan Neuschäfer – Patrick Rudolph – Philip Hug • EDK2 – Abner Chang • And others
  • 29. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 29 Thank you!! • Q&A ?
  • 30. © 2019 Western Digital Corporation or its affiliates. All rights reserved. 1/6/2020
  • 31. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 31 Backup
  • 32. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 32 EDK2 implementation details • OpenSBI used as library • Open Source EDK2 (UEFI implementation) OpenSBI integration – HPE leading this effort – Available in EDK2 staging area for U540 on Xilinx VC707 FPGA – OpenSBI built with EDK2 build environment Passed via ‘a2’ register ZSBL (M-mode) (ROM) Bootloader (Grub/U- Boot) Loads Jumps Open Source RISC-V specific EDK2 FSBL (M-mode) (ROM) Linux (S-Mode) OS SEC phase PEI phase (M-Mode) DXE phase (S-Mode) BDS phase (S-Mode) EDK2 OpenSBI DXE Driver (S-Mode) OpenSBI library (M-Mode)
  • 33. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 33 Reference • SBI – https://github.com/riscv/riscv-sbi-doc • EDK2 – https://edk2.groups.io/g/devel/message/46479?p=,,,20,0,0,0::Created,,riscv,20,2,0,33047245

Editor's Notes

  1. U-Boot supports MMC card & tftpbooting Why another runtime service Provider ? Why OpenSBI ?? Qemu can load super
  2. That’s the personification of RISC-V I could come up with which tells how incapable is right brain is  Legacy – BBL + Vmlinux as a single binary Grub was ported to RISC-V were upstreamed sometime in last year. UEFI support in U-Boot was done even before that time. But it was way ahead of its time as there was no effort in separating supervisor binary interface implementation from the Linux.
  3. Maintain and evolve the SBI specifications
  4. 20K lines of code 49K – dynamic firmware
  5. SPL (Secondary Program Loader) is a small binary, generated from U-Boot source, that fits in the SRAM and loads the main U-Boot into system RAM. SPL also support network/mmc boot.
  6. OpenSBI firmware with dynamic information about the next booting stage The next stage booting stage (i.e. BOOTLADER) and FW_DYNAMIC are loaded by the previous booting stage (i.e. LOADER) The previous booting stage (i.e. LOADER) passes the location of struct fw_dynamic_info to FW_DYNAMIC via ‘a2’ register Down-side: Previous booting stage (i.e. LOADER) needs to be aware of struct fw_dynamic_info