Skip to content

Commit 3c11bf3

Browse files
dgarskedanielinux
authored andcommitted
Peer review fixes
1 parent 5d71feb commit 3c11bf3

8 files changed

Lines changed: 29 additions & 14 deletions

File tree

config/examples/polarfire_mpfs250_m_qspi.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ OPTIMIZATION_LEVEL=1
5959
RISCV_MMODE?=1
6060

6161
# Stack size per hart: set to 0 for M-mode (only E51/hart 0 runs;
62-
# secondary harts park in eNVM WFI loop and never use L2 Scratch stacks)
62+
# secondary harts park in eNVM WFI loop and never use L2 Scratch stacks).
63+
# The linker script (mpfs250-m.ld) uses STACK_SIZE_PER_HART = 0 to match.
6364
CFLAGS_EXTRA+=-DSTACK_SIZE_PER_HART=0
6465

6566
# E51 core lacks RISC-V crypto extensions (Zknh), use portable C implementations

docs/Targets.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,12 @@ These flags apply to `polarfire_mpfs250_m_qspi.config` and are added via `CFLAGS
839839

840840
#### Stack overflow detection
841841

842-
The trap handler in `src/boot_riscv.c` automatically detects stack overflow on synchronous exceptions. When a trap fires with `SP < _main_hart_stack_bottom`, it prints:
842+
The trap handler in `src/boot_riscv.c` automatically detects stack overflow on synchronous exceptions (requires `DEBUG_BOOT`). When a trap fires with `SP < _main_hart_stack_bottom`, it prints:
843843

844844
```
845-
TRAP: cause=2 epc=A000740 tval=0 sp=A02FFE8
846-
STACK OVERFLOW: sp=A02FFE8 < bottom=A030000 (under by 24)
845+
TRAP: cause=2 epc=A000740 tval=0
846+
sp=A02FFE8
847+
STACK OVERFLOW: under by 24
847848
```
848849

849850
This is helpful for diagnosing illegal-instruction TRAPs at random valid `.text` addresses, which are the classic signature of stack overflow corrupting the return address.

hal/mpfs250-m.ld

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ PROVIDE(_start_heap = _end);
119119
*
120120
* Total stack area: STACK_SIZE + 4 * STACK_SIZE_PER_HART
121121
*/
122-
PROVIDE(STACK_SIZE_PER_HART = 8192);
122+
/* M-mode: only E51 (hart 0) runs; secondary harts park in eNVM WFI loop.
123+
* Set to 0 so no L2 Scratch is wasted on phantom secondary stacks. */
124+
PROVIDE(STACK_SIZE_PER_HART = 0);
123125

124126
/* End of L2 scratchpad */
125127
PROVIDE(_l2_scratch_end = ORIGIN(L2_SCRATCH) + LENGTH(L2_SCRATCH));

hal/mpfs250.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ extern uint8_t _main_hart_hls; /* linker-provided address symbol; typed as uint8
122122
# define WATCHDOG_TIMEOUT_TICKS ((WATCHDOG_TIMEOUT_MS) * 300U)
123123
#endif
124124

125-
/* Saved boot ROM watchdog value, restored in hal_prepare_boot() */
125+
/* Saved boot ROM watchdog values, restored in hal_prepare_boot() */
126126
static uint32_t mpfs_wdt_default_mvrp = 0;
127+
static uint32_t mpfs_wdt_default_ctrl = 0;
127128

128129

129130
/* CLINT MSIP register for IPI delivery */
@@ -178,8 +179,9 @@ static void qspi_uart_program(void);
178179
void hal_init(void)
179180
{
180181
#ifdef WOLFBOOT_RISCV_MMODE
181-
/* Capture boot ROM WDT default for restoration in hal_prepare_boot() */
182+
/* Capture boot ROM WDT defaults for restoration in hal_prepare_boot() */
182183
mpfs_wdt_default_mvrp = MSS_WDT_MVRP(MSS_WDT_E51_BASE);
184+
mpfs_wdt_default_ctrl = MSS_WDT_CONTROL(MSS_WDT_E51_BASE);
183185

184186
#ifndef WATCHDOG
185187
/* WATCHDOG=0 (default): disable WDT for the duration of wolfBoot.
@@ -191,6 +193,7 @@ void hal_init(void)
191193
* never have to pet the WDT during ECDSA verify. */
192194
MSS_WDT_REFRESH(MSS_WDT_E51_BASE) = 0xDEADC0DEU;
193195
MSS_WDT_MVRP(MSS_WDT_E51_BASE) = WATCHDOG_TIMEOUT_TICKS;
196+
MSS_WDT_CONTROL(MSS_WDT_E51_BASE) |= MSS_WDT_CTRL_ENABLE;
194197
#endif
195198

196199
mpfs_config_l2_cache();
@@ -407,12 +410,13 @@ int hal_dts_fixup(void* dts_addr)
407410
void hal_prepare_boot(void)
408411
{
409412
#ifdef WOLFBOOT_RISCV_MMODE
410-
/* Restore boot ROM WDT default so the application sees a normal WDT.
413+
/* Restore boot ROM WDT defaults so the application sees a normal WDT.
411414
* Refresh first so the timer doesn't fire immediately after we apply
412-
* the new MVRP. Re-enable in case it was disabled by hal_init(). */
415+
* the new MVRP. Restore the original CONTROL value (including the
416+
* enable bit) rather than unconditionally enabling. */
413417
MSS_WDT_REFRESH(MSS_WDT_E51_BASE) = 0xDEADC0DEU;
414418
MSS_WDT_MVRP(MSS_WDT_E51_BASE) = mpfs_wdt_default_mvrp;
415-
MSS_WDT_CONTROL(MSS_WDT_E51_BASE) |= MSS_WDT_CTRL_ENABLE;
419+
MSS_WDT_CONTROL(MSS_WDT_E51_BASE) = mpfs_wdt_default_ctrl;
416420
#endif
417421
/* reset the eMMC/SD card? */
418422
}
@@ -1339,7 +1343,7 @@ static void uart_init_base(unsigned long base)
13391343
MMUART_IER(base) = 0u;
13401344
MMUART_FCR(base) = CLEAR_RX_FIFO_MASK | CLEAR_TX_FIFO_MASK | RXRDY_TXRDYN_EN_MASK;
13411345
MMUART_MCR(base) &= ~(LOOP_MASK | RLOOP_MASK);
1342-
MMUART_MCR(base) |= (1U << 1); /* Assert RTS — required for USB-UART bridge CTS */
1346+
MMUART_MCR(base) |= RTS_MASK; /* Assert RTS — required for USB-UART bridge CTS */
13431347
MMUART_MM1(base) &= ~(E_MSB_TX_MASK | E_MSB_RX_MASK);
13441348
MMUART_MM2(base) &= ~(EAFM_MASK | ESWM_MASK);
13451349
MMUART_MM0(base) &= ~(ETTG_MASK | ERTO_MASK | EFBR_MASK);

hal/mpfs250.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ extern const unsigned long MSS_UART_BASE_ADDR[5];
168168
#define CLEAR_RX_FIFO_MASK (1U << 1) /* Clear receiver FIFO */
169169
#define CLEAR_TX_FIFO_MASK (1U << 2) /* Clear transmitter FIFO */
170170

171+
#define RTS_MASK (1U << 1) /* Request To Send */
171172
#define LOOP_MASK (1U << 4) /* Local loopback */
172173
#define RLOOP_MASK (1U << 5) /* Remote loopback & Automatic echo*/
173174

hal/sama5d3.ld

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ SECTIONS
3838
}
3939

4040
/* collect all uninitialized .bss sections */
41-
.bss (NOLOAD) : {
41+
.bss (NOLOAD) : {
4242
. = ALIGN(4);
4343
_start_bss = .;
4444
*(.bss)
4545
_end_bss = .;
46+
_end = .;
4647
}
4748
}
4849

src/boot_riscv_start.S

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ _copy_params:
274274
j .L_bss_clear
275275
.L_bss_clear_done:
276276

277-
278277
#ifndef TARGET_mpfs250
279278
/* Clear SiFive bus error unit accrued registers (not present on MPFS) */
280279
la a4,0x01700020UL

tools/scripts/mpfs_qspi_prog.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ def wait_for(port, keyword, timeout_sec, label=""):
5757
while time.monotonic() < deadline:
5858
remaining = deadline - time.monotonic()
5959
port.timeout = min(1.0, remaining)
60-
line = port.readline()
60+
try:
61+
line = port.readline()
62+
except serial.SerialException:
63+
# JTAG reset can cause a brief USB-UART glitch on PTY proxies.
64+
# Tolerate the transient disconnect and keep trying.
65+
time.sleep(0.5)
66+
continue
6167
if not line:
6268
continue
6369
text = line.decode("ascii", errors="replace").rstrip()

0 commit comments

Comments
 (0)