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

embed: refactor sector_count constants

This commit is contained in:
Pavol Rusnak 2018-06-20 14:52:39 +02:00
parent 815d30f41a
commit e7b761e66f
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 12 additions and 8 deletions

View File

@ -28,7 +28,6 @@
#define USB_PACKET_SIZE 64 #define USB_PACKET_SIZE 64
#define FIRMWARE_UPLOAD_CHUNK_RETRY_COUNT 2 #define FIRMWARE_UPLOAD_CHUNK_RETRY_COUNT 2
#define FIRMWARE_SECTORS_COUNT 13
extern const uint8_t firmware_sectors[FIRMWARE_SECTORS_COUNT]; extern const uint8_t firmware_sectors[FIRMWARE_SECTORS_COUNT];
secbool msg_parse_header(const uint8_t *buf, uint16_t *msg_id, uint32_t *msg_size); secbool msg_parse_header(const uint8_t *buf, uint16_t *msg_id, uint32_t *msg_size);

View File

@ -27,15 +27,18 @@
#define BOOTLOADER_START 0x08020000 #define BOOTLOADER_START 0x08020000
#define FIRMWARE_START 0x08040000 #define FIRMWARE_START 0x08040000
#define BOOTLOADER_SECTORS_COUNT (1)
#define FIRMWARE_SECTORS_COUNT (6 + 7)
#define IMAGE_HEADER_SIZE 0x400 #define IMAGE_HEADER_SIZE 0x400
#define IMAGE_SIG_SIZE 65 #define IMAGE_SIG_SIZE 65
#define IMAGE_CHUNK_SIZE (128 * 1024) #define IMAGE_CHUNK_SIZE (128 * 1024)
#define BOOTLOADER_IMAGE_MAGIC 0x425A5254 // TRZB #define BOOTLOADER_IMAGE_MAGIC 0x425A5254 // TRZB
#define BOOTLOADER_IMAGE_MAXSIZE (1 * IMAGE_CHUNK_SIZE) #define BOOTLOADER_IMAGE_MAXSIZE (BOOTLOADER_SECTORS_COUNT * IMAGE_CHUNK_SIZE)
#define FIRMWARE_IMAGE_MAGIC 0x465A5254 // TRZF #define FIRMWARE_IMAGE_MAGIC 0x465A5254 // TRZF
#define FIRMWARE_IMAGE_MAXSIZE (13 * IMAGE_CHUNK_SIZE) #define FIRMWARE_IMAGE_MAXSIZE (FIRMWARE_SECTORS_COUNT * IMAGE_CHUNK_SIZE)
typedef struct { typedef struct {
uint32_t magic; uint32_t magic;

View File

@ -37,6 +37,8 @@ def format_vtrust(vtrust):
IMAGE_HEADER_SIZE = 1024 IMAGE_HEADER_SIZE = 1024
IMAGE_SIG_SIZE = 65 IMAGE_SIG_SIZE = 65
IMAGE_CHUNK_SIZE = 128 * 1024 IMAGE_CHUNK_SIZE = 128 * 1024
BOOTLOADER_SECTORS_COUNT = 1
FIRMWARE_SECTORS_COUNT = 6 + 7
class BinImage(object): class BinImage(object):
@ -152,7 +154,7 @@ class BinImage(object):
class FirmwareImage(BinImage): class FirmwareImage(BinImage):
def __init__(self, data, vhdrlen): def __init__(self, data, vhdrlen):
super(FirmwareImage, self).__init__(data[vhdrlen:], magic=b'TRZF', max_size=6 * IMAGE_CHUNK_SIZE) super(FirmwareImage, self).__init__(data[vhdrlen:], magic=b'TRZF', max_size=FIRMWARE_SECTORS_COUNT * IMAGE_CHUNK_SIZE)
self.vhdrlen = vhdrlen self.vhdrlen = vhdrlen
self.vheader = data[:vhdrlen] self.vheader = data[:vhdrlen]
@ -166,7 +168,7 @@ class FirmwareImage(BinImage):
class BootloaderImage(BinImage): class BootloaderImage(BinImage):
def __init__(self, data): def __init__(self, data):
super(BootloaderImage, self).__init__(data, magic=b'TRZB', max_size=1 * IMAGE_CHUNK_SIZE) super(BootloaderImage, self).__init__(data, magic=b'TRZB', max_size=BOOTLOADER_SECTORS_COUNT * IMAGE_CHUNK_SIZE)
class VendorHeader(object): class VendorHeader(object):