mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 09:28:13 +00:00
bootloader/loader: reorganize checking code
This commit is contained in:
parent
fad4b80af8
commit
a4a939058b
@ -118,19 +118,24 @@ void check_and_jump(void)
|
|||||||
BOOTLOADER_PRINTLN("checking loader");
|
BOOTLOADER_PRINTLN("checking loader");
|
||||||
|
|
||||||
image_header hdr;
|
image_header hdr;
|
||||||
if (!image_parse_header((const uint8_t *)LOADER_START, &hdr)) {
|
|
||||||
|
if (image_parse_header((const uint8_t *)LOADER_START, &hdr)) {
|
||||||
|
BOOTLOADER_PRINTLN("valid loader header");
|
||||||
|
} else {
|
||||||
BOOTLOADER_PRINTLN("invalid loader header");
|
BOOTLOADER_PRINTLN("invalid loader header");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (image_check_signature((const uint8_t *)LOADER_START, &hdr, NULL)) {
|
if (image_check_signature((const uint8_t *)LOADER_START, &hdr, NULL)) {
|
||||||
BOOTLOADER_PRINTLN("valid loader signature");
|
BOOTLOADER_PRINTLN("valid loader signature");
|
||||||
|
|
||||||
// TODO: remove debug wait
|
// TODO: remove debug wait
|
||||||
BOOTLOADER_PRINTLN("waiting 1 second");
|
BOOTLOADER_PRINTLN("waiting 1 second");
|
||||||
HAL_Delay(1000);
|
HAL_Delay(1000);
|
||||||
// end
|
// end
|
||||||
BOOTLOADER_PRINTLN("JUMP!");
|
BOOTLOADER_PRINTLN("JUMP!");
|
||||||
jump_to(LOADER_START + HEADER_SIZE);
|
jump_to(LOADER_START + HEADER_SIZE);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
BOOTLOADER_PRINTLN("invalid loader signature");
|
BOOTLOADER_PRINTLN("invalid loader signature");
|
||||||
}
|
}
|
||||||
|
@ -36,29 +36,41 @@ void display_vendor(const uint8_t *vimg, const char *vstr, uint32_t vstr_len, ui
|
|||||||
|
|
||||||
void check_and_jump(void)
|
void check_and_jump(void)
|
||||||
{
|
{
|
||||||
LOADER_PRINTLN("checking firmware");
|
LOADER_PRINTLN("checking vendor header");
|
||||||
|
|
||||||
vendor_header vhdr;
|
vendor_header vhdr;
|
||||||
if (!vendor_parse_header((const uint8_t *)(FIRMWARE_START), &vhdr)) {
|
if (vendor_parse_header((const uint8_t *)FIRMWARE_START, &vhdr)) {
|
||||||
|
LOADER_PRINTLN("valid vendor header");
|
||||||
|
} else {
|
||||||
LOADER_PRINTLN("invalid vendor header");
|
LOADER_PRINTLN("invalid vendor header");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!vendor_check_signature((const uint8_t *)(FIRMWARE_START), &vhdr)) {
|
|
||||||
LOADER_PRINTLN("unsigned vendor header");
|
if (vendor_check_signature((const uint8_t *)FIRMWARE_START, &vhdr)) {
|
||||||
|
LOADER_PRINTLN("valid vendor header signature");
|
||||||
|
} else {
|
||||||
|
LOADER_PRINTLN("invalid vendor header signature");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOADER_PRINTLN("checking firmware header");
|
||||||
|
|
||||||
image_header hdr;
|
image_header hdr;
|
||||||
if (!image_parse_header((const uint8_t *)(FIRMWARE_START + vhdr.hdrlen), &hdr)) {
|
if (image_parse_header((const uint8_t *)(FIRMWARE_START + vhdr.hdrlen), &hdr)) {
|
||||||
|
LOADER_PRINTLN("valid firmware header");
|
||||||
|
} else {
|
||||||
LOADER_PRINTLN("invalid firmware header");
|
LOADER_PRINTLN("invalid firmware header");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (image_check_signature((const uint8_t *)(FIRMWARE_START + vhdr.hdrlen), &hdr, &vhdr)) {
|
if (image_check_signature((const uint8_t *)(FIRMWARE_START + vhdr.hdrlen), &hdr, &vhdr)) {
|
||||||
LOADER_PRINTLN("valid firmware signature");
|
LOADER_PRINTLN("valid firmware signature");
|
||||||
|
|
||||||
display_vendor(vhdr.vimg, (const char *)vhdr.vstr, vhdr.vstr_len, hdr.version);
|
display_vendor(vhdr.vimg, (const char *)vhdr.vstr, vhdr.vstr_len, hdr.version);
|
||||||
HAL_Delay(1000); // TODO: remove?
|
HAL_Delay(1000); // TODO: remove?
|
||||||
LOADER_PRINTLN("JUMP!");
|
LOADER_PRINTLN("JUMP!");
|
||||||
jump_to(FIRMWARE_START + vhdr.hdrlen + HEADER_SIZE);
|
jump_to(FIRMWARE_START + vhdr.hdrlen + HEADER_SIZE);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LOADER_PRINTLN("invalid firmware signature");
|
LOADER_PRINTLN("invalid firmware signature");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user