diff options
Diffstat (limited to 'projects/hsm/mgmt-fpga.c')
-rw-r--r-- | projects/hsm/mgmt-fpga.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/projects/hsm/mgmt-fpga.c b/projects/hsm/mgmt-fpga.c index 06f2a26..af7ba11 100644 --- a/projects/hsm/mgmt-fpga.c +++ b/projects/hsm/mgmt-fpga.c @@ -55,20 +55,31 @@ extern hal_user_t user; static volatile uint32_t dfu_offset = 0; -static int _flash_write_callback(uint8_t *buf, size_t len) +static HAL_StatusTypeDef _flash_write_callback(uint8_t *buf, size_t len) { + HAL_StatusTypeDef res; + 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; + if ((res = fpgacfg_erase_sector(dfu_offset / FPGACFG_SECTOR_SIZE)) != CMSIS_HAL_OK) + return res; - int res = fpgacfg_write_data(dfu_offset, buf, BITSTREAM_UPLOAD_CHUNK_SIZE) == 1; + /* fpgacfg_write_data (a thin wrapper around n25q128_write_data) + * requires the offset and length to be page-aligned. The last chunk + * will be short, so we pad it out to the full chunk size. + */ + len = len; + res = fpgacfg_write_data(dfu_offset, buf, BITSTREAM_UPLOAD_CHUNK_SIZE); dfu_offset += BITSTREAM_UPLOAD_CHUNK_SIZE; return res; } static int cmd_fpga_bitstream_upload(struct cli_def *cli, const char *command, char *argv[], int argc) { + command = command; + argv = argv; + argc = argc; + if (user < HAL_USER_SO) { cli_print(cli, "Permission denied."); return CLI_ERROR; @@ -81,7 +92,7 @@ static int cmd_fpga_bitstream_upload(struct cli_def *cli, const char *command, c fpgacfg_access_control(ALLOW_ARM); cli_print(cli, "Checking if FPGA config memory is accessible"); - if (fpgacfg_check_id() != 1) { + if (fpgacfg_check_id() != CMSIS_HAL_OK) { cli_print(cli, "ERROR: FPGA config memory not accessible. Check that jumpers JP7 and JP8 are installed."); return CLI_ERROR; } @@ -96,10 +107,14 @@ static int cmd_fpga_bitstream_upload(struct cli_def *cli, const char *command, c static int cmd_fpga_bitstream_erase(struct cli_def *cli, const char *command, char *argv[], int argc) { + command = command; + argv = argv; + argc = argc; + fpgacfg_access_control(ALLOW_ARM); cli_print(cli, "Checking if FPGA config memory is accessible"); - if (fpgacfg_check_id() != 1) { + if (fpgacfg_check_id() != CMSIS_HAL_OK) { cli_print(cli, "ERROR: FPGA config memory not accessible. Check that jumpers JP7 and JP8 are installed."); return CLI_ERROR; } @@ -110,7 +125,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_sector(0) != 0) { + if (fpgacfg_erase_sector(0) != CMSIS_HAL_OK) { cli_print(cli, "Erasing first sector in FPGA config memory failed"); return CLI_ERROR; } @@ -123,6 +138,10 @@ static int cmd_fpga_bitstream_erase(struct cli_def *cli, const char *command, ch static int cmd_fpga_reset(struct cli_def *cli, const char *command, char *argv[], int argc) { + command = command; + argv = argv; + argc = argc; + fpgacfg_access_control(ALLOW_FPGA); fpgacfg_reset_fpga(RESET_FULL); hal_core_reset_table(); @@ -136,7 +155,11 @@ static int cmd_fpga_show_cores(struct cli_def *cli, const char *command, char *a hal_core_t *core; const hal_core_info_t *info; - if (! fpgacfg_check_done()) { + command = command; + argv = argv; + argc = argc; + + if (fpgacfg_check_done() != CMSIS_HAL_OK) { cli_print(cli, "FPGA has not loaded a bitstream"); return CLI_OK; } |