Message Edited by CrasyCat on 2007-04-13 11:14 AM
Thanks for reply. I'm having difficulty with the syntax in general with the linker and as its presented in the documentation.
Note that I've also been in contact with a Freescale engineer for another defect in the linker/locator(which I believe has been reported). That is, if you include a 'const' specifier in the definition of a variable enclosed with a #pragma ...begin and #pragma ...end statements then the linker incorrectly locates the variable to RAM space rather than that specified in the section specifier of the pragma. The .xMAP file clearly shows this error. Most annoying since you'd most likely want to include a const specifier say for any variable located within FLASH space. Like a database for example that was written there and needs to be referenced on POR. Any such variables are never written to (other than through flash write routines which the compiler and linker/locator are not cognizant of) and thus the const specifier is appropriate.
The syntax of the #pragma define_section is also somewhat confusing. The doc defines as follows:
#pragma define_section sname ".istr" [.ustr] [addrmode] [accmode]Parameters
sname
Identifier for source references to this user-defined section.
istr
Section-name string for initialized data assigned to this section. Double quotes must surround this parameter value, which must begin with a period. (Also applies to uninitialized data if there is no ustr value.)
----------------------
The Section-name for istr above leads one to believe that it could be a section name as defined by the linker syntax:
SECTIONS { section_spec[, section_spec] }Parameters
section_spec
sectionName : [AT (loadAddress)] {contents}
>segmentName
sectionName
Name for the output section, such as mysection. Must start with a period.
---------
However, I've only gotten the #pragma define_section to work correctly if the istr name is another name other than the sectionName above AND appearing within the {contents}. That is confusing and misleading.
Hello
Only thing I can do here is report that back to doc team and ask for a better documentation.
On the constant stuff, did you specify R as AccessType in the corresponding define_section pragma?
R is the accessType for constant data.
I am not sure I get the point when you say "the istr name is another name other than the sectionName above AND appearing within the {contents}. "
Can you eventually give me a syntax which was not working and should have been correct according to your understanding.
I am afraid it is a little bit fuzzy for me
CrasyCat
You wrote:
On the constant stuff, did you specify R as AccessType in the corresponding define_section pragma?
R is the accessType for constant data.
Yes, I did try the R specifier in the #pragma according to the allowed syntax and it was still improperly located to RAM. The R was also specified in the MEMORY segment defining the area of flash to which I wanted that 'variable' located. But if you think about it, providing an R explicitly in the pragma as a solution when using the const specifier doesn't make much sense when the absence of the const (implying that it is indeed r/w to the compiler anyway) correctly locates the 'variable' within the segment specified to flash. That is, if it properly locates to 'static' flash when you don't explicitly state R for a variable which is defined as something other than const then why would it not work when you're even more specific as to the variable's type? A 'developer' for Freescale (another SR which I'm currently discussing) also stated the following with respect to above:
Developer looked at this issue and he considers that this is not a bug.
He states that all "const" type must go to BSS segment (RAM) no matter
if they are declared in a pragma section.
To the above I'd just have to emphatically say HUH!!??? That's one of the points of declaring something const. Compiler will thwart any direct attempts to modify the variable declared as 'const' and linker will locate variable in flash space so as not to consume precious RAM space. Static strings, look-up tables declared as const, etc. all end up in flash and are fixed-up by linker to refer in code to their flash addresses.
You wrote:
I am not sure I get the point when you say "the istr name is another name other than the sectionName above AND appearing within the {contents}. "
Can you eventually give me a syntax which was not working and should have been correct according to your understanding.
I am afraid it is a little bit fuzzy for me
I'll try to make more clear what's also fuzzy to me. The "istr" description in the pragma define_section definition states that istr is a "section-name". sectionName is referred to in the LCF syntax as a name according to the SECTIONS{section-spec[,section-spec]} where sectionName is part of the sectionName : [AT (loadAddress)] {contents}
>segmentName
syntax. So, as an example, I ought to be able to do the following:
SECTIONS
{
.my_sectionName : {} >my_MEMORY_SEGMENT
}
#pragma define_section this_matrixdb ".my_sectionName" (R)
#pragma section this_matrixdb begin
MATRIX stMatrixInNVM;
#pragma section this_matrixdb end
However, the above doesn't work and linker reports an error as follows:
_stMatrixInNVM(.my_sectionName) in file matrix.c is referenced but has not been written.
Check your linker command file.
In order to get the pragma syntax accepted by linker and located to correct MEMORY segment then I must add an additional identifier within {} brackets of .my_sectionName above as follows and refer to this as "istr" in pragma statement:
.my_sectionName :
{ *(.my_additionalsectionName)
. =ALIGN(0x10);
} > my_MEMORY_SEGMENT
So, what does the linker error mean? In the original definition of .my_sectionName it refers to the MEMORY segment my_MEMORY_SEGMENT. So why isn't this sufficient and why do I need to define the additional .my_additionalsectionName? If above is required then why does syntax of #pragma define_section refer to istr as sectionName when it means rather something defined within the {contents} LCF syntax?
jes wrote:Compiler will thwart any direct attempts to modify the variable declared as 'const' and linker will locate variable in flash space so as not to consume precious RAM space.
#pragma define_section _Flash_CFM ".Flash_CFM_Data" far_absolute R
#pragma section _Flash_CFM begin/* CFM Flash Configuration Field */
/* 0x0400 Backdoor Comparison Key - High */
u32 u32KEY_UPPER = 0x00000000;
/* 0x0404 Backdoor Comparison Key - Low */
u32 u32KEY_LOWER = 0x00000000;
/* 0x0408 Flash Protection Bytes */
u32 u32CFMPROT = 0x00000000;
/* 0x040C Flash SUPV Access Bytes */
u32 u32CFMSACC = 0x00000000;
/* 0x0410 Flash DATA Access Bytes */
u32 u32CFMDACC = 0x00000000;
/* 0x0414 Flash Security Word */
u32 u32CFMSEC = 0x00000000;#pragma section _Flash_CFM end
FORCE_ACTIVE{_u32KEY_UPPER, _u32KEY_LOWER, _u32CFMPROT, _u32CFMSACC, _u32CFMDACC, _u32CFMSEC}
...SECTIONS
{
.Flash_CFM:
{
*(.Flash_CFM_Data)
} > Flash_CFM
#pragma push /* Save the compiler’s state. */ #pragma section data_type const_type ".Flash_CFM_Data" ".Flash_CFM_Data" data_mode=far_abs/* CFM Flash Configuration Field */ /* 0x0400 Backdoor Comparison Key - High */ unsigned long u32KEY_UPPER = 0x00000000; /* 0x0404 Backdoor Comparison Key - Low */ unsigned long u32KEY_LOWER = 0x00000000; /* 0x0408 Flash Protection Bytes */ unsigned long u32CFMPROT = 0x00000000; /* 0x040C Flash SUPV Access Bytes */ unsigned long u32CFMSACC = 0x00000000; /* 0x0410 Flash DATA Access Bytes */ unsigned long u32CFMDACC = 0x00000000; /* 0x0414 Flash Security Word */ unsigned long u32CFMSEC = 0x00000000; #pragma pop /* Save the compiler’s state. */
#pragma push
#pragma section code_type ".abs.00010000" code_mode=pc_rel
void func(void)
{
}
#pragma pop
Activates or deactivates a user-defined or predefined section.#pragma section sname begin | end
The only way I've been able to get this to work is to do it in assembler. In FlashReg.s:
.export u32KEY_UPPER
.export u32KEY_LOWER
.export u32CFMPROT
.export u32CFMSACC
.export u32CFMDACC
.export u32CFMSEC.section .text
/* CFM Flash Configuration Field */u32KEY_UPPER: .long 0x00000000 /* 0x0400 Backdoor Comparison Key */
u32KEY_LOWER: .long 0x00000000 /* 0x0404 Backdoor Comparison Key */
u32CFMPROT: .long 0x00000000 /* 0x0408 Flash Protection Bytes */
u32CFMSACC: .long 0x00000000 /* 0x040C Flash SUPV Access Bytes */
u32CFMDACC: .long 0x00000000 /* 0x0410 Flash DATA Access Bytes */
u32CFMSEC: .long 0x00000000 /* 0x0414 Flash Security Word */.end
In the linker file:
FORCE_ACTIVE
{
u32KEY_UPPER, u32KEY_LOWER, u32CFMPROT, u32CFMSACC, u32CFMDACC, u32CFMSEC
}
...
SECTIONS
{
.Flash_Reg:
{
FlashReg.s (.text)
} > Flash_Reg
...
}
It really shouldn't be this difficult...
Steve.
#pragma define_section _Flash_CFM ".Flash_CFM_Data" far_absolute R#pragma explicit_zero_data on__declspec(_Flash_CFM) unsigned long _cfm[6] = {/* CFM Flash Configuration Field *//* 0x0400 Backdoor Comparison Key - High */__declspec(_Flash_CFM) u32 u32KEY_UPPER = 0x00000000;/* 0x0404 Backdoor Comparison Key - Low */__declspec(_Flash_CFM) u32 u32KEY_LOWER = 0x00000000;/* 0x0408 Flash Protection Bytes */__declspec(_Flash_CFM) u32 u32CFMPROT = 0x00000000;/* 0x040C Flash SUPV Access Bytes */__declspec(_Flash_CFM) u32 u32CFMSACC = 0x00000000;/* 0x0410 Flash DATA Access Bytes */__declspec(_Flash_CFM) u32 u32CFMDACC = 0x00000000;/* 0x0414 Flash Security Word */__declspec(_Flash_CFM) u32 u32CFMSEC = 0x00000000;
.my_sectionName : {*(.my_sectionname)} >my_MEMORY_SEGMENT