diff --git a/core/embed/rust/src/ui/model_tr/bootloader/mod.rs b/core/embed/rust/src/ui/model_tr/bootloader/mod.rs index f2db761929f..3941e067e97 100644 --- a/core/embed/rust/src/ui/model_tr/bootloader/mod.rs +++ b/core/embed/rust/src/ui/model_tr/bootloader/mod.rs @@ -41,241 +41,49 @@ impl ReturnToC for ConfirmMsg { } } -fn screen_install_confirm( - vendor_str: &str, - version: &str, - fingerprint: &str, - should_keep_seed: bool, - is_newvendor: bool, - version_cmp: i32, -) -> u32 { - let mut version_str: BootloaderString = String::new(); - unwrap!(version_str.push_str("Firmware version ")); - unwrap!(version_str.push_str(version)); - unwrap!(version_str.push_str("\nby ")); - unwrap!(version_str.push_str(vendor_str)); - - let title_str = if is_newvendor { - "CHANGE FW VENDOR" - } else if version_cmp > 0 { - "UPDATE FIRMWARE" - } else if version_cmp == 0 { - "REINSTALL FW" - } else { - "DOWNGRADE FW" - }; - - let message = Label::left_aligned(version_str.as_str(), TEXT_NORMAL).vertically_centered(); - let fingerprint = Label::left_aligned( - fingerprint, - TEXT_NORMAL.with_line_breaking(BreakWordsNoHyphen), - ) - .vertically_centered(); - - let alert = - (!should_keep_seed).then_some(Label::left_aligned("Seed will be erased!", TEXT_NORMAL)); - - let mut frame = Confirm::new(BLD_BG, title_str, message, alert, "INSTALL", false) - .with_info_screen("FW FINGERPRINT", fingerprint); - run(&mut frame) -} - -fn screen_wipe_confirm() -> u32 { - let message = - Label::left_aligned("Seed and firmware will be erased!", TEXT_NORMAL).vertically_centered(); - - let mut frame = Confirm::new(BLD_BG, "FACTORY RESET", message, None, "RESET", false); - - run(&mut frame) -} - -fn screen_unlock_bootloader_confirm() -> u32 { - let message = - Label::left_aligned("This action cannot be undone!", TEXT_NORMAL).vertically_centered(); - - let mut frame = Confirm::new(BLD_BG, "UNLOCK BOOTLOADER?", message, None, "UNLOCK", true); - - run(&mut frame) -} - -fn screen_unlock_bootloader_success() { - let title = Label::centered("Bootloader unlocked", TEXT_BOLD).vertically_centered(); - - let content = - Label::centered("Please reconnect the\ndevice", TEXT_NORMAL).vertically_centered(); - - let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_SPINNER, title, content, true); - show(&mut frame, false); -} - -fn screen_menu(firmware_present: secbool) -> u32 { - run(&mut Menu::new(firmware_present)) -} - -fn screen_intro(bld_version: &str, vendor: &str, version: &str, fw_ok: bool) -> u32 { - let mut title_str: BootloaderString = String::new(); - unwrap!(title_str.push_str("BOOTLOADER ")); - unwrap!(title_str.push_str(bld_version)); - - let mut version_str: BootloaderString = String::new(); - unwrap!(version_str.push_str("Firmware version ")); - unwrap!(version_str.push_str(version)); - unwrap!(version_str.push_str("\nby ")); - unwrap!(version_str.push_str(vendor)); - - let mut frame = Intro::new(title_str.as_str(), version_str.as_str(), fw_ok); - run(&mut frame) -} - -fn screen_progress( - text: &str, - text2: &str, - progress: u16, - initialize: bool, - fg_color: Color, - bg_color: Color, - icon: Option<(Icon, Color)>, -) { - if initialize { - display::rect_fill(SCREEN, bg_color); - } - - let progress = if progress < 20 { 20 } else { progress }; - - display::rect_rounded2_partial( - Rect::new( - SCREEN.top_center() + Offset::new(-9, 3), - SCREEN.top_center() + Offset::new(9, 18 + 3), - ), - fg_color, - bg_color, - ((100_u32 * progress as u32) / 1000) as _, - icon, - ); - display::text_center( - SCREEN.center() + Offset::y(8), - text, - Font::BOLD, - fg_color, - bg_color, - ); - display::text_center( - SCREEN.center() + Offset::y(20), - text2, - Font::BOLD, - fg_color, - bg_color, - ); - - display::refresh(); -} - -fn screen_install_progress(progress: u16, initialize: bool) { - screen_progress( - "Installing", - "firmware", - progress, - initialize, - BLD_FG, - BLD_BG, - Some((ICON_SUCCESS, BLD_FG)), - ); -} - -fn screen_wipe_progress(progress: u16, initialize: bool) { - screen_progress( - "Resetting", - "Trezor", - progress, - initialize, - BLD_FG, - BLD_BG, - Some((ICON_SUCCESS, BLD_FG)), - ); -} - -fn screen_connect() { - let mut frame = Connect::new("Waiting for host...", BLD_FG, BLD_BG); - show(&mut frame, false); -} - -fn screen_wipe_success() { - let title = Label::centered("Trezor Reset", TEXT_BOLD).vertically_centered(); - - let content = - Label::centered("Please reconnect\nthe device", TEXT_NORMAL).vertically_centered(); - - let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_SPINNER, title, content, true); - show(&mut frame, false); -} - -fn screen_wipe_fail() { - let title = Label::centered("Reset failed", TEXT_BOLD).vertically_centered(); - - let content = - Label::centered("Please reconnect\nthe device", TEXT_NORMAL).vertically_centered(); - - let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_ALERT, title, content, true); - show(&mut frame, false); -} - -fn screen_boot_empty(_fading: bool) { - display::rect_fill(SCREEN, BLD_BG); - - let mut frame = WelcomeScreen::new(true); - show(&mut frame, false); -} - -fn screen_install_fail() { - let title = Label::centered("Install failed", TEXT_BOLD).vertically_centered(); - - let content = - Label::centered("Please reconnect\nthe device", TEXT_NORMAL).vertically_centered(); - - let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_ALERT, title, content, true); - show(&mut frame, false); -} - -fn screen_install_success(restart_seconds: u8, _initial_setup: bool, complete_draw: bool) { - let mut reboot_msg = BootloaderString::new(); - - if restart_seconds >= 1 { - unwrap!(reboot_msg.push_str("Restarting in ")); - // in practice, restart_seconds is 5 or less so this is fine - let seconds_char = b'0' + restart_seconds % 10; - unwrap!(reboot_msg.push(seconds_char as char)); - } else { - unwrap!(reboot_msg.push_str("Reconnect the device")); +impl ModelTRFeatures { + fn screen_progress( + text: &str, + text2: &str, + progress: u16, + initialize: bool, + fg_color: Color, + bg_color: Color, + icon: Option<(Icon, Color)>, + ) { + if initialize { + display::rect_fill(SCREEN, bg_color); + } + + let progress = if progress < 20 { 20 } else { progress }; + + display::rect_rounded2_partial( + Rect::new( + SCREEN.top_center() + Offset::new(-9, 3), + SCREEN.top_center() + Offset::new(9, 18 + 3), + ), + fg_color, + bg_color, + ((100_u32 * progress as u32) / 1000) as _, + icon, + ); + display::text_center( + SCREEN.center() + Offset::y(8), + text, + Font::BOLD, + fg_color, + bg_color, + ); + display::text_center( + SCREEN.center() + Offset::y(20), + text2, + Font::BOLD, + fg_color, + bg_color, + ); + + display::refresh(); } - - let title = Label::centered("Firmware installed", TEXT_BOLD).vertically_centered(); - - let content = Label::centered(reboot_msg.as_str(), TEXT_NORMAL).vertically_centered(); - - let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_SPINNER, title, content, complete_draw); - show(&mut frame, false); -} - -fn bld_continue_label(bg_color: Color) { - display::text_center( - Point::new(constant::WIDTH / 2, HEIGHT - 2), - "CONTINUE", - Font::NORMAL, - WHITE, - bg_color, - ); - ICON_ARM_LEFT.draw( - Point::new(constant::WIDTH / 2 - 36, HEIGHT - 6), - Alignment2D::TOP_LEFT, - WHITE, - bg_color, - ); - ICON_ARM_RIGHT.draw( - Point::new(constant::WIDTH / 2 + 25, HEIGHT - 6), - Alignment2D::TOP_LEFT, - WHITE, - bg_color, - ); } impl UIFeaturesBootloader for ModelTRFeatures { @@ -285,76 +93,197 @@ impl UIFeaturesBootloader for ModelTRFeatures { } fn bld_continue_label(bg_color: Color) { - bld_continue_label(bg_color); + display::text_center( + Point::new(constant::WIDTH / 2, HEIGHT - 2), + "CONTINUE", + Font::NORMAL, + WHITE, + bg_color, + ); + ICON_ARM_LEFT.draw( + Point::new(constant::WIDTH / 2 - 36, HEIGHT - 6), + Alignment2D::TOP_LEFT, + WHITE, + bg_color, + ); + ICON_ARM_RIGHT.draw( + Point::new(constant::WIDTH / 2 + 25, HEIGHT - 6), + Alignment2D::TOP_LEFT, + WHITE, + bg_color, + ); } - fn screen_install_success(restart_seconds: u8, initial_setup: bool, complete_draw: bool) { - screen_install_success(restart_seconds, initial_setup, complete_draw); + fn screen_install_success(restart_seconds: u8, _initial_setup: bool, complete_draw: bool) { + let mut reboot_msg = BootloaderString::new(); + + if restart_seconds >= 1 { + unwrap!(reboot_msg.push_str("Restarting in ")); + // in practice, restart_seconds is 5 or less so this is fine + let seconds_char = b'0' + restart_seconds % 10; + unwrap!(reboot_msg.push(seconds_char as char)); + } else { + unwrap!(reboot_msg.push_str("Reconnect the device")); + } + + let title = Label::centered("Firmware installed", TEXT_BOLD).vertically_centered(); + + let content = Label::centered(reboot_msg.as_str(), TEXT_NORMAL).vertically_centered(); + + let mut frame = + ResultScreen::new(BLD_FG, BLD_BG, ICON_SPINNER, title, content, complete_draw); + show(&mut frame, false); } fn screen_install_fail() { - screen_install_fail(); + let title = Label::centered("Install failed", TEXT_BOLD).vertically_centered(); + + let content = + Label::centered("Please reconnect\nthe device", TEXT_NORMAL).vertically_centered(); + + let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_ALERT, title, content, true); + show(&mut frame, false); } fn screen_install_confirm( - vendor_str: &str, + vendor: &str, version: &str, fingerprint: &str, should_keep_seed: bool, is_newvendor: bool, version_cmp: i32, ) -> u32 { - screen_install_confirm( - vendor_str, - version, + let mut version_str: BootloaderString = String::new(); + unwrap!(version_str.push_str("Firmware version ")); + unwrap!(version_str.push_str(version)); + unwrap!(version_str.push_str("\nby ")); + unwrap!(version_str.push_str(vendor)); + + let title_str = if is_newvendor { + "CHANGE FW VENDOR" + } else if version_cmp > 0 { + "UPDATE FIRMWARE" + } else if version_cmp == 0 { + "REINSTALL FW" + } else { + "DOWNGRADE FW" + }; + + let message = Label::left_aligned(version_str.as_str(), TEXT_NORMAL).vertically_centered(); + let fingerprint = Label::left_aligned( fingerprint, - should_keep_seed, - is_newvendor, - version_cmp, + TEXT_NORMAL.with_line_breaking(BreakWordsNoHyphen), ) + .vertically_centered(); + + let alert = + (!should_keep_seed).then_some(Label::left_aligned("Seed will be erased!", TEXT_NORMAL)); + + let mut frame = Confirm::new(BLD_BG, title_str, message, alert, "INSTALL", false) + .with_info_screen("FW FINGERPRINT", fingerprint); + run(&mut frame) } fn screen_wipe_confirm() -> u32 { - screen_wipe_confirm() + let message = Label::left_aligned("Seed and firmware will be erased!", TEXT_NORMAL) + .vertically_centered(); + + let mut frame = Confirm::new(BLD_BG, "FACTORY RESET", message, None, "RESET", false); + + run(&mut frame) } fn screen_unlock_bootloader_confirm() -> u32 { - screen_unlock_bootloader_confirm() + let message = + Label::left_aligned("This action cannot be undone!", TEXT_NORMAL).vertically_centered(); + + let mut frame = Confirm::new(BLD_BG, "UNLOCK BOOTLOADER?", message, None, "UNLOCK", true); + + run(&mut frame) } fn screen_unlock_bootloader_success() { - screen_unlock_bootloader_success(); + let title = Label::centered("Bootloader unlocked", TEXT_BOLD).vertically_centered(); + + let content = + Label::centered("Please reconnect the\ndevice", TEXT_NORMAL).vertically_centered(); + + let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_SPINNER, title, content, true); + show(&mut frame, false); } fn screen_menu(firmware_present: secbool) -> u32 { - screen_menu(firmware_present) + run(&mut Menu::new(firmware_present)) } - fn screen_intro(bld_version: &str, vendor_str: &str, version: &str, fw_ok: bool) -> u32 { - screen_intro(bld_version, vendor_str, version, fw_ok) + fn screen_intro(bld_version: &str, vendor: &str, version: &str, fw_ok: bool) -> u32 { + let mut title_str: BootloaderString = String::new(); + unwrap!(title_str.push_str("BOOTLOADER ")); + unwrap!(title_str.push_str(bld_version)); + + let mut version_str: BootloaderString = String::new(); + unwrap!(version_str.push_str("Firmware version ")); + unwrap!(version_str.push_str(version)); + unwrap!(version_str.push_str("\nby ")); + unwrap!(version_str.push_str(vendor)); + + let mut frame = Intro::new(title_str.as_str(), version_str.as_str(), fw_ok); + run(&mut frame) } - fn screen_boot_empty(fading: bool) { - screen_boot_empty(fading); + fn screen_boot_empty(_fading: bool) { + display::rect_fill(SCREEN, BLD_BG); + + let mut frame = WelcomeScreen::new(true); + show(&mut frame, false); } fn screen_wipe_progress(progress: u16, initialize: bool) { - screen_wipe_progress(progress, initialize); + ModelTRFeatures::screen_progress( + "Resetting", + "Trezor", + progress, + initialize, + BLD_FG, + BLD_BG, + Some((ICON_SUCCESS, BLD_FG)), + ); } fn screen_install_progress(progress: u16, initialize: bool, _initial_setup: bool) { - screen_install_progress(progress, initialize); + ModelTRFeatures::screen_progress( + "Installing", + "firmware", + progress, + initialize, + BLD_FG, + BLD_BG, + Some((ICON_SUCCESS, BLD_FG)), + ); } fn screen_connect(_initial_setup: bool) { - screen_connect(); + let mut frame = Connect::new("Waiting for host...", BLD_FG, BLD_BG); + show(&mut frame, false); } fn screen_wipe_success() { - screen_wipe_success(); + let title = Label::centered("Trezor Reset", TEXT_BOLD).vertically_centered(); + + let content = + Label::centered("Please reconnect\nthe device", TEXT_NORMAL).vertically_centered(); + + let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_SPINNER, title, content, true); + show(&mut frame, false); } fn screen_wipe_fail() { - screen_wipe_fail(); + let title = Label::centered("Reset failed", TEXT_BOLD).vertically_centered(); + + let content = + Label::centered("Please reconnect\nthe device", TEXT_NORMAL).vertically_centered(); + + let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_ALERT, title, content, true); + show(&mut frame, false); } } diff --git a/core/embed/rust/src/ui/model_tt/bootloader/mod.rs b/core/embed/rust/src/ui/model_tt/bootloader/mod.rs index c38ef293f05..a60f16c68f2 100644 --- a/core/embed/rust/src/ui/model_tt/bootloader/mod.rs +++ b/core/embed/rust/src/ui/model_tt/bootloader/mod.rs @@ -42,254 +42,55 @@ const RECONNECT_MESSAGE: &str = "PLEASE RECONNECT\nTHE DEVICE"; const SCREEN: Rect = ModelTTFeatures::SCREEN; -fn screen_install_confirm( - vendor: &str, - version: &str, - fingerprint: &str, - should_keep_seed: bool, - is_newvendor: bool, - version_cmp: cty::c_int, -) -> u32 { - let mut version_str: BootloaderString = String::new(); - unwrap!(version_str.push_str("Firmware version ")); - unwrap!(version_str.push_str(version)); - unwrap!(version_str.push_str("\nby ")); - unwrap!(version_str.push_str(vendor)); - - let title_str = if is_newvendor { - "CHANGE FW\nVENDOR" - } else if version_cmp > 0 { - "UPDATE FIRMWARE" - } else if version_cmp == 0 { - "REINSTALL FW" - } else { - "DOWNGRADE FW" - }; - let title = Label::left_aligned(title_str, TEXT_BOLD).vertically_centered(); - let msg = Label::left_aligned(version_str.as_ref(), TEXT_NORMAL); - let alert = - (!should_keep_seed).then_some(Label::left_aligned("SEED WILL BE ERASED!", TEXT_BOLD)); - - 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) - } else { - let l = Button::with_icon(Icon::new(X24)).styled(button_bld()); - let r = Button::with_icon(Icon::new(CHECK24)).styled(button_confirm()); - (l, r) - }; - - let mut frame = Confirm::new(BLD_BG, left, right, ConfirmTitle::Text(title), msg).with_info( - "FW FINGERPRINT", - fingerprint, - button_bld_menu(), - ); - - if let Some(alert) = alert { - frame = frame.with_alert(alert); +impl ModelTTFeatures { + fn screen_progress( + text: &str, + progress: u16, + initialize: bool, + fg_color: Color, + bg_color: Color, + icon: Option<(Icon, Color)>, + ) { + if initialize { + ModelTTFeatures::fadeout(); + display::rect_fill(SCREEN, bg_color); + } + + display::text_center( + Point::new(SCREEN.width() / 2, SCREEN.height() - 45), + text, + Font::NORMAL, + fg_color, + bg_color, + ); + display::loader(progress, -20, fg_color, bg_color, icon); + display::refresh(); + if initialize { + ModelTTFeatures::fadein(); + } } - run(&mut frame) -} - -fn screen_wipe_confirm() -> u32 { - let icon = Icon::new(FIRE40); - - let msg = Label::centered( - "Are you sure you want to factory reset the device?", - TEXT_WIPE_NORMAL, - ); - let alert = Label::centered("SEED AND FIRMWARE\nWILL BE ERASED!", TEXT_WIPE_BOLD); - - let right = Button::with_text("RESET").styled(button_wipe_confirm()); - let left = Button::with_text("CANCEL").styled(button_wipe_cancel()); - - let mut frame = - Confirm::new(BLD_WIPE_COLOR, left, right, ConfirmTitle::Icon(icon), msg).with_alert(alert); - - run(&mut frame) -} - -fn screen_menu(firmware_present: secbool) -> u32 { - run(&mut Menu::new(firmware_present)) -} - -fn screen_intro(bld_version: &str, vendor: &str, version: &str, fw_ok: bool) -> u32 { - let mut title_str: BootloaderString = String::new(); - unwrap!(title_str.push_str("BOOTLOADER ")); - unwrap!(title_str.push_str(bld_version)); - - let mut version_str: BootloaderString = String::new(); - unwrap!(version_str.push_str("Firmware version ")); - unwrap!(version_str.push_str(version)); - unwrap!(version_str.push_str("\nby ")); - unwrap!(version_str.push_str(vendor)); - - let mut frame = Intro::new(title_str.as_str(), version_str.as_str(), fw_ok); - - run(&mut frame) -} - -fn screen_progress( - text: &str, - progress: u16, - initialize: bool, - fg_color: Color, - bg_color: Color, - icon: Option<(Icon, Color)>, -) { - if initialize { - ModelTTFeatures::fadeout(); - display::rect_fill(SCREEN, bg_color); - } - - display::text_center( - Point::new(SCREEN.width() / 2, SCREEN.height() - 45), - text, - Font::NORMAL, - fg_color, - bg_color, - ); - display::loader(progress, -20, fg_color, bg_color, icon); - display::refresh(); - if initialize { - ModelTTFeatures::fadein(); - } -} - -fn screen_install_progress(progress: u16, initialize: bool, initial_setup: bool) { - let bg_color = if initial_setup { WELCOME_COLOR } else { BLD_BG }; - let fg_color = if initial_setup { FG } else { BLD_FG }; - - screen_progress( - "Installing firmware", - progress, - initialize, - fg_color, - bg_color, - Some((Icon::new(DOWNLOAD32), fg_color)), - ) -} - -fn screen_wipe_progress(progress: u16, initialize: bool) { - screen_progress( - "Resetting Trezor", - progress, - initialize, - BLD_FG, - BLD_WIPE_COLOR, - Some((Icon::new(FIRE32), BLD_FG)), - ) -} - -fn screen_connect(initial_setup: bool) { - let bg = if initial_setup { WELCOME_COLOR } else { BLD_BG }; - let mut frame = Connect::new("Waiting for host...", BLD_TITLE_COLOR, bg); - show(&mut frame, true); -} - -fn screen_wipe_success() { - let mut frame = ResultScreen::new( - &RESULT_WIPE, - Icon::new(CHECK40), - "Trezor reset\nsuccessfully", - Label::centered(RECONNECT_MESSAGE, RESULT_WIPE.title_style()).vertically_centered(), - true, - ); - show(&mut frame, true); -} - -fn screen_wipe_fail() { - let mut frame = ResultScreen::new( - &RESULT_WIPE, - Icon::new(WARNING40), - "Trezor reset was\nnot successful", - Label::centered(RECONNECT_MESSAGE, RESULT_WIPE.title_style()).vertically_centered(), - true, - ); - show(&mut frame, true); -} - -fn screen_boot_empty(fading: bool) { - if fading { - ModelTTFeatures::fadeout(); + fn screen_install_success_bld(msg: &str, complete_draw: bool) { + let mut frame = ResultScreen::new( + &RESULT_FW_INSTALL, + Icon::new(CHECK40), + "Firmware installed\nsuccessfully", + Label::centered(msg, RESULT_FW_INSTALL.title_style()).vertically_centered(), + complete_draw, + ); + show(&mut frame, complete_draw); } - display::rect_fill(SCREEN, BLACK); - - let mut frame = WelcomeScreen::new(true); - show(&mut frame, false); - - if fading { - ModelTTFeatures::fadein(); - } else { - display::set_backlight(BACKLIGHT_NORMAL); + fn screen_install_success_initial(msg: &str, complete_draw: bool) { + let mut frame = ResultScreen::new( + &RESULT_INITIAL, + Icon::new(CHECK40), + "Firmware installed\nsuccessfully", + Label::centered(msg, RESULT_INITIAL.title_style()).vertically_centered(), + complete_draw, + ); + show(&mut frame, complete_draw); } - display::refresh(); -} - -fn screen_install_fail() { - let mut frame = ResultScreen::new( - &RESULT_FW_INSTALL, - Icon::new(WARNING40), - "Firmware installation was not successful", - Label::centered(RECONNECT_MESSAGE, RESULT_FW_INSTALL.title_style()).vertically_centered(), - true, - ); - show(&mut frame, true); -} - -fn screen_install_success_bld(msg: &str, complete_draw: bool) { - let mut frame = ResultScreen::new( - &RESULT_FW_INSTALL, - Icon::new(CHECK40), - "Firmware installed\nsuccessfully", - Label::centered(msg, RESULT_FW_INSTALL.title_style()).vertically_centered(), - complete_draw, - ); - show(&mut frame, complete_draw); -} - -fn screen_install_success_initial(msg: &str, complete_draw: bool) { - let mut frame = ResultScreen::new( - &RESULT_INITIAL, - Icon::new(CHECK40), - "Firmware installed\nsuccessfully", - Label::centered(msg, RESULT_INITIAL.title_style()).vertically_centered(), - complete_draw, - ); - show(&mut frame, complete_draw); -} - -fn screen_install_success(restart_seconds: u8, initial_setup: bool, complete_draw: bool) { - let mut reboot_msg = BootloaderString::new(); - - if restart_seconds >= 1 { - unwrap!(reboot_msg.push_str("RESTARTING IN ")); - // in practice, restart_seconds is 5 or less so this is fine - let seconds_char = b'0' + restart_seconds % 10; - unwrap!(reboot_msg.push(seconds_char as char)); - } else { - unwrap!(reboot_msg.push_str(RECONNECT_MESSAGE)); - } - - if initial_setup { - screen_install_success_initial(reboot_msg.as_str(), complete_draw) - } else { - screen_install_success_bld(reboot_msg.as_str(), complete_draw) - } - display::refresh(); -} - -fn bld_continue_label(bg_color: Color) { - display::text_center( - Point::new(SCREEN.width() / 2, SCREEN.height() - 5), - "click to continue ...", - Font::NORMAL, - WHITE, - bg_color, - ); } impl UIFeaturesBootloader for ModelTTFeatures { @@ -299,37 +100,111 @@ impl UIFeaturesBootloader for ModelTTFeatures { } fn bld_continue_label(bg_color: Color) { - bld_continue_label(bg_color); + display::text_center( + Point::new(SCREEN.width() / 2, SCREEN.height() - 5), + "click to continue ...", + Font::NORMAL, + WHITE, + bg_color, + ); } fn screen_install_success(restart_seconds: u8, initial_setup: bool, complete_draw: bool) { - screen_install_success(restart_seconds, initial_setup, complete_draw); + let mut reboot_msg = BootloaderString::new(); + + if restart_seconds >= 1 { + unwrap!(reboot_msg.push_str("RESTARTING IN ")); + // in practice, restart_seconds is 5 or less so this is fine + let seconds_char = b'0' + restart_seconds % 10; + unwrap!(reboot_msg.push(seconds_char as char)); + } else { + unwrap!(reboot_msg.push_str(RECONNECT_MESSAGE)); + } + + if initial_setup { + ModelTTFeatures::screen_install_success_initial(reboot_msg.as_str(), complete_draw) + } else { + ModelTTFeatures::screen_install_success_bld(reboot_msg.as_str(), complete_draw) + } + display::refresh(); } fn screen_install_fail() { - screen_install_fail(); + let mut frame = ResultScreen::new( + &RESULT_FW_INSTALL, + Icon::new(WARNING40), + "Firmware installation was not successful", + Label::centered(RECONNECT_MESSAGE, RESULT_FW_INSTALL.title_style()) + .vertically_centered(), + true, + ); + show(&mut frame, true); } fn screen_install_confirm( - vendor_str: &str, + vendor: &str, version: &str, fingerprint: &str, should_keep_seed: bool, is_newvendor: bool, version_cmp: i32, ) -> u32 { - screen_install_confirm( - vendor_str, - version, - fingerprint, - should_keep_seed, - is_newvendor, - version_cmp, - ) + let mut version_str: BootloaderString = String::new(); + unwrap!(version_str.push_str("Firmware version ")); + unwrap!(version_str.push_str(version)); + unwrap!(version_str.push_str("\nby ")); + unwrap!(version_str.push_str(vendor)); + + let title_str = if is_newvendor { + "CHANGE FW\nVENDOR" + } else if version_cmp > 0 { + "UPDATE FIRMWARE" + } else if version_cmp == 0 { + "REINSTALL FW" + } else { + "DOWNGRADE FW" + }; + let title = Label::left_aligned(title_str, TEXT_BOLD).vertically_centered(); + let msg = Label::left_aligned(version_str.as_ref(), TEXT_NORMAL); + let alert = + (!should_keep_seed).then_some(Label::left_aligned("SEED WILL BE ERASED!", TEXT_BOLD)); + + 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) + } else { + let l = Button::with_icon(Icon::new(X24)).styled(button_bld()); + let r = Button::with_icon(Icon::new(CHECK24)).styled(button_confirm()); + (l, r) + }; + + let mut frame = Confirm::new(BLD_BG, left, right, ConfirmTitle::Text(title), msg) + .with_info("FW FINGERPRINT", fingerprint, button_bld_menu()); + + if let Some(alert) = alert { + frame = frame.with_alert(alert); + } + + run(&mut frame) } fn screen_wipe_confirm() -> u32 { - screen_wipe_confirm() + let icon = Icon::new(FIRE40); + + let msg = Label::centered( + "Are you sure you want to factory reset the device?", + TEXT_WIPE_NORMAL, + ); + let alert = Label::centered("SEED AND FIRMWARE\nWILL BE ERASED!", TEXT_WIPE_BOLD); + + let right = Button::with_text("RESET").styled(button_wipe_confirm()); + let left = Button::with_text("CANCEL").styled(button_wipe_cancel()); + + let mut frame = Confirm::new(BLD_WIPE_COLOR, left, right, ConfirmTitle::Icon(icon), msg) + .with_alert(alert); + + run(&mut frame) } fn screen_unlock_bootloader_confirm() -> u32 { @@ -341,34 +216,93 @@ impl UIFeaturesBootloader for ModelTTFeatures { } fn screen_menu(firmware_present: secbool) -> u32 { - screen_menu(firmware_present) + run(&mut Menu::new(firmware_present)) } - fn screen_intro(bld_version: &str, vendor_str: &str, version: &str, fw_ok: bool) -> u32 { - screen_intro(bld_version, vendor_str, version, fw_ok) + fn screen_intro(bld_version: &str, vendor: &str, version: &str, fw_ok: bool) -> u32 { + let mut title_str: BootloaderString = String::new(); + unwrap!(title_str.push_str("BOOTLOADER ")); + unwrap!(title_str.push_str(bld_version)); + + let mut version_str: BootloaderString = String::new(); + unwrap!(version_str.push_str("Firmware version ")); + unwrap!(version_str.push_str(version)); + unwrap!(version_str.push_str("\nby ")); + unwrap!(version_str.push_str(vendor)); + + let mut frame = Intro::new(title_str.as_str(), version_str.as_str(), fw_ok); + + run(&mut frame) } fn screen_boot_empty(fading: bool) { - screen_boot_empty(fading) + if fading { + ModelTTFeatures::fadeout(); + } + + display::rect_fill(SCREEN, BLACK); + + let mut frame = WelcomeScreen::new(true); + show(&mut frame, false); + + if fading { + ModelTTFeatures::fadein(); + } else { + display::set_backlight(BACKLIGHT_NORMAL); + } + display::refresh(); } fn screen_wipe_progress(progress: u16, initialize: bool) { - screen_wipe_progress(progress, initialize) + ModelTTFeatures::screen_progress( + "Resetting Trezor", + progress, + initialize, + BLD_FG, + BLD_WIPE_COLOR, + Some((Icon::new(FIRE32), BLD_FG)), + ) } fn screen_install_progress(progress: u16, initialize: bool, initial_setup: bool) { - screen_install_progress(progress, initialize, initial_setup) + let bg_color = if initial_setup { WELCOME_COLOR } else { BLD_BG }; + let fg_color = if initial_setup { FG } else { BLD_FG }; + + ModelTTFeatures::screen_progress( + "Installing firmware", + progress, + initialize, + fg_color, + bg_color, + Some((Icon::new(DOWNLOAD32), fg_color)), + ) } fn screen_connect(initial_setup: bool) { - screen_connect(initial_setup) + let bg = if initial_setup { WELCOME_COLOR } else { BLD_BG }; + let mut frame = Connect::new("Waiting for host...", BLD_TITLE_COLOR, bg); + show(&mut frame, true); } fn screen_wipe_success() { - screen_wipe_success() + let mut frame = ResultScreen::new( + &RESULT_WIPE, + Icon::new(CHECK40), + "Trezor reset\nsuccessfully", + Label::centered(RECONNECT_MESSAGE, RESULT_WIPE.title_style()).vertically_centered(), + true, + ); + show(&mut frame, true); } fn screen_wipe_fail() { - screen_wipe_fail() + let mut frame = ResultScreen::new( + &RESULT_WIPE, + Icon::new(WARNING40), + "Trezor reset was\nnot successful", + Label::centered(RECONNECT_MESSAGE, RESULT_WIPE.title_style()).vertically_centered(), + true, + ); + show(&mut frame, true); } } diff --git a/core/embed/rust/src/ui/ui_features.rs b/core/embed/rust/src/ui/ui_features.rs index 636c7dce905..0f17a3fa775 100644 --- a/core/embed/rust/src/ui/ui_features.rs +++ b/core/embed/rust/src/ui/ui_features.rs @@ -24,7 +24,7 @@ pub trait UIFeaturesBootloader { fn screen_install_fail(); fn screen_install_confirm( - vendor_str: &str, + vendor: &str, version: &str, fingerprint: &str, should_keep_seed: bool, @@ -40,7 +40,7 @@ pub trait UIFeaturesBootloader { fn screen_menu(firmware_present: secbool) -> u32; - fn screen_intro(bld_version: &str, vendor_str: &str, version: &str, fw_ok: bool) -> u32; + fn screen_intro(bld_version: &str, vendor: &str, version: &str, fw_ok: bool) -> u32; fn screen_boot_empty(fading: bool);