2 Replies Latest reply on Jun 16, 2019 5:21 PM by XiaoweiZ_71

    Can GCC linker generate a flat binary file?

    MiHo_2283311

      Hi,

       

      I'm developing for a 4200M-based target system, and I'm using Creator v4.2 with the ARM GCC 5.4 toolchain.

       

      Question: Is there a way to tell the linker to output a flat binary load image instead of hex and elf files?

       

      Thanks,

       

      Mike Holmes

      MPE Design Inc.

        • 1. Re: Can GCC linker generate a flat binary file?
          dafe_3707916

          Hi Mike,

           

          You can generate any binary or hex file using objcopy (arm-none-eabi-objcopy in most ARM toolchains used in embedded development).

           

          have a look at the man page for it so you see all the possibilities.

           

          To generate binaries out of elf files comming from the linker:

           

          arm-none-eabi-objcopy -S -O binary final.elf final.bin

           

          Instead of -S you may want to use -R <pattern> or -j <pattern>  to specify what sections do you not want or want included in the binary.

           

          Use --info on its own to see all the formats you can convert from and to (usually ihex, srec, binary, etc).

           

          Regards

          • 2. Re: Can GCC linker generate a flat binary file?
            XiaoweiZ_71

            I have encountered similar problem, my steps are somewhat complicated (not optimized), for reference only.

             

            GCC Compiler

            Assuming the current project name is Design01, and the Design01.elf file directory generated by the GCC compiler is

            C:\Users\xzng\Desktop\Workspace04\Design01.cydsn\CortexM0p\ARM_GCC_541\Debug

            Assuming the arm-none-eabi-objcopy utility file directory for the default GCC compiler is

            C:\Program Files (x86)\Cypress\PSoC Creator\4.2\PSoC Creator\import\gnu\arm\5.4.1\bin>

            Then you need to use the following steps to generate BIN file

             

            1 Open the DOS interface with the CMD command.

            2 Set the directory where the arm-none-eabi-objcopy tool is located to the current directory. cd C:\Program Files (x86)\Cypress\PSoC Creator\4.2\PSoC Creator\import\gnu\arm\5.4.1\bin\

            3 Enter command arm-none-eabi-objcopy -O binary C:\Users\xzng\Desktop\Workspace04\Design01.cydsn\CortexM0p\ARM_GCC_541\Debug\Design01.elf Design01.bin

            4 The generated BIN file is located in the directory C:\Users\xzng\AppData\Local\VirtualStore\Program Files (x86)\Cypress\PSoC Creator\4.2\PSoC Creator\import\gnu\arm\5.4.1\bin

             

             

            MDK Compiler

            Assuming the current project name is Design01, the Design01.elf file directory generated by the MDK compiler is

            C:\Users\xzng\Desktop\Workspace04\Design01.cydsn\CortexM0p\ARM_MDK_Generic\Debug\

            Assuming that the formelf tool file directory of the MDK compiler is C:\Keil_v5\ARM\ARMCC\bin\

            Then you need to use the following steps to generate BIN files from ELF files in DOS environment.

             

            1 Open the DOS interface with the CMD command.

            2 Set the directory where the formelf tool is located to the current directory. cd C:\Keil_v5\ARM\ARMCC\bin\

            3. Enter command fromelf --bin --output=Design01.bin C:\Users\xzng\Desktop\Workspace04\Design01.cydsn\CortexM0p\ARM_MDK_Generic\Debug\Design01.elf

            4. Enter command fromelf --bincombined --output=Design01.bin C:\Users\xzng\Desktop\Workspace04\Design01.cydsn\CortexM0p\ARM_MDK_Generic\Debug\Design01.elf

            Note: The fromelf option --bin generates one binary file for each load region of your application. if one complete binary file is needed, consider using the option --bincombined.