• AVR Freaks

Helpful ReplyCustom Linker Script Section

Author
weehau
Starting Member
  • Total Posts : 49
  • Reward points : 0
  • Joined: 2010/03/28 02:10:50
  • Location: 0
  • Status: offline
2019/08/24 06:39:39 (permalink)
0

Custom Linker Script Section

Hello,
 
I have a problem here with linker script modification. My MCU part number is PIC32MZ2048EFG100.
I have a large constant array in a file name res.c. The declaration of the constant is as follow:
const unsigned char res[] = {......}
The res[] array is the binary image of webpages generated by a third-party utility program.
 
Right now, i want to move the res[] to the program flash memory starting at 0x9D100000. I know the following declaration in res.c will work:
 
const unsigned char __attribute__((address(0x9D100000),keep)) res[]
 
However, this requires me to change the utility program which is written in C#. I want to do the changes in linker script instead. So instead of declaring the res[] with __attribute, i want to modify the linker script to place the res[] starting at 0x9D100000.
 
These are lines i have added to my linker script (app_mz.ld):
MEMORY
{
    kseg1_boot_mem : ORIGIN = 0x9D000000, LENGTH = 0x480
    kseg0_program_mem (rx) : ORIGIN = 0x9D000000 + 0x480, LENGTH = 0x100000 - 0x480
    kseg0_boot_mem : ORIGIN = 0x9D000000, LENGTH = 0x0
    webpage_bin_mem : ORIGIN = 0x9D100000, LENGTH = 0xFC000
    app_setting_mem : ORIGIN = 0x9D1FC000, LENGTH = 0x4000
  kseg0_data_mem (w!x) : ORIGIN = 0x80000000, LENGTH = 0x80000
  sfrs : ORIGIN = 0xBF800000, LENGTH = 0x100000
  kseg2_ebi_data_mem : ORIGIN = 0xC0000000, LENGTH = 0x4000000
  kseg2_sqi_data_mem : ORIGIN = 0xD0000000, LENGTH = 0x4000000
  kseg3_ebi_data_mem : ORIGIN = 0xE0000000, LENGTH = 0x4000000
  kseg3_sqi_data_mem : ORIGIN = 0xF0000000, LENGTH = 0x4000000
}

 
In the memory regions, i have added a webpage_bin_mem region starting at 0x9D100000.
And then in the SECTIONS i have added a new output section named web. And place the res.o in the webpage_bin_mem region.
 
.web: 
{
    res.o
} > webpage_bin_mem

 
When compiled, there were errors returned by the linker:
pic32m-ld.exe:app_mz.ld.00:202: syntax error
collect2.exe: error: ld returned 255 exit status
 
Can someone shed some light here what's my mistakes?
post edited by weehau - 2019/08/24 06:47:57
#1
jdeguire
Super Member
  • Total Posts : 471
  • Reward points : 0
  • Joined: 2012/01/13 07:48:44
  • Location: United States
  • Status: offline
Re: Custom Linker Script Section 2019/08/26 10:52:10 (permalink) ☄ Helpfulby weehau 2019/08/27 17:59:28
0
Hmmm...I'm not sure how sticking whole object files into output sections works.  What I generally do is create a section such as ".web_bin" and then use the section attribute to locate the array or whatever in there.
 
/* In the linker script */
.web:
{
    _webpage_bin_mem_begin = .;
    KEEP(*(.web_bin))
    _webpage_bin_mem_end = .;
} > webpage_bin_mem
 
/* In your C code. */
const unsigned char __attribute__((section(".web_bin"))) res[];

 
#2
Jump to:
© 2019 APG vNext Commercial Version 4.5