mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
trezorhal: move image related defines to image.h
This commit is contained in:
parent
28aca51bc8
commit
0c6ee14ee1
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -3,11 +3,6 @@
|
||||
|
||||
#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);
|
||||
|
||||
void clear_otg_hs_memory(void);
|
||||
|
@ -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;
|
||||
|
@ -4,6 +4,11 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#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;
|
||||
|
Loading…
Reference in New Issue
Block a user