diff --git a/core/embed/firmware/main.c b/core/embed/firmware/main.c index 64e42da49..ba35e7a99 100644 --- a/core/embed/firmware/main.c +++ b/core/embed/firmware/main.c @@ -104,6 +104,26 @@ // from util.s extern void shutdown_privileged(void); +#ifdef USE_OPTIGA +#if !PYOPT +#include +#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(); @@ -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) { diff --git a/core/embed/trezorhal/optiga/optiga_commands.c b/core/embed/trezorhal/optiga/optiga_commands.c index 3884dd6a7..a77d79591 100644 --- a/core/embed/trezorhal/optiga/optiga_commands.c +++ b/core/embed/trezorhal/optiga/optiga_commands.c @@ -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; } diff --git a/core/embed/trezorhal/optiga/optiga_transport.c b/core/embed/trezorhal/optiga/optiga_transport.c index 362d6821d..16f0ca017 100644 --- a/core/embed/trezorhal/optiga/optiga_transport.c +++ b/core/embed/trezorhal/optiga/optiga_transport.c @@ -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) { @@ -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; } }