From 29c16c212dd94c4e42fa9fa9f15e1481ad113253 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Mon, 18 Sep 2023 16:58:34 +0200 Subject: [PATCH] fix(core): fix T2B1 "restarting in" label capitalization [no changelog] --- core/embed/bootloader/bootui.c | 12 +----- core/embed/bootloader/emulator.c | 3 +- core/embed/rust/rust_ui.h | 2 +- .../rust/src/ui/model_tr/bootloader/mod.rs | 17 ++++++-- .../rust/src/ui/model_tr/component/result.rs | 39 +++++++++++++++---- .../rust/src/ui/model_tt/bootloader/mod.rs | 34 ++++++++++------ .../rust/src/ui/model_tt/component/error.rs | 5 ++- .../rust/src/ui/model_tt/component/result.rs | 12 +++--- 8 files changed, 80 insertions(+), 44 deletions(-) diff --git a/core/embed/bootloader/bootui.c b/core/embed/bootloader/bootui.c index 39a0a0ed29..4c7e5674aa 100644 --- a/core/embed/bootloader/bootui.c +++ b/core/embed/bootloader/bootui.c @@ -242,17 +242,7 @@ void ui_screen_wipe_progress(int pos, int len) { // done UI void ui_screen_done(uint8_t restart_seconds, secbool full_redraw) { - const char *str; - char count_str[24]; - if (restart_seconds >= 1) { - mini_snprintf(count_str, sizeof(count_str), "RESTARTING IN %d", - restart_seconds); - str = count_str; - } else { - str = "RECONNECT THE DEVICE"; - } - - screen_install_success(str, initial_setup, full_redraw); + screen_install_success(restart_seconds, initial_setup, full_redraw); } void ui_screen_boot_empty(bool fading) { screen_boot_empty(fading); } diff --git a/core/embed/bootloader/emulator.c b/core/embed/bootloader/emulator.c index 065c465de9..952fde585c 100644 --- a/core/embed/bootloader/emulator.c +++ b/core/embed/bootloader/emulator.c @@ -87,7 +87,8 @@ __attribute__((noreturn)) void jump_to(void *addr) { "STORAGE WAS ERASED"); } else { printf("storage was retained\n"); - screen_install_success("STORAGE WAS RETAINED", true, true); + screen_fatal_error_rust("BOOTLOADER EXIT", "Jumped to firmware", + "STORAGE WAS RETAINED"); } display_backlight(180); display_refresh(); diff --git a/core/embed/rust/rust_ui.h b/core/embed/rust/rust_ui.h index 5fc503500f..9dc21fa869 100644 --- a/core/embed/rust/rust_ui.h +++ b/core/embed/rust/rust_ui.h @@ -19,7 +19,7 @@ void screen_fatal_error_rust(const char* title, const char* msg, const char* footer); void screen_wipe_success(void); void screen_wipe_fail(void); -uint32_t screen_install_success(const char* reboot_msg, bool initial_setup, +uint32_t screen_install_success(uint8_t restart_seconds, bool initial_setup, bool complete_draw); uint32_t screen_install_fail(void); void screen_welcome_model(void); 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 0e6fed0405..8f10f155a0 100644 --- a/core/embed/rust/src/ui/model_tr/bootloader/mod.rs +++ b/core/embed/rust/src/ui/model_tr/bootloader/mod.rs @@ -301,7 +301,7 @@ extern "C" fn screen_wipe_success() { let title = Label::centered("Trezor Reset", theme::TEXT_BOLD).vertically_centered(); let content = - Label::centered("Reconnect\nthe device", theme::TEXT_NORMAL).vertically_centered(); + Label::centered("Please reconnect\nthe device", theme::TEXT_NORMAL).vertically_centered(); let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_SPINNER, title, content, true); show(&mut frame); @@ -339,15 +339,24 @@ extern "C" fn screen_install_fail() { #[no_mangle] extern "C" fn screen_install_success( - reboot_msg: *const cty::c_char, + restart_seconds: u8, _initial_setup: bool, complete_draw: bool, ) { - let msg = unwrap!(unsafe { from_c_str(reboot_msg) }); + 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", theme::TEXT_BOLD).vertically_centered(); - let content = Label::centered(msg, theme::TEXT_NORMAL).vertically_centered(); + let content = Label::centered(reboot_msg.as_str(), theme::TEXT_NORMAL).vertically_centered(); let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_SPINNER, title, content, complete_draw); show(&mut frame); diff --git a/core/embed/rust/src/ui/model_tr/component/result.rs b/core/embed/rust/src/ui/model_tr/component/result.rs index 86f07bb346..0fea93cf40 100644 --- a/core/embed/rust/src/ui/model_tr/component/result.rs +++ b/core/embed/rust/src/ui/model_tr/component/result.rs @@ -5,8 +5,10 @@ use crate::ui::{ geometry::{Alignment2D, Offset, Point, Rect}, }; -const MESSAGE_AREA_START: i16 = 26; -const FOOTER_AREA_START: i16 = 40; +const MESSAGE_AREA_START: i16 = 24 + 11; +const MESSAGE_AREA_START_2L: i16 = 24 + 7; +const FOOTER_AREA_START: i16 = MESSAGE_AREA_START + 10; +const FOOTER_AREA_START_2L: i16 = MESSAGE_AREA_START_2L + 10; const ICON_TOP: i16 = 12; pub struct ResultScreen<'a> { @@ -53,15 +55,36 @@ impl<'a> Component for ResultScreen<'a> { fn place(&mut self, bounds: Rect) -> Rect { self.bg.place(bounds); - self.message_top.place(Rect::new( - Point::new(0, MESSAGE_AREA_START), - Point::new(WIDTH, FOOTER_AREA_START), - )); - let bottom_area = Rect::new(Point::new(0, FOOTER_AREA_START), Point::new(WIDTH, HEIGHT)); - self.small_pad.place(bottom_area); self.message_bottom.place(bottom_area); + let h = self.message_bottom.inner().text_height(WIDTH); + + if h > 8 { + self.message_top.place(Rect::new( + Point::new(0, MESSAGE_AREA_START_2L), + Point::new(WIDTH, FOOTER_AREA_START_2L), + )); + + let bottom_area = Rect::new( + Point::new(0, FOOTER_AREA_START_2L), + Point::new(WIDTH, FOOTER_AREA_START_2L + h), + ); + self.message_bottom.place(bottom_area); + } else { + self.message_top.place(Rect::new( + Point::new(0, MESSAGE_AREA_START), + Point::new(WIDTH, FOOTER_AREA_START), + )); + + let bottom_area = Rect::new( + Point::new(0, FOOTER_AREA_START), + Point::new(WIDTH, FOOTER_AREA_START + h), + ); + self.message_bottom.place(bottom_area); + } + + self.small_pad.place(bottom_area); bounds } 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 c0a1257f08..36daa14520 100644 --- a/core/embed/rust/src/ui/model_tt/bootloader/mod.rs +++ b/core/embed/rust/src/ui/model_tt/bootloader/mod.rs @@ -315,7 +315,7 @@ extern "C" fn screen_wipe_success() { &RESULT_WIPE, Icon::new(CHECK40), "Trezor reset\nsuccessfully", - RECONNECT_MESSAGE, + Label::centered(RECONNECT_MESSAGE, RESULT_WIPE.title_style()).vertically_centered(), true, ); show(&mut frame, true); @@ -327,7 +327,7 @@ extern "C" fn screen_wipe_fail() { &RESULT_WIPE, Icon::new(WARNING40), "Trezor reset was\nnot successful", - RECONNECT_MESSAGE, + Label::centered(RECONNECT_MESSAGE, RESULT_WIPE.title_style()).vertically_centered(), true, ); show(&mut frame, true); @@ -357,29 +357,29 @@ extern "C" fn screen_install_fail() { &RESULT_FW_INSTALL, Icon::new(WARNING40), "Firmware installation was not successful", - RECONNECT_MESSAGE, + Label::centered(RECONNECT_MESSAGE, RESULT_FW_INSTALL.title_style()).vertically_centered(), true, ); show(&mut frame, true); } -fn screen_install_success_bld(msg: &'static str, complete_draw: bool) { +fn screen_install_success_bld(msg: &str, complete_draw: bool) { let mut frame = ResultScreen::new( &RESULT_FW_INSTALL, Icon::new(CHECK40), "Firmware installed\nsuccessfully", - msg, + Label::centered(msg, RESULT_FW_INSTALL.title_style()).vertically_centered(), complete_draw, ); show(&mut frame, complete_draw); } -fn screen_install_success_initial(msg: &'static str, complete_draw: bool) { +fn screen_install_success_initial(msg: &str, complete_draw: bool) { let mut frame = ResultScreen::new( &RESULT_INITIAL, Icon::new(CHECK40), "Firmware installed\nsuccessfully", - msg, + Label::centered(msg, RESULT_INITIAL.title_style()).vertically_centered(), complete_draw, ); show(&mut frame, complete_draw); @@ -387,15 +387,25 @@ fn screen_install_success_initial(msg: &'static str, complete_draw: bool) { #[no_mangle] extern "C" fn screen_install_success( - reboot_msg: *const cty::c_char, + restart_seconds: u8, initial_setup: bool, complete_draw: bool, ) { - let msg = unwrap!(unsafe { from_c_str(reboot_msg) }); - if initial_setup { - screen_install_success_initial(msg, 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 { - screen_install_success_bld(msg, complete_draw) + 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(); } diff --git a/core/embed/rust/src/ui/model_tt/component/error.rs b/core/embed/rust/src/ui/model_tt/component/error.rs index 7867c831e8..a9d1000408 100644 --- a/core/embed/rust/src/ui/model_tt/component/error.rs +++ b/core/embed/rust/src/ui/model_tt/component/error.rs @@ -30,7 +30,10 @@ impl> ErrorScreen<'_, T> { pub fn new(title: T, message: T, footer: T) -> Self { let title = Label::centered(title, STYLE.title_style()); let message = Label::centered(message, STYLE.message_style()); - let footer = ResultFooter::new(footer, STYLE); + let footer = ResultFooter::new( + Label::centered(footer, STYLE.title_style()).vertically_centered(), + STYLE, + ); Self { bg: Pad::with_background(FATAL_ERROR_COLOR).with_clear(), diff --git a/core/embed/rust/src/ui/model_tt/component/result.rs b/core/embed/rust/src/ui/model_tt/component/result.rs index abab957901..26bffb84f6 100644 --- a/core/embed/rust/src/ui/model_tt/component/result.rs +++ b/core/embed/rust/src/ui/model_tt/component/result.rs @@ -48,10 +48,10 @@ pub struct ResultFooter<'a, T> { } impl<'a, T: AsRef> ResultFooter<'a, T> { - pub fn new(text: T, style: &'a ResultStyle) -> Self { + pub fn new(text: Label, style: &'a ResultStyle) -> Self { Self { style, - text: Label::centered(text, style.title_style()).vertically_centered(), + text, area: Rect::zero(), } } @@ -101,7 +101,7 @@ pub struct ResultScreen<'a, T> { style: &'a ResultStyle, icon: Icon, message: Child>, - footer: Child>, + footer: Child>, } impl<'a, T: StringType> ResultScreen<'a, T> { @@ -109,7 +109,7 @@ impl<'a, T: StringType> ResultScreen<'a, T> { style: &'a ResultStyle, icon: Icon, message: T, - footer: T, + footer: Label<&'a str>, complete_draw: bool, ) -> Self { let mut instance = Self { @@ -130,13 +130,13 @@ impl<'a, T: StringType> ResultScreen<'a, T> { } } -impl Component for ResultScreen<'_, T> { +impl<'a, T: StringType> Component for ResultScreen<'a, T> { type Msg = Never; fn place(&mut self, _bounds: Rect) -> Rect { self.bg.place(screen()); - let (main_area, footer_area) = ResultFooter::::split_bounds(); + let (main_area, footer_area) = ResultFooter::<&'a str>::split_bounds(); self.footer_pad.place(footer_area); self.footer.place(footer_area);