aboutsummaryrefslogtreecommitdiff
path: root/projects/hsm
diff options
context:
space:
mode:
Diffstat (limited to 'projects/hsm')
-rw-r--r--projects/hsm/Makefile20
-rw-r--r--projects/hsm/hsm.c10
-rw-r--r--projects/hsm/mgmt-misc.c38
-rw-r--r--projects/hsm/mgmt-task.c44
4 files changed, 108 insertions, 4 deletions
diff --git a/projects/hsm/Makefile b/projects/hsm/Makefile
index 927c9f1..3430e14 100644
--- a/projects/hsm/Makefile
+++ b/projects/hsm/Makefile
@@ -9,9 +9,8 @@ OBJS = mgmt-cli.o \
mgmt-masterkey.o \
mgmt-misc.o \
mgmt-task.o \
- log.o
-
-BOARD_OBJS += $(TOPLEVEL)/task.o
+ log.o \
+ $(TOPLEVEL)/task.o
CFLAGS += -DNUM_RPC_TASK=4
@@ -21,10 +20,23 @@ CFLAGS += -I$(LIBCLI_SRC)
LIBS += $(LIBHAL_BLD)/libhal.a $(LIBTFM_BLD)/libtfm.a
LIBS += $(LIBCLI_BLD)/libcli.a
+LDFLAGS += -mcpu=cortex-m4 -mthumb -mlittle-endian -mthumb-interwork
+LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
+LDFLAGS += -Wl,--gc-sections
+
+ifdef DO_PROFILING
+OBJS += $(TOPLEVEL)/memfunc.o
+LDFLAGS += --specs=rdimon.specs -lc -lrdimon
+endif
+
+ifdef DO_TASK_METRICS
+CFLAGS += -DDO_TASK_METRICS
+endif
+
all: $(PROJ:=.elf)
%.elf: %.o $(BOARD_OBJS) $(OBJS) $(LIBS)
- $(CC) $(CFLAGS) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map
+ $(CC) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map $(LDFLAGS)
$(OBJCOPY) -O binary $*.elf $*.bin
$(SIZE) $*.elf
diff --git a/projects/hsm/hsm.c b/projects/hsm/hsm.c
index 7fc7410..f20ee64 100644
--- a/projects/hsm/hsm.c
+++ b/projects/hsm/hsm.c
@@ -268,6 +268,11 @@ size_t uart_rx_max = 0;
void HAL_SYSTICK_Callback(void)
{
+#ifdef DO_PROFILING
+ extern void profil_callback(void);
+ profil_callback();
+#endif
+
size_t count = RINGBUF_COUNT(uart_ringbuf);
if (uart_rx_max < count) uart_rx_max = count;
@@ -393,6 +398,11 @@ void hal_task_yield(void)
task_yield();
}
+void hal_task_yield_maybe(void)
+{
+ task_yield_maybe();
+}
+
/* A mutex to arbitrate concurrent access to the keystore.
*/
task_mutex_t ks_mutex = { 0 };
diff --git a/projects/hsm/mgmt-misc.c b/projects/hsm/mgmt-misc.c
index b06003f..86f1be8 100644
--- a/projects/hsm/mgmt-misc.c
+++ b/projects/hsm/mgmt-misc.c
@@ -113,6 +113,35 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal
return CLI_ERROR;
}
+#ifdef DO_PROFILING
+static int cmd_profile_start(struct cli_def *cli, const char *command, char *argv[], int argc)
+{
+ cli = cli;
+ command = command;
+ argv = argv;
+ argc = argc;
+
+ extern uint32_t CRYPTECH_FIRMWARE_START;
+ extern char __etext; /* end of text/code symbol, defined by linker */
+ extern void monstartup (size_t lowpc, size_t highpc);
+ monstartup((size_t)&CRYPTECH_FIRMWARE_START, (size_t)&__etext);
+ return CLI_OK;
+}
+
+static int cmd_profile_stop(struct cli_def *cli, const char *command, char *argv[], int argc)
+{
+ cli = cli;
+ command = command;
+ argv = argv;
+ argc = argc;
+
+ extern void _mcleanup(void);
+ _mcleanup();
+ return CLI_OK;
+}
+
+#endif
+
static int cmd_reboot(struct cli_def *cli, const char *command, char *argv[], int argc)
{
command = command;
@@ -128,6 +157,15 @@ static int cmd_reboot(struct cli_def *cli, const char *command, char *argv[], in
void configure_cli_misc(struct cli_def *cli)
{
+#ifdef DO_PROFILING
+ struct cli_command *c_profile = cli_register_command(cli, NULL, "profile", NULL, 0, 0, NULL);
+
+ /* profile start */
+ cli_register_command(cli, c_profile, "start", cmd_profile_start, 0, 0, "Start collecting profiling data");
+
+ /* profile stop */
+ cli_register_command(cli, c_profile, "stop", cmd_profile_stop, 0, 0, "Stop collecting profiling data");
+#endif
/* reboot */
cli_register_command(cli, NULL, "reboot", cmd_reboot, 0, 0, "Reboot the STM32");
}
diff --git a/projects/hsm/mgmt-task.c b/projects/hsm/mgmt-task.c
index beffc32..c2a3d3f 100644
--- a/projects/hsm/mgmt-task.c
+++ b/projects/hsm/mgmt-task.c
@@ -77,10 +77,54 @@ static int cmd_task_show(struct cli_def *cli, const char *command, char *argv[],
return CLI_OK;
}
+#ifdef DO_TASK_METRICS
+static int cmd_task_show_metrics(struct cli_def *cli, const char *command, char *argv[], int argc)
+{
+ command = command;
+ argv = argv;
+ argc = argc;
+
+ struct task_metrics tm;
+
+ task_get_metrics(&tm);
+
+ cli_print(cli, "avg time between yields: %ld.%06ld sec", tm.avg.tv_sec, tm.avg.tv_usec);
+ cli_print(cli, "max time between yields: %ld.%06ld sec", tm.max.tv_sec, tm.max.tv_usec);
+
+ return CLI_OK;
+}
+
+static int cmd_task_reset_metrics(struct cli_def *cli, const char *command, char *argv[], int argc)
+{
+ cli = cli;
+ command = command;
+ argv = argv;
+ argc = argc;
+
+ task_reset_metrics();
+
+ return CLI_OK;
+}
+#endif
+
void configure_cli_task(struct cli_def *cli)
{
struct cli_command *c = cli_register_command(cli, NULL, "task", NULL, 0, 0, NULL);
/* task show */
+#ifdef DO_TASK_METRICS
+ struct cli_command *c_show =
+#endif
cli_register_command(cli, c, "show", cmd_task_show, 0, 0, "Show the active tasks");
+
+#ifdef DO_TASK_METRICS
+ /* task show metrics */
+ cli_register_command(cli, c_show, "metrics", cmd_task_show_metrics, 0, 0, "Show task metrics");
+
+ /* task reset */
+ struct cli_command *c_reset = cli_register_command(cli, c, "reset", NULL, 0, 0, NULL);
+
+ /* task reset metrics */
+ cli_register_command(cli, c_reset, "metrics", cmd_task_reset_metrics, 0, 0, "Reset task metrics");
+#endif
}