diff --git a/core/embed/prodtest/.changelog.d/3752.added b/core/embed/prodtest/.changelog.d/3752.added new file mode 100644 index 0000000000..76748afb30 --- /dev/null +++ b/core/embed/prodtest/.changelog.d/3752.added @@ -0,0 +1 @@ +Added commands to read bootloader and boardloader versions diff --git a/core/embed/prodtest/README.md b/core/embed/prodtest/README.md index e9302da623..64d6eb4ced 100644 --- a/core/embed/prodtest/README.md +++ b/core/embed/prodtest/README.md @@ -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 `..`. + +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 `..`. + +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. diff --git a/core/embed/prodtest/main.c b/core/embed/prodtest/main.c index 3a92daf402..d5215a7d30 100644 --- a/core/embed/prodtest/main.c +++ b/core/embed/prodtest/main.c @@ -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")) { diff --git a/core/embed/trezorhal/board_capabilities.h b/core/embed/trezorhal/board_capabilities.h index e7465960b0..66a4c28f59 100644 --- a/core/embed/trezorhal/board_capabilities.h +++ b/core/embed/trezorhal/board_capabilities.h @@ -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 diff --git a/core/embed/trezorhal/stm32f4/board_capabilities.c b/core/embed/trezorhal/stm32f4/board_capabilities.c index 7560aaf3af..c867c87cdc 100644 --- a/core/embed/trezorhal/stm32f4/board_capabilities.c +++ b/core/embed/trezorhal/stm32f4/board_capabilities.c @@ -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; }