1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

bootloader/loader: reorganize checking code

This commit is contained in:
Pavol Rusnak 2017-04-05 16:24:43 +02:00
parent fad4b80af8
commit a4a939058b
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 23 additions and 6 deletions

View File

@ -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");
}

View File

@ -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");
}