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.

How to add a data into already existing section on a elf file using TI toolchain.



Hello TI team,

How can I inject data directly into .elf file by adding a new section or in a already existing one? The injected data I need to be loaded at a specific address and carry on as part of the flashed image.

I tried to used tiarmobjcopy.exe but the sections does not get as part of the loadable image.

The following instruction I used and seems to not be enough to have it added as a loadable section.

tiarmobjcopy.exe --input-target=elf32-littlearm --output-target=elf32-littlearm --add-section=.newSectionName=myData.bin,load,readonly current.elf modified.elf

Best regards,

Alexei

  • HI Alexei,

    Redirecting this query to our tool chain expert, they will respond here. 
    Meanwhile, can you please mention what is your use case here?

    Regards,
    Parth

  • Hi Path,

    The use case for which I need to update an already existing elf:
    We need to generate HASH on the readonly sections from the image and append that information as a new section which then should be recognized by out2rprc and be generated as part of the final flash image to allow us having the information in a specific RAM area loaded with the image.

    Best regards,

    Alexei

  • A remark the section I was able to add with tiarmobjcopy command listed on above but still that I miss the way to update or mark the VMA and LMA for the new added section. Something similar to objcopy from linux utilis: 

           [--change-section-lma sectionpattern{=,+,-}val]
           [--change-section-vma sectionpattern{=,+,-}val]

  • How can I inject data directly into .elf file

    I've never done that.  But I have an idea that might work.  Before I try it out, I want to see if it has any chance of solving the problem.

    We need to generate HASH on the readonly sections from the image

    I think that means you know the exact length of the data to inject.  For now, I'll guess it is 8 bytes long.  As long as it is a fixed length that is not very long, I think my idea will work.

    Create an constant array at the required address, with the required length.  Put it in a section you name.  For now, call the section hash_section.  The final value of the hash is in a file named hash_value.bin.  Then an objcopy command similar to this should work ...

    tiarmobjcopy --update-section=hash_section=hash_value.bin old_executable_file.out new_executable_file.out

    Does this seem practical?  Should I try something similar just to prove the concept?

    Thanks and regards,

    -George

  • This is what I would need, but tiarmobjcopy seems does not support --update-section? Is there available on a specific release?

  • Is there available on a specific release?

    The tiarmobjcopy option --update-section is introduced with version 2.1.0.LTS.  This means it is available with any 2.1.x.LTS or 3.2.x.LTS release.

    I tried it just to prove the concept.  It works as I expect.  Here is how I create the hash value in C ...

    __attribute__((section("hash_section")))
    const int32_t hash_value[2] = { 0, 0 };

    In the linker command file, allocate hash_section as needed, just like any other initialized section.  Use the tiarmobjcopy command from my last post.  

    Note this constraint.  The number of bytes in the hash_value array, and the number of bytes in the file hash_value.bin, must be exactly equal.

    Thanks and regards,

    -George