Skip to content

Commit 77ebc8a

Browse files
committed
Refactor disk.c for generic use. Wired up uSD read for MBR/GPT
1 parent 2e8cd5f commit 77ebc8a

File tree

11 files changed

+347
-145
lines changed

11 files changed

+347
-145
lines changed

.github/workflows/test-build-riscv.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,21 @@ jobs:
8181
run: sudo apt-get update -o Acquire::Retries=3
8282

8383
- name: Download and install RISC-V toolchains
84+
if: ${{ inputs.arch == 'riscv' }}
8485
run: |
86+
# Download SiFive prebuilt toolchain with newlib
87+
wget -q https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz
88+
tar xzf riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz
89+
echo "$GITHUB_WORKSPACE/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin" >> $GITHUB_PATH
90+
8591
# Download latest prebuilt RISC-V toolchains
8692
#wget -q https://github.com/RISCV-Tools/riscv-gnu-toolchain/releases/latest/download/riscv32-elf-ubuntu-24.04-gcc.tar.xz
8793
#tar -xf riscv32-elf-ubuntu-24.04-gcc.tar.xz
8894
#echo "$GITHUB_WORKSPACE/riscv/bin" >> $GITHUB_PATH
8995
96+
- name: Download and install RISC-V toolchains
97+
if: ${{ inputs.arch == 'riscv64' }}
98+
run: |
9099
wget -q https://github.com/RISCV-Tools/riscv-gnu-toolchain/releases/latest/download/riscv64-elf-ubuntu-24.04-gcc.tar.xz
91100
tar -xf riscv64-elf-ubuntu-24.04-gcc.tar.xz
92101
echo "$GITHUB_WORKSPACE/riscv/bin" >> $GITHUB_PATH
@@ -106,7 +115,7 @@ jobs:
106115
- name: Build wolfboot (riscv32)
107116
if: ${{ inputs.arch == 'riscv' }}
108117
run: |
109-
# using riscv64 for now since riscv64-unknown-elf- is missing "zicsr" extension
118+
# using riscv64 for now since riscv32-unknown-elf- is missing "zicsr" extension
110119
make CROSS_COMPILE=riscv64-unknown-elf- FREEDOM_E_SDK=$GITHUB_WORKSPACE/freedom-e-sdk ${{inputs.make-args}}
111120
112121
- name: Build wolfboot (riscv64))

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ line-count-nrf52:
528528
cloc --force-lang-def cloc_lang_def.txt src/boot_arm.c src/image.c src/libwolfboot.c src/loader.c src/update_flash.c hal/nrf52.c
529529

530530
line-count-x86:
531-
cloc --force-lang-def cloc_lang_def.txt src/boot_x86_fsp.c src/boot_x86_fsp_payload.c src/boot_x86_fsp_start.S src/image.c src/keystore.c src/libwolfboot.c src/loader.c src/string.c src/update_disk.c src/gpt.c src/x86/ahci.c src/x86/ata.c src/x86/common.c src/x86/disk.c src/x86/hob.c src/pci.c src/x86/tgl_fsp.c hal/x86_fsp_tgl.c hal/x86_uart.c
531+
cloc --force-lang-def cloc_lang_def.txt src/boot_x86_fsp.c src/boot_x86_fsp_payload.c src/boot_x86_fsp_start.S src/image.c src/keystore.c src/libwolfboot.c src/loader.c src/string.c src/update_disk.c src/gpt.c src/x86/ahci.c src/x86/ata.c src/x86/common.c src/disk.c src/x86/hob.c src/pci.c src/x86/tgl_fsp.c hal/x86_fsp_tgl.c hal/x86_uart.c
532532

533533
stack-usage: wolfboot.bin
534534
$(Q)echo $(STACK_USAGE) > .stack_usage

arch.mk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,10 @@ endif
563563
ifeq ($(ARCH),RISCV64)
564564
CROSS_COMPILE?=riscv64-unknown-elf-
565565
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
566-
CFLAGS+=-DWOLFBOOT_UPDATE_DISK
566+
CFLAGS+=-DWOLFBOOT_UPDATE_DISK -DMAX_DISKS=1
567567
UPDATE_OBJS:=src/update_disk.o
568568
OBJS += src/gpt.o
569+
OBJS += src/disk.o
569570
ARCH_FLAGS=-march=rv64imafd -mabi=lp64d -mcmodel=medany
570571
CFLAGS+=-fno-builtin-printf -DUSE_M_TIME -g -nostartfiles -DARCH_RISCV64
571572
CFLAGS+=$(ARCH_FLAGS)
@@ -1117,7 +1118,7 @@ ifeq ("${FSP}", "1")
11171118
OBJS += src/x86/ahci.o
11181119
OBJS += src/x86/ata.o
11191120
OBJS += src/gpt.o
1120-
OBJS += src/x86/disk.o
1121+
OBJS += src/disk.o
11211122
OBJS += src/x86/mptable.o
11221123
OBJS += src/stage2_params.o
11231124
OBJS += src/x86/exceptions.o

docs/Targets.md

Lines changed: 107 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,10 @@ All build settings come from .config file. For this platform use `TARGET=mpfs250
799799
See example configuration at `config/examples/polarfire_mpfs250.config`.
800800

801801
```sh
802+
# Setup .config (build settings)
802803
cp config/examples/polarfire_mpfs250.config .config
804+
805+
# build boot loader
803806
make wolfboot.elf
804807
```
805808

@@ -822,13 +825,48 @@ hss-payload-generator -vvv -c ./hal/mpfs.yaml wolfboot.bin
822825

823826
Any customizations to the Device Tree can be made in mpfs.dts and it can be recompiled using: `dtc -I dts -O dtb mpfs.dts -o mpfs.dtb`
824827

825-
826828
Example one-shot command:
827829

828830
```sh
829831
cp ./config/examples/polarfire_mpfs250.config .config && make clean && make wolfboot.elf && size wolfboot.elf && hss-payload-generator -vvv -c ./hal/mpfs.yaml wolfboot.bin && file wolfboot.bin && ls -la wolfboot.bin
830832
```
831833

834+
#### Build PolarFire test-application, sign it and apply to uSD
835+
836+
```sh
837+
# make test-app
838+
make test-app/image.elf
839+
840+
# assemble GPT image
841+
dd if=/dev/zero of=app.bin bs=1M count=64
842+
/sbin/fdisk app.bin <<EOF
843+
g
844+
n
845+
1
846+
847+
+16M
848+
n
849+
850+
851+
+16M
852+
x
853+
n
854+
1
855+
OFP_A
856+
n
857+
2
858+
OFP_B
859+
r
860+
w
861+
EOF
862+
863+
cp test-app/image.elf image.bin
864+
tools/keytools/sign $SIGN $HASH image.bin wolfboot_signing_private_key.der 1
865+
tools/keytools/sign $SIGN $HASH image.bin wolfboot_signing_private_key.der 2
866+
dd if=image_v1_signed.bin of=app.bin bs=512 seek=2048 conv=notrunc
867+
dd if=image_v2_signed.bin of=app.bin bs=512 seek=34816 conv=notrunc
868+
```
869+
832870
### Flashing PolarFire SoC
833871

834872

@@ -879,10 +917,9 @@ set architecture riscv:rv64
879917
### PolarFire Example Boot Output
880918

881919
```
882-
wolfBoot Version: 2.7.0 (Dec 17 2025 11:59:22)
883-
disk_open: drv = 0
920+
wolfBoot Version: 2.7.0 (Dec 17 2025 17:03:55)
884921
mmc_set_timeout: timeout_val 500000 (12)
885-
mmc_set_clock: clock_khz: 400, freq_khz: 400
922+
mmc_set_clock: requested khz: 400, actual khz: 400
886923
mmc_send_cmd: cmd_index: 0, cmd_arg: 00000000, resp_type: 0
887924
mmc_send_cmd: cmd_index: 8, cmd_arg: 00000100, resp_type: 9
888925
mmc_init: xpc:0, si8r:1, max_ma (3.3v:128 1.8v:128)
@@ -908,17 +945,79 @@ mmc_send_cmd: cmd_index: 6, cmd_arg: 00000002, resp_type: 1
908945
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
909946
mmc_send_cmd: cmd_index: 16, cmd_arg: 00000008, resp_type: 1
910947
mmc_send_cmd: cmd_index: 55, cmd_arg: AAAA0000, resp_type: 1
911-
mmc_block_read: cmd_index: 51, block_addr: 00000000, dst 0x801FFCE0, sz: 8
948+
mmc_read: cmd_index: 51, block_addr: 00000000, dst 0x801FFCD0, sz: 8
949+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
950+
mmc_read: status: 0
951+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
952+
mmc_read: cmd_index: 6, block_addr: 00000001, dst 0x801FFC38, sz: 64
953+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
954+
mmc_read: status: 0
955+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
956+
mmc_read: cmd_index: 6, block_addr: 80000001, dst 0x801FFC38, sz: 64
957+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
958+
mmc_read: status: 0
959+
mmc_set_clock: requested khz: 50000, actual khz: 50000
960+
Reading MBR...
961+
disk_read: drv:0, start:0, count:512, dst:0x801FF918
962+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
963+
mmc_read: cmd_index: 17, block_addr: 00000000, dst 0x801FF918, sz: 512
912964
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
965+
mmc_read: status: 0
966+
Found GPT PTE at sector 1
967+
Found valid boot signature in MBR
968+
disk_read: drv:0, start:512, count:512, dst:0x801FF918
969+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
970+
mmc_read: cmd_index: 17, block_addr: 00000001, dst 0x801FF918, sz: 512
971+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
972+
mmc_read: status: 0
973+
Valid GPT partition table
974+
Current LBA: 0x1
975+
Backup LBA: 0x3B723FF
976+
Max number of partitions: 128
977+
Software limited: only allowing up to 16 partitions per disk.
978+
Disk size: 1850178048
979+
disk_read: drv:0, start:1024, count:128, dst:0x801FF818
980+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
981+
mmc_read: cmd_index: 17, block_addr: 00000002, dst 0x801FF588, sz: 512
913982
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
914-
mmc_block_read: cmd_index: 6, block_addr: 00000001, dst 0x801FFC48, sz: 64
983+
mmc_read: status: 0
984+
disk0.p0 (0_3FFFE00h@ 0_400000)
985+
disk_read: drv:0, start:1152, count:128, dst:0x801FF818
915986
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
987+
mmc_read: cmd_index: 17, block_addr: 00000002, dst 0x801FF588, sz: 512
916988
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
917-
mmc_block_read: cmd_index: 6, block_addr: 80000001, dst 0x801FFC48, sz: 64
989+
mmc_read: status: 0
990+
disk0.p1 (0_3FFFE00h@ 0_400000)
991+
disk_read: drv:0, start:1280, count:128, dst:0x801FF818
918992
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
919-
mmc_set_clock: clock_khz: 50000, freq_khz: 50000
993+
mmc_read: cmd_index: 17, block_addr: 00000002, dst 0x801FF588, sz: 512
994+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
995+
mmc_read: status: 0
996+
disk0.p2 (0_3FFFE00h@ 0_400000)
997+
disk_read: drv:0, start:1408, count:128, dst:0x801FF818
998+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
999+
mmc_read: cmd_index: 17, block_addr: 00000002, dst 0x801FF588, sz: 512
1000+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1001+
mmc_read: status: 0
1002+
disk0.p3 (0_3FFFE00h@ 0_400000)
1003+
disk_read: drv:0, start:1536, count:128, dst:0x801FF818
1004+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1005+
mmc_read: cmd_index: 17, block_addr: 00000003, dst 0x801FF588, sz: 512
1006+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1007+
mmc_read: status: 0
1008+
Total partitions on disk0: 4
9201009
Checking primary OS image in 0,1...
1010+
disk_read: drv:0, start:4194304, count:512, dst:0x801FFDA0
1011+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1012+
mmc_read: cmd_index: 17, block_addr: 00002000, dst 0x801FFDA0, sz: 512
1013+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1014+
mmc_read: status: 0
9211015
Checking secondary OS image in 0,2...
1016+
disk_read: drv:0, start:4194304, count:512, dst:0x801FFDA0
1017+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1018+
mmc_read: cmd_index: 17, block_addr: 00002000, dst 0x801FFDA0, sz: 512
1019+
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1020+
mmc_read: status: 0
9221021
No valid OS image found in either partition 1 or 2
9231022
wolfBoot: PANIC!
9241023
```

0 commit comments

Comments
 (0)