From ba065c5b38f60cac37586982b2ae8b6ed51bded6 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Wed, 27 Mar 2024 09:42:43 +0100 Subject: [PATCH] fix(core/prodtest): do not require sd detect pin for running SD card test [no changelog] --- core/embed/prodtest/main.c | 7 ++++++- core/embed/trezorhal/sdcard.h | 1 + core/embed/trezorhal/stm32f4/sdcard.c | 13 +++++++++---- core/embed/trezorhal/stm32u5/sdcard.c | 13 +++++++++---- core/embed/trezorhal/unix/sdcard.c | 4 +++- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/core/embed/prodtest/main.c b/core/embed/prodtest/main.c index 331173a740..c6a7144d45 100644 --- a/core/embed/prodtest/main.c +++ b/core/embed/prodtest/main.c @@ -402,12 +402,17 @@ static void test_sd(void) { static uint32_t buf1[BLOCK_SIZE / sizeof(uint32_t)]; static uint32_t buf2[BLOCK_SIZE / sizeof(uint32_t)]; +#ifndef TREZOR_MODEL_T3T1 if (sectrue != sdcard_is_present()) { vcp_println("ERROR NOCARD"); return; } +#endif - ensure(sdcard_power_on(), NULL); + if (sectrue != sdcard_power_on_unchecked()) { + vcp_println("ERROR POWER ON"); + return; + } if (sectrue != sdcard_read_blocks(buf1, 0, BLOCK_SIZE / SDCARD_BLOCK_SIZE)) { vcp_println("ERROR sdcard_read_blocks (0)"); goto power_off; diff --git a/core/embed/trezorhal/sdcard.h b/core/embed/trezorhal/sdcard.h index 3952f8d29c..8e76740991 100644 --- a/core/embed/trezorhal/sdcard.h +++ b/core/embed/trezorhal/sdcard.h @@ -52,6 +52,7 @@ #define SDCARD_BLOCK_SIZE (512) void sdcard_init(void); +secbool __wur sdcard_power_on_unchecked(void); secbool __wur sdcard_power_on(void); void sdcard_power_off(void); secbool __wur sdcard_is_present(void); diff --git a/core/embed/trezorhal/stm32f4/sdcard.c b/core/embed/trezorhal/stm32f4/sdcard.c index 023c66437b..c4d26e481d 100644 --- a/core/embed/trezorhal/stm32f4/sdcard.c +++ b/core/embed/trezorhal/stm32f4/sdcard.c @@ -148,10 +148,7 @@ void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd) { } } -secbool sdcard_power_on(void) { - if (sectrue != sdcard_is_present()) { - return secfalse; - } +secbool sdcard_power_on_unchecked(void) { if (sd_handle.Instance) { return sectrue; } @@ -200,6 +197,14 @@ error: return secfalse; } +secbool sdcard_power_on(void) { + if (sectrue != sdcard_is_present()) { + return secfalse; + } + + return sdcard_power_on_unchecked(); +} + void sdcard_power_off(void) { if (sd_handle.Instance) { HAL_SD_DeInit(&sd_handle); diff --git a/core/embed/trezorhal/stm32u5/sdcard.c b/core/embed/trezorhal/stm32u5/sdcard.c index fd1058531a..dfcac39437 100644 --- a/core/embed/trezorhal/stm32u5/sdcard.c +++ b/core/embed/trezorhal/stm32u5/sdcard.c @@ -152,10 +152,7 @@ void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd) { } } -secbool sdcard_power_on(void) { - if (sectrue != sdcard_is_present()) { - return secfalse; - } +secbool sdcard_power_on_unchecked(void) { if (sd_handle.Instance) { return sectrue; } @@ -203,6 +200,14 @@ error: return secfalse; } +secbool sdcard_power_on(void) { + if (sectrue != sdcard_is_present()) { + return secfalse; + } + + return sdcard_power_on_unchecked(); +} + void sdcard_power_off(void) { if (sd_handle.Instance) { HAL_SD_DeInit(&sd_handle); diff --git a/core/embed/trezorhal/unix/sdcard.c b/core/embed/trezorhal/unix/sdcard.c index c06e7a3b49..6f083c3931 100644 --- a/core/embed/trezorhal/unix/sdcard.c +++ b/core/embed/trezorhal/unix/sdcard.c @@ -87,12 +87,14 @@ void sdcard_init(void) { secbool sdcard_is_present(void) { return sectrue; } -secbool sdcard_power_on(void) { +secbool sdcard_power_on_unchecked(void) { sdcard_init(); sdcard_powered = sectrue; return sectrue; } +secbool sdcard_power_on(void) { return sdcard_power_on_unchecked(); } + void sdcard_power_off(void) { sdcard_powered = secfalse; } uint64_t sdcard_get_capacity_in_bytes(void) {