mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-17 01:52:02 +00:00
bootloader: add confirm dialogs for wipe/upgrade
This commit is contained in:
parent
ae94bc95fb
commit
2e00c090b6
@ -4,6 +4,7 @@
|
||||
#include "mini_printf.h"
|
||||
|
||||
#include "bootui.h"
|
||||
#include "touch.h"
|
||||
#include "version.h"
|
||||
|
||||
#include "icon_cancel.h"
|
||||
@ -109,6 +110,21 @@ void ui_screen_info(secbool buttons, const vendor_header * const vhdr, const ima
|
||||
|
||||
// install UI
|
||||
|
||||
void ui_screen_install_confirm(void)
|
||||
{
|
||||
display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, COLOR_WHITE);
|
||||
display_text(16, 32, "Firmware update", -1, FONT_NORMAL, COLOR_BLACK, COLOR_WHITE, 0);
|
||||
display_bar(16, 44, DISPLAY_RESX - 14 * 2, 1, COLOR_BLACK);
|
||||
display_icon(16, 54, 32, 32, toi_icon_info + 12, sizeof(toi_icon_info) - 12, COLOR_BLACK, COLOR_WHITE);
|
||||
display_text(55, 70, "Do you want to", -1, FONT_NORMAL, COLOR_BLACK, COLOR_WHITE, 0);
|
||||
display_text(55, 95, "update the firmware?", -1, FONT_NORMAL, COLOR_BLACK, COLOR_WHITE, 0);
|
||||
|
||||
display_bar_radius(9, 184, 108, 50, COLOR_BL_FAIL, COLOR_WHITE, 4);
|
||||
display_icon(9 + (108 - 16) / 2, 184 + (50 - 16) / 2, 16, 16, toi_icon_cancel + 12, sizeof(toi_icon_cancel) - 12, COLOR_WHITE, COLOR_BL_FAIL);
|
||||
display_bar_radius(123, 184, 108, 50, COLOR_BL_DONE, COLOR_WHITE, 4);
|
||||
display_icon(123 + (108 - 19) / 2, 184 + (50 - 16) / 2, 20, 16, toi_icon_confirm + 12, sizeof(toi_icon_confirm) - 12, COLOR_WHITE, COLOR_BL_DONE);
|
||||
}
|
||||
|
||||
void ui_screen_install(void)
|
||||
{
|
||||
display_fade(BACKLIGHT_NORMAL, 0, 100);
|
||||
@ -130,6 +146,23 @@ void ui_screen_install_progress_upload(int pos)
|
||||
|
||||
// wipe UI
|
||||
|
||||
void ui_screen_wipe_confirm(void)
|
||||
{
|
||||
display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, COLOR_WHITE);
|
||||
display_text(16, 32, "Wipe device", -1, FONT_NORMAL, COLOR_BLACK, COLOR_WHITE, 0);
|
||||
display_bar(16, 44, DISPLAY_RESX - 14 * 2, 1, COLOR_BLACK);
|
||||
display_icon(16, 54, 32, 32, toi_icon_info + 12, sizeof(toi_icon_info) - 12, COLOR_BLACK, COLOR_WHITE);
|
||||
display_text(55, 70, "Do you want to", -1, FONT_NORMAL, COLOR_BLACK, COLOR_WHITE, 0);
|
||||
display_text(55, 95, "wipe the device?", -1, FONT_NORMAL, COLOR_BLACK, COLOR_WHITE, 0);
|
||||
|
||||
display_text_center(120, 164, "Seed will be erased!", -1, FONT_NORMAL, COLOR_BL_FAIL, COLOR_WHITE, 0);
|
||||
|
||||
display_bar_radius(9, 184, 108, 50, COLOR_BL_FAIL, COLOR_WHITE, 4);
|
||||
display_icon(9 + (108 - 16) / 2, 184 + (50 - 16) / 2, 16, 16, toi_icon_cancel + 12, sizeof(toi_icon_cancel) - 12, COLOR_WHITE, COLOR_BL_FAIL);
|
||||
display_bar_radius(123, 184, 108, 50, COLOR_BL_DONE, COLOR_WHITE, 4);
|
||||
display_icon(123 + (108 - 19) / 2, 184 + (50 - 16) / 2, 20, 16, toi_icon_confirm + 12, sizeof(toi_icon_confirm) - 12, COLOR_WHITE, COLOR_BL_DONE);
|
||||
}
|
||||
|
||||
void ui_screen_wipe(void)
|
||||
{
|
||||
display_fade(BACKLIGHT_NORMAL, 0, 100);
|
||||
@ -182,3 +215,20 @@ void ui_fadeout(void)
|
||||
display_fade(BACKLIGHT_NORMAL, 0, 500);
|
||||
display_clear();
|
||||
}
|
||||
|
||||
secbool ui_button_response(void)
|
||||
{
|
||||
for (;;) {
|
||||
uint32_t evt = touch_click();
|
||||
uint16_t x = touch_get_x(evt);
|
||||
uint16_t y = touch_get_y(evt);
|
||||
// clicked on cancel button
|
||||
if (x >= 9 && x < 9 + 108 && y > 184 && y < 184 + 50) {
|
||||
return secfalse;
|
||||
}
|
||||
// clicked on confirm button
|
||||
if (x >= 123 && x < 123 + 108 && y > 184 && y < 184 + 50) {
|
||||
return sectrue;
|
||||
}
|
||||
}
|
||||
}
|
@ -10,10 +10,12 @@ void ui_screen_boot_click(void);
|
||||
|
||||
void ui_screen_info(secbool buttons, const vendor_header * const vhdr, const image_header * const hdr);
|
||||
|
||||
void ui_screen_install_confirm(void);
|
||||
void ui_screen_install(void);
|
||||
void ui_screen_install_progress_erase(int pos, int len);
|
||||
void ui_screen_install_progress_upload(int pos);
|
||||
|
||||
void ui_screen_wipe_confirm(void);
|
||||
void ui_screen_wipe(void);
|
||||
void ui_screen_wipe_progress(int pos, int len);
|
||||
|
||||
@ -24,4 +26,6 @@ void ui_screen_fail(void);
|
||||
void ui_fadein(void);
|
||||
void ui_fadeout(void);
|
||||
|
||||
secbool ui_button_response(void);
|
||||
|
||||
#endif
|
||||
|
@ -119,6 +119,7 @@ static secbool bootloader_usb_loop(const vendor_header * const vhdr, const image
|
||||
// invalid header -> discard
|
||||
continue;
|
||||
}
|
||||
secbool response;
|
||||
switch (msg_id) {
|
||||
case 0: // Initialize
|
||||
process_msg_Initialize(USB_IFACE_NUM, msg_size, buf, vhdr, hdr);
|
||||
@ -127,6 +128,13 @@ static secbool bootloader_usb_loop(const vendor_header * const vhdr, const image
|
||||
process_msg_Ping(USB_IFACE_NUM, msg_size, buf);
|
||||
break;
|
||||
case 5: // WipeDevice
|
||||
ui_screen_wipe_confirm();
|
||||
response = ui_button_response();
|
||||
if (sectrue != response) {
|
||||
ui_screen_info(secfalse, vhdr, hdr);
|
||||
send_user_abort(USB_IFACE_NUM, "Wipe cancelled");
|
||||
break;
|
||||
}
|
||||
ui_screen_wipe();
|
||||
r = process_msg_WipeDevice(USB_IFACE_NUM, msg_size, buf);
|
||||
if (r < 0) { // error
|
||||
@ -142,6 +150,13 @@ static secbool bootloader_usb_loop(const vendor_header * const vhdr, const image
|
||||
}
|
||||
break;
|
||||
case 6: // FirmwareErase
|
||||
ui_screen_install_confirm();
|
||||
response = ui_button_response();
|
||||
if (sectrue != response) {
|
||||
ui_screen_info(secfalse, vhdr, hdr);
|
||||
send_user_abort(USB_IFACE_NUM, "Firmware install cancelled");
|
||||
break;
|
||||
}
|
||||
ui_screen_install();
|
||||
process_msg_FirmwareErase(USB_IFACE_NUM, msg_size, buf);
|
||||
break;
|
||||
@ -248,20 +263,10 @@ main_start:
|
||||
|
||||
if (touched || firmware_present != sectrue) {
|
||||
ui_screen_info(sectrue, pvhdr, phdr);
|
||||
for (;;) {
|
||||
uint32_t evt = touch_click();
|
||||
uint16_t x = touch_get_x(evt);
|
||||
uint16_t y = touch_get_y(evt);
|
||||
// clicked on cancel button
|
||||
if (x >= 9 && x < 9 + 108 && y > 184 && y < 184 + 50) {
|
||||
ui_fadeout();
|
||||
goto main_start;
|
||||
}
|
||||
// clicked on confirm button
|
||||
if (x >= 123 && x < 123 + 108 && y > 184 && y < 184 + 50) {
|
||||
ui_fadeout();
|
||||
break;
|
||||
}
|
||||
secbool response = ui_button_response();
|
||||
ui_fadeout();
|
||||
if (sectrue != response) {
|
||||
goto main_start;
|
||||
}
|
||||
ui_screen_info(secfalse, pvhdr, phdr);
|
||||
if (bootloader_usb_loop(pvhdr, phdr) != sectrue) {
|
||||
|
@ -231,6 +231,14 @@ static secbool _recv_msg(uint8_t iface_num, uint32_t msg_size, uint8_t *buf, con
|
||||
#define MSG_RECV_CALLBACK(FIELD, CALLBACK) { msg_recv.FIELD.funcs.decode = &CALLBACK; }
|
||||
#define MSG_RECV(TYPE) _recv_msg(iface_num, msg_size, buf, TYPE##_fields, &msg_recv)
|
||||
|
||||
void send_user_abort(uint8_t iface_num, const char *msg)
|
||||
{
|
||||
MSG_SEND_INIT(Failure);
|
||||
MSG_SEND_ASSIGN_VALUE(code, FailureType_Failure_ActionCancelled);
|
||||
MSG_SEND_ASSIGN_STRING(message, msg);
|
||||
MSG_SEND(Failure);
|
||||
}
|
||||
|
||||
void process_msg_Initialize(uint8_t iface_num, uint32_t msg_size, uint8_t *buf, const vendor_header * const vhdr, const image_header * const hdr)
|
||||
{
|
||||
MSG_RECV_INIT(Initialize);
|
||||
|
@ -16,6 +16,8 @@ extern const uint8_t firmware_sectors[FIRMWARE_SECTORS_COUNT];
|
||||
|
||||
secbool msg_parse_header(const uint8_t *buf, uint16_t *msg_id, uint32_t *msg_size);
|
||||
|
||||
void send_user_abort(uint8_t iface_num, const char *msg);
|
||||
|
||||
void process_msg_Initialize(uint8_t iface_num, uint32_t msg_size, uint8_t *buf, const vendor_header * const vhdr, const image_header * const hdr);
|
||||
void process_msg_Ping(uint8_t iface_num, uint32_t msg_size, uint8_t *buf);
|
||||
void process_msg_FirmwareErase(uint8_t iface_num, uint32_t msg_size, uint8_t *buf);
|
||||
|
Loading…
Reference in New Issue
Block a user