BSP and Device Driver Development Guide
Now there's a problem with the initialized data: the .data
section
has to be in RAM as this data may be modified during the program execution.
But how will the values be initialized at boot time?
One approach is to place the entire program image in RAM and reload the image in its entirety each time the program is run. This is fine for use in a debug environment where a high-speed connection is available between the development host computer and the target. But even in this environment, it is cumbersome.
The solution is to place a copy of the initialized data in a separate
area of memory and copy it into the proper location each time the
program is started. It is common practice to place a copy of the initialized
.data
section at the end of the code (.text
) section
in ROM when building a PROM image. The GNU tool objcopy
can be used for this purpose.
The following figure illustrates the steps a linked program goes through to become a downloadable image.
+--------------+ +--------------------+ | .data RAM | | .data RAM | +--------------+ +--------------------+ | .bss RAM | | .bss RAM | +--------------+ +--------------------+ +----------------+ | .text ROM | | .text ROM | | .text | +--------------+ +--------------------+ +----------------+ | copy of .data ROM | | copy of .data | +--------------------+ +----------------+ Step 1 Step 2 Step 3
In Step 1, the program is linked together using the BSP linker script.
In Step 2, a copy is made of the .data
section and placed
after the .text
section so it can be placed in PROM. This step
is done after the linking time. There is an example
of doing this in the file $RTEMS_ROOT/make/custom/gen68340.cfg:
# make a PROM image using objcopy m68k-rtems-objcopy \ --adjust-section-vma .data= \ `m68k-rtems-objdump --section-headers \ $(basename $@).exe \ | awk '[...]` \ $(basename $@).exe
NOTE: The address of the "copy of .data
section" is
created by extracting the last address in the .text
section with an awk
script. The details of how
this is done are not relevant.
Step 3 shows the final executable image as it logically appears in
the target's non-volatile program memory. The board initialization
code will copy the ""copy of .data
section" (which are stored in
ROM) to their reserved location in RAM.
BSP and Device Driver Development Guide
Copyright © 1988-2008 OAR Corporation