Unable to relocate my code to new ROM section

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unable to relocate my code to new ROM section

591 Views
akhilprasad
Contributor III

I am using MPC5606S controller and code warrior IDE 5.90.

I am trying to relocated my code in a separate section mycode_flash. Memory modification is as follows:

 

/***********************Linker file ********************************/

MEMORY
{
boot_flash: org = 0x00000000, len = 0x00010000
interrupts_flash: org = 0x00010000, len = 0x00010000
internal_flash: org = 0x00020000, len = 0x00010000
mycode_flash: org = 0x00021000, len = 0x00010000
internal_ram: org = 0x40000000, len = 0x00007C00
stack_ram: org = 0x40007C00, len = 0x0400
}

 

Then I created a new section .mycode and mapped it to mycode_flash as below.

 

SECTIONS
{
.boot LOAD (0x00000000) : {} > boot_flash /* LOAD (0x0) prevents relocation by ROM copy during startup */

GROUP : { /* Note: _e_ prefix enables load after END of that specified section */
.ivor_branch_table (VLECODE) LOAD (ADDR(interrupts_flash)) : {}
.intc_hw_branch_table (VLECODE) LOAD (_e_ivor_branch_table) ALIGN (0x800) : {}
.ivor_handlers (VLECODE) LOAD (_e_intc_hw_branch_table) : {} /* Each MPC555x handler require 16B alignmt */
} > interrupts_flash


GROUP : {
.intc_sw_isr_vector_table ALIGN (2048) : {} /* For INTC in SW Vector Mode */

.text_vle (VLECODE) : {
*(.text)
*(.text_vle)
*(.fini)
*(.eini)
}
.init : {}
.init_vle (VLECODE) : {
*(.init)
*(.init_vle)
}
.ctors : {}
.dtors : {}
.rodata (CONST) : {
*(.rdata)
*(.rodata)
}
.sdata2 : {}
extab : {}
extabindex : {}

} > internal_flash

GROUP : {
.mycode (VLECODE) LOAD (0x00021000) ALIGN (0x1000) : {
*(.mycode)
}
} > mycode_flash

 

GROUP : {
.data (DATA) : {}
.sdata (DATA) : {}
.sbss (BSS) : {}
.bss (BSS) : {}
.PPC.EMB.sdata0 : {}
.PPC.EMB.sbss0 : {}
} > internal_ram
}

/***********************************************************************************/

 

Then I have called a function fun () from main and the description of fun is given below.

 

#pragma section RW ".mycode" code_mode=far_abs

__declspec(section ".mycode") extern int8_t fun(int8_t a);
int8_t fun(int8_t a)
{

a=0;
a=a+1;
return a;
}

 

MAP file has correct mapping as follows


Memory map:
                  Starting       Size             File             ROM          RAM Buffer    S-Record
                  address                         Offset             Address       Address          Line
.mycode    00021000    0000000c 00001000    00021000    00021000 87

 

 

.mycode section layout
Starting Virtual File
address Size address offset
---------------------------------
00000000 00000c 00021000 00001000 1 .mycode main.o
00000000 00000c 00021000 00001000 2 fun main.o

 

 

/***************************************************************************************************/

- But after loading the code to eval board, the code is breaking and going to an unknown location. By taking Disassemble of main I could find function fun is starting from  address "00000000".

/**************************Disassemble******************************************/

==> .symtab

[ 26] 241 00000000 12 GLOB FUNC 0 .mycode fun
[ 27] 245 00000238 78 GLOB FUNC 0 .text main
[ 28] 250 000000b3 17 GLOB OBJ 0 .debug_info .dwarf.i

**********************************************************************

; 83:
; 84: #pragma section RW ".mycode" code_mode=far_abs
; 85: // __declspec(section ".manjush")
; 86:
; 87: __declspec(section ".mycode") extern int8_t fun(int8_t a);
; 88: int8_t fun(int8_t a)
; 89: {
; 90:
; 91: a=0;
00000000: 4803 se_li r3,0
; 92: a=a+1;
; 93: return a;
00000002: 1C030001 e_add16i r0,r3,1
00000006: 7C030774 extsb r3,r0
; 94: }
0000000A: 0004 se_blr

/******************************************************************************/

- I am not getting correct value in variable 'a' during debugging as the code is 

- Did I make any mistake in linker file ? if so can someone please guide me to solve this issue.

Labels (1)
0 Kudos
1 Reply

434 Views
martin_kovar
NXP Employee
NXP Employee

Hello,

the only possible issue I see in your code is memory partitioning. Your flash section begins at 0x00020000 and it has length 0x00010000. So mycode_flash should begin at 0x00030000.

What data do you expect this function should return? This function will always return 1, no matter what is the value of the parameter.

Regards,

Martin

0 Kudos