Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a1bb766
F-14149: compute the ARMORED witness triangular number in 64 bits
danielinux Sep 23, 2026
b6f842c
F-14138: fix the DTCV base comment (2^13, not 2*13)
danielinux Sep 24, 2026
1a8378e
F-14133: drop the dead entry_out_set guard in the ELF check
danielinux Sep 24, 2026
6296f24
F-14132: stage1 loader requires the full partition read before the jump
danielinux Sep 24, 2026
0c8a9ae
F-14131: pass a sector count, not a byte length, to FLASH_EraseSector
danielinux Sep 24, 2026
5e065c6
F-14130: guard zero-length erase in the kinetis HAL
danielinux Sep 24, 2026
d17ea7a
F-14129: derive the C0 erase page from the flash-relative offset
danielinux Sep 24, 2026
f0e2c49
F-13656: bound e_phentsize to the program-header struct size
danielinux Sep 24, 2026
6025f35
F-13655: index the flash double-word fast path from the current offset
danielinux Sep 24, 2026
1d1977c
F-13654: index the NVM word fast path from the current offset
danielinux Sep 24, 2026
65e3b40
F-12884: flush the nRF54L UART conversion buffer when full
danielinux Sep 24, 2026
519552f
F-12872: reject a repeated squashelf -r option
danielinux Sep 24, 2026
5806172
F-12871: split cross-bank flash writes at the bank boundary
danielinux Sep 24, 2026
66b2205
F-12106: report flash programming errors on STM32U3
danielinux Sep 24, 2026
7860fa6
F-12071: early-exit sector scan for sector-zero ranges
danielinux Sep 24, 2026
9e9cdbe
F-12070: validate the persisted slot position in find_object_buffer
danielinux Sep 24, 2026
a2ad3c5
F-13607: bound the whole object header in the store guards
danielinux Sep 24, 2026
d6926a7
F-11030: consume long/size_t/pointer args at full width in uart_vprintf
danielinux Sep 24, 2026
0702a61
F-11048: clamp negative '*' field widths in uart_vprintf
danielinux Sep 24, 2026
647022b
x86: derive UART stop-bit field from requested stop count (F-12885)
danielinux Sep 24, 2026
e6824ae
ramboot: require full payload size from ext_flash_read (F-13605)
danielinux Sep 24, 2026
87b89a0
ramboot: accept image versions with the high bit set (F-13606)
danielinux Sep 24, 2026
d6464f9
hifive1: mask the HFROSCCFG divider shift with the divider field (F-9…
danielinux Sep 24, 2026
83d1e25
cmake: warn on security-weakening flags like the Makefile (F-6760)
danielinux Sep 24, 2026
772f640
F-6871: bound ext_flash read/write to the SPI NOR device size
danielinux Sep 24, 2026
a5e5d37
F-6872: assert hal_bl_scratch covers the bootloader slot budget
danielinux Sep 24, 2026
6da35c8
F-9741: close fd on mmap failure in sim HAL
danielinux Sep 24, 2026
93da376
F-9742: reject cross-bank flash erase on TI Hercules
danielinux Sep 24, 2026
f219d09
F-12067: test_flash returns -1 on mismatch, 0 on success
danielinux Sep 24, 2026
c7bf895
F-12886: reject non-positive length in HiFive1 flash erase
danielinux Sep 24, 2026
3d988c7
F-12919: log FIT compression from a bounded NUL-terminated copy
danielinux Sep 24, 2026
ef122f6
F-13608: check flash read/hash results in ELF image verification
danielinux Sep 24, 2026
13448ab
F-13609: consume over-long BOOT_ORDER tokens whole in env_next_name
danielinux Sep 24, 2026
455e535
F-13611: drop the shadowed dec_block in ext_flash_decrypt_read
danielinux Sep 24, 2026
07b573e
unit-tests: gitignore the generated extract headers and test binaries
danielinux Sep 24, 2026
641c9cf
F-12871: compare against the absolute bank 2 base
danielinux Sep 24, 2026
f528cab
F-14131: pass the byte length to FLASH_EraseSector
danielinux Sep 24, 2026
c236414
F-13608: check update_hash_flash_addr in ELF hashing
danielinux Sep 24, 2026
7570738
F-6871: bound ext_flash_erase to the device size
danielinux Sep 24, 2026
839a1d2
F-13609: return the truncated length for over-long tokens
danielinux Sep 24, 2026
d07d981
F-12067: check erase/write results in test_flash
danielinux Sep 24, 2026
c74ed95
F-12886: reject non-positive length in HiFive1 flash write
danielinux Sep 24, 2026
7a87f67
F-13607: use pointer comparisons in the store size guards
danielinux Sep 24, 2026
6632776
F-12884: drop the unused variable in the nrf54l write test
danielinux Sep 24, 2026
2f73f50
F-12885: reset the LCR counter in the no-fork x86 uart tests
danielinux Sep 24, 2026
815c461
F-11023: add the STM32G0 copy of the fast-path write test
danielinux Sep 24, 2026
48c937f
F-11030: cast %p through uintptr_t in uart_vprintf
danielinux Sep 24, 2026
f5c8f61
F-13606: declare ramboot 'ret' only where the NO_XIP reads use it
danielinux Sep 24, 2026
9bc15c1
fix Fenrir review: ls1028a test_flash return contract, x86 FSP stop bits
danielinux Sep 24, 2026
17e4327
footprint: SIGN=NONE limit 5172 -> 5180
danielinux Sep 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,71 @@ fs_b.img
tools/unit-tests/aarch64_arch_host.h
tools/unit-tests/imx8qm_usdhc_extract.h
tools/unit-tests/imx8qm_flexspi_extract.h
# unit-test binaries added since the last gitignore pass
tools/unit-tests/unit-ct-compare
tools/unit-tests/unit-custom-trailer-nopart
tools/unit-tests/unit-ecc-raw-der
tools/unit-tests/unit-elf-mmu-fail
tools/unit-tests/unit-elf-phentsize
tools/unit-tests/unit-fdt-memrsv-wrap
tools/unit-tests/unit-flash-erase-kinetis
tools/unit-tests/unit-flash-m2354
tools/unit-tests/unit-fwtpm-cmd-toctou
tools/unit-tests/unit-fwtpm-rsp-overrun
tools/unit-tests/unit-hifive1-flash-write
tools/unit-tests/unit-hifive1-hfrosccfg
tools/unit-tests/unit-keygen-keystore
tools/unit-tests/unit-kontron-tgl-spi
tools/unit-tests/unit-nrf5340-flash-protect
tools/unit-tests/unit-nrf5340-uart-crlf
tools/unit-tests/unit-nrf54l-uart-write
tools/unit-tests/unit-nsc-update
tools/unit-tests/unit-p1021-erase-advance
tools/unit-tests/unit-p1021-read-badblock
tools/unit-tests/unit-pci-4gib
tools/unit-tests/unit-pkcs11-pin-zeroize
tools/unit-tests/unit-pkcs11_store-stalecache
tools/unit-tests/unit-rp2350-flash-write
tools/unit-tests/unit-samr21-erase-advance
tools/unit-tests/unit-sdhci-acmd41-timeout
tools/unit-tests/unit-secure-handoff
tools/unit-tests/unit-stm32c0-write
tools/unit-tests/unit-stm32g4-write
tools/unit-tests/unit-stm32h7-flash-write
tools/unit-tests/unit-stm32l4-write
tools/unit-tests/unit-stm32u3-flash-write
tools/unit-tests/unit-stm32wb-write
tools/unit-tests/unit-t10xx-flash-status
tools/unit-tests/unit-ti-hercules-erase
tools/unit-tests/unit-update-disk-fsp
tools/unit-tests/unit-update-ram-custom-trailer
tools/unit-tests/unit-update-ram-nofixed-noramboot
tools/unit-tests/unit-update-trigger-scrub
tools/unit-tests/unit-x86-uart
# sources generated by the unit-test extraction rules
tools/unit-tests/ct_compare_extract.h
tools/unit-tests/fdt_memrsv_extract.h
tools/unit-tests/hifive1_flash_write_extract.h
tools/unit-tests/hifive1_hfrosccfg_extract.h
tools/unit-tests/keystore_api_extract.h
tools/unit-tests/keystore_emitted.c
tools/unit-tests/keystore_gen
tools/unit-tests/kinetis_erase_extract.h
tools/unit-tests/kontron_spi_extract.h
tools/unit-tests/kontron_spi_fn_extract.h
tools/unit-tests/nrf5340_protect_fn_extract.h
tools/unit-tests/nrf54l_uart_write_extract.h
tools/unit-tests/p1021_erase_extract.h
tools/unit-tests/p1021_erase_fn_extract.h
tools/unit-tests/p1021_read_extract.h
tools/unit-tests/p1021_read_fn_extract.h
tools/unit-tests/rp2350_flash_write_extract.h
tools/unit-tests/stm32c0_write_extract.h
tools/unit-tests/stm32g4_write_extract.h
tools/unit-tests/stm32h7_flash_write_extract.h
tools/unit-tests/stm32l4_write_extract.h
tools/unit-tests/stm32u3_flash_write_extract.h
tools/unit-tests/stm32wb_write_extract.h
tools/unit-tests/t10xx_flash_status_extract.h
tools/unit-tests/ti_hercules_erase_extract.h
tools/unit-tests/versal_host_write.c
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ endif()
#---------------------------------------------------------------------------------------------
if(SIGN STREQUAL "NONE")
list(APPEND KEYTOOL_OPTIONS --no-sign)
message(STATUS "Image signing disabled")
message(WARNING "SIGN=NONE / WOLFBOOT_NO_SIGN=1 disables firmware signature verification; images are NOT authenticated. Do not use in production.")
set(WOLFBOOT_SIGNING_PRIVATE_KEY
""
CACHE INTERNAL "")
Expand Down Expand Up @@ -1023,6 +1023,7 @@ if(EXT_FLASH)
endif()

if(ALLOW_DOWNGRADE)
message(WARNING "ALLOW_DOWNGRADE=1 disables anti-rollback enforcement; signed older firmware images can replace newer ones")
list(APPEND WOLFBOOT_DEFS ALLOW_DOWNGRADE)
endif()

Expand All @@ -1031,6 +1032,7 @@ if(NVM_FLASH_WRITEONCE)
endif()

if(DISABLE_BACKUP)
message(WARNING "DISABLE_BACKUP=1 disables power-fail-safe updates; losing power during an update can leave BOOT partially written and unrecoverable")
list(APPEND WOLFBOOT_DEFS DISABLE_BACKUP)
endif()

Expand Down
14 changes: 12 additions & 2 deletions hal/hifive1.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
#define HFROSCCFG_TRIM 0x001F0000UL
#define HFROSCCFG_EN (1UL << 30UL)
#define HFROSCCFG_READY (1UL << 31UL)
#define HFROSCCFG_DIV_SHIFT(d) ((d << 0) & HFROSCCFG_TRIM)
#define HFROSCCFG_DIV_SHIFT(d) ((d << 0) & HFROSCCFG_DIV)
#define HFROSCCFG_TRIM_SHIFT(t) ((t << 16) & HFROSCCFG_TRIM)

#define HFXOSCCFG_EN (1 << 30)
Expand Down Expand Up @@ -485,6 +485,10 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
uint8_t data_copy[FLASH_PAGE_SIZE];
int swmode = 0;

if (len < 0)
return -1;
if (len == 0)
return 0;

if (address >= FLASH_BASE)
address -= FLASH_BASE;
Expand Down Expand Up @@ -573,8 +577,14 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
{
uint32_t end;
uint32_t p;
if (address >= FLASH_BASE)

/* A non-positive length would underflow the inclusive end below. */
if (len <= 0) {
return 0;
}
if (address >= FLASH_BASE) {
address -= FLASH_BASE;
}
end = address + len - 1;

FESPI_REG_TXMARK = 1;
Expand Down
9 changes: 7 additions & 2 deletions hal/kinetis.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,18 @@ void RAMFUNCTION hal_flash_lock(void)
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
{
int idx = 0;

do_flash_init();
do {
/* Pre-test guard: a do/while would erase one full sector for a
* zero/negative length request. */
if (len <= 0)
return -1;
while (len > 0) {
if (FLASH_Erase(&pflash, address + WOLFBOOT_SECTOR_SIZE * idx, WOLFBOOT_SECTOR_SIZE, kFTFx_ApiEraseKey) != kStatus_FTFx_Success)
return -1;
len -= WOLFBOOT_SECTOR_SIZE;
idx++;
} while (len > 0);
}
FTFx_CACHE_ClearCachePrefetchSpeculation(&pcache, 1);
return 0;
}
Expand Down
9 changes: 7 additions & 2 deletions hal/mcxa.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ void RAMFUNCTION hal_flash_lock(void)

int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
{
if (len <= 0)
return -1;
while ((address % 4) != 0)
address --;
if (FLASH_EraseSector(&pflash, address, len, kFLASH_ApiEraseKey) != kStatus_Success)
address--;
/* FLASH_EraseSector takes the length in bytes (4-byte aligned),
* not a sector count (MCXA ROM API, fsl_romapi.h). */
if (FLASH_EraseSector(&pflash, address, (uint32_t)len, kFLASH_ApiEraseKey)
!= kStatus_Success)
return -1;
return 0;
}
17 changes: 12 additions & 5 deletions hal/nrf54l.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,29 @@ void uart_write_device(int device, const char* buf, unsigned int sz)
{
static char buffer[UART_WRITE_BUF_SIZE];
int bufsz = 0;
int i;

for (int i = 0; i < (int)sz && bufsz < UART_WRITE_BUF_SIZE; i++) {
for (i = 0; i < (int)sz; i++) {
char ch = (char) buf[i];

if (ch == '\r')
continue;

if (ch == '\n') {
if (bufsz >= (UART_WRITE_BUF_SIZE - 1))
break;

if (bufsz >= (UART_WRITE_BUF_SIZE - 1)) {
uart_write_raw(device, buffer, bufsz);
bufsz = 0;
}
buffer[bufsz++] = '\r';
}
if (bufsz >= UART_WRITE_BUF_SIZE) {
uart_write_raw(device, buffer, bufsz);
bufsz = 0;
}
buffer[bufsz++] = ch;
}
uart_write_raw(device, buffer, bufsz);
if (bufsz > 0)
uart_write_raw(device, buffer, bufsz);
}

void uart_write(const char* buf, unsigned int sz)
Expand Down
12 changes: 9 additions & 3 deletions hal/nxp_ls1028a.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,13 +780,17 @@ static int test_flash(void)
/* Erase sector */
ret = ext_flash_erase(TEST_ADDRESS, WOLFBOOT_SECTOR_SIZE);
wolfBoot_printf("Erase Sector: Ret %d\n", ret);
if (ret < 0)
return -1;

/* Write Pages */
for (i=0; i<sizeof(pageData); i++) {
pageData[i] = (i & 0xff);
}
ret = ext_flash_write(TEST_ADDRESS, pageData, sizeof(pageData));
wolfBoot_printf("Write Page: Ret %d\n", ret);
if (ret < 0)
return -1;

/* Read page */
memset(pageData, 0, sizeof(pageData));
Expand All @@ -799,12 +803,12 @@ static int test_flash(void)
wolfBoot_printf("check[%3d] %02x\n", i, pageData[i]);
if (pageData[i] != (i & 0xff)) {
wolfBoot_printf("Check Data @ %d failed\n", i);
return -i;
return -1;
}
}

wolfBoot_printf("Flash Test Passed\n");
return ret;
return 0;
}
#endif /* TEST_EXT_FLASH */

Expand Down Expand Up @@ -951,7 +955,9 @@ void hal_init(void)
wolfBoot_printf("Flash init done\n");

#ifdef TEST_EXT_FLASH
test_flash();
if (test_flash() != 0) {
wolfBoot_printf("External flash test FAILED\n");
}
#endif

#ifdef TPM_TEST
Expand Down
33 changes: 30 additions & 3 deletions hal/rtl8735b.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ extern void wolfboot_ram_entry(void);
static uint8_t hal_bl_scratch[2048]
__attribute__((section(".ram.noinit"), aligned(32)));

/* The bootloader writes seven fixed slots into hal_bl_scratch at 256-byte
* strides; the last one (phal_spic_adaptor) gets the remaining 512 bytes.
* The SDK struct sizes are only known in the SDK backend -- when SPIC
* adaptor reuse is enabled, re-derive the slots from sizeof() of the real
* structs and keep this budget check. */
typedef char hal_bl_scratch_budget_check[
(sizeof(hal_bl_scratch) >= 6 * 256 + 512) ? 1 : -1];

/* Exactly the 10 bytes "AmebaPro2\xff" (the trailing 0xff matters; a NUL pad
* fails as "Invalid FW Image Signature"). */
const unsigned char hal_ram_img_sig[10]
Expand Down Expand Up @@ -433,9 +441,28 @@ void ext_flash_lock(void)
#endif
}

int ext_flash_read(uintptr_t address, uint8_t *data, int len)
/* Physical SPI NOR capacity (16 MB) -- the ext_flash_* window. */
#define RTL8735B_EXT_FLASH_SIZE 0x1000000

/* All ext_flash callers derive (address, len) from the partition layout in
* target.h; reject anything past the device end before it reaches the SDK. */
static int ext_flash_in_layout(uintptr_t address, int len)
{
if (len < 0) {
return 0;
}
if ((uint32_t)address >= RTL8735B_EXT_FLASH_SIZE) {
return 0;
}
if ((uint32_t)len > RTL8735B_EXT_FLASH_SIZE - (uint32_t)address) {
return 0;
}
return 1;
}

int ext_flash_read(uintptr_t address, uint8_t *data, int len)
{
if (!ext_flash_in_layout(address, len)) {
return -1;
}
if (len == 0) {
Expand All @@ -459,7 +486,7 @@ int ext_flash_read(uintptr_t address, uint8_t *data, int len)

int ext_flash_write(uintptr_t address, const uint8_t *data, int len)
{
if (len < 0) {
if (!ext_flash_in_layout(address, len)) {
return -1;
}
if (len == 0) {
Expand All @@ -485,7 +512,7 @@ int ext_flash_erase(uintptr_t address, int len)
uint32_t sector_addr;
uint32_t end_addr;

if (len < 0 || (uint32_t)len > UINT32_MAX - (uint32_t)address) {
if (!ext_flash_in_layout(address, len)) {
return -1;
}
if (len == 0) {
Expand Down
6 changes: 3 additions & 3 deletions hal/same51.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
NVMCTRLB = (NVMCMD_PBC | NVMCMD_KEY);
while (i < len) {
if ((len - i > 3) && ((((address + i) & 0x03) == 0) && ((((uint32_t)data) + i) & 0x03) == 0)) {
dst = (uint32_t *)address;
src = (uint32_t *)data;
dst[i >> 2] = src[i >> 2];
dst = (uint32_t *)(address + i);
src = (uint32_t *)(data + i);
*dst = *src;
i+=4;
} else {
uint32_t val;
Expand Down
6 changes: 3 additions & 3 deletions hal/samr21.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
NVMCTRLA_REG = (NVMCMD_PBC | NVMCMD_KEY);
while (i < len) {
if ((len - i > 3) && ((((address + i) & 0x03) == 0) && ((((uint32_t)data) + i) & 0x03) == 0)) {
dst = (uint32_t *)address;
src = (uint32_t *)data;
dst[i >> 2] = src[i >> 2];
dst = (uint32_t *)(address + i);
src = (uint32_t *)(data + i);
*dst = *src;
i+=4;
} else {
uint32_t val;
Expand Down
4 changes: 3 additions & 1 deletion hal/sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,10 @@ static int mmap_file(const char *path, uint8_t *address, uint8_t** ret_address)

mmaped_addr = mmap(address, st.st_size, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if (mmaped_addr == MAP_FAILED)
if (mmaped_addr == MAP_FAILED) {
close(fd);
return -1;
}

wolfBoot_printf( "Simulator assigned %s to base %p\n", path, mmaped_addr);

Expand Down
6 changes: 5 additions & 1 deletion hal/stm32c0.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
#define FLASH_SECR (*(volatile uint32_t *)(FLASH_BASE + 0x80)) /* RM0490 - 3.7.13 - FLASH_SECR */
#endif /* !WOLFBOOT_UNIT_TEST_FLASH_ERASE */

#define FLASHMEM_ADDRESS_SPACE (0x08000000)

#define FLASH_PAGE_SIZE (0x800) /* 2KB */
#define FLASH_PAGE_SIZE_SHIFT 11 /* (1 << FLASH_PAGE_SIZE_SHIFT) == FLASH_PAGE_SIZE*/

Expand Down Expand Up @@ -207,10 +209,12 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
uint32_t p;
if (len == 0)
return -1;
address -= FLASHMEM_ADDRESS_SPACE;
end_address = address + len;
for (p = address; p < end_address; p += FLASH_PAGE_SIZE) {
uint32_t reg = FLASH_CR & (~(FLASH_CR_PNB_MASK << FLASH_CR_PNB_SHIFT));
FLASH_CR = reg | ((p >> FLASH_PAGE_SIZE_SHIFT) << FLASH_CR_PNB_SHIFT) | FLASH_CR_PER;
FLASH_CR = reg | (((p >> FLASH_PAGE_SIZE_SHIFT) & FLASH_CR_PNB_MASK) <<
FLASH_CR_PNB_SHIFT) | FLASH_CR_PER;
DMB();
FLASH_CR |= FLASH_CR_STRT;
flash_wait_complete();
Expand Down
2 changes: 1 addition & 1 deletion hal/stm32f4.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ int RAMFUNCTION hal_flash_erase(uint32_t _address, int len)
if ((end_address >= flash_sector[i]) && (end_address < flash_sector[i + 1])) {
end = i;
}
if (start > 0 && end > 0)
if (start >= 0 && end >= 0)
break;
}
if (start < 0 || end < 0)
Expand Down
8 changes: 4 additions & 4 deletions hal/stm32g0.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
flash_clear_errors();
if ((len - i >= 8) && ((((address + i) & 0x07) == 0) &&
((((uint32_t)data) + i) & 0x07) == 0)) {
src = (uint32_t *)data;
dst = (uint32_t *)address;
src = (uint32_t *)(data + i);
dst = (uint32_t *)(address + i);
flash_wait_complete();
dst[i >> 2] = src[i >> 2];
dst[(i >> 2) + 1] = src[(i >> 2) + 1];
dst[0] = src[0];
dst[1] = src[1];
flash_wait_complete();
i+=8;
} else {
Expand Down
Loading
Loading