Skip to content

Commit 6420f3b

Browse files
committed
Remove malloc from flash ram sim. Update tests to use stack memory for flash ram sim
1 parent 7c21ba3 commit 6420f3b

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
@@ -607,6 +607,8 @@ int main(int argc, char** argv)
607607
const char* nvmInitFilePath = NULL;
608608
int keyId = WH_KEYID_ERASED; /* Default key ID if none provided */
609609
int clientId = 12; /* Default client ID if none provided */
610+
uint8_t memory[FLASH_RAM_SIZE] = {0};
611+
610612

611613
/* Parse command-line arguments */
612614
for (int i = 1; i < argc; i++) {
@@ -645,6 +647,7 @@ int main(int argc, char** argv)
645647
.sectorSize = FLASH_RAM_SIZE / 2,
646648
.pageSize = 8,
647649
.erasedByte = (uint8_t)0,
650+
.memory = memory,
648651
}};
649652
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
650653

examples/posix/tcp/wh_server_tcp/wolfhsm_cfg.h

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

47-
#define WOLFHSM_CFG_FLASH_RAMSIM_MALLOC
48-
4947
#define XMEMFENCE() __atomic_thread_fence(__ATOMIC_SEQ_CST)
5048

5149
#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
@@ -53,6 +53,10 @@
5353
static int whTest_CertNonExportable(whClientContext* client);
5454
#endif
5555

56+
#define FLASH_RAM_SIZE (1024 * 1024) /* 1MB */
57+
#define FLASH_SECTOR_SIZE (128 * 1024) /* 128KB */
58+
#define FLASH_PAGE_SIZE (8) /* 8B */
59+
5660
#ifdef WOLFHSM_CFG_ENABLE_SERVER
5761
/* Run certificate configuration tests */
5862
int whTest_CertServerCfg(whServerConfig* serverCfg)
@@ -599,12 +603,14 @@ int whTest_CertRamSim(void)
599603
.server_id = 124,
600604
}};
601605
/* RamSim Flash state and configuration */
606+
uint8_t memory[FLASH_RAM_SIZE] = {0};
602607
whFlashRamsimCtx fc[1] = {0};
603608
whFlashRamsimCfg fc_conf[1] = {{
604-
.size = 1024 * 1024, /* 1MB Flash */
605-
.sectorSize = 128 * 1024, /* 128KB Sector Size */
606-
.pageSize = 8, /* 8B Page Size */
609+
.size = FLASH_RAM_SIZE, /* 1MB Flash */
610+
.sectorSize = FLASH_SECTOR_SIZE, /* 128KB Sector Size */
611+
.pageSize = FLASH_PAGE_SIZE, /* 8B Page Size */
607612
.erasedByte = ~(uint8_t)0,
613+
.memory = memory,
608614
}};
609615
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
610616

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
@@ -708,12 +710,14 @@ int whTest_ClientServerSequential(void)
708710
}};
709711

710712
/* RamSim Flash state and configuration */
713+
uint8_t memory[FLASH_RAM_SIZE] = {0};
711714
whFlashRamsimCtx fc[1] = {0};
712715
whFlashRamsimCfg fc_conf[1] = {{
713-
.size = 1024 * 1024, /* 1MB Flash */
714-
.sectorSize = 128 * 1024, /* 128KB Sector Size */
715-
.pageSize = 8, /* 8B Page Size */
716+
.size = FLASH_RAM_SIZE, /* 1MB Flash */
717+
.sectorSize = FLASH_SECTOR_SIZE, /* 128KB Sector Size */
718+
.pageSize = FLASH_PAGE_SIZE, /* 8B Page Size */
716719
.erasedByte = ~(uint8_t)0,
720+
.memory = memory,
717721
}};
718722
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
719723

@@ -1734,12 +1738,14 @@ static int wh_ClientServer_MemThreadTest(void)
17341738
}};
17351739

17361740
/* RamSim Flash state and configuration */
1741+
uint8_t memory[FLASH_RAM_SIZE] = {0};
17371742
whFlashRamsimCtx fc[1] = {0};
17381743
whFlashRamsimCfg fc_conf[1] = {{
17391744
.size = FLASH_RAM_SIZE,
17401745
.sectorSize = FLASH_RAM_SIZE/2,
17411746
.pageSize = 8,
17421747
.erasedByte = (uint8_t)0,
1748+
.memory = memory,
17431749
}};
17441750
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
17451751

@@ -1825,12 +1831,14 @@ static int wh_ClientServer_PosixMemMapThreadTest(void)
18251831
}};
18261832

18271833
/* RamSim Flash state and configuration */
1834+
uint8_t memory[FLASH_RAM_SIZE] = {0};
18281835
whFlashRamsimCtx fc[1] = {0};
18291836
whFlashRamsimCfg fc_conf[1] = {{
18301837
.size = FLASH_RAM_SIZE,
18311838
.sectorSize = FLASH_RAM_SIZE / 2,
18321839
.pageSize = 8,
18331840
.erasedByte = (uint8_t)0,
1841+
.memory = memory,
18341842
}};
18351843
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
18361844

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)
@@ -3028,12 +3032,14 @@ static int wh_ClientServer_MemThreadTest(void)
30283032
}};
30293033

30303034
/* RamSim Flash state and configuration */
3035+
uint8_t memory[FLASH_RAM_SIZE] = {0};
30313036
whFlashRamsimCtx fc[1] = {0};
30323037
whFlashRamsimCfg fc_conf[1] = {{
3033-
.size = 1024 * 1024, /* 1MB Flash */
3034-
.sectorSize = 128 * 1024, /* 128KB Sector Size */
3035-
.pageSize = 8, /* 8B Page Size */
3038+
.size = FLASH_RAM_SIZE, /* 1MB Flash */
3039+
.sectorSize = FLASH_SECTOR_SIZE, /* 128KB Sector Size */
3040+
.pageSize = FLASH_PAGE_SIZE, /* 8B Page Size */
30363041
.erasedByte = ~(uint8_t)0,
3042+
.memory = memory,
30373043
}};
30383044
const whFlashCb fcb[1] = {WH_FLASH_RAMSIM_CB};
30393045

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)