Hi @CK3
I think you're asking multiple questions here and it's a bit confusing.
If I were to break it out you have a bootloader that takes up some amount of space and you want to load application after it (which needs the Flash after it to be erased before loading in the application). So you need:
- Bootloader size
- Using the GCC created code by MCUXpresso for the FRDM-K22F, I take the sum of the words at 0x168 and 0x170
- This is SDK version dependent and you may find this information at slightly different locations (for the MK22FN1M0a the values are at 0x188 and 0x190)
- Device Flash Size
- I use the FLASH_GetProperty API with the kFLASH_PropertyPflash0TotalSize or kFLASH_PropertypflashTotalSize depending on the API
- This is one of the reasons why I whine about the different versions of the SDK for different devices
- Application Start Address
- This can be a bit tricky as you should NEVER place the application at the address following the bootloader size (1) but you need to place it at the sector following. See below.
To calculate the Application Start Address, use the statement:
applicationStartAddress = (bootloaderSize * (~(FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE - 1))) + FSL_FEATURE_FLASH_PFLASH_SECTOR_SIZE;
This will place your application at the start of the sector following the end of the bootloader and is the first sector that you can erase without affecting the bootloader code.
The "applicationStartAddress" is also the first sector you start erasing to the end of the devices Flash before the bootloader loads the application.
Good luck!
myke