diff options
Diffstat (limited to 'projects')
33 files changed, 421 insertions, 214 deletions
diff --git a/projects/board-test/fmc-perf.c b/projects/board-test/fmc-perf.c index 5ed47ec..e87f282 100644 --- a/projects/board-test/fmc-perf.c +++ b/projects/board-test/fmc-perf.c @@ -56,11 +56,11 @@ static void _time_check(char *label, const uint32_t t0) uint32_t t = HAL_GetTick() - t0; uart_send_string(label); - uart_send_integer(t / 1000, 0); + uart_send_integer(t / 1000, 1); uart_send_char('.'); uart_send_integer(t % 1000, 3); uart_send_string(" seconds, "); - uart_send_integer(((1000 * TEST_NUM_ROUNDS) / t), 0); + uart_send_integer(((1000 * TEST_NUM_ROUNDS) / t), 1); uart_send_string("/sec\r\n"); } diff --git a/projects/board-test/fmc-test.c b/projects/board-test/fmc-test.c index c6a37e6..2002f57 100644 --- a/projects/board-test/fmc-test.c +++ b/projects/board-test/fmc-test.c @@ -4,8 +4,7 @@ /* This requires a special bitstream with a special test register. - See core/platform/novena/fmc/rtl/novena_fmc_top.v, sections marked - `ifdef test: + See core/platform/alpha/rtl/alpha_fmc_test.v: //---------------------------------------------------------------- // Dummy Register // @@ -76,6 +75,7 @@ int test_fpga_address_bus(void); // Defines //------------------------------------------------------------------------------ #define TEST_NUM_ROUNDS 100000 +#define VERBOSE 0 //------------------------------------------------------------------------------ @@ -117,11 +117,15 @@ int main(void) // test address bus addr_test_ok = test_fpga_address_bus(); - uart_send_string("Data: "); - uart_send_integer(data_test_ok, 6); - uart_send_string(", addr: "); - uart_send_integer(addr_test_ok, 6); - uart_send_string("\r\n"); + if (VERBOSE || + (data_test_ok != TEST_NUM_ROUNDS || + addr_test_ok != TEST_NUM_ROUNDS)) { + uart_send_string("Data: "); + uart_send_integer(data_test_ok, 6); + uart_send_string(", addr: "); + uart_send_integer(addr_test_ok, 6); + uart_send_string("\r\n"); + } if (data_test_ok == TEST_NUM_ROUNDS && addr_test_ok == TEST_NUM_ROUNDS) { @@ -137,11 +141,12 @@ int main(void) } uart_send_string("Success "); - uart_send_integer(successful_runs, 0); + uart_send_integer(successful_runs, 1); uart_send_string(", fail "); - uart_send_integer(failed_runs, 0); - uart_send_string("\r\n\r\n"); - + uart_send_integer(failed_runs, 1); + uart_send_string("\r\n"); + if (VERBOSE) + uart_send_string("\r\n"); HAL_Delay(sleep); } @@ -194,13 +199,16 @@ int test_fpga_data_bus(void) data_diff = buf; data_diff ^= rnd; - uart_send_string("Sample of data bus test data: expected "); - uart_send_binary(rnd, 32); - uart_send_string(", got "); - uart_send_binary(buf, 32); - uart_send_string(", diff "); - uart_send_binary(data_diff, 32); - uart_send_string("\r\n"); + if (VERBOSE || data_diff) { + uart_send_string("Sample of data bus test data: expected "); + uart_send_binary(rnd, 32); + uart_send_string(", got "); + uart_send_binary(buf, 32); + uart_send_string(", diff "); + uart_send_binary(data_diff, 32); + uart_send_string("\r\n"); + } + // return number of successful tests return c; } @@ -263,13 +271,15 @@ int test_fpga_address_bus(void) addr_diff = buf; addr_diff ^= rnd; - uart_send_string("Sample of addr bus test data: expected "); - uart_send_binary(rnd, 32); - uart_send_string(", got "); - uart_send_binary(buf, 32); - uart_send_string(", diff "); - uart_send_binary(addr_diff, 32); - uart_send_string("\r\n"); + if (VERBOSE || addr_diff) { + uart_send_string("Sample of addr bus test data: expected "); + uart_send_binary(rnd, 32); + uart_send_string(", got "); + uart_send_binary(buf, 32); + uart_send_string(", diff "); + uart_send_binary(addr_diff, 32); + uart_send_string("\r\n"); + } return c; } diff --git a/projects/board-test/keystore-perf.c b/projects/board-test/keystore-perf.c index 09528a2..c2aa4fb 100644 --- a/projects/board-test/keystore-perf.c +++ b/projects/board-test/keystore-perf.c @@ -16,13 +16,13 @@ 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_integer(err, 1); uart_send_string("\r\n"); break; } @@ -36,19 +36,19 @@ 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_integer(err, 1); uart_send_string("\r\n"); break; } if (memcmp(read_buf, vrfy_buf, KEYSTORE_SUBSECTOR_SIZE) != 0) { uart_send_string("ERROR: verify failed in subsector "); - uart_send_integer(i, 0); + uart_send_integer(i, 1); uart_send_string("\r\n"); break; } @@ -61,13 +61,13 @@ 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_integer(err, 1); uart_send_string("\r\n"); break; } @@ -80,13 +80,13 @@ 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_integer(err, 1); uart_send_string("\r\n"); break; } @@ -114,18 +114,18 @@ 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_integer(err, 1); uart_send_string(" for subsector "); - uart_send_integer(i, 0); + uart_send_integer(i, 1); uart_send_string("\r\n"); break; } @@ -151,15 +151,15 @@ static void _time_check(char *label, const uint32_t t0, uint32_t n_rounds) uint32_t t = HAL_GetTick() - t0; uart_send_string(label); - uart_send_integer(t / 1000, 0); + uart_send_integer(t / 1000, 1); uart_send_char('.'); uart_send_integer(t % 1000, 3); uart_send_string(" sec"); if (n_rounds > 1) { uart_send_string(" for "); - uart_send_integer(n_rounds, 0); + uart_send_integer(n_rounds, 1); uart_send_string(" rounds, "); - uart_send_integer(t / n_rounds, 0); + uart_send_integer(t / n_rounds, 1); uart_send_char('.'); uart_send_integer(((t % n_rounds) * 100) / n_rounds, 2); uart_send_string(" ms each"); @@ -177,9 +177,8 @@ static void _time_check(char *label, const uint32_t t0, uint32_t n_rounds) 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/rtc-test.c b/projects/board-test/rtc-test.c index f1c2db1..bbb297a 100644 --- a/projects/board-test/rtc-test.c +++ b/projects/board-test/rtc-test.c @@ -94,7 +94,7 @@ void dump_sram() request_data(buf, RTC_RTC_ADDR, 0x0, RTC_SRAM_TOTAL_BYTES); uart_send_string("SRAM contents:\r\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, RTC_SRAM_TOTAL_BYTES); + uart_send_hexdump(buf, 0, RTC_SRAM_TOTAL_BYTES); uart_send_string("\r\n"); } @@ -104,12 +104,12 @@ void dump_eeprom() request_data(buf, RTC_EEPROM_ADDR, 0x0, RTC_EEPROM_TOTAL_BYTES); uart_send_string("EEPROM contents:\r\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, RTC_EEPROM_TOTAL_BYTES); + uart_send_hexdump(buf, 0, RTC_EEPROM_TOTAL_BYTES); uart_send_string("\r\n"); request_data(buf, RTC_EEPROM_ADDR, RTC_EEPROM_EUI48_OFFSET, RTC_EEPROM_EUI48_BYTES); uart_send_string("EEPROM EUI-48:\r\n"); - uart_send_hexdump(STM_UART_MGMT, buf, RTC_EEPROM_EUI48_OFFSET, RTC_EEPROM_EUI48_BYTES); + uart_send_hexdump(buf, RTC_EEPROM_EUI48_OFFSET, RTC_EEPROM_EUI48_BYTES); uart_send_string("\r\n"); } @@ -131,7 +131,6 @@ int main() { stm_init(); - uart_set_default(STM_UART_MGMT); uart_send_string("\r\n\r\n*** Init done\r\n"); dump_sram(); diff --git a/projects/board-test/spiflash-perf.c b/projects/board-test/spiflash-perf.c index 53f29cb..36c6131 100644 --- a/projects/board-test/spiflash-perf.c +++ b/projects/board-test/spiflash-perf.c @@ -33,9 +33,9 @@ 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_integer(err, 1); uart_send_string("\r\n"); break; } @@ -53,9 +53,9 @@ 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_integer(err, 1); uart_send_string("\r\n"); break; } @@ -75,15 +75,15 @@ 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_integer(err, 1); uart_send_string("\r\n"); break; } if (memcmp(read_buf, vrfy_buf, N25Q128_PAGE_SIZE) != 0) { uart_send_string("ERROR: verify failed in page "); - uart_send_integer(i, 0); + uart_send_integer(i, 1); uart_send_string("\r\n"); break; } @@ -100,9 +100,9 @@ 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_integer(err, 1); uart_send_string("\r\n"); break; } @@ -119,9 +119,9 @@ 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_integer(err, 1); uart_send_string("\r\n"); break; } @@ -136,9 +136,9 @@ 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_integer(err, 1); uart_send_string("\r\n"); } } @@ -171,11 +171,11 @@ 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_integer(err, 1); uart_send_string(" for page "); - uart_send_integer(i, 0); + uart_send_integer(i, 1); uart_send_string("\r\n"); break; } @@ -201,15 +201,15 @@ static void _time_check(char *label, const uint32_t t0, uint32_t n_rounds) uint32_t t = HAL_GetTick() - t0; uart_send_string(label); - uart_send_integer(t / 1000, 0); + uart_send_integer(t / 1000, 1); uart_send_char('.'); uart_send_integer(t % 1000, 3); uart_send_string(" sec"); if (n_rounds > 1) { uart_send_string(" for "); - uart_send_integer(n_rounds, 0); + uart_send_integer(n_rounds, 1); uart_send_string(" rounds, "); - uart_send_integer(t / n_rounds, 0); + uart_send_integer(t / n_rounds, 1); uart_send_char('.'); uart_send_integer(((t % n_rounds) * 100) / n_rounds, 2); uart_send_string(" ms each"); @@ -227,9 +227,8 @@ static void _time_check(char *label, const uint32_t t0, uint32_t n_rounds) 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/bootloader/bootloader.c b/projects/bootloader/bootloader.c index ead87d0..c62df12 100644 --- a/projects/bootloader/bootloader.c +++ b/projects/bootloader/bootloader.c @@ -84,7 +84,7 @@ int should_dfu() for (i = 0; i < 50; i++) { HAL_Delay(100); led_toggle(LED_BLUE); - if (uart_recv_char2(STM_UART_MGMT, &rx, 0) == HAL_OK) { + if (uart_recv_char(&rx, 0) == HAL_OK) { if (rx == 13) return 1; } } @@ -100,7 +100,7 @@ int main(void) stm_init(); - uart_send_string2(STM_UART_MGMT, (char *) "\r\n\r\nThis is the bootloader speaking..."); + uart_send_string("\r\n\r\nThis is the bootloader speaking..."); if (should_dfu()) { led_off(LED_BLUE); @@ -110,9 +110,9 @@ int main(void) */ led_off(LED_BLUE); led_on(LED_RED); - uart_send_string2(STM_UART_MGMT, (char *) "dfu_receive_firmware failed: "); - uart_send_number2(STM_UART_MGMT, status, 3, 16); - uart_send_string2(STM_UART_MGMT, (char *) "\r\n\r\nRebooting in three seconds\r\n"); + uart_send_string("dfu_receive_firmware failed: "); + uart_send_hex(status, 2); + uart_send_string("\r\n\r\nRebooting in three seconds\r\n"); HAL_Delay(3000); HAL_NVIC_SystemReset(); while (1) {}; @@ -124,7 +124,7 @@ int main(void) */ *dfu_control = HARDWARE_EARLY_DFU_JUMP; - uart_send_string2(STM_UART_MGMT, (char *) "loading firmware\r\n\r\n"); + uart_send_string("loading firmware\r\n\r\n"); /* De-initialize hardware by rebooting */ HAL_NVIC_SystemReset(); diff --git a/projects/bootloader/dfu.c b/projects/bootloader/dfu.c index a0ff372..83aef20 100644 --- a/projects/bootloader/dfu.c +++ b/projects/bootloader/dfu.c @@ -53,7 +53,7 @@ static int getline(char *buf, int len) uint8_t c; for (i = 0; i < len; ++i) { - if (uart_recv_char2(STM_UART_MGMT, &c, HAL_MAX_DELAY) != CMSIS_HAL_OK) + if (uart_recv_char(&c, HAL_MAX_DELAY) != CMSIS_HAL_OK) return -1; if (c == '\r') { buf[i] = '\0'; @@ -67,7 +67,7 @@ static int getline(char *buf, int len) static void uart_flush(void) { uint8_t c; - while (uart_recv_char2(STM_UART_MGMT, &c, 0) == CMSIS_HAL_OK) { ; } + while (uart_recv_char(&c, 0) == CMSIS_HAL_OK) { ; } } static int do_login(void) @@ -79,7 +79,7 @@ static int do_login(void) int n; uart_flush(); - uart_send_string2(STM_UART_MGMT, "\r\nUsername: "); + uart_send_string("\r\nUsername: "); if (getline(username, sizeof(username)) <= 0) return -1; if (strcmp(username, "wheel") == 0) @@ -92,7 +92,7 @@ static int do_login(void) user = HAL_USER_NONE; uart_flush(); - uart_send_string2(STM_UART_MGMT, "\r\nPassword: "); + uart_send_string("\r\nPassword: "); if ((n = getline(pin, sizeof(pin))) <= 0) return -1; @@ -101,7 +101,7 @@ static int do_login(void) hal_ks_init_read_only_pins_only(); if (hal_rpc_login(client, user, pin, n) != LIBHAL_OK) { - uart_send_string2(STM_UART_MGMT, "\r\nAccess denied\r\n"); + uart_send_string("\r\nAccess denied\r\n"); return -1; } return 0; @@ -118,33 +118,33 @@ int dfu_receive_firmware(void) return -1; /* Fake the CLI */ - uart_send_string2(STM_UART_MGMT, "\r\ncryptech> "); + uart_send_string("\r\ncryptech> "); char cmd[64]; if (getline(cmd, sizeof(cmd)) <= 0) return -1; if (strcmp(cmd, "firmware upload") != 0) { - uart_send_string2(STM_UART_MGMT, "\r\nInvalid command \""); - uart_send_string2(STM_UART_MGMT, cmd); - uart_send_string2(STM_UART_MGMT, "\"\r\n"); + uart_send_string("\r\nInvalid command \""); + uart_send_string(cmd); + uart_send_string("\"\r\n"); return -1; } - uart_send_string2(STM_UART_MGMT, "OK, write size (4 bytes), data in 4096 byte chunks, CRC-32 (4 bytes)\r\n"); + uart_send_string("OK, write size (4 bytes), data in 4096 byte chunks, CRC-32 (4 bytes)\r\n"); /* Read file size (4 bytes) */ - uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, sizeof(filesize), 10000); + uart_receive_bytes((void *) &filesize, sizeof(filesize), 10000); if (filesize < 512 || filesize > DFU_FIRMWARE_END_ADDR - DFU_FIRMWARE_ADDR) { - uart_send_string2(STM_UART_MGMT, "Invalid filesize "); - uart_send_number2(STM_UART_MGMT, filesize, 1, 10); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string("Invalid filesize "); + uart_send_integer(filesize, 1); + uart_send_string("\r\n"); return -1; } HAL_FLASH_Unlock(); - uart_send_string2(STM_UART_MGMT, "Send "); - uart_send_number2(STM_UART_MGMT, filesize, 1, 10); - uart_send_string2(STM_UART_MGMT, " bytes of data\r\n"); + uart_send_string("Send "); + uart_send_integer(filesize, 1); + uart_send_string(" bytes of data\r\n"); while (filesize) { /* By initializing buf to the same value that erased flash has (0xff), we don't @@ -156,7 +156,7 @@ int dfu_receive_firmware(void) n = filesize; } - if (uart_receive_bytes(STM_UART_MGMT, (void *) buf, n, 10000) != CMSIS_HAL_OK) { + if (uart_receive_bytes((void *) buf, n, 10000) != CMSIS_HAL_OK) { return -2; } filesize -= n; @@ -170,7 +170,7 @@ int dfu_receive_firmware(void) /* ACK this chunk by sending the current chunk counter (4 bytes) */ counter++; - uart_send_bytes(STM_UART_MGMT, (void *) &counter, 4); + uart_send_bytes((void *) &counter, 4); led_toggle(LED_BLUE); } @@ -178,20 +178,20 @@ int dfu_receive_firmware(void) HAL_FLASH_Lock(); - uart_send_string2(STM_UART_MGMT, "Send CRC-32\r\n"); + uart_send_string("Send CRC-32\r\n"); /* The sending side will now send its calculated CRC-32 */ - uart_receive_bytes(STM_UART_MGMT, (void *) &crc, sizeof(crc), 10000); + uart_receive_bytes((void *) &crc, sizeof(crc), 10000); - uart_send_string2(STM_UART_MGMT, "CRC-32 0x"); - uart_send_number2(STM_UART_MGMT, crc, 1, 16); - uart_send_string2(STM_UART_MGMT, ", calculated CRC 0x"); - uart_send_number2(STM_UART_MGMT, my_crc, 1, 16); + uart_send_string("CRC-32 0x"); + uart_send_hex(crc, 1); + uart_send_string(", calculated CRC 0x"); + uart_send_hex(my_crc, 1); if (crc == my_crc) { - uart_send_string2(STM_UART_MGMT, "CRC checksum MATCHED\r\n"); + uart_send_string("CRC checksum MATCHED\r\n"); return 0; } else { - uart_send_string2(STM_UART_MGMT, "CRC checksum did NOT match\r\n"); + uart_send_string("CRC checksum did NOT match\r\n"); } led_on(LED_RED); diff --git a/projects/bootloader/log.c b/projects/bootloader/log.c index c0d9df4..fbc0e73 100644 --- a/projects/bootloader/log.c +++ b/projects/bootloader/log.c @@ -63,6 +63,6 @@ void hal_log(const hal_log_level_t level, const char *format, ...) vsnprintf(buffer, sizeof(buffer), format, ap); va_end(ap); - uart_send_string2(STM_UART_MGMT, buffer); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string(buffer); + uart_send_string("\r\n"); } 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; } diff --git a/projects/hsm/hsm.c b/projects/hsm/hsm.c index 5ef2ccc..f20ee64 100644 --- a/projects/hsm/hsm.c +++ b/projects/hsm/hsm.c @@ -419,7 +419,6 @@ void hal_sleep(const unsigned seconds) { task_delay(seconds * 1000); } int main(void) { stm_init(); - uart_set_default(STM_UART_MGMT); led_on(LED_GREEN); if (hal_rpc_server_init() != LIBHAL_OK) @@ -428,7 +427,7 @@ int main(void) /* Initialize the ibuf queues. */ memset(&ibuf_waiting, 0, sizeof(ibuf_waiting)); memset(&ibuf_ready, 0, sizeof(ibuf_ready)); - for (int i = 0; i < sizeof(ibufs)/sizeof(ibufs[0]); ++i) + for (size_t i = 0; i < sizeof(ibufs)/sizeof(ibufs[0]); ++i) ibuf_put(&ibuf_waiting, &ibufs[i]); /* Create the rpc dispatch worker tasks. */ diff --git a/projects/hsm/log.c b/projects/hsm/log.c index c0d9df4..fbc0e73 100644 --- a/projects/hsm/log.c +++ b/projects/hsm/log.c @@ -63,6 +63,6 @@ void hal_log(const hal_log_level_t level, const char *format, ...) vsnprintf(buffer, sizeof(buffer), format, ap); va_end(ap); - uart_send_string2(STM_UART_MGMT, buffer); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string(buffer); + uart_send_string("\r\n"); } diff --git a/projects/hsm/mgmt-bootloader.c b/projects/hsm/mgmt-bootloader.c index 738686e..1d8b8ad 100644 --- a/projects/hsm/mgmt-bootloader.c +++ b/projects/hsm/mgmt-bootloader.c @@ -50,16 +50,19 @@ 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) { + command = command; + argv = argv; + argc = argc; + if (user < HAL_USER_SO) { cli_print(cli, "Permission denied."); return CLI_ERROR; diff --git a/projects/hsm/mgmt-cli.c b/projects/hsm/mgmt-cli.c index ec9bf8f..2b5be1f 100644 --- a/projects/hsm/mgmt-cli.c +++ b/projects/hsm/mgmt-cli.c @@ -64,8 +64,8 @@ static tcb_t *cli_task; #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; @@ -103,6 +103,8 @@ static uint8_t uart_rx; */ void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart) { + huart = huart; + ringbuf_write_char(&uart_ringbuf, uart_rx); task_wake(cli_task); } @@ -110,13 +112,13 @@ void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart) 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(crlf); } 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) task_sleep(); } @@ -125,7 +127,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/hsm/mgmt-firmware.c b/projects/hsm/mgmt-firmware.c index ec8a69d..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" @@ -49,6 +48,10 @@ extern hal_user_t user; static int cmd_firmware_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; 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; } diff --git a/projects/hsm/mgmt-keystore.c b/projects/hsm/mgmt-keystore.c index 0104265..b79a5fe 100644 --- a/projects/hsm/mgmt-keystore.c +++ b/projects/hsm/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>"); @@ -145,6 +151,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>"); @@ -205,7 +213,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, skipping: %s", @@ -276,6 +284,10 @@ static int show_pin(struct cli_def *cli, char *label, hal_user_t user) static int cmd_keystore_show_keys(struct cli_def *cli, const char *command, char *argv[], int argc) { + command = command; + argv = argv; + argc = argc; + int err = 0; err |= show_keys(cli, "Keystore:"); @@ -291,7 +303,9 @@ 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; if (argc != 1 || strcmp(argv[0], "YesIAmSure") != 0) { cli_print(cli, "Syntax: keystore erase YesIAmSure"); @@ -299,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-masterkey.c b/projects/hsm/mgmt-masterkey.c index 9f5e4d0..765cb10 100644 --- a/projects/hsm/mgmt-masterkey.c +++ b/projects/hsm/mgmt-masterkey.c @@ -82,6 +82,10 @@ static int cmd_masterkey_status(struct cli_def *cli, const char *command, char * { hal_error_t status; + command = command; + argv = argv; + argc = argc; + cli_print(cli, "Status of master key:\n"); status = hal_mkm_volatile_read(NULL, 0); @@ -107,7 +111,7 @@ static int _masterkey_set(struct cli_def *cli, char *argv[], int argc, return CLI_ERROR; } cli_print(cli, "Random 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"); } @@ -118,7 +122,7 @@ static int _masterkey_set(struct cli_def *cli, char *argv[], int argc, } 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"); } @@ -132,6 +136,8 @@ static int _masterkey_set(struct cli_def *cli, char *argv[], int argc, static int cmd_masterkey_set(struct cli_def *cli, const char *command, char *argv[], int argc) { + command = command; + return _masterkey_set(cli, argv, argc, "volatile", hal_mkm_volatile_write); } @@ -139,6 +145,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 { @@ -149,6 +159,8 @@ static int cmd_masterkey_erase(struct cli_def *cli, const char *command, char *a static int cmd_masterkey_unsecure_set(struct cli_def *cli, const char *command, char *argv[], int argc) { + command = command; + return _masterkey_set(cli, argv, argc, "flash", hal_mkm_flash_write); } @@ -156,6 +168,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/hsm/mgmt-misc.c b/projects/hsm/mgmt-misc.c index 016d7cb..86f1be8 100644 --- a/projects/hsm/mgmt-misc.c +++ b/projects/hsm/mgmt-misc.c @@ -60,7 +60,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), 2000) != CMSIS_HAL_OK) { + if (uart_receive_bytes((void *) &filesize, sizeof(filesize), 2000) != CMSIS_HAL_OK) { cli_print(cli, "Receive timed out"); goto fail; } @@ -75,7 +75,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, 2000) != CMSIS_HAL_OK) { + if (uart_receive_bytes((void *) buf, n, 2000) != CMSIS_HAL_OK) { cli_print(cli, "Receive timed out"); goto fail; } @@ -85,18 +85,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 okay; } 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), 2000); + uart_receive_bytes((void *) &crc, sizeof(crc), 2000); 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"); @@ -116,6 +116,11 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal #ifdef DO_PROFILING static int cmd_profile_start(struct cli_def *cli, const char *command, char *argv[], int argc) { + cli = cli; + command = command; + argv = argv; + argc = argc; + extern uint32_t CRYPTECH_FIRMWARE_START; extern char __etext; /* end of text/code symbol, defined by linker */ extern void monstartup (size_t lowpc, size_t highpc); @@ -125,6 +130,11 @@ static int cmd_profile_start(struct cli_def *cli, const char *command, char *arg static int cmd_profile_stop(struct cli_def *cli, const char *command, char *argv[], int argc) { + cli = cli; + command = command; + argv = argv; + argc = argc; + extern void _mcleanup(void); _mcleanup(); return CLI_OK; @@ -134,6 +144,10 @@ static int cmd_profile_stop(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/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 <libcli.h> -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); diff --git a/projects/hsm/mgmt-task.c b/projects/hsm/mgmt-task.c index 4668585..c2a3d3f 100644 --- a/projects/hsm/mgmt-task.c +++ b/projects/hsm/mgmt-task.c @@ -52,6 +52,10 @@ extern size_t request_queue_max(void); static int cmd_task_show(struct cli_def *cli, const char *command, char *argv[], int argc) { + command = command; + argv = argv; + argc = argc; + cli_print(cli, "name state stack high water"); cli_print(cli, "-------- -------- ----------------"); @@ -76,6 +80,10 @@ static int cmd_task_show(struct cli_def *cli, const char *command, char *argv[], #ifdef DO_TASK_METRICS static int cmd_task_show_metrics(struct cli_def *cli, const char *command, char *argv[], int argc) { + command = command; + argv = argv; + argc = argc; + struct task_metrics tm; task_get_metrics(&tm); @@ -88,6 +96,11 @@ static int cmd_task_show_metrics(struct cli_def *cli, const char *command, char static int cmd_task_reset_metrics(struct cli_def *cli, const char *command, char *argv[], int argc) { + cli = cli; + command = command; + argv = argv; + argc = argc; + task_reset_metrics(); return CLI_OK; diff --git a/projects/libhal-test/gettimeofday.c b/projects/libhal-test/gettimeofday.c index b13485d..f7a87f1 100644 --- a/projects/libhal-test/gettimeofday.c +++ b/projects/libhal-test/gettimeofday.c @@ -56,6 +56,8 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) { uint32_t tick = HAL_GetTick(); /* uptime in ms */ + tz = tz; + tv->tv_sec = tick / 1000; tv->tv_usec = (tick % 1000) * 1000; diff --git a/projects/libhal-test/printf.c b/projects/libhal-test/printf.c index 5a15d12..85af09b 100644 --- a/projects/libhal-test/printf.c +++ b/projects/libhal-test/printf.c @@ -244,7 +244,7 @@ OK, I found my mistake. The math here is _always_ unsigned */ if (precision != 0)
{
width = max(width, precision);
- if (precision > strlen(where))
+ if (precision > strlen((const char *)where))
flags |= PR_LZ;
precision = 0;
}
@@ -295,7 +295,7 @@ EMIT2: if((flags & PR_LJ) == 0) count++;
}
/* emit string/char/converted number */
- for(int i = (flags & PR_WS) ? 1 : 0;
+ for(unsigned i = (flags & PR_WS) ? 1 : 0;
i < length; ++i)
{
fn(*where++, &ptr);
@@ -362,6 +362,8 @@ You must write your own putchar() *****************************************************************************/
int vprintf_help(unsigned c, void **ptr)
{
+ ptr = ptr;
+
putchar(c);
return 0 ;
}
|