We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I write a bootloader to update the flash,but when the bootloader update the ?c?LIB_CODE,the MCU(C8051F005) always jump to another incorrect place. So I put the ?c?LIB_CODE into boot-area when linking. (BTW,my bootloader and app are compiled together.)
But I am afraid the ?c?LIB_CODE will increase when I use some new function in the newer applcation.then the app will be wrong if I do not update the ?c?LIB_CODE.
Any one has good ideas?
Thanks
I am tring to make two separate projects.
and then I have to add some same codes into the both projects.It maybe doubled the flash space
then,If I leave the subroutines ,such as flash_write(), in the bootloader,which LIB_CODE will be accessed when they require the function in LIB_CODE ?You know ,there are two LIB_CODE now.
Don't duplicate code. Either make the functions you want the boot loader to export to use fixed addresses, or create a single entry point that takes a command to select which exported function to access.
If you find a bug in the boot loader, you want to be able to fix this bug without having to rebuild any applications. Hence, the boot loader should only need to know a single start address to jump into the application (and optionally a way to evaluate a checksum on the applicatin to decide if a valid and complete application exists), and the application should always know the fixed address of a function or pointer table or similar into the boot loader, or should be able to scan for a magic signature to a descriptor table with required access information.
Thank Per Which kind of checksum do you suggest?
Will XORing or ADDing (like HEX file)all bytes of the 32/64K effective for check the possible error?
Or I have to use a CRC16 in bootloader to check my APP?
Now I am using the HEX type to receive the flash file.
Since I have check the Flash both before and after writing each line of the HEX data,and make sure there is no error during the updating, shall I still need to check the app before each time bootloader jumpping?
"I have check the Flash both before and after writing each line ... shall I still need to check the app before each time bootloader jumpping?"
Yes: otherwise you wouldn't detect if you'd missed a complete line!
Or, possibly, if you'd programmed the line correctly, but at the wrong address?
Avoid the simplest checksum method (just summing all bytes with overflow) since it fails quite a number of errors.
High-end methods often make use of crc16, crc32, md5 or similar, but they take quite a lot of code and processor time.
A very easy to implement checksum that is still very reliable with a minimum of processor requirements is adler16 or adler32. The Adler algorithm not just computes a sum, but also a sum of sums, which means that swapped bytes are detected. It is also affected by the length of the summed area, so there are no constant memory value that will represent a "null operation" when evaluating the checksum.
Here is a link for Adler32: en.wikipedia.org/.../Adler-32
It's quite easy to deduce a smaller Adler sum, if you don't want to use 32-bit integers. I think USB makes use of Adler-4 or Adler-8...