From 5e81443f931f57f48cd0ef429cbc1b0aa123fa9a Mon Sep 17 00:00:00 2001 From: Niklas Dusenlund Date: Tue, 6 Feb 2024 17:14:22 +0100 Subject: [PATCH 1/2] Helper scripts for setting new screen / securechip These scripts can be used to write what screen or securechip is mounted to the hardware using jlink. --- scripts/set-new-screen.jlink | 4 ++++ scripts/set-original-screen.jlink | 4 ++++ scripts/set-securechip-optiga.jlink | 4 ++++ 3 files changed, 12 insertions(+) create mode 100644 scripts/set-new-screen.jlink create mode 100644 scripts/set-original-screen.jlink create mode 100644 scripts/set-securechip-optiga.jlink diff --git a/scripts/set-new-screen.jlink b/scripts/set-new-screen.jlink new file mode 100644 index 000000000..9892d20a8 --- /dev/null +++ b/scripts/set-new-screen.jlink @@ -0,0 +1,4 @@ +mem 0xe002 1 +w1 0xe002 1 +mem 0xe002 1 +q diff --git a/scripts/set-original-screen.jlink b/scripts/set-original-screen.jlink new file mode 100644 index 000000000..64be0e32e --- /dev/null +++ b/scripts/set-original-screen.jlink @@ -0,0 +1,4 @@ +mem 0xe002 1 +w1 0xe002 0xff +mem 0xe002 1 +q diff --git a/scripts/set-securechip-optiga.jlink b/scripts/set-securechip-optiga.jlink new file mode 100644 index 000000000..940828aaf --- /dev/null +++ b/scripts/set-securechip-optiga.jlink @@ -0,0 +1,4 @@ +mem 0xe003 1 +w1 0xe003 1 +mem 0xe003 1 +q From 6a7ba4d620a1915b74a9a7ac26b07f7f621a5db6 Mon Sep 17 00:00:00 2001 From: Niklas Dusenlund Date: Fri, 9 Feb 2024 12:58:08 +0100 Subject: [PATCH 2/2] Add a function to help debugging --- src/util.c | 10 ++++++++++ src/util.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/util.c b/src/util.c index 4318214f0..8df53f74f 100644 --- a/src/util.c +++ b/src/util.c @@ -39,6 +39,16 @@ 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 e84ec1c2d..fa5cf3890 100644 --- a/src/util.h +++ b/src/util.h @@ -61,6 +61,10 @@ 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);