-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix bug in MBR for NRF52 series #6798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,8 @@ | |
extern uint32_t __Vectors[]; | ||
|
||
#define VECTORS_FLASH_START __Vectors | ||
#define UICR_BOOTLOADER_ADDRESS 0x10001014 | ||
#define MBR_ADDRESS 0x0 | ||
#define MBR_VTOR_ADDRESS 0x20000000 | ||
#define SOFTDEVICE_VTOR_ADDRESS 0x20000004 | ||
|
||
/** | ||
* @brief Function for relocation of the vector to RAM on nRF5x devices. | ||
|
@@ -68,36 +68,42 @@ extern uint32_t __Vectors[]; | |
void nrf_reloc_vector_table(void) | ||
{ | ||
// Copy and switch to dynamic vectors | ||
uint32_t *old_vectors = (uint32_t*)VECTORS_FLASH_START; | ||
uint32_t *old_vectors = VECTORS_FLASH_START; | ||
uint32_t i; | ||
for (i = 0; i< NVIC_NUM_VECTORS; i++) { | ||
nrf_dispatch_vector[i] = old_vectors[i]; | ||
} | ||
|
||
#if defined(SOFTDEVICE_PRESENT) | ||
/* Bootloader address is stored in UICR */ | ||
uint32_t *bootloader = (uint32_t *) UICR_BOOTLOADER_ADDRESS; | ||
|
||
/** | ||
* Before setting the new vector table address in the SoftDevice the MBR must be initialized. | ||
* If no bootloader is present the MBR will be initialized automatically. | ||
* Before setting the new vector table address in the SoftDevice the MBR must be initialized. | ||
* If no bootloader is present the MBR will be initialized automatically. | ||
* If a bootloader is present nrf_dfu_mbr_init_sd must be called once and only once. | ||
* | ||
* This application is a bootloader being booted for the first time if: | ||
* 1. The application's vector table (VECTORS_FLASH_START) is set in the UICR. | ||
* 2. SCB->VTOR is still pointing to the MBR's vector table (MBR_ADDRESS). | ||
* By resetting the MBR and SoftDevice VTOR address first, it becomes safe to initialize | ||
* the MBR again regardless of how the application was started. | ||
*/ | ||
if ((VECTORS_FLASH_START == (uint32_t *) *bootloader) && (SCB->VTOR == MBR_ADDRESS)) { | ||
|
||
/* Initialize MBR so SoftDevice service calls are being trapped correctly. */ | ||
nrf_dfu_mbr_init_sd(); | ||
} | ||
/* Reset MBR VTOR to original state before calling MBR init. */ | ||
uint32_t *mbr_vtor_address = (uint32_t *) MBR_VTOR_ADDRESS; | ||
*mbr_vtor_address = (uint32_t) VECTORS_FLASH_START; | ||
|
||
/* Reset SoftDevive VTOR. */ | ||
uint32_t *softdevice_vtor_address = (uint32_t *) SOFTDEVICE_VTOR_ADDRESS; | ||
*softdevice_vtor_address = 0xFFFFFFFF; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
|
||
/* Set SCB->VTOR to go through MBR to trap SoftDevice service calls. */ | ||
SCB->VTOR = 0x0; | ||
|
||
/* Initialize MBR so SoftDevice service calls are being trapped correctly. | ||
* This call sets MBR_VTOR_ADDRESS to point to the SoftDevice's VTOR at address 0x1000. | ||
*/ | ||
nrf_dfu_mbr_init_sd(); | ||
|
||
/* Instruct the SoftDevice to forward interrupts to the application's vector table in RAM. */ | ||
sd_softdevice_vector_table_base_set((uint32_t) nrf_dispatch_vector); | ||
|
||
#else | ||
|
||
/* No SoftDevice is present. Set all interrupts to vector table in RAM. */ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
MBR_VTOR_ADDRESS
the vector table itself or a pointer to the vector table address?