1

I'm currently in the process of writing an intermediate-memory bootloader for an ATMega.

I'd like to place a section of commonly used functions and data in a specific location in memory, such that:

  • limited size of the bootloader section is not overcome
  • library functions, drivers, etc, are not reproduced by the application section and thus wasting space

For illustrative purposes, a map of the desired memory layout is below: Memory layout

Following some help in this thread on avrfreaks, I'm to the point where I've been able to move all code (in my bootloader + library development environment - applications will be developed in separate projects) not tagged with __attribute__ ((section(".boot"))) to the shared library section successfully via means of a custom linker script.

It was suggested in the avrfreaks thread that I can link my applications by using avr-objcopy --strip-all --keep-symbol=fred --keep-symbol=greg ... boot.elf dummy.elf to create a symbol reference of what I have in my shared library, and then linking my applications against this memory layout with avr-gcc -o app.elf -Wl,--just-symbols=dummy.elf app1.o app2.o ....

The problem I face here is that I need to specify each symbol I want to keep in my dumy.elf. I can use the keep-symbols=<file> directive to specify a text file list of symbols to keep, but I still must generate this list.

I've noticed that there is a bunch of symbols that I don't want to include (stuff like C environment set-up code that is common in name, but different in functionality, for both the bootloader and application) that seems to start with the prefix '_' (but of course, there are some useful and large library functions with the same prefix, e.g. *printf and math routines). Perhaps there won't be conflicts if I link my application against the existing runtime code in the application/bootloader?

How can I generate a list of symbols for my library section that contains the code that I've written (maybe some sed magic and scanning header files)/excludes any symbols that may conflict in linking the application?

The project can be viewed in its current state at this github repository.

Edit: I want to make clear that I could tag everything I want to be in the shared library section with __attribute__ ((section(".library"))), but as I also want to share some rather large libc stuff (vsprintf, etc) between the bootloader and application, this becomes cumbersome very quickly. As such, I've elected to put everything not tagged as boot in the library memory region via a linker script.

Perhaps I just need some advice on my linker script, as I'm not super sure what I'm doing there.

4
  • You can think about creating a callback table in a fixed point of your memory map. offset0->callback0, offset1->callback1. Could be the top of your shared library code. Commented Jul 28, 2015 at 15:17
  • I know this is the common approach for a few functions, but I'm not really sure why. It has overhead both in flash space taken up from the table and in the application indirectly calling a function as well totally erasing compile-time type safety too. It might be useful in situations where the bootloader changes but the jump table stays the same so user applications don't have to be recompiled/linked, however. This isn't the case for my application. Commented Jul 28, 2015 at 21:31
  • I probably misunderstood your question. Is that shared library static (no changes in future) The real problem is to keep all symbols of shared library? Could you consider to link your static lib with only functions that you need in both project (application and bootloader) at a specific section/address into flash? Commented Jul 29, 2015 at 6:40
  • I can't quite tell if you've fully grasped my problem. I'd suggest you read the forum thread I linked to in the question for a bit more context. The bootloader will user-interactive with a menu displayed on an LCD and user input from buttons. The boot section (necessary as flash rewrite functions can only be run from here) can't fit these drivers in its limited space, and the application uses the same drivers (and other library functions), so they're placed in a separate memory section. I could tag everything with 'section' attributes, then I'd have to pollute libc - hence linker script. Commented Jul 29, 2015 at 12:32

1 Answer 1

0

Consider using -R <file> as linker option (gcc -Wl,-R -Wl,<file>).

This will generate references to (global) symbols in <file> just as if they were linked normally, but not include the referenced code.

Sign up to request clarification or add additional context in comments.

2 Comments

isn't the -R linker option just short for avr-gcc -o app.elf -Wl,--just-symbols=dummy.elf app1.o app2.o ... like what was already suggested? I'm looking for how to best create <file> so that it doesn't contain symbols that will conflict with the application code.
it is. Did you look into the --wildcard option of objcopy? Might allow you to hide symbols - at least those that aren't needed for relocation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.