Question

I'm compiling some firmware patches. These are normally written in C then patched into a firmware image to change the behavior of a hardware device. The trick is that I will replace a function call in the original firmware to dispatch to my patch, do my trickery then call the original function and finally return.

Here is a simple example:

__attribute__ ((section (".patches")))

void clean_memory() __attribute__ ((section (".patches")));

void clean_memory() {
  int *i;
  for (i=(int *)0x80000;i<(int *)0x84000;i++)
    *(i)=0;
  asm("jsr      0x12345\n\t"); // call the original function
}

I'm compiling it with the following:

m68k-rtems-gcc -mcpu32 -Wl,--section-start=.patches=0x31000 -O2 -c patches.c
m68k-rtems-ld -nostdlib --oformat=binary -M patches.o -o patches.bin

I would really like to automate this process rather than hand-patching the file every time I make a modification to the patch.

How can I get a list of the offsets and lengths where each function in the patches.bin file exist? This is important when I patch the original function call since the offsets will change as the size of every function in the patch changes

Was it helpful?

Solution

This information should be contained in the mapfile which you are already generating with the -M option. This sends it to a default mapfile. You can specify your own with something like -Map patches.map.

Generating a cross reference table in the mapfile with -cref may also contain some useful information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top