Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Procedure to download code in Flash Memory

Tags:

embedded

I am new to Embedded field. One doubt came up in my mind about hex file downloading: As output of the linker and locator is a binary file having various sections as .text,.bss,.data etc. and .text resides in Flash, .bss goes to RAM, .data goes to RAM ... so my question is that

  1. how .bss and .data are written to RAM as i am using FLASH Loader for burning my program onto flash.
  2. Is there any index kind of thing in the final binary which discriminates between .text and .bss segments.
  3. Is there any utility in the linker/locator which converts our simple binary into hex format.
  4. How can I discriminate between .text and .bss from the contents of hex file?

Thanks in advance. Please help.

like image 609
Phogat Ashish Avatar asked Sep 03 '11 18:09

Phogat Ashish


2 Answers

1.) how .bss and .data are written to RAM as i am using FLASH Loader for burning my program onto flash?

Code, constant data and initialized data are all written to FLASH. At runtime, initialized data is copied to bss during startup. Constant data is usually accessed directly (you declare it with the "const" keyword).

2.) Is there any index kind of thing in the final binary which discriminates between .text and .bss segments?

I think you mean by "binary" the linker output. This is usually referred to as an object file and is different from a binary image. The object file includes all code, data, symbol, debug information and memory addresses. For the GCC tool chain, the linker output is usually an .elf file.

Your linker uses a "link script" or other definition file to locate the various segments at the appropriate memory addresses. Your tool chain should have docs on how to change that.

3.) Is there any utility in the linker/locator which converts our simple binary into hex format?

The "objcopy" utility will read linker output and can write output files in a variety of formats, including Intel-hex. For human readable output see "objdump".

4.) How can I discriminate between .text and .bss from the contents of hex file?

By memory address. GCC uses the "initialized data" segment for data which is copied to the bss. It is located according to your linker script.

Intel-hex format: http://en.wikipedia.org/wiki/Intel_HEX

GCC: http://gcc.gnu.org/onlinedocs/

like image 172
2.718 Avatar answered Oct 12 '22 02:10

2.718


Your programming tools just write the program image (hex or binary file) into Flash, at the specified address.

When the compiler compiles the program, it adds information (look-up tables) containing information about the .bss and .data etc into the hex file, along with some C start-up code. The C start-up code, which runs before the C main() function begins, is responsible for initialising .bss and .data according to the information in the look-up tables in Flash memory. Typically, that means:

  • Initialising .bss to zeros.
  • Copying initialisation values for .data from the Flash memory into the appropriate locations in RAM.
    • (On some platforms, the initialisation values might even be stored compressed to save space in Flash, and the start-up code decompresses it as it writes it to RAM).

On some platforms, you might want to run code in RAM, for various reasons. The C start-up code can also copy code from Flash to RAM in a similar way.

The C start-up code can also do other essential things:

  • Initialise stack(s) and initial stack pointer
  • Initialise heap (if your program uses it)
  • Set some essential processor configuration, such as processor operating mode, clock speeds, Flash wait states, memory management unit, etc
like image 35
Craig McQueen Avatar answered Oct 12 '22 04:10

Craig McQueen