4
votes

I am using gcc to create an hex file por a pic32 microcontroller and I need to place the configuration words at special memory addresses in the program flash.

I am using this simple linker script:

MEMORY {
    boot_flash :    ORIGIN = 0x1FC00000, LENGTH = 0xBF0
    sfr :           ORIGIN = 0x1F800000, LENGTH = 0x100000
    program_flash : ORIGIN = 0x1D000000, LENGTH = 0x20000
    ram :           ORIGIN = 0x00000000, LENGTH = 0x8000
    config0       : ORIGIN = 0xBFC02FFC, LENGTH = 0x4
    config1       : ORIGIN = 0xBFC02FF8, LENGTH = 0x4
    config2       : ORIGIN = 0xBFC02FF4, LENGTH = 0x4
    config3       : ORIGIN = 0xBFC02FF0, LENGTH = 0x4
}

SECTIONS {
    .text : {
        *( .text )
    } >boot_flash
    .text : {
        *(.text)
    } >program_flash
    .bss : {
        *( .bss )
    } >ram
    .data : {
        *( .data )
    } >ram

    .config0 : {
        *( .config0 )
    } >config0
    .config1 : {
        *( .config1 )
    } >config1
    .config2 : {
        *( .config2 )
    } >config2
    .config3 : {
        *( .config3 )
    } >config3
}

Then, I compile this simple code:

...
uint32_t config0 __attribute__ ((section(".config0"))) = 0xFFFFFFFF;
uint32_t config1 __attribute__ ((section(".config1"))) = 0xFFFFAF0F;
uint32_t config2 __attribute__ ((section(".config2"))) = 0xFFFFFDFF;
uint32_t config3 __attribute__ ((section(".config3"))) = 0xFFFFFDFF;
...

An finally I check with mips-elf-objdump the resulting ELF file. The code and the data are ok but there are no .config sections in the output ELF.

What am I doing wrong?

2

2 Answers

1
votes

The code is ok. The problem was on mips-elf-objdump: I was using it with the -d option that does not show me the other ELF sections :-/

Sorry and thanks you your help! :-)

0
votes

Try adding some code somewhere in the app to reference the config items, like this:

volatile uint32_t dummy;
dummy = config0;
dummy = config1;
dummy = config2;
dummy = config3;

You may find that the linker has been discarding them because they're not referenced - you can tell the linker not to discard unused symbols, but I have had problems with recent versions with sections being discarded regardless.