Skip to content

Commit 2acc916

Browse files
committed
Added support for treating external FRAM as internal flash. Added check on image header size and sector size. Expanded the ML-DSA testing. Improved the Vorago build_test scripts to use .config for parameters. Made EDAC parameters build-time macros.
1 parent f89eb94 commit 2acc916

File tree

14 files changed

+276
-45
lines changed

14 files changed

+276
-45
lines changed

.github/workflows/test-sunnyday-simulator.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ jobs:
104104
- name: Run dualbank swap simulation
105105
run: |
106106
tools/scripts/sim-dualbank-swap-update.sh
107-
107+
108108
- name: Cleanup before WOLFBOOT_SMALL_STACK test
109109
run: |
110110
make keysclean
111111
mv .config.orig .config
112-
112+
113113
- name: Build wolfboot.elf (ECC256, WOLFBOOT_SMALL_STACK)
114114
run: |
115115
make clean && make test-sim-internal-flash-with-update SIGN=ECC256 WOLFBOOT_SMALL_STACK=1 SPMATH=1
@@ -617,10 +617,18 @@ jobs:
617617
run: |
618618
tools/scripts/sim-pq-sunnyday-update.sh config/examples/sim-xmss.config
619619
620-
- name: Run sunny day ML-DSA update test
620+
- name: Run sunny day ML-DSA level 2 update test
621621
run: |
622622
tools/scripts/sim-pq-sunnyday-update.sh config/examples/sim-ml-dsa.config
623623
624+
- name: Run sunny day ML-DSA level 3 update test
625+
run: |
626+
tools/scripts/sim-pq-sunnyday-update.sh config/examples/sim-ml-dsa3.config
627+
628+
- name: Run sunny day ML-DSA level 5 update test
629+
run: |
630+
tools/scripts/sim-pq-sunnyday-update.sh config/examples/sim-ml-dsa5.config
631+
624632
# 64 Bit simulator, Hybrid auth ML_DSA + ECDSA
625633
#
626634
- name: make clean

config/examples/sim-ml-dsa.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ IMAGE_HEADER_SIZE=8192
4949
# ML_DSA_LEVEL=5
5050
# IMAGE_SIGNATURE_SIZE=4627
5151
# IMAGE_HEADER_SIZE=12288
52-
# This example needsd larger sector size.
52+
# NOTE: This example needs larger sector size.
5353
# WOLFBOOT_SECTOR_SIZE=0x3000
5454
#
5555

config/examples/sim-ml-dsa3.config

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# ML-DSA signature example, based on sim.config example.
2+
#
3+
# The acceptable parameter values are those in FIPS 204:
4+
#
5+
# ML_DSA_LEVEL = {2, 3, 5}
6+
#
7+
# This corresponds to these security levels (from FIPS 204, Table 1.):
8+
#
9+
# Claimed Security Strength
10+
# ML-DSA-44 Category 2
11+
# ML-DSA-65 Category 3
12+
# ML-DSA-87 Category 5
13+
#
14+
# The signature, pub key, and priv key lengths are all a function
15+
# of this parameter. Refer to this table (from FIPS 204, Table 2.)
16+
# to configure your IMAGE_SIGNATURE_SIZE:
17+
#
18+
# Table 2. Sizes (in bytes) of keys and signatures of ML-DSA
19+
#
20+
# Private Key Public Key Signature Size
21+
# ML-DSA-44 2560 1312 2420
22+
# ML-DSA-65 4032 1952 3309
23+
# ML-DSA-87 4896 2592 4627
24+
#
25+
26+
ARCH=sim
27+
TARGET=sim
28+
SIGN=ML_DSA
29+
HASH=SHA256
30+
WOLFBOOT_SMALL_STACK=0
31+
SPI_FLASH=0
32+
DEBUG=0
33+
DELTA_UPDATES=0
34+
35+
#
36+
# ML-DSA config examples:
37+
#
38+
# Category 3:
39+
ML_DSA_LEVEL=3
40+
IMAGE_SIGNATURE_SIZE=3309
41+
IMAGE_HEADER_SIZE=8192
42+
43+
# sizes should be multiple of system page size
44+
WOLFBOOT_PARTITION_SIZE=0x40000
45+
WOLFBOOT_SECTOR_SIZE=0x2000
46+
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x20000
47+
# if on external flash, it should be multiple of system page size
48+
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x60000
49+
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xA0000
50+
51+
# required for keytools
52+
WOLFBOOT_FIXED_PARTITIONS=1

config/examples/sim-ml-dsa5.config

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# ML-DSA signature example, based on sim.config example.
2+
#
3+
# The acceptable parameter values are those in FIPS 204:
4+
#
5+
# ML_DSA_LEVEL = {2, 3, 5}
6+
#
7+
# This corresponds to these security levels (from FIPS 204, Table 1.):
8+
#
9+
# Claimed Security Strength
10+
# ML-DSA-44 Category 2
11+
# ML-DSA-65 Category 3
12+
# ML-DSA-87 Category 5
13+
#
14+
# The signature, pub key, and priv key lengths are all a function
15+
# of this parameter. Refer to this table (from FIPS 204, Table 2.)
16+
# to configure your IMAGE_SIGNATURE_SIZE:
17+
#
18+
# Table 2. Sizes (in bytes) of keys and signatures of ML-DSA
19+
#
20+
# Private Key Public Key Signature Size
21+
# ML-DSA-44 2560 1312 2420
22+
# ML-DSA-65 4032 1952 3309
23+
# ML-DSA-87 4896 2592 4627
24+
#
25+
26+
ARCH=sim
27+
TARGET=sim
28+
SIGN=ML_DSA
29+
HASH=SHA256
30+
WOLFBOOT_SMALL_STACK=0
31+
SPI_FLASH=0
32+
DEBUG=0
33+
DELTA_UPDATES=0
34+
35+
#
36+
# ML-DSA config examples:
37+
#
38+
# Category 5:
39+
ML_DSA_LEVEL=5
40+
IMAGE_SIGNATURE_SIZE=4627
41+
IMAGE_HEADER_SIZE=12288
42+
43+
# sizes should be multiple of system page size
44+
WOLFBOOT_PARTITION_SIZE=0x40000
45+
# This example needs larger sector size.
46+
WOLFBOOT_SECTOR_SIZE=0x3000
47+
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x20000
48+
# if on external flash, it should be multiple of system page size
49+
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x60000
50+
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xA0000
51+
52+
# required for keytools
53+
WOLFBOOT_FIXED_PARTITIONS=1

config/examples/vorago_va416x0.config

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
ARCH?=ARM
22
CORTEX_M4?=1
33
TARGET?=va416x0
4+
5+
# ECDSA P384 and SHA384
46
SIGN?=ECC384
57
HASH?=SHA384
68
IMAGE_HEADER_SIZE=512
9+
10+
# ML-DSA Level 5 (87)
11+
#SIGN=ML_DSA
12+
#HASH=SHA256
13+
#ML_DSA_LEVEL=5
14+
#IMAGE_SIGNATURE_SIZE=4627
15+
#IMAGE_HEADER_SIZE=12288
16+
717
WOLFBOOT_VERSION?=1
818
ARMORED?=1
919
DEBUG?=0
1020
DEBUG_SYMBOLS?=1
1121
DEBUG_UART?=1
1222
VTOR?=1
13-
EXT_FLASH?=1
23+
EXT_FLASH?=0
1424
SPI_FLASH?=0
1525
NO_XIP?=1
1626
NVM_FLASH_WRITEONCE?=0
@@ -35,19 +45,34 @@ NO_ARM_ASM?=0
3545
# Optional: Use smaller SHA512
3646
#CFLAGS_EXTRA+=-DUSE_SLOW_SHA512
3747

38-
# 2KB sector
39-
WOLFBOOT_SECTOR_SIZE?=0x800
40-
4148
# 38KB boot, 108KB partitions, 2KB swap
49+
WOLFBOOT_SECTOR_SIZE?=0x800
4250
WOLFBOOT_PARTITION_SIZE?=0x1B000
4351
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x9800
4452
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x24800
4553
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x3F800
4654

55+
# ML-DSA 5: 36KB boot, 104KB partitions, 12KB swap
56+
#WOLFBOOT_SECTOR_SIZE?=0x3000
57+
#WOLFBOOT_PARTITION_SIZE?=0x1A000
58+
#WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x9000
59+
#WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x23000
60+
#WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x3D000
61+
62+
# Debug: 64KB boot, 95KB partitions, 2KB swap
63+
#WOLFBOOT_SECTOR_SIZE?=0x800
64+
#WOLFBOOT_PARTITION_SIZE?=0x18000
65+
#WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xFC00
66+
#WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x27C00
67+
#WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x3FC00
68+
4769
# Vorago SDK common drivers directory
4870
VORAGO_SDK_DIR?=$(PWD)/../VA416xx_SDK/
4971

5072
# Use Verago FRAM driver
5173
USE_HAL_SPI_FRAM=1
5274

5375
#CFLAGS_EXTRA+=-DDEBUG_EXT_FLASH
76+
77+
#CFLAGS_EXTRA+=-DWOLFBOOT_EDAC_RAM_SCRUB=1000
78+
#CFLAGS_EXTRA+=-DWOLFBOOT_EDAC_ROM_SCRUB=125

docs/PQ.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ In terms of relative tradeoffs:
2626
See these config files for simulated target examples:
2727

2828
- `config/examples/sim-ml-dsa.config`
29+
- `config/examples/sim-ml-dsa3.config`
30+
- `config/examples/sim-ml-dsa5.config`
2931
- `config/examples/sim-lms.config`
3032
- `config/examples/sim-xmss.config`
3133

@@ -60,15 +62,16 @@ all depend on the parameter set:
6062

6163
### ML-DSA Config
6264

63-
A new ML-DSA sim example has been added here:
65+
See ML-DSA sim examples here:
6466

6567
```
6668
config/examples/sim-ml-dsa.config
69+
config/examples/sim-ml-dsa3.config
70+
config/examples/sim-ml-dsa5.config
6771
```
6872

6973
The security category level is configured with `ML_DSA_LEVEL=<num>`, where
70-
num = 2, 3, 5. Here is an example from the `sim-ml-dsa.config` for category
71-
2:
74+
num = 2, 3, 5. Here is an example for level 2:
7275

7376
```
7477
# ML-DSA config examples:

docs/Targets.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,12 +3586,12 @@ FLASH: The VA41630 has 256KB of internal SPI FRAM (for the VA41620 its external)
35863586

35873587
Default flash layout:
35883588

3589-
| Partition | Size | Address | Description |
3590-
|-----------|-------|---------|-------------|
3591-
| Boot | 38KB | 0x0 | Bootloader partition |
3592-
| Boot | 108KB | 0x9800 | Boot partition |
3593-
| Update | 108KB | 0x24800 | Update partition |
3594-
| Swap | 2KB | 0x3F800 | Swap area |
3589+
| Partition | Size | Address | Description |
3590+
|-------------|-------|---------|-------------|
3591+
| Bootloader | 38KB | 0x0 | Bootloader partition |
3592+
| Application | 108KB | 0x9800 | Boot partition |
3593+
| Update | 108KB | 0x24800 | Update partition |
3594+
| Swap | 2KB | 0x3F800 | Swap area |
35953595

35963596
SRAM: 64KB on-chip SRAM and 256KB on-chip instruction/program memory
35973597

hal/imx_rt.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767

6868
/* #define DEBUG_EXT_FLASH */
6969

70-
#ifdef __WOLFBOOT
7170

7271
/** Built-in ROM API for bootloaders **/
7372

@@ -866,8 +865,6 @@ void hal_prepare_boot(void)
866865
{
867866
}
868867

869-
#endif /* __WOLFBOOT */
870-
871868
static int RAMFUNCTION hal_flash_init(void)
872869
{
873870
status_t ret = 0;

hal/va416x0.c

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -296,28 +296,48 @@ hal_status_t FRAM_Erase(uint8_t spiBank, uint32_t addr, uint32_t len)
296296

297297
void RAMFUNCTION hal_flash_unlock(void)
298298
{
299-
299+
/* Enable writes to code memory space */
300+
VOR_SYSCONFIG->ROM_PROT |= SYSCONFIG_ROM_PROT_WREN_Msk;
300301
}
301302

302303
void RAMFUNCTION hal_flash_lock(void)
303304
{
304-
305+
/* Disable writes to code memory space */
306+
VOR_SYSCONFIG->ROM_PROT &= ~SYSCONFIG_ROM_PROT_WREN_Msk;
305307
}
306308

307309
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
308310
{
309-
/* no internal flash */
310-
(void)address;
311-
(void)data;
312-
(void)len;
313-
return 0;
311+
hal_status_t status;
312+
#ifdef DEBUG_EXT_FLASH
313+
wolfBoot_printf("ext write: addr 0x%x, dst 0x%x, len %d\n",
314+
address, data, len);
315+
#endif
316+
status = FRAM_Write(ROM_SPI_BANK, address, (uint8_t*)data, len);
317+
if (status == hal_status_ok) {
318+
/* update the shadow IRAM */
319+
memcpy((void*)address, data, len);
320+
}
321+
else {
322+
return -(int)status; /* convert to negative error code */
323+
}
324+
return len;
314325
}
315326

316327
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
317328
{
318-
/* no internal flash */
319-
(void)address;
320-
(void)len;
329+
hal_status_t status;
330+
#ifdef DEBUG_EXT_FLASH
331+
wolfBoot_printf("ext erase: addr 0x%x, len %d\n", address, len);
332+
#endif
333+
status = FRAM_Erase(ROM_SPI_BANK, address, len);
334+
if (status == hal_status_ok) {
335+
/* update the shadow IRAM */
336+
memset((void*)address, 0xFF, len);
337+
}
338+
else {
339+
return -(int)status; /* convert to negative error code */
340+
}
321341
return 0;
322342
}
323343

@@ -461,14 +481,14 @@ void hal_init(void)
461481
hal_status_t status;
462482

463483
#ifdef __WOLFBOOT /* build for wolfBoot only */
464-
/* Configure PLL to set CPU clock to 100MHz */
484+
/* Configure PLL to set CPU clock to 100MHz - 40MHz crystal * 2.5 */
465485
status = HAL_Clkgen_PLL(CLK_CTRL0_XTAL_N_PLL2P5X);
466486
if (status != hal_status_ok) {
467487
wolfBoot_printf("HAL_Clkgen_PLL failed\n");
468488
/* continue anyways */
469489
}
470490

471-
/* Disable Watchdog */
491+
/* Disable Watchdog - should be already disabled out of reset */
472492
VOR_WATCH_DOG->WDOGLOCK = 0x1ACCE551;
473493
VOR_WATCH_DOG->WDOGCONTROL = 0x0;
474494
NVIC_ClearPendingIRQ(WATCHDOG_IRQn);
@@ -477,7 +497,7 @@ void hal_init(void)
477497
SCB->CPACR |= ((0x3 << 20)|(0x3 << 22));
478498

479499
/* Init EDAC */
480-
ConfigEdac(1000, 125);
500+
ConfigEdac(WOLFBOOT_EDAC_RAM_SCRUB, WOLFBOOT_EDAC_ROM_SCRUB);
481501
#else
482502
/* get clock settings and update SystemCoreClock */
483503
SystemCoreClockUpdate();
@@ -518,6 +538,6 @@ void hal_init(void)
518538

519539
void hal_prepare_boot(void)
520540
{
521-
541+
/* Restore clock to hear-beat oscillator */
542+
(void)HAL_Clkgen_PLL(CLK_CFG_HBO);
522543
}
523-

hal/va416x0.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,13 @@
9999
#define ROM_SPI_CSN (0)
100100

101101

102+
/* EDAC Configuration defaults */
103+
#ifndef WOLFBOOT_EDAC_RAM_SCRUB
104+
#define WOLFBOOT_EDAC_RAM_SCRUB 1000
105+
#endif
106+
#ifndef WOLFBOOT_EDAC_ROM_SCRUB
107+
#define WOLFBOOT_EDAC_ROM_SCRUB 125
108+
#endif
109+
102110

103111
#endif /* VA416X0_DEF_INCLUDED */

0 commit comments

Comments
 (0)