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
Thanks in advance. Please help.
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/
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:
.bss
to zeros..data
from the Flash memory into the appropriate locations in 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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With