mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +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");
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
|
||||
if (image_check_signature((const uint8_t *)LOADER_START, &hdr, NULL)) {
|
||||
BOOTLOADER_PRINTLN("valid loader signature");
|
||||
|
||||
// TODO: remove debug wait
|
||||
BOOTLOADER_PRINTLN("waiting 1 second");
|
||||
HAL_Delay(1000);
|
||||
// end
|
||||
BOOTLOADER_PRINTLN("JUMP!");
|
||||
jump_to(LOADER_START + HEADER_SIZE);
|
||||
|
||||
} else {
|
||||
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)
|
||||
{
|
||||
LOADER_PRINTLN("checking firmware");
|
||||
LOADER_PRINTLN("checking vendor header");
|
||||
|
||||
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");
|
||||
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;
|
||||
}
|
||||
|
||||
LOADER_PRINTLN("checking firmware header");
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
|
||||
if (image_check_signature((const uint8_t *)(FIRMWARE_START + vhdr.hdrlen), &hdr, &vhdr)) {
|
||||
LOADER_PRINTLN("valid firmware signature");
|
||||
|
||||
display_vendor(vhdr.vimg, (const char *)vhdr.vstr, vhdr.vstr_len, hdr.version);
|
||||
HAL_Delay(1000); // TODO: remove?
|
||||
LOADER_PRINTLN("JUMP!");
|
||||
jump_to(FIRMWARE_START + vhdr.hdrlen + HEADER_SIZE);
|
||||
|
||||
} else {
|
||||
LOADER_PRINTLN("invalid firmware signature");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user