Skip to content

Commit

Permalink
Optional split of jump address from start address (ARMmbed#104)
Browse files Browse the repository at this point in the history
On targets like the NRF52, where the application's entry point is
not at the beginning of the firmware it is necessary to distinguish
between the two.

This commit adds an optional jump address to handle this corner
case. When the jump address is not defined the start address
becomes the default jump address.
  • Loading branch information
Marcus Chang authored and LiyouZhou committed Apr 30, 2018
1 parent 0d2873a commit 5ec5d35
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ NOTE: All these configurations must be set the same in the mbed cloud client whe
### Active Application and Header

1. `update-client.application-details`, Address at which the metadata header of the active firmware is written. **Must align to flash erase boundary**
1. `application-start-address`, Address at which The application starts **Must align to vector table size boundary and flash write page boundary**. It is assumed the region between `update-client.application-details` and `application-start-address` contains only the header. MUST be the same as "target.mbed_app_start" in the application.
1. `application-start-address`, Address at which the application starts **Must align to vector table size boundary and flash write page boundary**.
1. `application-jump-address`, Optional address for the application's entry point (vector table) if this is different from `application-start-address`.

If the `application-start-address` is set less than one erase sector after the `update-client.application-details`, the two regions will be erased together. Otherwise the two regions will be erased separately in which case `application-start-address` must also align to **flash erase boundary**.

If `application-jump-address` is not set, the `application-start-address` will be used as the application's entry point. The entry point MUST be the same as "target.mbed_app_start" in the application.

### Firmware Candidate Storage

1. `MBED_CLOUD_CLIENT_UPDATE_STORAGE`, This need to be set in the "macros" section of `mbed_app.json`. Choices are ARM_UCP_FLASHIAP_BLOCKDEVICE and ARM_UCP_FLASHIAP. This determines whether the firmware is stored on a blockdevice or internal flash. If blockdevice is used `ARM_UC_USE_PAL_BLOCKDEVICE=1` must also be set.
Expand Down
6 changes: 5 additions & 1 deletion mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
],
"config": {
"application-start-address": {
"help": "Address of the active application firmware in flash",
"help": "Address to the beginning of the active application firmware in flash",
"value": null
},
"application-jump-address": {
"help": "Jump address for running the active application firmware",
"value": null
},
"max-application-size": {
Expand Down
15 changes: 12 additions & 3 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO,
BlockDevice* arm_uc_blockdevice = &sd;
#endif

#ifndef MBED_CONF_APP_APPLICATION_START_ADDRESS
#error Application start address must be defined
#endif

/* If jump address is not set then default to start address. */
#ifndef MBED_CONF_APP_APPLICATION_JUMP_ADDRESS
#define MBED_CONF_APP_APPLICATION_JUMP_ADDRESS MBED_CONF_APP_APPLICATION_START_ADDRESS
#endif

int main(void)
{
/* Use malloc to allocate uint64_t version number on the heap */
Expand Down Expand Up @@ -167,15 +176,15 @@ int main(void)
firmware_update_test_end();
#endif
uint32_t app_start_addr = MBED_CONF_APP_APPLICATION_START_ADDRESS;
uint32_t app_stack_ptr = *((uint32_t*)(app_start_addr + 0));
uint32_t app_jump_addr = *((uint32_t*)(app_start_addr + 4));
uint32_t app_stack_ptr = *((uint32_t*)(MBED_CONF_APP_APPLICATION_JUMP_ADDRESS + 0));
uint32_t app_jump_addr = *((uint32_t*)(MBED_CONF_APP_APPLICATION_JUMP_ADDRESS + 4));

tr_info("Application's start address: 0x%" PRIX32, app_start_addr);
tr_info("Application's jump address: 0x%" PRIX32, app_jump_addr);
tr_info("Application's stack address: 0x%" PRIX32, app_stack_ptr);
tr_info("Forwarding to application...\r\n");

mbed_start_application(app_start_addr);
mbed_start_application(MBED_CONF_APP_APPLICATION_JUMP_ADDRESS);
}

/* Reset bootCounter; this allows a user to reapply a new bootloader
Expand Down

0 comments on commit 5ec5d35

Please sign in to comment.