mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-05 05:15:27 +00:00
avatar in rust homescreen
This commit is contained in:
parent
c695477698
commit
b391852442
@ -350,6 +350,7 @@ SOURCE_STMHAL = [
|
||||
|
||||
SOURCE_FIRMWARE = [
|
||||
'embed/firmware/bl_check.c',
|
||||
'embed/firmware/alloc_only.c',
|
||||
'embed/firmware/delay.c',
|
||||
'embed/firmware/header.S',
|
||||
'embed/firmware/main.c',
|
||||
|
54
core/embed/firmware/alloc_only.c
Normal file
54
core/embed/firmware/alloc_only.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "alloc_only.h"
|
||||
#include "common.h"
|
||||
#include "memzero.h"
|
||||
|
||||
extern uint32_t _heap_start;
|
||||
extern uint32_t _heap_end;
|
||||
|
||||
uint32_t * alloc_memory;
|
||||
|
||||
void * alloc_only(size_t size){
|
||||
|
||||
void * ptr = NULL;
|
||||
|
||||
size_t aligned_size = size;
|
||||
if (size % 4 != 0) {
|
||||
aligned_size++;
|
||||
}
|
||||
|
||||
if((alloc_memory + aligned_size) <= &_heap_end){
|
||||
ptr = alloc_memory;
|
||||
alloc_memory += aligned_size;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void alloc_only_init(bool clear) {
|
||||
alloc_memory = &_heap_start;
|
||||
|
||||
|
||||
if (clear) {
|
||||
size_t len = (&_heap_end - &_heap_start);
|
||||
memzero(alloc_memory, len);
|
||||
}
|
||||
}
|
34
core/embed/firmware/alloc_only.h
Normal file
34
core/embed/firmware/alloc_only.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _ALLOC_H
|
||||
#define _ALLOC_H
|
||||
|
||||
#include "common.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
|
||||
void * alloc_only(size_t size);
|
||||
|
||||
void alloc_only_init(bool clear);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //_ALLOC_H
|
@ -51,6 +51,7 @@
|
||||
#include "button.h"
|
||||
#endif
|
||||
#include "rust_ui.h"
|
||||
#include "alloc_only.h"
|
||||
|
||||
#ifdef SYSTEM_VIEW
|
||||
#include "systemview.h"
|
||||
@ -119,9 +120,6 @@ int main(void) {
|
||||
display_clear();
|
||||
#endif
|
||||
|
||||
display_backlight(150);
|
||||
boot_firmware(0);
|
||||
|
||||
#if !defined TREZOR_MODEL_1
|
||||
// jump to unprivileged mode
|
||||
// http://infocenter.arm.com/help/topic/com.arm.doc.dui0552a/CHDBIBGJ.html
|
||||
@ -133,6 +131,9 @@ int main(void) {
|
||||
ensure(sectrue * (zkp_context_init() == 0), NULL);
|
||||
#endif
|
||||
|
||||
display_backlight(150);
|
||||
alloc_only_init(false);
|
||||
boot_firmware();
|
||||
|
||||
printf("CORE: Preparing stack\n");
|
||||
// Stack limit should be less than real stack size, so we have a chance
|
||||
@ -146,6 +147,7 @@ int main(void) {
|
||||
#endif
|
||||
|
||||
// GC init
|
||||
alloc_only_init(true);
|
||||
printf("CORE: Starting GC\n");
|
||||
gc_init(&_heap_start, &_heap_end);
|
||||
|
||||
@ -158,7 +160,7 @@ int main(void) {
|
||||
mp_sys_path,
|
||||
MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
|
||||
|
||||
boot_firmware(1);
|
||||
|
||||
|
||||
// Execute the main script
|
||||
printf("CORE: Executing main script\n");
|
||||
|
@ -227,6 +227,8 @@ fn generate_trezorhal_bindings() {
|
||||
|
||||
let bindings = prepare_bindings()
|
||||
.header("trezorhal.h")
|
||||
.allowlist_function("alloc_only")
|
||||
.allowlist_function("alloc_only_init")
|
||||
// secbool
|
||||
.allowlist_type("secbool")
|
||||
.must_use_type("secbool")
|
||||
|
@ -1,3 +1,3 @@
|
||||
#include "common.h"
|
||||
|
||||
void boot_firmware(uint16_t stage);
|
||||
void boot_firmware();
|
||||
|
15
core/embed/rust/src/trezorhal/alloc.rs
Normal file
15
core/embed/rust/src/trezorhal/alloc.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use core::slice;
|
||||
use super::ffi;
|
||||
|
||||
pub fn alloc_only(size: usize) -> &'static mut [u8] {
|
||||
unsafe {
|
||||
let data= slice::from_raw_parts_mut(ffi::alloc_only(size) as _, size);
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alloc_only_init(clear: bool) {
|
||||
unsafe {
|
||||
ffi::alloc_only_init(clear);
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod alloc;
|
||||
pub mod bip39;
|
||||
#[macro_use]
|
||||
#[allow(unused_macros)]
|
||||
|
@ -143,4 +143,8 @@ impl<F> RustLayout<F>
|
||||
self.paint_if_requested();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process_and_finish(&mut self) {
|
||||
self.paint_if_requested();
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ use crate::ui::model_tt::theme;
|
||||
pub struct Homescreen<'a>{
|
||||
pad: Pad,
|
||||
device_name: &'a str,
|
||||
avatar: &'a[u8],
|
||||
}
|
||||
|
||||
|
||||
@ -25,11 +26,13 @@ pub enum HomescreenMsg {
|
||||
|
||||
impl<'a> Homescreen<'a> {
|
||||
|
||||
pub fn new(device_name: &'a str) -> Self {
|
||||
pub fn new(device_name: &'a str,
|
||||
avatar: &'a[u8]) -> Self {
|
||||
|
||||
let mut instance = Self {
|
||||
pad: Pad::with_background(theme::BG),
|
||||
device_name,
|
||||
avatar,
|
||||
};
|
||||
|
||||
instance.pad.clear();
|
||||
@ -38,12 +41,12 @@ impl<'a> Homescreen<'a> {
|
||||
|
||||
pub fn paint_unlocked(&self) {
|
||||
display::text_center(Point::new(screen().center().x, 35),self.device_name,theme::FONT_BOLD, theme::GREY_LIGHT, theme::BG);
|
||||
display::avatar(screen().center(), theme::IMAGE_HOMESCREEN, theme::WHITE, theme::BLACK);
|
||||
display::avatar(screen().center(), self.avatar, theme::WHITE, theme::BLACK);
|
||||
}
|
||||
|
||||
pub fn paint_not_connected(&self) {
|
||||
display::text_center(Point::new(screen().center().x, 35),self.device_name,theme::FONT_BOLD, theme::GREY_LIGHT, theme::BG);
|
||||
display::avatar(screen().center(), theme::IMAGE_HOMESCREEN, theme::WHITE, theme::BLACK);
|
||||
display::avatar(screen().center(), self.avatar, theme::WHITE, theme::BLACK);
|
||||
|
||||
let bar_area = Rect::new(Point::new(40, 100), Point::new(200, 140));
|
||||
let bar_area_in = Rect::new(Point::new(42, 102), Point::new(198, 138));
|
||||
|
@ -1,6 +1,7 @@
|
||||
use core::slice;
|
||||
use cstr_core::CStr;
|
||||
use heapless::String;
|
||||
use crate::trezorhal::alloc::alloc_only;
|
||||
use crate::trezorhal::storage::{storage_get, storage_get_length, storage_get_remaining, storage_init, storage_unlock, storage_wipe};
|
||||
use crate::ui::{constant, display, Homescreen, HomescreenMsg, PinKeyboard, PinKeyboardMsg};
|
||||
use crate::ui::constant::screen;
|
||||
@ -102,9 +103,20 @@ pub fn boot_workflow() {
|
||||
String::from("My Trezor")
|
||||
};
|
||||
|
||||
let avatar_len_res = storage_get_length(0x8106);
|
||||
//let rotation_len_res = storage_get_length(0x810F);
|
||||
|
||||
let avatar: &[u8] = if let Ok(len) = avatar_len_res {
|
||||
let mut data = alloc_only(len);
|
||||
storage_get(0x8106, &mut data).unwrap();
|
||||
data
|
||||
} else {
|
||||
theme::IMAGE_HOMESCREEN
|
||||
};
|
||||
|
||||
|
||||
let mut homescreen = RustLayout::new(Homescreen::new(device_name.as_str()));
|
||||
|
||||
let mut homescreen = RustLayout::new(Homescreen::new(device_name.as_str(), avatar));
|
||||
|
||||
loop {
|
||||
match state {
|
||||
@ -128,7 +140,7 @@ pub fn boot_workflow() {
|
||||
let pin_str = pin.inner().pin();
|
||||
let unlocked = storage_unlock(pin_str);
|
||||
if unlocked {
|
||||
homescreen = RustLayout::new(Homescreen::new("Unlocked"));
|
||||
homescreen = RustLayout::new(Homescreen::new("Unlocked", avatar));
|
||||
state = BootState::Unlocked;
|
||||
break;
|
||||
} else {
|
||||
@ -137,7 +149,7 @@ pub fn boot_workflow() {
|
||||
}
|
||||
}
|
||||
PinKeyboardMsg::Cancelled => {
|
||||
homescreen = RustLayout::new(Homescreen::new(device_name.as_str()));
|
||||
homescreen = RustLayout::new(Homescreen::new(device_name.as_str(), avatar));
|
||||
}
|
||||
|
||||
}
|
||||
@ -160,13 +172,13 @@ pub fn boot_workflow() {
|
||||
let pin_str = pin.inner().pin();
|
||||
let unlocked = storage_unlock(pin_str);
|
||||
if unlocked {
|
||||
homescreen = RustLayout::new(Homescreen::new("Unlocked"));
|
||||
homescreen = RustLayout::new(Homescreen::new("Unlocked", avatar));
|
||||
state = BootState::NotConnected;
|
||||
break;
|
||||
}
|
||||
}
|
||||
PinKeyboardMsg::Cancelled => {
|
||||
homescreen = RustLayout::new(Homescreen::new("Unlocked"));
|
||||
homescreen = RustLayout::new(Homescreen::new("Unlocked", avatar));
|
||||
state = BootState::NotConnected;
|
||||
break;
|
||||
}
|
||||
@ -174,9 +186,10 @@ pub fn boot_workflow() {
|
||||
}
|
||||
}
|
||||
BootState::Locked => {}
|
||||
BootState::Unlocked => {}
|
||||
BootState::Unlocked => {
|
||||
homescreen.process_and_finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,16 +8,12 @@ use crate::ui::workflow::boot::boot_workflow;
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn boot_firmware(
|
||||
stage: cty::uint16_t
|
||||
) {
|
||||
pub extern "C" fn boot_firmware() {
|
||||
|
||||
if stage == 0 {
|
||||
icon(constant::screen().center(), ICON_TREZOR_EMPTY, WHITE, BLACK);
|
||||
}else {
|
||||
icon(constant::screen().center(), ICON_TREZOR_FULL, WHITE, BLACK);
|
||||
|
||||
boot_workflow();
|
||||
icon(constant::screen().center(), ICON_TREZOR_FULL, WHITE, BLACK);
|
||||
|
||||
boot_workflow();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "alloc_only.h"
|
||||
#include "common.h"
|
||||
#include "display.h"
|
||||
#include "rgb_led.h"
|
||||
|
Loading…
Reference in New Issue
Block a user