1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-23 13:02:03 +00:00

fixup! feat(core/rust): model R bootloader implementation in rust

This commit is contained in:
tychovrahe 2022-10-25 14:35:56 +02:00
parent 7626a99a0f
commit b80c1a4d70
5 changed files with 166 additions and 139 deletions

View File

@ -1,5 +1,8 @@
use crate::ui::{ use crate::ui::{
component::{text::paragraphs::Paragraphs, Child, Component, Event, EventCtx, Pad}, component::{
text::paragraphs::{ParagraphVecShort, Paragraphs},
Child, Component, Event, EventCtx, Pad,
},
constant::screen, constant::screen,
display, display,
display::Color, display::Color,
@ -29,7 +32,7 @@ pub struct Confirm {
bg: Pad, bg: Pad,
bg_color: Color, bg_color: Color,
icon: Option<&'static [u8]>, icon: Option<&'static [u8]>,
message: Child<Paragraphs<&'static str>>, message: Child<Paragraphs<ParagraphVecShort<&'static str>>>,
left: Child<Button<&'static str>>, left: Child<Button<&'static str>>,
right: Child<Button<&'static str>>, right: Child<Button<&'static str>>,
confirm_left: bool, confirm_left: bool,
@ -39,7 +42,7 @@ impl Confirm {
pub fn new( pub fn new(
bg_color: Color, bg_color: Color,
icon: Option<&'static [u8]>, icon: Option<&'static [u8]>,
message: Paragraphs<&'static str>, message: Paragraphs<ParagraphVecShort<&'static str>>,
left: Button<&'static str>, left: Button<&'static str>,
right: Button<&'static str>, right: Button<&'static str>,
confirm_left: bool, confirm_left: bool,

View File

@ -1,5 +1,8 @@
use crate::ui::{ use crate::ui::{
component::{text::paragraphs::Paragraphs, Child, Component, Event, EventCtx, Pad}, component::{
text::paragraphs::{Paragraph, ParagraphVecShort, Paragraphs, VecExt},
Child, Component, Event, EventCtx, Pad,
},
geometry::{LinearPlacement, Point, Rect}, geometry::{LinearPlacement, Point, Rect},
model_tr::{ model_tr::{
bootloader::{ bootloader::{
@ -34,15 +37,18 @@ pub struct Intro {
title: Child<Title>, title: Child<Title>,
host: Child<Button<&'static str>>, host: Child<Button<&'static str>>,
menu: Child<Button<&'static str>>, menu: Child<Button<&'static str>>,
text: Child<Paragraphs<&'static str>>, text: Child<Paragraphs<ParagraphVecShort<&'static str>>>,
} }
impl Intro { impl Intro {
pub fn new(bld_version: &'static str, vendor: &'static str, version: &'static str) -> Self { pub fn new(bld_version: &'static str, vendor: &'static str, version: &'static str) -> Self {
let p1 = Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(TEXT_NORMAL, version)
.add(TEXT_NORMAL, vendor) messages.add(Paragraph::new(&TEXT_NORMAL, version));
.with_placement(LinearPlacement::vertical().align_at_start()); messages.add(Paragraph::new(&TEXT_NORMAL, vendor));
let p1 =
Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_start());
let mut instance = Self { let mut instance = Self {
bg: Pad::with_background(BLD_BG), bg: Pad::with_background(BLD_BG),

View File

@ -15,7 +15,10 @@ mod theme;
mod title; mod title;
use crate::ui::{ use crate::ui::{
component::{text::paragraphs::Paragraphs, Event, EventCtx}, component::{
text::paragraphs::{Paragraph, ParagraphVecShort, Paragraphs, VecExt},
Event, EventCtx,
},
constant::{screen, BACKLIGHT_NORMAL, WIDTH}, constant::{screen, BACKLIGHT_NORMAL, WIDTH},
display::{fade_backlight_duration, Color, TextOverlay}, display::{fade_backlight_duration, Color, TextOverlay},
event::ButtonEvent, event::ButtonEvent,
@ -115,26 +118,27 @@ extern "C" fn screen_install_confirm(
"Update firmware by" "Update firmware by"
}; };
let mut message = Paragraphs::new() let mut message = ParagraphVecShort::new();
.add(theme::TEXT_NORMAL, msg)
.centered() message.add(Paragraph::new(&theme::TEXT_NORMAL, msg).centered());
.add(theme::TEXT_NORMAL, text) message.add(Paragraph::new(&theme::TEXT_NORMAL, text).centered());
.centered() message.add(Paragraph::new(&theme::TEXT_NORMAL, version).centered());
.add(theme::TEXT_NORMAL, version)
.centered();
if vendor || downgrade { if vendor || downgrade {
message = message message.add(Paragraph::new(&theme::TEXT_BOLD, "Seed will be erased!").centered());
.add(theme::TEXT_BOLD, "Seed will be erased!")
.centered();
} }
message = message.with_placement(LinearPlacement::vertical().align_at_center());
let left = Button::with_text(ButtonPos::Left, "CANCEL", bld_button_cancel()); let left = Button::with_text(ButtonPos::Left, "CANCEL", bld_button_cancel());
let right = Button::with_text(ButtonPos::Right, "INSTALL", bld_button_default()); let right = Button::with_text(ButtonPos::Right, "INSTALL", bld_button_default());
let mut frame = Confirm::new(BLD_BG, ICON, message, left, right, false); let mut frame = Confirm::new(
BLD_BG,
ICON,
Paragraphs::new(message).with_placement(LinearPlacement::vertical().align_at_center()),
left,
right,
false,
);
run(&mut frame) run(&mut frame)
} }
@ -143,12 +147,19 @@ extern "C" fn screen_install_confirm(
extern "C" fn screen_wipe_confirm() -> u32 { extern "C" fn screen_wipe_confirm() -> u32 {
const ICON: Option<&'static [u8]> = None; //Some(ERASE_BIG); const ICON: Option<&'static [u8]> = None; //Some(ERASE_BIG);
let message = Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(theme::TEXT_NORMAL, "Do you really want to wipe the device?")
.centered() messages.add(
.add(theme::TEXT_BOLD, "Seed will be erased!") Paragraph::new(
.centered() &theme::TEXT_NORMAL,
.with_placement(LinearPlacement::vertical().align_at_center()); "Do you really want to wipe the device?",
)
.centered(),
);
messages.add(Paragraph::new(&theme::TEXT_BOLD, "Seed will be erased!").centered());
let message =
Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
let left = Button::with_text(ButtonPos::Left, "WIPE", bld_button_default()); let left = Button::with_text(ButtonPos::Left, "WIPE", bld_button_default());
let right = Button::with_text(ButtonPos::Right, "CANCEL", bld_button_cancel()); let right = Button::with_text(ButtonPos::Right, "CANCEL", bld_button_cancel());
@ -243,10 +254,12 @@ extern "C" fn screen_wipe_progress(progress: u16, initialize: bool) -> u32 {
#[no_mangle] #[no_mangle]
extern "C" fn screen_connect() -> u32 { extern "C" fn screen_connect() -> u32 {
let mut frame = Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(theme::TEXT_NORMAL, "Waiting for host...")
.centered() messages.add(Paragraph::new(&theme::TEXT_NORMAL, "Waiting for host...").centered());
.with_placement(LinearPlacement::vertical().align_at_center());
let mut frame =
Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
frame.place(SCREEN_ADJ); frame.place(SCREEN_ADJ);
frame.paint(); frame.paint();
@ -255,19 +268,19 @@ extern "C" fn screen_connect() -> u32 {
#[no_mangle] #[no_mangle]
extern "C" fn screen_wipe_success() -> u32 { extern "C" fn screen_wipe_success() -> u32 {
let m_top = Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(theme::TEXT_NORMAL, "Device wiped") messages.add(Paragraph::new(&theme::TEXT_NORMAL, "Device wiped").centered());
.centered() messages.add(Paragraph::new(&theme::TEXT_NORMAL, "successfully.").centered());
.add(theme::TEXT_NORMAL, "successfully.")
.centered()
.with_placement(LinearPlacement::vertical().align_at_center());
let m_bottom = Paragraphs::new() let m_top =
.add(theme::TEXT_NORMAL, "PLEASE RECONNECT") Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
.centered()
.add(theme::TEXT_NORMAL, "THE DEVICE") let mut messages = ParagraphVecShort::new();
.centered() messages.add(Paragraph::new(&theme::TEXT_NORMAL, "PLEASE RECONNECT").centered());
.with_placement(LinearPlacement::vertical().align_at_center()); messages.add(Paragraph::new(&theme::TEXT_NORMAL, "THE DEVICE").centered());
let m_bottom =
Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
let mut frame = ResultScreen::new(BLD_FG, BLD_BG, m_top, m_bottom, true); let mut frame = ResultScreen::new(BLD_FG, BLD_BG, m_top, m_bottom, true);
frame.place(SCREEN_ADJ); frame.place(SCREEN_ADJ);
@ -277,19 +290,19 @@ extern "C" fn screen_wipe_success() -> u32 {
#[no_mangle] #[no_mangle]
extern "C" fn screen_wipe_fail() -> u32 { extern "C" fn screen_wipe_fail() -> u32 {
let m_top = Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(theme::TEXT_NORMAL, "Device wipe was") messages.add(Paragraph::new(&theme::TEXT_NORMAL, "Device wipe was").centered());
.centered() messages.add(Paragraph::new(&theme::TEXT_NORMAL, "not successful.").centered());
.add(theme::TEXT_NORMAL, "not successful.")
.centered()
.with_placement(LinearPlacement::vertical().align_at_center());
let m_bottom = Paragraphs::new() let m_top =
.add(theme::TEXT_NORMAL, "PLEASE RECONNECT") Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
.centered()
.add(theme::TEXT_NORMAL, "THE DEVICE") let mut messages = ParagraphVecShort::new();
.centered() messages.add(Paragraph::new(&theme::TEXT_NORMAL, "PLEASE RECONNECT").centered());
.with_placement(LinearPlacement::vertical().align_at_center()); messages.add(Paragraph::new(&theme::TEXT_NORMAL, "THE DEVICE").centered());
let m_bottom =
Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
let mut frame = ResultScreen::new(BLD_FG, BLD_BG, m_top, m_bottom, true); let mut frame = ResultScreen::new(BLD_FG, BLD_BG, m_top, m_bottom, true);
frame.place(SCREEN_ADJ); frame.place(SCREEN_ADJ);
@ -304,19 +317,18 @@ extern "C" fn screen_boot_empty(_firmware_present: bool) {
#[no_mangle] #[no_mangle]
extern "C" fn screen_install_fail() -> u32 { extern "C" fn screen_install_fail() -> u32 {
let m_top = Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(theme::TEXT_NORMAL, "Firmware installation was") messages.add(Paragraph::new(&theme::TEXT_NORMAL, "Firmware installation was").centered());
.centered() messages.add(Paragraph::new(&theme::TEXT_NORMAL, "not successful.").centered());
.add(theme::TEXT_NORMAL, "not successful.") let m_top =
.centered() Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
.with_placement(LinearPlacement::vertical().align_at_center());
let m_bottom = Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(theme::TEXT_NORMAL, "PLEASE RECONNECT") messages.add(Paragraph::new(&theme::TEXT_NORMAL, "PLEASE RECONNECT").centered());
.centered() messages.add(Paragraph::new(&theme::TEXT_NORMAL, "THE DEVICE").centered());
.add(theme::TEXT_NORMAL, "THE DEVICE")
.centered() let m_bottom =
.with_placement(LinearPlacement::vertical().align_at_center()); Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
let mut frame = ResultScreen::new(BLD_FG, BLD_BG, m_top, m_bottom, true); let mut frame = ResultScreen::new(BLD_FG, BLD_BG, m_top, m_bottom, true);
frame.place(SCREEN_ADJ); frame.place(SCREEN_ADJ);
@ -325,17 +337,18 @@ extern "C" fn screen_install_fail() -> u32 {
} }
fn screen_install_success_bld(msg: &'static str, complete_draw: bool) -> u32 { fn screen_install_success_bld(msg: &'static str, complete_draw: bool) -> u32 {
let m_top = Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(theme::TEXT_NORMAL, "Firmware installed") messages.add(Paragraph::new(&theme::TEXT_NORMAL, "Firmware installed").centered());
.centered() messages.add(Paragraph::new(&theme::TEXT_NORMAL, "successfully.").centered());
.add(theme::TEXT_NORMAL, "successfully.")
.centered()
.with_placement(LinearPlacement::vertical().align_at_center());
let m_bottom = Paragraphs::new() let m_top =
.add(theme::TEXT_NORMAL, msg) Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
.centered()
.with_placement(LinearPlacement::vertical().align_at_center()); let mut messages = ParagraphVecShort::new();
messages.add(Paragraph::new(&theme::TEXT_NORMAL, msg).centered());
let m_bottom =
Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
let mut frame = ResultScreen::new(BLD_FG, BLD_BG, m_top, m_bottom, complete_draw); let mut frame = ResultScreen::new(BLD_FG, BLD_BG, m_top, m_bottom, complete_draw);
frame.place(SCREEN_ADJ); frame.place(SCREEN_ADJ);
@ -344,17 +357,18 @@ fn screen_install_success_bld(msg: &'static str, complete_draw: bool) -> u32 {
} }
fn screen_install_success_initial(msg: &'static str, complete_draw: bool) -> u32 { fn screen_install_success_initial(msg: &'static str, complete_draw: bool) -> u32 {
let m_top = Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(theme::TEXT_NORMAL, "Firmware installed") messages.add(Paragraph::new(&theme::TEXT_NORMAL, "Firmware installed").centered());
.centered() messages.add(Paragraph::new(&theme::TEXT_NORMAL, "successfully.").centered());
.add(theme::TEXT_NORMAL, "successfully.")
.centered()
.with_placement(LinearPlacement::vertical().align_at_center());
let m_bottom = Paragraphs::new() let m_top =
.add(theme::TEXT_NORMAL, msg) Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
.centered()
.with_placement(LinearPlacement::vertical().align_at_center()); let mut messages = ParagraphVecShort::new();
messages.add(Paragraph::new(&theme::TEXT_NORMAL, msg).centered());
let m_bottom =
Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
let mut frame = ResultScreen::new(BLD_FG, BLD_BG, m_top, m_bottom, complete_draw); let mut frame = ResultScreen::new(BLD_FG, BLD_BG, m_top, m_bottom, complete_draw);
frame.place(SCREEN_ADJ); frame.place(SCREEN_ADJ);
@ -378,14 +392,12 @@ extern "C" fn screen_install_success(
#[no_mangle] #[no_mangle]
extern "C" fn screen_welcome() -> u32 { extern "C" fn screen_welcome() -> u32 {
let mut frame = Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(theme::TEXT_BOLD, "Get started with") messages.add(Paragraph::new(&theme::TEXT_BOLD, "Get started with").centered());
.centered() messages.add(Paragraph::new(&theme::TEXT_BOLD, "your trezor at").centered());
.add(theme::TEXT_BOLD, "your trezor at") messages.add(Paragraph::new(&theme::TEXT_BOLD, "trezor.io/start").centered());
.centered() let mut frame =
.add(theme::TEXT_BOLD, "trezor.io/start") Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
.centered()
.with_placement(LinearPlacement::vertical().align_at_center());
frame.place(SCREEN_ADJ); frame.place(SCREEN_ADJ);
frame.paint(); frame.paint();

View File

@ -1,5 +1,8 @@
use crate::ui::{ use crate::ui::{
component::{text::paragraphs::Paragraphs, Child, Component, Event, EventCtx, Never, Pad}, component::{
text::paragraphs::{ParagraphVecShort, Paragraphs},
Child, Component, Event, EventCtx, Never, Pad,
},
constant::{HEIGHT, WIDTH}, constant::{HEIGHT, WIDTH},
display::Color, display::Color,
geometry::{Point, Rect}, geometry::{Point, Rect},
@ -10,16 +13,16 @@ pub struct ResultScreen {
small_pad: Pad, small_pad: Pad,
fg_color: Color, fg_color: Color,
bg_color: Color, bg_color: Color,
message_top: Child<Paragraphs<&'static str>>, message_top: Child<Paragraphs<ParagraphVecShort<&'static str>>>,
message_bottom: Child<Paragraphs<&'static str>>, message_bottom: Child<Paragraphs<ParagraphVecShort<&'static str>>>,
} }
impl ResultScreen { impl ResultScreen {
pub fn new( pub fn new(
fg_color: Color, fg_color: Color,
bg_color: Color, bg_color: Color,
message_top: Paragraphs<&'static str>, message_top: Paragraphs<ParagraphVecShort<&'static str>>,
message_bottom: Paragraphs<&'static str>, message_bottom: Paragraphs<ParagraphVecShort<&'static str>>,
complete_draw: bool, complete_draw: bool,
) -> Self { ) -> Self {
let mut instance = Self { let mut instance = Self {

View File

@ -1,5 +1,8 @@
use crate::ui::{ use crate::ui::{
component::{text::paragraphs::Paragraphs, Component}, component::{
text::paragraphs::{Paragraph, ParagraphVecShort, Paragraphs, VecExt},
Component,
},
geometry::LinearPlacement, geometry::LinearPlacement,
model_tr::{ model_tr::{
component::ResultScreen, component::ResultScreen,
@ -12,30 +15,30 @@ use crate::ui::{
#[no_mangle] #[no_mangle]
extern "C" fn screen_fatal_error(msg: *const cty::c_char, file: *const cty::c_char) -> u32 { extern "C" fn screen_fatal_error(msg: *const cty::c_char, file: *const cty::c_char) -> u32 {
let m_top = if msg.is_null() { let m_top = if msg.is_null() {
Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(TEXT_BOLD, "FATAL ERROR!")
.centered() messages.add(Paragraph::new(&TEXT_BOLD, "FATAL ERROR!").centered());
// .add(theme::TEXT_WIPE_NORMAL, unwrap!(unsafe { from_c_str(expr) }))
// .centered() messages.add(Paragraph::new(&TEXT_NORMAL, unwrap!(unsafe { from_c_str(file) })).centered());
.add(TEXT_NORMAL, unwrap!(unsafe { from_c_str(file) }))
.centered() Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center())
.with_placement(LinearPlacement::vertical().align_at_center())
} else { } else {
let msg = unwrap!(unsafe { from_c_str(msg) }); let msg = unwrap!(unsafe { from_c_str(msg) });
Paragraphs::new()
.add(TEXT_BOLD, "FATAL ERROR!") let mut messages = ParagraphVecShort::new();
.centered()
.add(TEXT_NORMAL, msg) messages.add(Paragraph::new(&TEXT_BOLD, "FATAL ERROR!").centered());
.centered() messages.add(Paragraph::new(&TEXT_NORMAL, msg).centered());
.with_placement(LinearPlacement::vertical().align_at_center()) Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center())
}; };
let m_bottom = Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(TEXT_BOLD, "PLEASE CONTACT")
.centered() messages.add(Paragraph::new(&TEXT_BOLD, "PLEASE CONTACT").centered());
.add(TEXT_BOLD, "TREZOR SUPPORT") messages.add(Paragraph::new(&TEXT_BOLD, "TREZOR SUPPORT").centered());
.centered()
.with_placement(LinearPlacement::vertical().align_at_center()); let m_bottom =
Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
let mut frame = ResultScreen::new(WHITE, BLACK, m_top, m_bottom, true); let mut frame = ResultScreen::new(WHITE, BLACK, m_top, m_bottom, true);
frame.place(constant::screen()); frame.place(constant::screen());
@ -48,26 +51,26 @@ extern "C" fn screen_error_shutdown(label: *const cty::c_char, msg: *const cty::
let label = unwrap!(unsafe { from_c_str(label) }); let label = unwrap!(unsafe { from_c_str(label) });
let m_top = if msg.is_null() { let m_top = if msg.is_null() {
Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(TEXT_BOLD, label)
.centered() messages.add(Paragraph::new(&TEXT_BOLD, label).centered());
.with_placement(LinearPlacement::vertical().align_at_center()) Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center())
} else { } else {
let msg = unwrap!(unsafe { from_c_str(msg) }); let msg = unwrap!(unsafe { from_c_str(msg) });
Paragraphs::new()
.add(TEXT_BOLD, label) let mut messages = ParagraphVecShort::new();
.centered()
.add(TEXT_NORMAL, msg) messages.add(Paragraph::new(&TEXT_BOLD, label).centered());
.centered() messages.add(Paragraph::new(&TEXT_NORMAL, msg).centered());
.with_placement(LinearPlacement::vertical().align_at_center()) Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center())
}; };
let m_bottom = Paragraphs::new() let mut messages = ParagraphVecShort::new();
.add(TEXT_BOLD, "PLEASE UNPLUG")
.centered() messages.add(Paragraph::new(&TEXT_BOLD, "PLEASE UNPLUG").centered());
.add(TEXT_BOLD, "THE DEVICE") messages.add(Paragraph::new(&TEXT_BOLD, "THE DEVICE").centered());
.centered() let m_bottom =
.with_placement(LinearPlacement::vertical().align_at_center()); Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
let mut frame = ResultScreen::new(WHITE, BLACK, m_top, m_bottom, true); let mut frame = ResultScreen::new(WHITE, BLACK, m_top, m_bottom, true);
frame.place(constant::screen()); frame.place(constant::screen());