cc3200: Enable bootloader safe boot on latest firmware.

The first safe boot level executes the latest firmware but skips
'main.py' and 'boot.py'.
This commit is contained in:
Daniel Campora 2015-08-05 17:05:41 +02:00
parent e54a4f1f48
commit 31f6a6fa70
2 changed files with 52 additions and 17 deletions

View File

@ -64,14 +64,16 @@
#define BOOTMGR_HASH_SIZE 32 #define BOOTMGR_HASH_SIZE 32
#define BOOTMGR_BUFF_SIZE 512 #define BOOTMGR_BUFF_SIZE 512
#define BOOTMGR_WAIT_SAFE_MODE_0_MS 3000 #define BOOTMGR_WAIT_SAFE_MODE_0_MS 500
#define BOOTMGR_WAIT_SAFE_MODE_0_BLINK_MS 500
#define BOOTMGR_WAIT_SAFE_MODE_1_MS 3000 #define BOOTMGR_WAIT_SAFE_MODE_1_MS 3000
#define BOOTMGR_WAIT_SAFE_MODE_1_BLINK_MS 250 #define BOOTMGR_WAIT_SAFE_MODE_1_BLINK_MS 250
#define BOOTMGR_WAIT_SAFE_MODE_2_MS 1500 #define BOOTMGR_WAIT_SAFE_MODE_2_MS 3000
#define BOOTMGR_WAIT_SAFE_MODE_2_BLINK_MS 100 #define BOOTMGR_WAIT_SAFE_MODE_2_BLINK_MS 250
#define BOOTMGR_WAIT_SAFE_MODE_3_MS 1500
#define BOOTMGR_WAIT_SAFE_MODE_3_BLINK_MS 100
//***************************************************************************** //*****************************************************************************
// Exported functions declarations // Exported functions declarations
@ -85,6 +87,7 @@ static void bootmgr_board_init (void);
static bool bootmgr_verify (_u8 *image); static bool bootmgr_verify (_u8 *image);
static void bootmgr_load_and_execute (_u8 *image); static void bootmgr_load_and_execute (_u8 *image);
static bool wait_while_blinking (uint32_t wait_time, uint32_t period, bool force_wait); static bool wait_while_blinking (uint32_t wait_time, uint32_t period, bool force_wait);
static bool safe_boot_request_start (uint32_t wait_time);
static void wait_for_safe_boot (sBootInfo_t *psBootInfo); static void wait_for_safe_boot (sBootInfo_t *psBootInfo);
static void bootmgr_image_loader (sBootInfo_t *psBootInfo); static void bootmgr_image_loader (sBootInfo_t *psBootInfo);
@ -260,24 +263,33 @@ static bool wait_while_blinking (uint32_t wait_time, uint32_t period, bool force
return MAP_GPIOPinRead(MICROPY_SAFE_BOOT_PORT, MICROPY_SAFE_BOOT_PORT_PIN) ? true : false; return MAP_GPIOPinRead(MICROPY_SAFE_BOOT_PORT, MICROPY_SAFE_BOOT_PORT_PIN) ? true : false;
} }
static bool safe_boot_request_start (uint32_t wait_time) {
if (MAP_GPIOPinRead(MICROPY_SAFE_BOOT_PORT, MICROPY_SAFE_BOOT_PORT_PIN)) {
UtilsDelay(UTILS_DELAY_US_TO_COUNT(wait_time * 1000));
}
return MAP_GPIOPinRead(MICROPY_SAFE_BOOT_PORT, MICROPY_SAFE_BOOT_PORT_PIN) ? true : false;
}
//***************************************************************************** //*****************************************************************************
//! Check for the safe mode pin //! Check for the safe mode pin
//***************************************************************************** //*****************************************************************************
static void wait_for_safe_boot (sBootInfo_t *psBootInfo) { static void wait_for_safe_boot (sBootInfo_t *psBootInfo) {
if (wait_while_blinking(BOOTMGR_WAIT_SAFE_MODE_0_MS, BOOTMGR_WAIT_SAFE_MODE_0_BLINK_MS, false)) { if (safe_boot_request_start(BOOTMGR_WAIT_SAFE_MODE_0_MS)) {
if (wait_while_blinking(BOOTMGR_WAIT_SAFE_MODE_1_MS, BOOTMGR_WAIT_SAFE_MODE_1_BLINK_MS, false)) {
// go back one step in time // go back one step in time
psBootInfo->ActiveImg = psBootInfo->PrevImg; psBootInfo->ActiveImg = psBootInfo->PrevImg;
if (wait_while_blinking(BOOTMGR_WAIT_SAFE_MODE_1_MS, BOOTMGR_WAIT_SAFE_MODE_1_BLINK_MS, false)) { if (wait_while_blinking(BOOTMGR_WAIT_SAFE_MODE_2_MS, BOOTMGR_WAIT_SAFE_MODE_2_BLINK_MS, false)) {
// go back directly to the factory image // go back directly to the factory image
psBootInfo->ActiveImg = IMG_ACT_FACTORY; psBootInfo->ActiveImg = IMG_ACT_FACTORY;
wait_while_blinking(BOOTMGR_WAIT_SAFE_MODE_2_MS, BOOTMGR_WAIT_SAFE_MODE_2_BLINK_MS, true); wait_while_blinking(BOOTMGR_WAIT_SAFE_MODE_3_MS, BOOTMGR_WAIT_SAFE_MODE_3_BLINK_MS, true);
}
} }
// turn off the system led // turn off the system led
MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, 0); MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, 0);
// request a safe boot to the application // request a safe boot to the application
PRCMRequestSafeBoot(); PRCMRequestSafeBoot();
} }
// uninit the safe boot pin // deinit the safe boot pin
mperror_deinit_sfe_pin(); mperror_deinit_sfe_pin();
} }

View File

@ -28,6 +28,27 @@ Open your FTP client of choice and connect to:
``ftp://192.168.1.1``, ``user: micro``, ``password: python`` ``ftp://192.168.1.1``, ``user: micro``, ``password: python``
FileZilla settings
------------------
Do not use the quick connect button, instead, open the site manager and create a new
configuration. In the ``General`` tab make sure that encryption is set to: ``Only use
plain FTP (insecure)``. In the Transfer Settings tab limit the max number of connections
to one, otherwise FileZilla will try to open a second command connection when retrieving
and saving files, and for simplicity and to reduce code size, only one command and one
data connections are possible. Other FTP clients might behave in a similar way.
Upgrading the firmware Over The Air
-----------------------------------
OTA software updates can be performed through the FTP server. Upload the ``mcuimg.bin`` file
to: ``/flash/sys/mcuimg.bin`` it will take around 6s. You won't see the file being stored
inside ``/flash/sys/`` because it's actually saved bypassing the user file system, but rest
assured that it was successfully transferred, and it has been signed with a MD5 checksum to
verify its integrity. Now, reset the MCU by pressing the switch on the board, or by typing::
import pyb
pyb.reset()
Boot modes Boot modes
---------- ----------
@ -54,13 +75,15 @@ and the WiPy will proceed to boot. The firmware selection mechanism is as follow
+-------------------------+-------------------------+----------------------------+ +-------------------------+-------------------------+----------------------------+
| 1st 3 secs window | 2nd 3 secs window | Final 1.5 secs window | | 1st 3 secs window | 2nd 3 secs window | Final 1.5 secs window |
+=========================+=========================+============================+ +=========================+=========================+============================+
| | Normal boot, *latest* | | Safe boot, *previous* | | Safe boot, the *factory* | | | Safe boot, *latest* | | Safe boot, *previous* | | Safe boot, the *factory* |
| | firmware is selected | | user update selected | | firmware is selected | | | firmware is selected | | user update selected | | firmware is selected |
+-------------------------+-------------------------+----------------------------+ +-------------------------+-------------------------+----------------------------+
When selecting a previous firmware version, safe boot mode is entered, meaning In any if the above 3 scenarios, safe boot mode is entered, meaning that
that the execution of both ``boot.py`` and ``main.py`` is skipped. This is the execution of both ``boot.py`` and ``main.py`` is skipped. This is
useful to recover from crash situations caused by the user scripts. useful to recover from crash situations caused by the user scripts. The selection
made during safe boot is not persistent, meaning that after the next normal reset,
the latest firmware will run again.
The heart beat LED The heart beat LED
------------------ ------------------