问题
I guess this is a continuation of this question. I've compiled my intermediate bootloader library and have verified it working, now it's time to write some application code against it.
I'm able to generate a symbol list from the bootloader's generated .hex
file using $(OBJCOPY) --wildcard --strip-symbol=main --strip-symbol="_*" $(TARGET).elf $(TARGET).syms
, this gives me bootloader.syms
.
I've written a test application that uses a few of the functions in the library section of memory, and I compile it as follows:
I pass GCC the location of all the header files used in the bootloader/library as well as the symbol file generated above. I've tested that GCC picks up the header files as intended.
Makefile invocation:
Making: obj/main.o
avr-gcc -Os -std=gnu99 -Wall -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -static -DF_CPU=8000000UL -DBAUD= -iquote../firmware/src/ -I. -I../firmware/src/ -MP -MD -mmcu=atmega16 -c -o obj/main.o src/main.c;
avr-gcc -Wl,-Map,app.map -Wl,--just-symbols=../firmware/bootloader.syms -T ld_script_app.x -mmcu=atmega16 obj/main.o -o app.elf
obj/main.o: In function `main':
main.c:(.text.startup.main+0x14): undefined reference to `lcd_init'
main.c:(.text.startup.main+0x8e): undefined reference to `lcd_fill'
main.c:(.text.startup.main+0x142): undefined reference to `gfx_draw_line'
collect2: error: ld returned 1 exit status
make: *** [app.elf] Error 1
I'm not sure what's causing the undefined references though. I was under the impression that they would be referenced through the symbols file.
回答1:
I recently got a two-part firmware build working. See this question and my self-answer for how I did this: Building a two-part firmware image using GCC toolchain. Your questions on here were helpful in getting onto the right track - thanks! - but there were quite a few steps needed to get it right.
My guess is that the undefined references you're getting are for functions that are in the bootloader source code, but not actually used in the bootloader. So the linker is leaving them out of the finished bootloader image. When you try to link your app, they aren't available in either main.o
or bootloader.syms
, so they show up as undefined references.
If so, there are a few ways to deal with this:
Try to force the linker to retain these symbols in the bootloader image even though they are not used. I think there are a few ways to do this.
Move these functions to separate source files and build them into the app.
Provide the object files for the bootloader when linking the app. Ordering on the linker command line matters, so if these are provided last, they should be used only to supply any functions that have not already been defined by the previous inputs.
来源:https://stackoverflow.com/questions/33207402/how-to-link-against-just-symbols-correctly