1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-02 19:01:04 +00:00

bootloader: wip

This commit is contained in:
Pavol Rusnak 2017-02-16 13:48:28 +01:00
parent 69f1569761
commit 8c296099f8
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
5 changed files with 22 additions and 11 deletions

View File

@ -17,10 +17,10 @@ res: ## update resources
build: build_stmhal build_unix build_cross ## build stmhal, unix and mpy-cross micropython ports
build_stmhal: vendor ## build stmhal port
build_stmhal: vendor build_cross ## build stmhal port
$(MAKE) -C vendor/micropython/stmhal BOARD=$(BOARD)
build_stmhal_debug: vendor ## build stmhal port with debug symbols
build_stmhal_debug: vendor build_cross ## build stmhal port with debug symbols
$(MAKE) -C vendor/micropython/stmhal BOARD=$(BOARD) DEBUG=1
build_stmhal_frozen: vendor res build_cross ## build stmhal port with frozen modules (from /src)

View File

@ -98,6 +98,8 @@ int main(void) {
check_sdcard();
check_signature();
if (check_header((const uint8_t *)STAGE2_START)) {
screen_stage2_jump();
// TODO: jump to second stage

View File

@ -5,17 +5,17 @@
#include "crypto.h"
/*
#define FLASH_BASE 0x08000000
void hash_flash(uint8_t hash[SHA256_DIGEST_LENGTH])
{
sha256_Raw((const uint8_t *)FLASH_BASE, 1024*1024, hash);
}
bool ed25519_verify(const uint8_t *msg, uint32_t msglen, uint8_t *pubkey, uint8_t *signature)
bool ed25519_verify(const uint8_t *msg, uint32_t msglen, const uint8_t *pubkey, const uint8_t *signature)
{
return (0 == ed25519_sign_open(msg, msglen, *(const ed25519_public_key *)pubkey, *(const ed25519_signature *)signature));
}
*/
bool check_header(const uint8_t *data)
{
@ -50,3 +50,13 @@ bool check_header(const uint8_t *data)
return true;
}
bool check_signature(void)
{
uint8_t hash[SHA256_DIGEST_LENGTH];
hash_flash(hash);
const uint8_t *pub = (const uint8_t *)"0123456789ABCDEF0123456789ABCDEF";
const uint8_t *sig = (const uint8_t *)"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
return ed25519_verify(hash, SHA256_DIGEST_LENGTH, pub, sig);
}

View File

@ -6,4 +6,6 @@
bool check_header(const uint8_t *data);
bool check_signature(void);
#endif

View File

@ -3,18 +3,15 @@
void screen_stage1(void)
{
display_clear();
display_text(0, 240, "BL stage 1", -1, FONT_MONO, ui_WHITE, ui_BLACK);
display_print("BL stage 1\n", -1);
}
void screen_stage2_jump(void)
{
display_clear();
display_text(0, 240, "BL stage 2 jump", -1, FONT_MONO, ui_WHITE, ui_BLACK);
display_print("BL stage 2 jump\n", -1);
}
void screen_stage2_invalid(void)
{
display_clear();
display_text(0, 240, "BL stage 2 invalid", -1, FONT_MONO, ui_WHITE, ui_BLACK);
display_print("BL stage 2 invalid\n", -1);
}