diff options
author | danicampora <danicampora@gmail.com> | 2015-02-25 22:38:33 +0100 |
---|---|---|
committer | danicampora <danicampora@gmail.com> | 2015-02-25 23:17:17 +0100 |
commit | 7a074a14ced0c9ea890793aa7dc43c896cfdf9b9 (patch) | |
tree | 02fee25f9d1375cde648ff82c87d0d0eacd2610e /cc3200/bootmgr | |
parent | 8a5aee103d0741efbbcf3fa7d0d0b3d2100eddb2 (diff) | |
download | micropython-7a074a14ced0c9ea890793aa7dc43c896cfdf9b9.tar.gz micropython-7a074a14ced0c9ea890793aa7dc43c896cfdf9b9.zip |
cc3200: Implement safe boot pin and system led behaviour.
The safe boot pin, when pulled high during reset rolls back the
firmware to the "factory" image and skips execution of 'boot.py'
and 'main.py'. This is useful to recover from a crash condition.
The system led is used mostly to signal errors.
Diffstat (limited to 'cc3200/bootmgr')
-rw-r--r-- | cc3200/bootmgr/bootloader.mk | 8 | ||||
-rw-r--r-- | cc3200/bootmgr/main.c | 56 |
2 files changed, 31 insertions, 33 deletions
diff --git a/cc3200/bootmgr/bootloader.mk b/cc3200/bootmgr/bootloader.mk index 64d7f671a9..1f687d9b88 100644 --- a/cc3200/bootmgr/bootloader.mk +++ b/cc3200/bootmgr/bootloader.mk @@ -5,6 +5,7 @@ BOOT_INC += -Ibootmgr/sl BOOT_INC += -Ihal BOOT_INC += -Ihal/inc BOOT_INC += -I../drivers/cc3100/inc +BOOT_INC += -Imisc BOOT_INC += -Imods BOOT_INC += -Isimplelink BOOT_INC += -Isimplelink/oslib @@ -39,6 +40,10 @@ BOOT_CC3100_SRC_C = $(addprefix drivers/cc3100/,\ src/wlan.c \ ) +BOOT_MISC_SRC_C = $(addprefix misc/,\ + mperror.c \ + ) + BOOT_MODS_SRC_C = $(addprefix mods/,\ pybwdt.c \ ) @@ -68,7 +73,7 @@ BOOT_STM_SRC_C = $(addprefix stmhal/,\ ) OBJ = $(addprefix $(BUILD)/, $(BOOT_HAL_SRC_C:.c=.o) $(BOOT_MODS_SRC_C:.c=.o) $(BOOT_SL_SRC_C:.c=.o) $(BOOT_CC3100_SRC_C:.c=.o) $(BOOT_UTIL_SRC_C:.c=.o)) -OBJ += $(addprefix $(BUILD)/, $(BOOT_MAIN_SRC_C:.c=.o) $(BOOT_MAIN_SRC_S:.s=.o) $(BOOT_PY_SRC_C:.c=.o) $(BOOT_STM_SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(BOOT_MISC_SRC_C:.c=.o) $(BOOT_MAIN_SRC_C:.c=.o) $(BOOT_MAIN_SRC_S:.s=.o) $(BOOT_PY_SRC_C:.c=.o) $(BOOT_STM_SRC_C:.c=.o)) # Add the linker script LINKER_SCRIPT = bootmgr/bootmgr.lds @@ -90,6 +95,7 @@ ifeq ($(BTYPE), debug) CFLAGS += -DDEBUG=DEBUG # Optimize the stable sources only $(BUILD)/hal/%.o: CFLAGS += -Os +$(BUILD)/misc/%.o: CFLAGS += -Os $(BUILD)/simplelink/%.o: CFLAGS += -Os $(BUILD)/drivers/cc3100/%.o: CFLAGS += -Os $(BUILD)/py/%.o: CFLAGS += -Os diff --git a/cc3200/bootmgr/main.c b/cc3200/bootmgr/main.c index 839e23ecdd..0e7ecd01b0 100644 --- a/cc3200/bootmgr/main.c +++ b/cc3200/bootmgr/main.c @@ -26,8 +26,10 @@ #include <stdint.h> #include <stdbool.h> - #include <std.h> + +#include "py/mpconfig.h" +#include MICROPY_HAL_H #include "hw_ints.h" #include "hw_types.h" #include "hw_gpio.h" @@ -50,6 +52,7 @@ #include "cc3200_hal.h" #include "debug.h" #include "pybwdt.h" +#include "mperror.h" //***************************************************************************** @@ -60,19 +63,11 @@ #define BOOTMGR_HASH_SIZE 32 #define BOOTMGR_BUFF_SIZE 512 -#define BOOTMGR_WAIT_SAFE_MODE_MS 2000 -#define BOOTMGR_WAIT_SAFE_MODE_TOOGLE_MS 250 - -#define BOOTMGR_SAFE_MODE_ENTER_MS 1000 -#define BOOTMGR_SAFE_MODE_ENTER_TOOGLE_MS 100 - -#define BOOTMGR_PINS_PRCM PRCM_GPIOA3 -#define BOOTMGR_PINS_PORT GPIOA3_BASE -#define BOOTMGR_LED_PIN_NUM PIN_21 -#define BOOTMGR_SFE_PIN_NUM PIN_18 -#define BOOTMGR_LED_PORT_PIN GPIO_PIN_1 // GPIO25 -#define BOOTMGR_SFE_PORT_PIN GPIO_PIN_4 // GPIO28 +#define BOOTMGR_WAIT_SAFE_MODE_MS 1600 +#define BOOTMGR_WAIT_SAFE_MODE_TOOGLE_MS 200 +#define BOOTMGR_SAFE_MODE_ENTER_MS 700 +#define BOOTMGR_SAFE_MODE_ENTER_TOOGLE_MS 70 //***************************************************************************** // Exported functions declarations @@ -159,18 +154,12 @@ static void bootmgr_board_init(void) { // Enable the Data Hashing Engine HASH_Init(); - // Enable GPIOA3 Peripheral Clock - MAP_PRCMPeripheralClkEnable(BOOTMGR_PINS_PRCM, PRCM_RUN_MODE_CLK); - - // Configure the bld - MAP_PinTypeGPIO(BOOTMGR_LED_PIN_NUM, PIN_MODE_0, false); - MAP_PinConfigSet(BOOTMGR_LED_PIN_NUM, PIN_STRENGTH_6MA, PIN_TYPE_STD); - MAP_GPIODirModeSet(BOOTMGR_PINS_PORT, BOOTMGR_LED_PORT_PIN, GPIO_DIR_MODE_OUT); + // Init the system led and the system switch + mperror_init0(); - // Configure the safe mode pin - MAP_PinTypeGPIO(BOOTMGR_SFE_PIN_NUM, PIN_MODE_0, false); - MAP_PinConfigSet(BOOTMGR_SFE_PIN_NUM, PIN_STRENGTH_4MA, PIN_TYPE_STD_PU); - MAP_GPIODirModeSet(BOOTMGR_PINS_PORT, BOOTMGR_SFE_PORT_PIN, GPIO_DIR_MODE_IN); + // clear the safe boot request, since we should not trust + // the register's state after reset + mperror_clear_safe_boot(); } //***************************************************************************** @@ -252,13 +241,14 @@ static void bootmgr_load_and_execute (_u8 *image) { //***************************************************************************** static bool safe_mode_boot (void) { _u32 count = 0; - while (!MAP_GPIOPinRead(BOOTMGR_PINS_PORT, BOOTMGR_SFE_PORT_PIN) && - ((BOOTMGR_WAIT_SAFE_MODE_TOOGLE_MS * count++) < BOOTMGR_WAIT_SAFE_MODE_MS)) { + while (MAP_GPIOPinRead(MICROPY_SAFE_BOOT_PORT, MICROPY_SAFE_BOOT_PORT_PIN) && + ((BOOTMGR_WAIT_SAFE_MODE_TOOGLE_MS * count++) < BOOTMGR_WAIT_SAFE_MODE_MS)) { // toogle the led - MAP_GPIOPinWrite(BOOTMGR_PINS_PORT, BOOTMGR_LED_PORT_PIN, ~MAP_GPIOPinRead(GPIOA3_BASE, BOOTMGR_LED_PORT_PIN)); + MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, ~MAP_GPIOPinRead(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN)); UtilsDelay(UTILS_DELAY_US_TO_COUNT(BOOTMGR_WAIT_SAFE_MODE_TOOGLE_MS * 1000)); } - return MAP_GPIOPinRead(BOOTMGR_PINS_PORT, BOOTMGR_SFE_PORT_PIN) ? false : true; + mperror_deinit_sfe_pin(); + return MAP_GPIOPinRead(MICROPY_SAFE_BOOT_PORT, MICROPY_SAFE_BOOT_PORT_PIN) ? true : false; } //***************************************************************************** @@ -268,14 +258,16 @@ static void bootmgr_image_loader(sBootInfo_t *psBootInfo) { _i32 fhandle; if (safe_mode_boot()) { _u32 count = 0; - while ((BOOTMGR_SAFE_MODE_ENTER_TOOGLE_MS * count++) > BOOTMGR_SAFE_MODE_ENTER_MS) { + while ((BOOTMGR_SAFE_MODE_ENTER_TOOGLE_MS * count++) < BOOTMGR_SAFE_MODE_ENTER_MS) { // toogle the led - MAP_GPIOPinWrite(BOOTMGR_PINS_PORT, BOOTMGR_LED_PORT_PIN, ~MAP_GPIOPinRead(GPIOA3_BASE, BOOTMGR_LED_PORT_PIN)); + MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, ~MAP_GPIOPinRead(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN)); UtilsDelay(UTILS_DELAY_US_TO_COUNT(BOOTMGR_SAFE_MODE_ENTER_TOOGLE_MS * 1000)); } psBootInfo->ActiveImg = IMG_ACT_FACTORY; // turn the led off - MAP_GPIOPinWrite(BOOTMGR_PINS_PORT, BOOTMGR_LED_PORT_PIN, 0); + MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, 0); + // request a safe boot to the application + mperror_request_safe_boot(); } // do we have a new update image that needs to be verified? else if ((psBootInfo->ActiveImg == IMG_ACT_UPDATE) && (psBootInfo->Status == IMG_STATUS_CHECK)) { @@ -350,7 +342,7 @@ int main (void) { // could not be loaded, so, loop forever and signal the crash to the user while (true) { // keep the bld on - MAP_GPIOPinWrite(BOOTMGR_PINS_PORT, BOOTMGR_LED_PORT_PIN, BOOTMGR_LED_PORT_PIN); + MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, MICROPY_SYS_LED_PORT_PIN); __asm volatile(" dsb \n" " isb \n" " wfi \n"); |