mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-19 12:58:13 +00:00
feat(core): enable Optiga logging in debug builds by default
[no changelog]
This commit is contained in:
parent
8623e57f43
commit
54c441a607
@ -104,6 +104,26 @@
|
|||||||
// from util.s
|
// from util.s
|
||||||
extern void shutdown_privileged(void);
|
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) {
|
int main(void) {
|
||||||
random_delays_init();
|
random_delays_init();
|
||||||
|
|
||||||
@ -199,6 +219,14 @@ int main(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_OPTIGA
|
#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_init();
|
||||||
optiga_open_application();
|
optiga_open_application();
|
||||||
if (sectrue == secret_ok) {
|
if (sectrue == secret_ok) {
|
||||||
|
@ -75,7 +75,7 @@ static optiga_result process_output(uint8_t **out_data, size_t *out_size) {
|
|||||||
|
|
||||||
*out_data = tx_buffer + 4;
|
*out_data = tx_buffer + 4;
|
||||||
*out_size = tx_size - 4;
|
*out_size = tx_size - 4;
|
||||||
OPTIGA_LOG("SUCCESS ", *out_data, *out_size)
|
OPTIGA_LOG("SUCCESS", *out_data, *out_size)
|
||||||
return OPTIGA_SUCCESS;
|
return OPTIGA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ optiga_result optiga_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static optiga_result optiga_i2c_write(const uint8_t *data, uint16_t data_size) {
|
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) {
|
for (int try_count = 0; try_count <= I2C_MAX_RETRY_COUNT; ++try_count) {
|
||||||
if (try_count != 0) {
|
if (try_count != 0) {
|
||||||
@ -205,7 +205,7 @@ static optiga_result optiga_i2c_read(uint8_t *buffer, uint16_t buffer_size) {
|
|||||||
HAL_Delay(1);
|
HAL_Delay(1);
|
||||||
if (HAL_OK == i2c_receive(OPTIGA_I2C_INSTANCE, OPTIGA_ADDRESS, buffer,
|
if (HAL_OK == i2c_receive(OPTIGA_I2C_INSTANCE, OPTIGA_ADDRESS, buffer,
|
||||||
buffer_size, I2C_TIMEOUT)) {
|
buffer_size, I2C_TIMEOUT)) {
|
||||||
OPTIGA_LOG("<<< ", buffer, buffer_size)
|
OPTIGA_LOG("<<<", buffer, buffer_size)
|
||||||
return OPTIGA_SUCCESS;
|
return OPTIGA_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user