industrialNETworXnetx

Rainer Versteeg

Rainer Versteeg

| 20.08.2008 | 12:48 | 32 replies

Load Variables automaticly in Backup RAM

HI,

I want that my variable are automaticly in BACKUP RAM (and only in BACKUP RAM).

Gives there a scriptfile like netx_sdram.scr that loads variables from a headerfile in the BACKUP RAM ? :roll:

Br,
Rainer

Chris

Chris

| 20.08.2008 | 15:26

Hi Rainer,

Rainer Versteeg wrote:
I want that my variable are automaticly in BACKUP RAM (and only in BACKUP RAM).
Gives there a scriptfile like netx_sdram.scr that loads variables from a headerfile in the BACKUP RAM ? :roll:

First some important things:

  • only netX500 has a backup ram[/*:m]
  • it has only 16K[/*:m]
  • the backup ram can only be accessed if the "Power Good" input is active[/*:m]
  • without a battery the contents are lost after power down[/*:m]

So please make sure that your netX500 hardware drives the "Power Good" input and that your variables do not use more than 16K Bytes.

I suggest that you give it a try first. I will describe how to change your project so that it works in the Hitop debugger.

Please note that you can not use this solution to build a bootable image. You will need 2 more steps for this.

HiScript can't help us here, we need to modify the linker description file (that's the *.ld file in your project).
To use the backup ram in your hitop project just add it like a normal ram to your ld file.

This is the new memory element for the ld file:

MEMORY
{
        BACKUPRAM(RW) : ORIGIN = 0x00300000, LENGTH = 0x00004000

...

}

...and this is the section:

SECTIONS
{

...

.backupram :
{
/* TODO: init sections for the backup ram here */
} >BACKUPRAM

...

}

Please note: do not forget to add the section with your variables below the "TODO".

Once this part is running we will proceed to the bootable image.

[/]

Rainer Versteeg

Rainer Versteeg

| 21.08.2008 | 14:04

Hi Chris,

What i must write in the TODO section :roll:

My variables are in the COMVAR.h file

Br,
Rainer

Chris

Chris

| 21.08.2008 | 14:38

Hi Rainer,

Rainer Versteeg wrote:
What i must write in the TODO section :roll:

My variables are in the COMVAR.h file

The header file contains only the declaration of your variables. We need the definition, which is (usually) in the *.c file. The compiler produces an object file from this, which is processed by the linker. This means the *.o files are important for us in the linker script.

I guess your object file will be "COMVAR.o" and it is written to the folder "output". This line will cover all read/write sections:

output/COMVAR.o(.bss .data*)

".bss" are uninitialized variables (which are of course not constant), ".data*" are pre-initialized variables which are not constant.

Please note: place the .backupram section at the beginning of the "SECTION" area to prevent that other sections already grab the .bss and .data* parts of the COMVAR.o file:

SECTIONS
{
        .backupram :
        {
                output/COMVAR.o(.bss .data*)
        } >BACKUPRAM

/* more sections follow */

...

}

Feel free to add more lines to the section if you want to place variables from more object files in the backup ram.

Rainer Versteeg

Rainer Versteeg

| 21.08.2008 | 16:56

HI Chris,

I have done what do you write.

I can build a project File.

Is that right that my variables are in SDRAM. In HITOP and in the LOADMAP the variables are at address 0x80xxxxxxx.

There must be at address 0x00300000 :?:

Br,
Rainer

Chris

Chris

| 22.08.2008 | 10:08

Hi Rainer,

Rainer Versteeg wrote:
Is that right that my variables are in SDRAM. In HITOP and in the LOADMAP the variables are at address 0x80xxxxxxx.

The vars should be at 0x00300000. Can you post your ld file?

Rainer Versteeg

Rainer Versteeg

| 22.08.2008 | 10:14

HI Chris

Here is my *.ld file

/****************************************************************************
  File          : netX.LD
-----------------------------------------------------------------------------
  Author        : Hilscher GmbH 

Copyright (c) 2003,2004 All Rights Reserved

Date : 22-May-2004

Project : netX - NetworX on Chip
-----------------------------------------------------------------------------
Description:

- GNU Linker Script file

Functions:

None

-----------------------------------------------------------------------------
Todo:
-----------------------------------------------------------------------------
Changes:

Name Date Version Description
-----------------------------------------------------------------------
Ab 22-May-2004 1.000 created
Ernest 11-Nov-2005 1.100 Optimized to reduce size in target
AJ/CT 27-Apr-2006 1.200 Updated Stack Section
AJ 20-Mrz-2007 1.300 Updated Stack Section and heap labels
****************************************************************************/

/* specify list of directories to search for libraries */

SEARCH_DIR("$(PATH_GNU_ARM)\arm-hitex-elf\lib\interwork\arm926ej-s")
SEARCH_DIR("$(PATH_GNU_ARM)\lib\gcc\arm-hitex-elf\4.0.3\interwork\arm926ej-s")
SEARCH_DIR("$(PATH_GNU_ARM)\lib\gcc\arm-hitex-elf\4.1.1\interwork\arm926ej-s")
SEARCH_DIR("./Lib")
SEARCH_DIR("./Lib/netx100")

/* include the list of objects to link */

INPUT
(
/* HiTOP will automatically put in here all object files to be linked. */
/* Leave this unchanged! */
$(LinkObjects)
)

/* HiTOP will automatically put in here the target file produced by the linker. */
/* Leave this unchanged! */
OUTPUT ($(TargetDir)$(Target))

/* Memory definitions
Note: the sdram size is fixed to 8MB, the smallest type for all our boards
*/
MEMORY
{
INTRAM0(rwx) : ORIGIN = 0x00000004, LENGTH = 0x00007ffc
INTRAM1(rwx) : ORIGIN = 0x00008000, LENGTH = 0x00008000
INTRAM2(rwx) : ORIGIN = 0x00010000, LENGTH = 0x00008000
INTRAM3(rwx) : ORIGIN = 0x00018000, LENGTH = 0x00008000
INTKERNELROM(rwx) : ORIGIN = 0x00202000, LENGTH = 0x6000
INTKERNELRAM(rwx) : ORIGIN = 0x10000000, LENGTH = 0x2000
SDRAM(rwx) : ORIGIN = 0x80000000, LENGTH = 0x00800000
BACKUPRAM(RW) : ORIGIN = 0x00300000, LENGTH = 0x00004000
}

/* Section Definitions */
SECTIONS
{

.backupram :
{
output/COMVAR.o(.bss.data*)
} >BACKUPRAM

.KernelRom (NOLOAD):
{
*RomSymbols.o(.text)
} >INTKERNELROM =0

.KernelRam (NOLOAD):
{
*RomSymbols.o(.data)
} >INTKERNELRAM =0

/* system vectors reserved area */
.system 0x00000000 :
{
. = . + 0x80;
} >INTRAM0

/* reserve edd buffers for all 4 channels
The first part of segment 0 is occupied by the system vectors and
can't be used. All other buffers start at the same offset in the
ram bank to keep the structure */
.eddbuffer0 0x00000618 :
{
PROVIDE (eddbuffer0_start = .);
. = . + 0x79e0;
PROVIDE (eddbuffer0_end = .);
} >INTRAM0
.eddbuffer1 0x00008618 :
{
PROVIDE (eddbuffer1_start = .);
. = . + 0x79e0;
PROVIDE (eddbuffer1_end = .);
} >INTRAM1
.eddbuffer2 0x00010618 :
{
PROVIDE (eddbuffer2_start = .);
. = . + 0x79e0;
PROVIDE (eddbuffer2_end = .);
} >INTRAM2
.eddbuffer3 0x00018618 :
{
PROVIDE (eddbuffer3_start = .);
. = . + 0x79e0;
PROVIDE (eddbuffer3_end = .);
} >INTRAM3

.stacks (NOLOAD):
{
. = . + 0x4000;
PROVIDE (top_of_stacks = .);
} >SDRAM

/* code section */
.sec0 :
{
*(.init_code)
*(.text)

*(.glue_7t) *(.glue_7)

/* .rodata section which is used for read-only data (constants) */
*(.rodata*)

. = ALIGN(4);

_etext = . ;
PROVIDE (etext = .);
} >SDRAM

/* .data section which is used for initialized data */
.data :
{
_data = . ;

*(.data)
SORT(CONSTRUCTORS)
} >SDRAM

/* .bss section which is used for uninitialized data */
.bss :
{
. = ALIGN(4);

__bss_start__ = . ;

*(.bss)

/* uninitialized data, see "Using LD, the GNU linker",
"Section Placement":
Specify where in your output file to place uninitialized
data with this notation. *(COMMON) by itself refers to all
uninitialized data from all input files (so far as it is
not yet allocated); */
*(COMMON)

/* align the end of the section to 32bit boundary */
. = ALIGN(4);

__bss_end__ = . ;
} >SDRAM

. = ALIGN(4);
_edata = . ;
PROVIDE (edata = .);

. = ALIGN(4);
_end = .;
PROVIDE (end = .);
PROVIDE (_end = .);
PROVIDE (_heap_start = .); /* starts right after the last data section */
PROVIDE (_heap_end = 0x80000000 + 7M - 4); /* ends at 7MB-4 from SDRAM start */

PROVIDE (abDrvRrdDiskArea = 0x80000000 + 7M);

/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
}

Br,
Rainer

Chris

Chris

| 22.08.2008 | 10:37

Hi Rainer,

Rainer Versteeg wrote:

...

.backupram :
{
output/COMVAR.o(.bss.data*)
} >BACKUPRAM

...


First idea: please insert a space between ".bss" and ".data", like this:

SECTIONS
{
        .backupram :
        {
                output/COMVAR.o(.bss .data*)
        } >BACKUPRAM

/* more sections follow */

...

}

With the space you will include vars from the sections ".bss" and from all sections which start with ".data". Without the space you try to include vars from all sections which start with ".bss.data". Of course the linker will not find such a section.

Rainer Versteeg

Rainer Versteeg

| 22.08.2008 | 10:44

HI Chris,

It is the same. The variables are at address 0x80xxxxxxx :roll:

Br,
Rainer

Rainer Versteeg

Rainer Versteeg

| 22.08.2008 | 11:51

HI Chris,

When i do this, then the variables are in 0x00300000.

/* .bss section which is used for uninitialized data */
        .bss :
        {
                . = ALIGN(4);

__bss_start__ = . ;

*(.bss)

/* uninitialized data, see "Using LD, the GNU linker",
"Section Placement":
Specify where in your output file to place uninitialized
data with this notation. *(COMMON) by itself refers to all
uninitialized data from all input files (so far as it is
not yet allocated); */
*(COMMON)

/* align the end of the section to 32bit boundary */
. = ALIGN(4);

__bss_end__ = . ;
} >BACKUPRAM

Are then all variables at the address or only my COMVAR.o :?:

Are something missing like this for COMVAR.o

Br,
Rainer

Rainer Versteeg

Rainer Versteeg

| 25.08.2008 | 13:52

HI Chris,

Anything news :?:

Should i send a demo project :?:

Br,
Rainer

Chris

Chris

| 26.08.2008 | 10:05

Hi Rainer,

Rainer Versteeg wrote:
Are then all variables at the address or only my COMVAR.o :?:

This places all variables in the backup ram.

Ok, another idea: Is the path to the object correct?

Go to your project directory (that's where the .htp file is). There should be a ".lnk" file. Open it in an editor. At the end of the file are several lines starting with "INPUT". They look like this:

INPUT ( ./Output/Something.o )

Locate your COMVAR object file. Copy the text in the brackets without any changes to the section:

SECTIONS
{
        .backupram :
        {
                ./Output/Something.o(.bss .data*)
        } >BACKUPRAM

/* more sections follow */

...

}

The linker is a linux tool which means it is case sensitive. This means "output/something.o" is not the same as "Output/Someting.o" .

There are also some cryptic issues with slashes, backslashes and the dot - thanks to Hitex for using cygwin.

Rainer Versteeg

Rainer Versteeg

| 26.08.2008 | 13:57

HI Chris,

It does not work !

Here is my COMVAR.C

/*------------------------------------------------------*/
/*      Programm : V1.0              Date : 17.05.08 */
/*      Modul    : COMVAR.C                             */
/*      Projekt  : Entwicklung CX                       */

/*------------------------------------------------------*/

float DOREAL; /* 01 DosierArt */
float SCHUET; /* 02 Schuettgewicht */
float ERNENN; /* 03 Ermit. Foerderleistung */
float TARALR; /* 04 Tara */
float VOLFL; /* 05 Vol. Foerderleistung */
float RESE1; /* 06 Dekadenschalter */
float VORPKT; /* 07 Vorhaltepunkt Charge */

Must i include the file under HITOP FileView/sourcefile.

Br,
Rainer

Chris

Chris

| 26.08.2008 | 14:52

Hi Rainer,

Rainer Versteeg wrote:
It does not work !

Give me some more hints, please.
  • Where is your .lnk file? (absolute path please)[/*:m]
  • Please copy/paste the "INPUT" line for the COMVAR.o file.[/*:m]
  • Please paste the updated .backupram section to your reply.[/*:m]

Quote:

Must i include the file under HITOP FileView/sourcefile.

Yes, you have to compile the file if that's what you mean.

[/]

Rainer Versteeg

Rainer Versteeg

| 26.08.2008 | 15:02

HI Chris,

My netx.lnk file lies in the root directory. Here is also the netx_sdram.ld file.

Here is my netx.lnk file

*
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  The search dirs entries in the next lines refer to the path where
  the linker can find the library files for the gnu lib
  These are different depending on where you installed the
  GNU tools. Plaese add your specifik path if you get
  a linker error like: arm-hitex-elf-ld: cannot find -lgcc
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
 
 SEARCH_DIR("C:\Program Files\Hitex\GnuToolPackageArm\arm-hitex-elf\lib\interwork\arm926ej-s")
 SEARCH_DIR("C:\Program Files\Hitex\GnuToolPackageArm\lib\gcc\arm-hitex-elf\4.1.1\interwork\arm926ej-s")
 SEARCH_DIR("C:\Program Files\Hitex\GnuToolPackageArm\lib\gcc\arm-hitex-elf\4.0.3\interwork\arm926ej-s")

SEARCH_DIR("C:\My tools\Hitex\GnuToolPackageArm\arm-hitex-elf\lib\interwork\arm926ej-s")
SEARCH_DIR("C:\My tools\Hitex\GnuToolPackageArm\lib\gcc\arm-hitex-elf\4.1.1\interwork\arm926ej-s")
SEARCH_DIR("C:\My tools\Hitex\GnuToolPackageArm\lib\gcc\arm-hitex-elf\4.0.3\interwork\arm926ej-s")

SEARCH_DIR("C:\Programme\Hitex\GnuToolPackageArm\arm-hitex-elf\lib\interwork\arm926ej-s")
SEARCH_DIR("C:\Programme\Hitex\GnuToolPackageArm\lib\gcc\arm-hitex-elf\4.1.1\interwork\arm926ej-s")
SEARCH_DIR("C:\Programme\Hitex\GnuToolPackageArm\lib\gcc\arm-hitex-elf\4.0.3\interwork\arm926ej-s")

SEARCH_DIR("D:\Programme\Hitex\GnuToolPackageArm\arm-hitex-elf\lib\interwork\arm926ej-s")
SEARCH_DIR("D:\Programme\Hitex\GnuToolPackageArm\lib\gcc\arm-hitex-elf\4.1.1\interwork\arm926ej-s")
SEARCH_DIR("D:\Programme\Hitex\GnuToolPackageArm\lib\gcc\arm-hitex-elf\4.0.3\interwork\arm926ej-s")

SEARCH_DIR("E:\Programme\Hitex\GnuToolPackageArm\arm-hitex-elf\lib\interwork\arm926ej-s")
SEARCH_DIR("E:\Programme\Hitex\GnuToolPackageArm\lib\gcc\arm-hitex-elf\4.1.1\interwork\arm926ej-s")
SEARCH_DIR("E:\Programme\Hitex\GnuToolPackageArm\lib\gcc\arm-hitex-elf\4.0.3\interwork\arm926ej-s")

/*
The next lines specify all program modules that need to
be linked into the target file
*/

SEARCH_DIR("./Lib")

INPUT ( ./Output/InitGnu.o )
INPUT ( ./Output/main.o )

There is an entry missing for COMVAR.O

Here is my netx_sdram.ld:

/* Section Definitions */
SECTIONS
{
       .backupram : 
	{
          ./Output/COMVAR.o(.bss .data*)
        } >BACKUPRAM       

I dont know what I make wrong

Can you send me a small demo, please :?:
It only needs a small project with the COMVAR.C :roll:

Br,
Rainer

Chris

Chris

| 26.08.2008 | 15:46

Hi Rainer,

Rainer Versteeg wrote:
 SEARCH_DIR("C:\Program Files\Hitex\GnuToolPackageArm\arm-hitex-elf\lib\interwork\arm926ej-s")
 SEARCH_DIR("C:\Program Files\Hitex\GnuToolPackageArm\lib\gcc\arm-hitex-elf\4.1.1\interwork\arm926ej-s")
 SEARCH_DIR("C:\Program Files\Hitex\GnuToolPackageArm\lib\gcc\arm-hitex-elf\4.0.3\interwork\arm926ej-s")

...

Please try to weed out the unused search paths. You will run into problems if you have multiple gcc versions installed.

Quote:
INPUT ( ./Output/InitGnu.o  )
INPUT ( ./Output/main.o )

There is an entry missing for COMVAR.O


Yes, there really is no line with the COMVAR object. If there is no line for an object, the linker will of course not process it. This is a matter of setting up a project in the HiTop environment.

Please read the according section in the HiTop documentation. You absolutely must know the basics before you proceed to do complicated stuff like this here.

Rainer Versteeg

Rainer Versteeg

| 27.08.2008 | 09:41

HI Chris,

I have learned the basic of the HITOP. 8)

You wrote about a *.lnk file. I dont need this file :!:

Now I have my vars at 0x003xxxxx, but I became always an error:

./Output/COMVAR.o:(.bss+0x0): multiple definition of `DOREAL'
.\Output\Comvar.o:(.bss+0x0): first defined here

When I remove the COMVAR.C file from my project than the error disapear.

The linker see two declaration of my vars, but to make an object file I must include the COMVAR.C in my project.

What I make wrong :?:

Br,
Rainer

Chris

Chris

| 27.08.2008 | 15:53

Hi Rainer,

Rainer Versteeg wrote:
I have learned the basic of the HITOP. 8)

Very good, welcome to the dark side! :twisted:

Quote:
You wrote about a *.lnk file. I dont need this file :!:

My HiTop still needs it. I guess you have a more recent version.

Quote:

Now I have my vars at 0x003xxxxx, but I became always an error:

./Output/COMVAR.o:(.bss+0x0): multiple definition of `DOREAL'
.\Output\Comvar.o:(.bss+0x0): first defined here

Ok, I think that's the problem: your HiTop includes the objectfile ".\Output\Comvar.o" on it's own. This means it does this without any .lnk file. But we try to include sections from "./Output/COMVAR.o" in the ld file.

Please try to remove the COMVAR.c file from your project, and use the ".\Output\Comvar.o" in the ".backupram" section in the ld file:

SECTIONS
{
        .backupram :
        {
                .\Output\Comvar.o(.bss .data*)
        } >BACKUPRAM

/* more sections follow */

...

}

Rainer Versteeg

Rainer Versteeg

| 28.08.2008 | 10:54

HI Chris,

This means that I must insert the COMVAR.C, when I want make a change, rebuild and than remove it form the project and rebuild :?:

That is not comfortable.

Br,
Rainer

Chris

Chris

| 28.08.2008 | 11:45

Hi Rainer,

Rainer Versteeg wrote:
This means that I must insert the COMVAR.C, when I want make a change, rebuild and than remove it form the project and rebuild :?:

That is not comfortable.


I agree, this would not be comfortable. But I think it is also not necessary. :)

Your last errormessage (the multiple definition, see below) shows that the COMVAR file is already part of your Project and will be compiled and linked. It's just another mixture of upper/lowercase. The windows filesystem does not care about this, "COMVAR.o" and "Comvar.o" will access the same file. The linker treats these as different files. It's a linux tool, remember?

./Output/COMVAR.o:(.bss+0x0): multiple definition of `DOREAL'
.\Output\Comvar.o:(.bss+0x0): first defined here

This means:
1) Do not add "COMVAR" to your project. It is already there. It will be compiled and linked if you change it.
2) Use "Comvar.o" in the ".backupram" section (please see my last post)

Rainer Versteeg

Rainer Versteeg

| 28.08.2008 | 12:10

HI Chris,

It was the wrong backlash .\output is right ./output is wrong.

That was not my fault :!: :roll:

You have told that:

Quote:

Once this part is running we will proceed to the bootable image

What I have to do next :?:

Br,
Rainer

Rainer Versteeg

Rainer Versteeg

| 28.08.2008 | 16:02

HI Chris,

I have another problem. The Vars are now in BackupRam, but there are always overwritten through the COMVAR.C

Declaration of my VARS "COMVAR.h"

float DOREAL;
float SCHUET,ERNENN;

Definition of my VARS "COMVAR.C"

float	DOREAL=0;	
float	SCHUET=0;		
float	ERNENN=0;		

The definition of the VARS are written direct in the BackupRAM and overwrite the old values.

I want that the VARS are in Backupram and that the values are the same after RESET, but there are overwritten through the COMVAR.C definition. Is that possible :?:

Br,
Rainer

Chris

Chris

| 08.09.2008 | 11:09

Hi Rainer,

Quote:

Declaration of my VARS "COMVAR.h"

float DOREAL;
float SCHUET,ERNENN;

I would suggest to declare the variables as "extern". Without this attribute the compiler might create another instance:
extern float DOREAL;
extern float SCHUET,ERNENN;

Quote:

The definition of the VARS are written direct in the BackupRAM and overwrite the old values.

I want that the VARS are in Backupram and that the values are the same after RESET, but there are overwritten through the COMVAR.C definition. Is that possible :?:

I guess you want the following behaviour: a blank backup area should be initialized with the values from COMVAR.C, but if there are already valid values, they should not be overwritten.

1) do not init the values by default -> remove the "= 0" in COMVAR.C:

float   DOREAL;
float   SCHUET;
float   ERNENN;

2) Select a suitable way to distinguish a blank backup area from valid values. This could be a cookie like 0x12345678 in the backup ram. If the cookie is not present, the default values are set.

3) Add the cookie to COMVAR.C

float   DOREAL;
float   SCHUET;
float   ERNENN;
unsigned long ulBackupArea_Cookie;

4) Now use this init code before the action starts:

if( ulBackupArea_Cookie!=0x12345678 )
{
    DOREAL = 0;
    SCHUET = 0;
    ERNENN = 0;
    ulBackupArea_Cookie = 0x12345678;
}

Rainer Versteeg

Rainer Versteeg

| 08.09.2008 | 16:12

HI Chris,

1. Change Variables in "extern":

extern float DOREAL;
erxtern float SCHUET,ERNENN;

O.K.

2. do not init the values by default->rmove the "=0" in COMVAR.c:

float DOREAL;
float SCHUET;
..

When I do this in rebuild my project the VARS are in SDRAM at 0x8004xxx.
When I init my VARS with DOREAL=0 and rebuld the VARS are in BACKUPRAM at 0x003xxxx.

What does the init method have to do ?

Br,
Rainer

M T

M T

Hilscher Gesellschaft für Systemautomation mbH

| 09.09.2008 | 07:30

Rainer Versteeg wrote:
When I do this in rebuild my project the VARS are in SDRAM at 0x8004xxx.
When I init my VARS with DOREAL=0 and rebuld the VARS are in BACKUPRAM at 0x003xxxx.

A look at the .map file would help here.

It has something to do with the placement of sections. You defined that .bss and .data of comvar.o should be placed in backup ram (".\Output\Comvar.o(.bss .data*)"). An object file consists of different sections:

.text contains code
.rodata contains constants
.data contains pre-initialized global/static variables, that are different from 0
.bss contains zero-initialized global/static variables
.COMMON contains uninitialized data.

And now it's time to learn a little GNU ld and modify your linker script. (see GNU LD Documentation)

Rainer Versteeg wrote:

What does the init method have to do ?

The linker/compiler does not know anything about the consistency of your backup RAM. So it can either never initialize the variables or always reinitialize the variables. But what you want, is to initialize the area once (or in case of an error) and keep it untouched on the following runs.

So it is up to you to define a custom behavior. And this is what your Init routine should do.

Regards

MT

Rainer Versteeg

Rainer Versteeg

| 09.09.2008 | 11:42

Hell MT,

The VARS are all uninitialized.

I have defined the VARS in BACKUPRAM with

SECTIONS
{
 
	.backupram :
        {	
         .\Output\NVVAR.o *(.data)  
        } >BACKUPRAM

My VARS are at address 0x0030xxxx. Thats O.K.

Now i change my VARS with HITOP to $FF. Restart HITOP and excute my program. The VARS are all $00 :!:

What is wrong in the definition ? I have tested it also with (.COMMON)

BR,
Rainer

Chris

Chris

| 10.09.2008 | 10:43

Hi Rainer,

I forgot the ".COMMON" part, sorry! Thanks MT!

Quote:
Now i change my VARS with HITOP to $FF. Restart HITOP and excute my program. The VARS are all $00 :!:

Have you already implemented the init routine from my last post (the one with the ulBackupArea_Cookie)?

Are you using a standard development board? If not: Are your RTC power pins and the power_fail signal connected?

Rainer Versteeg

Rainer Versteeg

| 10.09.2008 | 10:57

HI Chris,

Yes i have implemented your init routine. That is for the test not necessary.

The board is O.K. I have tested it.
I have written data in the backupram and disconnect at from the 24 V.

volatile unsigned char* BACKUPRAM = (volatile unsigned char*)0x00300000;
BACKUPRAM[0]=0x12;

After restart the written backupram is the same.

 volatile unsigned char* BACKUPRAM = (volatile unsigned char*)0x00300000;
 unsigned char value;

value=BACKUPRAM[0];

The value is 0x12.

I think that the configuration in the *.ld is not correct.
Do you have a small project that is really running ?

Br,
Rainer

M T

M T

Hilscher Gesellschaft für Systemautomation mbH

| 10.09.2008 | 14:06

Strange. It is all working correctly here on a NXDB500-SYS. I've attached my C modules and the LD file. I don't have a HiTop Project as I don't use this "Wanna-Be-IDE". The InitGnu.s is the standard unmodified version, delivered with the rcX and Low Level examples.

NOTE: The application runs in the internal RAM of the netX.

main.c

#include "backupram.h"

int main(void)
{
int i;

if(g_tBackupRam.ulCookie != BACKUPRAM_VALID_COOKIE)
{
/* Backup RAM not initialized, so initialize variables now */
g_tBackupRam.ulCookie = BACKUPRAM_VALID_COOKIE;
for(i = 0; i < sizeof(g_tBackupRam.abData); ++i)
{
g_tBackupRam.abData[i] = (unsigned char)i;
}
} else
{
/* Backup RAM seems to be valid, now verify content */
for(i = 0; i < sizeof(g_tBackupRam.abData); ++i)
{
if(g_tBackupRam.abData[i] != (unsigned char)i)
{
/* Verify error */
while(1) ;
}
}
}

while(1) ;

return 0;
}

backupram.h

#ifndef __BACKUPRAM__H
#define __BACKUPRAM__H

typedef struct BACKUPRAM_DATA_Ttag
{
unsigned long ulCookie;
unsigned char abData[1024];

} BACKUPRAM_DATA_T,*PBACKUPRAM_DATA_T;

extern BACKUPRAM_DATA_T g_tBackupRam;

#define BACKUPRAM_VALID_COOKIE 0x12345678UL

#endif /* __BACKUPRAM__H */

backupram.c

#include "backupram.h"

BACKUPRAM_DATA_T g_tBackupRam;

netx.ld

/* Memory definitions */
MEMORY
{
        INTRAM(rwx)             : ORIGIN = 0x00000000,  LENGTH = 128K
        BACKUPRAM(rwx)          : ORIGIN = 0x00300000,  LENGTH = 16K
}

/* Section Definitions */
SECTIONS
{

.backupram (NOLOAD):
{
*backupram.o(.data COMMON .bss)

} >BACKUPRAM

/* system vectors reserved area */
.system 0x00000000 :
{
. = . + 0x80;
} >INTRAM

.stacks (NOLOAD):
{
. = . + 0x4000;
PROVIDE (top_of_stacks = .);
} >INTRAM

/* code section */
.sec0 :
{
*(.init_code)
*(.text)

*(.glue_7t) *(.glue_7)

/* .rodata section which is used for read-only data (constants) */
*(.rodata*)

. = ALIGN(4);

_etext = . ;
PROVIDE (etext = .);
} >INTRAM

/* .data section which is used for initialized data */
.data :
{
_data = . ;

*(.data)
SORT(CONSTRUCTORS)
} >INTRAM

/* .bss section which is used for uninitialized data */
.bss :
{
. = ALIGN(4);

__bss_start__ = . ;

*(.bss)

/* uninitialized data, see "Using LD, the GNU linker",
"Section Placement":
Specify where in your output file to place uninitialized
data with this notation. *(COMMON) by itself refers to all
uninitialized data from all input files (so far as it is
not yet allocated); */
*(COMMON)

/* align the end of the section to 32bit boundary */
. = ALIGN(4);

__bss_end__ = . ;
} >INTRAM

. = ALIGN(4);
_edata = . ;
PROVIDE (edata = .);

/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
}

Regards

MT

Rainer Versteeg

Rainer Versteeg

| 10.09.2008 | 15:52

Hi MT,

Which IDE do you use ?

How can i download your project over bootwizard ?

Br,
Rainer

M T

M T

Hilscher Gesellschaft für Systemautomation mbH

| 10.09.2008 | 16:27

I am using command line tools for compilation. As "IDE" i am using Ultraedit.

You will need to make a HiTop Project and build the attached sources, as usual.

Regards

MT

Rainer Versteeg

Rainer Versteeg

| 11.09.2008 | 09:59

Hi MT,

Thank you for the detailed information. Now it is working fine. :lol:

Do you know how HITOP create the filemap with the addresses of the variables.

My first variable in COMVAR.c is DOREAL, but the first Variable in BACKUPRAM is not DOREAL.

Which algorithm HITOP use ?

BR,
Rainer

Chris

Chris

| 11.09.2008 | 11:56

Hi Rainer,

Quote:
Do you know how HITOP create the filemap with the addresses of the variables.

It's the compiler. Hitop is just the IDE (editor and some fancy buttons) and executes the arm-hitex-elf-gcc.

Quote:
My first variable in COMVAR.c is DOREAL, but the first Variable in BACKUPRAM is not DOREAL.

Which algorithm HITOP use ?


The GCC has some very clever algorithm to decide this stuff. I don't know how it comes to this placement, but you can use a structure to enforce a specific order. Please see MT's example for details.

Login