This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Self-contained C module or PIC

I need to write a self-contained module in C (is this even possible?) which is a part of a bigger app. This module should be loaded from some mass memory (most probably microSD card) to RAM and executed from there.
Actually, this code doesn't need to be position independent, because I can guarantee that the execution address in RAM is always the same. There is only one simple access function (kind of a data translator), it does not use any static variables, and can be (and, for now, it is) fully reentrant.

Of course, there is a dedicated load region for this module defined in the scatter file.
But:
- how to force the compiler to not use standard library function calls to the main app (as the adresses of library functions could change when we release new versions of the firmware)
or
- how to force the compiler to embed copies of library functions in the same region as the installable module, independent of what is in the main app,
or
- make the module ROPI, but then, how to call my access function from the main code? I thought, the only thing I need is a single const pointer to this function, placed in the first four bytes of the dedicated load region (still at an absolute address, remember?). I event created a section inside this region for this pointer only, declared it inside the my module and statically intialized it with the address of the access function. But the compiler complains about it, warning me like 'static initialization can cause link failure --ropi'.

After many hours of learning about this stuff I think, making the module ROPI does not change a thing, because there can still be calls to absolute addresses in the main app. Am I right?

Please help... I spent for now a few days looking for solutions, but found nothing really helpful ;( There are for real many questions about ropi or installable modules but still no precise answers...

Parents
  • Build it as a separate, freestanding project, and create your interface in the startup.s (or equivalent) file. This way it won't have any dependency on your main code.

    Define the IROM section as the area of RAM you expect to load it, and another RAM area for IRAM where it can put it's statics, variables, stack, etc. Define the sizes you carve out to match your needs.

    Say IROM 0x20000000,0x1000, IRAM 0x20001000,0x1000

    Other than that you could also dynamically memory, and use an executable/object format, and write a loader.

    Are you familiar with the concepts/implementation of DLLs?

Reply
  • Build it as a separate, freestanding project, and create your interface in the startup.s (or equivalent) file. This way it won't have any dependency on your main code.

    Define the IROM section as the area of RAM you expect to load it, and another RAM area for IRAM where it can put it's statics, variables, stack, etc. Define the sizes you carve out to match your needs.

    Say IROM 0x20000000,0x1000, IRAM 0x20001000,0x1000

    Other than that you could also dynamically memory, and use an executable/object format, and write a loader.

    Are you familiar with the concepts/implementation of DLLs?

Children