2018-02-26 13:06:10 +00:00
|
|
|
/*
|
2019-06-17 18:27:55 +00:00
|
|
|
* This file is part of the Trezor project, https://trezor.io/
|
2018-02-26 13:06:10 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2017-12-17 00:09:45 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "bootui.h"
|
2021-03-04 15:33:05 +00:00
|
|
|
#include "display.h"
|
2023-03-23 14:42:21 +00:00
|
|
|
#ifdef TREZOR_EMULATOR
|
|
|
|
#include "emulator.h"
|
|
|
|
#else
|
2021-03-04 15:33:05 +00:00
|
|
|
#include "mini_printf.h"
|
2023-03-23 14:42:21 +00:00
|
|
|
#endif
|
2022-05-05 11:47:19 +00:00
|
|
|
#include "rust_ui.h"
|
2021-03-04 15:33:05 +00:00
|
|
|
#include "version.h"
|
|
|
|
|
2017-12-17 00:09:45 +00:00
|
|
|
#define BACKLIGHT_NORMAL 150
|
|
|
|
|
2022-04-29 08:38:30 +00:00
|
|
|
#define COLOR_BL_BG COLOR_WHITE // background
|
|
|
|
#define COLOR_BL_FG COLOR_BLACK // foreground
|
|
|
|
|
|
|
|
#ifdef RGB16
|
2019-03-29 15:26:02 +00:00
|
|
|
#define COLOR_BL_FAIL RGB16(0xFF, 0x00, 0x00) // red
|
|
|
|
#define COLOR_BL_DONE RGB16(0x00, 0xAE, 0x0B) // green
|
|
|
|
#define COLOR_BL_PROCESS RGB16(0x4A, 0x90, 0xE2) // blue
|
|
|
|
#define COLOR_BL_GRAY RGB16(0x99, 0x99, 0x99) // gray
|
2022-04-29 08:38:30 +00:00
|
|
|
#else
|
|
|
|
#define COLOR_BL_FAIL COLOR_BL_FG
|
|
|
|
#define COLOR_BL_DONE COLOR_BL_FG
|
|
|
|
#define COLOR_BL_PROCESS COLOR_BL_FG
|
|
|
|
#define COLOR_BL_GRAY COLOR_BL_FG
|
|
|
|
#endif
|
2017-12-17 00:09:45 +00:00
|
|
|
|
2018-01-26 15:05:45 +00:00
|
|
|
// common shared functions
|
|
|
|
|
2022-05-05 11:47:19 +00:00
|
|
|
static void format_ver(const char *format, uint32_t version, char *buffer,
|
|
|
|
size_t buffer_len) {
|
|
|
|
mini_snprintf(buffer, buffer_len, format, (int)(version & 0xFF),
|
2019-03-29 15:26:02 +00:00
|
|
|
(int)((version >> 8) & 0xFF), (int)((version >> 16) & 0xFF)
|
|
|
|
// ignore build field (int)((version >> 24) & 0xFF)
|
|
|
|
);
|
2018-01-26 15:05:45 +00:00
|
|
|
}
|
|
|
|
|
2017-12-17 00:09:45 +00:00
|
|
|
// boot UI
|
|
|
|
|
2018-01-28 12:47:03 +00:00
|
|
|
static uint16_t boot_background;
|
2022-05-05 11:47:19 +00:00
|
|
|
static bool initial_setup = true;
|
|
|
|
|
|
|
|
void ui_set_initial_setup(bool initial) { initial_setup = initial; }
|
2018-01-28 12:47:03 +00:00
|
|
|
|
2019-03-29 15:26:02 +00:00
|
|
|
void ui_screen_boot(const vendor_header *const vhdr,
|
|
|
|
const image_header *const hdr) {
|
|
|
|
const int show_string = ((vhdr->vtrust & VTRUST_STRING) == 0);
|
|
|
|
if ((vhdr->vtrust & VTRUST_RED) == 0) {
|
2022-04-29 08:38:30 +00:00
|
|
|
boot_background = COLOR_BL_FAIL;
|
2019-03-29 15:26:02 +00:00
|
|
|
} else {
|
|
|
|
boot_background = COLOR_BLACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t *vimg = vhdr->vimg;
|
|
|
|
const uint32_t fw_version = hdr->version;
|
|
|
|
|
|
|
|
display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, boot_background);
|
|
|
|
|
|
|
|
int image_top = show_string ? 30 : (DISPLAY_RESY - 120) / 2;
|
|
|
|
|
|
|
|
// check whether vendor image is 120x120
|
2022-08-16 14:51:10 +00:00
|
|
|
if (memcmp(vimg, "TOIF\x78\x00\x78\x00", 4) == 0) {
|
2019-03-29 15:26:02 +00:00
|
|
|
uint32_t datalen = *(uint32_t *)(vimg + 8);
|
2023-02-09 22:56:03 +00:00
|
|
|
display_image((DISPLAY_RESX - 120) / 2, image_top, vimg, datalen + 12);
|
2019-03-29 15:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (show_string) {
|
2022-05-05 11:47:19 +00:00
|
|
|
char ver_str[64];
|
2019-03-29 15:26:02 +00:00
|
|
|
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 5 - 50, vhdr->vstr,
|
2021-03-10 16:54:30 +00:00
|
|
|
vhdr->vstr_len, FONT_NORMAL, COLOR_BL_BG,
|
2019-03-29 15:26:02 +00:00
|
|
|
boot_background);
|
2022-05-05 11:47:19 +00:00
|
|
|
format_ver("%d.%d.%d", fw_version, ver_str, sizeof(ver_str));
|
2019-03-29 15:26:02 +00:00
|
|
|
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 5 - 25, ver_str, -1,
|
2021-03-10 16:54:30 +00:00
|
|
|
FONT_NORMAL, COLOR_BL_BG, boot_background);
|
2019-03-29 15:26:02 +00:00
|
|
|
}
|
2022-10-14 10:43:37 +00:00
|
|
|
|
|
|
|
PIXELDATA_DIRTY();
|
|
|
|
display_refresh();
|
2017-12-17 00:09:45 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 15:26:02 +00:00
|
|
|
void ui_screen_boot_wait(int wait_seconds) {
|
|
|
|
char wait_str[16];
|
|
|
|
mini_snprintf(wait_str, sizeof(wait_str), "starting in %d s", wait_seconds);
|
|
|
|
display_bar(0, DISPLAY_RESY - 5 - 20, DISPLAY_RESX, 5 + 20, boot_background);
|
|
|
|
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 5, wait_str, -1,
|
2021-03-10 16:54:30 +00:00
|
|
|
FONT_NORMAL, COLOR_BL_BG, boot_background);
|
2022-10-14 10:43:37 +00:00
|
|
|
PIXELDATA_DIRTY();
|
|
|
|
display_refresh();
|
2017-12-17 00:09:45 +00:00
|
|
|
}
|
|
|
|
|
2023-03-28 12:40:39 +00:00
|
|
|
#if defined USE_TOUCH
|
|
|
|
#include "touch/touch.h"
|
|
|
|
|
|
|
|
void ui_click(void) {
|
|
|
|
// flush touch events if any
|
|
|
|
while (touch_read()) {
|
|
|
|
}
|
|
|
|
// wait for TOUCH_START
|
|
|
|
while ((touch_read() & TOUCH_START) == 0) {
|
|
|
|
}
|
|
|
|
// wait for TOUCH_END
|
|
|
|
while ((touch_read() & TOUCH_END) == 0) {
|
|
|
|
}
|
|
|
|
// flush touch events if any
|
|
|
|
while (touch_read()) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined USE_BUTTON
|
|
|
|
#include "button.h"
|
|
|
|
|
|
|
|
void ui_click(void) {
|
|
|
|
for (;;) {
|
|
|
|
button_read();
|
|
|
|
if (button_state_left() != 0 && button_state_right() != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
button_read();
|
|
|
|
if (button_state_left() != 1 && button_state_right() != 1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error "No input method defined"
|
|
|
|
#endif
|
|
|
|
|
2017-12-17 00:09:45 +00:00
|
|
|
void ui_screen_boot_click(void) {
|
2019-03-29 15:26:02 +00:00
|
|
|
display_bar(0, DISPLAY_RESY - 5 - 20, DISPLAY_RESX, 5 + 20, boot_background);
|
|
|
|
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 5,
|
2021-03-10 16:54:30 +00:00
|
|
|
"click to continue ...", -1, FONT_NORMAL, COLOR_BL_BG,
|
2019-03-29 15:26:02 +00:00
|
|
|
boot_background);
|
2022-10-14 10:43:37 +00:00
|
|
|
PIXELDATA_DIRTY();
|
|
|
|
display_refresh();
|
2023-03-28 12:40:39 +00:00
|
|
|
ui_click();
|
2017-12-17 00:09:45 +00:00
|
|
|
}
|
|
|
|
|
2018-01-25 13:16:21 +00:00
|
|
|
// welcome UI
|
2017-12-17 00:09:45 +00:00
|
|
|
|
2023-03-11 20:02:31 +00:00
|
|
|
void ui_screen_welcome_model(void) { screen_welcome_model(); }
|
2022-05-05 11:47:19 +00:00
|
|
|
void ui_screen_welcome(void) { screen_welcome(); }
|
2018-01-24 17:28:10 +00:00
|
|
|
|
2022-05-05 11:47:19 +00:00
|
|
|
uint32_t ui_screen_intro(const vendor_header *const vhdr,
|
|
|
|
const image_header *const hdr) {
|
|
|
|
char bld_ver[32];
|
|
|
|
char ver_str[64];
|
|
|
|
format_ver("%d.%d.%d", VERSION_UINT32, bld_ver, sizeof(bld_ver));
|
|
|
|
format_ver("%d.%d.%d", hdr->version, ver_str, sizeof(ver_str));
|
2018-01-24 17:28:10 +00:00
|
|
|
|
2022-05-05 11:47:19 +00:00
|
|
|
return screen_intro(bld_ver, vhdr->vstr, vhdr->vstr_len, ver_str);
|
2018-01-24 17:28:10 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 09:59:13 +00:00
|
|
|
uint32_t ui_screen_menu(void) { return screen_menu(); }
|
2017-12-17 00:09:45 +00:00
|
|
|
|
|
|
|
// install UI
|
|
|
|
|
2023-03-30 13:43:49 +00:00
|
|
|
uint32_t ui_screen_install_confirm(const vendor_header *const vhdr,
|
|
|
|
const image_header *const hdr,
|
|
|
|
secbool should_keep_seed,
|
|
|
|
secbool is_newvendor, int version_cmp) {
|
2022-05-05 11:47:19 +00:00
|
|
|
uint8_t fingerprint[32];
|
|
|
|
char ver_str[64];
|
|
|
|
get_image_fingerprint(hdr, fingerprint);
|
|
|
|
format_ver("%d.%d.%d", hdr->version, ver_str, sizeof(ver_str));
|
|
|
|
return screen_install_confirm(vhdr->vstr, vhdr->vstr_len, ver_str,
|
2023-03-30 13:43:49 +00:00
|
|
|
fingerprint, should_keep_seed == sectrue,
|
|
|
|
is_newvendor == sectrue, version_cmp);
|
2018-01-24 16:00:25 +00:00
|
|
|
}
|
|
|
|
|
2022-05-05 11:47:19 +00:00
|
|
|
void ui_screen_install_start() {
|
|
|
|
screen_install_progress(0, true, initial_setup);
|
2017-12-17 00:09:45 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 15:26:02 +00:00
|
|
|
void ui_screen_install_progress_erase(int pos, int len) {
|
2022-05-05 11:47:19 +00:00
|
|
|
screen_install_progress(250 * pos / len, false, initial_setup);
|
2017-12-17 00:09:45 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 15:26:02 +00:00
|
|
|
void ui_screen_install_progress_upload(int pos) {
|
2022-05-05 11:47:19 +00:00
|
|
|
screen_install_progress(pos, false, initial_setup);
|
2017-12-17 00:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// wipe UI
|
|
|
|
|
2022-05-05 11:47:19 +00:00
|
|
|
uint32_t ui_screen_wipe_confirm(void) { return screen_wipe_confirm(); }
|
2018-01-24 16:00:25 +00:00
|
|
|
|
2022-05-05 11:47:19 +00:00
|
|
|
void ui_screen_wipe(void) { screen_wipe_progress(0, true); }
|
2017-12-17 00:09:45 +00:00
|
|
|
|
2019-03-29 15:26:02 +00:00
|
|
|
void ui_screen_wipe_progress(int pos, int len) {
|
2022-05-05 11:47:19 +00:00
|
|
|
screen_wipe_progress(1000 * pos / len, false);
|
2017-12-17 00:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// done UI
|
2023-03-23 14:42:21 +00:00
|
|
|
void ui_screen_done(uint8_t restart_seconds, secbool full_redraw) {
|
2019-03-29 15:26:02 +00:00
|
|
|
const char *str;
|
|
|
|
char count_str[24];
|
|
|
|
if (restart_seconds >= 1) {
|
2023-03-13 17:56:16 +00:00
|
|
|
mini_snprintf(count_str, sizeof(count_str), "RESTARTING IN %d",
|
2019-03-29 15:26:02 +00:00
|
|
|
restart_seconds);
|
|
|
|
str = count_str;
|
|
|
|
} else {
|
2023-03-13 17:56:16 +00:00
|
|
|
str = "RECONNECT THE DEVICE";
|
2019-03-29 15:26:02 +00:00
|
|
|
}
|
2022-10-14 10:43:37 +00:00
|
|
|
|
2022-05-05 11:47:19 +00:00
|
|
|
screen_install_success(str, initial_setup, full_redraw);
|
2017-12-17 00:09:45 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 20:41:16 +00:00
|
|
|
void ui_screen_boot_empty(bool fading) { screen_boot_empty(fading); }
|
2017-12-17 00:09:45 +00:00
|
|
|
|
2022-05-05 11:47:19 +00:00
|
|
|
// error UI
|
|
|
|
void ui_screen_fail(void) { screen_install_fail(); }
|
|
|
|
|
2017-12-17 00:09:45 +00:00
|
|
|
// general functions
|
|
|
|
|
2019-03-29 15:26:02 +00:00
|
|
|
void ui_fadein(void) { display_fade(0, BACKLIGHT_NORMAL, 1000); }
|
2017-12-17 00:09:45 +00:00
|
|
|
|
2019-03-29 15:26:02 +00:00
|
|
|
void ui_fadeout(void) {
|
|
|
|
display_fade(BACKLIGHT_NORMAL, 0, 500);
|
|
|
|
display_clear();
|
2017-12-17 00:09:45 +00:00
|
|
|
}
|