本帖最后由 wangpengcheng 于 2014-5-18 11:10 编辑
MQX中有一个分散加载的变量:USEDFLASH_END,它的意义在于可以算出来代码量有多大,让用户可以将剩余的Flash作为数据Flash区域,不用去人工计算数据Flash的起始地址,其在分散加载文件中的定义是:
- #define MY_ALIGN(address, alignment) ((address + (alignment-1)) AND ~(alignment-1))
复制代码
- USEDFLASH_END MY_ALIGN(ImageLimit(CODE) , FLASHX_SECT_SIZE) EMPTY 0x4
- {
- }
复制代码
意思是从CODE段的结束地址的下一个扇区开始!
但是经过我跟HEX对比,发现其实ImageLimit(CODE) 并不是所有HEX文件的结尾,只是程序代码的结尾,其后面还有许多数据,这些数据应该是RW与ZI生成的常量,所以USEDFLASH_END的起始地址应该是:CODE扇区结束地址+DATA扇区尺寸的地址,下一个扇区开始!
但是DATA段定义在后面,所以我们要将USEDFLASH_END定义放在文件后面:
- #! armcc -E
- #define INTFLASH_END_ADDR 0x00040000
- #define INTFLASH_BASE_ADDR 0x00000000
- #define INTFLASH_SIZE (INTFLASH_END_ADDR - INTFLASH_BASE_ADDR)
- #define FLASHX_SECT_SIZE (0x800)
- #define MY_ALIGN(address, alignment) ((address + (alignment-1)) AND ~(alignment-1))
- LOAD_REGION_INTFLASH INTFLASH_BASE_ADDR INTFLASH_SIZE
- {
- VECTORS INTFLASH_BASE_ADDR
- {
- vectors.o (.vectors_rom,+FIRST)
- vectors.o (.cfmconfig)
- }
- CODE +0
- {
- * (InRoot$Sections) ; All library sections for example, __main.o,
- ; __scatter*.o, __dc*.o, and * Region$Table
- * (KERNEL)
- * (TEXT)
- * (+RO)
- }
- RAM_VECTORS 0x1FFF8000 ; For ram vector table. Used when MQX_ROM_VECTORS is set to zero.
- {
- vectors.o (.vectors_ram)
- }
-
- DATA +0
- {
- * (+RW)
- * (+ZI)
- }
- USB_BDT MY_ALIGN(ImageLimit(DATA), 512)
- {
- * (.usb_bdt)
- }
- KERNEL_DATA_START MY_ALIGN(ImageLimit(USB_BDT), 0x10)
- {
- * (KERNEL_DATA_START) ; start of kernel data
- }
-
- KERNEL_DATA_END 0x20007FF0 ; RAM_END
- {
- * (KERNEL_DATA_END) ; end of kernel data
- }
- ; mem_init writes a storeblock_struct at the end of kernel data,
- ; max size 32 bytes, so use 0x100 offset
- BOOT_STACK_ADDR 0x20007EF0
- {
- * (BOOT_STACK)
- }
-
- USEDFLASH_END MY_ALIGN(ImageLimit(CODE) + (ImageLimit(DATA) - ImageBase(DATA)), FLASHX_SECT_SIZE) EMPTY 0x4
- {
- }
- ; make sure this alignment matches the alignment in kernel_data.s in the bsp
- FLASHX_START MY_ALIGN(ImageLimit(CODE) + (ImageLimit(DATA) - ImageBase(DATA)), FLASHX_SECT_SIZE)
- {
- * (FLASHX)
- }
- }
复制代码
最后希望大家开发顺利!
一周热门 更多>