My firmware support upgrade by means of a bootloader (USB bootloader). I do not wan't to upgrade all the firmware, but only a specific function in the firmware.
My problem with updating all the firmware at once is that if a user removes power from the target while upating, it won't be possible to recover the target unless some form of backup is on the target board or physical re-porgramming of the target with a programmer.
I do not have the option of a backup.
So to be safe, I only want to update the specific function, and after all that is the only thing that will be changed in the firmware.
The function is compiled at an absolute address and does not use any interrupts.
I am faced with several problems.
1.) Is it possible to compile the function by itself, since the function does use other functions from the project? Because if I want to update the function only I will need a HEX file containing the data of the function only.If possible, how do I do this?
2.) What happens if I size of the function changes, will the rest of the project be able to detect the end address of the function. What affect will this have on the stack, PC etc.?
And then I come back to what I asked. If I want to change or improve a function, how do I compile it so that I obtain a HEX file containing the data of the function only. This allows me to upload only the code of the function and not all the firmware.
you can compile the function that won't be a problem, but you can't link it without the rest.
Here is what I have done in the past: - compile and link the app - convert it to a binary (HexToBin) - ectract your code starting at binoffset 0x3000
The above will only work if the update funktion is at the end of your code. You will need to write some tools to extract the function. Of course your firmware needs to have some checks if the update is successfull.
But keep attention: var overlaying can very critical in such cases. you can not use more vars in your function after the product is delivered unless you have a special mempool reserved for that in your firmware.
Thomas
Hi Thomas
Good to know there is someone who have tried this before.
Yes, I thought it would have to be something like this, just maybe there was a way to skip the writing of a tool to extract the required data. But as you say, "but you can't link it without the rest."
I will make sure that my variables is in place for the overlay process with every function.
One last question:
The app knows the start address of the function since I compile it at a fixed address (0x3000). So the calling address of this function is known. But what about the return address, will there be any problems with the overlay process when the function changes in size??
But what about the return address, will there be any problems with the overlay process when the function changes in size??
no that won't be any problem since the return address is poped from the stack. One last thing I forgot: all used lib functions have to be already in the code. You will need a snapshot of your shiped code and have to make sure that no new lib functions will be included. This will be the hardest task I think.
My approach for the last projects was a bit different: I build two different apps update code at 0x0000 main firmware at 0x2000. With some tests you can ensure that update code is always startable even after a broken download. That will be much more stable if update and firmware resist in different flashpages.
you can not use more vars in your function after the product is delivered unless you have a special mempool reserved for that in your firmware.
How can I reserve a mempool/memory space for future variables?
MC
How can I reserve a mempool/memory space for future variables? that depends on the memory you have in reserve One way would to declare a array or struct globally in your app with a fixed address. This memory space can then be used in your function.