1

Problem description:

I have two binary files(lets call them file A and B). File A is the kernel and file B is the application to be run on(yes it is an embedded operative system). With file A i need to fill the gap from the end of the kernel to the program start which starts at address 0x00020000.

And then from 0x00020000 + program length i need to fill the gap to 0x00080000.

I tried looking into arm-none-eabi-objcopy gap fill with no luck.(contiki uses it)

I basically have two questions. How do i know when to start the padding from file A to 0x00080000 and obviously how to do the padding.

If something was not clear please let me know and i will try to explain in more detail to the best of my capabilities.

Clifford
  • 88,407
  • 13
  • 85
  • 165
EmbeddedOS
  • 173
  • 6
  • 18
  • 1
    [srec_cat](http://srecord.sourceforge.net/) may be able to do this. Or just write you own custom program that will perform the basic file I/O that you want. – kkrambo Jun 07 '18 at 12:59
  • The SRecord utility suite as suggested by @kkrambo is what I would suggest. I am not sure the suggestion is worthy of an answer rather then just a comment. – Clifford Jun 07 '18 at 13:59
  • You have not shown how you have tried to use objcopy - you certainly do not use it as shown in your question. `arm-none-eabi-objcopy --gap-fill xx` followed by other arguments perhaps. But `--gap-fill` alone fills gaps _between_ sections, not between address spaces in separate files. – Clifford Jun 07 '18 at 14:09
  • For an actual binary, you can use various options to `dd` with `/dev/zero` as a source where needed. Understanding how much padding you need is a simple matter of figuring out the size of the pieces you have and doing math relative to the addresses. Though with the `dd` method you can also just start by creating a file full of zeroes and then writing the desired pieces over that at the correct offsets. – Chris Stratton Jun 12 '18 at 05:15

1 Answers1

0

To use objcopy to append padding after the last section you need to use --pad-to <address> in combination with --gap-fill <fillvalue>.

e.g.:

arm-none-eabi-objcopy --gap-fill 0x00 --pad-to 0x80000 filea.out filea_padded.out

It is necessary however that objcopy is performed on the object file rather than a raw binary. A raw binary lacks the address information and section meta-data that tells it where the gaps and end-address are.

If your "binary" is in fact a hex file (Intel or S-Record format for example), you can use the SRecord utility suite to manipulate those, as the format included address/location meta-data. You can also use this to concatenate the two files into a single image.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • Clifford, thank you for your answer but it seems like i need some changes to be done. First of all i have one binary right now. It usually contains around 25 240 bytes. I need to fill this binary with 0xff's so the binary size will be exactly 516 096 bytes. Is it still possible to use objcpy to do this? Thank you for your help – EmbeddedOS Jun 20 '18 at 13:55
  • @EmbeddedOS try it and see. I just read the documentation. I don't see the difference between your comment and your original question. – Clifford Jun 20 '18 at 14:01
  • i did try it and i cant control the size of the binary. It became over 1kb after using the command you posted – EmbeddedOS Jun 20 '18 at 23:40