From 189df371631a2b7bef91803d449e47470ad6a7bf Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Wed, 22 Feb 2017 14:11:12 -0500 Subject: Refactor flash code. --- projects/cli-test/mgmt-dfu.c | 4 +--- projects/cli-test/mgmt-fpga.c | 10 ++++++++-- projects/cli-test/mgmt-keystore.c | 2 +- projects/cli-test/mgmt-show.c | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) (limited to 'projects/cli-test') diff --git a/projects/cli-test/mgmt-dfu.c b/projects/cli-test/mgmt-dfu.c index 8f258ea..851c8ea 100644 --- a/projects/cli-test/mgmt-dfu.c +++ b/projects/cli-test/mgmt-dfu.c @@ -72,9 +72,7 @@ static int cmd_dfu_erase(struct cli_def *cli, const char *command, char *argv[], { 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), + cli_print(cli, "Erasing flash address %p to %p - expect the CLI to crash now", dfu_firmware, dfu_firmware_end); diff --git a/projects/cli-test/mgmt-fpga.c b/projects/cli-test/mgmt-fpga.c index 31a6e27..b1b0973 100644 --- a/projects/cli-test/mgmt-fpga.c +++ b/projects/cli-test/mgmt-fpga.c @@ -47,7 +47,13 @@ static volatile uint32_t dfu_offset = 0; -static int _flash_write_callback(uint8_t *buf, size_t len) { +static int _flash_write_callback(uint8_t *buf, size_t len) +{ + if ((dfu_offset % FPGACFG_SECTOR_SIZE) == 0) + /* first page in sector, need to erase sector */ + if (fpgacfg_erase_sector(dfu_offset / FPGACFG_SECTOR_SIZE) != 1) + return CLI_ERROR; + int res = fpgacfg_write_data(dfu_offset, buf, BITSTREAM_UPLOAD_CHUNK_SIZE) == 1; dfu_offset += BITSTREAM_UPLOAD_CHUNK_SIZE; return res; @@ -91,7 +97,7 @@ static int cmd_fpga_bitstream_erase(struct cli_def *cli, const char *command, ch * * This command could be made to accept an argument indicating the whole memory should be erased. */ - if (! fpgacfg_erase_sectors(1)) { + if (fpgacfg_erase_sector(0) != 0) { cli_print(cli, "Erasing first sector in FPGA config memory failed"); return CLI_ERROR; } diff --git a/projects/cli-test/mgmt-keystore.c b/projects/cli-test/mgmt-keystore.c index 457abc2..09d512e 100644 --- a/projects/cli-test/mgmt-keystore.c +++ b/projects/cli-test/mgmt-keystore.c @@ -334,7 +334,7 @@ static int cmd_keystore_erase(struct cli_def *cli, const char *command, char *ar } cli_print(cli, "OK, erasing keystore, this might take a while..."); - if ((status = keystore_erase_sectors(0, KEYSTORE_NUM_SECTORS - 1)) != 1) { + if ((status = keystore_erase_bulk()) != 1) { cli_print(cli, "Failed erasing token keystore: %i", status); return CLI_ERROR; } diff --git a/projects/cli-test/mgmt-show.c b/projects/cli-test/mgmt-show.c index 5cca8b7..f124830 100644 --- a/projects/cli-test/mgmt-show.c +++ b/projects/cli-test/mgmt-show.c @@ -132,7 +132,7 @@ static int cmd_show_keystore_data(struct cli_def *cli, const char *command, char } } else { cli_print(cli, "Erasing first sector since all the first 8 bytes are tombstones"); - if ((i = keystore_erase_sectors(1, 1)) != 1) { + if ((i = keystore_erase_sector(0)) != 1) { cli_print(cli, "Failed erasing the first sector: %li", i); return CLI_ERROR; } -- cgit v1.2.3