[coreboot] How to run coreboot + BBL/opensbi (provide SBI support) + Linux kernel on HiFive Unleashe

本文档详细介绍了如何在HiFive Unleashed板上通过coreboot+BBL(提供SBI支持)+Linux内核进行启动。主要步骤包括获取源代码、构建BBL和coreboot、编译Linux内核,以及烧录到SD卡和SPI闪存。同时提到了当前coreboot版本尚不能直接运行Linux内核,但可以通过HardenedLinux和SiFive提供的工作版本进行测试。
摘要由CSDN通过智能技术生成

Summary

This article is a breif intro about how to run coreboot + BBL/opensbi (provide SBI support) + Linux kernel on HiFive Unleashed.

The current coreboot version( Jan 7 2019) is not able to run linux kernel on HiFive Unleashed yet. We’ve been using the workaround version(BBL provide SBI support / opensbi provide SBI support) for test provided by HardenedLinux and BBL/linux provided by SiFive. Plz note that we will continue to upstreaming Unleashed code to the coreboot. W/ many thanks to Jonathan Neuschäfer, Philipp Hug and Ron Minnich.

The difference of the boot process between sifive’s firmware and coreboot

sifive's original firmware boot process:
                                    +-----------+
+------+    +------+    +------+    | BBL       |
| MSEL |--->| ZSBL |--->| FSBL |--->|   +-------+
+------+    +------+    +------+    |   | linux |
                                    +---+-------+

coreboot boot process:
                      +---------------------------------------------------------------------+
                      | coreboot                                                            |
+------+   +------+   |  +-----------+  +----------+  +----------+  +-----------------------+
| MSEL |-->| ZSBL |-->|  | bootblock |->| romstage |->| ramstage |->| payload (BBL/opensbi) |
+------+   +------+   |  +-----------+  +----------+  +----------+  |             +-------+ |
                      |                                             |             | linux | |
                      +---------------------------------------------+-------------+-------+-+

BBL provide SBI support

Get the source code

git clone -b HiFive-Unleashed-Test-Change git@github.com:hardenedlinux/coreboot-HiFiveUnleashed.git
git clone git@github.com:sifive/freedom-u-sdk.git

Build BBL

Because coreboot will occupy a portion of the memory starting at 0x80000000, BBL cannot run from address 0x80000000. So we need to adjust the starting address of the BBL. Modify freedom-u-sdk/riscv-pk/bbl/bbl.lds as follows:

diff --git a/bbl/bbl.lds b/bbl/bbl.lds
index 2fd0d7c..181f3ff 100644
--- a/bbl/bbl.lds
+++ b/bbl/bbl.lds
@@ -10,7 +10,7 @@ SECTIONS
   /*--------------------------------------------------------------------*/

   /* Begining of code and text segment */
-  . = 0x80000000;
+  . = 0x82000000;
   _ftext = .;
   PROVIDE( eprol = . );

Type make to compile. BBL’s elf image is located at freedom-u-sdk/work/riscv-pk/bbl

Build coreboot

Build toolchain

make crossgcc-riscv

Configuration

make menuconfig
  • Mainboard->Mainboard vendor, select SiFive
  • Mainboard->Mainboard model, select HiFive Unleashed
  • Chipset->Privilege level for payload, select payload running in m-mode
  • Payload->Add a payload, select An ELF executable payload
  • Payload->Payload path and filename, Use default value payload.elf

Compile

Copy BBL image from freedom-u-sdk/work/riscv-pk/bbl to coreboot/payload.elf, then type make to compile.

opensbi provide SBI support

Get the source code

git clone -b opensbi-test git@github.com:hardenedlinux/coreboot-HiFiveUnleashed.git
git clone git@github.com:sifive/freedom-u-sdk.git

Build linux kernel

Type make to compile. linux’s elf image is located at freedom-u-sdk/work/linux/vmlinux-stripped

Build coreboot

Build toolchain

make crossgcc-riscv

Configuration

make menuconfig
  • Mainboard->Mainboard vendor, select SiFive
  • Mainboard->Mainboard model, select HiFive Unleashed
  • Payload->Add a payload, select An linux binary payload
  • Payload->Payload path and filename, Use default value payload.bin

Compile

Create linux image: riscv64-elf-objcopy -O binary freedom-u-sdk/work/linux/vmlinux-stripped coreboot/payload.bin, then type make to compile.

Burn

There are two ways to burn coreboot, write to spi flash or sdcard.

Burn to sdcard

sudo dd build/coreboot.rom /dev/sdx

/dev/sdx is the device of your sd card reader

Burn to spi flash

Get the original firmware

wget https://static.dev.sifive.com/dev-kits/hifive-unleashed/hifive-unleashed-firmware-1.0.zip

Start the original firmware from the sd card

Unzip the original firmware and burn hifive-unleashed-a00-A.B-YYYY-MM-DD.gpt to the sd card.

sudo dd if=hifive-unleashed-a00-A.B-YYYY-MM-DD.gpt of=/dev/sdx

/dev/sdx is the device of your sd card reader

Turn the MSEL DIP switch to 11, connect the USB and network cable, and connect ttyUSB1 via minicom (baud rate 115200 8N1), then press the reset button to restart.

Then log in the Linux by terminal, username: root, password: sifive. In my test the network can not be automatically configured, you need to enter the following command by yourself.

/etc/init.d/S40network restart

Burn to spi flash

scp coreboot/build/coreboot.rom root@$target_ip:/tmp/
ssh root@$target_ip "/usr/sbin/flashcp -v /tmp/coreboot.rom /dev/mtd0"

target_ip is the IP of HiFive Unleashed

Testing

Turn the MSEL DIP switch to 15/11 (15 for boot from spi flash, 11 for boot from sdcard), connect the USB and network cable, and connect ttyUSB1 via minicom (baud rate 115200 8N1), then press the reset button to restart. Then you will see the log in the terminal.

Linux username: root, password: sifive.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值