python-intelhex / intelhex

Python IntelHex library
BSD 3-Clause "New" or "Revised" License
198 stars 106 forks source link

Option to insert 'Extended Segment Address' record type instead of 'Extended Linear Address' #40

Open fernandez85 opened 4 years ago

fernandez85 commented 4 years ago

Hello, my issue might be considered more as improvement. So I don't know if this is the right place. I've observed that when You want to use write_hex_file, then You cannot decide which type of Extend Address record type will be used in hex file:

Always second one will be used (0x04) and it cannot be changed as far I can see. The code responsible while cur_addr <= maxaddr: if need_offset_record: bin = array('B', asbytes('\0'*7)) bin[0] = 2 # reclen bin[1] = 0 # offset msb bin[2] = 0 # offset lsb bin[3] = 4 # rectyp I know that having that record type (0x04) shouldn't be a problem for most cases, but I have to deal with some legacy software. I run into problems when this record is not 0x02. Is there any chance to add an option for 'write_to_hex' to have possibility to have functionality tp force using Extended Segment Address record types in output file. In particular scenario when You initialize IntelHex with file that contains this kind of records, writing this with 'write_hex_file' (without changing any byte of payload) will result with differences comparing to original.

I can try to create a pull request with changes by myself, but I'm not very experienced Python programmer. I do Embedded (mostly C), but I starting to use Python more and more, especially for tooling.

bialix commented 4 years ago

IIRC this record should be selected based on starting address type. But I see what you mean, and this is valid request. For pull request we need a corresponding unit test, please. You can ask for tips and some help with writing a patch.

bialix commented 4 years ago

BTW, do you have starting address record in your file?

fernandez85 commented 4 years ago

No, I don't use it in my project. I have only "bare" data. So there is only Data and Extend Address records (and End of File record of course). In matter of fact I have to delete Starting Address info in some cases. I need to integrate some hex files (which have that record included) into one. But this is not a problem. BTW, maybe I'm missing something, but I don't see any connection between Starting Address and Extend Address records. Only that both can be "Segment" or "Linear", but this is just a type/mode of addressing.

bialix commented 4 years ago

Only that both can be "Segment" or "Linear", but this is just a type/mode of addressing.

Well, that is. But you can probably expect to get only one type of addressing to be using in one document. I don't think mix of two is a good idea. It's counterintuituive for me. Anyway, start address type could be used only to guess the mode, but in your case it's better to be able to override the mode aand set the desired one.

bialix commented 4 years ago

I need to integrate some hex files (which have that record included) into one.

That's why I've added merge feature. I hope it works for you.

fernandez85 commented 4 years ago

Well, that is. But you can probably expect to get only one type of addressing to be using in one document. I don't think mix of two is a good idea. It's counterintuituive for me.

For me it is always good idea to have one type of addressing for simple consistency reasons. But believe me, there are tools that do the really crazy stuff on output. Then it is expected that Your software will support that. And on the end You have to struggle with this ;)

Anyway, start address type could be used only to guess the mode, but in your case it's better to be able to override the mode aand set the desired one.

I have a solution in mind to cope all the scenarios. I will present this as soon the change will be ready.

That's why I've added merge feature. I hope it works for you.

I know I can use it, but I just use 'fromFile'. I don't have manipulate the data (besides deleting Starting Address info data, but this I do right after loading the data). Just open and load, so for me this is simpler than calling the constructor (which opens and loads data inside) and then merge. Unless 'merge' has some extra features that would change my mind ;)