aboutsummaryrefslogtreecommitdiff
path: root/projects/hsm/mgmt-bootloader.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2016-07-10 22:51:47 -0400
committerPaul Selkirk <paul@psgd.org>2016-07-10 22:51:47 -0400
commit26a343971eb6f0e6e055441df353e60e81cf3595 (patch)
tree65e05394ff9807a9e709ce55e63ab46416d3067a /projects/hsm/mgmt-bootloader.c
parent708103998b7005c51fd78fc5563e46dd93fee283 (diff)
Sign/verifiy installable imagesparade_of_half_baked_ideas
Receive the image into sdram, verify the signature before copying to flash. It would be great if worked...
Diffstat (limited to 'projects/hsm/mgmt-bootloader.c')
-rw-r--r--projects/hsm/mgmt-bootloader.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/projects/hsm/mgmt-bootloader.c b/projects/hsm/mgmt-bootloader.c
index d2d7ffe..68a0b38 100644
--- a/projects/hsm/mgmt-bootloader.c
+++ b/projects/hsm/mgmt-bootloader.c
@@ -38,6 +38,7 @@
#include "stm-uart.h"
#include "stm-flash.h"
#include "stm-fpgacfg.h"
+#include "sdram-malloc.h"
#include "mgmt-cli.h"
#include "mgmt-misc.h"
@@ -50,15 +51,6 @@
extern hal_user_t user;
-static uint32_t dfu_offset;
-
-static int _flash_write_callback(uint8_t *buf, size_t len)
-{
- stm_flash_write32(dfu_offset, (uint32_t *)buf, sizeof(buf)/4);
- dfu_offset += DFU_UPLOAD_CHUNK_SIZE;
- return 1;
-}
-
static int cmd_bootloader_upload(struct cli_def *cli, const char *command, char *argv[], int argc)
{
if (user < HAL_USER_SO) {
@@ -78,13 +70,24 @@ static int cmd_bootloader_upload(struct cli_def *cli, const char *command, char
return CLI_ERROR;
}
- uint8_t buf[DFU_UPLOAD_CHUNK_SIZE];
- dfu_offset = DFU_BOOTLOADER_ADDR;
+ uint8_t *filebuf;
+ size_t file_len;
- cli_receive_data(cli, buf, sizeof(buf), _flash_write_callback);
+ if (cli_receive_data(cli, &filebuf, &file_len, DFU_UPLOAD_CHUNK_SIZE) == CLI_ERROR)
+ return CLI_ERROR;
- cli_print(cli, "DFU offset now: %li (%li chunks)", dfu_offset, dfu_offset / DFU_UPLOAD_CHUNK_SIZE);
- return CLI_OK;
+ cli_print(cli, "Writing flash");
+ int res = stm_flash_write32(DFU_BOOTLOADER_ADDR, (uint32_t *)filebuf, file_len/4) == 1;
+ sdram_free(filebuf);
+
+ if (res) {
+ cli_print(cli, "SUCCESS");
+ return CLI_OK;
+ }
+ else {
+ cli_print(cli, "FAIL");
+ return CLI_ERROR;
+ }
}
void configure_cli_bootloader(struct cli_def *cli)