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.

Binary file generation in CCSV6 GNU Compiler

Other Parts Discussed in Thread: EK-TM4C1294XL, UNIFLASH, SYSBIOS

Hi All,


I need binary file to load the TM4C129 Controller using LM Flash player. I need the build steps (commands) to generate the binary file while compiling the project with GNU Compiler.

Regards,


M Srinivas.

  • Hello Srinivas,

    The GCC application is arm-none-eabi-objcopy.exe to convert the obj file to bin file. Please do check the options.

    Regards
    Amit
  • Hi Amit,

    Thanks for the reply.

    This are the commands in CCS Build -> steps -> post-build steps for TI Compiler "${CCE_INSTALL_ROOT}/utils/tiobj2bin/tiobj2bin" "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin" "${CG_TOOL_ROOT}/bin/armofd" "${CG_TOOL_ROOT}/bin/armhex" "${CCE_INSTALL_ROOT}/utils/tiobj2bin/mkhex4bin" to generate binary file.

    I want the similar option for GNU Compiler. Kindly reply in detail as i am new to it.

    Regards,
    M Srinivas
  • Hello Srinivas

    Now, I do not know what options you want to specify. I used the command along with the name of the input file and output bin file and it generated the bin file.

    Regards
    Amit
  • Hi Amit,

    Can you give me more details (like where i have to give command). I am using CCSV6 in windows.

    Regards,
    M Srinivas
  • Hello Srinivas,

    The same place as CCS Build -> Steps -> Post Build Step

    Regards
    Amit
  • Hi Amit,

    It is converting 771KB .out file into 512MB .bin file. Binary file should be less than 50KB. This is my command "C:\ti\ccsv6\tools\compiler\gcc-arm-none-eabi-4_8-2014q3\bin\arm-none-eabi-objcopy.exe" -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin". Can you correct the command

    Regards,
    M Srinivas
  • Hello Srinivas,

    OK. Can you remove it from the post build steps and instead enable the same in GNU Objcopy Utility when you go to the properties for the project. I did the same for a hello project which has 100KB out file and generates a 14KB bin file. The compile logs show up as

    'Invoking: GNU Objcopy Utility'
    "D:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_8-2014q3/bin/arm-none-eabi-objcopy.exe" -O binary "hello.out" "hello.bin"
    'Finished building: hello.bin'
    ' '

    Regards
    Amit
  • ...-objcopy -S -O binary ....

  • Hi Petrei,

    Can you give complete command and its properties location

    Regards,
    M Srinivas
  • Hi,

    Your command is almost completely, the only missing switch is -S, which strips all debug and relocation info.

  • Hello Petrei,

    Having -S would not cause the image to bloat up so drastically!!!

    Regards
    Amit
  • Srinivas Mula said:
    It is converting 771KB .out file into 512MB .bin file. Binary file should be less than 50KB.

    On a TM4C device flash starts at address 0x00000000 and SRAM starts at address 0x20000000 which is a 512MB difference.

    If the .bin file is 512MB the probably reason is that the program contains loadable sections in both flash and SRAM, where as for a program to boot from flash (and generate a small .bin file) all loadable sections need to be in flash.

    For the GNU compiler this is controlled by the .lds Linker script. Can you show the .lds file for your project.

    [For information, see https://e2e.ti.com/support/development_tools/compiler/f/343/t/472718 for a similar problem of getting a 512MB .bin file when using the TI ARM compiler]

  • Hello Chester,

    Good post. But there must be an option in the Linker as well for GCC.

    Regards
    Amit
  • Amit Ashara said:
    But there must be an option in the Linker as well for GCC.

    Looking at the options for the arm-none-eabi-ld in the gcc-arm-none-eabi-4_8-2014q3 tool chain in CCS 6.1.1 I can't see the equivalent of the --rom_model and --ram_model options in the TI ARM linker.

    The TI ARM code generation tools integrate the Initialization Model options in the linker (--ram_model / --rom_model) with the run time support library start-up code.

    Whereas with the GNU compiler that is left to the linker script file and device specific run-time start-up code. In CCS 6.1.1 when a new project is created for a TM4C device the default linker script and the ResetISR code in the default *_startup_css_gcc.c source file effectively support the same as the --ram_model option in the TI ARM compiler, in that the data segement initializers are stored in flash and copied to SRAM during start up which results in a small .bin file being generated.

  • Srinivas Mula said:
    It is converting 771KB .out file into 512MB .bin file. Binary file should be less than 50KB. This is my command "C:\ti\ccsv6\tools\compiler\gcc-arm-none-eabi-4_8-2014q3\bin\arm-none-eabi-objcopy.exe" -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin".

    If you post the following that should provide information on why the .bin file is 512MB:

    1) The .lds linker script file from the project.

    2) The .map file generated by the linker.

    3) The output from running the following command, which shows the loadable sections in the generated .out file:

    C:\ti\ccsv6\tools\compiler\gcc-arm-none-eabi-4_8-2014q3\bin\arm-none-eabi-objdump.exe -h <.out file>

  • Hello Chester,

    I tried reproducing by changing the LENGTH of Flash for the 512MB region. However even without the -S option, the file size of the binary does not go up. I guess you are right, that we need to see the LD file.

    Regards
    Amit
  • Hi Petrei,

    Even after adding -S, still iam getting 512MB binary file. This is my command "C:\ti\ccsv6\tools\compiler\gcc-arm-none-eabi-4_8-2014q3\bin\arm-none-eabi-objcopy.exe" -S -O binary  "file.out" "file.bin". LDS file is attached.

    Regards,

    M Srinivas

    DK_TM4C129X.lds.txt
    /******************************************************************************
     *
     * Default Linker script for the Texas Instruments TM4C129XNCZAD
     *
     * This is derived from revision 12623 of the TivaWare Library.
     *
     *****************************************************************************/
    
    MEMORY
    {
        FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x00100000
        SRAM (WX)  : ORIGIN = 0x20000000, LENGTH = 0x00040000
    }
    
    REGION_ALIAS("REGION_TEXT", FLASH);
    REGION_ALIAS("REGION_BSS", SRAM);
    REGION_ALIAS("REGION_DATA", SRAM);
    REGION_ALIAS("REGION_STACK", SRAM);
    REGION_ALIAS("REGION_HEAP", SRAM);
    REGION_ALIAS("REGION_ARM_EXIDX", FLASH);
    REGION_ALIAS("REGION_ARM_EXTAB", FLASH);
    
    SECTIONS {
    
        PROVIDE (_intvecs_base_address =
            DEFINED(_intvecs_base_address) ? _intvecs_base_address : 0x0);
    
        .intvecs (_intvecs_base_address) : AT (_intvecs_base_address) {
            KEEP (*(.intvecs))
        } > REGION_TEXT
    
        PROVIDE (_vtable_base_address =
            DEFINED(_vtable_base_address) ? _vtable_base_address : 0x20000000);
    
        .vtable (_vtable_base_address) : AT (_vtable_base_address) {
            KEEP (*(.vtable))
        } > REGION_DATA
    
        .text : {
            CREATE_OBJECT_SYMBOLS
            *(.text)
            *(.text.*)
            . = ALIGN(0x4);
            KEEP (*(.ctors))
            . = ALIGN(0x4);
            KEEP (*(.dtors))
            . = ALIGN(0x4);
            __init_array_start = .;
            KEEP (*(.init_array*))
            __init_array_end = .;
            *(.init)
            *(.fini*)
        } > REGION_TEXT AT> REGION_TEXT
    
        PROVIDE (__etext = .);
        PROVIDE (_etext = .);
        PROVIDE (etext = .);
    
        .rodata : {
            *(.rodata)
            *(.rodata*)
        } > REGION_TEXT AT> REGION_TEXT
    
        .data : ALIGN (4) {
            __data_load__ = LOADADDR (.data);
            __data_start__ = .;
            *(.data)
            *(.data*)
            . = ALIGN (4);
            __data_end__ = .;
        } > REGION_DATA AT> REGION_TEXT
    
        .ARM.exidx : {
            __exidx_start = .;
            *(.ARM.exidx* .gnu.linkonce.armexidx.*)
            __exidx_end = .;
        } > REGION_ARM_EXIDX AT> REGION_ARM_EXIDX
    
        .ARM.extab : {
            *(.ARM.extab* .gnu.linkonce.armextab.*)
        } > REGION_ARM_EXTAB AT> REGION_ARM_EXTAB
    
        .bss : {
            __bss_start__ = .;
            *(.shbss)
            *(.bss)
            *(.bss.*)
            *(COMMON)
            . = ALIGN (4);
            __bss_end__ = .;
        } > REGION_BSS AT> REGION_BSS
    
        .heap : {
            __heap_start__ = .;
            end = __heap_start__;
            _end = end;
            __end = end;
            KEEP(*(.heap))
            __heap_end__ = .;
            __HeapLimit = __heap_end__;
        } > REGION_HEAP AT> REGION_HEAP
    
        .stack (NOLOAD) : ALIGN(0x8) {
            _stack = .;
            __stack = .;
            KEEP(*(.stack))
        } > REGION_STACK AT> REGION_STACK
    }
    

  • Hi,

    Looks like your .ld file is too crowded and a little bit disorganised, with some errors. How big is your file.out? depending on your program, if bigger than several MB, then you have a problem.

    I have attached a .zip file, containing two linker files. Use first  the tm4c...ld.txt (remove the .txt extension) - and if correctly .bin file, then that is. For your info, it is possible to use a modified version of TI's .cmd file - like I have done with uart-echo.ld file. 

    If still big generated .bin file, then is possible to be something wrong with your computer - try first to re-install the GNU package then if the same result, then you may have some viruses/rootkits (if WSEK-GNU-ICDI.zip

    you observe same other unusual bigger files on your computer)

  • Hi Petrei,

    file.out is 771KB. Still iam getting 512MB.

    Regards,
    M Srinivas
  • Hello Srinivas

    Can you please share either the project?

    Regards
    Amit
  • Hi Amit,

    Project attached.

    Sample.7z

    Regards,

    M Srinivas

  • Srinivas Mula said:
    Project attached.

    Running objdump on the .out file shows the problem is caused by the loadable .vtable section, which has both a VMA and LMA in flash:

    c:\ti_ccs6_0\ccsv6\tools\compiler\gcc-arm-none-eabi-4_7-2013q3\bin\arm-none-eabi-objdump.exe -h Sample.out
    
    Sample.out:     file format elf32-littlearm
    
    Sections:
    Idx Name          Size      VMA       LMA       File off  Algn
      0 .intvecs      0000003c  00000000  00000000  00008000  2**2
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
      1 .vtable       00000360  20000000  20000000  00018000  2**2
                      CONTENTS, ALLOC, LOAD, DATA
      2 .text         00004510  00000040  00000040  00008040  2**4
                      CONTENTS, ALLOC, LOAD, READONLY, CODE
      3 .c_int00      00000044  00004550  00004550  0000c550  2**2
                      CONTENTS, ALLOC, LOAD, READONLY, CODE
      4 .rodata       000006cc  00004594  00004594  0000c594  2**2
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
      5 .data         0000076c  20000360  00004c60  00010360  2**3
                      CONTENTS, ALLOC, LOAD, DATA
      6 .bss          00000a54  20000ad0  20000ad0  00018360  2**3
                      ALLOC
      7 .stack        00000200  20001528  20001528  00018360  2**3
                      ALLOC
      8 xdc.meta      000000d0  000053cc  000053cc  00018360  2**2
                      CONTENTS, READONLY
      9 .debug_info   00040717  00000000  00000000  00018430  2**0
                      CONTENTS, READONLY, DEBUGGING
     10 .debug_abbrev 00006afb  00000000  00000000  00058b47  2**0
                      CONTENTS, READONLY, DEBUGGING
     11 .debug_aranges 00001fa0  00000000  00000000  0005f648  2**3
                      CONTENTS, READONLY, DEBUGGING
     12 .debug_ranges 00003390  00000000  00000000  000615e8  2**0
                      CONTENTS, READONLY, DEBUGGING
     13 .debug_line   00014c05  00000000  00000000  00064978  2**0
                      CONTENTS, READONLY, DEBUGGING
     14 .debug_str    000211d9  00000000  00000000  0007957d  2**0
                      CONTENTS, READONLY, DEBUGGING
     15 .comment      000000e0  00000000  00000000  0009a756  2**0
                      CONTENTS, READONLY
     16 .ARM.attributes 00000039  00000000  00000000  0009a836  2**0
                      CONTENTS, READONLY
     17 .debug_frame  00005c88  00000000  00000000  0009a870  2**2
                      CONTENTS, READONLY, DEBUGGING
     18 .debug_loc    0000b875  00000000  00000000  000a04f8  2**0
                      CONTENTS, READONLY, DEBUGGING
    

    As this is a TI-RTOS project, I don't think the DK_TM4C129X.lds linker script in the project gets used. Will try and find out how to fix this problem for a TI-RTOS project.

  • Hi Chester,

    Any Update.

    Regards,
    M Srinivas
  • Hello Srinivas,

    I have asked the same question on the TI RTOS forum

    e2e.ti.com/.../476307

    Regards
    Amit
  • Hello Srinivas,

    The issue has been now resolved. Please see the TI RTOS thread for details.

    Regards
    Amit
  • Hi,

    Thanks Ashish and Amit.

    Amit can you share the information regarding advantages and limitations of TI and GNU compiler (License, code versions, code limitations, migrations etc., ).

    Regards,
    M Srinivas
  • Hi Amit,

    Binary is generating, but it is not executing.

    Regards,
    M Srinivas
  • Hello Srinivas,

    OK. First of all does the out file execute when loaded from CCS?

    Regards
    Amit
  • Srinivas Mula said:
    Binary is generating, but it is not executing.

    To try and investigate I performed the following steps:

    1) Imported your posted Sample project into CCS 6.1.1.00022, with compiler GNU v4.8.4 and TI-RTOS for TivaC v2.14.0.10

    2) Modified the DK_TM4C129X.lds linker script to set NOLOAD on the .vtable section:

        .vtable (_vtable_base_address) (NOLOAD) : {
            KEEP (*(.vtable))
        } > REGION_DATA
    

    3) In the DK_TM4C129X source file, changed the gpioPinConfigs array to match the Output pins connected to LEDs on a EK-TM4C1294XL.

    I only performed this step as have a EK-TM4C1294XL LaunchPad and not a DK-TM4C129X Development Kit.

    4) Compiled the project, and the generated .bin file size was 21444 bytes.

    5) Used CCS to load the program into the EK-TM4C1294XL, and checked that it ran correctly in that the user LED was flashing.

    6) Used Uniflash v3.4 to erase the EK-TM4C1294XL flash, and then power-cycled. Checked that this had erased the program loaded by CCS, in that the user LED was no longer flashing.

    7) Use Uniflash v3.4 to program the .bin file into the EK-TM4C1294XL flash, and then power cycled. The program was running correctly in that the user LED was flashing.

    Therefore, I can't repeat the failure (albeit using a different board).

    As Amit has already suggested, checking if the program runs when loaded from CCS would be a good next step to investigate the cause of the problem.

  • Chester Gillon said:
    To try and investigate I performed the following steps:

    Hello Chester

    We really appreciate the added step you have taken to help the forum poster.

    Regards

    Amit

  • Hi Chester,

    with .out file it is executing fine, with binary it is not executing. This is my command "C:\ti\ccsv6\tools\compiler\gcc-arm-none-eabi-4_8-2014q3\bin\arm-none-eabi-objcopy.exe" -O binary "Sample.out" "Sample.bin". I have modified .vtable. Is there any other build steps to be enabled or modified. My project is already attached in forum. Can you modify the attached project and attach again?

    Regards,
    M Srinivas
  • Hello Srinivas

    Did you check the Fault Status register to see if the application has encountered a bus fault?

    Regards
    Amit
  • Srinivas Mula said:
    I have modified .vtable. Is there any other build steps to be enabled or modified.

    In my previous test, I didn't have to modify any other build step.
    Srinivas Mula said:
    Can you modify the attached project and attach again?
    I may not be able to do that until Friday, as the PC I am currently using doesn't have the correct software installed to compile the project.

    Srinivas Mula said:
    Is there any other build steps to be enabled or modified.

    Can you just confirm under the CCS Project Properties -> RTSC which XDCtools version and which TI-RTOS for TivaC is in use. If you hover the mouse over the versions, does CCS display a warning about the version in the project not being used?

  • Srinivas Mula said:
    with .out file it is executing fine

    Can you confirm that after loading the .out file from the CCS debugger, if you stop the CCS debug session and then power-cycle or reset the board does the program still execute correctly?

    Wanted to check if not having the debugger connected stops the program from starting.

  • Hello Chester,

    Exactly. Some times the rerun of the peripherals with a CPU reset may not enable a peripheral that is by default disabled and enabled in a previous run. Kind of a stale hardware cache

    Regards
    Amit
  • Hi Chester,

    XDCtools version is 3.31.1.33_core and TI RTOS is 2.14.0.10. It is not executing .out file when debugger is removed.

    Regards,
    M Srinivas
  • Hello Srinivas,

    Did you connect the debugger to failing code w/o loading the code and checking for the data we had earlier requested for?

    Regards
    Amit
  • Hi Amit,

    If i simply connect without debugger then .out file also not executing.

    Regards,
    M Srinivas
  • Hello Srinivas,

    I will rephrase. Once you load the out file and the code does not execute, you can still connect the debugger w/o having to load the code.

    For this create a new target configuration file (ccxml file) and then launch the same and right click after launching to connect to the CPU. Then you may load the out file as Symbols and see where the code is stuck.

    Regards
    Amit
  • Hi Amit,

    Here is the debugg message-

    Stellaris In-Circuit Debug Interface/CORTEX_M4_0 (Suspended - HW Breakpoint)
    main() at main.c:75 0x000003D0
    startupC() at startup.c:79 0x0000733E
    0x00008AA6 (no symbols are defined for 0x00008AA6)
    Regards,
    M Srinivas
  • Hello Srinivas,

    Now you can load the symbols by Load Symbols (and select the out file). That will let you see the symbols.

    Also while the debugger is connected, please do check the NVIC_FAULTSTAT and NVIC_FAULTADDR registers at 0xE000ED28 and 0xE000ED38 respectively.

    Regards
    Amit
  • Hi Amit,

    Screen shot attached

    Regards,

    M Srinivas

  • Hello Srinivas

    The Target is not connected as you can see in the message

    Regards
    Amit
  • Hi Srinivas,

    Srinivas Mula said:

    Hi Chester,

    XDCtools version is 3.31.1.33_core and TI RTOS is 2.14.0.10. It is not executing .out file when debugger is removed.

    Regards,
    M Srinivas

    If you have semi-hosting enabled, then the application will not work with the debugger removed. Please disable semi-hosting and rebuild the app.

    Here's the link to a wiki page on this topic:

    http://processors.wiki.ti.com/index.php/TI-RTOS_Examples_SemiHosting

    Hope this helps.

    Best,

    Ashish

  • Thanks Ashish,

    These are the final steps do be done for GCC binary creation and standalone execution
    1) In CCS Build -> steps -> "C:\ti\ccsv6\tools\compiler\gcc-arm-none-eabi-4_8-2014q3\bin\arm-none-eabi-objcopy.exe" -O binary "project.out" "project.bin"
    2) In GNU Linker -> Libraries -> Libraries -> "nosys" should present
    3) In project.cfg (cfg Script), following should disable
    /*if (Program.build.target.$name.match(/gnu/)) {
    var SemiHost = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport'); */

    Regards,
    M Srinivas