mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-06 10:16:07 +00:00
feat(core/prodtest): add hw-revision command and driver
This commit is contained in:
parent
a22c15663c
commit
dcf9002f00
@ -10,7 +10,7 @@ BOOTLOADER_DEVEL = ARGUMENTS.get('BOOTLOADER_DEVEL', '0') == '1'
|
||||
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
|
||||
UI_DEBUG_OVERLAY = ARGUMENTS.get('UI_DEBUG_OVERLAY', '0') == '1'
|
||||
|
||||
FEATURES_WANTED = ["input", "sbu", "nfc", "sd_card", "rgb_led", "usb", "consumption_mask", "optiga", "haptic", "tropic", "ble"]
|
||||
FEATURES_WANTED = ["input", "sbu", "nfc", "sd_card", "rgb_led", "usb", "consumption_mask", "optiga", "haptic", "tropic", "ble", "hw_revision"]
|
||||
|
||||
CCFLAGS_MOD = ''
|
||||
CPPPATH_MOD = []
|
||||
@ -108,6 +108,7 @@ SOURCE_PRODTEST = [
|
||||
'embed/projects/prodtest/cmd/prodtest_get_cpuid.c',
|
||||
'embed/projects/prodtest/cmd/prodtest_haptic.c',
|
||||
'embed/projects/prodtest/cmd/prodtest_help.c',
|
||||
'embed/projects/prodtest/cmd/prodtest_hw_revision.c',
|
||||
'embed/projects/prodtest/cmd/prodtest_nfc.c',
|
||||
'embed/projects/prodtest/cmd/prodtest_nrf.c',
|
||||
'embed/projects/prodtest/cmd/prodtest_optiga.c',
|
||||
|
@ -64,4 +64,18 @@
|
||||
#define SBU_2_PORT GPIOA
|
||||
#define SBU_2_CLK_ENA __HAL_RCC_GPIOA_CLK_ENABLE
|
||||
|
||||
#define HW_REVISION_PUPD GPIO_PULLUP
|
||||
#define HW_REVISION_0_PIN GPIO_PIN_0
|
||||
#define HW_REVISION_0_PORT GPIOF
|
||||
#define HW_REVISION_0_CLOCK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
#define HW_REVISION_1_PIN GPIO_PIN_1
|
||||
#define HW_REVISION_1_PORT GPIOF
|
||||
#define HW_REVISION_1_CLOCK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
#define HW_REVISION_2_PIN GPIO_PIN_2
|
||||
#define HW_REVISION_2_PORT GPIOF
|
||||
#define HW_REVISION_2_CLOCK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
#define HW_REVISION_3_PIN GPIO_PIN_3
|
||||
#define HW_REVISION_3_PORT GPIOF
|
||||
#define HW_REVISION_3_CLOCK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
|
||||
#endif //_TREZOR_T3B1_H
|
||||
|
@ -127,4 +127,18 @@
|
||||
#define SBU_2_PORT GPIOA
|
||||
#define SBU_2_CLK_ENA __HAL_RCC_GPIOA_CLK_ENABLE
|
||||
|
||||
#endif //_TREZOR_T_H
|
||||
#define HW_REVISION_PUPD GPIO_PULLUP
|
||||
#define HW_REVISION_0_PIN GPIO_PIN_0
|
||||
#define HW_REVISION_0_PORT GPIOF
|
||||
#define HW_REVISION_0_CLOCK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
#define HW_REVISION_1_PIN GPIO_PIN_1
|
||||
#define HW_REVISION_1_PORT GPIOF
|
||||
#define HW_REVISION_1_CLOCK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
#define HW_REVISION_2_PIN GPIO_PIN_2
|
||||
#define HW_REVISION_2_PORT GPIOF
|
||||
#define HW_REVISION_2_CLOCK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
#define HW_REVISION_3_PIN GPIO_PIN_3
|
||||
#define HW_REVISION_3_PORT GPIOF
|
||||
#define HW_REVISION_3_CLOCK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
|
||||
#endif //_TREZOR_T3T1_H
|
||||
|
@ -187,4 +187,15 @@
|
||||
#define NFC_EXTI_INTERRUPT_NUM EXTI10_IRQn
|
||||
#define NFC_EXTI_INTERRUPT_HANDLER EXTI10_IRQHandler
|
||||
|
||||
#define HW_REVISION_PUPD GPIO_PULLDOWN
|
||||
#define HW_REVISION_0_PIN GPIO_PIN_1
|
||||
#define HW_REVISION_0_PORT GPIOI
|
||||
#define HW_REVISION_0_CLOCK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
#define HW_REVISION_1_PIN GPIO_PIN_2
|
||||
#define HW_REVISION_1_PORT GPIOI
|
||||
#define HW_REVISION_1_CLOCK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
#define HW_REVISION_2_PIN GPIO_PIN_3
|
||||
#define HW_REVISION_2_PORT GPIOI
|
||||
#define HW_REVISION_2_CLOCK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
|
||||
#endif // TREZOR_T3W1_REVA_H_
|
||||
|
@ -160,4 +160,15 @@
|
||||
#define NRF_OUT_FW_RUNNING_PORT GPIOE
|
||||
#define NRF_OUT_FW_RUNNING_CLK_ENA __HAL_RCC_GPIOE_CLK_ENABLE
|
||||
|
||||
#define HW_REVISION_PUPD GPIO_PULLDOWN
|
||||
#define HW_REVISION_0_PIN GPIO_PIN_1
|
||||
#define HW_REVISION_0_PORT GPIOI
|
||||
#define HW_REVISION_0_CLOCK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
#define HW_REVISION_1_PIN GPIO_PIN_2
|
||||
#define HW_REVISION_1_PORT GPIOI
|
||||
#define HW_REVISION_1_CLOCK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
#define HW_REVISION_2_PIN GPIO_PIN_3
|
||||
#define HW_REVISION_2_PORT GPIOI
|
||||
#define HW_REVISION_2_CLOCK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
|
||||
#endif // TREZOR_T3W1_REVA_H_
|
||||
|
@ -187,4 +187,15 @@
|
||||
#define NFC_EXTI_INTERRUPT_NUM EXTI10_IRQn
|
||||
#define NFC_EXTI_INTERRUPT_HANDLER EXTI10_IRQHandler
|
||||
|
||||
#define HW_REVISION_PUPD GPIO_PULLDOWN
|
||||
#define HW_REVISION_0_PIN GPIO_PIN_1
|
||||
#define HW_REVISION_0_PORT GPIOI
|
||||
#define HW_REVISION_0_CLOCK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
#define HW_REVISION_1_PIN GPIO_PIN_2
|
||||
#define HW_REVISION_1_PORT GPIOI
|
||||
#define HW_REVISION_1_CLOCK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
#define HW_REVISION_2_PIN GPIO_PIN_3
|
||||
#define HW_REVISION_2_PORT GPIOI
|
||||
#define HW_REVISION_2_CLOCK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
|
||||
#endif // TREZOR_T3W1_REVA_H_
|
||||
|
1
core/embed/projects/prodtest/.changelog.d/4682.added
Normal file
1
core/embed/projects/prodtest/.changelog.d/4682.added
Normal file
@ -0,0 +1 @@
|
||||
[T3B1,T3T1] Added hw-revision command.
|
@ -268,6 +268,15 @@ haptic-test 3000
|
||||
OK
|
||||
```
|
||||
|
||||
### hw-revision
|
||||
Retrieves the hardware revision of the device. The command returns `OK` followed by the hardware revision.
|
||||
|
||||
Example:
|
||||
```
|
||||
hw-revision
|
||||
OK 1
|
||||
```
|
||||
|
||||
### nrf-communication
|
||||
Tests the internal communication between the main MCU and NRF MCU. The command returns `OK` if the communication is successful.
|
||||
|
||||
|
45
core/embed/projects/prodtest/cmd/prodtest_hw_revision.c
Normal file
45
core/embed/projects/prodtest/cmd/prodtest_hw_revision.c
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifdef USE_HW_REVISION
|
||||
#include <trezor_rtl.h>
|
||||
|
||||
#include <rtl/cli.h>
|
||||
#include <util/hw_revision.h>
|
||||
|
||||
static void prodtest_hw_revision(cli_t* cli) {
|
||||
uint8_t rev = hw_revision_get();
|
||||
|
||||
if (cli_arg_count(cli) > 0) {
|
||||
cli_error_arg_count(cli);
|
||||
return;
|
||||
}
|
||||
|
||||
cli_ok(cli, "%d", rev);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
|
||||
PRODTEST_CLI_CMD(
|
||||
.name = "hw-revision",
|
||||
.func = prodtest_hw_revision,
|
||||
.info = "Read the HW revision",
|
||||
.args = ""
|
||||
);
|
||||
|
||||
#endif
|
@ -86,6 +86,10 @@
|
||||
#include "cmd/prodtest_ble.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_HW_REVISION
|
||||
#include <util/hw_revision.h>
|
||||
#endif
|
||||
|
||||
#ifdef TREZOR_MODEL_T2T1
|
||||
#define MODEL_IDENTIFIER "TREZOR2-"
|
||||
#else
|
||||
@ -207,6 +211,9 @@ static void drivers_init(void) {
|
||||
#ifdef USE_TROPIC
|
||||
tropic_init();
|
||||
#endif
|
||||
#ifdef USE_HW_REVISION
|
||||
hw_revision_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
#define BACKLIGHT_NORMAL 150
|
||||
|
28
core/embed/util/hw_revision/inc/util/hw_revision.h
Normal file
28
core/embed/util/hw_revision/inc/util/hw_revision.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <trezor_types.h>
|
||||
|
||||
void hw_revision_init(void);
|
||||
|
||||
void hw_revision_deinit(void);
|
||||
|
||||
uint8_t hw_revision_get(void);
|
114
core/embed/util/hw_revision/stm32/hw_revision.c
Normal file
114
core/embed/util/hw_revision/stm32/hw_revision.c
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifdef KERNEL_MODE
|
||||
|
||||
#include <trezor_bsp.h>
|
||||
#include <trezor_model.h>
|
||||
#include <trezor_rtl.h>
|
||||
|
||||
#include <util/hw_revision.h>
|
||||
|
||||
typedef struct {
|
||||
uint8_t revision;
|
||||
bool initialized;
|
||||
} hw_revision_t;
|
||||
|
||||
static hw_revision_t g_hw_revision;
|
||||
|
||||
static uint8_t hw_revision_read(void) {
|
||||
bool rev0 =
|
||||
GPIO_PIN_SET == HAL_GPIO_ReadPin(HW_REVISION_0_PORT, HW_REVISION_0_PIN);
|
||||
bool rev1 =
|
||||
GPIO_PIN_SET == HAL_GPIO_ReadPin(HW_REVISION_1_PORT, HW_REVISION_1_PIN);
|
||||
bool rev2 =
|
||||
GPIO_PIN_SET == HAL_GPIO_ReadPin(HW_REVISION_2_PORT, HW_REVISION_2_PIN);
|
||||
bool rev3 = false;
|
||||
#ifdef HW_REVISION_3_PIN
|
||||
rev3 =
|
||||
GPIO_PIN_SET == HAL_GPIO_ReadPin(HW_REVISION_3_PORT, HW_REVISION_3_PIN);
|
||||
#endif
|
||||
|
||||
uint8_t revision = 0;
|
||||
revision |= rev0 ? 1 : 0;
|
||||
revision |= rev1 ? 2 : 0;
|
||||
revision |= rev2 ? 4 : 0;
|
||||
revision |= rev3 ? 8 : 0;
|
||||
|
||||
return revision;
|
||||
}
|
||||
|
||||
void hw_revision_init(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
|
||||
HW_REVISION_0_CLOCK_ENABLE();
|
||||
GPIO_InitStructure.Pin = HW_REVISION_0_PIN;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStructure.Pull = HW_REVISION_PUPD;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
|
||||
HAL_GPIO_Init(HW_REVISION_0_PORT, &GPIO_InitStructure);
|
||||
|
||||
HW_REVISION_1_CLOCK_ENABLE();
|
||||
GPIO_InitStructure.Pin = HW_REVISION_1_PIN;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStructure.Pull = HW_REVISION_PUPD;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
|
||||
HAL_GPIO_Init(HW_REVISION_1_PORT, &GPIO_InitStructure);
|
||||
|
||||
HW_REVISION_2_CLOCK_ENABLE();
|
||||
GPIO_InitStructure.Pin = HW_REVISION_2_PIN;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStructure.Pull = HW_REVISION_PUPD;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
|
||||
HAL_GPIO_Init(HW_REVISION_2_PORT, &GPIO_InitStructure);
|
||||
|
||||
#ifdef HW_REVISION_3_PIN
|
||||
GPIO_InitStructure.Pin = HW_REVISION_3_PIN;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStructure.Pull = HW_REVISION_PUPD;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
|
||||
HAL_GPIO_Init(HW_REVISION_3_PORT, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
memset(&g_hw_revision, 0, sizeof(hw_revision_t));
|
||||
g_hw_revision.revision = hw_revision_read();
|
||||
g_hw_revision.initialized = true;
|
||||
|
||||
// deinit the GPIOs to save power
|
||||
HAL_GPIO_DeInit(HW_REVISION_0_PORT, HW_REVISION_0_PIN);
|
||||
HAL_GPIO_DeInit(HW_REVISION_1_PORT, HW_REVISION_1_PIN);
|
||||
HAL_GPIO_DeInit(HW_REVISION_2_PORT, HW_REVISION_2_PIN);
|
||||
#ifdef HW_REVISION_3_PIN
|
||||
HAL_GPIO_DeInit(HW_REVISION_3_PORT, HW_REVISION_3_PIN);
|
||||
#endif
|
||||
}
|
||||
|
||||
void hw_revision_deinit(void) {
|
||||
memset(&g_hw_revision, 0, sizeof(hw_revision_t));
|
||||
}
|
||||
|
||||
uint8_t hw_revision_get(void) {
|
||||
hw_revision_t *hw_revision = &g_hw_revision;
|
||||
if (!hw_revision->initialized) {
|
||||
hw_revision_init();
|
||||
}
|
||||
|
||||
return hw_revision->revision;
|
||||
}
|
||||
|
||||
#endif
|
@ -96,6 +96,11 @@ def configure(
|
||||
paths += ["embed/sec/consumption_mask/inc"]
|
||||
defines += [("USE_CONSUMPTION_MASK", "1")]
|
||||
|
||||
if "hw_revision" in features_wanted:
|
||||
defines += [("USE_HW_REVISION", "1")]
|
||||
paths += ["embed/util/hw_revision/inc"]
|
||||
sources += ["embed/util/hw_revision/stm32/hw_revision.c"]
|
||||
|
||||
defines += [
|
||||
("USE_HASH_PROCESSOR", "1"),
|
||||
("USE_STORAGE_HWKEY", "1"),
|
||||
|
@ -129,6 +129,11 @@ def configure(
|
||||
features_available.append("optiga")
|
||||
defines += [("USE_OPTIGA", "1")]
|
||||
|
||||
if "hw_revision" in features_wanted:
|
||||
defines += [("USE_HW_REVISION", "1")]
|
||||
paths += ["embed/util/hw_revision/inc"]
|
||||
sources += ["embed/util/hw_revision/stm32/hw_revision.c"]
|
||||
|
||||
defines += [
|
||||
("USE_HASH_PROCESSOR", "1"),
|
||||
("USE_STORAGE_HWKEY", "1"),
|
||||
|
@ -189,6 +189,11 @@ def configure(
|
||||
paths += ["embed/io/usb/inc"]
|
||||
defines += [("USE_USB", "1")]
|
||||
|
||||
if "hw_revision" in features_wanted:
|
||||
defines += [("USE_HW_REVISION", "1")]
|
||||
paths += ["embed/util/hw_revision/inc"]
|
||||
sources += ["embed/util/hw_revision/stm32/hw_revision.c"]
|
||||
|
||||
defines += [
|
||||
"FRAMEBUFFER",
|
||||
"DISPLAY_RGBA8888",
|
||||
|
Loading…
Reference in New Issue
Block a user