nRF51 production: program whole flash with one image and start with app mode

Recently, there are a few queries from Japanese customers on nRF51 production. Basically the expectations are

- Program the flash as a whole, including bootloader, application and soft device
- Target starts up as application not bootloader 

I did a test in SDK 8.1.0 and achieved like below.

First, we update the bootloader project to make it run App on start up.

SDK_8.1.0\components\libraries\bootloader_dfu\bootloader_settings.c

#if defined ( __CC_ARM )
#ifdef DFU_CUSTOMIZE
uint8_t  m_boot_settings[CODE_PAGE_SIZE] __attribute__((at(BOOTLOADER_SETTINGS_ADDRESS))) __attribute__((used)) = {BANK_VALID_APP}; /**< This variable reserves a codepage for bootloader specific settings, to ensure the compiler doesn't locate any code or variables at his location. */
#else
uint8_t  m_boot_settings[CODE_PAGE_SIZE] __attribute__((at(BOOTLOADER_SETTINGS_ADDRESS))) __attribute__((used));                /**< This variable reserves a codepage for bootloader specific settings, to ensure the compiler doesn't locate any code or variables at his location. */
#endif

Here I only updated the __CC_ARM part, with code under #ifdef DFU_CUSTOMIZE. The idiea is to initiate m_boot_settings with BANK_VALID_APP flag for Bootloader main() to start App.

Reference link: https://devzone.nordicsemi.com/question/12800/flashing-bootloader-and-application-via-j-link/

Build project 8.1.0\examples\dfu\bootloader\pca10028\dual_bank_ble_s130\arm5_no_packs with the flag of DFU_CUSTOMIZE and get the customized bootloader "nrf51422_xxac.hex". Copy it to SDK_8.1.0\examples\dfu\ble_dfu_send_hex\test_images_update for later merging.

Copy the S130 softdevice hex to SDK_8.1.0\examples\dfu\ble_dfu_send_hex\test_images_update, too.

Open a CMD window, move to ** SDK_8.1.0\examples\dfu\ble_dfu_send_hex\test_images_update**. Next merge the bootloader, the application and the softdevice into one .hex.

SDK_8.1.0\examples\dfu\ble_dfu_send_hex\test_images_update>mergehex -m s130_nrf51_1.0.0_softdevice.hex dfu_test_app_hrm_s130.hex nrf51422_xxac.hex -o merged_image.hex
Parsing input hex files.
Merging files.
Storing merged file.

Next, flash the whole image to nRF51DK

SDK_8.1.0\examples\dfu\ble_dfu_send_hex\test_images_update>nrfjprog --eraseall
Erasing code and UICR flash areas.
Applying system reset.

SDK_8.1.0\examples\dfu\ble_dfu_send_hex\test_images_update>nrfjprog --program merged_image.hex
Parsing hex file.
Reading flash area to program to guarantee it is erased.
Checking that the area to write is not protected.
Programing device.

SDK_8.1.0\examples\dfu\ble_dfu_send_hex\test_images_update>nrfjprog --reset
Applying system reset.
Run.

Last, confirm the App is running with MCP.

image description