From 0c6ee14ee1830457155eec5e0ba1eebbdff5a754 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 26 Oct 2017 01:17:57 +0200 Subject: [PATCH] trezorhal: move image related defines to image.h --- embed/boardloader/main.c | 4 ++-- embed/bootloader/main.c | 2 +- embed/trezorhal/common.h | 5 ----- embed/trezorhal/image.c | 6 +++--- embed/trezorhal/image.h | 5 +++++ 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/embed/boardloader/main.c b/embed/boardloader/main.c index f1d071976f..a8c15f0cb8 100644 --- a/embed/boardloader/main.c +++ b/embed/boardloader/main.c @@ -112,7 +112,7 @@ static bool copy_sdcard(void) sdcard_power_on(); uint32_t buf[SDCARD_BLOCK_SIZE / sizeof(uint32_t)]; - for (int i = 0; i < (HEADER_SIZE + codelen) / SDCARD_BLOCK_SIZE; i++) { + for (int i = 0; i < (IMAGE_HEADER_SIZE + codelen) / SDCARD_BLOCK_SIZE; i++) { sdcard_read_blocks((uint8_t *)buf, i, 1); for (int j = 0; j < SDCARD_BLOCK_SIZE / sizeof(uint32_t); j++) { if (!flash_write_word(BOOTLOADER_START + i * SDCARD_BLOCK_SIZE + j * sizeof(uint32_t), buf[j])) { @@ -186,7 +186,7 @@ int main(void) image_check_signature((const uint8_t *)BOOTLOADER_START, &hdr, BOARDLOADER_KEY_M, BOARDLOADER_KEY_N, BOARDLOADER_KEYS), "invalid bootloader signature"); - jump_to(BOOTLOADER_START + HEADER_SIZE); + jump_to(BOOTLOADER_START + IMAGE_HEADER_SIZE); return 0; } diff --git a/embed/bootloader/main.c b/embed/bootloader/main.c index c9afb91412..be4a81b1b4 100644 --- a/embed/bootloader/main.c +++ b/embed/bootloader/main.c @@ -347,7 +347,7 @@ int main(void) display_fade(BACKLIGHT_NORMAL, 0, 500); display_clear(); - jump_to(FIRMWARE_START + vhdr.hdrlen + HEADER_SIZE); + jump_to(FIRMWARE_START + vhdr.hdrlen + IMAGE_HEADER_SIZE); return 0; } diff --git a/embed/trezorhal/common.h b/embed/trezorhal/common.h index a0c31d9b17..3c8cdf8285 100644 --- a/embed/trezorhal/common.h +++ b/embed/trezorhal/common.h @@ -3,11 +3,6 @@ #include -#define BOARDLOADER_START 0x08000000 -#define BOOTLOADER_START 0x08020000 -#define FIRMWARE_START 0x08040000 -#define HEADER_SIZE 0x200 - extern void memset_reg(volatile void *start, volatile void *stop, uint32_t val); void clear_otg_hs_memory(void); diff --git a/embed/trezorhal/image.c b/embed/trezorhal/image.c index 04da31dfb7..b3ab312e0e 100644 --- a/embed/trezorhal/image.c +++ b/embed/trezorhal/image.c @@ -35,7 +35,7 @@ bool image_parse_header(const uint8_t * const data, const uint32_t magic, const if (hdr->magic != magic) return false; memcpy(&hdr->hdrlen, data + 4, 4); - if (hdr->hdrlen != HEADER_SIZE) return false; + if (hdr->hdrlen != IMAGE_HEADER_SIZE) return false; memcpy(&hdr->expiry, data + 8, 4); // TODO: expiry mechanism needs to be ironed out before production or those @@ -63,11 +63,11 @@ bool image_check_signature(const uint8_t *data, const image_header *hdr, uint8_t uint8_t hash[BLAKE2S_DIGEST_LENGTH]; BLAKE2S_CTX ctx; blake2s_Init(&ctx, BLAKE2S_DIGEST_LENGTH); - blake2s_Update(&ctx, data, HEADER_SIZE - 65); + blake2s_Update(&ctx, data, IMAGE_HEADER_SIZE - 65); for (int i = 0; i < 65; i++) { blake2s_Update(&ctx, (const uint8_t *)"\x00", 1); } - blake2s_Update(&ctx, data + HEADER_SIZE, hdr->codelen); + blake2s_Update(&ctx, data + IMAGE_HEADER_SIZE, hdr->codelen); blake2s_Final(&ctx, hash, BLAKE2S_DIGEST_LENGTH); ed25519_public_key pub; diff --git a/embed/trezorhal/image.h b/embed/trezorhal/image.h index c00158b8a9..6f7bb3f744 100644 --- a/embed/trezorhal/image.h +++ b/embed/trezorhal/image.h @@ -4,6 +4,11 @@ #include #include +#define BOARDLOADER_START 0x08000000 +#define BOOTLOADER_START 0x08020000 +#define FIRMWARE_START 0x08040000 +#define IMAGE_HEADER_SIZE 0x200 + typedef struct { uint32_t magic; uint32_t hdrlen;