diff --git a/core/embed/bootloader/main.c b/core/embed/bootloader/main.c index 6ad99498f..8e1577ac0 100644 --- a/core/embed/bootloader/main.c +++ b/core/embed/bootloader/main.c @@ -419,16 +419,28 @@ int bootloader_main(void) { i2c_init(); #endif -#ifdef USE_TOUCH - touch_power_on(); - touch_init(); -#endif + display_reinit(); #ifdef USE_DMA2D dma2d_init(); #endif - display_reinit(); + unit_variant_init(); + +#ifdef USE_TOUCH + touch_power_on(); +#ifdef TREZOR_MODEL_T3T1 + // on T3T1, tester needs to run without touch, so making an exception + // until unit variant is written in OTP + if (unit_variant_present()) { + ensure(touch_init(), "Touch screen panel was not loaded properly."); + } else { + touch_init(); + } +#else + ensure(touch_init(), "Touch screen panel was not loaded properly."); +#endif +#endif #ifdef STM32U5 ensure(secret_ensure_initialized(), "secret reinitialized"); @@ -508,8 +520,6 @@ int bootloader_main(void) { rgb_led_init(); #endif - unit_variant_init(); - #if PRODUCTION && !defined STM32U5 // for STM32U5, this check is moved to boardloader check_bootloader_version(); diff --git a/core/embed/trezorhal/stm32f4/touch/ft6x36.c b/core/embed/trezorhal/stm32f4/touch/ft6x36.c index b7c59bbeb..e2729541c 100644 --- a/core/embed/trezorhal/stm32f4/touch/ft6x36.c +++ b/core/embed/trezorhal/stm32f4/touch/ft6x36.c @@ -107,7 +107,7 @@ static void touch_active_pin_state(void) { HAL_Delay(5); } -void touch_set_mode(void) { +secbool touch_set_mode(void) { // set register 0xA4 G_MODE to interrupt trigger mode (0x01). basically, CTPM // generates a pulse when new data is available uint8_t touch_panel_config[] = {0xA4, 0x01}; @@ -115,12 +115,12 @@ void touch_set_mode(void) { if (HAL_OK == i2c_transmit(TOUCH_I2C_INSTANCE, TOUCH_ADDRESS, touch_panel_config, sizeof(touch_panel_config), 10)) { - return; + return sectrue; } i2c_cycle(TOUCH_I2C_INSTANCE); } - ensure(secfalse, "Touch screen panel was not loaded properly."); + return secfalse; } void touch_power_on(void) { @@ -136,7 +136,7 @@ void touch_power_off(void) { touch_default_pin_state(); } -void touch_init(void) { +secbool touch_init(void) { GPIO_InitTypeDef GPIO_InitStructure; // PC4 capacitive touch panel module (CTPM) interrupt (INT) input @@ -147,8 +147,10 @@ void touch_init(void) { HAL_GPIO_Init(TOUCH_INT_PORT, &GPIO_InitStructure); __HAL_GPIO_EXTI_CLEAR_FLAG(TOUCH_INT_PIN); - touch_set_mode(); - touch_sensitivity(TOUCH_SENSITIVITY); + if (sectrue != touch_set_mode()) { + return secfalse; + } + return touch_sensitivity(TOUCH_SENSITIVITY); } void touch_wait_until_ready(void) { @@ -158,19 +160,19 @@ void touch_wait_until_ready(void) { } } -void touch_sensitivity(uint8_t value) { +secbool touch_sensitivity(uint8_t value) { // set panel threshold (TH_GROUP) - default value is 0x12 uint8_t touch_panel_threshold[] = {0x80, value}; for (int i = 0; i < 3; i++) { if (HAL_OK == i2c_transmit(TOUCH_I2C_INSTANCE, TOUCH_ADDRESS, touch_panel_threshold, sizeof(touch_panel_threshold), 10)) { - return; + return sectrue; } i2c_cycle(TOUCH_I2C_INSTANCE); } - ensure(secfalse, "Touch screen panel was not loaded properly."); + return secfalse; } uint32_t touch_is_detected(void) { diff --git a/core/embed/trezorhal/stm32f4/touch/stmpe811.c b/core/embed/trezorhal/stm32f4/touch/stmpe811.c index 4e21a6aa4..48889f5bb 100644 --- a/core/embed/trezorhal/stm32f4/touch/stmpe811.c +++ b/core/embed/trezorhal/stm32f4/touch/stmpe811.c @@ -470,7 +470,7 @@ void stmpe811_Reset() { IOE_Delay(2); } -void touch_init(void) { +secbool touch_init(void) { GPIO_InitTypeDef GPIO_InitStructure; __HAL_RCC_GPIOA_CLK_ENABLE(); @@ -486,9 +486,11 @@ void touch_init(void) { stmpe811_Reset(); touch_set_mode(); touch_sensitivity(0x06); + + return sectrue; } -void touch_sensitivity(uint8_t value) { +secbool touch_sensitivity(uint8_t value) { // set panel threshold (TH_GROUP) - default value is 0x12 // uint8_t touch_panel_threshold[] = {0x80, value}; // ensure(sectrue * @@ -496,6 +498,7 @@ void touch_sensitivity(uint8_t value) { // &I2c_handle, TOUCH_ADDRESS, touch_panel_threshold, // sizeof(touch_panel_threshold), 10)), // NULL); + return sectrue; } uint32_t touch_is_detected(void) { diff --git a/core/embed/trezorhal/stm32u5/common.c b/core/embed/trezorhal/stm32u5/common.c index 9b081c446..9524acb0a 100644 --- a/core/embed/trezorhal/stm32u5/common.c +++ b/core/embed/trezorhal/stm32u5/common.c @@ -49,6 +49,8 @@ uint32_t systick_val_copy = 0; extern void shutdown_privileged(void); void __attribute__((noreturn)) trezor_shutdown(void) { + display_finish_actions(); + __HAL_RCC_SAES_CLK_DISABLE(); // Erase all secrets TAMP->CR2 |= TAMP_CR2_BKERASE; diff --git a/core/embed/trezorhal/stm32u5/touch/sitronix.c b/core/embed/trezorhal/stm32u5/touch/sitronix.c index a9f4d0a43..8629558d1 100644 --- a/core/embed/trezorhal/stm32u5/touch/sitronix.c +++ b/core/embed/trezorhal/stm32u5/touch/sitronix.c @@ -1135,7 +1135,7 @@ static int32_t SITRONIX_Probe(uint32_t Instance) { #include #include "touch.h" -void touch_init(void) { +secbool touch_init(void) { TS_Init_t TsInit; /* Initialize the TouchScreen */ @@ -1145,10 +1145,12 @@ void touch_init(void) { TsInit.Accuracy = 10; BSP_TS_Init(0, &TsInit); + + return sectrue; } void touch_power_on(void) {} void touch_power_off(void) {} -void touch_sensitivity(uint8_t value) {} +secbool touch_sensitivity(uint8_t value) { return sectrue; } uint32_t touch_is_detected(void) { return sitronix_touching != 0; } diff --git a/core/embed/trezorhal/touch.h b/core/embed/trezorhal/touch.h index d56c2e4ee..2f37f442d 100644 --- a/core/embed/trezorhal/touch.h +++ b/core/embed/trezorhal/touch.h @@ -2,17 +2,18 @@ #define _TOUCH_H #include +#include "secbool.h" #define TOUCH_START (1U << 24) #define TOUCH_MOVE (1U << 25) #define TOUCH_END (1U << 26) -void touch_init(void); +secbool touch_init(void); void touch_power_on(void); void touch_power_off(void); void touch_wait_until_ready(void); -void touch_sensitivity(uint8_t value); +secbool touch_sensitivity(uint8_t value); uint32_t touch_read(void); uint32_t touch_click(void); uint32_t touch_is_detected(void); diff --git a/core/embed/trezorhal/unix/touch/touch.c b/core/embed/trezorhal/unix/touch/touch.c index 4b724c081..a5d18132f 100644 --- a/core/embed/trezorhal/unix/touch/touch.c +++ b/core/embed/trezorhal/unix/touch/touch.c @@ -217,7 +217,7 @@ uint32_t touch_read(void) { return ev_type | touch_pack_xy(ev_x, ev_y); } -void touch_init(void) {} +secbool touch_init(void) { return sectrue; } void touch_power_on(void) {} void touch_wait_until_ready(void) {}