• AVR Freaks

placing object files at specific address

Author
rinke
Super Member
  • Total Posts : 187
  • Reward points : 0
  • Joined: 2003/11/07 12:35:59
  • Location: Germany
  • Status: offline
2013/09/18 06:50:37 (permalink)
0

placing object files at specific address

Hello community,
 
firstly what i am using:
dsPIC33EP512MU810
MPLAB 8.92
MPLABC30, V3.30
 
The problem:
i want to place two object files at the adress 0x0800, then have a gap until 0x1000 an place all the other code from there.
the original linker script looks like this:
  program (xr)   : ORIGIN = 0x1000,        LENGTH = 0x547FE
  auxflash (xr)  : ORIGIN = 0x7FC000,      LENGTH = 0x3FF8
  FGS            : ORIGIN = 0xF80004,      LENGTH = 0x2
with 2 sections like this
  .text :
  {
        *(.init);
        *(.user_init);
        KEEP (*(.handle));
        KEEP (*(.isr*));
        *(.libc) *(.libm) *(.libdsp);  /* keep together in this order */
        *(.lib*);
  } >program
and
  usercode :
  {
        *(usercode);
  } >program

What i tried is to define another region (boot) like this:
  boot (xr)         : ORIGIN = 0x0800,        LENGTH = 0x007FE
  program (xr)   : ORIGIN = 0x1000,        LENGTH = 0x547FE
  auxflash (xr)   : ORIGIN = 0x7FC000,      LENGTH = 0x3FF8

and place my objects in it:
  bootcode 0x0800:
  {
      *(..\obj_EP\boot33E.o);
      *(..\obj_EP\memory33E.o);
  } >boot  

 
But nothing is placed at address 0x0800, reset vector and IVT are placed ok, but all the other stuff starts at 0x1000.
What am i doing wrong? The first thing will be that i didn´t understand how the linker is working and how the linker script is to be modified of course (;-)
 
 Any help in understanding linker scripts would be nice, i read the help files and the pdf, but couldn´t find a solution...
 
regards, Wolfgang
#1

9 Replies Related Threads

    shibanifa
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2010/08/13 13:21:56
    • Location: 0
    • Status: offline
    Re:placing object files at specific address 2013/09/18 10:29:22 (permalink)
    0
    You cannot map object files to output sections.
    bootcode 0x0800:
      {
          boot33E.o(*);
          memory33E.o(*);
      } >boot This will map all sections from [font="verdana, arial, helvetica, sans-serif; font-size: 10px; line-height: 2"]boot33E.o  [font="verdana, arial, helvetica, sans-serif; font-size: 10px; line-height: 2"]memory33E.o into bootcode output section.
    #2
    rinke
    Super Member
    • Total Posts : 187
    • Reward points : 0
    • Joined: 2003/11/07 12:35:59
    • Location: Germany
    • Status: offline
    Re:placing object files at specific address 2013/09/19 05:05:07 (permalink)
    0
    Great, this worked - nearly ...
     
    Now I get the message:
    Link Error: attributes for input section '.data' conflict with output section '.bootcode'
    I post the complete linker script here without the sfrs and the ivt:
     
    /*
    ** Memory Regions
    */
    MEMORY
    {
      data  (a!xr)   : ORIGIN = 0x1000,        LENGTH = 0xD000
      reset          : ORIGIN = 0x0,           LENGTH = 0x4
      ivt            : ORIGIN = 0x4,           LENGTH = 0x1FC
    /* change for bootloader:              */ 
      boot (xr)      : ORIGIN = 0x0800,        LENGTH = 0x007FE
      program (xr)   : ORIGIN = 0x1000,        LENGTH = 0x547FE
      auxflash (xr)  : ORIGIN = 0x7FC000,      LENGTH = 0x3FF8
      FGS            : ORIGIN = 0xF80004,      LENGTH = 0x2
      FOSCSEL        : ORIGIN = 0xF80006,      LENGTH = 0x2
      FOSC           : ORIGIN = 0xF80008,      LENGTH = 0x2
      FWDT           : ORIGIN = 0xF8000A,      LENGTH = 0x2
      FPOR           : ORIGIN = 0xF8000C,      LENGTH = 0x2
      FICD           : ORIGIN = 0xF8000E,      LENGTH = 0x2
      FAS            : ORIGIN = 0xF80010,      LENGTH = 0x2
      FUID0          : ORIGIN = 0xF80012,      LENGTH = 0x2
    }
    __FGS = 0xF80004;
    __FOSCSEL = 0xF80006;
    __FOSC = 0xF80008;
    __FWDT = 0xF8000A;
    __FPOR = 0xF8000C;
    __FICD = 0xF8000E;
    __FAS = 0xF80010;
    __FUID0 = 0xF80012;
    __IVT_BASE  = 0x4;
    __BOOT_BASE = 0x0800;
    __DATA_BASE = 0x1000;
    __DATA_LENGTH = 0xD000;
    __YDATA_BASE = 0x9000;
    __DMA_BASE = 0xD000;
    __DMA_END = 0xDFFF;
    __CODE_BASE = 0x7FC000; /* ??? */
    __CODE_LENGTH = 0x3FFA;

    /*
    ** ==================== Section Map ======================
    */
    SECTIONS
    {
      /*
      ** ========== Program Memory ==========
      */

      /*
      ** Reset Instruction
      */
      .reset :
      {
            SHORT(ABSOLUTE(__reset));
            SHORT(0x04);
            SHORT((ABSOLUTE(__reset) >> 16) & 0x7F);
            SHORT(0);
      } >reset

      /*
      ** Interrupt Vector Tables
      **
      ** The primary and alternate tables are loaded
      ** here, between sections .reset and .text.
      ** Vector table source code appears below.
      */
      .bootcode 0x0800:
      {
       ..\obj_EP\PDCboot33E.o(*);
       ..\obj_EP\memory33E.o(*);
      } >boot

      /* change for bootlader:
      ** User-Defined Section in Program Memory for bootloader reset vector and bootloader delay
      **
      ** note: can specify an address using
      **       the following syntax:
      **
      **       usercode 0x1234 :
      **         {
      **           *(usercode);
      **         } >program
      */
      .usercode 0x1000:
      {
      SHORT(0x01); /* Bootloader timeout in sec */
      SHORT(0x00); /* Bootloader timeout in sec */
      SHORT(ABSOLUTE(__reset));
      SHORT(0x04);
      SHORT((ABSOLUTE(__reset) >> 16) & 0x7F);
      SHORT(0);
      } >program
     
      /*
      ** User Code and Library Code
      **
      ** This section must not be assigned to __CODE_BASE,
      ** because CodeGuard(tm) sections may be located there.
      **
      ** Note that input sections *(.text) are not mapped here.
      ** The best-fit allocator locates them, so that .text
      ** may flow around PSV sections as needed.
      */
      .text :
      {
            *(.init);
            *(.user_init);
            KEEP (*(.handle));
            KEEP (*(.isr*));
            *(.libc) *(.libm) *(.libdsp);  /* keep together in this order */
            *(.lib*);
      } >program

      /*
      ** User-Defined Section in Program Memory
      **
      ** note: can specify an address using
      **       the following syntax:
      **
      **       usercode 0x1234 :
      **         {
      **           *(usercode);
      **         } >program
      */
      usercode :
      {
            *(usercode);
      } >program

      /*
      ** User-Defined Constants in Program Memory
      **
      ** For PSV type sections, the Load Memory Address (LMA)
      ** should be specified as follows:
      **
      **       userconst : AT(0x1234)
      **         {
      **           *(userconst);
      **         } >program
      **
      ** Note that mapping PSV sections in linker scripts
      ** is not generally recommended.
      **
      ** Because of page alignment restrictions, memory is
      ** often used more efficiently when PSV sections
      ** do not appear in the linker script.
      **
      ** For more information on memory allocation,
      ** please refer to chapter 10, 'Linker Processing'
      ** in the Assembler, Linker manual (DS51317).
      */

      /*
      ** Configuration Words
      */
      __FGS :
      { *(__FGS.sec)    } >FGS
      __FOSCSEL :
      { *(__FOSCSEL.sec)    } >FOSCSEL
      __FOSC :
      { *(__FOSC.sec)    } >FOSC
      __FWDT :
      { *(__FWDT.sec)    } >FWDT
      __FPOR :
      { *(__FPOR.sec)    } >FPOR
      __FICD :
      { *(__FICD.sec)    } >FICD
      __FAS :
      { *(__FAS.sec)    } >FAS
      __FUID0 :
      { *(__FUID0.sec)    } >FUID0

      /*
      ** =========== Data Memory ===========
      */

      /*
      ** ICD Debug Exec
      **
      ** This section provides optional storage for
      ** the ICD2 debugger. Define a global symbol
      ** named __ICD2RAM to enable ICD2. This section
      ** must be loaded at data address 0x800.
      */
      .icd __DATA_BASE (NOLOAD):
      {
        . += (DEFINED (__ICD2RAM) ? 0x50 : 0 );
      } > data

      /*
      ** Other sections in data memory are not explicitly mapped.
      ** Instead they are allocated according to their section
      ** attributes, which is most efficient.
      **
      ** If a specific arrangement of sections is required
      ** (other than what can be achieved using attributes)
      ** additional sections may be defined here. See chapter
      ** 10.5 in the MPLAB ASM30/LINK30 User's Guide (DS51317)
      ** for more information.
      */

      /*
      ** ========== Debug Info ==============
      */
      .comment        0 : { *(.comment) }
      /*
      ** DWARF-2
      */
      .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
      .debug_abbrev   0 : { *(.debug_abbrev) }
      .debug_line     0 : { *(.debug_line) }
      .debug_frame    0 : { *(.debug_frame) }
      .debug_str      0 : { *(.debug_str) }
      .debug_loc      0 : { *(.debug_loc) }
      .debug_macinfo  0 : { *(.debug_macinfo) }
      .debug_pubnames 0 : { *(.debug_pubnames) }
      .debug_ranges   0 : { *(.debug_ranges) }
      .debug_aranges  0 : { *(.debug_aranges) }
    } /* SECTIONS */
    /*
    ** ================= End of Section Map ================
    */

    i cannot see why the section bootcode interferes with the data section...
    And i don´t find anything about "xr" and "a!xr"...
    Any thank for any help and
    greetings from berlin,
     
    Wolfgang
     
    post edited by rinke - 2013/09/19 05:10:25
    #3
    aschen0866
    Super Member
    • Total Posts : 4587
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re:placing object files at specific address 2013/09/19 07:42:55 (permalink)
    0
    I am afraid you are on the wrong path. The idea of having a bootloader and an application together as one single project will be very difficult to work with. The first hurdle is the C startup code. Unless you write your own, I don't see a way around this. Then if your bootloader calls any library functions, how can you guarantee those libraries end up in the "boot" region? I think you are better off treating them as two independent projects. Microchip's AN1157 might be a good place to start.
    #4
    rinke
    Super Member
    • Total Posts : 187
    • Reward points : 0
    • Joined: 2003/11/07 12:35:59
    • Location: Germany
    • Status: offline
    Re:placing object files at specific address 2013/09/19 08:05:53 (permalink)
    0
    Yeah, you are right,
     
    its a mess, and the an1157 is working fine with my application.
    Nevertheless i am used from my assembler projects, that i can have the application and the bootloader in one hexfile, and would like to try my luck. But i already fail to modify the linker script because i don´t understand what happens there and the documentation is not that detailed for helping me out.
     
    regards,
     
    Wolfgang
    #5
    Neiwiertz
    Super Member
    • Total Posts : 2125
    • Reward points : 0
    • Joined: 2004/09/01 02:58:52
    • Status: offline
    Re: placing object files at specific address 2014/12/08 04:31:22 (permalink)
    0
    I also try to Relocate an ObjectFile to a predefined program region into flash, but also without "luck"
    I split the program memory into two region like this (take example from Rinke), but no code of hello.o is seen at 0x0800 it stays within program region, i try to over come to use __attribute__ ... for each function of boot.o and would like all functions into a predefined custom region within program memory flash, (At C18 lkr it is possible to this but at this gld script i am unknown )
     
    Probarly i confuse input and output sections which i readed about at DS52106A-page 150, if somebody could provide an example that would be handy thanks in advance

    boot (xr)      : ORIGIN = 0x0800,        LENGTH = 0x007FE 
      program (xr)   : ORIGIN = 0x1000,        LENGTH = 0x547FE
     
      .text :
      {
            *(.init);
            *(.user_init);
            KEEP (*(.handle));
            KEEP (*(.isr*));
            *(.libc) *(.libm) *(.libdsp);  /* keep together in this order */
            *(.lib*);
      } >program
     
      .bootcode 0x0800:
      {
         *output/hello.o(.text)
      } >boot


    Flying With --|Explorer 16|HardWare|SoftWare|-- Fav(s) Gallery Lists
    #6
    Neiwiertz
    Super Member
    • Total Posts : 2125
    • Reward points : 0
    • Joined: 2004/09/01 02:58:52
    • Status: offline
    Re: placing object files at specific address 2014/12/08 06:21:33 (permalink)
    0
    At DS50002071C-page 184 i found an example by creating a section and using the attribute section to relocate a function, this is helpfull
    but still figure how all function(s) (.text) of an certain object file could be mapped to a custom defined output section, by provide and create a custom input section description at the gld file see DS52106A-page 150 or simular

    Flying With --|Explorer 16|HardWare|SoftWare|-- Fav(s) Gallery Lists
    #7
    Neiwiertz
    Super Member
    • Total Posts : 2125
    • Reward points : 0
    • Joined: 2004/09/01 02:58:52
    • Status: offline
    Re: placing object files at specific address 2014/12/09 01:11:21 (permalink)
    0
    LD is a nice reference, along DS50002071C-page 184 and DS52106A-page 150 this will do
    .bootcode 0x0800:
    {
      output\hello.o(.text);
    } >boot


    Flying With --|Explorer 16|HardWare|SoftWare|-- Fav(s) Gallery Lists
    #8
    aodhanc
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2017/10/09 08:35:08
    • Location: 0
    • Status: offline
    Re: placing object files at specific address 2018/03/18 14:19:32 (permalink)
    0
    Trying to do something very similar, except with a library (e.g. ezbl_lib.a) instead of an output file. 
     
     
    usercode 0x100:
    {
         *(usercode);
         libraries\ezbl_integration\ezbl_lib.a(*);
    } >program
     
     
    I checked the map file afterwards, the library isn't linked where i hoped it would be, the section I created is named but is blank.

    Does anyone know if its even possible to do this?
    #9
    RISC
    Super Member
    • Total Posts : 5776
    • Reward points : 0
    • Status: offline
    Re: placing object files at specific address 2018/03/18 15:57:49 (permalink)
    0
    Hi,
    this thread is 4 years old...create your own one.
    Regards
     
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5