Description It is sometimes necessary to merge two (or more) binary images together to form a single image. For example, you may have two binary images (created from a scatter file which specifies two load regions) which need joining together to blow onto a single ROM. As another example, you may need to join some binary program code (e.g. created with '-bin') with a data file (e.g. font data from a 3rd party) to form a single binary (e.g. ROMmable) image. There are four possible ways to acheive this: 1. Use a debugger to join images If the absolute address locations of each image are known in advance, then one simple way to merge them is to use the getfile/putfile facility of the ARM debuggers (armsd, ADW, ADU): 1. Load the first image into the debugger's memory with 'File->Get file' (or 'getfile' for armsd). Note that you must specify an address to load into, e.g. 0x0000. 2. Load the second image into the debugger in the same way. Again, specify a (different, non-overlapping) address e.g. 0x8000. 3. Output the combined image from memory onto disc with 'File->Put file' (or 'putfile' for armsd). Specify the start and end addresses (e.g. 0x0000 to 0xFFFF) of the image to output, and give it a filename. This produces one combined image from two (or more) code/data files. Note that this method simply joins images together. It does not perform any 'intelligent' placement of areas, as the linker does. 2. Use a debugger to create the bin file When creating scatter loaded images with multiple load regions, instead of using fromelf to generate the plain binary images (which you then have to join together), you can simply use the debugger to create a single plain binary image from the ELF file. You can use the armsd command line debugger to load the full ELF image into the debugger and then use 'putfile' to write one single concatenated binary image out to a file. For example, if your ELF image is called image.elf and produces several load regions, the first of which is placed at 0x0 and the last of which ends at address 0x8000 then the following script.txt file can be used:
load image.elf putfile image.bin 0x0,0x8000 quit
To invoke this simply type on the command line
armsd -exec -script script.txt
Note that it is also possible to pass the file name in the armsd invocation rather than the script itself. You may not always know the end address of the last region (0x8000 in the example above) in advance, however, it is possible to automate this. When you load the ELF file (which contains the binaries) into armsd, this not only loads the binary information but also loads the debug information. This means that you have direct access inside the debugger to the low level scatter loading symbol names. Thus if your last load region contained the single execution region LAST (which does not relocate), you could save out both binaries as a single file using:
putfile image.bin 0x0,(Image$$LAST$$Base+Image$$LAST$$Length)
Note that if the base of your flash is not at 0x0, then you could specify the address using the the symbol Image$$FIRST$$Base, where FIRST is the name of the first execution region in the first load region. In later toolkits, the linker will only generate these symbols if your source code refers to them. In this case you need to create a dummy code region that creates references to the appropriate symbols, like this:
AREA Dummy, CODE IMPORT |Image$$FIRST$$Base| IMPORT |Image$$LAST$$Base| IMPORT |Image$$LAST$$Length| END
Simply assemble this and link the object file into your project. 3. Using DOS 'copy' or Unix 'cat' To concatenate binaries using DOS or Unix, use:
(DOS) copy /b app.bin+data.bin romimage (Unix) cat app.bin data.bin > romimage
This produces one combined image from two (or more) code/data files. Note that this method simply joins images together. It does not perform any 'intelligent' placement of areas, as the linker does. 4. Using BIN2AOF at build time Another approach is to convert the binary data files into AOF objects, which can then be 'intelligently' linked together by armlink. The conversion from binary to AOF can be done with a utility called BIN2AOF, which you may download (see below). The linker can then link the converted AOF object(s) with other code/data .o files (produced by the compilers or assemblers) to create a final combined image. This approach can also be used in 'scatter loaded' projects. You may download BIN2AOF (23K Zip file). This contains the bin2aof_readme.txt, 'bin2aof.exe' for PC (DOS) (38K executable file) and 'bin2aof' for Solaris (13K executable file). Please note that this BIN2AOF utility is provided free and unsupported. 5. Using armasm's INCBIN (SDT 2.50 and later) The INCBIN directive of armasm includes a file into an assembler file. The file is included as it is, without being assembled. You can use INCBIN to include executable files, literals, or any arbitrary data. The contents of the file are added to the current AOF area, byte for byte, without being interpreted in any way. See SDT 2.50 Reference Guide, section 5.8.44.
|