From ed774184f5a401acb69233050f7a12ed3f2b5afd Mon Sep 17 00:00:00 2001 From: Niklas Dusenlund Date: Mon, 11 Nov 2024 11:30:11 +0100 Subject: [PATCH] Remove semihosting define --- CMakeLists.txt | 5 ----- src/CMakeLists.txt | 22 ++++------------------ src/firmware.c | 2 -- src/hardfault.c | 1 - src/platform/platform_init.c | 7 ------- src/util.c | 13 +++---------- src/util.h | 36 ------------------------------------ 7 files changed, 7 insertions(+), 79 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c89847337..757c84469 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,14 +61,9 @@ option(COVERAGE "Compile with test coverage flags." OFF) option(SANITIZE_ADDRESS "Compile with asan." OFF) option(SANITIZE_UNDEFINED "Compile with ubsan." OFF) option(CMAKE_VERBOSE_MAKEFILE "Verbose build." OFF) -option(SEMIHOSTING "Enable semihosting." OFF) # Generate compile_command.json (for tidy and other tools) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -if(SEMIHOSTING AND NOT CMAKE_CROSSCOMPILING) - message(FATAL_ERROR "It doesn't make sense to semihost for the build machine") -endif() - #----------------------------------------------------------------------------- # Force out-of-source build diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e5870c2d..2680f4f47 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -418,15 +418,8 @@ if(CMAKE_CROSSCOMPILING) # Select the smaller version of libc called nano. target_compile_options(${elf} PRIVATE --specs=nano.specs) target_link_libraries(${elf} PRIVATE --specs=nano.specs) - if(SEMIHOSTING) - # Select an implementation of the system calls that can communicate with the debugger - target_compile_options(${elf} PRIVATE --specs=rdimon.specs) - target_link_libraries(${elf} PRIVATE --specs=rdimon.specs) - target_compile_definitions(${elf} PRIVATE SEMIHOSTING) - else() - target_compile_options(${elf} PRIVATE --specs=nosys.specs) - target_link_libraries(${elf} PRIVATE --specs=nosys.specs) - endif() + target_compile_options(${elf} PRIVATE --specs=nosys.specs) + target_link_libraries(${elf} PRIVATE --specs=nosys.specs) endforeach(bootloader) foreach(bootloader ${BOOTLOADERS-BITBOX02}) @@ -475,15 +468,8 @@ if(CMAKE_CROSSCOMPILING) # Select the smaller version of libc called nano. target_compile_options(${elf} PRIVATE --specs=nano.specs) target_link_libraries(${elf} PRIVATE --specs=nano.specs) - if(SEMIHOSTING) - # Select an implementation of the system calls that can communicate with the debugger - target_compile_options(${elf} PRIVATE --specs=rdimon.specs) - target_link_libraries(${elf} PRIVATE --specs=rdimon.specs) - target_compile_definitions(${elf} PRIVATE SEMIHOSTING) - else() - target_compile_options(${elf} PRIVATE --specs=nosys.specs) - target_link_libraries(${elf} PRIVATE --specs=nosys.specs) - endif() + target_compile_options(${elf} PRIVATE --specs=nosys.specs) + target_link_libraries(${elf} PRIVATE --specs=nosys.specs) target_link_libraries(${elf} PRIVATE ${firmware}_rust_c) endforeach(firmware) diff --git a/src/firmware.c b/src/firmware.c index 9b797d389..feaee8734 100644 --- a/src/firmware.c +++ b/src/firmware.c @@ -22,7 +22,6 @@ #include "qtouch.h" #include "screen.h" #include "ui/screen_stack.h" -#include "util.h" #include "workflow/idle_workflow.h" #include "workflow/orientation_screen.h" @@ -39,7 +38,6 @@ int main(void) qtouch_init(); common_main(); bitbox02_smarteeprom_init(); - traceln("%s", "Device initialized"); orientation_screen_blocking(); idle_workflow_blocking(); firmware_main_loop(); diff --git a/src/hardfault.c b/src/hardfault.c index 0c5522501..05a87638b 100644 --- a/src/hardfault.c +++ b/src/hardfault.c @@ -35,7 +35,6 @@ void MemManage_Handler(void) void Abort(const char* msg) { screen_print_debug(msg, 0); - traceln("Aborted: %s", msg); usb_stop(); #if !defined(TESTING) #if defined(BOOTLOADER) diff --git a/src/platform/platform_init.c b/src/platform/platform_init.c index b10b25432..df6fcaee5 100644 --- a/src/platform/platform_init.c +++ b/src/platform/platform_init.c @@ -18,16 +18,9 @@ #if !defined(BOOTLOADER) #include "sd_mmc/sd_mmc_start.h" #endif -#include "util.h" - -extern void initialise_monitor_handles(void); void platform_init(void) { -#if defined(SEMIHOSTING) - initialise_monitor_handles(); - traceln("%s", "Semihosting enabled"); -#endif oled_init(); #if !defined(BOOTLOADER) sd_mmc_start(); diff --git a/src/util.c b/src/util.c index 0cd5cf65f..2a789f3ff 100644 --- a/src/util.c +++ b/src/util.c @@ -29,7 +29,10 @@ void util_zero(volatile void* dst, size_t len) // the data type. #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers" rust_util_zero(rust_util_bytes_mut(dst, len)); +#pragma clang diagnostic pop #pragma GCC diagnostic pop } @@ -39,16 +42,6 @@ void util_uint8_to_hex(const uint8_t* in_bin, const size_t in_len, char* out) rust_util_bytes(in_bin, in_len), rust_util_bytes_mut((uint8_t*)out, in_len * 2 + 1)); } -#if defined(SEMIHOSTING) -char* util_uint8_to_hex_alloc(const uint8_t* in_bin, const size_t in_len) -{ - void* out = malloc(in_len * 2 + 1); - rust_util_uint8_to_hex( - rust_util_bytes(in_bin, in_len), rust_util_bytes_mut((uint8_t*)out, in_len * 2 + 1)); - return (char*)out; -} -#endif - void util_cleanup_str(char** str) { util_zero(*str, strlens(*str)); diff --git a/src/util.h b/src/util.h index 4103e6932..90c65ce6c 100644 --- a/src/util.h +++ b/src/util.h @@ -61,10 +61,6 @@ void util_zero(volatile void* dst, size_t len); // `out` must be of size in_len*2+1. Use BB_HEX_SIZE() to compute the size. void util_uint8_to_hex(const uint8_t* in_bin, size_t in_len, char* out); -// This function is only compiled when we compile with SEMIHOSTING, it is convenient when debugging -// to print byte arrays as hex. -char* util_uint8_to_hex_alloc(const uint8_t* in_bin, size_t in_len); - #define BB_HEX_SIZE(in_bin) (sizeof((in_bin)) * 2 + 1) void util_cleanup_str(char** str); @@ -85,38 +81,6 @@ void util_cleanup_64(uint8_t** buf); uint8_t* __attribute__((__cleanup__(util_cleanup_64))) var##_clean __attribute__((unused)) = \ var; -/** - * Tracing tools. Only enabled in semihosting builds - * - * Since we are using C99 it is necessary to provide at least 1 argument to "...". To print a - * string, provide the format string "%s" and your string as the second argument. - * - * "do {} while" is a hack to make a macro work like a function in some cases. - * - * stderr is not buffered and takes forever to print stdout is used instead. - * - * SOURCE_PATH_SIZE is a definition provided from the command line which is the length of the path - * to the project directory. - */ - -#if defined(SEMIHOSTING) -#define LOG_LEVEL 1 -#else -#define LOG_LEVEL 0 -#endif -#define FILENAME (&__FILE__[SOURCE_PATH_SIZE]) - -#define trace(format, ...) \ - do { \ - if (LOG_LEVEL > 0) fprintf(stdout, "%s:%d: " format, FILENAME, __LINE__, __VA_ARGS__); \ - } while (0) - -#define traceln(format, ...) \ - do { \ - if (LOG_LEVEL > 0) \ - fprintf(stdout, "%s:%d: " format "\n", FILENAME, __LINE__, __VA_ARGS__); \ - } while (0) - /** * Struct definining a rw buffer (buffer + length). */