Skip to content

Commit c11f292

Browse files
committed
Peer review fixes and attempts to resolve CI compiler
1 parent e154972 commit c11f292

6 files changed

Lines changed: 41 additions & 27 deletions

File tree

arch.mk

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -563,11 +563,13 @@ endif
563563
## RISCV (32-bit)
564564
ifeq ($(ARCH),RISCV)
565565
CROSS_COMPILE?=riscv32-unknown-elf-
566-
# GCC 12+ requires explicit zicsr/zifencei extensions
567-
# Note: use $(CROSS_COMPILE)gcc directly because CC is not yet defined
568-
# at this point in the Makefile (it's set later in the USE_GCC block).
569-
RISCV32_ZICSR := $(shell echo "" | $(CROSS_COMPILE)gcc -march=rv32imac_zicsr -x c -c - -o /dev/null 2>/dev/null && echo _zicsr)
570-
RISCV32_ZIFENCEI := $(shell echo "" | $(CROSS_COMPILE)gcc -march=rv32imac_zifencei -x c -c - -o /dev/null 2>/dev/null && echo _zifencei)
566+
# GCC 12-14 split CSR/fence.i into separate extensions (zicsr, zifencei)
567+
# and require them explicitly. GCC 15+ re-implies them, and adding them
568+
# explicitly can cause multilib lookup failures. Detect by testing if a
569+
# CSR/fence.i instruction assembles WITHOUT the extension flag. If it
570+
# fails, add the extension.
571+
RISCV32_ZICSR := $(shell echo "void f(void){__asm__ volatile(\"csrr a0,mhartid\");}" | $(CROSS_COMPILE)gcc -march=rv32imac -mabi=ilp32 -x c -c - -o /dev/null 2>/dev/null || echo _zicsr)
572+
RISCV32_ZIFENCEI := $(shell echo "void f(void){__asm__ volatile(\"fence.i\");}" | $(CROSS_COMPILE)gcc -march=rv32imac -mabi=ilp32 -x c -c - -o /dev/null 2>/dev/null || echo _zifencei)
571573
ARCH_FLAGS=-march=rv32imac$(RISCV32_ZICSR)$(RISCV32_ZIFENCEI) -mabi=ilp32 -mcmodel=medany
572574
CFLAGS+=-fno-builtin-printf -DUSE_M_TIME -g -nostartfiles -DARCH_RISCV
573575
CFLAGS+=$(ARCH_FLAGS)
@@ -610,12 +612,13 @@ ifeq ($(ARCH),RISCV64)
610612
UPDATE_OBJS?=src/update_ram.o
611613
endif
612614

613-
# GCC 12+ / binutils 2.38+ split CSR and fence.i instructions into
614-
# separate extensions (zicsr, zifencei). Detect and add if supported.
615-
# Note: use $(CROSS_COMPILE)gcc directly because CC is not yet defined
616-
# at this point in the Makefile (it's set later in the USE_GCC block).
617-
RISCV64_ZICSR := $(shell echo "" | $(CROSS_COMPILE)gcc -march=rv64imac_zicsr -x c -c - -o /dev/null 2>/dev/null && echo _zicsr)
618-
RISCV64_ZIFENCEI := $(shell echo "" | $(CROSS_COMPILE)gcc -march=rv64imac_zifencei -x c -c - -o /dev/null 2>/dev/null && echo _zifencei)
615+
# GCC 12-14 split CSR/fence.i into separate extensions (zicsr, zifencei)
616+
# and require them explicitly. GCC 15+ re-implies them, and adding them
617+
# explicitly can cause multilib lookup failures. Detect by testing if a
618+
# CSR/fence.i instruction assembles WITHOUT the extension flag. If it
619+
# fails, add the extension.
620+
RISCV64_ZICSR := $(shell echo "void f(void){__asm__ volatile(\"csrr a0,mhartid\");}" | $(CROSS_COMPILE)gcc -march=rv64imac -mabi=lp64 -x c -c - -o /dev/null 2>/dev/null || echo _zicsr)
621+
RISCV64_ZIFENCEI := $(shell echo "void f(void){__asm__ volatile(\"fence.i\");}" | $(CROSS_COMPILE)gcc -march=rv64imac -mabi=lp64 -x c -c - -o /dev/null 2>/dev/null || echo _zifencei)
619622

620623
ifeq ($(RISCV_MMODE),1)
621624
# E51 core: rv64imac (no FPU, no crypto extensions)

docs/Targets.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,13 +1444,14 @@ Benchmark complete
14441444
wolfBoot supports running directly in Machine Mode (M-mode) on PolarFire SoC,
14451445
replacing the Hart Software Services (HSS) as the first-stage bootloader. In
14461446
M-mode, wolfBoot runs on the E51 monitor core and loads a signed application
1447-
from SC QSPI flash to on-chip LIM (Loosely Integrated Memory).
1447+
from SC QSPI flash to L2 Scratchpad SRAM. LIM is not used as an execute region
1448+
due to instruction-fetch limitations (see note below).
14481449
14491450
#### M-Mode Features
14501451
14511452
* Runs on E51 monitor core (hart 0) directly from eNVM
14521453
* Executes from L2 Scratchpad SRAM (256KB at 0x0A000000)
1453-
* Loads signed application from SC QSPI flash to LIM (0x08000000)
1454+
* Loads signed application from SC QSPI flash to L2 Scratchpad (0x0A010200)
14541455
* No HSS or DDR required — boots entirely from on-chip memory
14551456
* Wakes and manages secondary U54 harts via IPI
14561457
* Per-hart UART output (each hart uses its own MMUART)

hal/mpfs250.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,7 @@ static void qspi_uart_program(void)
10511051
{
10521052
uint8_t ch = 0;
10531053
uint32_t addr, size, n_sectors, written, t;
1054+
uint32_t i, s;
10541055
uint8_t chunk[QSPI_PROG_CHUNK];
10551056

10561057
wolfBoot_printf("QSPI-PROG: Press 'P' within 3s to program flash\r\n");
@@ -1080,10 +1081,10 @@ static void qspi_uart_program(void)
10801081

10811082
/* Receive destination address then data length (4 bytes LE each) */
10821083
addr = 0;
1083-
for (int i = 0; i < 4; i++)
1084+
for (i = 0; i < 4; i++)
10841085
addr |= ((uint32_t)uart_qspi_rx() << (i * 8));
10851086
size = 0;
1086-
for (int i = 0; i < 4; i++)
1087+
for (i = 0; i < 4; i++)
10871088
size |= ((uint32_t)uart_qspi_rx() << (i * 8));
10881089

10891090
wolfBoot_printf("QSPI-PROG: addr=0x%x size=%u bytes\r\n", addr, size);
@@ -1098,7 +1099,7 @@ static void qspi_uart_program(void)
10981099
wolfBoot_printf("QSPI-PROG: Erasing %u sector(s) at 0x%x...\r\n",
10991100
n_sectors, addr);
11001101
ext_flash_unlock();
1101-
for (uint32_t s = 0; s < n_sectors; s++)
1102+
for (s = 0; s < n_sectors; s++)
11021103
ext_flash_erase(addr + s * FLASH_SECTOR_SIZE, FLASH_SECTOR_SIZE);
11031104

11041105
/* "ERASED\r\n" must be the last bytes before the first ACK (0x06).
@@ -1114,7 +1115,7 @@ static void qspi_uart_program(void)
11141115

11151116
uart_qspi_tx(QSPI_PROG_ACK); /* request next chunk */
11161117

1117-
for (uint32_t i = 0; i < chunk_len; i++)
1118+
for (i = 0; i < chunk_len; i++)
11181119
chunk[i] = uart_qspi_rx();
11191120

11201121
ext_flash_write(addr + written, chunk, (int)chunk_len);

src/sdhci.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,10 +1367,14 @@ int sdhci_init(void)
13671367
reg &= ~SDHCI_HRS06_EMM_MASK;
13681368
#ifdef DISK_EMMC
13691369
reg |= SDHCI_HRS06_MODE_LEGACY; /* eMMC Legacy mode */
1370+
#ifdef DEBUG_SDHCI
13701371
wolfBoot_printf("SDHCI: eMMC mode\n");
1372+
#endif
13711373
#else
13721374
reg |= SDHCI_HRS06_MODE_SD; /* SD card mode */
1375+
#ifdef DEBUG_SDHCI
13731376
wolfBoot_printf("SDHCI: SDCard mode\n");
1377+
#endif
13741378
#endif
13751379
SDHCI_REG_SET(SDHCI_HRS06, reg);
13761380

@@ -1446,15 +1450,15 @@ int sdhci_init(void)
14461450
/* Run full eMMC card initialization */
14471451
status = emmc_card_full_init();
14481452
if (status != 0) {
1449-
wolfBoot_printf("eMMC: Card initialization failed\n");
1453+
wolfBoot_printf("eMMC: Card init failed (%d)\n", status);
14501454
return status;
14511455
}
14521456

14531457
#else /* DISK_SDCARD */
14541458
/* Run full SD card initialization */
14551459
status = sdcard_card_full_init();
14561460
if (status != 0) {
1457-
wolfBoot_printf("SD Card: Card initialization failed\n");
1461+
wolfBoot_printf("SD Card: Card init failed (%d)\n", status);
14581462
return status;
14591463
}
14601464

@@ -1466,6 +1470,7 @@ int sdhci_init(void)
14661470
status = sdhci_set_timeout(SDHCI_DATA_TIMEOUT_US);
14671471
}
14681472

1473+
#ifdef DEBUG_SDHCI
14691474
{
14701475
const char *card_type;
14711476
#ifdef DISK_EMMC
@@ -1475,6 +1480,7 @@ int sdhci_init(void)
14751480
#endif
14761481
wolfBoot_printf("sdhci_init: %s status: %d\n", card_type, status);
14771482
}
1483+
#endif
14781484

14791485
return status;
14801486
}

test-app/startup_riscv.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ void __attribute__((naked,section(".init"))) _reset(void) {
4242
asm volatile("la gp, _global_pointer");
4343
asm volatile("la sp, _end_stack");
4444

45-
/* Set up M-mode vectored interrupt table.
46-
* wolfBoot M-mode does a direct jr (no enter_smode), so payload runs in M-mode.
47-
* Use mtvec. The +1 sets MODE=1 (vectored). */
45+
/* Set up vectored interrupt table. The +1 sets MODE=1 (vectored). */
46+
#ifdef WOLFBOOT_RISCV_MMODE
4847
asm volatile("csrw mtvec, %0":: "r"((uint8_t *)(&_start_vector) + 1));
48+
#else
49+
asm volatile("csrw stvec, %0":: "r"((uint8_t *)(&_start_vector) + 1));
50+
#endif
4951

5052
src = (uint32_t *) &_stored_data;
5153
dst = (uint32_t *) &_start_data;
@@ -77,8 +79,11 @@ void do_boot(const uint32_t *app_offset)
7779
static uint32_t synctrap_cause = 0;
7880
void __attribute__((naked)) isr_synctrap(void)
7981
{
80-
/* Use mcause: payload runs in M-mode (wolfBoot does M-mode direct jump) */
82+
#ifdef WOLFBOOT_RISCV_MMODE
8183
asm volatile("csrr %0, mcause" : "=r"(synctrap_cause));
84+
#else
85+
asm volatile("csrr %0, scause" : "=r"(synctrap_cause));
86+
#endif
8287
}
8388

8489
void isr_empty(void)

test-app/vector_riscv.S

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@
6262
ld x30, 112(sp)
6363
ld x31, 120(sp)
6464
addi sp, sp, 128
65-
/* mret: payload runs in M-mode (wolfBoot does M-mode direct jump) */
66-
mret
65+
MODE_PREFIX(ret)
6766
.endm
6867

6968
#else /* __riscv_xlen == 32 */
@@ -107,8 +106,7 @@
107106
lw x30, 56(sp)
108107
lw x31, 60(sp)
109108
addi sp, sp, 64
110-
/* mret: payload runs in M-mode (wolfBoot does M-mode direct jump) */
111-
mret
109+
MODE_PREFIX(ret)
112110
.endm
113111

114112
#endif /* __riscv_xlen */

0 commit comments

Comments
 (0)