small refactoring, add efm8 reset
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
|
||||
#define IS_BOOTLOADER
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
|
||||
#define PRINTING_USE_VCOM
|
||||
|
||||
#define USING_DEV_BOARD
|
||||
@@ -20,7 +22,7 @@
|
||||
|
||||
#define PUSH_BUTTON gpioPortF,6
|
||||
|
||||
#define DISABLE_CTAPHID_PING
|
||||
//#define DISABLE_CTAPHID_PING
|
||||
#define DISABLE_CTAPHID_WINK
|
||||
#define DISABLE_CTAPHID_CBOR
|
||||
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include "ctap.h"
|
||||
#include "device.h"
|
||||
#include "app.h"
|
||||
#include "log.h"
|
||||
|
||||
#if defined(USING_PC) || defined(IS_BOOTLOADER)
|
||||
typedef enum
|
||||
@@ -101,7 +102,7 @@ void crypto_sha256_hmac_init(uint8_t * key, uint32_t klen, uint8_t * hmac)
|
||||
|
||||
if(klen > 64)
|
||||
{
|
||||
printf("Error, key size must be <= 64\n");
|
||||
printf2(TAG_ERR,"Error, key size must be <= 64\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ void crypto_sha256_hmac_final(uint8_t * key, uint32_t klen, uint8_t * hmac)
|
||||
|
||||
if(klen > 64)
|
||||
{
|
||||
printf("Error, key size must be <= 64\n");
|
||||
printf2(TAG_ERR,"Error, key size must be <= 64\n");
|
||||
exit(1);
|
||||
}
|
||||
memmove(buf, key, klen);
|
||||
@@ -165,7 +166,7 @@ void crypto_ecc256_sign(uint8_t * data, int len, uint8_t * sig)
|
||||
{
|
||||
if ( uECC_sign(_signing_key, data, len, sig, _es256_curve) == 0)
|
||||
{
|
||||
printf("error, uECC failed\n");
|
||||
printf2(TAG_ERR,"error, uECC failed\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -190,19 +191,19 @@ void crypto_ecdsa_sign(uint8_t * data, int len, uint8_t * sig, int MBEDTLS_ECP_I
|
||||
if (_key_len != 32) goto fail;
|
||||
break;
|
||||
default:
|
||||
printf("error, invalid ECDSA alg specifier\n");
|
||||
printf2(TAG_ERR,"error, invalid ECDSA alg specifier\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( uECC_sign(_signing_key, data, len, sig, curve) == 0)
|
||||
{
|
||||
printf("error, uECC failed\n");
|
||||
printf2(TAG_ERR,"error, uECC failed\n");
|
||||
exit(1);
|
||||
}
|
||||
return;
|
||||
|
||||
fail:
|
||||
printf("error, invalid key length\n");
|
||||
printf2(TAG_ERR,"error, invalid key length\n");
|
||||
exit(1);
|
||||
|
||||
}
|
||||
@@ -242,7 +243,7 @@ void crypto_ecc256_make_key_pair(uint8_t * pubkey, uint8_t * privkey)
|
||||
{
|
||||
if (uECC_make_key(pubkey, privkey, _es256_curve) != 1)
|
||||
{
|
||||
printf("Error, uECC_make_key failed\n");
|
||||
printf2(TAG_ERR,"Error, uECC_make_key failed\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -251,7 +252,7 @@ void crypto_ecc256_shared_secret(const uint8_t * pubkey, const uint8_t * privkey
|
||||
{
|
||||
if (uECC_shared_secret(pubkey, privkey, shared_secret, _es256_curve) != 1)
|
||||
{
|
||||
printf("Error, uECC_shared_secret failed\n");
|
||||
printf2(TAG_ERR,"Error, uECC_shared_secret failed\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@@ -51,7 +51,7 @@ int main(void)
|
||||
TAG_ERR
|
||||
);
|
||||
|
||||
printf("Bootloader init\r\n");
|
||||
printf1(TAG_GEN,"Bootloader init\r\n");
|
||||
|
||||
if (GPIO_PinInGet(PUSH_BUTTON) == 0)
|
||||
{
|
||||
@@ -60,8 +60,9 @@ int main(void)
|
||||
;
|
||||
if (GPIO_PinInGet(PUSH_BUTTON) == 0) {
|
||||
bootmode:
|
||||
printf("Reflash condition detected\n");
|
||||
printf1(TAG_GEN,"Reflash condition detected\n");
|
||||
ctaphid_init();
|
||||
reset_efm8();
|
||||
/* Infinite loop */
|
||||
int count = 0;
|
||||
while (1) {
|
||||
@@ -97,13 +98,13 @@ bootmode:
|
||||
}
|
||||
}
|
||||
|
||||
printf("Normal boot\n");
|
||||
printf1(TAG_GEN,"Normal boot\n");
|
||||
|
||||
if (is_authorized_to_boot())
|
||||
{
|
||||
BOOT_boot();
|
||||
} else {
|
||||
printf("Warning: not authorized to boot\n");
|
||||
printf1(TAG_GEN,"Warning: not authorized to boot\n");
|
||||
goto bootmode;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user