aboutsummaryrefslogtreecommitdiff
path: root/projects/cli-test/cli-test.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2019-01-12 18:20:10 -0500
committerPaul Selkirk <paul@psgd.org>2019-01-12 18:20:10 -0500
commit44dc84d3696795fbe0b6f1786cabaa08fd88ade6 (patch)
tree34f3fa7cc69b5f89c4c6cc90d6015b24fe9eba53 /projects/cli-test/cli-test.c
parent07af68c08baefbced001a0081256cb1fff8ed491 (diff)
Timing tests for RSA signing and sub-components thereof.
This is not the sort of thing that should go anywhere near production code, so it's on a dangling branch. I may rebase it from time to time.
Diffstat (limited to 'projects/cli-test/cli-test.c')
-rw-r--r--projects/cli-test/cli-test.c50
1 files changed, 36 insertions, 14 deletions
diff --git a/projects/cli-test/cli-test.c b/projects/cli-test/cli-test.c
index c0fe57e..c50338b 100644
--- a/projects/cli-test/cli-test.c
+++ b/projects/cli-test/cli-test.c
@@ -57,9 +57,18 @@ int
main()
{
stm_init();
-
led_on(LED_GREEN);
+ /* For the hsm, the keystores are initialized in hal_rpc_server_init(),
+ * which is...less than optimal, but this is not the time or place to fix
+ * it, especially in light of all the terrible things I'm doing in this
+ * version of cli-test.
+ */
+ extern void *hal_ks_token, *hal_ks_volatile;
+ extern int hal_ks_init(void *, int);
+ if (hal_ks_init(hal_ks_volatile, 1) != 0 || hal_ks_init(hal_ks_token, 1) != 0)
+ Error_Handler();
+
while (1) {
cli_main();
/* embedded_cli_loop returns when the user enters 'quit' or 'exit' */
@@ -70,23 +79,36 @@ main()
}
-/*
- * Dummy to solve link problem. Not obvious to me that a program
- * called "cli-test" should be duplicating all of the HSM keystore
- * logic, let alone that it should be doing it badly, but, whatever.
- *
- * We could just copy the sdram_malloc() code from hsm.c, but since
- * one of the other commands linked into cli-test goes merrily stomping
- * all over the entire SDRAM chip, that might not work out so well.
- *
- * Issue deferred until somebody cares.
- */
+/* end of variables declared with __attribute__((section(".sdram1"))) */
+extern uint8_t _esdram1 __asm ("_esdram1");
+/* end of SDRAM1 section */
+extern uint8_t __end_sdram1 __asm ("__end_sdram1");
+static uint8_t *sdram_heap = &_esdram1;
-#warning hal_allocate_static_memory() stubbed out in cli-test, see source code
+/* Allocate memory from SDRAM1. */
+static uint8_t *sdram_malloc(size_t size)
+{
+ uint8_t *p = sdram_heap;
+#define pad(n) (((n) + 3) & ~3)
+ size = pad(size);
+
+ if (p + size + sizeof(uint32_t) > &__end_sdram1)
+ return NULL;
+
+ *(uint32_t *)p = (uint32_t)size;
+ p += sizeof(uint32_t);
+
+ sdram_heap += size + sizeof(uint32_t);
+ return p;
+}
+
+/* Implement static memory allocation for libhal over sdram_malloc().
+ * Used in hal_ks_init.
+ */
void *hal_allocate_static_memory(const size_t size)
{
- return NULL;
+ return sdram_malloc(size);
}
int hal_free_static_memory(const void * const ptr)