This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler: Knowing in runtime our own flash code size?

Tool/software: TI C/C++ Compiler

Hello,

I'm working on the controlcard F2837xD.

TO prepare a future Bootlader, I need to have in my code a constante which contains the total size taken by itself in the FLASH

In my case, the flash contains many section:

codestart : > BEGIN, PAGE = 0
.text : > FLASH, PAGE = 0, ALIGN(4)
.cinit : > FLASH, PAGE = 0, ALIGN(4)
.binit : > FLASH, PAGE = 0, ALIGN(4)
.pinit : > FLASH, PAGE = 0, ALIGN(4)
 
 ...
 
/* Initalized sections go in Flash */
.econst : > FLASH, PAGE = 0, ALIGN(4)
.switch : > FLASH, PAGE = 0, ALIGN(4)

.reset : > RESET, PAGE = 0, TYPE = DSECT /* not used, */

So the code should be able to copy itself in an external SPI NOR flash. Then I need to know the size of data to copy from begin of FLASH Section.

First solution will be to copy all FLASH but this is not optimal. I'm really interested by copy only the number of data really present in the µC Flash..

How know this size?

Thank

  • Unfortunately, there is not a well defined solution for this situation.  Please see if the solutions discussed in this thread are helpful.

    Thanks and regards,

    -George

  • Hello

    I read the different thread, and I made the following:

    In Linker file I define for all section located in flash, the Start, End and Size like following: (Assuming Section "BEGIN" is placed at 0x080000 Length = 2 and section "FLASH" begin at 0x80002....

    /* Allocate program areas: */
       codestart        : > BEGIN,      PAGE = 0, START(_Link_FlashCodeStartStart), SIZE(_Link_FlashCodeStartSize), END(_Link_FlashCodeStartEnd)
       .text            : > FLASH,      PAGE = 0, START(_Link_FlashTextStart),      SIZE(_Link_FlashTextSize),      END(_Link_FlashTextEnd),        ALIGN(4)
       .cinit           : > FLASH,      PAGE = 0, START(_Link_FlashCInitStart),     SIZE(_Link_FlashCInitSize),     END(_Link_FlashCInitEnd),       ALIGN(4)
       .binit           : > FLASH,      PAGE = 0, START(_Link_FlashBInitStart),     SIZE(_Link_FlashBInitSize),     END(_Link_FlashBInitEnd),       ALIGN(4)
       .pinit           : > FLASH,      PAGE = 0, START(_Link_FlashPInitStart),     SIZE(_Link_FlashPInitSize),     END(_Link_FlashPInitEnd),       ALIGN(4)
    
       /* Initalized sections go in Flash */
       .econst          : > FLASH,      PAGE = 0, START(_Link_FlashEConstStart),    SIZE(_Link_FlashEConstSize),    END(_Link_FlashEConstEnd),      ALIGN(4)
       .switch          : > FLASH,      PAGE = 0, START(_Link_FlashSwitchStart),    SIZE(_Link_FlashSwitchSize),    END(_Link_FlashSwitchEnd),      ALIGN(4)
    
       .reset           : > RESET,      PAGE = 0, TYPE = DSECT /* not used, */
    
       .TI.ramfunc      : {} LOAD = FLASH, RUN = RAMLS_D, table(BINIT), PAGE = 0, LOAD_START(_Link_FlashRamFuncStart), LOAD_SIZE(_Link_FlashRamFuncSize), LOAD_END(_Link_FlashRamFuncEnd), ALIGN(4)   
     
    

    And then at the end of linker file

    _Link_FlashTotalStart = _Link_FlashCodeStartStart;
    _Link_FlashTotalSize = _Link_FlashCodeStartSize + _Link_FlashTextSize + _Link_FlashCInitSize + _Link_FlashBInitSize + _Link_FlashPInitSize + _Link_FlashEConstSize + _Link_FlashSwitchSize + _Link_FlashRamFuncSize;

    In the c Code file:

    extern uint32_t           Link_FlashTotalStart;       /* Start address of code in flash, defined by the linker file */
    extern uint32_t           Link_FlashTotalSize;        /* Size code in flash, defined by the linker file */


  • Please note your proposed solution ignores gaps between sections.  This became a problem for the customer in the other thread.  Is it a problem for you?

    Thanks and regards,

    -George

  • I will check but I dont think I have a gap between each section.

    If There are, a solution will be to détermine the max of all section END and make the difference with the start address of the first section which is placed from 80000 tout 80002.

  • You are right,

    SO in my code I made the following compute (If later I add a Section, I must update this part of the code...):

     uint32_t LocalFlashCodeSize;
      
      /* Determine the Code size (not use the total size because it can be some gap between each section) */
      LocalFlashCodeSize = 0;
      LocalFlashCodeSize = Max(LocalFlashCodeSize, (uint32_t)&Link_FlashTextEnd);
      LocalFlashCodeSize = Max(LocalFlashCodeSize, (uint32_t)&Link_FlashCInitEnd);
      LocalFlashCodeSize = Max(LocalFlashCodeSize, (uint32_t)&Link_FlashBInitEnd);
      LocalFlashCodeSize = Max(LocalFlashCodeSize, (uint32_t)&Link_FlashPInitEnd);
      LocalFlashCodeSize = Max(LocalFlashCodeSize, (uint32_t)&Link_FlashEConstEnd);
      LocalFlashCodeSize = Max(LocalFlashCodeSize, (uint32_t)&Link_FlashSwitchEnd);
      LocalFlashCodeSize -= (uint32_t)&Link_FlashTotalStart;