diff options
Diffstat (limited to 'projects/cli-test')
-rw-r--r-- | projects/cli-test/cli-test.c | 1 | ||||
-rw-r--r-- | projects/cli-test/mgmt-cli.c | 15 | ||||
-rw-r--r-- | projects/cli-test/mgmt-dfu.c | 17 | ||||
-rw-r--r-- | projects/cli-test/mgmt-fpga.c | 39 | ||||
-rw-r--r-- | projects/cli-test/mgmt-keystore.c | 32 | ||||
-rw-r--r-- | projects/cli-test/mgmt-masterkey.c | 24 | ||||
-rw-r--r-- | projects/cli-test/mgmt-misc.c | 22 | ||||
-rw-r--r-- | projects/cli-test/mgmt-misc.h | 2 | ||||
-rw-r--r-- | projects/cli-test/mgmt-show.c | 38 | ||||
-rw-r--r-- | projects/cli-test/mgmt-test.c | 4 | ||||
-rw-r--r-- | projects/cli-test/test-fmc.c | 16 | ||||
-rw-r--r-- | projects/cli-test/test-mkmif.c | 36 |
12 files changed, 177 insertions, 69 deletions
diff --git a/projects/cli-test/cli-test.c b/projects/cli-test/cli-test.c index c288257..82946fa 100644 --- a/projects/cli-test/cli-test.c +++ b/projects/cli-test/cli-test.c @@ -57,7 +57,6 @@ int main() { stm_init(); - uart_set_default(STM_UART_MGMT); led_on(LED_GREEN); diff --git a/projects/cli-test/mgmt-cli.c b/projects/cli-test/mgmt-cli.c index eacb944..d7f7383 100644 --- a/projects/cli-test/mgmt-cli.c +++ b/projects/cli-test/mgmt-cli.c @@ -58,8 +58,8 @@ #endif typedef struct { - int ridx; - volatile int widx; + unsigned ridx; + unsigned widx; mgmt_cli_dma_state_t rx_state; uint8_t buf[CLI_UART_RECVBUF_SIZE]; } ringbuf_t; @@ -97,19 +97,20 @@ static uint8_t uart_rx; */ void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart) { + huart = huart; + ringbuf_write_char(&uart_ringbuf, uart_rx); } static void uart_cli_print(struct cli_def *cli __attribute__ ((unused)), const char *buf) { - char crlf[] = "\r\n"; - uart_send_string2(STM_UART_MGMT, buf); - uart_send_string2(STM_UART_MGMT, crlf); + uart_send_string(buf); + uart_send_string("\r\n"); } static ssize_t uart_cli_read(struct cli_def *cli __attribute__ ((unused)), void *buf, size_t count) { - for (int i = 0; i < count; ++i) { + for (size_t i = 0; i < count; ++i) { while (ringbuf_read_char(&uart_ringbuf, (uint8_t *)(buf + i)) == 0) { } } @@ -118,7 +119,7 @@ static ssize_t uart_cli_read(struct cli_def *cli __attribute__ ((unused)), void static ssize_t uart_cli_write(struct cli_def *cli __attribute__ ((unused)), const void *buf, size_t count) { - uart_send_bytes(STM_UART_MGMT, (uint8_t *) buf, count); + uart_send_bytes((uint8_t *) buf, count); return (ssize_t)count; } diff --git a/projects/cli-test/mgmt-dfu.c b/projects/cli-test/mgmt-dfu.c index 5c9b4b7..c7273f4 100644 --- a/projects/cli-test/mgmt-dfu.c +++ b/projects/cli-test/mgmt-dfu.c @@ -58,10 +58,14 @@ __IO uint32_t *dfu_code_ptr = &CRYPTECH_FIRMWARE_START + 1; 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; } @@ -70,6 +74,10 @@ static int cmd_dfu_erase(struct cli_def *cli, const char *command, char *argv[], { int status; + 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); @@ -84,6 +92,11 @@ static int cmd_dfu_erase(struct cli_def *cli, const char *command, char *argv[], 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. */ diff --git a/projects/cli-test/mgmt-fpga.c b/projects/cli-test/mgmt-fpga.c index b1b0973..b913316 100644 --- a/projects/cli-test/mgmt-fpga.c +++ b/projects/cli-test/mgmt-fpga.c @@ -3,7 +3,7 @@ * ----------- * CLI code to manage the FPGA configuration etc. * - * Copyright (c) 2016, NORDUnet A/S All rights reserved. + * Copyright (c) 2016-2017, NORDUnet A/S All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -47,14 +47,21 @@ 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, 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; } @@ -63,12 +70,16 @@ static int cmd_fpga_bitstream_upload(struct cli_def *cli, const char *command, c { uint8_t buf[BITSTREAM_UPLOAD_CHUNK_SIZE]; + command = command; + argv = argv; + argc = argc; + dfu_offset = 0; 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; } @@ -83,10 +94,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() != HAL_OK) { cli_print(cli, "ERROR: FPGA config memory not accessible. Check that jumpers JP7 and JP8 are installed."); return CLI_ERROR; } @@ -97,7 +112,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; } @@ -110,6 +125,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); cli_print(cli, "FPGA has been reset"); @@ -119,6 +138,10 @@ static int cmd_fpga_reset(struct cli_def *cli, const char *command, char *argv[] static int cmd_fpga_reset_registers(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_REGISTERS); cli_print(cli, "FPGA registers have been reset"); diff --git a/projects/cli-test/mgmt-keystore.c b/projects/cli-test/mgmt-keystore.c index 18447c8..6d0d38d 100644 --- a/projects/cli-test/mgmt-keystore.c +++ b/projects/cli-test/mgmt-keystore.c @@ -59,6 +59,8 @@ static int cmd_keystore_set_pin(struct cli_def *cli, const char *command, char * hal_error_t status; hal_client_handle_t client = { -1 }; + command = command; + if (argc != 2) { cli_print(cli, "Wrong number of arguments (%i).", argc); cli_print(cli, "Syntax: keystore set pin <user|so|wheel> <pin>"); @@ -91,6 +93,8 @@ static int cmd_keystore_clear_pin(struct cli_def *cli, const char *command, char hal_error_t status; hal_client_handle_t client = { -1 }; + command = command; + if (argc != 1) { cli_print(cli, "Wrong number of arguments (%i).", argc); cli_print(cli, "Syntax: keystore clear pin <user|so|wheel>"); @@ -122,6 +126,8 @@ static int cmd_keystore_set_pin_iterations(struct cli_def *cli, const char *comm hal_error_t status; hal_client_handle_t client = { -1 }; + command = command; + if (argc != 1) { cli_print(cli, "Wrong number of arguments (%i).", argc); cli_print(cli, "Syntax: keystore set pin iterations <number>"); @@ -156,6 +162,8 @@ static int cmd_keystore_set_key(struct cli_def *cli, const char *command, char * hal_error_t status; int hint = 0; + command = command; + if (argc != 2) { cli_print(cli, "Wrong number of arguments (%i).", argc); cli_print(cli, "Syntax: keystore set key <name> <der>"); @@ -187,6 +195,8 @@ static int cmd_keystore_delete_key(struct cli_def *cli, const char *command, cha hal_error_t status; hal_uuid_t name; + command = command; + if (argc != 1) { cli_print(cli, "Wrong number of arguments (%i).", argc); cli_print(cli, "Syntax: keystore delete key <name>"); @@ -214,19 +224,23 @@ static int cmd_keystore_show_data(struct cli_def *cli, const char *command, char uint8_t buf[KEYSTORE_PAGE_SIZE]; uint32_t i; - if (keystore_check_id() != 1) { + command = command; + argv = argv; + argc = argc; + + 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; } cli_print(cli, "First page from keystore memory:\r\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); - uart_send_string2(STM_UART_MGMT, (char *) "\r\n\r\n"); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); + cli_print(cli, "\n"); return CLI_OK; } @@ -263,7 +277,7 @@ static int show_keys(struct cli_def *cli, const char *title) if (!done) previous_uuid = uuids[sizeof(uuids)/sizeof(*uuids) - 1]; - for (int i = 0; i < n; i++) { + for (unsigned i = 0; i < n; i++) { if ((status = hal_uuid_format(&uuids[i], key_name, sizeof(key_name))) != LIBHAL_OK) { cli_print(cli, "Could not convert key name: %s", @@ -318,6 +332,10 @@ static int show_keys(struct cli_def *cli, const char *title) static int cmd_keystore_show_keys(struct cli_def *cli, const char *command, char *argv[], int argc) { + command = command; + argv = argv; + argc = argc; + if (show_keys(cli, "Keystore:")) return CLI_OK; else @@ -329,13 +347,15 @@ static int cmd_keystore_erase(struct cli_def *cli, const char *command, char *ar hal_error_t err; int status; + command = command; + if (argc != 1 || strcmp(argv[0], "YesIAmSure") != 0) { cli_print(cli, "Syntax: keystore erase YesIAmSure"); return CLI_ERROR; } 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-masterkey.c b/projects/cli-test/mgmt-masterkey.c index 623d19b..811e15b 100644 --- a/projects/cli-test/mgmt-masterkey.c +++ b/projects/cli-test/mgmt-masterkey.c @@ -83,6 +83,10 @@ static int cmd_masterkey_status(struct cli_def *cli, const char *command, char * hal_error_t status; uint8_t buf[KEK_LENGTH] = {0}; + command = command; + argv = argv; + argc = argc; + cli_print(cli, "Status of master key:\n"); status = hal_mkm_volatile_read(NULL, 0); @@ -98,7 +102,7 @@ static int cmd_masterkey_status(struct cli_def *cli, const char *command, char * status = hal_mkm_volatile_read(&buf[0], sizeof(buf)); if (status == LIBHAL_OK || status == HAL_ERROR_MASTERKEY_NOT_SET) { cli_print(cli, "\nVolatile read-out:\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); cli_print(cli, "\n"); } else { cli_print(cli, "Failed reading from volatile memory: %s", hal_error_string(status)); @@ -107,7 +111,7 @@ static int cmd_masterkey_status(struct cli_def *cli, const char *command, char * status = hal_mkm_flash_read(&buf[0], sizeof(buf)); if (status == LIBHAL_OK || status == HAL_ERROR_MASTERKEY_NOT_SET) { cli_print(cli, "\nFlash read-out:\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); cli_print(cli, "\n"); } else { cli_print(cli, "Failed reading from flash: %s", hal_error_string(status)); @@ -122,13 +126,15 @@ static int cmd_masterkey_set(struct cli_def *cli, const char *command, char *arg hal_error_t err; int i; + command = command; + if ((i = _parse_hex_groups(&buf[0], sizeof(buf), argv, argc)) != 1) { cli_print(cli, "Failed parsing master key (%i)", i); return CLI_OK; } cli_print(cli, "Parsed key:\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); cli_print(cli, "\n"); if ((err = hal_mkm_volatile_write(buf, sizeof(buf))) == LIBHAL_OK) { @@ -143,6 +149,10 @@ static int cmd_masterkey_erase(struct cli_def *cli, const char *command, char *a { hal_error_t err; + command = command; + argv = argv; + argc = argc; + if ((err = hal_mkm_volatile_erase(KEK_LENGTH)) == LIBHAL_OK) { cli_print(cli, "Erased master key from volatile memory"); } else { @@ -157,13 +167,15 @@ static int cmd_masterkey_unsecure_set(struct cli_def *cli, const char *command, hal_error_t err; int i; + command = command; + if ((i = _parse_hex_groups(&buf[0], sizeof(buf), argv, argc)) != 1) { cli_print(cli, "Failed parsing master key (%i)", i); return CLI_OK; } cli_print(cli, "Parsed key:\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); cli_print(cli, "\n"); if ((err = hal_mkm_flash_write(buf, sizeof(buf))) == LIBHAL_OK) { @@ -178,6 +190,10 @@ static int cmd_masterkey_unsecure_erase(struct cli_def *cli, const char *command { hal_error_t err; + command = command; + argv = argv; + argc = argc; + if ((err = hal_mkm_flash_erase(KEK_LENGTH)) == LIBHAL_OK) { cli_print(cli, "Erased unsecure master key from flash"); } else { diff --git a/projects/cli-test/mgmt-misc.c b/projects/cli-test/mgmt-misc.c index 7db08f2..db8dbd2 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) @@ -67,7 +67,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal cli_print(cli, "OK, write size (4 bytes), data in %li byte chunks, CRC-32 (4 bytes)", (uint32_t) n); - if (uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, sizeof(filesize), 1000) != CMSIS_HAL_OK) { + if (uart_receive_bytes((void *) &filesize, sizeof(filesize), 1000) != CMSIS_HAL_OK) { cli_print(cli, "Receive timed out"); goto fail; } @@ -82,7 +82,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal if (filesize < n) n = filesize; - if (uart_receive_bytes(STM_UART_MGMT, (void *) buf, n, 1000) != CMSIS_HAL_OK) { + if (uart_receive_bytes((void *) buf, n, 1000) != CMSIS_HAL_OK) { cli_print(cli, "Receive timed out"); goto fail; } @@ -92,18 +92,18 @@ 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; } counter++; - uart_send_bytes(STM_UART_MGMT, (void *) &counter, 4); + uart_send_bytes((void *) &counter, 4); } my_crc = hal_crc32_finalize(my_crc); cli_print(cli, "Send CRC-32"); - uart_receive_bytes(STM_UART_MGMT, (void *) &crc, sizeof(crc), 1000); + uart_receive_bytes((void *) &crc, sizeof(crc), 1000); cli_print(cli, "CRC-32 0x%x, calculated CRC 0x%x", (unsigned int) crc, (unsigned int) my_crc); if (crc == my_crc) { cli_print(cli, "CRC checksum MATCHED"); @@ -120,6 +120,10 @@ static int cmd_filetransfer(struct cli_def *cli, const char *command, char *argv { uint8_t buf[FILETRANSFER_UPLOAD_CHUNK_SIZE]; + command = command; + argv = argv; + argc = argc; + demo_crc = hal_crc32_init(); cli_receive_data(cli, &buf[0], sizeof(buf), _count_bytes_callback); demo_crc = hal_crc32_finalize(demo_crc); @@ -129,6 +133,10 @@ static int cmd_filetransfer(struct cli_def *cli, const char *command, char *argv static int cmd_reboot(struct cli_def *cli, const char *command, char *argv[], int argc) { + command = command; + argv = argv; + argc = argc; + cli_print(cli, "\n\n\nRebooting\n\n\n"); HAL_NVIC_SystemReset(); 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 f124830..4338dcd 100644 --- a/projects/cli-test/mgmt-show.c +++ b/projects/cli-test/mgmt-show.c @@ -56,6 +56,10 @@ static int cmd_show_cpuspeed(struct cli_def *cli, const char *command, char *arg { volatile uint32_t hclk; + command = command; + argv = argv; + argc = argc; + hclk = HAL_RCC_GetHCLKFreq(); cli_print(cli, "HSE_VALUE: %li", HSE_VALUE); cli_print(cli, "HCLK: %li (%i MHz)", hclk, (int) hclk / 1000 / 1000); @@ -65,7 +69,11 @@ static int cmd_show_cpuspeed(struct cli_def *cli, const char *command, char *arg static int cmd_show_fpga_status(struct cli_def *cli, const char *command, char *argv[], int argc) { - cli_print(cli, "FPGA has %sloaded a bitstream", fpgacfg_check_done() ? "":"NOT "); + command = command; + argv = argv; + argc = argc; + + cli_print(cli, "FPGA has %sloaded a bitstream", (fpgacfg_check_done() == CMSIS_HAL_OK) ? "":"NOT "); return CLI_OK; } @@ -74,7 +82,11 @@ static int cmd_show_fpga_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; } @@ -90,7 +102,11 @@ static int cmd_show_fpga_cores(struct cli_def *cli, const char *command, char *a static int cmd_show_keystore_status(struct cli_def *cli, const char *command, char *argv[], int argc) { - cli_print(cli, "Keystore memory is %sonline", (keystore_check_id() != 1) ? "NOT ":""); + command = command; + argv = argv; + argc = argc; + + cli_print(cli, "Keystore memory is %sonline", (keystore_check_id() == CMSIS_HAL_OK) ? "":"NOT "); return CLI_OK; } @@ -99,19 +115,23 @@ static int cmd_show_keystore_data(struct cli_def *cli, const char *command, char uint8_t buf[KEYSTORE_PAGE_SIZE]; uint32_t i; - if (keystore_check_id() != 1) { + command = command; + argv = argv; + argc = argc; + + 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; } cli_print(cli, "First page from keystore memory:\r\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); - uart_send_string2(STM_UART_MGMT, (char *) "\r\n\r\n"); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); + cli_print(cli, "\n"); for (i = 0; i < 8; i++) { if (buf[i] == 0xff) break; /* never written */ @@ -125,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/mgmt-test.c b/projects/cli-test/mgmt-test.c index 1a22996..9b9972d 100644 --- a/projects/cli-test/mgmt-test.c +++ b/projects/cli-test/mgmt-test.c @@ -52,6 +52,8 @@ static int cmd_test_sdram(struct cli_def *cli, const char *command, char *argv[] // run external memory initialization sequence int ok, num_cycles = 1, i, test_completed; + command = command; + if (argc == 1) { num_cycles = strtol(argv[0], NULL, 0); if (num_cycles > 100) num_cycles = 100; @@ -106,6 +108,8 @@ static int cmd_test_fmc(struct cli_def *cli, const char *command, char *argv[], { int i, num_cycles = 1, num_rounds = 100000; + command = command; + if (argc >= 1) { num_cycles = strtol(argv[0], NULL, 0); if (num_cycles > 100000) num_cycles = 100000; diff --git a/projects/cli-test/test-fmc.c b/projects/cli-test/test-fmc.c index b393dac..87f80ce 100644 --- a/projects/cli-test/test-fmc.c +++ b/projects/cli-test/test-fmc.c @@ -105,7 +105,7 @@ int test_fpga_data_bus(struct cli_def *cli, uint32_t test_rounds) HAL_RNG_Init(&rng_inst); /* run some rounds of data bus test */ - for (c = 0; c < test_rounds; c++) { + for (c = 0; c < (int)test_rounds; c++) { data_diff = 0; /* try to generate "random" number */ hal_result = HAL_RNG_GenerateRandomNumber(&rng_inst, &rnd); @@ -121,9 +121,9 @@ int test_fpga_data_bus(struct cli_def *cli, uint32_t test_rounds) data_diff = buf ^ rnd; if (data_diff) { cli_print(cli, "Data bus FAIL: expected %lx got %lx", rnd, buf); - uart_send_string2(STM_UART_MGMT, (char *) "Binary diff: "); - uart_send_number2(STM_UART_MGMT, data_diff, 32, 2); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string((char *) "Binary diff: "); + uart_send_binary(data_diff, 32); + uart_send_string("\r\n"); break; } @@ -163,7 +163,7 @@ int test_fpga_address_bus(struct cli_def *cli, uint32_t test_rounds) HAL_RNG_Init(&rng_inst); /* run some rounds of address bus test */ - for (c = 0; c < test_rounds; c++) { + for (c = 0; c < (int)test_rounds; c++) { addr_diff = 0; /* try to generate "random" number */ hal_result = HAL_RNG_GenerateRandomNumber(&rng_inst, &addr); @@ -192,9 +192,9 @@ int test_fpga_address_bus(struct cli_def *cli, uint32_t test_rounds) addr_diff = buf ^ addr; if (addr_diff) { cli_print(cli, "Address bus FAIL: expected 0x%lx got 0x%lx", addr, buf); - uart_send_string2(STM_UART_MGMT, (char *) "Binary diff: "); - uart_send_number2(STM_UART_MGMT, addr_diff, 32, 2); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string((char *) "Binary diff: "); + uart_send_binary(addr_diff, 32); + uart_send_string("\r\n"); break; } diff --git a/projects/cli-test/test-mkmif.c b/projects/cli-test/test-mkmif.c index bb41b4d..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; } @@ -142,8 +142,12 @@ int cmd_test_mkmif(struct cli_def *cli, const char *command, char *argv[], int a hal_core_t *core = hal_core_find(MKMIF_NAME, NULL); hal_error_t res; + command = command; + argv = argv; + 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; } |