Skip to content

Commit 31f6a6f

Browse files
author
Daniel Campora
committed
cc3200: Enable bootloader safe boot on latest firmware.
The first safe boot level executes the latest firmware but skips 'main.py' and 'boot.py'.
1 parent e54a4f1 commit 31f6a6f

File tree

2 files changed

+52
-17
lines changed

2 files changed

+52
-17
lines changed

cc3200/bootmgr/main.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,16 @@
6464
#define BOOTMGR_HASH_SIZE 32
6565
#define BOOTMGR_BUFF_SIZE 512
6666

67-
#define BOOTMGR_WAIT_SAFE_MODE_0_MS 3000
68-
#define BOOTMGR_WAIT_SAFE_MODE_0_BLINK_MS 500
67+
#define BOOTMGR_WAIT_SAFE_MODE_0_MS 500
6968

7069
#define BOOTMGR_WAIT_SAFE_MODE_1_MS 3000
7170
#define BOOTMGR_WAIT_SAFE_MODE_1_BLINK_MS 250
7271

73-
#define BOOTMGR_WAIT_SAFE_MODE_2_MS 1500
74-
#define BOOTMGR_WAIT_SAFE_MODE_2_BLINK_MS 100
72+
#define BOOTMGR_WAIT_SAFE_MODE_2_MS 3000
73+
#define BOOTMGR_WAIT_SAFE_MODE_2_BLINK_MS 250
74+
75+
#define BOOTMGR_WAIT_SAFE_MODE_3_MS 1500
76+
#define BOOTMGR_WAIT_SAFE_MODE_3_BLINK_MS 100
7577

7678
//*****************************************************************************
7779
// Exported functions declarations
@@ -85,6 +87,7 @@ static void bootmgr_board_init (void);
8587
static bool bootmgr_verify (_u8 *image);
8688
static void bootmgr_load_and_execute (_u8 *image);
8789
static bool wait_while_blinking (uint32_t wait_time, uint32_t period, bool force_wait);
90+
static bool safe_boot_request_start (uint32_t wait_time);
8891
static void wait_for_safe_boot (sBootInfo_t *psBootInfo);
8992
static void bootmgr_image_loader (sBootInfo_t *psBootInfo);
9093

@@ -260,24 +263,33 @@ static bool wait_while_blinking (uint32_t wait_time, uint32_t period, bool force
260263
return MAP_GPIOPinRead(MICROPY_SAFE_BOOT_PORT, MICROPY_SAFE_BOOT_PORT_PIN) ? true : false;
261264
}
262265

266+
static bool safe_boot_request_start (uint32_t wait_time) {
267+
if (MAP_GPIOPinRead(MICROPY_SAFE_BOOT_PORT, MICROPY_SAFE_BOOT_PORT_PIN)) {
268+
UtilsDelay(UTILS_DELAY_US_TO_COUNT(wait_time * 1000));
269+
}
270+
return MAP_GPIOPinRead(MICROPY_SAFE_BOOT_PORT, MICROPY_SAFE_BOOT_PORT_PIN) ? true : false;
271+
}
272+
263273
//*****************************************************************************
264274
//! Check for the safe mode pin
265275
//*****************************************************************************
266276
static void wait_for_safe_boot (sBootInfo_t *psBootInfo) {
267-
if (wait_while_blinking(BOOTMGR_WAIT_SAFE_MODE_0_MS, BOOTMGR_WAIT_SAFE_MODE_0_BLINK_MS, false)) {
268-
// go back one step in time
269-
psBootInfo->ActiveImg = psBootInfo->PrevImg;
277+
if (safe_boot_request_start(BOOTMGR_WAIT_SAFE_MODE_0_MS)) {
270278
if (wait_while_blinking(BOOTMGR_WAIT_SAFE_MODE_1_MS, BOOTMGR_WAIT_SAFE_MODE_1_BLINK_MS, false)) {
271-
// go back directly to the factory image
272-
psBootInfo->ActiveImg = IMG_ACT_FACTORY;
273-
wait_while_blinking(BOOTMGR_WAIT_SAFE_MODE_2_MS, BOOTMGR_WAIT_SAFE_MODE_2_BLINK_MS, true);
279+
// go back one step in time
280+
psBootInfo->ActiveImg = psBootInfo->PrevImg;
281+
if (wait_while_blinking(BOOTMGR_WAIT_SAFE_MODE_2_MS, BOOTMGR_WAIT_SAFE_MODE_2_BLINK_MS, false)) {
282+
// go back directly to the factory image
283+
psBootInfo->ActiveImg = IMG_ACT_FACTORY;
284+
wait_while_blinking(BOOTMGR_WAIT_SAFE_MODE_3_MS, BOOTMGR_WAIT_SAFE_MODE_3_BLINK_MS, true);
285+
}
274286
}
275287
// turn off the system led
276288
MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, 0);
277289
// request a safe boot to the application
278290
PRCMRequestSafeBoot();
279291
}
280-
// uninit the safe boot pin
292+
// deinit the safe boot pin
281293
mperror_deinit_sfe_pin();
282294
}
283295

docs/wipy/general.rst

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ There is a small internal file system (a drive) on the WiPy, called ``/flash``,
1818
which is stored within the external serial flash memory. If a micro SD card
1919
is hooked-up and enabled, it is available as ``/sd``.
2020

21-
When the WiPy boots up, it always boots from the ``boot.py`` located in the
21+
When the WiPy boots up, it always boots from the ``boot.py`` located in the
2222
``/flash`` file system. If during the boot process the SD card is enabled and
2323
it's selected as the current drive then the WiPy will try to execute ``main.py``
2424
that should be located in the SD card.
@@ -28,6 +28,27 @@ Open your FTP client of choice and connect to:
2828

2929
``ftp://192.168.1.1``, ``user: micro``, ``password: python``
3030

31+
FileZilla settings
32+
------------------
33+
Do not use the quick connect button, instead, open the site manager and create a new
34+
configuration. In the ``General`` tab make sure that encryption is set to: ``Only use
35+
plain FTP (insecure)``. In the Transfer Settings tab limit the max number of connections
36+
to one, otherwise FileZilla will try to open a second command connection when retrieving
37+
and saving files, and for simplicity and to reduce code size, only one command and one
38+
data connections are possible. Other FTP clients might behave in a similar way.
39+
40+
Upgrading the firmware Over The Air
41+
-----------------------------------
42+
43+
OTA software updates can be performed through the FTP server. Upload the ``mcuimg.bin`` file
44+
to: ``/flash/sys/mcuimg.bin`` it will take around 6s. You won't see the file being stored
45+
inside ``/flash/sys/`` because it's actually saved bypassing the user file system, but rest
46+
assured that it was successfully transferred, and it has been signed with a MD5 checksum to
47+
verify its integrity. Now, reset the MCU by pressing the switch on the board, or by typing::
48+
49+
import pyb
50+
pyb.reset()
51+
3152
Boot modes
3253
----------
3354

@@ -54,19 +75,21 @@ and the WiPy will proceed to boot. The firmware selection mechanism is as follow
5475
+-------------------------+-------------------------+----------------------------+
5576
| 1st 3 secs window | 2nd 3 secs window | Final 1.5 secs window |
5677
+=========================+=========================+============================+
57-
| | Normal boot, *latest* | | Safe boot, *previous* | | Safe boot, the *factory* |
78+
| | Safe boot, *latest* | | Safe boot, *previous* | | Safe boot, the *factory* |
5879
| | firmware is selected | | user update selected | | firmware is selected |
5980
+-------------------------+-------------------------+----------------------------+
6081

61-
When selecting a previous firmware version, safe boot mode is entered, meaning
62-
that the execution of both ``boot.py`` and ``main.py`` is skipped. This is
63-
useful to recover from crash situations caused by the user scripts.
82+
In any if the above 3 scenarios, safe boot mode is entered, meaning that
83+
the execution of both ``boot.py`` and ``main.py`` is skipped. This is
84+
useful to recover from crash situations caused by the user scripts. The selection
85+
made during safe boot is not persistent, meaning that after the next normal reset,
86+
the latest firmware will run again.
6487

6588
The heart beat LED
6689
------------------
6790

6891
By default the heart beat LED flashes once every 5s to signal that the system is
69-
alive. This can be overridden through the HeartBeat class:
92+
alive. This can be overridden through the HeartBeat class:
7093

7194
``pyb.HeartBeat().disable()``
7295

0 commit comments

Comments
 (0)