1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-21 23:18:13 +00:00

loader: show firmware version in loader, remove image_options.h

This commit is contained in:
Pavol Rusnak 2017-04-05 17:41:10 +02:00
parent a4a939058b
commit fdef0575b1
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
7 changed files with 32 additions and 20 deletions

View File

@ -1,2 +0,0 @@
#define IMAGE_MAGIC 0x4C5A5254 // TRZL
#define IMAGE_MAXSIZE (1 * 64 * 1024 + 7 * 128 * 1024)

View File

@ -13,6 +13,9 @@
#define BOOTLOADER_PRINT(X) do { display_print(X, -1); display_print_out(BOOTLOADER_FGCOLOR, BOOTLOADER_BGCOLOR); } while(0)
#define BOOTLOADER_PRINTLN(X) do { display_print(X "\n", -1); display_print_out(BOOTLOADER_FGCOLOR, BOOTLOADER_BGCOLOR); } while(0)
#define IMAGE_MAGIC 0x4C5A5254 // TRZL
#define IMAGE_MAXSIZE (1 * 64 * 1024 + 7 * 128 * 1024)
void pendsv_isr_handler(void) {
__fatal_error("pendsv");
}
@ -43,7 +46,7 @@ bool check_sdcard(void)
sdcard_power_off();
if (image_parse_header((const uint8_t *)buf, NULL)) {
if (image_parse_header((const uint8_t *)buf, IMAGE_MAGIC, IMAGE_MAXSIZE, NULL)) {
BOOTLOADER_PRINTLN("SD card header is valid");
return true;
} else {
@ -86,7 +89,7 @@ bool copy_sdcard(void)
sdcard_read_blocks((uint8_t *)buf, 0, 1);
image_header hdr;
if (!image_parse_header((const uint8_t *)buf, &hdr)) {
if (!image_parse_header((const uint8_t *)buf, IMAGE_MAGIC, IMAGE_MAXSIZE, &hdr)) {
BOOTLOADER_PRINTLN("invalid header");
sdcard_power_off();
HAL_FLASH_Lock();
@ -119,7 +122,7 @@ void check_and_jump(void)
image_header hdr;
if (image_parse_header((const uint8_t *)LOADER_START, &hdr)) {
if (image_parse_header((const uint8_t *)LOADER_START, IMAGE_MAGIC, IMAGE_MAXSIZE, &hdr)) {
BOOTLOADER_PRINTLN("valid loader header");
} else {
BOOTLOADER_PRINTLN("invalid loader header");

View File

@ -1,2 +0,0 @@
#define IMAGE_MAGIC 0x465A5254 // TRZF
#define IMAGE_MAXSIZE (7 * 128 * 1024)

View File

@ -12,13 +12,15 @@
#define LOADER_PRINT(X) do { display_print(X, -1); display_print_out(LOADER_FGCOLOR, LOADER_BGCOLOR); } while(0)
#define LOADER_PRINTLN(X) do { display_print(X "\n", -1); display_print_out(LOADER_FGCOLOR, LOADER_BGCOLOR); } while(0)
#define IMAGE_MAGIC 0x465A5254 // TRZF
#define IMAGE_MAXSIZE (7 * 128 * 1024)
void pendsv_isr_handler(void) {
__fatal_error("pendsv");
}
void display_vendor(const uint8_t *vimg, const char *vstr, uint32_t vstr_len, uint32_t fw_version)
{
(void)fw_version;
display_clear();
if (memcmp(vimg, "TOIf", 4) != 0) {
return;
@ -29,8 +31,15 @@ void display_vendor(const uint8_t *vimg, const char *vstr, uint32_t vstr_len, ui
return;
}
uint32_t datalen = *(uint32_t *)(vimg + 8);
display_image((DISPLAY_RESX - w) / 2, (DISPLAY_RESY - h) / 2, w, h, vimg + 12, datalen);
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY * 3 / 4 + 20, vstr, vstr_len, FONT_BOLD, 0xFFFF, 0x0000);
display_image(60, 32, w, h, vimg + 12, datalen);
display_text_center(120, 192, vstr, vstr_len, FONT_BOLD, 0xFFFF, 0x0000);
char ver_str[] = "v0.0.0.0";
// TODO: fixme - the following does not work for values >= 10
ver_str[1] += fw_version & 0xFF;
ver_str[3] += (fw_version >> 8) & 0xFF;
ver_str[5] += (fw_version >> 16) & 0xFF;
ver_str[7] += (fw_version >> 24) & 0xFF;
display_text_center(120, 215, ver_str, -1, FONT_NORMAL, 0x7BEF, 0x0000);
display_refresh();
}
@ -56,7 +65,7 @@ void check_and_jump(void)
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), IMAGE_MAGIC, IMAGE_MAXSIZE, &hdr)) {
LOADER_PRINTLN("valid firmware header");
} else {
LOADER_PRINTLN("invalid firmware header");

View File

@ -51,7 +51,7 @@ static bool compute_pubkey(const vendor_header *vhdr, uint8_t sigmask, ed25519_p
return 0 == ed25519_cosi_combine_publickeys(res, keys, vsig_m);
}
bool image_parse_header(const uint8_t *data, image_header *hdr)
bool image_parse_header(const uint8_t *data, uint32_t magic, uint32_t maxsize, image_header *hdr)
{
if (!hdr) {
image_header h;
@ -59,7 +59,7 @@ bool image_parse_header(const uint8_t *data, image_header *hdr)
}
memcpy(&hdr->magic, data, 4);
if (hdr->magic != IMAGE_MAGIC) return false;
if (hdr->magic != magic) return false;
memcpy(&hdr->hdrlen, data + 4, 4);
if (hdr->hdrlen != HEADER_SIZE) return false;
@ -69,7 +69,7 @@ bool image_parse_header(const uint8_t *data, image_header *hdr)
memcpy(&hdr->codelen, data + 12, 4);
if (hdr->hdrlen + hdr->codelen < 4 * 1024) return false;
if (hdr->hdrlen + hdr->codelen > IMAGE_MAXSIZE) return false;
if (hdr->hdrlen + hdr->codelen > maxsize) return false;
if ((hdr->hdrlen + hdr->codelen) % 512 != 0) return false;
memcpy(&hdr->version, data + 16, 4);
@ -121,10 +121,14 @@ bool vendor_parse_header(const uint8_t *data, vendor_header *vhdr)
memcpy(&vhdr->vsig_m, data + 14, 1);
memcpy(&vhdr->vsig_n, data + 15, 1);
if (vhdr->vsig_n > MAX_VENDOR_PUBLIC_KEYS) {
return false;
}
for (int i = 0; i < vhdr->vsig_n; i++) {
vhdr->vpub[i] = data + 16 + i * 32;
}
for (int i = vhdr->vsig_n; i < 8; i++) {
for (int i = vhdr->vsig_n; i < MAX_VENDOR_PUBLIC_KEYS; i++) {
vhdr->vpub[i] = 0;
}

View File

@ -4,8 +4,6 @@
#include <stdint.h>
#include <stdbool.h>
#include "image_options.h"
typedef struct {
uint32_t magic;
uint32_t hdrlen;
@ -17,6 +15,8 @@ typedef struct {
uint8_t sig[64];
} image_header;
#define MAX_VENDOR_PUBLIC_KEYS 8
typedef struct {
uint32_t magic;
uint32_t hdrlen;
@ -24,7 +24,7 @@ typedef struct {
uint16_t version;
uint8_t vsig_m;
uint8_t vsig_n;
const uint8_t *vpub[8];
const uint8_t *vpub[MAX_VENDOR_PUBLIC_KEYS];
uint8_t vstr_len;
const uint8_t *vstr;
const uint8_t *vimg;
@ -32,7 +32,7 @@ typedef struct {
uint8_t sig[64];
} vendor_header;
bool image_parse_header(const uint8_t *data, image_header *hdr);
bool image_parse_header(const uint8_t *data, uint32_t magic, uint32_t maxsize, image_header *hdr);
bool image_check_signature(const uint8_t *data, const image_header *hdr, const vendor_header *vhdr);

2
vendor/norcow vendored

@ -1 +1 @@
Subproject commit ea6d2d03d07ca9c51ff22a1521ce35dfda9fc12e
Subproject commit 81c00e0a53792c5d2c29895824c861e5d4341737