Need code to check for succesfull download with bootloader...

Started by diebobo, Apr 24, 2024, 03:49 PM

Previous topic - Next topic

diebobo

Hi,

I am in need for a piece of code that enables me to see if a software download has been succesfull or not.

Longer explanation :

I've got a PIC24 with a bootloader, which works fine. But sometimes the download or flashing via the bootloader fails, and that is something i want to detect within the software i want to run on that PIC..  If it detects a not good software then it just needs to jump to the bootloader position, otherwise continue the software.

My thoughts so far was to put a pre determined number in the programcode at very last spot before the bootloader ( sits at last block ), so if that number is there i know the software is correct..

Any ideas / code ?

JohnB

Traditionally one would add a CRC check on the loaded code which you would calculate as the program is loaded.  The last item in the loaded program would be the expected CRC value which should tally with the CRC calculated on the fly while loading.  Just checking that certain value has been placed at the end of the code doesn't mean all the code is correctly loaded just that it has reached the end of the load.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
JohnB

trastikata

Quote from: diebobo on Apr 24, 2024, 03:49 PMMy thoughts so far was to put a pre determined number in the programcode at very last spot before the bootloader ( sits at last block ), so if that number is there i know the software is correct..

Any ideas / code ?

It is done differently.

Before the bootloader starts self-flashing it verifies and writes marker FLAS_NOT_COMPLETE in the EEPROM or in a designated flash area that new flash-write was initiated.

When your bootloader start writes in FLASH, it writes in blocks of say for example 64 bytes, correct?

Then write those bytes, read them back fro flash and compare that with what was supposed to be written in the block. If the block write successful, the bootloader sends back OK message thereby requesting the next block.

If an error was detected, the  bootloader sends NotOk and either reboots the PIC thus entering into boot mode or requests that write block information again and then you act accordingly.

At the end of flash update operation, if everything went fine, the bootloader updates that marker to FLASH_COMPLETE.

Next time when the bootloader or the program start, they first check the flag and if they see the FLASH_NOT_COMPLETE flag, the device acts accordingly.