1

what contains a binary file which come from a ARM GCC for ARM devices?

Is there inside it some information about destination address which write to? Or just native, pure, content of program without information about memory location?

If i have a bootloader, Or any way through programmer, can i write a binary file everywhere in flash or written itself by internal information about specific memory address?

If i setup my linker-script to write a program in a specific memory address, is there an influence in the bin file?

artless noise
  • 21,212
  • 6
  • 68
  • 105
MrBit
  • 290
  • 4
  • 20
  • Take a look at `objdump` to inspect object files. There are generally relocation tables, symbol tables etc. for runtime linking of memory addresses. Bootloaders and Flash programs don't have that, but memory addresses must be correct! And yes, linker scripts affect the bin file as they define what it must look like. – Kenney Sep 18 '15 at 19:32
  • so, a binary file, describes and the Main Program memory address which specified in linker-script? – MrBit Sep 18 '15 at 19:51
  • In essence, all files are binary files since they are stored using bits. You're probably looking for Object file (see [here](http://stackoverflow.com/questions/7718299/whats-an-object-file-in-c) and [here](https://en.wikipedia.org/wiki/Object_file)). Flash-chip programs and the bootloader are exceptions - they contain CPU instructions and some embedded data, no meta-data. The memory addresses they use are dictated by the hardware. – Kenney Sep 18 '15 at 20:03
  • I don't search information for object files, but for binary files, and what really stored inside them. what kind information are in there? Can i flash a binary file which specified (in linker-script) with different main program memory address through a bootloader in the same memory address? – MrBit Sep 18 '15 at 20:11
  • You don't seem to know what binary files are yet you are sure you don't need to know what object files are? – Kenney Sep 18 '15 at 20:12
  • Yes i'm already looking that, but i really want to know how binary and linker-script are associated and affect the programmer or a bootloader to write the main application in specified address – MrBit Sep 18 '15 at 20:18
  • if i using a bootloader to read a bin file and update my main application it is neccesary to specify the memory location? – MrBit Sep 18 '15 at 20:29
  • You're going to have to be much more specific, because your either/or questions can effectively be answered with "yes". Even within the ARM world, "bootloader" could mean anything from a handful of Cortex-M0 startup code to full-blown UEFI. A bootloader that is essentially a stub of code linked to an application at build time has totally different requirements to one that can itself load and run standard ELF or PE/COFF executables; make the question about the particular thing you're interested in. – Notlikethat Sep 18 '15 at 23:00
  • I'm searching for informations about binary files which are generated from ARM GCC, what that contains and like this. In additional, how can i write a binary file in Flash memory of an ARM device, through some bootloader, (e.g. UART bootloader) for self upgrade. and finally how affect the selected main program memory address in link-script to "self-upgrafe" (Bootloader writing firmware in a specific constant address so i don't understand the affect of link-script to main program address). – MrBit Sep 18 '15 at 23:48
  • 2
    GCC emits ELF objects (occasionally PE/COFF or other object formats for certain targets, but mostly ELF). The particular "binary" format a particular bootloader is expecting depends a lot on that bootloader: does it merely start executing the code in-place in flash? Does it do any sort of relocation first? Does it look for some kind of header/checksum/etc.? What you do for a particular device *depends entirely on the bootloader behaviour, peripherals, and memory layout of **that device***; replace "ARM" with "MIPS", "PowerPC", "AVR" or anything else and it's still exactly the same question. – Notlikethat Sep 19 '15 at 12:35
  • So, binary files may they contains, except main firmware, header, checksum, memory relocations... – MrBit Sep 19 '15 at 13:41
  • How can i see the structure of a binary i have? i mean, if there's a header of signature or magic number in it, how can i know and find that? – MrBit Sep 19 '15 at 14:16
  • 1
    See the book [Assemblers, linkers and loaders](http://www.davidsalomon.name/assem.advertis/asl.pdf) by David Salomon. You need to setup a 'C' environment with a stack, clear the 'BSS' and copy init data from flash to RAM for a boot loader, etc; typically bootstrap written in assembler. The compiler/assembler can be PC relative (and data relative) or it maybe absolute. Compiler flags, specific assembler, etc will determine based on the **design** of the binary code. Binary files maybe anything. There is a tool 'binwalk' (and probably others) for analysis, but they may have false positives. – artless noise Sep 19 '15 at 17:37
  • The typical bootloader handles a "binary" that is a standalone program in an executable image file. Some ARM loaders (e.g. for Atmel ARM9) rely on the image to contain the ARM Exception Vector in the first 28 bytes of the image. The image is typically linked to be loaded and executed at a specific memory address (unless the program was coded to be 100% relocatable, which is rare). – sawdust Sep 23 '15 at 23:29

1 Answers1

1

There are several types of files, which are called "binary' (at least among my colleagues):

.bin file extension. Contains only data that would/could be written to single continuous partition. It doesn't contain any addresses or offsets inside. When flashing this file to microcontroller you should explicitly specify destination address (often this is 0x0, beginning of flash). If you need to write to different partitions you need separate .bin for each of them (or it can be merged one if these partitions are consecutive). So this file type is like memory footprint.
Pros: minimum overhead if you have a single continuous partition and destination address always the same (so it can be hardcoded)

.hex is an Intel hex file format. It contains destination address for each line in it. Can be opened in any text editor.

.s19 or .srec Motorola s-record. Very similar to .hex, just another format. Also can include some metadata, that wouldn't be flashed.

Pros of last two types: best choice if you have several inconsistent partitions. Can be compressed by removing gaps

For VSCode there are several plugins that can highlight .s19 and .hex files

Dmitriy I
  • 51
  • 4