7 Replies Latest reply on Sep 11, 2018 1:24 AM by david.fernandez_3707916

    [CY8CKIT-042-BLE PIONEER KIT] How to create a hex file from elf file in linux?

    raiyan.kabir_2528116

      Hi Guys,

         

      I am trying to build binary for CYBL10563-56LQX1 processor with came with came with CY8CKIT-042-BLE PIONEER KIT.

         

      I managed to generate the a make file from the PSoC Creator and use it to build the application under Ubuntu Linux.

         

      But the hex file created by the objcopy does not work. I mean the PSoC Programmer does not load.

         

      The command I used to generate the hex file is as follows:

         

      arm-none-eabi-objcopy -j .text -j .data -O ihex "$1" output/debug/bin.hex

         

      I have compared the binary produced by objcopy and cyelftool.exe with a hex editor and found that the format is completely different.

         

      Clearly the linux command is not doing the job.

         

      Anyone knows how I can generate the correct hex file for the KIT? Or may be load the objcopy hex file?

         

      Your help will be much appreciated.

         

      Thanks in advance.

        • 1. Re: [CY8CKIT-042-BLE PIONEER KIT] How to create a hex file from elf file in linux?
          raiyan.kabir_2528116

          I have converted the elf generated in linux using the cyelftool and pushed into the processor successfully. It works perfectly. I need the entire build process to work on linux. So that I can take the final hex file from Jenkins and push it to hardware. 

          • 2. Re: [CY8CKIT-042-BLE PIONEER KIT] How to create a hex file from elf file in linux?
            user_365962704

            Hi,

               

            Great to know that you got it working on Linux, here's something i found about the cyelftool usage:

               


            The CyElfTool tool is used to patch *.elf files. This is critical as many/most 3rd party tools use the *.elf file for programming devices and thus it needs to have all important information contained in it.

               

            The cyelftool inserts or updates the following sections of the post-link .elf file:

               

            .cychecksum - All devices, contains the checksum of the flash portion of the application

               

            .cyloadermeta - All devices. The tool will update the section with the bootloader checksum and size information for a bootloader project.

               


            .cymeta - All devices. The checksum field will already have the silicon ID so that the cyelftool only needs to read the value, update it with the checksum, and write it back to the .elf file

               

            .cyloadablemeta (.cyloadable1meta/.cyloadable2meta) - All devices. The linker flow will populate all but the Application Checksum, Application Entry Address, and Application Length in these sections. The tool will need to compute these missing items and insert them into the post-link .elf file.

               

             

               

            Maybe those sections are not updated by objcopy and therefore the hex file produced by objcopy wasn't correct.

               

             

               

            What tool are you using to flash the device? Seems like soon OpenOCD will have support for KitProg and all the PCoC families :)

            1 of 1 people found this helpful
            • 3. Re: [CY8CKIT-042-BLE PIONEER KIT] How to create a hex file from elf file in linux?
              user_399270343

              I have created hex files with objcopy and uploaded with J-Link program and debug probe successfully. Lately I have heard report that miniprog3 is unable to understand this file. I went through the file manually and encountered no issues against the standard. CyElfTool.exe can be run with wine on Linux nicely. It creates hex file where data line contains 64 bytes instead of 16. I saw no other major difference. Few sections of memory had littlebit different content, it may be the checksums or something like that minor to the application program. You need also the libelf.dll. BUT it is reported that miniprog3 is not accepting this either.

              • 4. Re: [CY8CKIT-042-BLE PIONEER KIT] How to create a hex file from elf file in linux?
                user_399270343

                I have figured out something. There is issue with EEPROM section starting at address 0x90200000. I had to remove this section from the hex file and miniprog3 started to program the device.

                • 5. Re: [CY8CKIT-042-BLE PIONEER KIT] How to create a hex file from elf file in linux?
                  user_399270343

                  Some more updates on this topic: read http://www.cypress.com/forum/psoc-creator-software/error-cyeeprom-data-will-not-fit-eeprom#comment-422506 about the needed changes into linker script to avoid unneccessary EEPROM section in elf and hex files. Also I had to use CyElfTool.exe from PSoCCreator v 3.3SP2 to successfully create hex file from gcc produced elf file. I had issue with v 4.1 elf tool. It complained that "Failed to generate output.hex: Flash address outside hex file range". What this might mean: only the creators of this tool would decipher.

                  • 6. Re: [CY8CKIT-042-BLE PIONEER KIT] How to create a hex file from elf file in linux?
                    jobi

                    Hi,

                       

                    I am successful in creating HEX file using cyelftool provided with PSoC Creator 4.1

                       

                       

                    Able to successfully program the dualapp.hex as well using PSoC Programmer.

                       

                    Thanks

                       

                    Jobin GT

                       

                    • 7. Re: [CY8CKIT-042-BLE PIONEER KIT] How to create a hex file from elf file in linux?
                      david.fernandez_3707916

                      Hi there,

                       

                      Following from all that has been said, I've been fiddling with several tools, and I believe I got the same result as cyelftool.exe in linux, although my current project might not be as complex as some others, but sure it willgive the relevant tips for other people to apply this to more complex projects.

                       

                      The hex file from cyelftool is just an intel hex format, but formatted to have 64 bytes in the data records, instead of the usual 16.

                       

                      Also, cyelftool seems to fill the gaps and pad with zeroes all the way up to 0x8000 (this was for a PSoC 4).

                       

                      Then it calculates a checksum for the normal sections and puts it in 0x90300000.

                       

                      Then it outputs three special sections... May be they also get checksumed in more complex projects.

                       

                      One thing I noticed, but that might be because I am using a newer ARM toochain in linux or another thing about cyelftool, is that the third dword in .cymeta is zero for me and something else after building it all with the PSoc Creator 4.2... something to look into to see where it comes from.

                       

                      So this is what I did in postbuild.sh using objcopy and srec tools:

                       

                      #!/bin/sh

                       

                      OC_BASE=arm-none-eabi-objcopy

                      OC_PATH=$(which $OC_BASE 2>/dev/null)

                      OC=${OC_PATH:-./Export/cyelftool}

                       

                      SC_BASE=srec_cat

                      SC_PATH=$(which $SC_BASE 2>/dev/null)

                      SC=${SC_PATH:-echo ${0##*/}: Cannot find srec_cat}

                       

                      # Extract normal alloc load sections.

                      $OC -j .text \

                          -j .eh_frame \

                          -j .rodata \

                          -j .data \

                          -O ihex \

                          --gap-fill 0 --pad-to 32768 \

                          "$1" "${1%.elf}"-1.ihex

                       

                      LAST_EXIT=$?

                      if [ $LAST_EXIT != 0 ]; then

                          exit $LAST_EXIT

                      fi

                       

                      # Extract special sections.

                      $OC -j .cyflashprotect \

                          -j .cymeta \

                          -j .cychipprotect \

                          --set-section-flags .cyflashprotect=alloc,load \

                          --set-section-flags .cymeta=alloc,load \

                          --set-section-flags .cychipprotect=alloc,load \

                          -O ihex \

                          "$1" "${1%.elf}-2.ihex"

                       

                      LAST_EXIT=$?

                      if [ $LAST_EXIT != 0 ]; then

                          exit $LAST_EXIT

                      fi

                       

                      # Combine all and get rid of trivial headers

                      $SC -Output_Block_Size 64 \

                          -Output_Block_Packing \

                          -ENable Optional_Address \

                          -DISable Execution_Start_Address \

                          "${1%.elf}"-1.ihex -Intel \

                          -Checksum_Positive_Big_Endian 0x90300000 2 1 \

                          "${1%.elf}"-2.ihex -Intel \

                          -Output "${1%.elf}.hex" -Intel \

                          -line-termination=crlf

                       

                      LAST_EXIT=$?

                      if [ $LAST_EXIT != 0 ]; then

                          exit $LAST_EXIT

                      fi