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

More alignment fixes

This commit is contained in:
Jochen Hoenicke 2016-08-29 23:22:49 +02:00
parent fd79570aaf
commit 6d65551b82
No known key found for this signature in database
GPG Key ID: 65B10C0466560648
5 changed files with 32 additions and 23 deletions

View File

@ -180,11 +180,15 @@ static void ethereumFormatAmount(bignum256 *val, char buffer[25])
char value[25] = {0};
char *value_ptr = value;
// convert val into base 1000 for easy printing.
uint16_t num[26];
uint8_t last_used = 0;
for (int i = 0; i < 26; i++) {
bn_divmod1000(val, (uint32_t *)&(num[i]));
if (num[i] > 0) {
uint32_t limb;
bn_divmod1000(val, &limb);
// limb is < 1000.
num[i] = (uint16_t) limb;
if (limb > 0) {
last_used = i;
}
}

View File

@ -51,9 +51,9 @@
// message methods
static uint8_t msg_resp[MSG_OUT_SIZE];
static uint8_t msg_resp[MSG_OUT_SIZE] __attribute__ ((aligned));
#define RESP_INIT(TYPE) TYPE *resp = (TYPE *)msg_resp; \
#define RESP_INIT(TYPE) TYPE *resp = (TYPE *) (void *) msg_resp; \
_Static_assert(sizeof(msg_resp) >= sizeof(TYPE), #TYPE " is too large"); \
memset(resp, 0, sizeof(TYPE));
@ -1142,10 +1142,10 @@ void fsm_msgDebugLinkMemoryWrite(DebugLinkMemoryWrite *msg)
if (msg->flash) {
flash_clear_status_flags();
flash_unlock();
uint32_t* src = (uint32_t *) msg->memory.bytes;
for (unsigned int i = 0; i < length; i += 4) {
flash_program_word(msg->address + i, *src);
src++;
uint32_t word;
memcpy(&word, msg->memory.bytes + i, 4);
flash_program_word(msg->address + i, word);
}
flash_lock();
} else {

View File

@ -42,7 +42,7 @@
Storage storage;
uint8_t storage_uuid[12];
uint32_t storage_uuid[12/sizeof(uint32_t)];
char storage_uuid_str[25];
/*
@ -77,6 +77,7 @@ be added to the storage u2f_counter to get the real counter value.
#define FLASH_STORAGE_U2FAREA (FLASH_STORAGE_PINAREA + FLASH_STORAGE_PINAREA_LEN)
#define FLASH_STORAGE_U2FAREA_LEN (0x100)
#define FLASH_STORAGE_REALLEN (4 + sizeof(storage_uuid) + sizeof(Storage))
_Static_assert(FLASH_STORAGE_START + FLASH_STORAGE_REALLEN <= FLASH_STORAGE_PINAREA, "Storage struct is too large for TREZOR flash");
_Static_assert((sizeof(storage_uuid) & 3) == 0, "storage uuid unaligned");
_Static_assert((sizeof(storage) & 3) == 0, "storage unaligned");
@ -87,6 +88,9 @@ _Static_assert((sizeof(storage) & 3) == 0, "storage unaligned");
*/
static uint32_t storage_u2f_offset;
/* magic constant to check validity of storage block */
static const uint32_t storage_magic = 0x726f7473; // 'stor' as uint32_t
static bool sessionSeedCached, sessionSeedUsesPassphrase;
static uint8_t sessionSeed[64];
@ -114,7 +118,7 @@ void storage_check_flash_errors(void)
bool storage_from_flash(void)
{
if (memcmp((void *)FLASH_STORAGE_START, "stor", 4) != 0) {
if (memcmp((void *)FLASH_STORAGE_START, &storage_magic, 4) != 0) {
// wrong magic
return false;
}
@ -182,7 +186,7 @@ void storage_init(void)
void storage_reset_uuid(void)
{
// set random uuid
random_buffer(storage_uuid, sizeof(storage_uuid));
random_buffer((uint8_t *)storage_uuid, sizeof(storage_uuid));
data2hex(storage_uuid, sizeof(storage_uuid), storage_uuid_str);
}
@ -216,7 +220,7 @@ static uint32_t storage_flash_words(uint32_t addr, uint32_t *src, int nwords) {
static void storage_commit_locked(void)
{
uint8_t meta_backup[FLASH_META_DESC_LEN];
uint32_t meta_backup[FLASH_META_DESC_LEN/4];
// backup meta
memcpy(meta_backup, (uint8_t*)FLASH_META_START, FLASH_META_DESC_LEN);
@ -225,11 +229,11 @@ static void storage_commit_locked(void)
flash_erase_sector(FLASH_META_SECTOR_FIRST, FLASH_CR_PROGRAM_X32);
// copy meta
uint32_t flash = FLASH_META_START;
flash = storage_flash_words(flash, (uint32_t *)meta_backup, FLASH_META_DESC_LEN/4);
flash = storage_flash_words(flash, meta_backup, FLASH_META_DESC_LEN/4);
// copy storage
flash_program_word(flash, *(uint32_t *) "stor");
flash_program_word(flash, storage_magic);
flash += 4;
flash = storage_flash_words(flash, (uint32_t *)&storage_uuid, sizeof(storage_uuid)/4);
flash = storage_flash_words(flash, storage_uuid, sizeof(storage_uuid)/4);
flash = storage_flash_words(flash, (uint32_t *)&storage, sizeof(storage)/4);
// fill remainder with zero for future extensions
while (flash < FLASH_STORAGE_PINAREA) {

View File

@ -297,7 +297,7 @@ void u2fhid_init(const U2FHID_FRAME *in)
{
const U2FHID_INIT_REQ *init_req = (const U2FHID_INIT_REQ *)&in->init.data;
U2FHID_FRAME f;
U2FHID_INIT_RESP *resp = (U2FHID_INIT_RESP *)f.init.data;
U2FHID_INIT_RESP resp;
debugLog(0, "", "u2fhid_init");
@ -312,13 +312,14 @@ void u2fhid_init(const U2FHID_FRAME *in)
f.init.bcnth = 0;
f.init.bcntl = U2FHID_INIT_RESP_SIZE;
memcpy(resp->nonce, init_req->nonce, sizeof(init_req->nonce));
resp->cid = in->cid == CID_BROADCAST ? next_cid() : in->cid;
resp->versionInterface = U2FHID_IF_VERSION;
resp->versionMajor = VERSION_MAJOR;
resp->versionMinor = VERSION_MINOR;
resp->versionBuild = VERSION_PATCH;
resp->capFlags = CAPFLAG_WINK;
memcpy(resp.nonce, init_req->nonce, sizeof(init_req->nonce));
resp.cid = in->cid == CID_BROADCAST ? next_cid() : in->cid;
resp.versionInterface = U2FHID_IF_VERSION;
resp.versionMajor = VERSION_MAJOR;
resp.versionMinor = VERSION_MINOR;
resp.versionBuild = VERSION_PATCH;
resp.capFlags = CAPFLAG_WINK;
memcpy(&f.init.data, &resp, sizeof(resp));
queue_u2f_pkt(&f);
}

View File

@ -342,7 +342,7 @@ static void hid_u2f_rx_callback(usbd_device *dev, uint8_t ep)
debugLog(0, "", "hid_u2f_rx_callback");
if ( usbd_ep_read_packet(dev, ENDPOINT_ADDRESS_U2F_OUT, buf, 64) != 64) return;
u2fhid_read(tiny, (const U2FHID_FRAME *)buf);
u2fhid_read(tiny, (const U2FHID_FRAME *) (void*) buf);
}
#if DEBUG_LINK