finish bootloader

This commit is contained in:
Conor Patrick
2018-07-14 23:03:25 -04:00
parent b05f3cc9e8
commit 4cb4be21d9
17 changed files with 1504 additions and 51 deletions

View File

@@ -29,6 +29,11 @@
<folderInfo id="com.silabs.ss.tool.ide.arm.toolchain.gnu.cdt.debug#com.silabs.ss.tool.ide.arm.toolchain.gnu.cdt:7.2.1.20170904." name="/" resourcePath="">
<toolChain id="com.silabs.ide.si32.gcc.cdt.managedbuild.toolchain.exe.930698941" name="Si32 GNU ARM" superClass="com.silabs.ide.si32.gcc.cdt.managedbuild.toolchain.exe">
<option id="com.silabs.ide.si32.gcc.cdt.managedbuild.toolchain.debug.level.2037798819" name="Debug Level" superClass="com.silabs.ide.si32.gcc.cdt.managedbuild.toolchain.debug.level" value="com.silabs.ide.si32.gcc.cdt.managedbuild.toolchain.debug.level.default" valueType="enumerated"/>
<option id="com.silabs.ide.si32.gcc.cdt.managedbuild.tool.gnu.c.linker.overrideflash.495029551" name="Override default flash options" superClass="com.silabs.ide.si32.gcc.cdt.managedbuild.tool.gnu.c.linker.overrideflash" value="true" valueType="boolean"/>
<option id="com.silabs.ide.si32.gcc.cdt.managedbuild.tool.gnu.c.linker.flashlength.2021030475" name="LENGTH" superClass="com.silabs.ide.si32.gcc.cdt.managedbuild.tool.gnu.c.linker.flashlength" value="0x8000" valueType="string"/>
<option id="com.silabs.ide.si32.gcc.cdt.managedbuild.tool.gnu.c.linker.overrideram.2020332041" name="Override default RAM options" superClass="com.silabs.ide.si32.gcc.cdt.managedbuild.tool.gnu.c.linker.overrideram" value="true" valueType="boolean"/>
<option id="com.silabs.ide.si32.gcc.cdt.managedbuild.tool.gnu.c.linker.ramorigin.2081162957" name="ORIGIN" superClass="com.silabs.ide.si32.gcc.cdt.managedbuild.tool.gnu.c.linker.ramorigin" value="0x20000000" valueType="string"/>
<option id="com.silabs.ide.si32.gcc.cdt.managedbuild.tool.gnu.c.linker.ramlength.1981650487" name="LENGTH" superClass="com.silabs.ide.si32.gcc.cdt.managedbuild.tool.gnu.c.linker.ramlength" value="0x8000" valueType="string"/>
<targetPlatform binaryParser="org.eclipse.cdt.core.ELF;org.eclipse.cdt.core.GNU_ELF;com.silabs.ss.framework.debugger.core.BIN;com.silabs.ss.framework.debugger.core.HEX;com.silabs.ss.framework.debugger.core.S37;com.silabs.ss.framework.debugger.core.EBL;com.silabs.ss.framework.debugger.core.GBL" id="com.silabs.ide.si32.gcc.cdt.managedbuild.target.gnu.platform.base.613101530" isAbstract="false" name="Debug Platform" osList="win32,linux,macosx" superClass="com.silabs.ide.si32.gcc.cdt.managedbuild.target.gnu.platform.base"/>
<builder buildPath="${workspace_loc:/efm32boot}/GNU ARM v7.2.1 - Debug" id="com.silabs.ide.si32.gcc.cdt.managedbuild.target.gnu.builder.base.2113865201" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Si32 GNU ARM Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.silabs.ide.si32.gcc.cdt.managedbuild.target.gnu.builder.base"/>
<tool id="com.silabs.ide.si32.gcc.cdt.managedbuild.tool.gnu.c.compiler.base.981192541" name="GNU ARM C Compiler" superClass="com.silabs.ide.si32.gcc.cdt.managedbuild.tool.gnu.c.compiler.base">
@@ -91,9 +96,9 @@
</folderInfo>
<sourceEntries>
<entry excluding="crypto|fido2|efm32" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
<entry excluding="aes-gcm/|micro-ecc/examples/|micro-ecc/scripts/|micro-ecc/test/|tiny-AES-c/" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="crypto"/>
<entry excluding=".settings/|CMSIS/|docs/|emlib/|GNU ARM v7.2.1 - Debug/|hw/|inc/|mbedtls/|sl_crypto/|src/.crypto.c.swp|src/.device.c.swp|src/app.h|src/main.c|.cproject|.project|EFM32.hwconf|Makefile|src/crypto.c" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="efm32"/>
<entry excluding=".ctap_errors.h.swp|.ctap.c.swp|.ctap.h.swp|.main.c.swp|.storage.h.swp|.wallet.c.swp|.wallet.h.swp|crypto.c|main.c|ctap_parse.c|ctap.c" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="fido2"/>
<entry excluding="aes-gcm/|micro-ecc/examples/|micro-ecc/scripts/|micro-ecc/test/|tiny-AES-c/" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="crypto"/>
<entry excluding=".settings/|CMSIS/|docs/|emlib/|GNU ARM v7.2.1 - Debug/|hw/|inc/|mbedtls/|sl_crypto/|src/.crypto.c.swp|src/.device.c.swp|src/app.h|src/main.c|.cproject|.project|EFM32.hwconf|Makefile|src/crypto.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="efm32"/>
<entry excluding=".ctap_errors.h.swp|.ctap.c.swp|.ctap.h.swp|.main.c.swp|.storage.h.swp|.wallet.c.swp|.wallet.h.swp|crypto.c|main.c|ctap_parse.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="fido2"/>
</sourceEntries>
</configuration>
</storageModule>

View File

@@ -16,7 +16,18 @@
#define BRIDGE_TO_WALLET
#define JUMP_LOC 0x8000
#define PUSH_BUTTON gpioPortF,6
#define DISABLE_CTAPHID_PING
#define DISABLE_CTAPHID_WINK
#define DISABLE_CTAPHID_CBOR
void printing_init();
int bootloader_bridge(uint8_t klen, uint8_t * keyh);
int is_authorized_to_boot();
#endif /* SRC_APP_H_ */

98
efm32boot/src/boot.c Normal file
View File

@@ -0,0 +1,98 @@
/**************************************************************************//**
* @file boot.c
* @brief Functions for booting another application
* @author Silicon Labs
* @version 1.03
******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
* obligation to support this Software. Silicon Labs is providing the
* Software "AS IS", with no express or implied warranties of any kind,
* including, but not limited to, any implied warranties of merchantability
* or fitness for any particular purpose or warranties against infringement
* of any proprietary rights of a third party.
*
* Silicon Labs will not be liable for any consequential, incidental, or
* special damages, or any other relief, or for any claim by any third party,
* arising from your use of this Software.
*
******************************************************************************/
#include "em_device.h"
#include "em_gpio.h"
#include "em_cmu.h"
#include "app.h"
/******************************************************************************
* This function sets up the Cortex-M3 with a new SP and PC.
*****************************************************************************/
#if defined ( __CC_ARM )
__asm void BOOT_jump(uint32_t sp, uint32_t pc)
{
/* Set new MSP, PSP based on SP (r0)*/
msr msp, r0
msr psp, r0
/* Jump to PC (r1)*/
bx r1
}
#else
void BOOT_jump(uint32_t sp, uint32_t pc)
{
(void) sp;
(void) pc;
/* Set new MSP, PSP based on SP (r0)*/
__asm("msr msp, r0");
__asm("msr psp, r0");
/* Jump to PC (r1)*/
__asm("mov pc, r1");
}
#endif
/* Resets any peripherals that have been in use by
* the bootloader before booting the appliation */
static void resetPeripherals(void)
{
}
/******************************************************************************
* Boots the firmware. This function will activate the vector table
* of the firmware application and set the PC and SP from this table.
*****************************************************************************/
void BOOT_boot(void)
{
uint32_t pc, sp;
uint32_t *bootAddress = (uint32_t *)(JUMP_LOC);
resetPeripherals();
/* Set new vector table */
SCB->VTOR = (uint32_t)bootAddress;
/* Read new SP and PC from vector table */
sp = bootAddress[0];
pc = bootAddress[1];
/* Do a jump by loading the PC and SP into the CPU registers */
BOOT_jump(sp, pc);
}

View File

@@ -1,28 +1,106 @@
#include "em_device.h"
#include "em_chip.h"
#include "device.h"
#include "app.h"
#include "u2f.h"
#include "log.h"
#include "InitDevice.h"
void bootloader_init(void);
int main(void)
{
/* Chip errata */
CHIP_Init();
int count = 0;
uint32_t t1 = 0;
uint32_t t2 = 0;
uint32_t accum = 0;
uint32_t dt = 0;
uint8_t hidmsg[64];
/* Chip errata */
CHIP_Init();
EMU_enter_DefaultMode_from_RESET();
CMU_enter_DefaultMode_from_RESET();
// ADC0_enter_DefaultMode_from_RESET();
USART0_enter_DefaultMode_from_RESET();
USART1_enter_DefaultMode_from_RESET();
LDMA_enter_DefaultMode_from_RESET();
CRYOTIMER_enter_DefaultMode_from_RESET();
PORTIO_enter_DefaultMode_from_RESET();
EMU_enter_DefaultMode_from_RESET();
CMU_enter_DefaultMode_from_RESET();
// ADC0_enter_DefaultMode_from_RESET();
USART0_enter_DefaultMode_from_RESET();
USART1_enter_DefaultMode_from_RESET();
// LDMA_enter_DefaultMode_from_RESET();
CRYOTIMER_enter_DefaultMode_from_RESET();
PORTIO_enter_DefaultMode_from_RESET();
bootloader_init();
bootloader_init();
set_logging_mask(
/*0*/
TAG_GEN|
/*TAG_MC |*/
/*TAG_GA |*/
/*TAG_WALLET |*/
TAG_STOR |
/*TAG_CP |*/
// TAG_CTAP|
/*TAG_HID|*/
/*TAG_U2F|*/
/*TAG_PARSE |*/
// TAG_TIME|
/*TAG_DUMP|*/
/*TAG_GREEN|*/
/*TAG_RED|*/
TAG_ERR
);
printf("Bootloader init\r\n");
if (GPIO_PinInGet(PUSH_BUTTON) == 0)
{
t1 = millis();
while(GPIO_PinInGet(PUSH_BUTTON) == 0 && (millis() - t1) < 2000)
;
if (GPIO_PinInGet(PUSH_BUTTON) == 0) {
bootmode:
printf("Reflash condition detected\n");
ctaphid_init();
/* Infinite loop */
int count = 0;
while (1) {
if (millis() - t1 > 1000)
{
/*printf("heartbeat %ld\n", beat++);*/
heartbeat();
t1 = millis();
}
if (usbhid_recv(hidmsg) > 0)
{
/*printf("%d>> ",count++); dump_hex1(TAG_DUMP, hidmsg,sizeof(hidmsg));*/
// t2 = millis();
ctaphid_handle_packet(hidmsg);
// accum += millis() - t2;
// printf("accum: %d\n", (uint32_t)accum);
// printf("dt: %d\n", t2 - dt);
// dt = t2;
memset(hidmsg, 0, sizeof(hidmsg));
}
else
{
/*main_loop_delay();*/
}
ctaphid_check_timeouts();
}
}
}
printf("Normal boot\n");
if (is_authorized_to_boot())
{
BOOT_boot();
} else {
printf("Warning: not authorized to boot\n");
goto bootmode;
}
/* Infinite loop */
while (1) {
}
}