From 8a034b096088ce13a9351aa58d833c6d82e126af Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Tue, 18 Oct 2022 22:55:29 +0200 Subject: [PATCH] feat(core/rust): loading UI2 homescreen bg from storage [no changelog] --- core/embed/rust/src/lib.rs | 1 + core/embed/rust/src/storage/mod.rs | 55 +++++++++++++++++++ .../src/ui/model_tt/component/homescreen.rs | 13 ++++- 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 core/embed/rust/src/storage/mod.rs diff --git a/core/embed/rust/src/lib.rs b/core/embed/rust/src/lib.rs index 396e09fa41..bb11e7e1be 100644 --- a/core/embed/rust/src/lib.rs +++ b/core/embed/rust/src/lib.rs @@ -16,6 +16,7 @@ mod trezorhal; mod micropython; #[cfg(feature = "protobuf")] mod protobuf; +mod storage; mod time; #[cfg(feature = "ui_debug")] mod trace; diff --git a/core/embed/rust/src/storage/mod.rs b/core/embed/rust/src/storage/mod.rs new file mode 100644 index 0000000000..1b37ab669d --- /dev/null +++ b/core/embed/rust/src/storage/mod.rs @@ -0,0 +1,55 @@ +use crate::{ + micropython::ffi, + trezorhal::storage::{get, get_length}, +}; +use core::slice; + +const STORAGE_VERSION_01: u8 = 1; +const STORAGE_VERSION_02: u8 = 2; +const STORAGE_VERSION_CURRENT: u8 = STORAGE_VERSION_02; + +const FLAG_PUBLIC: u16 = 0x8000; +const FLAG_WRITE: u16 = 0xC000; +const APP_DEVICE: u16 = 0x0100; + +const DEVICE_ID: u16 = FLAG_PUBLIC | APP_DEVICE; +const VERSION: u16 = APP_DEVICE | 0x0001; +const MNEMONIC_SECRET: u16 = APP_DEVICE | 0x0002; +// NOTE: 0x03 key was used in the past for LANGUAGE. Not used anymore. +const LABEL: u16 = FLAG_PUBLIC | APP_DEVICE | 0x0004; +const USE_PASSPHRASE: u16 = APP_DEVICE | 0x0005; +const HOMESCREEN: u16 = FLAG_PUBLIC | APP_DEVICE | 0x0006; +const NEEDS_BACKUP: u16 = APP_DEVICE | 0x0007; +const FLAGS: u16 = APP_DEVICE | 0x0008; +const U2F_COUNTER_PRIVATE: u16 = APP_DEVICE | 0x0009; +const U2F_COUNTER: u16 = FLAG_PUBLIC | APP_DEVICE | 0x0009; +const PASSPHRASE_ALWAYS_ON_DEVICE: u16 = APP_DEVICE | 0x000A; +const UNFINISHED_BACKUP: u16 = APP_DEVICE | 0x000B; +const AUTOLOCK_DELAY_MS: u16 = APP_DEVICE | 0x000C; +const NO_BACKUP: u16 = APP_DEVICE | 0x000D; +const BACKUP_TYPE: u16 = APP_DEVICE | 0x000E; +const ROTATION: u16 = FLAG_PUBLIC | APP_DEVICE | 0x000F; +const SLIP39_IDENTIFIER: u16 = APP_DEVICE | 0x0010; +const SLIP39_ITERATION_EXPONENT: u16 = APP_DEVICE | 0x0011; +const SD_SALT_AUTH_KEY: u16 = FLAG_PUBLIC | APP_DEVICE | 0x0012; +const INITIALIZED: u16 = FLAG_PUBLIC | APP_DEVICE | 0x0013; +const SAFETY_CHECK_LEVEL: u16 = APP_DEVICE | 0x0014; +const EXPERIMENTAL_FEATURES: u16 = APP_DEVICE | 0x0015; + +pub fn get_avatar() -> Result<&'static mut [u8], ()> { + let avatar_len_res = get_length(HOMESCREEN); + + return if let Ok(len) = avatar_len_res { + let data_ptr_raw = unsafe { ffi::gc_alloc(len, 0) }; + let buffer = unsafe { slice::from_raw_parts_mut(data_ptr_raw as _, len) }; + + if len <= buffer.len() { + unwrap!(get(HOMESCREEN, buffer)); + Ok(&mut buffer[..len]) + } else { + Err(()) + } + } else { + Err(()) + }; +} diff --git a/core/embed/rust/src/ui/model_tt/component/homescreen.rs b/core/embed/rust/src/ui/model_tt/component/homescreen.rs index 2178702360..da0f793283 100644 --- a/core/embed/rust/src/ui/model_tt/component/homescreen.rs +++ b/core/embed/rust/src/ui/model_tt/component/homescreen.rs @@ -1,4 +1,5 @@ use crate::{ + storage::get_avatar, time::{Duration, Instant}, trezorhal::usb::usb_configured, ui::{ @@ -188,7 +189,7 @@ where let notification = self.get_notification(); homescreen( - IMAGE_HOMESCREEN, + get_image(), texts, notification, self.paint_notification_only, @@ -269,7 +270,15 @@ where None, ],)); - homescreen(IMAGE_HOMESCREEN, texts, None, false); + homescreen(get_image(), texts, None, false); + } +} + +fn get_image() -> &'static [u8] { + if let Ok(data) = get_avatar() { + data + } else { + IMAGE_HOMESCREEN } }