EDK2 first boot

Hello folks,

I’ve been playing with the bootloader process on the pioneer board. This morning made the advance that I got edk2 to boot as part of the bootflow. I am not to the point of launching grub, although I will try that soon.

Steps to reproduce:

  1. Clone the bootloader repository

git clone GitHub - sophgo/bootloader-riscv

  1. Use the default environment setup supplied by sophgo

cd bootloader-riscv/scripts
. ./envsetup.sh
export CHIP=mango

We set the chip to be the mango chip. i.e. the sg2042

  1. The debian cross compiler for riscv does not contain support for some of the CPU features (at least in bookworm aarch64), so build the compiler. This takes ages, so I would recommend adding some parallelism by editing the envsetup.sh script at the build_rv_gcc function.

build_rv_gcc

  1. With the compiler built we can start by building the components, firstly zsbl or the zerostage bootloader.

cd $RV_TOP_DIR
git clone https://github.com/sophgo/zsbl.git

I could not get the conf.ini settings to affect dynamically so for this test I have overridden the values in the defaults for the sd card.

Apply the following diff:

diff --git a/plat/sg2042/boot.c b/plat/sg2042/boot.c
index 638f501..8ffb654 100644
--- a/plat/sg2042/boot.c
+++ b/plat/sg2042/boot.c
@@ -140,9 +140,9 @@ BOOT_FILE boot_file[ID_MAX] = {
 static char *img_name_sd[] = {
        "0:riscv64/conf.ini",
        "0:riscv64/fw_dynamic.bin",
-       "0:riscv64/riscv64_Image",
-       "0:riscv64/initrd.img",
-       "0:riscv64/mango.dtb",
+       "0:riscv64/SG2042.fd",
+       NULL,
+       "0:riscv64/mango-milkv-pioneer.dtb",
 };

 static char *img_name_spi[] = {

Finally we build the zsbl.bin file.

build_rv_zsbl

  1. Get the OpenSBI

cd $RV_TOP_DIR
git clone GitHub - sophgo/opensbi: RISC-V Open Source Supervisor Binary Interface

Build the sbi image with

build_rv_sbi

  1. Get the edk repo and build.

cd $RV_TOP_DIR
git clone GitHub - sophgo/sophgo-edk2

Build it with:

build_rv_edk2

  1. Assemble the files into a SD card. I used any rando raspberrypi sd card, because we only need to have a fat filesystem in partition 1.

a. Based on that root (/) copy the file from $RV_TOP_DIR/bootloader-riscv/firmware/fip.bin to the root of that partition.
b. Copy the zsbl in that same folder by $RV_TOP_DIR/install/soc_mango/single_chip/firmware/zsbl.bin
c. make a directory called riscv64
d. copy the EFI to the riscv64 directory from $RV_TOP_DIR/sophgo-edk2/Build/SG2042_EVB/RELEASE_GCC5/FV/SG2042.fd
e. copy the dtbs into the riscv64 directory from the fedora image, or you can make the linux kernel using the build env.

Anyway hopefully if you got this far then you can just place the SD card into the slot and boot the pioneer board and be greeted with a console log similar to the one below.

Enjoy, Arielle :slight_smile:

Console trace:


SOPHGO ZSBL
sg2042:v0.3

sg2042 work in single socket mode
chip0 ddr info: raw data=0x29290606,
    ddr0 size:0x400000000
    ddr1 size:0x400000000
    ddr2 size:0x0
    ddr3 size:0x0
SD initializing 100000000Hz (transfer frequency at 25000000Hz)
sd card init ok
0:riscv64/conf.ini file size is 143
read config from sd
rv boot from sd card
SD initializing 100000000Hz (transfer frequency at 25000000Hz)
sd card init ok
0:riscv64/fw_dynamic.bin file size is 270032
0:riscv64/SG2042.fd file size is 7995392
0:riscv64/mango-milkv-pioneer.dtb file size is 45099
sd read file ok
chip0 ddr node in dtb:
    base:0x0000000000, len:0xc0000000
    base:0x0100000000, len:0x300000000
    base:0x0400000000, len:0x400000000
use default mac address
main core sbi jump to 0x0, dynamic info:40019860

OpenSBI v1.2-117-g3745939
Build time: 2024-02-05 21:57:32 +0100
Build compiler: gcc version 13.2.0 (gc891d8dc23e)
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|___/_____|
        | |
        |_|

Platform Name             : Sophgo Mango
Platform Features         : medeleg
Platform HART Count       : 64
Platform IPI Device       : aclint-mswi
Platform Timer Device     : aclint-mtimer @ 50000000Hz
Platform Console Device   : uart8250
Platform HSM Device       : ---
Platform PMU Device       :
Platform Reboot Device    : mango-reset
Platform Shutdown Device  : mango-reset
Platform Suspend Device   : ---
Firmware Base             : 0x0
Firmware Size             : 1376 KB
Firmware RW Offset        : 0x40000
Runtime SBI Version       : 1.0

Domain0 Name              : root
Domain0 Boot HART         : 7
Domain0 HARTs             : 0*,1*,2*,3*,4*,5*,6*,7*,8*,9*,10*,11*,12*,13*,14*,15*,16*,17*,18*,19*,20*,21*,22*,23*,24*,25*,26*,27*,28*,29*,30*,31*,32*,33*,34*,35*,36*,37*,38*,39*,40*,41*,42*,43*,44*,45*,46*,47*,48*,49*,50*,51*,52*,53*,54*,55*,56*,57*,58*,59*,60*,61*,62*,63*
Domain0 Region00          : 0x0000007094000000-0x0000007094003fff M: (I,R,W) S/U: ()
Domain0 Region01          : 0x0000000000000000-0x000000000003ffff M: (R,X) S/U: ()
Domain0 Region02          : 0x0000000000000000-0x00000000001fffff M: (R,W) S/U: ()
Domain0 Region03          : 0x00000070ac000000-0x00000070ac3fffff M: (I,R,W) S/U: ()
Domain0 Region04          : 0x0000000000000000-0xffffffffffffffff M: (R,W,X) S/U: (R,W,X)
Domain0 Next Address      : 0x0000000002000000
Domain0 Next Arg1         : 0x000000004009fd90
Domain0 Next Mode         : S-mode
Domain0 SysReset          : yes
Domain0 SysSuspend        : yes

Boot HART ID              : 7
Boot HART Domain          : root
Boot HART Priv Version    : v1.11
Boot HART Base ISA        : rv64imafdcvx
Boot HART ISA Extensions  : time
Boot HART PMP Count       : 8
Boot HART PMP Granularity : 2048
Boot HART PMP Address Bits: 38
Boot HART MHPM Count      : 29
Boot HART MIDELEG         : 0x0000000000020222
Boot HART MEDELEG         : 0x000000000000b109
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03040002 I0
PROGRESS CODE: V03040003 I0
PROGRESS CODE: V03041001 I0
PROGRESS CODE: V03051005 I0
PROGRESS CODE: V02010000 I0
PROGRESS CODE: V02011000 I0
PROGRESS CODE: V02011000 I0
PROGRESS CODE: V02011000 I0
PROGRESS CODE: V02011000 I0
PROGRESS CODE: V02011001 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010000 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0


































PROGRESS CODE: V01040001 I0
PROGRESS CODE: V02020000 I0
PROGRESS CODE: V02020004 I0
PROGRESS CODE: V02020003 I0
PROGRESS CODE: V02020006 I0
PROGRESS CODE: V02020006 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02020000 I0
PROGRESS CODE: V02020004 I0
PROGRESS CODE: V02020003 I0
PROGRESS CODE: V02020006 I0
PROGRESS CODE: V02020006 I0
PROGRESS CODE: V02020006 I0
PROGRESS CODE: V02020006 I0
PROGRESS CODE: V01010004 I0
PROGRESS CODE: V01010003 I0
PROGRESS CODE: V01010006 I0
PROGRESS CODE: V01010001 I0
PROGRESS CODE: V01011001 I0
PROGRESS CODE: V02020006 I0
PROGRESS CODE: V02020000 I0
PROGRESS CODE: V02020000 I0
PROGRESS CODE: V02010000 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010000 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010000 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010000 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0
PROGRESS CODE: V02010004 I0


































UEFI Interactive Shell v2.2
EDK II
UEFI v2.70 (EDK II, 0x00010000)
Mapping table
      FS0: Alias(s):HD1b:;BLK3:
          VenHw(11322596-DD4F-47FA-9E6C-CE787E11E4B1)/HD(1,MBR,0x3E247B30,0x2000
,0x80000)
     BLK2: Alias(s):
          VenHw(11322596-DD4F-47FA-9E6C-CE787E11E4B1)
     BLK0: Alias(s):
          PcieRoot(0x3)/Pci(0x0,0x0)/Pci(0x0,0x0)/Pci(0x8,0x0)/Pci(0x0,0x0)/NVMe
(0x1,16-DA-BF-71-BA-38-25-00)
     BLK1: Alias(s):
          PcieRoot(0x3)/Pci(0x0,0x0)/Pci(0x0,0x0)/Pci(0x8,0x0)/Pci(0x0,0x0)/NVMe
(0x1,16-DA-BF-71-BA-38-25-00)/HD(1,GPT,AB72C99F-813D-3543-8E96-6AD2310D65C8,0x80
0,0x1DCF2800)
     BLK4: Alias(s):
          VenHw(11322596-DD4F-47FA-9E6C-CE787E11E4B1)/HD(2,MBR,0x3E247B30,0x8200
0,0x7B6000)
Press ESC in 1 seconds to skip startup.nsh or any other key to continue.
Shell> ls fs0:
Directory of: fs0:\
04/05/2023  11:32              30,390  bcm2710-rpi-2-b.dtb
04/05/2023  11:32              32,753  bcm2710-rpi-3-b-plus.dtb
04/05/2023  11:32              32,142  bcm2710-rpi-3-b.dtb
04/05/2023  11:32              30,285  bcm2710-rpi-cm3.dtb
04/05/2023  11:32              31,318  bcm2710-rpi-zero-2-w.dtb
04/05/2023  11:32              31,318  bcm2710-rpi-zero-2.dtb
04/05/2023  11:32              52,593  bcm2711-rpi-4-b.dtb
04/05/2023  11:32              52,682  bcm2711-rpi-400.dtb
04/05/2023  11:32              38,182  bcm2711-rpi-cm4-io.dtb
04/05/2023  11:32              53,202  bcm2711-rpi-cm4.dtb
04/05/2023  11:32              50,504  bcm2711-rpi-cm4s.dtb
04/05/2023  11:32              52,476  bootcode.bin
05/03/2023  03:23                 193  cmdline.txt
05/03/2023  02:53               2,109  config.txt
04/05/2023  11:32              18,693  COPYING.linux
01/18/2024  14:52             285,706  fip.bin
04/05/2023  11:32               7,266  fixup.dat
04/05/2023  11:32               5,399  fixup4.dat
04/05/2023  11:32               3,173  fixup4cd.dat
04/05/2023  11:32               8,381  fixup4db.dat
04/05/2023  11:32               8,387  fixup4x.dat
04/05/2023  11:32               3,173  fixup_cd.dat
04/05/2023  11:32              10,230  fixup_db.dat
04/05/2023  11:32              10,228  fixup_x.dat
05/03/2023  03:23                 145  issue.txt
04/05/2023  11:32           8,219,600  kernel8.img
04/05/2023  11:32               1,594  LICENCE.broadcom
05/03/2023  02:53 <DIR>        24,576  overlays
02/06/2024  18:57 <DIR>         2,048  riscv64
04/05/2023  11:32           2,975,680  start.elf
04/05/2023  11:32           2,251,392  start4.elf
04/05/2023  11:32             805,756  start4cd.elf
04/05/2023  11:32           3,747,688  start4db.elf
04/05/2023  11:32           2,998,888  start4x.elf
04/05/2023  11:32             805,756  start_cd.elf
04/05/2023  11:32           4,819,624  start_db.elf
04/05/2023  11:32           3,722,504  start_x.elf
02/05/2024  22:02           1,002,088  u-boot.bin
02/07/2024  10:03             657,208  zsbl.bin
         37 File(s)  32,858,706 bytes
          2 Dir(s)
Shell>
6 Likes

Following up myself, which I know is bad form (sorry). I have successfully got my debian install booting using the following flow:

zsbl → opensbi → uefi/edk2 → grub → linux

Also update-grub2 in debian is able to manage the boot profiles in grub, as it would in any other platform.

There are still many sharp edges, but I will make a blog post and link it here once I have written it up.

So far seems pretty reliable.

Thanks

Arielle

4 Likes

Just wanted to say thanks for sharing this info. Looking forward to the blog post and any other details you can share about what you’ve discovered about the boot flow process.

1 Like