Skip to content

Commit

Permalink
feat(core): enable Optiga logging in debug builds by default
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
matejcik authored and andrewkozlik committed May 3, 2024
1 parent 8623e57 commit 54c441a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
28 changes: 28 additions & 0 deletions core/embed/firmware/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@
// from util.s
extern void shutdown_privileged(void);

#ifdef USE_OPTIGA
#if !PYOPT
#include <inttypes.h>
#if 1 // color log
#define OPTIGA_LOG_FORMAT \
"%" PRIu32 " \x1b[35moptiga\x1b[0m \x1b[32mDEBUG\x1b[0m %s: "
#else
#define OPTIGA_LOG_FORMAT "%" PRIu32 " optiga DEBUG %s: "
#endif
static void optiga_log_hex(const char *prefix, const uint8_t *data,
size_t data_size) {
printf(OPTIGA_LOG_FORMAT, hal_ticks_ms() * 1000, prefix);
for (size_t i = 0; i < data_size; i++) {
printf("%02x", data[i]);
}
printf("\n");
}
#endif
#endif

int main(void) {
random_delays_init();

Expand Down Expand Up @@ -199,6 +219,14 @@ int main(void) {
#endif

#ifdef USE_OPTIGA

#if !PYOPT
// command log is relatively quiet so we enable it in debug builds
optiga_command_set_log_hex(optiga_log_hex);
// transport log can be spammy, uncomment if you want it:
// optiga_transport_set_log_hex(optiga_log_hex);
#endif

optiga_init();
optiga_open_application();
if (sectrue == secret_ok) {
Expand Down
2 changes: 1 addition & 1 deletion core/embed/trezorhal/optiga/optiga_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static optiga_result process_output(uint8_t **out_data, size_t *out_size) {

*out_data = tx_buffer + 4;
*out_size = tx_size - 4;
OPTIGA_LOG("SUCCESS ", *out_data, *out_size)
OPTIGA_LOG("SUCCESS", *out_data, *out_size)
return OPTIGA_SUCCESS;
}

Expand Down
4 changes: 2 additions & 2 deletions core/embed/trezorhal/optiga/optiga_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ optiga_result optiga_init(void) {
}

static optiga_result optiga_i2c_write(const uint8_t *data, uint16_t data_size) {
OPTIGA_LOG(">>> ", data, data_size)
OPTIGA_LOG(">>>", data, data_size)

for (int try_count = 0; try_count <= I2C_MAX_RETRY_COUNT; ++try_count) {
if (try_count != 0) {
Expand All @@ -205,7 +205,7 @@ static optiga_result optiga_i2c_read(uint8_t *buffer, uint16_t buffer_size) {
HAL_Delay(1);
if (HAL_OK == i2c_receive(OPTIGA_I2C_INSTANCE, OPTIGA_ADDRESS, buffer,
buffer_size, I2C_TIMEOUT)) {
OPTIGA_LOG("<<< ", buffer, buffer_size)
OPTIGA_LOG("<<<", buffer, buffer_size)
return OPTIGA_SUCCESS;
}
}
Expand Down

0 comments on commit 54c441a

Please sign in to comment.