Skip to content

Commit bce102e

Browse files
committed
remove address from checking app valid function
either use address after SD or MBR
1 parent d95684c commit bce102e

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

lib/sdk11/components/libraries/bootloader_dfu/bootloader.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,37 +143,32 @@ static void wait_for_events(void)
143143
}
144144

145145

146-
bool bootloader_app_is_valid(uint32_t app_addr)
146+
bool bootloader_app_is_valid(void)
147147
{
148-
bootloader_settings_t const * p_bootloader_settings;
148+
uint32_t const app_addr = DFU_BANK_0_REGION_START;
149+
bootloader_settings_t const *p_bootloader_settings;
149150

150-
// There exists an application in CODE region 1.
151-
if (*((uint32_t *)app_addr) == EMPTY_FLASH_MASK)
152-
{
153-
return false;
154-
}
151+
bool success = false;
155152

156-
bool success = false;
153+
bootloader_util_settings_get(&p_bootloader_settings);
157154

158-
bootloader_util_settings_get(&p_bootloader_settings);
155+
// The application in CODE region 1 is flagged as valid during update.
156+
if ( p_bootloader_settings->bank_0 == BANK_VALID_APP )
157+
{
158+
uint16_t image_crc = 0;
159159

160-
// The application in CODE region 1 is flagged as valid during update.
161-
if (p_bootloader_settings->bank_0 == BANK_VALID_APP)
160+
// A stored crc value of 0 indicates that CRC checking is not used.
161+
if ( p_bootloader_settings->bank_0_crc != 0 )
162162
{
163-
uint16_t image_crc = 0;
164-
165-
// A stored crc value of 0 indicates that CRC checking is not used.
166-
if (p_bootloader_settings->bank_0_crc != 0)
167-
{
168-
image_crc = crc16_compute((uint8_t *)app_addr,
169-
p_bootloader_settings->bank_0_size,
170-
NULL);
171-
}
172-
173-
success = (image_crc == p_bootloader_settings->bank_0_crc);
163+
image_crc = crc16_compute((uint8_t*) app_addr,
164+
p_bootloader_settings->bank_0_size,
165+
NULL);
174166
}
175167

176-
return success;
168+
success = (image_crc == p_bootloader_settings->bank_0_crc);
169+
}
170+
171+
return success;
177172
}
178173

179174

lib/sdk11/components/libraries/bootloader_dfu/bootloader.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,10 @@
3333
uint32_t bootloader_init(void);
3434

3535
/**@brief Function for validating application region in flash.
36-
*
37-
* @param[in] app_addr Address to the region in flash where the application is stored.
38-
*
3936
* @retval true If Application region is valid.
4037
* @retval false If Application region is not valid.
4138
*/
42-
bool bootloader_app_is_valid(uint32_t app_addr);
39+
bool bootloader_app_is_valid(void);
4340

4441
/**@brief Function for starting the Device Firmware Update.
4542
*

lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ static inline bool is_sd_existed(void)
4141
#define NRF_UICR_BOOT_START_ADDRESS (NRF_UICR_BASE + 0x14) /**< Register where the bootloader start address is stored in the UICR register. */
4242
#define NRF_UICR_MBR_PARAMS_PAGE_ADDRESS (NRF_UICR_BASE + 0x18) /**< Register where the mbr params page is stored in the UICR register. (Only in use in nRF52 MBR).*/
4343

44-
// TODO more testing/checking
44+
// Application address is either after MBR or SD (if existed)
4545
#define CODE_REGION_1_START (is_sd_existed() ? SD_SIZE_GET(MBR_SIZE) : MBR_SIZE) /**< This field should correspond to the size of Code Region 0, (which is identical to Start of Code Region 1), found in UICR.CLEN0 register. This value is used for compile safety, as the linker will fail if application expands into bootloader. Runtime, the bootloader will use the value found in UICR.CLEN0. */
46+
4647
#define SOFTDEVICE_REGION_START MBR_SIZE /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
4748
#define CODE_PAGE_SIZE 0x1000 /**< Size of a flash codepage. Used for size of the reserved flash space in the bootloader region. Will be runtime checked against NRF_UICR->CODEPAGESIZE to ensure the region is correct. */
4849

0 commit comments

Comments
 (0)