第一步:atmega128的片内flash分区描述
在atmega128 datasheet的275页中有分区描述

对应的在284页中,有具体的应用区与boot区的大小设置

注意:Byte address = word address * 2
这里的BOOT区首地址,$F000 = 0x1E000

根据手册中的描述,我们使用JTAG MKII 烧写器通过软件 Avr Studio 4,配置熔丝位 BOOTSZ为00

注意:这里面的4096 words = 8K bytes

第二步:说明一下linker(.xcl)文件的作用
好了,怎么让我们的程序烧写到flash中是在指定的0x1E000处呢?这就需要在link文件中指定CODE区的位置了。
适用于atmega128 bootloader程序的.xcl文件如下:

/*                      - lnkm128.xcl -**   XLINK command file for the ICCAVR C-compiler using the --cpu=m128, -ms*   options. Segments are defined for an ATmega128 whithout external*   memory. It is also possible to "add" external SRAM, EPROM and EEPROM.**   Usage: xlink your_file(s) -f lnkm128**   File version:   $Name: $*//*========================================================================*/
/* NOTE: This file has been modified to be used with the code example in: */
/*    AVR106: C functions for reading and writing to Flash memory         */
/* Se comments further down in this file, and the application note for    */
/* more information.                                                      */
/*========================================================================*//*====================================================*/
/* * Constants used down below, * Do not change these lines, * if it is not stated otherwise *//* Code (flash) segments */
-D_..X_INTVEC_SIZE=8C   /* 4 bytes * 35 vectors */
-D_..X_FLASH_TEND=FF    /* End of tiny flash memory */
-D_..X_FLASH_NEND=FFFF  /* End of near flash memory */
-D_..X_FLASH_END=1FFFF  /* End of flash memory *//* Internal data memory *//* * Change the two lines below to 60(BASE) and FF(TEND) * if you are running in "mega103 mode" */
-D_..X_SRAM_BASE=100    /* Start of ram memory */
-D_..X_SRAM_TEND=100    /* End of tiny ram memory */-D_..X_SRAM_END=10FF    /* End of ram memory */
/* Internal EEPROM */
-D_..X_EEPROM_END=FFF   /* End of eeprom memory */
/*====================================================*//** Modify the lines below to alter the size of the RSTACK, CSTACK and HEAP* segments. These need to be fine tuned to suit your specific application.* The '_..X_' prefix is used by C-SPY as an indication that the label should* not be displayed in the dissassembly window.*///-D_..X_CSTACK_SIZE=200  /* 512 bytes for auto variables and saved registers. */
//-D_..X_RSTACK_SIZE=40   /* 64 bytes for return addresses, equivalent to 32 *//* levels of calls, including interrupts. */
//-D_..X_HEAP_SIZE=100    /* 256 bytes of heap. */-D_..X_CSTACK_SIZE=300  /* 512 bytes for auto variables and saved registers. */
-D_..X_RSTACK_SIZE=40   /* 64 bytes for return addresses, equivalent to 32 *//* levels of calls, including interrupts. */
-D_..X_HEAP_SIZE=100    /* 256 bytes of heap. *//** Modify these lines if you have an external SRAM connected to the system.** Note: Remember to turn on the external data and address busses in*       __low_level_init if external memory is used.*/
-D_..X_EXT_SRAM_BASE=_..X_SRAM_BASE
-D_..X_EXT_SRAM_END=_..X_SRAM_END/** Modify these lines if you have an external EPROM connected to the system.** Note: Remember to turn on the external data and address busses in*       __low_level_init if external memory is used.*/
-D_..X_EXT_EPROM_BASE=_..X_SRAM_BASE
-D_..X_EXT_EPROM_END=_..X_SRAM_END/** Modify these lines if you have an external EEPROM connected to the system.** Note: Remember to turn on the external data and address busses in*       __low_level_init if external memory is used.*/
-D_..X_EXT_EEPROM_BASE=_..X_SRAM_BASE
-D_..X_EXT_EEPROM_END=_..X_SRAM_END/** The following segments are located in the internal memory of* the ATmega128. Do not change these lines.*//* Define CPU */
-ca90/*========================================================================*/
/* How to move the complete project and interrupt table to a Boot Sector. */
/*========================================================================*/
/* This method can be used on any device with boot sectors.               */
/* It presumes these defines are predefined:                              */
/*     _..X_INTVEC_SIZE, _..X_FLASH_TEND,                                 */
/*     _..X_FLASH_NEND, _..X_FLASH_END                                    */
/*========================================================================*/
/* -1- Find and remove (/comment out) the following section from the      */
/*     original XCL file.                                                 */
/*========================================================================*//* Code memory */
//-Z(CODE)INTVEC=0-(_..X_INTVEC_SIZE-1)/* Fill unused interrupt vector's with RETI */
/*
-H1895
-h(CODE)0-_..X_INTVEC_SIZE-Z(CODE)TINY_F=_..X_INTVEC_SIZE-_..X_FLASH_TEND
-Z(CODE)NEAR_F,SWITCH,DIFUNCT=_..X_INTVEC_SIZE-_..X_FLASH_NEND
-Z(CODE)CODE=_..X_INTVEC_SIZE-_..X_FLASH_END
-Z(FARCODE)FAR_F=_..X_INTVEC_SIZE-_..X_FLASH_END
-Z(CODE)HUGE_F,INITTAB=_..X_INTVEC_SIZE-_..X_FLASH_END
-Z(CODE)TINY_ID,NEAR_ID,CHECKSUM=_..X_INTVEC_SIZE-_..X_FLASH_END
*//*========================================================================*/
/* -2- Paste in the following section as a replacement.                   */
/* -3- Remove the comment marking on the used Boot Sector Size            */
/*========================================================================*//* Boot Sector Size */
-D_..X_BOOTSEC_SIZE=2000  /* 4096 words  */
//-D_..X_BOOTSEC_SIZE=1000  /* 2048 words */
//-D_..X_BOOTSEC_SIZE= 800  /* 1024 words */
//-D_..X_BOOTSEC_SIZE= 400  /*  512 words */
//-D_..X_BOOTSEC_SIZE= 200  /*  256 words */
//-D_..X_BOOTSEC_SIZE= 100  /*  128 words */
-D_..X_DEFSEC_POS=1000/* Code memory */
-Z(CODE)INTVEC=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+1)-(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE)
-Z(CODE)DEFSEC=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+1+_..X_DEFSEC_POS)-_..X_FLASH_END/* Fill unused interrupt vector's with RETI */
-H1895
-h(CODE)(_..X_FLASH_END-_..X_BOOTSEC_SIZE+1)-(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE) /*========================================================================*/
/* -4- If the flash size is 32kB or less then;                            */
/*     - Remove the comment marking on following line:                    */
/*========================================================================*///-Z(CODE)NEAR_F,SWITCH,DIFUNCT=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE+1)-_..X_FLASH_NEND/*========================================================================*/
/* -5- If the flash size is 32kB or less then;                            */
/*     - Remove the SWITCH segment from the following line:               */
/*========================================================================*/-Z(CODE)CODE,SWITCH=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE+1)-_..X_FLASH_END-Z(FARCODE)FAR_F=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE+1)-_..X_FLASH_END
-Z(CODE)HUGE_F,INITTAB=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE+1)-_..X_FLASH_END
-Z(CODE)TINY_ID,NEAR_ID,CHECKSUM=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE+1)-_..X_FLASH_END/*========================================================================*/
/*========================================================================*//* Internal data memory */
-Z(DATA)TINY_I,TINY_Z,TINY_N=_..X_SRAM_BASE-_..X_SRAM_TEND
-Z(DATA)NEAR_I,NEAR_Z=_..X_SRAM_BASE-_..X_SRAM_END,_..X_EXT_SRAM_BASE-_..X_EXT_SRAM_END/** If external SRAM is available it is possible to place the stacks there.* However, the external memory is slower than the internal so moving the* stacks to the external memory will degrade the system performance.*/
-Z(DATA)RSTACK+_..X_RSTACK_SIZE=_..X_SRAM_BASE-_..X_SRAM_END /* ,_..X_EXT_SRAM_BASE-_..X_EXT_SRAM_END */
-Z(DATA)CSTACK+_..X_CSTACK_SIZE=_..X_SRAM_BASE-_..X_SRAM_END /* ,_..X_EXT_SRAM_BASE-_..X_EXT_SRAM_END *//** If external SRAM is available it might be a good idea to move the* heap segment there, i.e. remove the _..X_SRAM_BASE-_..X_SRAM_END range.*/
-Z(DATA)HEAP+_..X_HEAP_SIZE=_..X_SRAM_BASE-_..X_SRAM_END,_..X_EXT_SRAM_BASE-_..X_EXT_SRAM_END/* Internal eeprom memory */
-Z(XDATA)EEPROM_I,EEPROM_N=0-_..X_EEPROM_END/** The following segment definitions are only used if external memory is* connected to the AVR controller.*//* External EPROM */
-Z(CONST)NEAR_C=_..X_EXT_EPROM_BASE-_..X_EXT_EPROM_END/* External EEPROM */
-Z(DATA)NEAR_N=_..X_EXT_EEPROM_BASE-_..X_EXT_EEPROM_END/* Select reduced "printf" support to reduce library size.See configuration section in manual concerning printf/sprintf. *//*Dlib*/
-e_Printf_1=_Printf/*Clib*/
-e_small_write=_formatted_write
-e_small_write_P=_formatted_write_P/* Disable floating-point support in "scanf" to reduce library size.See configuration section in manual concerning scanf/sscanf *//*Dlib*/
-e_Scanf_1=_Scanf/*Clib*/
-e_medium_read=_formatted_read
-e_medium_read_P=_formatted_read_P/* Suppress one warning which is not relevant for this processor */
-w29/* Code will now reside in file aout.a90 or aout.d90, unless -o is specified */
/* .d90 is the default if debug system is linked (option -r) */
/* .a90 is the default without debugging. Default format is -Fmotorola */

其中

-D_..X_BOOTSEC_SIZE=2000  /* 4096 words  */

确定了BOOT区的大小为4096字,与我们设置的BOOTSZ = 00正好吻合。
然后

-Z(CODE)INTVEC=(_..X_FLASH_END-_..X_BOOTSEC_SIZE+1)-(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE)
-h(CODE)(_..X_FLASH_END-_..X_BOOTSEC_SIZE+1)-(_..X_FLASH_END-_..X_BOOTSEC_SIZE+_..X_INTVEC_SIZE)

表示中断向量区的范围从0x1E000 ~ 0x1E08B,并将其填充

具体参数项,可以参考AVR的帮助文档 Linker and library Tools reference guide.

参考:ATMEL的官方应用文档的AVR106号应用笔记
http://www.atmel.com/dyn/products/app_notes.asp?family_id=607

第三步:bootloader程序,linker文件加载
1)将以上代码保存为lnkm128.xcl,并放于工程目录下
2)通过配置工程 Linker->Config->Override default将该文件加载进来

第四步:验证生成的hex文件是否将代码编译到了片内flash的0x1E000地址处

021000  -> 确定偏移段地址为0x1000
10E000  -> 确定段内地址从 0xE000开始
经计算实际地址为 0x10000 + 0xE000 = 0x1E000

转载于:https://www.cnblogs.com/aqing1987/p/4185390.html

atmega128 bootloader程序在IAR-AVR下 linker文件的配置及原因相关推荐

  1. 详解Apache下.htaccess文件常用配置

    .htaccess文件是Apache服务器中最常用的一个配置文件,它负责相关目录下的网页配置.通过htaccess文件,可以帮我们实现:网页301重定向.自定义404错误页面.改变文件扩展名.允许/阻 ...

  2. python程序开子进程打包成exe文件运行炸内存原因剖析

    from multiprocessing import Processdef task():print("hahaha")passif __name__ == '__main__' ...

  3. Win2003利用dfs(分布式文件系统)在负载均衡下的文件同步配置方案

    2019独角兽企业重金招聘Python工程师标准>>> 因网站流量增加为了给网站减轻负担特需要文件同步与负载均衡,通过增加一台服务器,通过dfs配置实现文件的同步 1. 建议要同步的 ...

  4. linux下repo文件的配置

    首先我们需要说明,在linux下,repo文件都是存放在/etc/yum.repos.d文件夹之中的.repo文件即是我们常说的源文件(repositry匹配文件),在使用yum命令的时候系统会自动读 ...

  5. Linux 下定时文件crontab配置

    定时实例 # 每分钟执行[这里都最好用绝对路径 不然可能执行失败] */1 * * * * /usr/local/php/bin/php /data/wwwroot/ooody.cn/artisan ...

  6. Linux系统下C语言实现遍历该目录下所有文件

    #include <stdio.h> #include <dirent.h> //头文件int ReadDir(char *path) //读取文件 {DIR *dir; ch ...

  7. IAR环境下STM32+IAP方案的实现(转)

    –基于STM32F103ZET6的UART通讯实现 一.什么是IAP,为什么要IAP  IAP即为In Application Programming(在应用中编程),一般情况下,以STM32F10x ...

  8. 嵌入式IAP开发笔记之一:面向STM32的BootLoader程序

    对于很多人来说,BootLoader并不是一个陌生的词,甚至会经常用到它.因为在很多情况下我们都需要BootLoader程序,比如我们需要对系统在线升级时就需要它,还有当我们需要在外部存储器中运行程序 ...

  9. STM32CbueMX之 USB下载更新固件Download Firmware Update(DFU)之一BootLoader程序编写

    声明: STM32CbueMX之 USB下载更新固件Download Firmware Update(DFU)之一BootLoader程序编写https://blog.csdn.net/sudaroo ...

  10. S12(X)微控制器的Bootloader程序

    需要实现远程升级单片机,正好在网上找到了官方提供的Bootloader程序及其对应的文档,赶快弄下来学习研究,这是对其文档的翻译. 翻译的资料是公开的,在这里下载https://www.nxp.com ...

最新文章

  1. PCL基础3:点云程序运行时间计时
  2. Linux常用的基本命令02
  3. Java数据结构与算法(25) - ch11哈希(双重哈希)
  4. 第三次毕业设计任务书
  5. jupyter notebook_远程终端访问(win11 / ECS云服务器)
  6. 在线聊天javascript代码
  7. [ARC073C] Ball Coloring(贪心)
  8. android 4.4 屏幕方向,Android4.4屏幕旋转功能
  9. java手机状态栏圆形图标,android实现状态栏添加图标的函数实例
  10. 脏牛Linux本地提权漏洞复现(CVE-2016-5195、Linux、Android、提权)
  11. 程序员的炫酷动态科幻桌面壁纸
  12. WebCrack:网站后台弱口令批量检测工具 ——yzddMr6
  13. ArcGIS教程 - 1 绪论
  14. Cityscapes数据集介绍
  15. JS面试题汇总(六)
  16. 解决高度塌陷的几种方法
  17. mac常用基本操作笔记
  18. 如何给typora更换主题背景
  19. 第10课:生活中的迭代模式——下一个就是你了
  20. [生存志] 第117节 九章算术均徭赋

热门文章

  1. OpenCV图像预处理常用函数及流程
  2. android名字的由来构词,词根词缀词典_根据词缀查单词的词典_词根词缀 书_词根词缀记忆字典4.4.0 for android...
  3. Windows中的iTunes Setup Assistant驱动程序错误修复
  4. 基于Python实现的Alpha-Beta剪枝算法
  5. IDEA:Windows 下载安装 IDEA 详细教程
  6. IBM上线了一个人工智能,叫做Project Debater,堪称辩论神器!
  7. PMP培训内容有哪些?都要仔细看!
  8. SpringBoot项目多环境配置(亲测有效)
  9. 地理空间数据云 Landsat 8 OLI_TIRS 影像数据下载详解
  10. css实现接地气的checkbox框