Is it possible to remote update or patch only certain piece of code to an embedded device (microcontroller)?
I am writing a bare metal C program on a microcontroller. Lets say I have main program which comprises of function A()
, B()
, C()
and D()
each in their own .c file.
I would like to do a remote update (patching) of only B()
which has its own custom section in the main program so that the address is fixed and known.
The thing that puzzles me is how do I produce an updated executable of B()
? Given that it relies on standard C library or other global variables from the main program. I need to resolve all the symbols from the main program.
Would appreciate any suggestions or reference to other thread if this question has been asked before (I tried to search but couldn't find any)
Solutions:
- from Russ Schultz: Compile the new
B()
, and link it with the symbol file previously generated from the main program using gcc--just-symbols
option. The resultant elf will contain justB()
that assumes all these other symbols are there. (I haven't tried it but this is the concept that I was looking for) - Compile the whole program with the new
B()
, and manually take only theB()
part binary from the main program (because its section address and size are known). SendB()
binary to the device for remote update (not efficient as it involves many manual works).