2016-06-20 02:21 PM
Hello Forum,
I've been reading on the forums about custom bootloaders stored in flash and I was wondering if there was another possibility (possibly because I want to avoid messing with stack pointers, reset vectors etc.) In my main app, I have a bootloader function, that copies the new app stored in external flash to processor flash. This bootloader function contains a number of inline functions to read from external flash and copy to processor flash. Checking the .map file, this bootloader function looks to be all located in one place. My thought process is to copy this bootloader function into RAM at say 0x20000100 and then jump to that address as shown below void CopyLoaderToRam(void) { // uint32_t *Ram = (uint32_t *)RAM_ADDR; char *Ram = (char *)RAM_ADDR;///////////// Byte Alignment test typedef void (*pFunction)(void); pFunction RunCode; ptr_bootloader_fn = &bootloader; // Find the address of the bootloader function. // memcpy(Ram, (void *)ptr_bootloader_fn, LOADER_FLASH_SIZE); // Copy bootloader into ram char *boot_byte; boot_byte = (char *)&bootloader; int i; for (i=0; i<= 4*LOADER_FLASH_SIZE; i++) { Ram[i] = *(boot_byte+i); } RunCode = (pFunction)Ram[1]; // ResetHandler (PC in second vector) RunCode(); } Well the first issue is it doesnt seem to work as I get a hard fault.My fears are that I am overwriting some necessary data in Ram or some alignment issue. I'm not sure. However, is it even technically feasible in the first place and if not, why? If it is a non-starter, I would rather know at this stage. Device is a STM32F051. Kind Regards Bob2016-08-15 01:12 AM
Hi Clive,
As the bootloader runs from memory, I would have thought that there should be no requirement to maintain a separate area and that all flash could be overwritten. Am I wrong in this assumption?Bob2016-08-15 01:14 AM
Hi Clive,
As the bootloader runs from memory, I would have thought that there should be no requirement to maintain a separate area and that all flash could be overwritten. Am I wrong in this assumption?Bob2016-08-15 04:12 AM
Sure you can do that, the problem lies where the end-user removes the power mid-process, or it fails for some other reason, and you are left with a bricked device.
2016-08-15 07:03 AM
OK Clive,
Got you loud and clear.Bob