• AVR Freaks

Helpful ReplyHot!Linker Script Modification to place web bin in specific memory location in program flash

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:54:28 (permalink)
0

Linker Script Modification to place web bin in specific memory location in program flash

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? 

Attachment(s)

Attachments are not available: Download requirements not met
#1
andersm
Super Member
  • Total Posts : 2637
  • Reward points : 0
  • Joined: 2012/10/07 14:57:44
  • Location: 0
  • Status: offline
Re: Linker Script Modification to place web bin in specific memory location in program fla 2019/08/24 09:25:10 (permalink) ☄ Helpfulby weehau 2019/08/25 07:31:21
0
As described in the documentation, the section name must be surrounded by white space:
.web : 
{
    res.o
} > webpage_bin_mem

You can save yourself some future headaches by placing your array in a distinctly named section, to prevent unintended wildcard matches on *(.rodata).
#2
aschen0866
Super Member
  • Total Posts : 4496
  • Reward points : 0
  • Joined: 2006/01/08 22:18:32
  • Location: San Diego
  • Status: offline
Re: Linker Script Modification to place web bin in specific memory location in program fla 2019/08/24 09:29:40 (permalink) ☄ Helpfulby weehau 2019/08/25 07:49:08
0
I don't think you need to create a new region. Try this

 
.web 0x9D100000 :
{
*res.o(.rodata)
} > kseg0_program_mem
 

The .map file should report something like this

.web 0x9d100000 0xaafe8
*res.o(.rodata)
.rodata 0x9d100000 0xaafe8 build/default/production/res.o
0x9d100000 res

post edited by aschen0866 - 2019/08/24 09:31:51
#3
weehau
Starting Member
  • Total Posts : 49
  • Reward points : 0
  • Joined: 2010/03/28 02:10:50
  • Location: 0
  • Status: offline
Re: Linker Script Modification to place web bin in specific memory location in program fla 2019/08/25 07:34:13 (permalink)
0
andersm
As described in the documentation, the section name must be surrounded by white space:
.web : 
{
    res.o
} > webpage_bin_mem

You can save yourself some future headaches by placing your array in a distinctly named section, to prevent unintended wildcard matches on *(.rodata).




Hi Anderson, thanks for your reply. Adding a white space in between of section and colon solved the syntax issue. But the compiler is still complaining that it cannot find res.o
pic32m-ld.exe: cannot find res.o
 
Do u know how to solve this?
#4
weehau
Starting Member
  • Total Posts : 49
  • Reward points : 0
  • Joined: 2010/03/28 02:10:50
  • Location: 0
  • Status: offline
Re: Linker Script Modification to place web bin in specific memory location in program fla 2019/08/25 08:02:47 (permalink)
0
Hi aschen0866,
 
Thanks for your comment. Your solution works, but there is one more issue.
I want to reserve the program flash memory with address starts from 0x9D100000 to 0x9D1FFFFF for web binary only, no executable code.
 
I noticed that if i use your setting in the linker script, the linker will place subsequent .text (executable code) after the web binary. Please check the attached image.
 
For example:
Initially all .text and .rodata were placed correctly starting from 0x9D00000 until 0x9D01d5b4, then it skips and place the .web section at 0x9D100000. After .web section, it continues with .rodata and .text (starting at 0x9D1aafe8).
 
I want to keep 0x9D100000 - 0x9D1FFFFF just for web binary only.
 
Question:
1. Any reason why linker didn't fill up the empty flash area between 0x9D000000 - 0x9D100000, and place the subsequent code after .web instead?
2. how to force the linker to fill up the empty area first before placing them at the bank 2 of the program flash memory
post edited by weehau - 2019/08/25 08:36:02

Attachment(s)

Attachments are not available: Download requirements not met
#5
aschen0866
Super Member
  • Total Posts : 4496
  • Reward points : 0
  • Joined: 2006/01/08 22:18:32
  • Location: San Diego
  • Status: offline
Re: Linker Script Modification to place web bin in specific memory location in program fla 2019/08/26 10:50:17 (permalink) ☄ Helpfulby weehau 2019/08/26 18:39:48
+1 (1)
weehau
 I want to keep 0x9D100000 - 0x9D1FFFFF just for web binary only.
 

In that case, you should go back to your first approach by creating a new region called webpage_bin_mem.
 
 
weehau
Question:
1. Any reason why linker didn't fill up the empty flash area between 0x9D000000 - 0x9D100000, and place the subsequent code after .web instead?
2. how to force the linker to fill up the empty area first before placing them at the bank 2 of the program flash memory

The linker's "fill" behavior has always been a bit sketchy. I always end up using the hexmate tool provided by the MPLABX IDE to do any fill operation.
 
I tried this on a test project and it seemed to do the job

SECTIONS
{
.web :
{
*res.o(.rodata)
FILL(0xAAAA);
. = ORIGIN(webpage_bin_mem) + LENGTH(webpage_bin_mem) - 1;
} > webpage_bin_mem
}

Here is the map

.web 0x9d100000 0xfbfff
*res.o(.rodata)
.rodata 0x9d100000 0xaafe8 build/default/production/_ext/1472/res.o
0x9d100000 res
FILL mask 0xaaaa
0x9d1fbfff . = ((ORIGIN (webpage_bin_mem) + 0xfc000) - 0x1)
*fill* 0x9d1aafe8 0x51017 aaaa

 
 
#6
weehau
Starting Member
  • Total Posts : 49
  • Reward points : 0
  • Joined: 2010/03/28 02:10:50
  • Location: 0
  • Status: offline
Re: Linker Script Modification to place web bin in specific memory location in program fla 2019/08/26 18:42:14 (permalink)
0
Thanks everyone for the helpful advice! I am all right now. 
#7
Jump to:
© 2019 APG vNext Commercial Version 4.5