Skip to content

Commit

Permalink
Remove semihosting define
Browse files Browse the repository at this point in the history
  • Loading branch information
NickeZ committed Nov 11, 2024
1 parent 5c5644d commit 4cf1f3d
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 79 deletions.
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 4 additions & 18 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/hardfault.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions src/platform/platform_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 0 additions & 10 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,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));
Expand Down
36 changes: 0 additions & 36 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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).
*/
Expand Down

0 comments on commit 4cf1f3d

Please sign in to comment.