Skip to content

Commit

Permalink
feat(core/prodtest): add tropic01 HAL integration and basic productio…
Browse files Browse the repository at this point in the history
…n tests

[no changelog]
  • Loading branch information
TychoVrahe committed Feb 14, 2025
1 parent de73b38 commit f21ffe9
Show file tree
Hide file tree
Showing 12 changed files with 522 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
[submodule "vendor/stm32u5xx_hal_driver"]
path = vendor/stm32u5xx_hal_driver
url = https://github.com/trezor/stm32u5xx_hal_driver.git
[submodule "vendor/libtropic"]
path = vendor/libtropic
url = https://github.com/tropicsquare/libtropic.git
3 changes: 2 additions & 1 deletion core/SConscript.prodtest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ PRODUCTION = ARGUMENTS.get('PRODUCTION', '0') == '1'
BOOTLOADER_DEVEL = ARGUMENTS.get('BOOTLOADER_DEVEL', '0') == '1'
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)

FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led", "usb", "consumption_mask", "optiga", "haptic"]
FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led", "usb", "consumption_mask", "optiga", "haptic", "tropic"]

CCFLAGS_MOD = ''
CPPPATH_MOD = []
Expand Down Expand Up @@ -117,6 +117,7 @@ SOURCE_PRODTEST = [
'embed/projects/prodtest/cmd/prodtest_sdcard.c',
'embed/projects/prodtest/cmd/prodtest_sbu.c',
'embed/projects/prodtest/cmd/prodtest_touch.c',
'embed/projects/prodtest/cmd/prodtest_tropic.c',
'embed/projects/prodtest/cmd/prodtest_wpc.c',
]

Expand Down
32 changes: 32 additions & 0 deletions core/embed/projects/prodtest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,35 @@ powerctl-hibernate
# Device is powered externally, hibernation is not possible.
OK
```


## Tropic
### tropic-get-riscv-fw-version

Reads the version of the RISC-V firmware. The command returns `OK` followed by the version.

Example:
```
tropic-get-riscv-fw-version
OK 00020100
```

### tropic-get-spect-fw-version

Reads the version of the SPECT firmware. The command returns `OK` followed by the version.

Example:
```
tropic-get-spect-fw-version
OK 00000300
```

### tropic-get-chip-id

Reads the Tropic chip ID. The command returns `OK` followed by the chip ID.

Example:
```
tropic-get-chip-id
OK 00000001000000000000000000000000000000000000000000000000000000000000000001000000054400000000FFFFFFFFFFFF01F00F000544545354303103001300000B54524F50494330312D4553FFFFFFFF000100000000FFFF000100000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF13000300
```
98 changes: 98 additions & 0 deletions core/embed/projects/prodtest/cmd/prodtest_tropic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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_TROPIC

#include <trezor_rtl.h>

#include <rtl/cli.h>
#include <sec/tropic.h>

static void prodtest_tropic_get_riscv_fw_version(cli_t* cli) {
if (cli_arg_count(cli) > 0) {
cli_error_arg_count(cli);
return;
}

uint8_t version[LT_L2_GET_INFO_RISCV_FW_SIZE];
if (!tropic_get_riscv_fw_version(version, sizeof(version))) {
cli_error(cli, CLI_ERROR, "Unable to get RISCV FW version");
}

// Respond with an OK message and version
cli_ok_hexdata(cli, &version, sizeof(version));
}

static void prodtest_tropic_get_spect_fw_version(cli_t* cli) {
if (cli_arg_count(cli) > 0) {
cli_error_arg_count(cli);
return;
}

uint8_t version[LT_L2_GET_INFO_SPECT_FW_SIZE];
if (!tropic_get_spect_fw_version(version, sizeof(version))) {
cli_error(cli, CLI_ERROR, "Unable to get SPECT FW version");
}

// Respond with an OK message and version
cli_ok_hexdata(cli, &version, sizeof(version));
}

static void prodtest_tropic_get_chip_id(cli_t* cli) {
if (cli_arg_count(cli) > 0) {
cli_error_arg_count(cli);
return;
}

uint8_t chip_id[LT_L2_GET_INFO_CHIP_ID_SIZE];
if (!tropic_get_chip_id(chip_id, sizeof(chip_id))) {
cli_error(cli, CLI_ERROR, "Unable to get CHIP ID");
}

// Respond with an OK message and chip ID
cli_ok_hexdata(cli, &chip_id, sizeof(chip_id));
}

// clang-format off

PRODTEST_CLI_CMD(
.name = "tropic-get-riscv-fw-version",
.func = prodtest_tropic_get_riscv_fw_version,
.info = "Get RISCV FW version",
.args = ""
);

PRODTEST_CLI_CMD(
.name = "tropic-get-spect-fw-version",
.func = prodtest_tropic_get_spect_fw_version,
.info = "Get SPECT FW version",
.args = ""
);

PRODTEST_CLI_CMD(
.name = "tropic-get-chip-id",
.func = prodtest_tropic_get_chip_id,
.info = "Get Tropic CHIP ID",
.args = ""
);




#endif
7 changes: 7 additions & 0 deletions core/embed/projects/prodtest/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
#include "cmd/prodtest_optiga.h"
#endif

#ifdef USE_TROPIC
#include <sec/tropic.h>
#endif

#ifdef USE_HAPTIC
#include <io/haptic.h>
#endif
Expand Down Expand Up @@ -185,6 +189,9 @@ static void drivers_init(void) {
#ifdef USE_RGB_LED
rgb_led_init();
#endif
#ifdef USE_TROPIC
tropic_init();
#endif
}

#define BACKLIGHT_NORMAL 150
Expand Down
34 changes: 34 additions & 0 deletions core/embed/sec/tropic/inc/sec/tropic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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>

#include <libtropic.h>

bool tropic_init(void);

void tropic_deinit(void);

bool tropic_get_spect_fw_version(uint8_t* version_buffer, uint16_t max_len);

bool tropic_get_riscv_fw_version(uint8_t* version_buffer, uint16_t max_len);

bool tropic_get_chip_id(uint8_t* chip_id, uint16_t max_len);
Loading

0 comments on commit f21ffe9

Please sign in to comment.