Skip to content

Commit

Permalink
Touch thd89:update bootloader (#495)
Browse files Browse the repository at this point in the history
* fix(core):update the boot initialization process

* feat(core):display the boot version during SE upgrade

* fix(core):fix parameter error in the certificate reading interface
  • Loading branch information
lihuanhuan authored Oct 23, 2023
1 parent a0c2bb6 commit 5215a4a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
7 changes: 6 additions & 1 deletion core/embed/bootloader/bootui.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ void ui_install_ble_confirm(void) {
FONT_PJKS_BOLD_26, COLOR_BL_DONE, COLOR_BL_ICON);
}

void ui_install_thd89_confirm(const char *old_ver) {
void ui_install_thd89_confirm(const char *old_ver, const char *boot_ver) {
char str[128] = {0};
ui_title_update();
ui_logo_center();
Expand All @@ -824,6 +824,11 @@ void ui_install_thd89_confirm(const char *old_ver) {
strcat(str, old_ver);
display_text_center(DISPLAY_RESX / 2, 268, str, -1, FONT_NORMAL,
COLOR_BL_SUBTITLE, COLOR_BL_BG);
memset(str, 0, sizeof(str));
strcat(str, "boot version is ");
strcat(str, boot_ver);
display_text_center(DISPLAY_RESX / 2, 296, str, -1, FONT_NORMAL,
COLOR_BL_SUBTITLE, COLOR_BL_BG);

display_bar(8, 694, 231, 98, COLOR_BL_ICON);
display_text_center(DISPLAY_RESX / 4, 755, "Cancel", -1, FONT_PJKS_BOLD_26,
Expand Down
2 changes: 1 addition & 1 deletion core/embed/bootloader/bootui.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void ui_wipe_confirm(const image_header* const hdr);
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);
void ui_install_thd89_confirm(const char* old_ver, const char* boot_ver);
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
14 changes: 7 additions & 7 deletions core/embed/bootloader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,22 +460,22 @@ int main(void) {
lcd_para_init(DISPLAY_RESX, DISPLAY_RESY, LCD_PIXEL_FORMAT_RGB565);
lcd_pwm_init();

#if defined TREZOR_MODEL_T
// display_set_little_endian();
touch_init();
touch_power_on();
#endif

thd89_init();
se_reset_se();
hal_delay(350); // time for se to reset
hal_delay(500); // time for se to reset

random_delays_init();

ble_usart_init();

device_para_init();

#if defined TREZOR_MODEL_T
// display_set_little_endian();
touch_init();
touch_power_on();
#endif

#if defined TREZOR_MODEL_R
button_init();
rgb_led_init();
Expand Down
9 changes: 6 additions & 3 deletions core/embed/bootloader/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,21 +642,24 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
"Invalid firmware header");
return -3;
}
const char *se_version = se_get_version();
char se_ver[16] = {0}, boot_ver[16] = {0};
strncpy(se_ver, se_get_version(), sizeof(se_ver));
if (!se_back_to_boot_progress()) {
send_failure(iface_num, FailureType_Failure_ProcessError,
"SE back to boot error");
return -1;
}

strncpy(boot_ver, se_get_version(), sizeof(boot_ver));

if (!se_verify_firmware(chunk_buffer, IMAGE_HEADER_SIZE)) {
send_failure(iface_num, FailureType_Failure_ProcessError,
"SE verify header error");
return -1;
}

ui_fadeout();
ui_install_thd89_confirm(se_version);
ui_install_thd89_confirm(se_ver, boot_ver);
ui_fadein();

int response = INPUT_CANCEL;
Expand Down Expand Up @@ -1155,8 +1158,8 @@ void process_msg_ReadSEPublicCert(uint8_t iface_num, uint32_t msg_size,
MSG_RECV_INIT(ReadSEPublicCert);
MSG_RECV(ReadSEPublicCert);

uint16_t cert_len = 0;
uint8_t cert[512] = {0};
uint16_t cert_len = sizeof(cert);

MSG_SEND_INIT(SEPublicCert);
if (se_read_certificate(cert, &cert_len)) {
Expand Down
7 changes: 5 additions & 2 deletions core/embed/emmc_wrapper/emmc_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,21 +774,24 @@ int process_msg_FirmwareUpdateEmmc(uint8_t iface_num, uint32_t msg_size, uint8_t
send_failure(iface_num, FailureType_Failure_ProcessError, "Firmware file length error!");
return -1;
});
const char *se_version = se_get_version();
char se_ver[16] = {0}, boot_ver[16] = {0};
strncpy(se_ver, se_get_version(), sizeof(se_ver));
if ( !se_back_to_boot_progress() )
{
send_failure(iface_num, FailureType_Failure_ProcessError, "SE back to boot error");
return -1;
}

strncpy(boot_ver, se_get_version(), sizeof(boot_ver));

if ( !se_verify_firmware(bl_buffer->misc_buff, IMAGE_HEADER_SIZE))
{
send_failure(iface_num, FailureType_Failure_ProcessError, "SE verify header error");
return -1;
}
// ui confirm
ui_fadeout();
ui_install_thd89_confirm(se_version);
ui_install_thd89_confirm(se_ver, boot_ver);
ui_fadein();

int response = ui_input_poll(INPUT_CONFIRM | INPUT_CANCEL, true);
Expand Down
2 changes: 1 addition & 1 deletion core/embed/trezorhal/se_thd89.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ secbool se_read_certificate(uint8_t *cert, uint16_t *len) {

secbool se_has_cerrificate(void) {
uint8_t cert[512];
uint16_t cert_len;
uint16_t cert_len = sizeof(cert);
return se_read_certificate(cert, &cert_len);
}

Expand Down

0 comments on commit 5215a4a

Please sign in to comment.