-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image2hex (ESPTOOL-818) #959
Conversation
👋 Hello LeZerb, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. Click to see more instructions ...
Review and merge process you can expect ...
|
Hello @LeZerb, esptool supports generating intel files! Please see the command We try not to add new commands to esptool if not absolutely needed. The proposed Do you have any specific use case where such a command is needed? |
Hello, thanks for your response. Probably I am misunderstanding your description. I do not see a way to get from an ESP image to a hex file. I do not have the elf file available (previous build that I did not correctly archive). The use case for me was that I needed to binary patch an ESP image. |
You can run:
This way you'll convert an elf file to hex like this: |
I understand that. In my use case however, I do not have the elf file to begin with. I am starting with an ESP application binary image. ESP image -> hex -> ESP image |
In that case, just skip step 1).
|
I cannot see how this would work. From what I can see in the codebase there is nothing in there that would do what I expect. When converting from the ESP image to hex I need to provide an address and then merge_bin just puts the whole binary blob at that address. What I would expect is that the segments that are defined in the ESP image are also present in the hex file. Providing an address in that case should not be necessary at all. Maybe an example is helpful. This is output from image_info Entry point: 40380250 Segment 1: len 0x82318 load 0x3c0d0020 file_offs 0x00000018 [DROM] What I would expect is that the output hex file also contains exactly those sections with the gaps inbetween. At least that is what this PR is trying to achieve. |
Hi @LeZerb,
Correct, with one small addition, merge_bin can merge binaries, shift them and also convert them to necessary format. So in your case you can provide address 0x0 which won't do any shifting. If you provide just one binary, it will also skip the merging part and you can use the last mentioned feature to just convert from raw binary file to hex format. This was suggested by Radim in one of the comments above.
Those segments of original image should be there in hex file as well. When doing just the conversion the hex file should contain exactly the same data as the binary, but in a different format. Converting back to binary should result in same data. Have you tried running command suggested by Radim and there was something missing?
For your use case it is not needed, but we are using a command that is used in a first place for merging the binaries, the conversion is just additional feature that this command can do. We are trying to avoid adding a new command in case the same can be done by adding correct arguments to already existing command. The commands that you are trying to add can be done like this:
If I don't change anything in the hex file I get exactly the same response from the image info. Btw you can even check the produced hex file directly with image_info command and verify that all segments are there at the same place. See the output below, I have used a blink example that was built for ESP32-C6, converted it with a command mentioned above and then used image_info on hex file directly. I get the same response if I run the image_info on original bin, hex, a file converted twice: bin->hex->bin:
Have you tried the commands mentioned above and you experienced any issues with them? If yes, please share more details so we can investigate, this should work. |
I think we are still not talking about the same thing. Lets say I have an ESP image file blink.bin (lets say the size would be 0x3020) with the following content Header: 0x20 bytes at @ 0x0 When I call "esptool.py --chip esp32s3 merge_bin 0x0 blink.bin --format hex --output blink.hex" I am getting a hex file that has 1 segment sized 0x3020 at offset 0. What I would expect is the hex file to not include the header at all and to define 1 segment of 0x1000 bytes at 0x10000 and 1 segment of 0x2000 bytes at offset 0x20000. The next step would then be to edit this hex file and then convert the hex file back to an ESP image including a valid header (other PR) |
Hi @LeZerb, We plan to change the current For this reason, this PR won't be accepted. but we'll keep this open until your desired functionality can be achieved with |
Hi @LeZerb, I am sorry for the late reply. I have investigated this further and we have discussed this also with our team. Unfortunately, I don't think we can implement this feature. When converting to IntelHex we need to keep the information that is stored in the header and footer of binary file. Using your approach we would lose a lot of necessary metadata when flashing the binary. There isn't any good way how we could maintain this metadata in IntelHex. It would require a lot of changes to the current approach with little or no real benefits other than hacking the binary content. The current approach is easy to maintain while also providing an advantage over raw binary files in skipping the filler bytes, which was the main goal of this feature. Because of those reasons, we have decided to keep the current implementation of IntelHex as is for now. |
This modification adds a function image2hex which will parse an image and generate an intel hex file containing all segments from the provided image.
I have tested this change with the following hardware & software combinations:
Windows 11, ESP32C3 SuperMini
I have run the esptool.py automated integration tests with this change and the above hardware:
NO TESTING