Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions legacy/bootloader/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ static void handle_error(usbd_device *dev, uint8_t error_code,
const char *line1, const char *line2);
static void get_current_mcu_info(uint32_t *version, uint32_t *purpose);
static secbool check_mcu_downgrade(usbd_device *dev, uint32_t new_version,
uint32_t current_version);
uint32_t current_version,
uint32_t new_purpose,
uint32_t current_purpose);
static secbool check_se_minimum_version(usbd_device *dev,
uint32_t se_minimum_version,
uint32_t latest_se_version);
Expand Down Expand Up @@ -279,10 +281,18 @@ static void get_current_mcu_info(uint32_t *version, uint32_t *purpose) {

// Helper: Check MCU downgrade
static secbool check_mcu_downgrade(usbd_device *dev, uint32_t new_version,
uint32_t current_version) {
uint32_t current_version,
uint32_t new_purpose,
uint32_t current_purpose) {
if (current_version > 0) {
int version_diff = version_compare(new_version, current_version);
if (version_diff < 0) {
// Only allow MCU downgrade when switching General -> BTC-only.
if (current_purpose == FIRMWARE_PURPOSE_GENERAL &&
new_purpose == FIRMWARE_PURPOSE_BTC_ONLY) {
return sectrue;
}

handle_error(dev, FAILURE_PROCESS_ERROR, "Firmware downgrade",
"not allowed.");
return secfalse;
Expand Down Expand Up @@ -724,7 +734,8 @@ static secbool process_new_format_upgrade_header(usbd_device *dev) {
if (upgrade_hdr->flags & UPGRADE_FLAG_MCU_PRESENT) {
// Check downgrade
if (check_mcu_downgrade(dev, upgrade_hdr->mcu_info.version,
current_mcu_version) != sectrue) {
current_mcu_version, upgrade_hdr->mcu_info.purpose,
current_mcu_purpose) != sectrue) {
return secfalse;
}

Expand Down Expand Up @@ -781,7 +792,8 @@ static secbool process_old_format_upgrade_header(usbd_device *dev) {

// Check downgrade
if (check_mcu_downgrade(dev, firmware_hdr->onekey_version,
current_mcu_version) != sectrue) {
current_mcu_version, firmware_hdr->purpose,
current_mcu_purpose) != sectrue) {
return secfalse;
}

Expand Down
2 changes: 1 addition & 1 deletion legacy/bootloader/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define VERSION_MAJOR 2
#define VERSION_MINOR 1
#define VERSION_PATCH 1
#define VERSION_PATCH 2
16 changes: 16 additions & 0 deletions legacy/firmware/bl_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ char bootloader_version[8] = {0};
static int known_bootloader(int r, const uint8_t *hash) {
if (r != 32) return 0;
// BEGIN AUTO-GENERATED QA BOOTLOADER ENTRIES (bl_check_qa.txt)
if (0 ==
memcmp(hash,
"\x56\x34\x5a\x66\x45\xb0\x60\x9f\x43\x0e\x5c\x6b\x34\x90\x8f\xd8"
"\xa4\x12\x04\x9c\x2b\x30\x8c\x91\xc5\xac\x07\x26\x5a\x04\x45\xe5",
32)) {
memcpy(bootloader_version, "2.1.2", strlen("2.1.2"));
return 1; // 2.1.2 shipped with fw 3.18.0
}
if (0 ==
memcmp(hash,
"\x92\x2a\xcb\x7f\xb9\x3a\xa3\x6e\x1d\xb4\xb5\x89\x2a\xdc\x4e\xed"
Expand Down Expand Up @@ -85,6 +93,14 @@ static int known_bootloader(int r, const uint8_t *hash) {
static int known_bootloader(int r, const uint8_t *hash) {
if (r != 32) return 0;
// BEGIN AUTO-GENERATED BOOTLOADER ENTRIES (bl_check.txt)
if (0 ==
memcmp(hash,
"\xc9\xbe\x0f\xdf\x3f\x44\x13\xca\xb9\xf1\x84\xd3\xab\x1a\x27\x90"
"\xa3\x55\x31\x10\x72\xcd\xbc\xef\x1d\x10\xf4\x1d\xd9\x35\xbb\x8d",
32)) {
memcpy(bootloader_version, "2.1.2", strlen("2.1.2"));
return 1; // 2.1.2 shipped with fw 3.18.0
}
if (0 ==
memcmp(hash,
"\x7f\xc0\xaf\x68\xa4\x27\x5d\xbe\xf6\xd4\x42\x53\x63\xef\x3a\xe5"
Expand Down
1 change: 1 addition & 0 deletions legacy/firmware/bl_check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ f6985aa0f3cf4a6285ff4c6335bb6bf194820d3f49b861b7b5ef8b9e09073255 2.0.7 shipped w
28bcd946abf77e69e7f5db4d1867db11aa1f2a46801e5da2fa4d88c8e5555d8a 2.0.8 shipped with fw 3.11.0
d549aafcd0708d5e97542ff215e67357ad2840d8a5381444b213998a8473c03f 2.1.0 shipped with fw 3.15.0
7fc0af68a4275dbef6d4425363ef3ae5d2eb023c99c91123a96e2c1cea26300f 2.1.1 shipped with fw 3.16.0
c9be0fdf3f4413cab9f184d3ab1a2790a355311072cdbcef1d10f41dd935bb8d 2.1.2 shipped with fw 3.18.0
1 change: 1 addition & 0 deletions legacy/firmware/bl_check_qa.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ f1d184fe18f406a38edec9829b981d56cd71ca3d7b7169d1e4f88a8c5a643ac1 2.0.7 shipped w
5e4eb922a24fb37c3970e07753013d679054c930dc682929eac4771b03c2c8df 2.0.8 shipped with fw 3.11.0
c31d2a0333accf663bcbc94658c12cf2be93dccdae790062621fa1a27fbdfbcb 2.1.0 shipped with fw 3.15.0
922acb7fb93aa36e1db4b5892adc4eed557e8305782e74cd08aa4712106edcb4 2.1.1 shipped with fw 3.16.0
56345a6645b0609f430e5c6b34908fd8a412049c2b308c91c5ac07265a0445e5 2.1.2 shipped with fw 3.18.0
Binary file modified legacy/firmware/bootloader.dat
Binary file not shown.
Binary file modified legacy/firmware/bootloader_qa.dat
Binary file not shown.
Loading