From 7f240247a437de34aaddc28002dc3225401321e3 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Thu, 19 Dec 2024 16:38:30 +0100 Subject: [PATCH] feat(lincoln): initial commit - build variables, lincoln UI selected for compilation only with `UI_LINCOLN_DEV=1` - lincoln directory structure - bootloader UI and assets copied from mercury - FirmwareUI trait functions are empty - Python layout functions are copied from mercury except some of more complicated ones which raise NotImplemented for now --- core/Makefile | 9 +- core/embed/rust/Cargo.toml | 1 + core/embed/rust/build.rs | 14 +- core/embed/rust/src/ui/constant.rs | 8 +- core/embed/rust/src/ui/geometry.rs | 4 + core/embed/rust/src/ui/mod.rs | 11 +- .../src/ui/model_lincoln/bootloader/intro.rs | 113 ++ .../src/ui/model_lincoln/bootloader/menu.rs | 111 ++ .../src/ui/model_lincoln/bootloader/mod.rs | 473 ++++++++ .../ui/model_lincoln/bootloader/welcome.rs | 67 + .../src/ui/model_lincoln/component/button.rs | 470 ++++++++ .../src/ui/model_lincoln/component/error.rs | 94 ++ .../src/ui/model_lincoln/component/mod.rs | 11 + .../src/ui/model_lincoln/component/result.rs | 175 +++ .../model_lincoln/component/welcome_screen.rs | 68 ++ .../src/ui/model_lincoln/component_msg_obj.rs | 34 + .../rust/src/ui/model_lincoln/constant.rs | 24 + .../src/ui/model_lincoln/cshape/loader.rs | 38 + .../rust/src/ui/model_lincoln/cshape/mod.rs | 3 + .../rust/src/ui/model_lincoln/flow/mod.rs | 0 core/embed/rust/src/ui/model_lincoln/mod.rs | 71 ++ .../model_lincoln/res/bootloader/check24.toif | Bin 0 -> 111 bytes .../model_lincoln/res/bootloader/check40.toif | Bin 0 -> 87 bytes .../res/bootloader/download24.png | Bin 0 -> 233 bytes .../res/bootloader/download24.toif | Bin 0 -> 91 bytes .../model_lincoln/res/bootloader/fire24.toif | Bin 0 -> 176 bytes .../model_lincoln/res/bootloader/fire32.toif | Bin 0 -> 235 bytes .../model_lincoln/res/bootloader/fire40.toif | Bin 0 -> 285 bytes .../model_lincoln/res/bootloader/info32.toif | Bin 0 -> 217 bytes .../model_lincoln/res/bootloader/menu32.toif | Bin 0 -> 29 bytes .../res/bootloader/refresh24.toif | Bin 0 -> 159 bytes .../res/bootloader/warning40.toif | Bin 0 -> 258 bytes .../ui/model_lincoln/res/bootloader/x24.toif | Bin 0 -> 74 bytes .../ui/model_lincoln/res/bootloader/x32.toif | Bin 0 -> 84 bytes .../src/ui/model_lincoln/res/lock_full.toif | Bin 0 -> 419 bytes .../src/ui/model_lincoln/res/warning40.toif | Bin 0 -> 258 bytes .../rust/src/ui/model_lincoln/screens.rs | 32 + .../src/ui/model_lincoln/theme/backlight.rs | 50 + .../src/ui/model_lincoln/theme/bootloader.rs | 249 ++++ .../rust/src/ui/model_lincoln/theme/mod.rs | 66 + .../rust/src/ui/model_lincoln/ui_firmware.rs | 495 ++++++++ .../src/ui/model_mercury/theme/bootloader.rs | 24 +- .../upymod/modtrezorutils/modtrezorutils.c | 2 + core/site_scons/models/T3W1/__init__.py | 3 + .../site_tools/micropython/__init__.py | 7 +- core/site_scons/ui/__init__.py | 3 +- core/site_scons/ui/lincoln.py | 63 + core/src/all_modules.py | 8 + core/src/trezor/ui/layouts/__init__.py | 2 + core/src/trezor/ui/layouts/fido.py | 2 + .../src/trezor/ui/layouts/lincoln/__init__.py | 1073 +++++++++++++++++ core/src/trezor/ui/layouts/lincoln/fido.py | 54 + .../src/trezor/ui/layouts/lincoln/recovery.py | 147 +++ core/src/trezor/ui/layouts/lincoln/reset.py | 356 ++++++ core/src/trezor/ui/layouts/recovery.py | 2 + core/src/trezor/ui/layouts/reset.py | 2 + python/src/trezorlib/cli/firmware.py | 1 + python/src/trezorlib/debuglink.py | 3 + tests/click_tests/test_lock.py | 3 +- tests/conftest.py | 1 + tests/device_tests/test_firmware_hash.py | 1 + tests/device_tests/test_language.py | 1 + 62 files changed, 4427 insertions(+), 22 deletions(-) create mode 100644 core/embed/rust/src/ui/model_lincoln/bootloader/intro.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/bootloader/menu.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/bootloader/mod.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/bootloader/welcome.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/component/button.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/component/error.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/component/mod.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/component/result.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/component/welcome_screen.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/component_msg_obj.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/constant.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/cshape/loader.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/cshape/mod.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/flow/mod.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/mod.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/check24.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/check40.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/download24.png create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/download24.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/fire24.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/fire32.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/fire40.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/info32.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/menu32.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/refresh24.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/warning40.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/x24.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/bootloader/x32.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/lock_full.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/res/warning40.toif create mode 100644 core/embed/rust/src/ui/model_lincoln/screens.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/theme/backlight.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/theme/bootloader.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/theme/mod.rs create mode 100644 core/embed/rust/src/ui/model_lincoln/ui_firmware.rs create mode 100644 core/site_scons/ui/lincoln.py create mode 100644 core/src/trezor/ui/layouts/lincoln/__init__.py create mode 100644 core/src/trezor/ui/layouts/lincoln/fido.py create mode 100644 core/src/trezor/ui/layouts/lincoln/recovery.py create mode 100644 core/src/trezor/ui/layouts/lincoln/reset.py diff --git a/core/Makefile b/core/Makefile index ffb8893aa5..0107f0cb94 100644 --- a/core/Makefile +++ b/core/Makefile @@ -33,6 +33,7 @@ BOOTLOADER_QA ?= 0 BOOTLOADER_DEVEL ?= 0 DISABLE_OPTIGA ?= 0 TREZOR_MODEL ?= T +UI_LINCOLN_DEV ?= 0 TREZOR_MEMPERF ?= 0 ADDRESS_SANITIZER ?= 0 CMAKELISTS ?= 0 @@ -69,7 +70,12 @@ MODEL_FEATURE = model_tr else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),T3W1)) MCU = STM32U5 OPENOCD_TARGET = target/stm32u5x.cfg +# model_tt by default so far, lincoln if requested +ifeq ($(UI_LINCOLN_DEV),1) +MODEL_FEATURE = model_lincoln +else MODEL_FEATURE = model_tt +endif else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),DISC1)) MCU = STM32F4 OPENOCD_TARGET = target/stm32f4x.cfg @@ -151,7 +157,8 @@ SCONS_VARS = \ TREZOR_EMULATOR_ASAN="$(ADDRESS_SANITIZER)" \ TREZOR_EMULATOR_DEBUGGABLE=$(TREZOR_EMULATOR_DEBUGGABLE) \ TREZOR_MEMPERF="$(TREZOR_MEMPERF)" \ - TREZOR_MODEL="$(TREZOR_MODEL)" + TREZOR_MODEL="$(TREZOR_MODEL)" \ + UI_LINCOLN_DEV="$(UI_LINCOLN_DEV)" SCONS_OPTS = -Q -j $(JOBS) ifeq ($(QUIET_MODE),1) diff --git a/core/embed/rust/Cargo.toml b/core/embed/rust/Cargo.toml index 83ecdc4b6e..25f15deda2 100644 --- a/core/embed/rust/Cargo.toml +++ b/core/embed/rust/Cargo.toml @@ -11,6 +11,7 @@ crypto = ["zeroize"] model_tt = ["jpeg"] model_tr = [] model_mercury = ["jpeg", "dma2d"] +model_lincoln = ["jpeg", "dma2d"] micropython = [] protobuf = ["micropython"] ui = [] diff --git a/core/embed/rust/build.rs b/core/embed/rust/build.rs index 83e4022894..d93f1674b8 100644 --- a/core/embed/rust/build.rs +++ b/core/embed/rust/build.rs @@ -86,12 +86,24 @@ const DEFAULT_BINDGEN_MACROS_T3T1: &[&str] = &[ #[cfg(not(feature = "model_mercury"))] const DEFAULT_BINDGEN_MACROS_T3T1: &[&str] = &[]; +#[cfg(feature = "model_lincoln")] +const DEFAULT_BINDGEN_MACROS_T3W1: &[&str] = &[ + "-DSTM32U5", + "-DTREZOR_MODEL_T3W1", + "-DFLASH_BIT_ACCESS=0", // FIXME: fill in correct value + "-DFLASH_BLOCK_WORDS=4", + "-DTREZOR_BOARD=\"T3W1/boards/t3w1-unix.h\"", +]; +#[cfg(not(feature = "model_lincoln"))] +const DEFAULT_BINDGEN_MACROS_T3W1: &[&str] = &[]; + fn add_bindgen_macros<'a>(clang_args: &mut Vec<&'a str>, envvar: Option<&'a str>) { let default_macros = DEFAULT_BINDGEN_MACROS_COMMON .iter() .chain(DEFAULT_BINDGEN_MACROS_T2T1) .chain(DEFAULT_BINDGEN_MACROS_T2B1) - .chain(DEFAULT_BINDGEN_MACROS_T3T1); + .chain(DEFAULT_BINDGEN_MACROS_T3T1) + .chain(DEFAULT_BINDGEN_MACROS_T3W1); match envvar { Some(envvar) => clang_args.extend(envvar.split(',')), diff --git a/core/embed/rust/src/ui/constant.rs b/core/embed/rust/src/ui/constant.rs index 3237db67aa..ba394d5f26 100644 --- a/core/embed/rust/src/ui/constant.rs +++ b/core/embed/rust/src/ui/constant.rs @@ -1,10 +1,14 @@ //! Reexporting the `constant` module according to the //! current feature (Trezor model) +#[cfg(all( + feature = "model_lincoln", + not(any(feature = "model_mercury", feature = "model_tr", feature = "model_tt")) +))] +pub use super::model_lincoln::constant::*; #[cfg(all( feature = "model_mercury", - not(feature = "model_tr"), - not(feature = "model_tt") + not(any(feature = "model_tr", feature = "model_tt"),) ))] pub use super::model_mercury::constant::*; #[cfg(all(feature = "model_tr", not(feature = "model_tt")))] diff --git a/core/embed/rust/src/ui/geometry.rs b/core/embed/rust/src/ui/geometry.rs index dde44132e4..f753e02170 100644 --- a/core/embed/rust/src/ui/geometry.rs +++ b/core/embed/rust/src/ui/geometry.rs @@ -30,6 +30,10 @@ const fn clamp(x: i16, min: i16, max: i16) -> i16 { /// Relative offset in 2D space, used for representing translation and /// dimensions of objects. Absolute positions on the screen are represented by /// the `Point` type. +/// +/// Coordinate system orientation: +/// * x-axis: negative values go left, positive values go right +/// * y-axis: negative values go up, positive values go down #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct Offset { pub x: i16, diff --git a/core/embed/rust/src/ui/mod.rs b/core/embed/rust/src/ui/mod.rs index 6ed81d9f91..4a06409d7a 100644 --- a/core/embed/rust/src/ui/mod.rs +++ b/core/embed/rust/src/ui/mod.rs @@ -17,6 +17,8 @@ pub mod layout; mod api; +#[cfg(feature = "model_lincoln")] +pub mod model_lincoln; #[cfg(feature = "model_mercury")] pub mod model_mercury; #[cfg(feature = "model_tr")] @@ -32,10 +34,15 @@ pub mod ui_firmware; pub use ui_common::CommonUI; +#[cfg(all( + feature = "model_lincoln", + not(any(feature = "model_mercury", feature = "model_tr", feature = "model_tt")) +))] +pub type ModelUI = crate::ui::model_lincoln::UILincoln; + #[cfg(all( feature = "model_mercury", - not(feature = "model_tr"), - not(feature = "model_tt") + not(any(feature = "model_tr", feature = "model_tt")) ))] pub type ModelUI = crate::ui::model_mercury::UIMercury; diff --git a/core/embed/rust/src/ui/model_lincoln/bootloader/intro.rs b/core/embed/rust/src/ui/model_lincoln/bootloader/intro.rs new file mode 100644 index 0000000000..816b14c848 --- /dev/null +++ b/core/embed/rust/src/ui/model_lincoln/bootloader/intro.rs @@ -0,0 +1,113 @@ +use crate::{ + strutil::TString, + ui::{ + component::{Child, Component, Event, EventCtx, Label, Pad}, + constant::screen, + display::Icon, + geometry::{Alignment, Insets, Point, Rect}, + shape::Renderer, + }, +}; + +use super::super::{ + component::{Button, ButtonMsg::Clicked}, + constant::WIDTH, + theme::bootloader::{ + button_bld, button_bld_menu, text_title, BLD_BG, BUTTON_AREA_START, BUTTON_HEIGHT, + CONTENT_PADDING, CORNER_BUTTON_AREA, MENU32, TEXT_NORMAL, TEXT_WARNING, TITLE_AREA, + }, +}; + +#[repr(u32)] +#[derive(Copy, Clone, ToPrimitive)] +pub enum IntroMsg { + Menu = 1, + Host = 2, +} + +pub struct Intro<'a> { + bg: Pad, + title: Child>, + menu: Child