1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 06:48:16 +00:00

trezorhal: move image related defines to image.h

This commit is contained in:
Pavol Rusnak 2017-10-26 01:17:57 +02:00
parent 28aca51bc8
commit 0c6ee14ee1
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
5 changed files with 11 additions and 11 deletions

View File

@ -112,7 +112,7 @@ static bool copy_sdcard(void)
sdcard_power_on(); sdcard_power_on();
uint32_t buf[SDCARD_BLOCK_SIZE / sizeof(uint32_t)]; 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); sdcard_read_blocks((uint8_t *)buf, i, 1);
for (int j = 0; j < SDCARD_BLOCK_SIZE / sizeof(uint32_t); j++) { 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])) { 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), image_check_signature((const uint8_t *)BOOTLOADER_START, &hdr, BOARDLOADER_KEY_M, BOARDLOADER_KEY_N, BOARDLOADER_KEYS),
"invalid bootloader signature"); "invalid bootloader signature");
jump_to(BOOTLOADER_START + HEADER_SIZE); jump_to(BOOTLOADER_START + IMAGE_HEADER_SIZE);
return 0; return 0;
} }

View File

@ -347,7 +347,7 @@ int main(void)
display_fade(BACKLIGHT_NORMAL, 0, 500); display_fade(BACKLIGHT_NORMAL, 0, 500);
display_clear(); display_clear();
jump_to(FIRMWARE_START + vhdr.hdrlen + HEADER_SIZE); jump_to(FIRMWARE_START + vhdr.hdrlen + IMAGE_HEADER_SIZE);
return 0; return 0;
} }

View File

@ -3,11 +3,6 @@
#include <stdint.h> #include <stdint.h>
#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); extern void memset_reg(volatile void *start, volatile void *stop, uint32_t val);
void clear_otg_hs_memory(void); void clear_otg_hs_memory(void);

View File

@ -35,7 +35,7 @@ bool image_parse_header(const uint8_t * const data, const uint32_t magic, const
if (hdr->magic != magic) return false; if (hdr->magic != magic) return false;
memcpy(&hdr->hdrlen, data + 4, 4); 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); memcpy(&hdr->expiry, data + 8, 4);
// TODO: expiry mechanism needs to be ironed out before production or those // 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]; uint8_t hash[BLAKE2S_DIGEST_LENGTH];
BLAKE2S_CTX ctx; BLAKE2S_CTX ctx;
blake2s_Init(&ctx, BLAKE2S_DIGEST_LENGTH); 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++) { for (int i = 0; i < 65; i++) {
blake2s_Update(&ctx, (const uint8_t *)"\x00", 1); 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); blake2s_Final(&ctx, hash, BLAKE2S_DIGEST_LENGTH);
ed25519_public_key pub; ed25519_public_key pub;

View File

@ -4,6 +4,11 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#define BOARDLOADER_START 0x08000000
#define BOOTLOADER_START 0x08020000
#define FIRMWARE_START 0x08040000
#define IMAGE_HEADER_SIZE 0x200
typedef struct { typedef struct {
uint32_t magic; uint32_t magic;
uint32_t hdrlen; uint32_t hdrlen;