Background:
We have a product that has one button that both power it on and that is used for simple commands, there is also one led to indicate its status. The button is latching the power on so that the device is not consuming any power when it is shut down. This product was developed using the legacy bootloader of SDK11. In this bootloader we used the app_timer to measure how long the user pressed the button to determine if we should start BL or App. A long press followed by tapping it starts the BL. This was easy because the softdevice and ble_stack was initialized before the check was done. Now before production we are going to use the new secure bootloader, (will be flashed in production, devices with old bl will not be updated), in order to be compatible with future versions. We are going to start of with SDK 12.3 for now.
In order to achieve this I have done some modifications to the secure bootloader and want to check with you that this is ok and will be a stable and good solution. We will also use the button-less dfu from app.
S132 v3.0.0. IAR 7.60.2 for the BL and IAR 8.30.1 for the App. The app uses FreeRTOS from SDK 14.2 and the rest is from SDK 12.3.
Secure BL Modifications:
The modifications are more or less copied from the legacy bootloader startup sequence:
- ble_stack_init(true) is moved from ble_dfu_transport_init() to nrf_dfu_init() (like the legacy bootloader only here it was in main.c). This is done right before nrf_dfu_enter_check.
- The initialization of the softdevice is commented out in nrf_bootloader_app_start. (because now the SD is already intialized)
- The softdevice_disable() is called before jumping to application (like the legacy bootloader).
ble_stack_init(true);
uint32_t nrf_dfu_init() { ... timers_init(); ble_stack_init(true); scheduler_init(); //check time of button press and decide ..... if(enter_bootloader_mode != 0 || !nrf_dfu_app_is_valid()) { ... } if (nrf_dfu_app_is_valid()) { app_timer_stop_all(); sd_softdevice_disable(); NRF_LOG_INFO("Jumping to: 0x%08x\r\n", MAIN_APPLICATION_START_ADDR); nrf_bootloader_app_start(MAIN_APPLICATION_START_ADDR); }
Questions:
- Is this ok? (it seems to work, but I need it to be bulletproof)
- Are there any thing else I need to de-init before jumping to the app now that I have initialized the ble_stack and SD?
- Are there any stability reasons for these design changes in the secure bl vs the legacy?
- In the legacy bootloader the SD was not initialized if the app_reset was set. Do I need to do a similar check in the secure BL with my modification?
Finally I would suggest some minor design pattern changes to the bootloader. I really like the weak functions you have provided that gives the user an easy way of customizing the bl for his product, however for the LEDs this is not the case.We use various blinking patterns for our single LED and have to modify all the parts of the SDK-code where the LEDs are changed. In stead it would be nice if you provided weak functions for the state-changes in the BL that enabled the user to do what he/she wants with leds and other stuff. Also BSP_BUTTON3 has to be defined even though I only have one button. It is important to keep the custom code in one place, otherwise it will be very time consuming to upgrade to newer SDK versions.
Thanks in advance and best regards
Erik