AnsweredAssumed Answered

Unable to relocate my code to new ROM section

Question asked by akhilprasad on Feb 8, 2017
Latest reply on Feb 9, 2017 by Martin Kovar

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.

Outcomes