mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
fix(core/bootloader): properly display upgrade/downgrade
This commit is contained in:
parent
d1d373a51f
commit
63c27bafd6
@ -179,30 +179,17 @@ uint32_t ui_screen_menu(void) { return screen_menu(); }
|
||||
|
||||
// install UI
|
||||
|
||||
uint32_t ui_screen_install_confirm_upgrade(const vendor_header *const vhdr,
|
||||
const image_header *const hdr) {
|
||||
uint32_t ui_screen_install_confirm(const vendor_header *const vhdr,
|
||||
const image_header *const hdr,
|
||||
secbool should_keep_seed,
|
||||
secbool is_newvendor, int version_cmp) {
|
||||
uint8_t fingerprint[32];
|
||||
char ver_str[64];
|
||||
get_image_fingerprint(hdr, fingerprint);
|
||||
format_ver("%d.%d.%d", hdr->version, ver_str, sizeof(ver_str));
|
||||
return screen_install_confirm(vhdr->vstr, vhdr->vstr_len, ver_str,
|
||||
fingerprint, false, false);
|
||||
}
|
||||
|
||||
uint32_t ui_screen_install_confirm_newvendor_or_downgrade_wipe(
|
||||
const vendor_header *const vhdr, const image_header *const hdr,
|
||||
secbool downgrade_wipe) {
|
||||
uint8_t fingerprint[32];
|
||||
char ver_str[64];
|
||||
get_image_fingerprint(hdr, fingerprint);
|
||||
format_ver("%d.%d.%d", hdr->version, ver_str, sizeof(ver_str));
|
||||
if (downgrade_wipe) {
|
||||
return screen_install_confirm(vhdr->vstr, vhdr->vstr_len, ver_str,
|
||||
fingerprint, true, false);
|
||||
} else {
|
||||
return screen_install_confirm(vhdr->vstr, vhdr->vstr_len, ver_str,
|
||||
fingerprint, false, true);
|
||||
}
|
||||
fingerprint, should_keep_seed == sectrue,
|
||||
is_newvendor == sectrue, version_cmp);
|
||||
}
|
||||
|
||||
void ui_screen_install_start() {
|
||||
|
@ -46,11 +46,10 @@ uint32_t ui_screen_intro(const vendor_header* const vhdr,
|
||||
|
||||
uint32_t ui_screen_menu(void);
|
||||
|
||||
uint32_t ui_screen_install_confirm_upgrade(const vendor_header* const vhdr,
|
||||
const image_header* const hdr);
|
||||
uint32_t ui_screen_install_confirm_newvendor_or_downgrade_wipe(
|
||||
const vendor_header* const vhdr, const image_header* const hdr,
|
||||
secbool downgrade_wipe);
|
||||
uint32_t ui_screen_install_confirm(const vendor_header* const vhdr,
|
||||
const image_header* const hdr,
|
||||
secbool shold_keep_seed,
|
||||
secbool is_newvendor, int version_cmp);
|
||||
void ui_screen_install_start();
|
||||
void ui_screen_install_progress_erase(int pos, int len);
|
||||
void ui_screen_install_progress_upload(int pos);
|
||||
|
@ -432,10 +432,10 @@ static void detect_installation(const vendor_header *current_vhdr,
|
||||
const vendor_header *const new_vhdr,
|
||||
const image_header *const new_hdr,
|
||||
secbool *is_new, secbool *is_upgrade,
|
||||
secbool *is_downgrade_wipe) {
|
||||
secbool *is_newvendor) {
|
||||
*is_new = secfalse;
|
||||
*is_upgrade = secfalse;
|
||||
*is_downgrade_wipe = secfalse;
|
||||
*is_newvendor = secfalse;
|
||||
if (sectrue != check_vendor_header_keys(current_vhdr)) {
|
||||
*is_new = sectrue;
|
||||
return;
|
||||
@ -454,10 +454,10 @@ static void detect_installation(const vendor_header *current_vhdr,
|
||||
vendor_header_hash(new_vhdr, hash1);
|
||||
vendor_header_hash(current_vhdr, hash2);
|
||||
if (0 != memcmp(hash1, hash2, 32)) {
|
||||
*is_newvendor = sectrue;
|
||||
return;
|
||||
}
|
||||
if (version_compare(new_hdr->version, current_hdr->fix_version) < 0) {
|
||||
*is_downgrade_wipe = sectrue;
|
||||
return;
|
||||
}
|
||||
*is_upgrade = sectrue;
|
||||
@ -482,8 +482,8 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
|
||||
}
|
||||
|
||||
static image_header hdr;
|
||||
secbool is_upgrade = secfalse;
|
||||
secbool is_downgrade_wipe = secfalse;
|
||||
secbool is_newvendor = secfalse;
|
||||
secbool should_keep_seed = secfalse;
|
||||
|
||||
if (firmware_block == 0) {
|
||||
if (headers_offset == 0) {
|
||||
@ -562,20 +562,17 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
|
||||
|
||||
if (is_new == secfalse) {
|
||||
detect_installation(¤t_vhdr, current_hdr, &vhdr, &hdr, &is_new,
|
||||
&is_upgrade, &is_downgrade_wipe);
|
||||
&should_keep_seed, &is_newvendor);
|
||||
}
|
||||
|
||||
uint32_t response = INPUT_CANCEL;
|
||||
if (sectrue == is_new) {
|
||||
// new installation - auto confirm
|
||||
response = INPUT_CONFIRM;
|
||||
} else if (sectrue == is_upgrade) {
|
||||
// firmware upgrade
|
||||
response = ui_screen_install_confirm_upgrade(&vhdr, &hdr);
|
||||
} else {
|
||||
// downgrade with wipe or new firmware vendor
|
||||
response = ui_screen_install_confirm_newvendor_or_downgrade_wipe(
|
||||
&vhdr, &hdr, is_downgrade_wipe);
|
||||
int version_cmp = version_compare(hdr.version, current_hdr->version);
|
||||
response = ui_screen_install_confirm(&vhdr, &hdr, should_keep_seed,
|
||||
is_newvendor, version_cmp);
|
||||
}
|
||||
|
||||
if (INPUT_CANCEL == response) {
|
||||
@ -601,7 +598,7 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
|
||||
// first block with the headers parsed -> the first chunk is now complete
|
||||
read_offset = 0;
|
||||
// if firmware is not upgrade, erase storage
|
||||
if (sectrue != is_upgrade) {
|
||||
if (sectrue != should_keep_seed) {
|
||||
ensure(
|
||||
flash_erase_sectors(STORAGE_SECTORS, STORAGE_SECTORS_COUNT, NULL),
|
||||
NULL);
|
||||
|
@ -9,8 +9,9 @@ void loader_uncompress_r(int32_t y_offset, uint16_t fg_color, uint16_t bg_color,
|
||||
|
||||
uint32_t screen_install_confirm(const char* vendor_str, uint8_t vendor_str_len,
|
||||
const char* version_str,
|
||||
const uint8_t* fingerprint, bool downgrade,
|
||||
bool vendor);
|
||||
const uint8_t* fingerprint,
|
||||
bool should_keep_seed, bool is_newvendor,
|
||||
int version_cmp);
|
||||
uint32_t screen_wipe_confirm(void);
|
||||
void screen_install_progress(int16_t progress, bool initialize,
|
||||
bool initial_setup);
|
||||
|
@ -139,8 +139,9 @@ extern "C" fn screen_install_confirm(
|
||||
vendor_str_len: u8,
|
||||
version: *const cty::c_char,
|
||||
fingerprint: *const cty::uint8_t,
|
||||
downgrade: bool,
|
||||
vendor: bool,
|
||||
should_keep_seed: bool,
|
||||
is_newvendor: bool,
|
||||
version_cmp: cty::c_int,
|
||||
) -> u32 {
|
||||
let text = unwrap!(unsafe { from_c_array(vendor_str, vendor_str_len as usize) });
|
||||
let version = unwrap!(unsafe { from_c_str(version) });
|
||||
@ -158,23 +159,25 @@ extern "C" fn screen_install_confirm(
|
||||
unwrap!(version_str.push_str("\nby "));
|
||||
unwrap!(version_str.push_str(text));
|
||||
|
||||
let title_str = if downgrade {
|
||||
"DOWNGRADE FW"
|
||||
} else if vendor {
|
||||
let title_str = if is_newvendor {
|
||||
"CHANGE FW\nVENDOR"
|
||||
} else {
|
||||
} else if version_cmp > 0 {
|
||||
"UPDATE FIRMWARE"
|
||||
} else if version_cmp == 0 {
|
||||
"REINSTALL FW"
|
||||
} else {
|
||||
"DOWNGRADE FW"
|
||||
};
|
||||
let title = Label::new(title_str, Alignment::Start, theme::TEXT_BOLD)
|
||||
.vertically_aligned(Alignment::Center);
|
||||
let msg = Label::new(version_str.as_ref(), Alignment::Start, theme::TEXT_NORMAL);
|
||||
let alert = (vendor || downgrade).then_some(Label::new(
|
||||
let alert = (!should_keep_seed).then_some(Label::new(
|
||||
"SEED WILL BE ERASED!",
|
||||
Alignment::Start,
|
||||
theme::TEXT_BOLD,
|
||||
));
|
||||
|
||||
let (left, right) = if !(vendor || downgrade) {
|
||||
let (left, right) = if should_keep_seed {
|
||||
let l = Button::with_text("CANCEL").styled(button_bld());
|
||||
let r = Button::with_text("INSTALL").styled(button_confirm());
|
||||
(l, r)
|
||||
|
Loading…
Reference in New Issue
Block a user