Hi Roy,
1. For MKW21D256, the first 16 bytes, represent the bitmap for the internal MCU Flash. Some of the remaining bytes are used as an erase bitmap for the FlexNVM region (the emulated EEPOPM).
2. An example of the sector bitmap is: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE00000000000000000000000000000000
This will erase almost all the MCU Flash. The Bootloader itself will not be erased/updated, but the new image must contain the Bootloader code, and it will be skipped at upgrade.
Also, the last Flash sector will remain unchanged (because of the 0xFE value) to not alter the gHardwareParameters structure.
The last 16 zeros means that the FlexNVM will not be erased!
If you are using NVM instead of FlexNvm, and you need to preserve the information stored, then you must modify the sector bitmap, to skip the NVM sectors also.
a) The original image is stored right after the bootloader region. The written image cannot and must not cross over the INTERNAL_STORAGE boundary. The IAR will issue a section placement error if this happens.
The new image will be stored in reserved FLASH region and it will not overwrite the existing application code!
b) See the example from above.
3. In the OTAP demo provided, the gHardwareParameters structure is explicitly placed in the FREESCALE_PROD_DATA section:
#pragma location = "FREESCALE_PROD_DATA"
HardwareParameters_t const gHardwareParameters =
…
.internalStorage_StartAddr = gDefaultInternalStorage_StartAddress_c,
Then gDefaultInternalStorage_StartAddress_c is defined as:
#define gDefaultInternalStorage_StartAddress_c gEepromParams_StartOffset_c
And if gEepromType_d == gEepromDevice_InternalFlash_c:
#define gEepromParams_StartOffset_c ((uint32_t)INT_STORAGE_END)
The FSL_PROD_DATA_END_ADDRESS and FSL_PROD_DATA_START_ADDRESS symbols are not visible in C source code because they are not defined as “exported symbols”. If you need to use those symbols, you must add the “exported” keyword to their definition.
The bootloader knows the offset of the internalStorage_StartAddr field, and it uses its value to decide from where to read the new image.
4. You must verify that the gHardwareParameters structure is placed at the beginning of the last Flash sector:
gHardwareParameters 0x0003f800 0x50 Data Gb NV_Data.o [1]
then you must check that the value of the internalStorage_StartAddr is INT_STORAGE_END.
5. Yes, you can debug the bootloader using the provided project: Freescale\Codebases\BeeKit Kinetis MAC Codebase 4.0.1\SSM\FreeScale\V01.00\Generic\Bootloader_OTAP\
You must attach to the running target, before the MCU reset which starts the upgrade process!