Skip to content

Commit 9f4e774

Browse files
committed
Peer review fixes and another attempt to fix CI
1 parent 1014558 commit 9f4e774

9 files changed

Lines changed: 119 additions & 53 deletions

File tree

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,11 @@ jobs:
9292
echo "$GITHUB_WORKSPACE/riscv/bin" >> $GITHUB_PATH
9393
$GITHUB_WORKSPACE/riscv/bin/riscv32-unknown-elf-gcc --version
9494
95-
- name: Download and install RISC-V toolchain (riscv64)
95+
- name: Install RISC-V toolchain (riscv64)
9696
if: ${{ inputs.arch == 'riscv64' }}
9797
run: |
98-
wget -q https://github.com/riscv-collab/riscv-gnu-toolchain/releases/latest/download/riscv64-elf-ubuntu-24.04-gcc.tar.xz
99-
tar -xf riscv64-elf-ubuntu-24.04-gcc.tar.xz
100-
echo "$GITHUB_WORKSPACE/riscv/bin" >> $GITHUB_PATH
101-
$GITHUB_WORKSPACE/riscv/bin/riscv64-unknown-elf-gcc --version
98+
sudo apt-get install -y gcc-riscv64-unknown-elf binutils-riscv64-unknown-elf
99+
riscv64-unknown-elf-gcc --version
102100
103101
# ============================================================
104102
# Build wolfboot

.github/workflows/test-configs.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
with:
2020
arch: riscv
2121
config-file: ./config/examples/hifive1.config
22-
# Only building wolfBoot (test-app needs freedom-e-sdk multilib for ilp32d)
23-
make-args: wolfboot.bin
2422

2523
sama5d3_test:
2624
uses: ./.github/workflows/test-build.yml

config/examples/polarfire_mpfs250_hss_l2lim.config

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ DUALBANK_SWAP?=0
2525
PKA?=0
2626
ENCRYPT=0
2727
WOLFTPM?=0
28-
ELF?=1
29-
#DEBUG_ELF?=1
28+
ELF?=0
3029

31-
# Use RISC-V assembly version of ECDSA and SHA
32-
NO_ASM?=0
30+
# U54 cores lack RISC-V crypto extensions (Zknh); use portable C implementations
31+
NO_ASM?=1
3332

3433
# QSPI Flash Configuration
3534
# Using Micron MT25QL01GBBB (128MB, 64KB sectors)

hal/mpfs250-m.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ SECTIONS
6565
*(.text*)
6666
*(.rodata*)
6767
*(.srodata*)
68-
. = ALIGN(4);
68+
. = ALIGN(8);
6969
_end_text = .;
7070
} > L2_SCRATCH AT > FLASH_ENVM
7171

hal/mpfs250.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static __attribute__((noinline)) void udelay(uint32_t us)
103103
/* Multi-Hart Support */
104104
#ifdef WOLFBOOT_RISCV_MMODE
105105

106-
extern uint64_t _main_hart_hls;
106+
extern uint8_t _main_hart_hls; /* linker-provided address symbol; typed as uint8_t to avoid size confusion */
107107

108108
/* CLINT MSIP register for IPI delivery */
109109
#define CLINT_MSIP_REG(hart) (*(volatile uint32_t*)(CLINT_BASE + (hart) * 4))

hal/riscv.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@
4848
#define VECTOR_ALIGN 2
4949
#endif
5050

51-
/* S-mode timer frequency (1 MHz default; platform may override) */
52-
#ifndef RISCV_SMODE_TIMER_FREQ
51+
/* S-mode timer frequency (1 MHz default; platform may override).
52+
* In M-mode, hal_get_timer() returns mcycle so the platform (e.g. mpfs250.h)
53+
* sets RISCV_SMODE_TIMER_FREQ to the CPU clock; do not default it here. */
54+
#if !defined(WOLFBOOT_RISCV_MMODE) && !defined(RISCV_SMODE_TIMER_FREQ)
5355
#define RISCV_SMODE_TIMER_FREQ 1000000
5456
#endif
5557

src/boot_riscv_start.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ _reset:
5757
bnez a0, .L_secondary_hart_wait_envm
5858

5959
#ifdef TARGET_mpfs250
60-
/* Enable L2 ways (0-3 cache + 8-11 scratchpad) and clear shutdown
60+
/* Enable L2 ways (mask 0x0B: ways 0, 1, 3) and clear shutdown
6161
* before copying text to L2 scratchpad. */
6262
li t1, 0x02010000
6363
li t2, 0x0B

test-app/RISCV64-mpfs250.ld

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,23 @@ MEMORY
2626
/* Define output sections */
2727
SECTIONS
2828
{
29-
/* The startup code goes first into IRAM */
29+
/* Entry point must be first for raw binary (.bin) boot.
30+
* _reset() initializes GP, SP, BSS, then calls main().
31+
* For ELF boot the ENTRY(_reset) directive handles this,
32+
* but for .bin wolfBoot jumps to the load address directly. */
33+
.init :
34+
{
35+
. = ALIGN(8);
36+
KEEP(*(.init))
37+
. = ALIGN(8);
38+
} >IRAM
39+
40+
/* Interrupt/trap vector table */
3041
.isr_vector :
3142
{
3243
. = ALIGN(8);
33-
KEEP(*(.isr_vector)) /* Startup code */
3444
_start_vector = .;
45+
KEEP(*(.isr_vector))
3546
. = ALIGN(8);
3647
} >IRAM
3748

@@ -45,7 +56,6 @@ SECTIONS
4556
*(.rodata) /* .rodata sections (constants, strings, etc.) */
4657
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
4758

48-
KEEP (*(.init))
4959
KEEP (*(.fini))
5060

5161
. = ALIGN(8);

tools/scripts/mpfs_program.sh

Lines changed: 93 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set -e
1414
# Use uart-monitor PTY proxy paths for serial access (allows concurrent monitoring)
1515
HSS_TTY="${HSS_TTY:-/tmp/uart-monitor/pty/POLARFIRE_SOC_UART0}"
1616
WOLFBOOT_TTY="${WOLFBOOT_TTY:-/tmp/uart-monitor/pty/POLARFIRE_SOC_UART1}"
17-
BLOCK_DEV="${BLOCK_DEV:-/dev/sde}"
17+
BLOCK_DEV="${BLOCK_DEV:-/dev/sdf}"
1818
PI_HOST="${PI_HOST:-pi@Pi4}"
1919
GPIO_PIN="${GPIO_PIN:-20}"
2020
BAUD_RATE="${BAUD_RATE:-115200}"
@@ -1007,19 +1007,52 @@ build_wolfboot_l2lim() {
10071007
}
10081008

10091009
# Build and sign test-app for current config
1010+
# Signs using the same SIGN_ENV variables that the Makefile uses.
1011+
# We call the sign tool directly (not via make) to avoid triggering a
1012+
# wolfboot.elf rebuild that would lose the UART_QSPI_PROGRAM=1 override.
10101013
build_sign_testapp() {
10111014
local strip_debug="${1:-0}"
10121015

1013-
log_info "Building test-app..."
1014-
make test-app/image.elf
1016+
# Determine image format from .config: ELF or raw binary
1017+
local use_elf
1018+
use_elf=$(grep -m1 '^ELF' .config | sed 's/.*[?]*=//')
1019+
use_elf="${use_elf:-0}"
1020+
1021+
# Build test-app directly via its own Makefile to avoid the top-level
1022+
# Makefile's wolfboot.elf dependency chain (which has a FORCE target
1023+
# that could trigger a wolfboot rebuild and lose UART_QSPI_PROGRAM=1).
1024+
# wolfboot.elf and include/target.h are already built by build_wolfboot_*.
1025+
local boot_img
1026+
if [[ "$use_elf" -eq 1 ]]; then
1027+
boot_img="test-app/image.elf"
1028+
log_info "Building test-app (ELF)..."
1029+
make -C test-app WOLFBOOT_ROOT="$PWD" image.elf
1030+
else
1031+
boot_img="test-app/image.bin"
1032+
log_info "Building test-app (BIN)..."
1033+
make -C test-app WOLFBOOT_ROOT="$PWD" image.bin
1034+
fi
10151035

1016-
if [[ "$strip_debug" -eq 1 ]]; then
1036+
if [[ "$strip_debug" -eq 1 ]] && [[ "$use_elf" -eq 1 ]]; then
10171037
log_info "Stripping debug symbols (M-Mode L2 Scratch fit)..."
10181038
riscv64-unknown-elf-strip --strip-debug test-app/image.elf
10191039
fi
10201040

1021-
log_info "Signing test-app with ECC384 + SHA384..."
1022-
./tools/keytools/sign --ecc384 --sha384 test-app/image.elf \
1041+
# Read signing parameters from .config (same values the Makefile uses)
1042+
# Config lines may use = or ?= assignment
1043+
local hdr_size partition_size sector_size
1044+
hdr_size=$(grep -m1 '^IMAGE_HEADER_SIZE' .config | sed 's/.*[?]*=//')
1045+
hdr_size="${hdr_size:-512}"
1046+
partition_size=$(grep -m1 '^WOLFBOOT_PARTITION_SIZE' .config | sed 's/.*[?]*=//')
1047+
sector_size=$(grep -m1 '^WOLFBOOT_SECTOR_SIZE' .config | sed 's/.*[?]*=//')
1048+
1049+
local img_size
1050+
img_size=$(stat -c%s "$boot_img")
1051+
log_info "Signing $boot_img (${img_size} bytes, IMAGE_HEADER_SIZE=${hdr_size})..."
1052+
IMAGE_HEADER_SIZE="$hdr_size" \
1053+
WOLFBOOT_PARTITION_SIZE="$partition_size" \
1054+
WOLFBOOT_SECTOR_SIZE="$sector_size" \
1055+
./tools/keytools/sign --ecc384 --sha384 "$boot_img" \
10231056
wolfboot_signing_private_key.der 1
10241057

10251058
log_success "Test-app built and signed: test-app/image_v1_signed.bin"
@@ -1144,11 +1177,19 @@ run_qspi() {
11441177
unmount_block_device
11451178
echo ""
11461179

1147-
# Step 4: Power cycle and flash test-app via UART QSPI programmer
1148-
log_info "=== Step 4: Power cycling and flashing test-app via UART QSPI ==="
1180+
# Step 4: Flash test-app via UART QSPI programmer
1181+
# Start QSPI programmer FIRST (it waits for the prompt), then power cycle.
1182+
# wolfBoot has a 3-second window for 'P' after boot.
1183+
log_info "=== Step 4: Flashing test-app via UART QSPI ==="
1184+
flash_qspi_testapp "test-app/image_v1_signed.bin" "$QSPI_BOOT_OFFSET" "$WOLFBOOT_TTY" &
1185+
local qspi_pid=$!
1186+
sleep 1 # Let python script open serial port
11491187
power_cycle
1150-
sleep 2
1151-
flash_qspi_testapp "test-app/image_v1_signed.bin" "$QSPI_BOOT_OFFSET" "$WOLFBOOT_TTY"
1188+
log_info "Waiting for QSPI programmer to complete..."
1189+
wait $qspi_pid || {
1190+
log_error "QSPI flash failed"
1191+
exit 1
1192+
}
11521193
echo ""
11531194

11541195
# Step 5: Power cycle and capture boot output
@@ -1191,11 +1232,19 @@ run_l2lim() {
11911232
unmount_block_device
11921233
echo ""
11931234

1194-
# Step 4: Power cycle and flash test-app via UART QSPI programmer
1195-
log_info "=== Step 4: Power cycling and flashing test-app via UART QSPI ==="
1235+
# Step 4: Flash test-app via UART QSPI programmer
1236+
# Start QSPI programmer FIRST (it waits for the prompt), then power cycle.
1237+
# wolfBoot has a 3-second window for 'P' after boot.
1238+
log_info "=== Step 4: Flashing test-app via UART QSPI ==="
1239+
flash_qspi_testapp "test-app/image_v1_signed.bin" "$QSPI_BOOT_OFFSET" "$WOLFBOOT_TTY" &
1240+
local qspi_pid=$!
1241+
sleep 1 # Let python script open serial port
11961242
power_cycle
1197-
sleep 2
1198-
flash_qspi_testapp "test-app/image_v1_signed.bin" "$QSPI_BOOT_OFFSET" "$WOLFBOOT_TTY"
1243+
log_info "Waiting for QSPI programmer to complete..."
1244+
wait $qspi_pid || {
1245+
log_error "QSPI flash failed"
1246+
exit 1
1247+
}
11991248
echo ""
12001249

12011250
# Step 5: Power cycle and capture boot output
@@ -1419,55 +1468,65 @@ run_mmode() {
14191468
local output_file="${2:-mmode_output_$(date +%Y%m%d_%H%M%S).log}"
14201469

14211470
log_info "Starting M-Mode wolfBoot programming workflow..."
1422-
log_info "Mode: JTAG programming to eNVM (bootmode 1)"
1471+
log_info "Mode: JTAG programming to eNVM + UART QSPI for test-app"
14231472
echo ""
14241473

1425-
# Step 1: Build (if not skipped)
1474+
# Step 1: Build wolfBoot and test-app
14261475
if [[ "$skip_build" -eq 0 ]]; then
14271476
log_info "=== Step 1: Building wolfBoot (M-Mode) ==="
14281477
build_wolfboot_mmode
14291478
echo ""
1479+
1480+
log_info "=== Step 2: Building and signing test-app ==="
1481+
build_sign_testapp 1 # strip_debug=1 for L2 Scratch fit
1482+
echo ""
14301483
else
1431-
log_info "=== Step 1: Skipping build ==="
1484+
log_info "=== Steps 1-2: Skipping build ==="
14321485
if [[ ! -f "wolfboot.elf" ]]; then
14331486
log_error "wolfboot.elf not found. Cannot skip build."
14341487
exit 1
14351488
fi
14361489
echo ""
14371490
fi
14381491

1439-
# Step 2: Power on target (JTAG requires power)
1440-
log_info "=== Step 2: Powering on target ==="
1492+
# Step 3: Power on target (JTAG requires power)
1493+
log_info "=== Step 3: Powering on target ==="
14411494
power_on
14421495
sleep 2 # Give device time to power up
14431496
echo ""
14441497

1445-
# Step 3: Flash via JTAG
1446-
log_info "=== Step 3: Flashing via JTAG ==="
1498+
# Step 4: Flash wolfBoot via JTAG
1499+
log_info "=== Step 4: Flashing wolfBoot via JTAG ==="
14471500
flash_jtag
14481501
echo ""
14491502

1450-
# Step 4: Power cycle to boot with new firmware
1451-
log_info "=== Step 4: Power cycling to boot new firmware ==="
1503+
# Step 5: Flash test-app via UART QSPI programmer
1504+
# Start the QSPI programmer FIRST (it waits for the prompt), then power cycle.
1505+
# wolfBoot has a 3-second window for 'P' after boot.
1506+
log_info "=== Step 5: Flashing test-app via UART QSPI ==="
1507+
flash_qspi_testapp "test-app/image_v1_signed.bin" "$QSPI_BOOT_OFFSET" "$MMODE_TTY" &
1508+
local qspi_pid=$!
1509+
sleep 1 # Let python script open serial port
14521510
power_off
14531511
sleep 1
14541512
power_on
1513+
log_info "Waiting for QSPI programmer to complete..."
1514+
wait $qspi_pid || {
1515+
log_error "QSPI flash failed"
1516+
exit 1
1517+
}
14551518
echo ""
14561519

1457-
# Step 5: Capture M-Mode output (should show "wolfBoot Version: " if successful)
1458-
log_info "=== Step 5: Capturing M-Mode output ==="
1459-
log_info "Looking for 'wolfBoot Version:' in output..."
1520+
# Step 6: Power cycle and capture boot output (wolfBoot loads test-app from QSPI)
1521+
log_info "=== Step 6: Power cycling and capturing boot output ==="
1522+
power_off
1523+
sleep 1
1524+
power_on
1525+
sleep 1
14601526
capture_mmode_output "$output_file"
14611527
echo ""
14621528

1463-
# Check if wolfBoot started successfully
1464-
if grep -q "wolfBoot" "$output_file" 2>/dev/null; then
1465-
log_success "=== M-Mode workflow completed successfully! ==="
1466-
log_success "wolfBoot output detected in $output_file"
1467-
else
1468-
log_warn "=== M-Mode workflow completed ==="
1469-
log_warn "No wolfBoot output detected - check $output_file for details"
1470-
fi
1529+
check_test_result "$output_file" "M-Mode"
14711530
}
14721531

14731532
# Parse command line arguments

0 commit comments

Comments
 (0)