两个project在一个solution下边,靠makefile与AVR-GCC,并分配2个project的地址,一个是boot loader 一个是app
如下:
## Assembly specific flags
ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS += -Wl,-Map=C103_BOOTLOADER.map
LDFLAGS += -Wl,-section-start=.bootloader=0xFF00 //section .bootloader start from 0xff00
LDFLAGS += -Ttext=0xE000 //bootloader compile from 0xe000
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
see .map 文件发现
Address of section .text set to 0xe000
0x00000000 __TEXT_REGION_ORIGIN__ = DEFINED (__TEXT_REGION_ORIGIN__)?__TEXT_REGION_ORIGIN__:0x0
[0x00800100] __DATA_REGION_ORIGIN__ = DEFINED (__DATA_REGION_ORIGIN__)?__DATA_REGION_ORIGIN__:0x800060
[0x00010000] __TEXT_REGION_LENGTH__ = DEFINED (__TEXT_REGION_LENGTH__)?__TEXT_REGION_LENGTH__:0x20000
[0x00001000] __DATA_REGION_LENGTH__ = DEFINED (__DATA_REGION_LENGTH__)?__DATA_REGION_LENGTH__:0xffa0
[0x00000800] __EEPROM_REGION_LENGTH__ = DEFINED (__EEPROM_REGION_LENGTH__)?__EEPROM_REGION_LENGTH__:0x10000
[0x00000003] __FUSE_REGION_LENGTH__ = DEFINED (__FUSE_REGION_LENGTH__)?__FUSE_REGION_LENGTH__:0x400
0x00000400 __LOCK_REGION_LENGTH__ = DEFINED (__LOCK_REGION_LENGTH__)?__LOCK_REGION_LENGTH__:0x400
0x00000400 __SIGNATURE_REGION_LENGTH__ = DEFINED (__SIGNATURE_REGION_LENGTH__)?__SIGNATURE_REGION_LENGTH__:0x400
0x00000400 __USER_SIGNATURE_REGION_LENGTH__ = DEFINED (__USER_SIGNATURE_REGION_LENGTH__)?__USER_SIGNATURE_REGION_LENGTH__:0x400
整个boot loader的地址都是从0xe000开始的
.text 0x0000e000 0x1cfe
*(.vectors)
.vectors 0x0000e000 0x7c c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr5/crtatmega644p.o
0x0000e000 __vector_default
0x0000e000 __vectors
*(.vectors)
*(.progmem.gcc*)
.progmem.gcc_sw_table.__vector_20
0x0000e07c 0x10 rdm.o
0x0000e08c . = ALIGN (0x2)
0x0000e08c __trampolines_start = .
*(.trampolines)
.trampolines 0x0000e08c 0x0 linker stubs
*(.trampolines*)
0x0000e08c __trampolines_end = .
*libprintf_flt.a:*(.progmem.data)
*libc.a:*(.progmem.data)
*(.progmem*)
.progmem.data.device_model_string
0x0000e08c 0x12 rdm.o
0x0000e08c device_model_string
.progmem.data.manufacturer_ID_string
0x0000e09e 0xa rdm.o
0x0000e09e manufacturer_ID_string
.progmem.data.supported_parameters_response_subdevice
0x0000e0a8 0x8 rdm.o
0x0000e0a8 supported_parameters_response_subdevice
.progmem.data.supported_parameters_response_root
0x0000e0b0 0xe rdm.o
0x0000e0b0 supported_parameters_response_root
.progmem.data.device_info_response_subdevice
0x0000e0be 0x13 rdm.o
0x0000e0be device_info_response_subdevice
.progmem.data.device_info_response_root
0x0000e0d1 0x13 rdm.o
0x0000e0d1 device_info_response_root
.progmem.data.kTable
0x0000e0e4 0x20 aes.o
0x0000e0e4 kTable
.progmem.data.init_chainCipherBlock
0x0000e104 0x10 bootloader.o
0x0000e114 . = ALIGN (0x2)
看app的bootloader 并没有说开始地址从哪里开始的,那怎么知道app从0000开始的呢?app的bootloader只说再0xE000有个.bootloader的section,把位置留下来或者会把这个.bootloader的地址编译进去。这里没说编译开始的地址。
## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS += -Wl,-Map=C103.map
LDFLAGS += -Wl,-section-start=.bootloader=0xE000
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
是因为再WINAVR的WinAVR-20100110\avr\lib\ldscripts\avr6.x文件有描述,默认.TEXT从000开始。
/* Default linker script, for normal executables */
OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
OUTPUT_ARCH(avr:106)
MEMORY
{
text (rx) : ORIGIN = 0, LENGTH = 1024K
data (rw!x) : ORIGIN = 0x802000, LENGTH = 0xffa0
eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K
lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K
signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K
}
SECTIONS
{
/* Read-only sections, merged into text segment: */
.hash : { *(.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rel.init : { *(.rel.init) }
.rela.init : { *(.rela.init) }
.rel.text :
到此弄清楚来这个win-avr-gcc是怎么通过makefile链接memory的
本文所涉及到的文件地址 : https://download.csdn.net/download/hurg101/11958643