Putting Data into ROM

The embedded features package includes facilities for various data items to be put into ROM. The assumption is that the program text is in ROM, so these features are designed to put specified data items with the program text.

Putting Initialized Data into ROM

A program located in ROM may need to initialize RAM memory upon power-up or restart. If the program needs to have RAM variables that are initialized to specified values, proper steps must be taken to set up those variables at startup. Normally, executable files created by the linker consist of instructions in .text, initialized data in .data, and zero-initialized data in .bss.

Since all memory variables are in sections, they are initialized one entire section at a time. There are three ways that sections are initialized, depending on the type of section. Read-only sections have all of their initial values in the executable file. The contents of this section are downloaded to the target via the debug server or the contents are burned into ROM. Read-write sections are initialized by creating a read-only section which is a copy of the read-write section. This read-only section is initialized as described above. Then, during program startup, the contents are copied from the read-only image to the read-write section in RAM.

Zero-initialized sections (.bss sections) are initialized to zero during program startup. All variables in these sections have been implicitly initialized to zero.

The new ROM linker directives files make these actions largely automatic. By using the Green Hills startup code, a program can be put into ROM, and still have initialized variables (whose values are automatically copied from ROM to RAM at program startup time). In addition, its bss sections are automatically cleared, so that .bss variables start proper initialization to zero. "Linker Directives Files" provides more information.

How to Copy Data Sections from ROM to RAM and Clear .bss (zero-initialized data)

The Green Hills startup code automatically clears .bss sections and copies ROM to RAM; however, you can customize this, using the following pointers:

_ _ghsbinfo_clear

_ _ghseinfo_clear

_ _ghsbinfo_copy

_ _ghseinfo_copy

These pointers reference the .secinfo section which contains addresses specifying the areas of memory that need to be copied or cleared. For further information on customizing, on copying ROM to RAM, and to see the code that does the copy or clear, refer to "ind_crt0.c".

Verifying Program Integrity

One use of the _ _psinfo structure is to checksum sections in memory to verify that they have not changed from the state in which they were created by the linker. For this purpose, the linker calculates a CRC checksum for each F_TEXT or F_DATA section of non-zero length, and stores it as the last four bytes of the section. Upon initialization, it is possible to scan the _ _psinfo table sections of this type, calculate the same CRC on all but the last four bytes, and then compare the result to the stored CRC. A match indicates that the program has the same byte values in memory that it had when the linker created the executable file.


Previous

Next



Copyright © 1999, Green Hills Software. All rights reserved.