forked from solokeys/solo1
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connected: #9
- Loading branch information
Showing
11 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ int main(int argc, char *argv[]) | |
TAG_RED| | ||
TAG_EXT| | ||
TAG_CCID| | ||
TAG_TIME | | ||
TAG_ERR | ||
); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include APP_CONFIG | ||
#include "flash.h" | ||
#include "log.h" | ||
#include "memory_layout.h" | ||
#include "nfc.h" | ||
#include "crypto.h" | ||
#include "device.h" | ||
#include "device-bootloader-update.h" | ||
|
||
|
||
#if !defined(IS_BOOTLOADER) && defined(APP_UPDATE_BOOTLOADER) | ||
#include "boot_payload.h" | ||
|
||
#warning "Bootloader payload added" | ||
|
||
void erase_bootloader(void){ | ||
int page; | ||
printf1(TAG_ERR,"Erasing bootloader\r\n"); | ||
for(page = 0; page < APPLICATION_START_PAGE; page++) | ||
{ | ||
printf1(TAG_ERR,"Erasing page: %d\r\n", page); | ||
flash_erase_page(page); | ||
} | ||
} | ||
|
||
void bootloader_calculate_hash(uint8_t *hash){ | ||
timestamp(); | ||
const uint16_t hashlen = APPLICATION_START_ADDR-BOOTLOADER_START_ADDR; | ||
crypto_sha256_init(); | ||
crypto_sha256_update( (uint8_t*) BOOTLOADER_START_ADDR, hashlen); | ||
crypto_sha256_final(hash); | ||
printf1(TAG_TIME,"hash time flash: %d ms\n",timestamp()); | ||
|
||
printf1(TAG_ERR, "hash: start: %p, len: %d\n", BOOTLOADER_START_ADDR, hashlen); | ||
dump_arrl(TAG_ERR, hash, 32); | ||
} | ||
|
||
void update_bootloader(void){ | ||
if (device_is_nfc() == NFC_IS_ACTIVE) | ||
{ | ||
printf1(TAG_ERR, "NFC is active. Skip bootloader update.\n"); | ||
return; | ||
} | ||
#if DEBUG_LEVEL >= 2 | ||
uint8_t hash[32]; | ||
bootloader_calculate_hash(hash); | ||
#endif | ||
bool success = memcmp((uint8_t*) BOOTLOADER_START_ADDR, boot_payload, boot_payload_length) == 0; | ||
if (success) { | ||
printf1(TAG_ERR, "Bootloader already up-to-date. Skipping.\n"); | ||
return; | ||
} | ||
led_rgb(0xFF0000); | ||
timestamp(); | ||
erase_bootloader(); //about 250 ms | ||
printf1(TAG_TIME,"boot erase: %d ms\n",timestamp()); | ||
printf1(TAG_ERR, "Write: %p %d\n", boot_payload, boot_payload_length); | ||
flash_write(BOOTLOADER_START_ADDR,boot_payload, boot_payload_length); //about 250 ms | ||
printf1(TAG_TIME,"boot write: %d ms\n",timestamp()); | ||
led_rgb(0x00FF00); | ||
|
||
success = memcmp((uint8_t*) BOOTLOADER_START_ADDR, boot_payload, boot_payload_length) == 0; | ||
#if DEBUG_LEVEL >= 2 | ||
bootloader_calculate_hash(hash); | ||
#endif | ||
|
||
led_rgb(0x0000FF); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef DEVICE_BOOTLOADER_UPDATE_H | ||
#define DEVICE_BOOTLOADER_UPDATE_H | ||
|
||
void update_bootloader(void); | ||
void bootloader_calculate_hash(uint8_t *hash); | ||
|
||
|
||
#endif //DEVICE_BOOTLOADER_UPDATE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters