Skip to content

Commit 07aa125

Browse files
committed
Remove malloc from flash ram sim. Update tests to use stack memory for flash ram sim
1 parent eca1a12 commit 07aa125

File tree

17 files changed

+72
-36
lines changed

17 files changed

+72
-36
lines changed

benchmark/config/wolfhsm_cfg.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
#define WOLFHSM_CFG_CERTIFICATE_MANAGER
4242
#define WOLFHSM_CFG_CERTIFICATE_MANAGER_ACERT
4343

44-
#define WOLFHSM_CFG_FLASH_RAMSIM_MALLOC
45-
4644
/* Benchmark configs */
4745
#define WOLFHSM_CFG_BENCH_ENABLE
4846
#endif /* WOLFHSM_CFG_H_ */

benchmark/wh_bench.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ int wh_Bench_ClientServer_Posix(void)
562562
{
563563
uint8_t req[BUFFER_SIZE] = {0};
564564
uint8_t resp[BUFFER_SIZE] = {0};
565+
uint8_t memory[FLASH_RAM_SIZE] = {0};
565566

566567
/* Transport memory configuration */
567568
whTransportMemConfig tmcf[1] = {{
@@ -601,6 +602,7 @@ int wh_Bench_ClientServer_Posix(void)
601602
.sectorSize = FLASH_RAM_SIZE / 2,
602603
.pageSize = 8,
603604
.erasedByte = (uint8_t)0,
605+
.memory = memory,
604606
}};
605607
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
606608

@@ -679,4 +681,4 @@ int wh_Bench_ClientServer_Posix(void)
679681

680682
#endif /* WOLFHSM_CFG_TEST_POSIX */
681683

682-
#endif /* WOLFHSM_CFG_BENCH_ENABLE */
684+
#endif /* WOLFHSM_CFG_BENCH_ENABLE */

examples/posix/tcp/wh_server_tcp/wh_server_tcp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ int main(int argc, char** argv)
567567
const char* nvmInitFilePath = NULL;
568568
int keyId = WH_KEYID_ERASED; /* Default key ID if none provided */
569569
int clientId = 12; /* Default client ID if none provided */
570+
uint8_t memory[FLASH_RAM_SIZE] = {0};
571+
570572

571573
/* Parse command-line arguments */
572574
for (int i = 1; i < argc; i++) {
@@ -605,6 +607,7 @@ int main(int argc, char** argv)
605607
.sectorSize = FLASH_RAM_SIZE / 2,
606608
.pageSize = 8,
607609
.erasedByte = (uint8_t)0,
610+
.memory = memory,
608611
}};
609612
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
610613

examples/posix/tcp/wh_server_tcp/wolfhsm_cfg.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
#define WOLFHSM_CFG_CERTIFICATE_MANAGER
4343
#define WOLFHSM_CFG_CERTIFICATE_MANAGER_ACERT
4444

45-
#define WOLFHSM_CFG_FLASH_RAMSIM_MALLOC
46-
4745
#define XMEMFENCE() __atomic_thread_fence(__ATOMIC_SEQ_CST)
4846

4947
#endif /* WOLFHSM_CFG_H_ */

src/wh_flash_ramsim.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ int whFlashRamsim_Init(void* context, const void* config)
7070
ctx->size = cfg->size;
7171
ctx->sectorSize = cfg->sectorSize;
7272
ctx->pageSize = cfg->pageSize;
73-
#if defined(WOLFHSM_CFG_FLASH_RAMSIM_MALLOC)
74-
ctx->memory = (uint8_t*)malloc(ctx->size);
75-
#else
7673
ctx->memory = cfg->memory;
77-
#endif
7874
ctx->erasedByte = cfg->erasedByte;
7975
ctx->writeLocked = 0;
8076

test/config/wolfhsm_cfg.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
#define WOLFHSM_CFG_CERTIFICATE_MANAGER
4444
#define WOLFHSM_CFG_CERTIFICATE_MANAGER_ACERT
4545

46-
#define WOLFHSM_CFG_FLASH_RAMSIM_MALLOC
47-
4846
/* Enable Image Manager feature */
4947
#define WOLFHSM_CFG_SERVER_IMG_MGR
5048

test/wh_test_cert.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
#include "wh_test_cert_data_acert.h"
5050
#endif
5151

52+
#define FLASH_RAM_SIZE (1024 * 1024) /* 1MB */
53+
#define FLASH_SECTOR_SIZE (128 * 1024) /* 128KB */
54+
#define FLASH_PAGE_SIZE (8) /* 8B */
55+
5256
#ifdef WOLFHSM_CFG_ENABLE_SERVER
5357
/* Run certificate configuration tests */
5458
int whTest_CertServerCfg(whServerConfig* serverCfg)
@@ -517,12 +521,14 @@ int whTest_CertRamSim(void)
517521
.server_id = 124,
518522
}};
519523
/* RamSim Flash state and configuration */
524+
uint8_t memory[FLASH_RAM_SIZE] = {0};
520525
whFlashRamsimCtx fc[1] = {0};
521526
whFlashRamsimCfg fc_conf[1] = {{
522-
.size = 1024 * 1024, /* 1MB Flash */
523-
.sectorSize = 128 * 1024, /* 128KB Sector Size */
524-
.pageSize = 8, /* 8B Page Size */
527+
.size = FLASH_RAM_SIZE, /* 1MB Flash */
528+
.sectorSize = FLASH_SECTOR_SIZE, /* 128KB Sector Size */
529+
.pageSize = FLASH_PAGE_SIZE, /* 8B Page Size */
525530
.erasedByte = ~(uint8_t)0,
531+
.memory = memory,
526532
}};
527533
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
528534

test/wh_test_clientserver.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
#define REPEAT_COUNT 10
6262
#define ONE_MS 1000
6363
#define FLASH_RAM_SIZE (1024 * 1024) /* 1MB */
64+
#define FLASH_SECTOR_SIZE (128 * 1024) /* 128KB */
65+
#define FLASH_PAGE_SIZE (8) /* 8B */
6466

6567
#ifdef WOLFHSM_CFG_DMA
6668
#define DMA_TEST_MEM_NWORDS 3
@@ -534,12 +536,14 @@ int whTest_ClientServerSequential(void)
534536
}};
535537

536538
/* RamSim Flash state and configuration */
539+
uint8_t memory[FLASH_RAM_SIZE] = {0};
537540
whFlashRamsimCtx fc[1] = {0};
538541
whFlashRamsimCfg fc_conf[1] = {{
539-
.size = 1024 * 1024, /* 1MB Flash */
540-
.sectorSize = 128 * 1024, /* 128KB Sector Size */
541-
.pageSize = 8, /* 8B Page Size */
542+
.size = FLASH_RAM_SIZE, /* 1MB Flash */
543+
.sectorSize = FLASH_SECTOR_SIZE, /* 128KB Sector Size */
544+
.pageSize = FLASH_PAGE_SIZE, /* 8B Page Size */
542545
.erasedByte = ~(uint8_t)0,
546+
.memory = memory,
543547
}};
544548
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
545549

@@ -1556,12 +1560,14 @@ static int wh_ClientServer_MemThreadTest(void)
15561560
}};
15571561

15581562
/* RamSim Flash state and configuration */
1563+
uint8_t memory[FLASH_RAM_SIZE] = {0};
15591564
whFlashRamsimCtx fc[1] = {0};
15601565
whFlashRamsimCfg fc_conf[1] = {{
15611566
.size = FLASH_RAM_SIZE,
15621567
.sectorSize = FLASH_RAM_SIZE/2,
15631568
.pageSize = 8,
15641569
.erasedByte = (uint8_t)0,
1570+
.memory = memory,
15651571
}};
15661572
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
15671573

@@ -1647,12 +1653,14 @@ static int wh_ClientServer_PosixMemMapThreadTest(void)
16471653
}};
16481654

16491655
/* RamSim Flash state and configuration */
1656+
uint8_t memory[FLASH_RAM_SIZE] = {0};
16501657
whFlashRamsimCtx fc[1] = {0};
16511658
whFlashRamsimCfg fc_conf[1] = {{
16521659
.size = FLASH_RAM_SIZE,
16531660
.sectorSize = FLASH_RAM_SIZE / 2,
16541661
.pageSize = 8,
16551662
.erasedByte = (uint8_t)0,
1663+
.memory = memory,
16561664
}};
16571665
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
16581666

test/wh_test_crypto.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
#include "port/posix/posix_flash_file.h"
6565
#endif
6666

67+
#define FLASH_RAM_SIZE (1024 * 1024) /* 1MB */
68+
#define FLASH_SECTOR_SIZE (128 * 1024) /* 128KB */
69+
#define FLASH_PAGE_SIZE (8) /* 8B */
70+
6771
enum {
6872
/* Total size needs to fit:
6973
* - Transport CSR (whTransportMemCsr)
@@ -2868,12 +2872,14 @@ static int wh_ClientServer_MemThreadTest(void)
28682872
}};
28692873

28702874
/* RamSim Flash state and configuration */
2875+
uint8_t memory[FLASH_RAM_SIZE] = {0};
28712876
whFlashRamsimCtx fc[1] = {0};
28722877
whFlashRamsimCfg fc_conf[1] = {{
2873-
.size = 1024 * 1024, /* 1MB Flash */
2874-
.sectorSize = 128 * 1024, /* 128KB Sector Size */
2875-
.pageSize = 8, /* 8B Page Size */
2878+
.size = FLASH_RAM_SIZE, /* 1MB Flash */
2879+
.sectorSize = FLASH_SECTOR_SIZE, /* 128KB Sector Size */
2880+
.pageSize = FLASH_PAGE_SIZE, /* 8B Page Size */
28762881
.erasedByte = ~(uint8_t)0,
2882+
.memory = memory,
28772883
}};
28782884
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
28792885

test/wh_test_flash_ramsim.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ int whTest_Flash_RamSim(void)
6262
{
6363
int ret;
6464
whFlashRamsimCtx ctx;
65+
uint8_t memory[TEST_FLASH_SIZE] = {0};
6566
whFlashRamsimCfg cfg = {.size = TEST_FLASH_SIZE,
6667
.sectorSize = TEST_SECTOR_SIZE,
6768
.pageSize = TEST_PAGE_SIZE,
6869
.erasedByte = 0xFF,
69-
#ifndef WOLFHSM_CFG_FLASH_RAMSIM_MALLOC
70-
.memory = WOLFHSM_CFG_TEST_FLASH_RAMSIM_MEMORY_ADDR;
71-
#endif
70+
.memory = memory,
7271
};
7372

7473
uint8_t testData[TEST_PAGE_SIZE] = {0};

0 commit comments

Comments
 (0)