aboutsummaryrefslogtreecommitdiff
path: root/projects/cli-test/mgmt-dfu.c
diff options
context:
space:
mode:
Diffstat (limited to 'projects/cli-test/mgmt-dfu.c')
-rw-r--r--projects/cli-test/mgmt-dfu.c44
1 files changed, 29 insertions, 15 deletions
diff --git a/projects/cli-test/mgmt-dfu.c b/projects/cli-test/mgmt-dfu.c
index 27fd722..c7273f4 100644
--- a/projects/cli-test/mgmt-dfu.c
+++ b/projects/cli-test/mgmt-dfu.c
@@ -40,7 +40,10 @@
#include <string.h>
-extern uint32_t update_crc(uint32_t crc, uint8_t *buf, int len);
+#define DFU_FIRMWARE_ADDR ((uint32_t) &CRYPTECH_FIRMWARE_START)
+#define DFU_FIRMWARE_END_ADDR ((uint32_t) &CRYPTECH_FIRMWARE_END)
+#define DFU_UPLOAD_CHUNK_SIZE 256
+#define HARDWARE_EARLY_DFU_JUMP 0xBADABADA
/* Linker symbols are strange in C. Make regular pointers for sanity. */
__IO uint32_t *dfu_control = &CRYPTECH_DFU_CONTROL;
@@ -53,25 +56,29 @@ __IO uint32_t *dfu_msp_ptr = &CRYPTECH_FIRMWARE_START;
*/
__IO uint32_t *dfu_code_ptr = &CRYPTECH_FIRMWARE_START + 1;
-
-
-int cmd_dfu_dump(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_dfu_dump(struct cli_def *cli, const char *command, char *argv[], int argc)
{
+ command = command;
+ argv = argv;
+ argc = argc;
+
cli_print(cli, "First 256 bytes from DFU application address %p:\r\n", dfu_firmware);
- uart_send_hexdump(STM_UART_MGMT, (uint8_t *) dfu_firmware, 0, 0xff);
- uart_send_string2(STM_UART_MGMT, (char *) "\r\n\r\n");
+ uart_send_hexdump((uint8_t *) dfu_firmware, 0, 0xff);
+ cli_print(cli, "\n");
return CLI_OK;
}
-int cmd_dfu_erase(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_dfu_erase(struct cli_def *cli, const char *command, char *argv[], int argc)
{
int status;
- cli_print(cli, "Erasing flash sectors %i to %i (address %p to %p) - expect the CLI to crash now",
- stm_flash_sector_num((uint32_t) dfu_firmware),
- stm_flash_sector_num((uint32_t) dfu_firmware_end),
+ command = command;
+ argv = argv;
+ argc = argc;
+
+ cli_print(cli, "Erasing flash address %p to %p - expect the CLI to crash now",
dfu_firmware,
dfu_firmware_end);
@@ -82,9 +89,14 @@ int cmd_dfu_erase(struct cli_def *cli, const char *command, char *argv[], int ar
return CLI_OK;
}
-int cmd_dfu_jump(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_dfu_jump(struct cli_def *cli, const char *command, char *argv[], int argc)
{
uint32_t i;
+
+ command = command;
+ argv = argv;
+ argc = argc;
+
/* Load first byte from the DFU_FIRMWARE_PTR to verify it contains an IVT before
* jumping there.
*/
@@ -112,9 +124,11 @@ int cmd_dfu_jump(struct cli_def *cli, const char *command, char *argv[], int arg
void configure_cli_dfu(struct cli_def *cli)
{
- cli_command_root(dfu);
+ struct cli_command *c;
+
+ c = cli_register_command(cli, NULL, "dfu", NULL, 0, 0, NULL);
- cli_command_node(dfu, dump, "Show the first 256 bytes of the loaded firmware");
- cli_command_node(dfu, jump, "Jump to the loaded firmware");
- cli_command_node(dfu, erase, "Erase the firmware memory (will crash the CLI)");
+ cli_register_command(cli, c, "dump", cmd_dfu_dump, 0, 0, "Show the first 256 bytes of the loaded firmware");
+ cli_register_command(cli, c, "jump", cmd_dfu_jump, 0, 0, "Jump to the loaded firmware");
+ cli_register_command(cli, c, "erase", cmd_dfu_erase, 0, 0, "Erase the firmware memory (will crash the CLI)");
}