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.

AM3358: How to remove unwanted zeros from binary file

Part Number: AM3358
Other Parts Discussed in Thread: PROCESSOR-SDK-AM335X

Hi!

I am using sitara AM3358 processor on custom board with processor_sdk_rtos_am335x_6_01_00_08. In binary file there are bunch of zeros due to this size of binary file is in MB and crossing 10MB.

Kindly suggest any solution to remove the unwanted zeros from binary file.

Regards,

Gaurav

  • Hello Gaurav,

    Please explain a little more for us. Which binary file are you talking about?

    Regards,

    Nick

  • Nick,

    I am converting project .out file into project .bin file. 

    size of .out file is around 13 MB and size of .bin file is around  8 MB.

    I am talking binary file which we flash to  NAND flash memory.

    I am attaching linker map file and .cmd file for your reference.

    Linker_Map_File.txt

    /*
    * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
    */
    /*
    *  Redistribution and use in source and binary forms, with or without
    *  modification, are permitted provided that the following conditions
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the
    *    documentation and/or other materials provided with the
    *    distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    */
    
    /****************************************************************************/
    /* LNK32.CMD - v4.5.0 COMMAND FILE FOR LINKING TMS470 32BIS C/C++ PROGRAMS  */
    /*                                                                          */
    /*   Usage:  lnk470 <obj files...>    -o <out file> -m <map file> lnk32.cmd */
    /*           cl470 <src files...> -z -o <out file> -m <map file> lnk32.cmd  */
    /*                                                                          */
    /*   Description: This file is a sample command file that can be used       */
    /*                for linking programs built with the TMS470 C/C++          */
    /*                Compiler.   Use it as a guideline; you may want to change */
    /*                the allocation scheme according to the size of your       */
    /*                program and the memory layout of your target system.      */
    /*                                                                          */
    /*   Notes: (1)   You must specify the directory in which run-time support  */
    /*                library is located.  Either add a "-i<directory>" line to */
    /*                this file, or use the system environment variable C_DIR   */
    /*                to specify a search path for libraries.                   */
    /*                                                                          */
    /*          (2)   If the run-time support library you are using is not      */
    /*                named below, be sure to use the correct name here.        */
    /*                                                                          */
    /****************************************************************************/
    -stack  0x0008                             /* SOFTWARE STACK SIZE           */
    -heap   0xFFFF                             /* HEAP AREA SIZE                */
    -e Entry
    /*  Since we used 'Entry' as the entry-point symbol the compiler issues a   */
    /*  warning (#10063-D: entry-point symbol other than "_c_int00" specified:  */
    /*  "Entry"). The CCS Version (5.1.0.08000) stops building from command     */
    /*  line when there is a warning. So this warning is suppressed with the    */
    /*  below flag. */
    
    --diag_suppress=10063
    
    /* SPECIFY THE SYSTEM MEMORY MAP */
    
    MEMORY
    {
    	SRAM:     o = 0x402F0400  l = 0x0000FC00  /* 64kB internal SRAM */
        L3OCMC0:  o = 0x40300000  l = 0x00010000  /* 64kB L3 OCMC SRAM */
        M3SHUMEM: o = 0x44D00000  l = 0x00004000  /* 16kB M3 Shared Unified Code Space */
        M3SHDMEM: o = 0x44D80000  l = 0x00002000  /* 8kB M3 Shared Data Memory */
        DDR_MEM     : org = 0x80000000  len = 0x1FFFFFFF /* RAM */ //256 MB
    }
    
    /* SPECIFY THE SECTIONS ALLOCATION INTO MEMORY */
    
    SECTIONS
    {
        .text:Entry : load > 0x80000000
    
        .text    : load > DDR_MEM              /* CODE                          */
        .data    : load > DDR_MEM              /* INITIALIZED GLOBAL AND STATIC VARIABLES */
        //.bss     : load > DDR_MEM              /* UNINITIALIZED OR ZERO INITIALIZED */
                                               /* GLOBAL & STATIC VARIABLES */
    
        .bss     : load > 0x80100000
                        RUN_START(bss_start)
                        RUN_END(bss_end)
        .const   : load > DDR_MEM              /* GLOBAL CONSTANTS              */
        .stack   : load > 0x87FFFFF0           /* SOFTWARE SYSTEM STACK         */
        .cinit         >  DDR_MEM
    
    
    
    }
    
    

    Regards,

    Gaurav

  • Please check the usage notes here for AM335x bootloader for guidance on this issue.

    https://software-dl.ti.com/processor-sdk-rtos/esd/docs/06_03_00_106/rtos/index_Foundational_Components.html#usage-notes

    The notes on heap and boot image creation should help.

  • Part Number: PROCESSOR-SDK-AM335X

    Hi!

    I have managed to reduced the size of binary file from 8MB to  1MB by memory mapping properly. There are no bunch of zeros but in between there are few zeros at irregular interval. But still it is more and it will affect the boot timing.

    Is there any further possibility to reduce the size by any kind of optimization through CCS?

    Regards

    Gaurav

  • Hi Gaurav,

    Is this a continuation of thread https://e2e.ti.com/support/processors/f/791/t/977449? If so, can you please post your question to that thread for continuity? Once you do that, I'll close this one.

  • Hi!

    I have managed to reduced the size of binary file from 8MB to  1MB by memory mapping properly. There are no bunch of zeros but in between there are few zeros at irregular interval. But still it is more and it will affect the boot timing.

    Is there any further possibility to reduce the size by any kind of optimization through CCS?

    Regards

    Gaurav

  • Yes, it is continuation of that thread.

    Please answer there.

    Regards,

    Gaurav

  • Hi Jianzhongxu,

    I have posted the question in that thread but no one has replied.

    Regards,

    Gaurav

  • Gaurav,

    As I indicated the bootloader supported with Processor SDK RTOS from starterware, can only load application binaries as a contiguous binary using the tiimage.exe boot format utility. It does not implement a ELF or a section parser and hence if there are holes in the memory map as in case of stack and heaps, the boot utilities will fill those up with zeros. 

    If you want to avoid this issue, then you will need to modify the bootloader to implement an ELF parser and migrate to using the out2rprc utility that we support for newer devices like AM57x and K2G. This is currently inot supported in the bootloader on AM335x and AM437x. The effort to support ELF parser in bootloader is a significant change impacting current customers so we currently don`t plan to back port to the AM335x/AM437x devices.

    How significant of an impact does the boot binary cause to your application boot times. Have you tried to increase the speed of the boot peripheral or choose a faster boot media if that is an option. 

    Regards,

    Rahul

    PS: This is a good reference to understand the boot image formats created using tiimage and ELF parser/out2rprc

    https://software-dl.ti.com/processor-sdk-rtos/esd/docs/06_03_00_106/rtos/index_Foundational_Components.html#id72 

  • Rahul,

    Currently, first priority is NAND and processor is booting from NAND. Required booting time is less than 3 second but it is taking 5.3 seconds due to increase in size of binary file. Is there possibility to reduce the booting time without ELF?

    I can't change the booting sequence on custom board.

    Regards,

    Gaurav

  • Gaurav,

    Couple of things to try would be, 

    1. Ensure GPMC timings used in bootloader are aggressive to meet the fast load time of the binary. 

    2. Analyze the .out and try to identify sections due to which zeros are inserted and or eliminate any wholes by keeping memory sections , code and data sections close. I am guessing, you have already eliminated stack and heap and other uninitialized sections.

    Regards,

    Rahul

  • Rahul,

    I will change GPMC timings and will let you know.

    Can I send .out file, linker map file and .cmd file in test format so that you can verify once at your end? 

    Regards,

    Gaurav

  • Rahul,

    I have optimized the GPMC timings but I didn't get much reduction in booting time. Still I have to reduce 2.5 seconds.

    Currently it is taking 5.4 seconds and my requirement is less than 2 seconds.

    Regards,

    Gaurav

  • Gaurav,

    Unfortunately, the part was not natively designed for fast boot. The only other option that I can think of is to integrate DMA to move the data from GPMC to local memory. There are other techniques discussed in the app note here:

    https://www.ti.com/tool/TIDEP0049

    Techniques discussed will also apply to AM335x.

    Regards,

    Rahul 

  • Rahul,

    Can I get example on DMA excess with GPMC? My requirement is to boot the processor from NAND only so I can't go for other boot options.

    Regards,

    Gaurav

  • Gaurav,

    It appears that on this device, you don`t have the option of using DMA with GPMC to move data from NAND flash. You can only do that with direct mapped parallel NOR flash. 

    This leaves us with only couple of options:

    1. You can analyze your output binary and split the application image into chunks of contiguous binaries to avoid loading zeros or holes in the application image.

    2. Explore option to split application into critical for fast boot and non critical for initial fast boot. Load the the fast boot section as a smaller chunk and then load the non fast boot critical section after you have taken initial action/initialization 

    This will however, require some modifications to secondary bootloader and potentially to application image.

    Regards,

    Rahul

  • Rahul,

    As I told there are no bunch of zeros in binary file but there are zeros at regular interval. Another thing is that, in linker map file under const section there are repetitively same font object file, is it correct?

    I am sending a binary file, linker map file and cmd file in text format. Could you please check at your end and let me know?

    Is there any document to get the info on splitting the application image file to speed up boot times?

    linker_map.txt

    binary_file.txt

    /*
    * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
    */
    /*
    *  Redistribution and use in source and binary forms, with or without
    *  modification, are permitted provided that the following conditions
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the
    *    documentation and/or other materials provided with the
    *    distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    */
    
    /****************************************************************************/
    /* LNK32.CMD - v4.5.0 COMMAND FILE FOR LINKING TMS470 32BIS C/C++ PROGRAMS  */
    /*                                                                          */
    /*   Usage:  lnk470 <obj files...>    -o <out file> -m <map file> lnk32.cmd */
    /*           cl470 <src files...> -z -o <out file> -m <map file> lnk32.cmd  */
    /*                                                                          */
    /*   Description: This file is a sample command file that can be used       */
    /*                for linking programs built with the TMS470 C/C++          */
    /*                Compiler.   Use it as a guideline; you may want to change */
    /*                the allocation scheme according to the size of your       */
    /*                program and the memory layout of your target system.      */
    /*                                                                          */
    /*   Notes: (1)   You must specify the directory in which run-time support  */
    /*                library is located.  Either add a "-i<directory>" line to */
    /*                this file, or use the system environment variable C_DIR   */
    /*                to specify a search path for libraries.                   */
    /*                                                                          */
    /*          (2)   If the run-time support library you are using is not      */
    /*                named below, be sure to use the correct name here.        */
    /*                                                                          */
    /****************************************************************************/
    -stack  0x0008                             /* SOFTWARE STACK SIZE           */
    -heap   0xFFFF                             /* HEAP AREA SIZE                */
    -e Entry
    /*  Since we used 'Entry' as the entry-point symbol the compiler issues a   */
    /*  warning (#10063-D: entry-point symbol other than "_c_int00" specified:  */
    /*  "Entry"). The CCS Version (5.1.0.08000) stops building from command     */
    /*  line when there is a warning. So this warning is suppressed with the    */
    /*  below flag. */
    
    --diag_suppress=10063
    
    /* SPECIFY THE SYSTEM MEMORY MAP */
    
    MEMORY
    {
    	//SRAM:     o = 0x402F0400  l = 0x0000FC00  /* 64kB internal SRAM */
    //    L3OCMC0:  o = 0x40300000  l = 0x00010000  /* 64kB L3 OCMC SRAM */
     //   M3SHUMEM: o = 0x44D00000  l = 0x00004000  /* 16kB M3 Shared Unified Code Space */
    //    M3SHDMEM: o = 0x44D80000  l = 0x00002000  /* 8kB M3 Shared Data Memory */
        DDR_MEM     : org = 0x80000000  len = 0x1FFFFFFF /* RAM */ //256 MB
    }
    
    /* SPECIFY THE SECTIONS ALLOCATION INTO MEMORY */
    
    SECTIONS
    {
        .text:Entry : load > 0x80000000
    
        .text    : load > DDR_MEM              /* CODE                          */
        .data    : load > DDR_MEM              /* INITIALIZED GLOBAL AND STATIC VARIABLES */
        //.bss     : load > DDR_MEM              /* UNINITIALIZED OR ZERO INITIALIZED */
                                               /* GLOBAL & STATIC VARIABLES */
    
        .bss     : load > 0x80200000
                        RUN_START(bss_start)
                        RUN_END(bss_end)
        .const   : load > DDR_MEM              /* GLOBAL CONSTANTS              */
        .stack   : load > 0x87FFFFF0           /* SOFTWARE SYSTEM STACK         */
        .cinit         >  DDR_MEM
    
    
    
    }
    
    

    Regards,

    Gaurav

  • Gaurav,

    I noticed that you are building the software using TI ARM toolchain. We are currently only supporting GCC compiler for AM335x. Can yo u explain why you are using TI ARM toolchain for this build. We currently only support TI ARM toolchain for ARM9 cores or MCU cores (M4, R5).. Is your code based older legacy starterware that used that tool chain? 

    Additionally, can you explain why do you have such a large .const section. If these are some kind of images that you are using with the GUI then that may be the section you want to break up and load the initial application quickly with limited .const section and then load the rest of the const section from the flash. 

    Regards,

    Rahul

  • Rahul,

    Earlier I was using GCC compiler only but I faced some issue in interrupt so I shift to TI ARM compiler.  In my application, I am drawing some graphics with arial font. There are multiple pages to draw. I used older starterware.

    I am trying to figure out regarding this large .const section. 

    Will different compiler create impact on size of binary file?

    Regards,

    Gaurav

  • Hi Gaurav,

    I will need to limit my guidance to GCC compiler as we are not currently in a position to support multiple ARM compilers for RTOS/bare-metal development for this product. Also, we have indicated on this forums that we do not support older starterware baseline for any ongoing development.

    Having said that let me respond to your question regarding the impact of the toolchain on the .const section. Change in compiler is likely to not make a difference with the .const section. You will need to find a way to compress that section or partially load that section to reduce the boot time. 

    If you do find a solution, please post your solution for the benefit of the community.

    Regards,

    Rahul