I have wrote a SD bootloader. this bootloader seems to work properly but a single strange bug has to be identified and fixed
Supose I have two programs PA and PB. I amd doing the following stages:
1. program the MCU with the Bootloader application. and shut down the MCU power.
2. Copy the PA program ( its hex file of course) to the SD and insert it to the card slot.
3. Power up the board. now the bootloader starts updating the Flash with the PA program.
When finished it lunches the program and the program deletes the hex file from the SD.
4. I power down and then power up the board. since there is no more hex file on the SD card
The bootloader ( that is invoked on power up) finds the already loaded program from stage3 and
launches it.
5. I have powered down the board and added again the hex of PA to the SD card. on power up, as expected
the bootloader (since found an hex file on SD) started to load the PA and at the end he launched it and deleted the
hex file from the SD
6. Until now everything behaved correctly. Now I have power down the board and inserted to the SD card the hex file of the
PB program. On power up the bootloader started to load the PB program. when loading has finished it went to the launching
stage of the program but failed to launch it !!
conclusions:
- The Bootloader application can load and launch application from SD card.
- After loading and launching application he can do it again ( ssee staage #3)
- After loading a different application it fails to launch it ( although lokkks like succeeded to load it to the flash)
If some one would like to find the problem and fix it I will be happy to deliver him the project and assist him. the code has many comments and is not complicated.
I would like to add a 'trick' that I have used to implement the bootloader:
1. since the bootloader application and the PA and PB applications are compiled with MikroC, all of them will include the BootVT
function that is automatically inserted y MikroE to a fixed address of 0xBFC00380. Now since at this address is already the BootVT
of the bootloader code that has been loaded to the MCU via MikroProg, I have decided in my bootloader to neglect this part of the
hex file of the application that I am loading. thus when the bootloader hits this address in the hex file he trying to load it just skips
it. The idea was that since this BootVT is used as exception handler for the bootstrap stage of the MCU I should keep the
one that has been loaded by the Mikroprog since the bootloader is the application that is running upon power up.
by the way, the address of BootVT cannot be changed. it is fixed and #pragma funcorg will not move it.
there is difference btween the bootVT of the PA to the one of PB:
-----------PA BootVT-------------------
Code: Select all
____BootVT:
0xBFC00380 0x3C1E9D04 LUI R30, 40196
0xBFC00384 0x37DE0534 ORI R30, R30, 1332
0xBFC00388 0x03C00008 JR R30
0xBFC0038C 0x70000000 NOP
; end of ____BootVT
Code: Select all
____BootVT:
0xBFC00380 0x3C1E9D04 LUI R30, 40196
0xBFC00384 0x37DE0798 ORI R30, R30, 1944
0xBFC00388 0x03C00008 JR R30
0xBFC0038C 0x70000000 NOP
; end of ____BootVT
My asumption was that this difference does not matter since it reflects different positions of the __BootGenExcept function.
As I have wrote, I am willing to deliver the code for anyone that will try to find ad solved the PA and PB problem.
an one that is interested, please reply here in the forum. I do promise to explain every line in the code.
Regards,
M. Hooper