1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-05-28 19:58:45 +00:00

refactor(core): prepare board_capabilities for secmon api

[no changelog]
This commit is contained in:
cepetr 2025-05-07 16:17:07 +02:00 committed by cepetr
parent 0f0c28404b
commit b9bb71a243
4 changed files with 42 additions and 46 deletions

View File

@ -103,14 +103,14 @@ static void drivers_deinit(void) {
#endif #endif
} }
struct BoardCapabilities capabilities board_capabilities_t capabilities
__attribute__((section(".capabilities_section"))) = { __attribute__((section(".capabilities_section"))) = {
.header = CAPABILITIES_HEADER, .header = CAPABILITIES_HEADER,
.model_tag = TAG_MODEL_NAME, .model_tag = TAG_MODEL_NAME,
.model_length = sizeof(uint32_t), .model_length = sizeof(uint32_t),
.model_name = HW_MODEL, .model_name = HW_MODEL,
.version_tag = TAG_BOARDLOADER_VERSION, .version_tag = TAG_BOARDLOADER_VERSION,
.version_length = sizeof(struct BoardloaderVersion), .version_length = sizeof(boardloader_version_t),
.version = {.version_major = VERSION_MAJOR, .version = {.version_major = VERSION_MAJOR,
.version_minor = VERSION_MINOR, .version_minor = VERSION_MINOR,
.version_patch = VERSION_PATCH, .version_patch = VERSION_PATCH,

View File

@ -31,8 +31,8 @@ static void prodtest_boardloader_version(cli_t* cli) {
cli_trace(cli, "Parsing boardloader capabilities..."); cli_trace(cli, "Parsing boardloader capabilities...");
parse_boardloader_capabilities(); parse_boardloader_capabilities();
const boardloader_version_t* v = get_boardloader_version(); boardloader_version_t v = get_boardloader_version();
cli_ok(cli, "%d.%d.%d", v->version_major, v->version_minor, v->version_patch); cli_ok(cli, "%d.%d.%d", v.version_major, v.version_minor, v.version_patch);
} }
// clang-format off // clang-format off

View File

@ -17,26 +17,33 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __TREZORHAL_BOARD_CAPABILITIES_H__ #pragma once
#define __TREZORHAL_BOARD_CAPABILITIES_H__
/*
Simple key-tag-length-value structure at fixed boardloader address.
* header 4 bytes `TRZC`
* each field is 4 bytes or multiple (because of alignment)
* 4 bytes are
* 1-byte tag+type - CapabilityTag
* 1 byte length - counting from next byte forward
* 0 or more bytes of data, doesn't have to be aligned
Last tag must be terminator or all space used.
*/
#include <trezor_types.h> #include <trezor_types.h>
#ifdef KERNEL_MODE #ifdef KERNEL_MODE
typedef struct __attribute__((packed)) {
uint8_t version_major;
uint8_t version_minor;
uint8_t version_patch;
uint8_t version_build;
} boardloader_version_t;
// Structure holding board capabilities.
// Older boardloaders can have it missing or reordered.
//
// Simple key-tag-length-value structure at fixed boardloader address.
//
// header 4 bytes `TRZC`
// each field is 4 bytes or multiple (because of alignment)
// 4 bytes are
// 1-byte tag+type - CapabilityTag
// 1 byte length - counting from next byte forward
// 0 or more bytes of data, doesn't have to be aligned
//
// Last tag must be terminator or all space used.
#define CAPABILITIES_HEADER "TRZC" #define CAPABILITIES_HEADER "TRZC"
enum CapabilityTag { enum CapabilityTag {
@ -46,38 +53,29 @@ enum CapabilityTag {
TAG_BOARDLOADER_VERSION = 0x03 TAG_BOARDLOADER_VERSION = 0x03
}; };
typedef struct __attribute__((packed)) BoardloaderVersion { typedef struct __attribute__((packed)) {
uint8_t version_major;
uint8_t version_minor;
uint8_t version_patch;
uint8_t version_build;
} boardloader_version_t;
/*
* Structure of current boardloader. Older boardloaders can have it missing,
* reordered.
*/
struct __attribute__((packed)) BoardCapabilities {
uint8_t header[4]; uint8_t header[4];
uint8_t model_tag; uint8_t model_tag;
uint8_t model_length; uint8_t model_length;
uint32_t model_name; uint32_t model_name;
uint8_t version_tag; uint8_t version_tag;
uint8_t version_length; uint8_t version_length;
struct BoardloaderVersion version; boardloader_version_t version;
enum CapabilityTag terminator_tag; uint8_t terminator_tag;
uint8_t terminator_length; uint8_t terminator_length;
}; } board_capabilities_t;
/* // Parses capabiilites from boardloader into RAM
* Parse capabilities into RAM. Use while boardloader is accessible, //
* before MPU is active. // This function must be called before any other function
*/ // that uses the capabilities
void parse_boardloader_capabilities(); void parse_boardloader_capabilities();
const uint32_t get_board_name(); // Gets four bytes containing characters identifying the board
const boardloader_version_t* get_boardloader_version(); // (e.g. `T3T1` for Trezor Safe 5)
uint32_t get_board_name();
// Gets the boardloader version
boardloader_version_t get_boardloader_version();
#endif // KERNEL_MODE #endif // KERNEL_MODE
#endif

View File

@ -27,13 +27,11 @@
static uint32_t board_name = 0; static uint32_t board_name = 0;
static struct BoardloaderVersion boardloader_version; static boardloader_version_t boardloader_version = {0};
const uint32_t get_board_name() { return board_name; } const uint32_t get_board_name() { return board_name; }
const boardloader_version_t *get_boardloader_version() { boardloader_version_t get_boardloader_version() { return boardloader_version; }
return &boardloader_version;
}
void parse_boardloader_capabilities() { void parse_boardloader_capabilities() {
mpu_mode_t mpu_mode = mpu_reconfig(MPU_MODE_BOARDCAPS); mpu_mode_t mpu_mode = mpu_reconfig(MPU_MODE_BOARDCAPS);