MYNEWT-618; bootloader was not calling hal_bsp_init(), so uart was not getting initialized. Watchdog needs to be tickled from within serial downloader.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/2c909377 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2c909377 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2c909377 Branch: refs/heads/develop Commit: 2c909377d4b3f1e1e9b886c061e48baf9ba7a2fb Parents: d484e46 Author: Marko Kiiskila <ma...@runtime.io> Authored: Fri Feb 3 15:44:27 2017 -0800 Committer: Marko Kiiskila <ma...@runtime.io> Committed: Fri Feb 3 15:44:27 2017 -0800 ---------------------------------------------------------------------- apps/boot/src/boot.c | 20 ++------------- boot/boot_serial/pkg.yml | 4 +++ boot/boot_serial/src/boot_serial.c | 43 +++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2c909377/apps/boot/src/boot.c ---------------------------------------------------------------------- diff --git a/apps/boot/src/boot.c b/apps/boot/src/boot.c index fbc4b7d..6b21407 100755 --- a/apps/boot/src/boot.c +++ b/apps/boot/src/boot.c @@ -28,8 +28,6 @@ #include <hal/hal_system.h> #include <hal/hal_flash.h> #if MYNEWT_VAL(BOOT_SERIAL) -#include <hal/hal_gpio.h> -#include <boot_serial/boot_serial.h> #include <sysinit/sysinit.h> #endif #include <console/console.h> @@ -39,10 +37,6 @@ #define BOOT_AREA_DESC_MAX (256) #define AREA_DESC_MAX (BOOT_AREA_DESC_MAX) -#if MYNEWT_VAL(BOOT_SERIAL) -#define BOOT_SER_CONS_INPUT 128 -#endif - int main(void) { @@ -50,23 +44,13 @@ main(void) int rc; #if MYNEWT_VAL(BOOT_SERIAL) + hal_bsp_init(); sysinit(); #else flash_map_init(); - hal_bsp_init(); + hal_bsp_init(); /* XXX this should be before flash_map_init() */ #endif -#if MYNEWT_VAL(BOOT_SERIAL) - /* - * Configure a GPIO as input, and compare it against expected value. - * If it matches, await for download commands from serial. - */ - hal_gpio_init_in(BOOT_SERIAL_DETECT_PIN, BOOT_SERIAL_DETECT_PIN_CFG); - if (hal_gpio_read(BOOT_SERIAL_DETECT_PIN) == BOOT_SERIAL_DETECT_PIN_VAL) { - boot_serial_start(BOOT_SER_CONS_INPUT); - assert(0); - } -#endif rc = boot_go(&rsp); assert(rc == 0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2c909377/boot/boot_serial/pkg.yml ---------------------------------------------------------------------- diff --git a/boot/boot_serial/pkg.yml b/boot/boot_serial/pkg.yml index 5913877..544c63a 100644 --- a/boot/boot_serial/pkg.yml +++ b/boot/boot_serial/pkg.yml @@ -37,3 +37,7 @@ pkg.deps: pkg.req_apis: - console + +pkg.init: + boot_serial_os_dev_init: 0 + boot_serial_pkg_init: 200 http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2c909377/boot/boot_serial/src/boot_serial.c ---------------------------------------------------------------------- diff --git a/boot/boot_serial/src/boot_serial.c b/boot/boot_serial/src/boot_serial.c index c46e270..d384b78 100644 --- a/boot/boot_serial/src/boot_serial.c +++ b/boot/boot_serial/src/boot_serial.c @@ -29,6 +29,8 @@ #include <flash_map/flash_map.h> #include <hal/hal_flash.h> #include <hal/hal_system.h> +#include <hal/hal_gpio.h> +#include <hal/hal_watchdog.h> #include <os/endian.h> #include <os/os.h> @@ -48,6 +50,7 @@ #include "boot_serial/boot_serial.h" #include "boot_serial_priv.h" +#define BOOT_SERIAL_INPUT_MAX 128 #define BOOT_SERIAL_OUT_MAX 48 static uint32_t curr_off; @@ -411,6 +414,9 @@ boot_serial_start(int max_input) int dec_off; int full_line; + rc = hal_watchdog_init(MYNEWT_VAL(WATCHDOG_INTERVAL)); + assert(rc == 0); + rc = console_init(NULL); assert(rc == 0); console_echo(0); @@ -421,12 +427,19 @@ boot_serial_start(int max_input) off = 0; while (1) { + hal_watchdog_tickle(); rc = console_read(buf + off, max_input - off, &full_line); if (rc <= 0 && !full_line) { continue; } off += rc; if (!full_line) { + if (off == max_input) { + /* + * Full line, no newline yet. Reset the input buffer. + */ + off = 0; + } continue; } if (buf[0] == SHELL_NLIP_PKT_START1 && @@ -443,3 +456,33 @@ boot_serial_start(int max_input) off = 0; } } + +/* + * os_init() will not be called with bootloader, so we need to initialize + * devices created by hal_bsp_init() here. + */ +void +boot_serial_os_dev_init(void) +{ + os_dev_initialize_all(OS_DEV_INIT_PRIMARY); + os_dev_initialize_all(OS_DEV_INIT_SECONDARY); + + /* + * Configure GPIO line as input. This is read later to see if + * we should stay and keep waiting for input. + */ + hal_gpio_init_in(BOOT_SERIAL_DETECT_PIN, BOOT_SERIAL_DETECT_PIN_CFG); +} + +void +boot_serial_pkg_init(void) +{ + /* + * Configure a GPIO as input, and compare it against expected value. + * If it matches, await for download commands from serial. + */ + if (hal_gpio_read(BOOT_SERIAL_DETECT_PIN) == BOOT_SERIAL_DETECT_PIN_VAL) { + boot_serial_start(BOOT_SERIAL_INPUT_MAX); + assert(0); + } +}