Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 128 additions & 22 deletions core/embed/bootloader/bootui.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ const char* format_ver(const char* format, uint32_t version) {
static uint16_t boot_background;
static bool ble_name_show = false;
static int ui_bootloader_page_current = 0;

static int current_progress_value = 0;

int get_current_progress_value(void) { return current_progress_value; }

char* format_progress_value(char* prefix) {
static char buf[128] = {0};
mini_snprintf(buf, sizeof(buf), "%s %d", prefix, current_progress_value);
return buf;
}

int get_ui_bootloader_page_current(void) { return ui_bootloader_page_current; }

void ui_logo_onekey(void) {
Expand Down Expand Up @@ -252,9 +263,7 @@ void ui_screen_firmware_fingerprint(const image_header* const hdr) {

// install UI

void ui_screen_install_confirm_newvendor_or_downgrade_wipe(
const vendor_header* const vhdr, const image_header* const hdr,
secbool downgrade_wipe) {
void ui_screen_install_confirm_newvendor_or_downgrade_wipe(char* new_version) {
vendor_header current_vhdr;
image_header current_hdr;
// char str[128] = {0};
Expand All @@ -272,10 +281,8 @@ void ui_screen_install_confirm_newvendor_or_downgrade_wipe(
ui_statusbar_update();
ui_logo_warning();

display_text_center(
MAX_DISPLAY_RESX / 2, TITLE_OFFSET_Y,
(sectrue == downgrade_wipe) ? "Firmware Downgrade" : "Vendor Change", -1,
FONT_PJKS_BOLD_38, COLOR_BL_FG, COLOR_BL_BG);
display_text_center(MAX_DISPLAY_RESX / 2, TITLE_OFFSET_Y, "Vendor Change", -1,
FONT_PJKS_BOLD_38, COLOR_BL_FG, COLOR_BL_BG);
display_text_center(DISPLAY_RESX / 2, SUBTITLE_OFFSET_Y,
"Still installing this firmware?", -1, FONT_NORMAL,
COLOR_BL_SUBTITLE, COLOR_BL_BG);
Expand All @@ -293,17 +300,10 @@ void ui_screen_install_confirm_newvendor_or_downgrade_wipe(
// } while (split);
display_bar_radius_ex(BOARD_OFFSET_X, 295, BUTTON_FULL_WIDTH, BUTTON_HEIGHT,
COLOR_BL_PANEL, COLOR_BL_BG, BUTTON_RADIUS);
const char* ver_str = format_ver("%d.%d.%d", current_hdr.onekey_version);
display_text_right(MAX_DISPLAY_RESX / 2 - 25, 350, ver_str, -1, FONT_NORMAL,
COLOR_BL_SUBTITLE, COLOR_BL_DARK);
ver_str = format_ver("%d.%d.%d", hdr->onekey_version);

display_text(MAX_DISPLAY_RESX / 2 + 25, 350, ver_str, -1, FONT_NORMAL,
display_text(MAX_DISPLAY_RESX / 2 + 25, 350, new_version, -1, FONT_NORMAL,
COLOR_BL_SUBTITLE, COLOR_BL_DARK);

display_image(227, 330, 25, 23, toi_icon_arrow_right + 12,
sizeof(toi_icon_arrow_right) - 12);

ui_confirm_cancel_buttons("Cancel", "Install", COLOR_BL_DARK, COLOR_BL_FAIL);
}

Expand Down Expand Up @@ -333,20 +333,31 @@ void ui_screen_confirm(char* title, char* note_l1, char* note_l2, char* note_l3,
ui_confirm_cancel_buttons("Back", "OK", COLOR_BL_DARK, COLOR_BL_FAIL);
}

void ui_screen_progress_bar_init(char* title, char* notes, int progress) {
ui_statusbar_update();
ui_logo_onekey();
if (title != NULL) {
display_text_center(DISPLAY_RESX / 2, TITLE_OFFSET_Y, title, -1,
FONT_PJKS_BOLD_38, COLOR_BL_FG, COLOR_BL_BG);
}
display_progress(notes ? notes : "Keep connected.", progress);
}

void ui_screen_progress_bar_prepare(char* title, char* notes) {
ui_statusbar_update();
ui_logo_onekey();
ui_screen_progress_bar_update(title, notes, -1);
}

void ui_screen_progress_bar_update(char* title, char* notes, int progress) {
if (title != NULL)
if (title != NULL) {
display_text_center(DISPLAY_RESX / 2, TITLE_OFFSET_Y, title, -1,
FONT_PJKS_BOLD_38, COLOR_BL_FG, COLOR_BL_BG);
}

if ((progress >= 0) && (progress <= 100)) {
if (progress > 0) {
display_progress(NULL, progress * 10);
display_progress(NULL, progress);
}
} else {
display_progress(notes ? notes : "Keep connected.", 0);
Expand All @@ -368,10 +379,13 @@ void ui_screen_install_progress_erase(int pos, int len) {
display_text_center(DISPLAY_RESX / 2, TITLE_OFFSET_Y, "Installing", -1,
FONT_PJKS_BOLD_38, COLOR_BL_FG, COLOR_BL_BG);

display_progress("Keep connected.", 250 * pos / len);
display_progress("Keep connected.", 25 * pos / len);
}

void ui_screen_install_progress_upload(int pos) { display_progress(NULL, pos); }
void ui_screen_install_progress_upload(int pos) {
current_progress_value = pos;
display_progress(NULL, pos);
}

// wipe UI

Expand Down Expand Up @@ -403,7 +417,7 @@ void ui_screen_wipe(void) {
}

void ui_screen_wipe_progress(int pos, int len) {
display_progress(NULL, 1000 * pos / len);
display_progress(NULL, 100 * pos / len);
}

void ui_screen_wipe_done(void) {
Expand Down Expand Up @@ -657,6 +671,20 @@ void ui_wipe_confirm(const image_header* const hdr) {
ui_confirm_cancel_buttons("Cancel", "Wipe", COLOR_BL_DARK, COLOR_BL_FAIL);
}

void ui_screen_install_title_clear(void) {
display_bar(0, TITLE_OFFSET_Y - 30, DISPLAY_RESX, TITLE_OFFSET_Y + 90,
COLOR_BLACK);
}

void ui_show_version_info(int y, char* current_ver, char* new_ver) {
display_text_right(3 * DISPLAY_RESX / 4 - 15, y, current_ver, -1, FONT_NORMAL,
COLOR_WHITE, COLOR_BL_PANEL);
display_text(3 * DISPLAY_RESX / 4 + 20, y, new_ver, -1, FONT_NORMAL,
COLOR_WHITE, COLOR_BL_PANEL);
display_image(350, y - 20, 25, 23, toi_icon_arrow_right + 12,
sizeof(toi_icon_arrow_right) - 12);
}

void ui_install_confirm(image_header* current_hdr,
const image_header* const new_hdr) {
if ((current_hdr == NULL) || (new_hdr == NULL)) return;
Expand Down Expand Up @@ -722,11 +750,89 @@ void ui_install_thd89_confirm(const char* old_ver, const char* boot_ver) {
ui_confirm_cancel_buttons("Cancel", "Install", COLOR_BL_DARK, COLOR_BL_DONE);
}

void ui_update_info_show(update_info_t update_info) {
int offset_y = SUBTITLE_OFFSET_Y;
int offset_x = 32;
int bar_height = 66;
int font_offset = 8;

ui_statusbar_update();
ui_logo_onekey();

display_text_center(DISPLAY_RESX / 2, TITLE_OFFSET_Y, "Update Firmware", -1,
FONT_PJKS_BOLD_38, COLOR_BL_FG, COLOR_BL_BG);

if (update_info.boot.type == UPDATE_BOOTLOADER) {
display_bar_radius_ex(BUTTON_LEFT_OFFSET_X, offset_y - bar_height / 2,
BUTTON_FULL_WIDTH, bar_height, COLOR_BL_PANEL,
COLOR_BL_BG, bar_height / 2);

display_text(offset_x, offset_y + font_offset, "Bootloader", -1,
FONT_NORMAL, COLOR_BL_FG, COLOR_BL_BG);

ui_show_version_info(offset_y + font_offset,
update_info.boot.current_version,
update_info.boot.new_version);
offset_y += 80;
}

if (update_info.mcu_location) {
display_bar_radius_ex(BUTTON_LEFT_OFFSET_X, offset_y - bar_height / 2,
BUTTON_FULL_WIDTH, bar_height, COLOR_BL_PANEL,
COLOR_BL_BG, bar_height / 2);

display_text(offset_x, offset_y + font_offset, "System", -1, FONT_NORMAL,
COLOR_BL_FG, COLOR_BL_BG);

ui_show_version_info(
offset_y + font_offset,
update_info.items[update_info.mcu_location - 1].current_version,
update_info.items[update_info.mcu_location - 1].new_version);
offset_y += 80;
}

if (update_info.se_count) {
display_bar_radius_ex(BUTTON_LEFT_OFFSET_X, offset_y - bar_height / 2,
BUTTON_FULL_WIDTH, bar_height, COLOR_BL_PANEL,
COLOR_BL_BG, bar_height / 2);

display_text(offset_x, offset_y + font_offset, "SE", -1, FONT_NORMAL,
COLOR_BL_FG, COLOR_BL_BG);
ui_show_version_info(
offset_y + font_offset,
update_info.items[update_info.se_location[0] - 1].current_version,
update_info.items[update_info.se_location[0] - 1].new_version);
offset_y += 80;
}

if (update_info.ble_location) {
display_bar_radius_ex(BUTTON_LEFT_OFFSET_X, offset_y - bar_height / 2,
BUTTON_FULL_WIDTH, bar_height, COLOR_BL_PANEL,
COLOR_BL_BG, bar_height / 2);

display_text(offset_x, offset_y + font_offset, "Bluetooth", -1, FONT_NORMAL,
COLOR_BL_FG, COLOR_BL_BG);
ui_show_version_info(
offset_y + font_offset,
update_info.items[update_info.ble_location - 1].current_version,
update_info.items[update_info.ble_location - 1].new_version);
offset_y += 80;
}

ui_confirm_cancel_buttons("Cancel", "Install", COLOR_BL_DARK, COLOR_BL_DONE);
}

void ui_bootloader_first(const image_header* const hdr) {
ui_bootloader_page_current = 0;
uint8_t se_state;
char se_info[64] = {0};

static image_header* current_hdr = NULL;

if (current_hdr == NULL && hdr) {
current_hdr = (image_header*)hdr;
}

ui_statusbar_update();
// info icon 48 * 48 - the entry point of the bootloader details
display_icon(INFO_ICON_OFFSET_X, INFO_ICON_OFFSET_Y, INFO_ICON_SIZE,
Expand All @@ -747,8 +853,8 @@ void ui_bootloader_first(const image_header* const hdr) {

display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 92, "SafeOS", -1,
FONT_PJKS_BOLD_38, COLOR_BL_FG, COLOR_BL_BG);
if (hdr) {
const char* ver_str = format_ver("%d.%d.%d", (hdr->onekey_version));
if (current_hdr) {
const char* ver_str = format_ver("%d.%d.%d", (current_hdr->onekey_version));
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 50, ver_str, -1,
FONT_NORMAL, COLOR_BL_SUBTITLE, COLOR_BL_BG);
}
Expand Down
10 changes: 7 additions & 3 deletions core/embed/bootloader/bootui.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "secbool.h"
#include "stdbool.h"

char* format_progress_value(char* prefix);

const char* format_ver(const char* format, uint32_t version);
void ui_screen_boot(const vendor_header* const vhdr,
const image_header* const hdr);
Expand All @@ -42,15 +44,14 @@ void ui_screen_firmware_fingerprint(const image_header* const hdr);

void ui_screen_install_confirm_upgrade(const vendor_header* const vhdr,
const image_header* const hdr);
void ui_screen_install_confirm_newvendor_or_downgrade_wipe(
const vendor_header* const vhdr, const image_header* const hdr,
secbool downgrade_wipe);
void ui_screen_install_confirm_newvendor_or_downgrade_wipe(char* new_version);
void ui_screen_install_start(void);
void ui_screen_install_progress_erase(int pos, int len);
void ui_screen_install_progress_upload(int pos);

void ui_screen_confirm(char* title, char* note_l1, char* note_l2, char* note_l3,
char* note_l4);
void ui_screen_progress_bar_init(char* title, char* notes, int progress);
void ui_screen_progress_bar_prepare(char* title, char* notes);
void ui_screen_progress_bar_update(char* msg_status, char* notes, int progress);

Expand Down Expand Up @@ -86,10 +87,13 @@ void ui_bootloader_simple(void);
void ui_bootloader_first(const image_header* const hdr);
void ui_bootloader_view_details(const image_header* const hdr);
void ui_wipe_confirm(const image_header* const hdr);
void ui_show_version_info(int y, char* current_ver, char* new_ver);
void ui_screen_install_title_clear(void);
void ui_install_confirm(image_header* current_hdr,
const image_header* const new_hdr);
void ui_install_ble_confirm(void);
void ui_install_thd89_confirm(const char* old_ver, const char* boot_ver);
void ui_update_info_show(update_info_t update_info);
void ui_install_progress(image_header* current_hdr,
const image_header* const new_hdr);
void ui_bootloader_page_switch(const image_header* const hdr);
Expand Down
67 changes: 60 additions & 7 deletions core/embed/bootloader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@
#include "camera.h"
#include "emmc_wrapper.h"

#define USB_IFACE_NUM 0

#if !PRODUCTION

// DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING
Expand Down Expand Up @@ -309,6 +307,50 @@ static void charge_switch(void) {
}
}

void bootloader_usb_loop_tiny(uint32_t tick) {
static uint32_t tick_start = 0;
if (tick_start == 0) {
tick_start = tick;
}
// 500ms
if (tick - tick_start > 500) {
tick_start = tick;
uint8_t buf[USB_PACKET_SIZE];
bool cmd_received = false;
if (USB_PACKET_SIZE == spi_slave_poll(buf)) {
host_channel = CHANNEL_SLAVE;
cmd_received = true;
} else if (USB_PACKET_SIZE ==
usb_webusb_read(USB_IFACE_NUM, buf, USB_PACKET_SIZE)) {
host_channel = CHANNEL_USB;
cmd_received = true;
}
if (cmd_received) {
if (buf[0] != '?' || buf[1] != '#' || buf[2] != '#') {
return;
}
if (buf[3] == 0 && buf[4] == 0) {
send_msg_features_simple(USB_IFACE_NUM);
} else {
send_failure(USB_IFACE_NUM, FailureType_Failure_ProcessError,
format_progress_value("Update mode"));
}
}
}
}

void enable_usb_tiny_task(bool init_usb) {
if (init_usb) {
usb_init_all(secfalse);
usb_start();
}
systick_enable_dispatch(SYSTICK_DISPATCH_USB_TINY, bootloader_usb_loop_tiny);
}

void disable_usb_tiny_task(void) {
systick_disable_dispatch(SYSTICK_DISPATCH_USB_TINY);
}

static secbool bootloader_usb_loop(const vendor_header* const vhdr,
const image_header* const hdr) {
// if both are NULL, we don't have a firmware installed
Expand Down Expand Up @@ -595,6 +637,10 @@ static void check_bootloader_version(void) {

#endif

static bool enter_boot_forced(void) {
return *BOOT_TARGET_FLAG_ADDR == BOOT_TARGET_BOOTLOADER;
}

static BOOT_TARGET decide_boot_target(vendor_header* const vhdr,
image_header* const hdr,
secbool* vhdr_valid, secbool* hdr_valid,
Expand Down Expand Up @@ -753,6 +799,10 @@ int main(void) {

#endif

if (!enter_boot_forced()) {
check_firmware_from_file(USB_IFACE_NULL);
}

vendor_header vhdr;
image_header hdr;
secbool vhdr_valid = secfalse;
Expand Down Expand Up @@ -800,17 +850,20 @@ int main(void) {

if ((vhdr.vtrust & VTRUST_CLICK) == 0) {
ui_screen_boot_click();
while (touch_read() == 0)
;
int counter = 0;
while (touch_read() == 0) {
hal_delay(10);
counter++;
if (counter > 200) {
break;
}
}
}
}

display_clear();
bus_fault_disable();

__disable_irq();
__disable_fault_irq();

// enable firmware region
mpu_config_firmware(sectrue, sectrue);

Expand Down
Loading
Loading