Cannot find answers to these questions in kboot reference manual or anywhere else.
1.) When transferring data via I2C and using the WriteMemory tagged command packet, what is the max number of data packets that can follow the WriteMemory command packet?2.) What is the max number of data bytes that can be contained in a single data packet that follows the WriteMemory command packet?
3.) Does the data from the data packet get written immediately to flash (assume that a valid flash start address was provided in the command packet) before the bootloader sends the ack response packet back to the host?
4.) How does the kboot bootloader respond to any packet it receives where it computers the CRC16 and the result doesn't match the provided CRC16 in the packet? The reference manual doesn't appear to detail this case.
5.) Does the bootloader have some way of knowing a valid program has been put into flash, or does it just blindly jump to the start address that was set within the bootloader by the host?
6) How do we manage the whole image integrity, packetized CRC only? and are retries built into the ROM loader?
Hope it helps.
Have a great day!
JeremyI think you can find all the answers to your questions from Figure 5-6 Protocol Sequence for WriteMemory Command in kboot RM v2.0.0.
Let me answer your questions one by one:
1). When you issue write-memory command, You must first specify startAddress and dataLength in the WriteMemory command packet, so device should know the total data bytes to write before receiving any data packet, then device will count the received data bytes while receiving data packet, when the amount of received data is matched with the total num, then device will stop receiving data. so the max num of data packet depends on the actual bytes in each data packet.
For example: if you want to flash 100 byte by WriteMemory command, and you put 10 byte data in every data packet, then you need to provide 10 data packets. but if you put 25 bytes data in every data packet, then you just need to provide 4 data packets.
2). The max num of data bytes in single data packet is 32, because device bootloader only offer a 32 byte memory space to buffer received data. this restriction is just for ROM-resident bootloader, if you are playing with flash-resident bootloader, then you can customize the max num of data bytes.
3). When your specified memory is SRAM, the answer is yes. When the specified memory is FLASH, the answer is not necessarily, because there are two methods for bootloader to program flash memory, Kinetis FTFx memory module provides two basic Program command (ProgramWord(4 or 8 bytes) or ProgramSection (1K bytes)), bootloader implements both methods in source code, but each time we can only use one method, the default method may be different in different device, you need to check BL_FEATURE_ENABLE_FLASH_PROGRAM_SECTION in bootloader_config.h file.
if this macro is set to 0, then bootloader will progam data immediately before sending the ACK to host.
If this macro is set to 1, then bootloader will buffer received data to 1K bytes, at this time, the ACK sending from bootloader just means that the data has been received properly.
4). When bootloader gets a packet from host, if the CRC16 verification is passed, then bootloader will just give a ACK packet to host, but if it fails, then bootloader will give a generic responce packet to host which indicates error code.
5) / 6). See chapter 2.7 Application integrity check in kboot RM v2.0.0.
Best Regards,
Jay