mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-19 05:58:09 +00:00
feat(core/prodtest): add commands to read bootloader and boardloader versions
This commit is contained in:
parent
e30fe7769a
commit
b37971eea4
1
core/embed/prodtest/.changelog.d/3752.added
Normal file
1
core/embed/prodtest/.changelog.d/3752.added
Normal file
@ -0,0 +1 @@
|
||||
Added commands to read bootloader and boardloader versions
|
@ -282,6 +282,26 @@ FIRMWARE VERSION
|
||||
OK 0.2.6
|
||||
```
|
||||
|
||||
### BOOTLOADER VERSION
|
||||
Returns the version of the bootlaoder.
|
||||
The command returns `OK` followed by the version in the format `<major>.<minor>.<patch>`.
|
||||
|
||||
Example:
|
||||
```
|
||||
BOOTLOADER_VERSION
|
||||
OK 2.1.7
|
||||
```
|
||||
|
||||
### BOARDLOADER VERSION
|
||||
Returns the version of the boardloader.
|
||||
The command returns `OK` followed by the version in the format `<major>.<minor>.<patch>`.
|
||||
|
||||
Example:
|
||||
```
|
||||
FIRMWARE VERSION
|
||||
OK 0.2.6
|
||||
```
|
||||
|
||||
### WIPE
|
||||
This command invalidates the current firmware in the flash memory by erasing its beginning, including metadata.
|
||||
After performing this operation, it displays the text "WIPED" on the screen and returns the response OK.
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include STM32_HAL_H
|
||||
|
||||
#include "board_capabilities.h"
|
||||
#include "button.h"
|
||||
#include "common.h"
|
||||
#include "display.h"
|
||||
@ -591,6 +592,32 @@ static void test_firmware_version(void) {
|
||||
vcp_println("OK %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
|
||||
}
|
||||
|
||||
static uint32_t read_bootloader_version(void) {
|
||||
const image_header *header = read_image_header(
|
||||
(const uint8_t *)BOOTLOADER_START, BOOTLOADER_IMAGE_MAGIC, 0xffffffff);
|
||||
|
||||
if (secfalse == header) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return header->version;
|
||||
}
|
||||
|
||||
static void test_bootloader_version(uint32_t version) {
|
||||
vcp_println("OK %d.%d.%d", version & 0xFF, (version >> 8) & 0xFF,
|
||||
(version >> 16) & 0xFF);
|
||||
}
|
||||
|
||||
static const boardloader_version_t *read_boardloader_version(void) {
|
||||
parse_boardloader_capabilities();
|
||||
return get_boardloader_version();
|
||||
}
|
||||
|
||||
static void test_boardloader_version(const boardloader_version_t *version) {
|
||||
vcp_println("OK %d.%d.%d", version->version_major, version->version_minor,
|
||||
version->version_patch);
|
||||
}
|
||||
|
||||
static void test_wipe(void) {
|
||||
invalidate_firmware();
|
||||
display_clear();
|
||||
@ -778,6 +805,9 @@ int main(void) {
|
||||
#endif
|
||||
usb_init_all();
|
||||
|
||||
uint32_t bootloader_version = read_bootloader_version();
|
||||
const boardloader_version_t *boardloader_version = read_boardloader_version();
|
||||
|
||||
mpu_config_prodtest_initial();
|
||||
|
||||
#ifdef USE_OPTIGA
|
||||
@ -897,7 +927,10 @@ int main(void) {
|
||||
|
||||
} else if (startswith(line, "FIRMWARE VERSION")) {
|
||||
test_firmware_version();
|
||||
|
||||
} else if (startswith(line, "BOOTLOADER VERSION")) {
|
||||
test_bootloader_version(bootloader_version);
|
||||
} else if (startswith(line, "BOARDLOADER VERSION")) {
|
||||
test_boardloader_version(boardloader_version);
|
||||
} else if (startswith(line, "WIPE")) {
|
||||
test_wipe();
|
||||
} else if (startswith(line, "REBOOT")) {
|
||||
|
@ -45,12 +45,12 @@ enum CapabilityTag {
|
||||
TAG_BOARDLOADER_VERSION = 0x03
|
||||
};
|
||||
|
||||
struct __attribute__((packed)) BoardloaderVersion {
|
||||
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,
|
||||
@ -75,6 +75,6 @@ struct __attribute__((packed)) BoardCapabilities {
|
||||
void parse_boardloader_capabilities();
|
||||
|
||||
const uint32_t get_board_name();
|
||||
const struct BoardloaderVersion* get_boardloader_version();
|
||||
const boardloader_version_t* get_boardloader_version();
|
||||
|
||||
#endif
|
||||
|
@ -28,7 +28,7 @@ static struct BoardloaderVersion boardloader_version;
|
||||
|
||||
const uint32_t get_board_name() { return board_name; }
|
||||
|
||||
const struct BoardloaderVersion *get_boardloader_version() {
|
||||
const boardloader_version_t *get_boardloader_version() {
|
||||
return &boardloader_version;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user