Skip to content

Commit

Permalink
Transmit whole firmware with empty blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoHood committed Mar 19, 2016
1 parent b7c8245 commit 0cb1ec1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion SecureLoader/BootloaderHID.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ void EVENT_USB_Device_ControlRequest(void)
{
RunBootloader = false;
}
else{
// Do not overwrite the bootloader or write out of bounds
else if (PageAddress < BOOT_START_ADDR){
static uint8_t key[32] = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b,
0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b,
0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
Expand Down
7 changes: 4 additions & 3 deletions SecureLoader/HostLoaderApp/hid_bootloader_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ int main(int argc, char **argv)
aes256CbcMacInit(&ctx, key);

for (addr = 0; addr < code_size; addr += block_size) {
printf_verbose("\n%d", addr);
if (addr > 0 && !ihex_bytes_within_range(addr, addr + block_size - 1)) {
// don't waste time on blocks that are unused,
// but always do the first one to erase the chip
continue;
printf_verbose(" Empty block!");
//continue;
}
//printf_verbose(".");
printf_verbose("\n%d", addr);
if (code_size < 0x10000) {
buf[0] = addr & 255;
buf[1] = (addr >> 8) & 255;
Expand All @@ -176,7 +177,7 @@ int main(int argc, char **argv)

// Calculate and save CBC-MAC
aes256CbcMac(&ctx, buf, block_size + 2);
memcpy(buf + block_size + 2, ctx.cbcMac[i], AES256_CBC_LENGTH)
memcpy(buf + block_size + 2, ctx.cbcMac, AES256_CBC_LENGTH);

r = teensy_write(buf, block_size + 2 + AES256_CBC_LENGTH, first_block ? 3.0 : 0.25);
if (!r) die("error writing to Teensy\n");
Expand Down

0 comments on commit 0cb1ec1

Please sign in to comment.