Updated: 06/Jul/2001 [IOLW]
Archived: $Revision: 1.3 $
The current version of the IAR XLINK linking utility can not generate output into several files, only into one big file contaning all segments of the project. To program an AVR chip using Atmel AVR tools (AVR Studio or Atmel AVR ISP) we must have a file with format Intel extended (or Motorola S-records, works with Atmel AVR ISP). A big drawback with these formats is that both Intel extended and Motorola hex format describe the memory space as one continuous chain, i.e. like the memory in the von Neumann model. This does not fit the purpose for a chip of Harward architecture. The AVR architecture has at least two memory spaces, flash and EEPROM, and some architectures can address external EPROM memory.
The IAR UBROF8 format, which can be read by the IAR C-SPY Debugger, has support for the Harward architecture memory model and therefore we can simulate a project without splitting up flash and EEPROM memory (and external EPROM memory) spaces.
Since the Atmel tools cannot read the UBROF8 format we have to split our data into three separate hex files: Code, to program the internal flash memory; EEPROM, to program the internal EEPROM memory; Data, to program the external EPROM (if any). One way to do this is to have several projects, one for each memory area, that are linked separately. With the IAR Postlink utility it is however possible to have all the project files independent of memory space in the same project. The IAR Postlink utility makes multiple output files based on segment types.
The IAR Postlink utility takes as input an object file (of the XLINK simple format) and extract one or more of its XLINK memory types into one file (this file can be on either Intel extended hex format or Motorola S-record format). For example, it can put all code segments into one file and all EEPROM segments into another.
To put a segment into EEPROM we map it to have segment type XDATA. The IAR Compiler uses the segments EEPROM_N, EEPROM_I for this purpose (see Avr EEPROM howto.htm for more details on this topic). The table below illustrates how AVR memory areas are related to XLINK segment types.
Memory area Segment type flash code eeprom xdata external eprom const, data
First we must specify an output format. The available possibilities is Motorola or Intel extended output format. We can choose between these with the options -motorola or -intel-extended. If nothing is specified Motorola output format will be choosed by default.
Then we must tell which XLINK memory type the IAR Postlink utility should include in the output file. The options are: -code, -data, -xdata, -idata, -bit, -const and -untyped.
We can let Postlink build our output filename from the input filename. The option -use_base_name makes Postlink to let the output file name begin with the input filename without the extension. If we add -use_suffix suffix we can specify the suffix of the output file.
If we want some verbose information to XLINK we add the -v option to the command line.
A input file name is a required option and must refere to a file on the simple format.
As the last option we specify our output file name. Note that we cannot specify an output file name if the option -use_base_name is used.
NOTE: If no output file is given and the -use_base_name option is omitted, output is sent to the standard output stream.
Choose one of the existing .xcl-files that fits your target. Then be sure to choose the XLINK command line option -FSimple to get a file of simple format. Example:
xlink.exe -Fsimple file1.r90 file2.r90 -f lnk_file.xcl
This will by default create a file called aout.raw, this file can be used as input to the IAR Postlink utility.
To extract the EEPROM data into one file from the file in the above example we can use:
postlink.exe -intel-extended -xdata aout.raw > aout_eeprom.hex
This will put the EEPROM data in Intel extended format into the file called aout_eeprom.hex. The aout_eeprom.hex file can be used as input to program the chip EEPROM memory. To extract the data that should be put into flash memory we call the IAR Postlink utility with command line option -code instead of -xdata. If we have data that should be put into an external EPROM memory we should use both -data and -const command line options instead of -xdata.
There is a script called postlink.bat that will do this job for the most common AVR purposes and this script will be handled in the next section.
The postlink.bat script can be used to facilitate the usual usage of the IAR Postlink utility for AVR users. You can either use this script as it is or modify it to fit your special purposes. The postlink.bat script takes as input a file of the XLINK simple format (the path to postlink.exe must also be specified on the command line). From this file the script creates three files: one file consisting of all code segments, another file consisting of all constant and data segments. And a third file that consists of all the EEPROM segments, i.e. the segments of the XLINK memory type XDATA.
A easy way to get access to the postlink.bat script is to configure it as a tool in the IAR Embedded Workbench tool meny. Just choose "Tools->Configure Tools" in the IAR Embedded Workbench. In the Configure Tools dialog box, type in the following and press the Add button:
The postlink.bat script is located in the avr/bin directory under your IAR Embedded Workbench installation root.
To use the postlink.bat script choose "tools->Postlink".
Create a new project.
Activate the program memory window and choose "File->Load" from the menu bar. Browse to the file contaning the code (i.e. *_code.hex if you used postlink.bat script).
Then activate the Data EEPROM memory window and load the file contaning EEPROM data.
The AVR studio cannot read UBROF files greater than version 6. To be able to use AVR studio to program the AVR chip, import the Intel Extended hex-files into AVR Studio. Use "File->Open" and point out the hex-file that contains the CODE segment (i.e. *_code.hex if you used postlink.bat script).
Then use "File->Upload/download memories" from the menu bar, choose browse in the hex-file section and browse to the hex-file containing EEPROM memory (i.e. *_eeprom.hex if we used postlink.bat script). To load the file into AVR Studio EEPROM memory, press program in the EEPROM section.
If your chip has a external EPROM memory you should again choose "File->Upload/download memories" from the menu bar. Then choose browse in the hex-file section and browse to the hex-file containing Constant data memory (i.e. *_data.hex if you used postlink.bat script). To load the file into AVR Studio Data memory press program in the SRAM section.
Copyright 2001 IAR Systems. All rights reserved.