0
votes

The problem definition: There is a need to have two parts of the code in an AVR microcontroller, a fixed one that is always there and does not change (often), and a transient one, that is (not so) often to be replaced or appended. The challenge is to give the ability for the transient code to call functions and access global variables of the fixed one -- and vice versa.

It is quite obvious that there should be special methods for the fixed code to access transient one -- like having calculated function pointers in RAM and using only them to call transient code procedures.

For the calling in backwards direction, I was thinking about linking transient code against existing .elf file of the fixed code.

I'm using avr-gcc toolchain (as in ubuntu 20.20), gcc version 5.4.0

What's I've already tried:

  1. adding '-shared' as a link argument when building fixed code -- appears to be unsupported for AVR (linker reports an error).

  2. adding instead '-Wl,--export-dynamic' as a link argument -- it seems to be ignored, no .dynsym section appears in the elf.

There is still a .symtab section in the fixed code elf -- could that be somehow used to link against it?

Note: my division of 'fixed' and 'transient' code has nothing to do with boot-area of some AVR microcontroller, boot is just something I do not care here about.

Note2: The question is much alike this one, but gives clear explanation for the need.

1
Optiboot bootloader offers a function to be called by the application. see optiboot.h: github.com/Optiboot/optiboot/blob/master/optiboot/examples/… and optiboot source codeJuraj
Don't try to use dynamic libraries, that's a fancy thing for actual PCs that have operating systems. You should be able to do what you want on the AVR but there are tons of little problems to solve, and solving those problems will probably require you to get familiar with AVR assembly, your C compiler, and your linker. You need methods to figure out what memory address contains the function you want to call, and you must make sure that the functions in your program do not try to use the same pieces of RAM for conflicting purposes.David Grayson

1 Answers

0
votes

You have to forget all big computer knowledge. 8 bits AVRs are timy microcontrollers. Code has to be linked statically. There is no other way.