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:
parent
0f0c28404b
commit
b9bb71a243
@ -103,14 +103,14 @@ static void drivers_deinit(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
struct BoardCapabilities capabilities
|
||||
board_capabilities_t capabilities
|
||||
__attribute__((section(".capabilities_section"))) = {
|
||||
.header = CAPABILITIES_HEADER,
|
||||
.model_tag = TAG_MODEL_NAME,
|
||||
.model_length = sizeof(uint32_t),
|
||||
.model_name = HW_MODEL,
|
||||
.version_tag = TAG_BOARDLOADER_VERSION,
|
||||
.version_length = sizeof(struct BoardloaderVersion),
|
||||
.version_length = sizeof(boardloader_version_t),
|
||||
.version = {.version_major = VERSION_MAJOR,
|
||||
.version_minor = VERSION_MINOR,
|
||||
.version_patch = VERSION_PATCH,
|
||||
|
@ -31,8 +31,8 @@ static void prodtest_boardloader_version(cli_t* cli) {
|
||||
cli_trace(cli, "Parsing boardloader capabilities...");
|
||||
parse_boardloader_capabilities();
|
||||
|
||||
const boardloader_version_t* v = get_boardloader_version();
|
||||
cli_ok(cli, "%d.%d.%d", v->version_major, v->version_minor, v->version_patch);
|
||||
boardloader_version_t v = get_boardloader_version();
|
||||
cli_ok(cli, "%d.%d.%d", v.version_major, v.version_minor, v.version_patch);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
|
@ -17,26 +17,33 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __TREZORHAL_BOARD_CAPABILITIES_H__
|
||||
#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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <trezor_types.h>
|
||||
|
||||
#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"
|
||||
|
||||
enum CapabilityTag {
|
||||
@ -46,38 +53,29 @@ enum CapabilityTag {
|
||||
TAG_BOARDLOADER_VERSION = 0x03
|
||||
};
|
||||
|
||||
typedef struct __attribute__((packed)) BoardloaderVersion {
|
||||
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 {
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t header[4];
|
||||
uint8_t model_tag;
|
||||
uint8_t model_length;
|
||||
uint32_t model_name;
|
||||
uint8_t version_tag;
|
||||
uint8_t version_length;
|
||||
struct BoardloaderVersion version;
|
||||
enum CapabilityTag terminator_tag;
|
||||
boardloader_version_t version;
|
||||
uint8_t terminator_tag;
|
||||
uint8_t terminator_length;
|
||||
};
|
||||
} board_capabilities_t;
|
||||
|
||||
/*
|
||||
* Parse capabilities into RAM. Use while boardloader is accessible,
|
||||
* before MPU is active.
|
||||
*/
|
||||
// Parses capabiilites from boardloader into RAM
|
||||
//
|
||||
// This function must be called before any other function
|
||||
// that uses the capabilities
|
||||
void parse_boardloader_capabilities();
|
||||
|
||||
const uint32_t get_board_name();
|
||||
const boardloader_version_t* get_boardloader_version();
|
||||
// Gets four bytes containing characters identifying the board
|
||||
// (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
|
||||
|
@ -27,13 +27,11 @@
|
||||
|
||||
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 boardloader_version_t *get_boardloader_version() {
|
||||
return &boardloader_version;
|
||||
}
|
||||
boardloader_version_t get_boardloader_version() { return boardloader_version; }
|
||||
|
||||
void parse_boardloader_capabilities() {
|
||||
mpu_mode_t mpu_mode = mpu_reconfig(MPU_MODE_BOARDCAPS);
|
||||
|
Loading…
Reference in New Issue
Block a user