From 5af4a915edf3e77705fa2625081200b61f8dda26 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Sun, 15 Oct 2017 21:34:00 -0400 Subject: Cleanup: All drivers return HAL_StatusTypeDef rather than magic values. Note: This affects libhal/ks_token.c, which uses the keystore driver directly. --- projects/board-test/keystore-perf.c | 22 +++++++++++----------- projects/board-test/spiflash-perf.c | 16 ++++++++-------- projects/cli-test/mgmt-fpga.c | 16 +++++++++------- projects/cli-test/mgmt-keystore.c | 6 +++--- projects/cli-test/mgmt-misc.c | 6 +++--- projects/cli-test/mgmt-misc.h | 2 +- projects/cli-test/mgmt-show.c | 14 +++++++------- projects/cli-test/test-mkmif.c | 32 ++++++++++++++++---------------- projects/hsm/mgmt-bootloader.c | 7 +++---- projects/hsm/mgmt-firmware.c | 1 - projects/hsm/mgmt-fpga.c | 18 ++++++++++-------- projects/hsm/mgmt-keystore.c | 4 ++-- projects/hsm/mgmt-misc.c | 2 +- projects/hsm/mgmt-misc.h | 3 ++- 14 files changed, 76 insertions(+), 73 deletions(-) (limited to 'projects') diff --git a/projects/board-test/keystore-perf.c b/projects/board-test/keystore-perf.c index 09528a2..3552d30 100644 --- a/projects/board-test/keystore-perf.c +++ b/projects/board-test/keystore-perf.c @@ -16,11 +16,11 @@ static void test_read_data(void) { uint8_t read_buf[KEYSTORE_SUBSECTOR_SIZE]; uint32_t i; - int err; + HAL_StatusTypeDef err; for (i = 0; i < KEYSTORE_NUM_SUBSECTORS; ++i) { err = keystore_read_data(i * KEYSTORE_SUBSECTOR_SIZE, read_buf, KEYSTORE_SUBSECTOR_SIZE); - if (err != 1) { + if (err != HAL_OK) { uart_send_string("ERROR: keystore_read_data returned "); uart_send_integer(err, 0); uart_send_string("\r\n"); @@ -36,11 +36,11 @@ static void _read_verify(uint8_t *vrfy_buf) { uint8_t read_buf[KEYSTORE_SUBSECTOR_SIZE]; uint32_t i; - int err; + HAL_StatusTypeDef err; for (i = 0; i < KEYSTORE_NUM_SUBSECTORS; ++i) { err = keystore_read_data(i * KEYSTORE_SUBSECTOR_SIZE, read_buf, KEYSTORE_SUBSECTOR_SIZE); - if (err != 1) { + if (err != HAL_OK) { uart_send_string("ERROR: keystore_read_data returned "); uart_send_integer(err, 0); uart_send_string("\r\n"); @@ -61,11 +61,11 @@ static void _read_verify(uint8_t *vrfy_buf) static void test_erase_sector(void) { uint32_t i; - int err; + HAL_StatusTypeDef err; for (i = 0; i < KEYSTORE_NUM_SECTORS; ++i) { err = keystore_erase_sector(i); - if (err != 1) { + if (err != HAL_OK) { uart_send_string("ERROR: keystore_erase_sector returned "); uart_send_integer(err, 0); uart_send_string("\r\n"); @@ -80,11 +80,11 @@ static void test_erase_sector(void) static void test_erase_subsector(void) { uint32_t i; - int err; + HAL_StatusTypeDef err; for (i = 0; i < KEYSTORE_NUM_SUBSECTORS; ++i) { err = keystore_erase_subsector(i); - if (err != 1) { + if (err != HAL_OK) { uart_send_string("ERROR: keystore_erase_subsector returned "); uart_send_integer(err, 0); uart_send_string("\r\n"); @@ -114,14 +114,14 @@ static void test_write_data(void) { uint8_t write_buf[KEYSTORE_SUBSECTOR_SIZE]; uint32_t i; - int err; + HAL_StatusTypeDef err; for (i = 0; i < sizeof(write_buf); ++i) write_buf[i] = i & 0xFF; for (i = 0; i < KEYSTORE_NUM_SUBSECTORS; ++i) { err = keystore_write_data(i * KEYSTORE_SUBSECTOR_SIZE, write_buf, KEYSTORE_SUBSECTOR_SIZE); - if (err != 1) { + if (err != HAL_OK) { uart_send_string("ERROR: keystore_write_data returned "); uart_send_integer(err, 0); uart_send_string(" for subsector "); @@ -179,7 +179,7 @@ int main(void) stm_init(); uart_set_default(STM_UART_MGMT); - if (keystore_check_id() != 1) { + if (keystore_check_id() != HAL_OK) { uart_send_string("ERROR: keystore_check_id failed\r\n"); return 0; } diff --git a/projects/board-test/spiflash-perf.c b/projects/board-test/spiflash-perf.c index 53f29cb..2691504 100644 --- a/projects/board-test/spiflash-perf.c +++ b/projects/board-test/spiflash-perf.c @@ -33,7 +33,7 @@ static void test_read_page(void) for (i = 0; i < N25Q128_NUM_PAGES; ++i) { err = n25q128_read_page(ctx, i, read_buf); - if (err != 1) { + if (err != HAL_OK) { uart_send_string("ERROR: n25q128_read_page returned "); uart_send_integer(err, 0); uart_send_string("\r\n"); @@ -53,7 +53,7 @@ static void test_read_subsector(void) for (i = 0; i < N25Q128_NUM_SUBSECTORS; ++i) { err = n25q128_read_subsector(ctx, i, read_buf); - if (err != 1) { + if (err != HAL_OK) { uart_send_string("ERROR: n25q128_read_subsector returned "); uart_send_integer(err, 0); uart_send_string("\r\n"); @@ -75,7 +75,7 @@ static void _read_verify(uint8_t *vrfy_buf) for (i = 0; i < N25Q128_NUM_PAGES; ++i) { err = n25q128_read_page(ctx, i, read_buf); - if (err != 1) { + if (err != HAL_OK) { uart_send_string("ERROR: n25q128_read_page returned "); uart_send_integer(err, 0); uart_send_string("\r\n"); @@ -100,7 +100,7 @@ static void test_erase_sector(void) for (i = 0; i < N25Q128_NUM_SECTORS; ++i) { err = n25q128_erase_sector(ctx, i); - if (err != 1) { + if (err != HAL_OK) { uart_send_string("ERROR: n25q128_erase_sector returned "); uart_send_integer(err, 0); uart_send_string("\r\n"); @@ -119,7 +119,7 @@ static void test_erase_subsector(void) for (i = 0; i < N25Q128_NUM_SUBSECTORS; ++i) { err = n25q128_erase_subsector(ctx, i); - if (err != 1) { + if (err != HAL_OK) { uart_send_string("ERROR: n25q128_erase_subsector returned "); uart_send_integer(err, 0); uart_send_string("\r\n"); @@ -136,7 +136,7 @@ static void test_erase_bulk(void) int err; err = n25q128_erase_bulk(ctx); - if (err != 1) { + if (err != HAL_OK) { uart_send_string("ERROR: n25q128_erase_bulk returned "); uart_send_integer(err, 0); uart_send_string("\r\n"); @@ -171,7 +171,7 @@ static void test_write_page(void) for (i = 0; i < N25Q128_NUM_PAGES; ++i) { err = n25q128_write_page(ctx, i, write_buf); - if (err != 1) { + if (err != HAL_OK) { uart_send_string("ERROR: n25q128_write_page returned "); uart_send_integer(err, 0); uart_send_string(" for page "); @@ -229,7 +229,7 @@ int main(void) stm_init(); uart_set_default(STM_UART_MGMT); - if (n25q128_check_id(ctx) != 1) { + if (n25q128_check_id(ctx) != HAL_OK) { uart_send_string("ERROR: n25q128_check_id failed\r\n"); return 0; } diff --git a/projects/cli-test/mgmt-fpga.c b/projects/cli-test/mgmt-fpga.c index da539f1..a307436 100644 --- a/projects/cli-test/mgmt-fpga.c +++ b/projects/cli-test/mgmt-fpga.c @@ -47,14 +47,16 @@ 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)) != HAL_OK) + return res; - int res = fpgacfg_write_data(dfu_offset, buf, len) == 1; + res = fpgacfg_write_data(dfu_offset, buf, len); dfu_offset += len; return res; } @@ -72,7 +74,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() != HAL_OK) { cli_print(cli, "ERROR: FPGA config memory not accessible. Check that jumpers JP7 and JP8 are installed."); return CLI_ERROR; } @@ -94,7 +96,7 @@ static int cmd_fpga_bitstream_erase(struct cli_def *cli, const char *command, ch fpgacfg_access_control(ALLOW_ARM); cli_print(cli, "Checking if FPGA config memory is accessible"); - if (fpgacfg_check_id() != 1) { + if (fpgacfg_check_id() != HAL_OK) { cli_print(cli, "ERROR: FPGA config memory not accessible. Check that jumpers JP7 and JP8 are installed."); return CLI_ERROR; } @@ -105,7 +107,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) != HAL_OK) { 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 ea1f263..8c16f35 100644 --- a/projects/cli-test/mgmt-keystore.c +++ b/projects/cli-test/mgmt-keystore.c @@ -228,12 +228,12 @@ static int cmd_keystore_show_data(struct cli_def *cli, const char *command, char argv = argv; argc = argc; - if (keystore_check_id() != 1) { + if (keystore_check_id() != CMSIS_HAL_OK) { cli_print(cli, "ERROR: The keystore memory is not accessible."); } memset(buf, 0, sizeof(buf)); - if ((i = keystore_read_data(0, buf, sizeof(buf))) != 1) { + if ((i = keystore_read_data(0, buf, sizeof(buf))) != CMSIS_HAL_OK) { cli_print(cli, "Failed reading first page from keystore memory: %li", i); return CLI_ERROR; } @@ -355,7 +355,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_bulk()) != 1) { + if ((status = keystore_erase_bulk()) != CMSIS_HAL_OK) { cli_print(cli, "Failed erasing token keystore: %i", status); return CLI_ERROR; } diff --git a/projects/cli-test/mgmt-misc.c b/projects/cli-test/mgmt-misc.c index 4be9a4b..1216bd5 100644 --- a/projects/cli-test/mgmt-misc.c +++ b/projects/cli-test/mgmt-misc.c @@ -49,9 +49,9 @@ static volatile hal_crc32_t demo_crc; -static int _count_bytes_callback(uint8_t *buf, size_t len) { +static HAL_StatusTypeDef _count_bytes_callback(uint8_t *buf, size_t len) { demo_crc = hal_crc32_update(demo_crc, buf, len); - return 1; + return CMSIS_HAL_OK; } int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_callback data_callback) @@ -92,7 +92,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal /* After reception of a chunk but before ACKing we have "all" the time in the world to * calculate CRC and invoke the data_callback. */ - if (data_callback != NULL && ! data_callback(buf, (size_t) n)) { + if (data_callback != NULL && data_callback(buf, n) != CMSIS_HAL_OK) { cli_print(cli, "Data processing failed"); goto fail; } diff --git a/projects/cli-test/mgmt-misc.h b/projects/cli-test/mgmt-misc.h index c549f63..c0581c9 100644 --- a/projects/cli-test/mgmt-misc.h +++ b/projects/cli-test/mgmt-misc.h @@ -39,7 +39,7 @@ #define FILETRANSFER_UPLOAD_CHUNK_SIZE 256 -typedef int (*cli_data_callback)(uint8_t *, size_t); +typedef HAL_StatusTypeDef (*cli_data_callback)(uint8_t *, size_t); extern int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_callback data_callback); diff --git a/projects/cli-test/mgmt-show.c b/projects/cli-test/mgmt-show.c index e829744..e276b15 100644 --- a/projects/cli-test/mgmt-show.c +++ b/projects/cli-test/mgmt-show.c @@ -73,7 +73,7 @@ static int cmd_show_fpga_status(struct cli_def *cli, const char *command, char * argv = argv; argc = argc; - cli_print(cli, "FPGA has %sloaded a bitstream", fpgacfg_check_done() ? "":"NOT "); + cli_print(cli, "FPGA has %sloaded a bitstream", (fpgacfg_check_done() == CMSIS_HAL_OK) ? "":"NOT "); return CLI_OK; } @@ -86,7 +86,7 @@ static int cmd_show_fpga_cores(struct cli_def *cli, const char *command, char *a argv = argv; argc = argc; - if (! fpgacfg_check_done()) { + if (fpgacfg_check_done() != CMSIS_HAL_OK) { cli_print(cli, "FPGA has not loaded a bitstream"); return CLI_OK; } @@ -106,7 +106,7 @@ static int cmd_show_keystore_status(struct cli_def *cli, const char *command, ch argv = argv; argc = argc; - cli_print(cli, "Keystore memory is %sonline", (keystore_check_id() != 1) ? "NOT ":""); + cli_print(cli, "Keystore memory is %sonline", (keystore_check_id() == CMSIS_HAL_OK) ? "":"NOT "); return CLI_OK; } @@ -119,12 +119,12 @@ static int cmd_show_keystore_data(struct cli_def *cli, const char *command, char argv = argv; argc = argc; - if (keystore_check_id() != 1) { + if (keystore_check_id() != CMSIS_HAL_OK) { cli_print(cli, "ERROR: The keystore memory is not accessible."); } memset(buf, 0, sizeof(buf)); - if ((i = keystore_read_data(0, buf, sizeof(buf))) != 1) { + if ((i = keystore_read_data(0, buf, sizeof(buf))) != CMSIS_HAL_OK) { cli_print(cli, "Failed reading first page from keystore memory: %li", i); return CLI_ERROR; } @@ -145,14 +145,14 @@ static int cmd_show_keystore_data(struct cli_def *cli, const char *command, char if (buf[i] == 0xff) { cli_print(cli, "Tombstoning byte %li", i); buf[i] = 0x55; - if ((i = keystore_write_data(0, buf, sizeof(buf))) != 1) { + if ((i = keystore_write_data(0, buf, sizeof(buf))) != CMSIS_HAL_OK) { cli_print(cli, "Failed writing data at offset 0: %li", i); return CLI_ERROR; } } } else { cli_print(cli, "Erasing first sector since all the first 8 bytes are tombstones"); - if ((i = keystore_erase_sector(0)) != 1) { + if ((i = keystore_erase_sector(0)) != CMSIS_HAL_OK) { cli_print(cli, "Failed erasing the first sector: %li", i); return CLI_ERROR; } diff --git a/projects/cli-test/test-mkmif.c b/projects/cli-test/test-mkmif.c index 6321dde..cd71040 100644 --- a/projects/cli-test/test-mkmif.c +++ b/projects/cli-test/test-mkmif.c @@ -32,18 +32,18 @@ static hal_error_t sclk_test(struct cli_def *cli, hal_core_t *core, const uint32 uint32_t readback; hal_error_t err; - cli_print(cli, "Trying to adjust the clockspeed (divisor %x).\n", (unsigned int) divisor); + cli_print(cli, "Trying to adjust the clockspeed (divisor %x).", (unsigned int) divisor); if ((err = hal_mkmif_set_clockspeed(core, divisor)) != LIBHAL_OK) { - cli_print(cli, "hal_mkmif_set_clockspeed: %s\n", hal_error_string(err)); + cli_print(cli, "hal_mkmif_set_clockspeed: %s", hal_error_string(err)); return err; } if ((err = hal_mkmif_get_clockspeed(core, &readback)) != LIBHAL_OK) { - cli_print(cli, "hal_mkmif_get_clockspeed: %s\n", hal_error_string(err)); + cli_print(cli, "hal_mkmif_get_clockspeed: %s", hal_error_string(err)); return err; } if (readback != divisor) { - cli_print(cli, "expected %x, got %x\n", (unsigned int)divisor, (unsigned int)readback); + cli_print(cli, "expected %x, got %x", (unsigned int)divisor, (unsigned int)readback); return HAL_ERROR_IO_UNEXPECTED; } return LIBHAL_OK; @@ -53,10 +53,10 @@ static hal_error_t init_test(struct cli_def *cli, hal_core_t *core) { hal_error_t err; - cli_print(cli, "Trying to init to the memory in continuous mode.\n"); + cli_print(cli, "Trying to init to the memory in continuous mode."); if ((err = hal_mkmif_init(core)) != LIBHAL_OK) { - cli_print(cli, "hal_mkmif_init: %s\n", hal_error_string(err)); + cli_print(cli, "hal_mkmif_init: %s", hal_error_string(err)); return err; } @@ -74,11 +74,11 @@ static hal_error_t write_test(struct cli_def *cli, hal_core_t *core) i < 0x10; write_data += 0x01010101, write_address += 4, ++i) { - cli_print(cli, "Trying to write 0x%08x to memory address 0x%08x.\n", + cli_print(cli, "Trying to write 0x%08x to memory address 0x%08x.", (unsigned int)write_data, (unsigned int)write_address); if ((err = hal_mkmif_write_word(core, write_address, write_data)) != LIBHAL_OK) { - cli_print(cli, "hal_mkmif_write: %s\n", hal_error_string(err)); + cli_print(cli, "hal_mkmif_write: %s", hal_error_string(err)); return err; } } @@ -97,13 +97,13 @@ static hal_error_t read_test(struct cli_def *cli, hal_core_t *core) i < 0x10; read_address += 4, ++i) { - cli_print(cli, "Trying to read from memory address 0x%08x.\n", (unsigned int)read_address); + cli_print(cli, "Trying to read from memory address 0x%08x.", (unsigned int)read_address); if ((err = hal_mkmif_read_word(core, read_address, &read_data)) != LIBHAL_OK) { - cli_print(cli, "hal_mkmif_read: %s\n", hal_error_string(err)); + cli_print(cli, "hal_mkmif_read: %s", hal_error_string(err)); return err; } - cli_print(cli, "Data read: 0x%08x\n", (unsigned int)read_data); + cli_print(cli, "Data read: 0x%08x", (unsigned int)read_data); } return LIBHAL_OK; @@ -115,22 +115,22 @@ static hal_error_t write_read_test(struct cli_def *cli, hal_core_t *core) uint32_t readback; hal_error_t err; - cli_print(cli, "Trying to write 0xdeadbeef to the memory and then read back.\n"); + cli_print(cli, "Trying to write 0xdeadbeef to the memory and then read back."); data = 0xdeadbeef; if ((err = hal_mkmif_write_word(core, 0x00000000, data)) != LIBHAL_OK) { - cli_print(cli, "write error: %s\n", hal_error_string(err)); + cli_print(cli, "write error: %s", hal_error_string(err)); return err; } if ((err = hal_mkmif_read_word(core, 0x00000000, &readback)) != LIBHAL_OK) { - cli_print(cli, "read error: %s\n", hal_error_string(err)); + cli_print(cli, "read error: %s", hal_error_string(err)); return err; } if (readback != data) { - cli_print(cli, "read %08x, expected %08x\n", (unsigned int)readback, (unsigned int)data); + cli_print(cli, "read %08x, expected %08x", (unsigned int)readback, (unsigned int)data); return HAL_ERROR_IO_UNEXPECTED; } @@ -147,7 +147,7 @@ int cmd_test_mkmif(struct cli_def *cli, const char *command, char *argv[], int a argc = argc; if (core == NULL) { - cli_print(cli, "MKMIF core not present, not testing.\n"); + cli_print(cli, "MKMIF core not present, not testing."); return HAL_ERROR_CORE_NOT_FOUND; } diff --git a/projects/hsm/mgmt-bootloader.c b/projects/hsm/mgmt-bootloader.c index ce24560..1d8b8ad 100644 --- a/projects/hsm/mgmt-bootloader.c +++ b/projects/hsm/mgmt-bootloader.c @@ -50,12 +50,11 @@ extern hal_user_t user; static uint32_t dfu_offset; -static int _flash_write_callback(uint8_t *buf, size_t len) +static HAL_StatusTypeDef _flash_write_callback(uint8_t *buf, size_t len) { - if (stm_flash_write32(dfu_offset, (uint32_t *)buf, (uint32_t)len/4) != 1) - return 0; + HAL_StatusTypeDef status = stm_flash_write32(dfu_offset, (uint32_t *)buf, len/4); dfu_offset += DFU_UPLOAD_CHUNK_SIZE; - return 1; + return status; } static int cmd_bootloader_upload(struct cli_def *cli, const char *command, char *argv[], int argc) diff --git a/projects/hsm/mgmt-firmware.c b/projects/hsm/mgmt-firmware.c index 85eb78b..b6b3321 100644 --- a/projects/hsm/mgmt-firmware.c +++ b/projects/hsm/mgmt-firmware.c @@ -36,7 +36,6 @@ #define HAL_OK CMSIS_HAL_OK #include "stm-init.h" #include "stm-uart.h" -#include "stm-flash.h" #include "mgmt-cli.h" diff --git a/projects/hsm/mgmt-fpga.c b/projects/hsm/mgmt-fpga.c index f6c6f20..b535b1d 100644 --- a/projects/hsm/mgmt-fpga.c +++ b/projects/hsm/mgmt-fpga.c @@ -55,14 +55,16 @@ 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, len) == 1; + res = fpgacfg_write_data(dfu_offset, buf, len); dfu_offset += len; return res; } @@ -85,7 +87,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; } @@ -107,7 +109,7 @@ static int cmd_fpga_bitstream_erase(struct cli_def *cli, const char *command, ch 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; } @@ -118,7 +120,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; } @@ -152,7 +154,7 @@ static int cmd_fpga_show_cores(struct cli_def *cli, const char *command, char *a argv = argv; argc = argc; - if (! fpgacfg_check_done()) { + if (fpgacfg_check_done() != CMSIS_HAL_OK) { cli_print(cli, "FPGA has not loaded a bitstream"); return CLI_OK; } diff --git a/projects/hsm/mgmt-keystore.c b/projects/hsm/mgmt-keystore.c index 100c428..b79a5fe 100644 --- a/projects/hsm/mgmt-keystore.c +++ b/projects/hsm/mgmt-keystore.c @@ -303,7 +303,7 @@ static int cmd_keystore_show_keys(struct cli_def *cli, const char *command, char static int cmd_keystore_erase(struct cli_def *cli, const char *command, char *argv[], int argc) { hal_error_t err; - int status; + HAL_StatusTypeDef status; command = command; @@ -313,7 +313,7 @@ static int cmd_keystore_erase(struct cli_def *cli, const char *command, char *ar } cli_print(cli, "OK, erasing keystore, this will take about 45 seconds..."); - if ((status = keystore_erase_bulk()) != 1) { + if ((status = keystore_erase_bulk()) != CMSIS_HAL_OK) { cli_print(cli, "Failed erasing token keystore: %i", status); return CLI_ERROR; } diff --git a/projects/hsm/mgmt-misc.c b/projects/hsm/mgmt-misc.c index e834b7d..65da7ff 100644 --- a/projects/hsm/mgmt-misc.c +++ b/projects/hsm/mgmt-misc.c @@ -85,7 +85,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal /* After reception of a chunk but before ACKing we have "all" the time in the world to * calculate CRC and invoke the data_callback. */ - if (data_callback != NULL && ! data_callback(buf, (size_t) n)) { + if (data_callback != NULL && data_callback(buf, n) != CMSIS_HAL_OK) { cli_print(cli, "Data processing failed"); goto okay; } diff --git a/projects/hsm/mgmt-misc.h b/projects/hsm/mgmt-misc.h index 862ca0c..ef63a9e 100644 --- a/projects/hsm/mgmt-misc.h +++ b/projects/hsm/mgmt-misc.h @@ -37,7 +37,8 @@ #include -typedef int (*cli_data_callback)(uint8_t *, size_t); +/* Write a chunk of received data to flash. */ +typedef HAL_StatusTypeDef (*cli_data_callback)(uint8_t *, size_t); extern int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_callback data_callback); -- cgit v1.2.3