【原創出品§轉載請注明出處】
出處:http://www.cnblogs.com/libra13179/p/5787084.html
我們打開app_valid_setting_apply.hex如下
:020000040003F7
:10FC00000100000000000000FE000000FFFFFFFFF9
:00000001FF
分析如下
對數據幀結構
|
補充
數據類型
'00' Data Rrecord:用來記錄數據,HEX文件的大部分記錄都是數據記錄
'01' End of File Record:用來標識文件結束,放在文件的最后,標識HEX文件的結尾
'02' Extended Segment Address Record:用來標識擴展段地址的記錄
'03' Start Segment Address Record:開始段地址記錄
'04' Extended Linear Address Record:用來標識擴展線性地址的記錄
'05' Start Linear Address Record:開始線性地址記錄
好了現在正式開始
:020000040003F7 :10FC00000100000000000000FE000000FFFFFFFFF9 :00000001FF :020000040008F2 :10 0004 00 FF00A0E314209FE5001092E5011092E5 A3 :00000001FF 對上面的HEX文件進行分析: 第1條記錄的長度為02,LOAD OFFSET為0000,RECTYPE為04,說明該記錄為擴展段地址記錄。數據為0003,校驗和為F7。
從這個記錄的長度和數據,我們可以計算出一個基地址,這個地址為(0x0003 << 16)。后面的數據記錄都以這個地址為基地址。 第2條記錄的長度為10(16),LOAD OFFSET為FC00,RECTYPE為00,說明該記錄為數據記錄。數據為0100000000000000FE000000FFFFFFFF,共16個BYTE。這個記錄的校驗和為F9。
此時的基地址為0X30000,加上OFFSET,這個記錄里的16BYTE的數據的起始地址就是0x30000 + 0xFC00 = 0x3FC00. 第3條記錄的長度為00,LOAD OFFSET為0000,TYPE= 01,校驗和為FF。說明這個是一個END OF FILE RECORD,標識文件的結尾。
問題來了這個0x3FC00是什么鬼??
在dfu_types.H文件中
#ifdef NRF51 #ifdef SIGNING #define BOOTLOADER_REGION_START 0x00039C00 /**< 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. */ #define BOOTLOADER_SETTINGS_ADDRESS 0x0003D800 /**< The field specifies the page location of the bootloader settings address. */ #else #define BOOTLOADER_REGION_START 0x0003C000 /**< 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. */ #define BOOTLOADER_SETTINGS_ADDRESS 0x0003FC00 /**< The field specifies the page location of the bootloader settings address. */ #endif #define CODE_PAGE_SIZE 0x0400 /**< 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. */ #elif NRF52 #define BOOTLOADER_REGION_START 0x0007B000 /**< 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. */ #define BOOTLOADER_SETTINGS_ADDRESS 0x0007F000 /**< The field specifies the page location of the bootloader settings address. */ #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. */ #else #error No target defined #endif
我們繼續跟蹤
#if defined ( __CC_ARM ) 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. */ uint32_t m_uicr_bootloader_start_address __attribute__((at(NRF_UICR_BOOT_START_ADDRESS))) = BOOTLOADER_REGION_START; /**< This variable ensures that the linker script will write the bootloader start address to the UICR register. This value will be written in the HEX file and thus written to UICR when the bootloader is flashed into the chip. */ #elif defined ( __GNUC__ ) __attribute__ ((section(".bootloaderSettings"))) uint8_t m_boot_settings[CODE_PAGE_SIZE]; /**< This variable reserves a codepage for bootloader specific settings, to ensure the compiler doesn't locate any code or variables at his location. */ __attribute__ ((section(".uicrBootStartAddress"))) volatile uint32_t m_uicr_bootloader_start_address = BOOTLOADER_REGION_START; /**< This variable ensures that the linker script will write the bootloader start address to the UICR register. This value will be written in the HEX file and thus written to UICR when the bootloader is flashed into the chip. */ #elif defined ( __ICCARM__ ) __no_init uint8_t m_boot_settings[CODE_PAGE_SIZE] @ 0x0003FC00; /**< This variable reserves a codepage for bootloader specific settings, to ensure the compiler doesn't locate any code or variables at his location. */ __root const uint32_t m_uicr_bootloader_start_address @ 0x10001014 = BOOTLOADER_REGION_START; /**< This variable ensures that the linker script will write the bootloader start address to the UICR register. This value will be written in the HEX file and thus written to UICR when the bootloader is flashed into the chip. */ #endif
我們看到這個
void bootloader_util_settings_get(const bootloader_settings_t ** pp_bootloader_settings) { // Read only pointer to bootloader settings in flash. bootloader_settings_t const * const p_bootloader_settings = (bootloader_settings_t *)&m_boot_settings[0]; *pp_bootloader_settings = p_bootloader_settings; }
看到這個我們將0100000000000000FE000000FFFFFFFF的具體含義了
/**@brief Structure holding bootloader settings for application and bank data. */ typedef struct { bootloader_bank_code_t bank_0; /**< Variable to store if bank 0 contains a valid application. */ uint16_t bank_0_crc; /**< If bank is valid, this field will contain a valid CRC of the total image. */ bootloader_bank_code_t bank_1; /**< Variable to store if bank 1 has been erased/prepared for new image. Bank 1 is only used in Banked Update scenario. */ uint32_t bank_0_size; /**< Size of active image in bank0 if present, otherwise 0. */ uint32_t sd_image_size; /**< Size of SoftDevice image in bank0 if bank_0 code is BANK_VALID_SD. */ uint32_t bl_image_size; /**< Size of Bootloader image in bank0 if bank_0 code is BANK_VALID_SD. */ uint32_t app_image_size; /**< Size of Application image in bank0 if bank_0 code is BANK_VALID_SD. */ uint32_t sd_image_start; /**< Location in flash where SoftDevice image is stored for SoftDevice update. */ } bootloader_settings_t;