ASCII Text to I8HEX Format Converter

May 01, 2008 11 Replies

I have a large amount of text that I need to put on an EEPROM and I wa wondering if there is a program that will convert ASCII text to I8HEX Inte HEX format.



Not just ASCII to HEX, but the full properly formatted and checksumme I8HEX format, like shown here here:



formatting link



If anyone knows of a program that can do that it would help a lot.



Thanks for any suggestions.


formatting link

Converts anything to anything.

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

objcopy -I binary -O ihex input.txt output.hex

formatting link

Grant Edwards grante Yow! Gee, I feel kind of at LIGHT in the head now, visi.com knowing I can't make my satellite dish PAYMENTS!

I saw that program, but I wasn't sure how to get it to run under Windows. Thanks, I'll see if I can figure it out.

Or roll your own. All respondents suggestions were good but the time it takes you to find such a tool is probably more than the effort it would take to write it yourself.

JJS

dohzer ha scritto:

uhm, what about eeprom starting address ?

I give up. What about it?

Grant Edwards grante Yow! at BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI- visi.com

Grant Edwards ha scritto:

ehm, ASCII text file don't contain any address, HEX file records needs addresses; may be that the tool objcopy will make the good job starting with default address 0x00 ; else you should --set-start Set the start address to to match eeprom starting address.

under windows i feed filein.cod to obsend.exe (st7 tools). obsend filein.cod,f,fileout.hex,i

filein.cod = 4_byte_LH_address + 4byte_LH_lenght + ascii_file.txt

easy to make with any hex editor.

regards

The --set-start option doesn't do what you think it does. It sets the "entry point". It sets the address to which one is supposed to jump in order to start execution of the resulting image. The start address is sent using record type 0x03 and is typically located at the end of the hex file:

$ objcopy -I binary -O ihex --set-start=0x5555 asdf.txt asdf.hex $ head -n3 asdf.hex; tail -n3 asdf.hex :100000000A546865207175657374696F6E206F6638 :1000100020656D756C6174696E672061207365720F :1000200069616C20706F727420696E2075736572DF :0A02C0002D200A4772616E740A0ACD :04000003000055554F :00000001FF

If you want to relocate the output data to an address other than that of the input data [files of type "binary" have an implicit address of 0], you use the --change-addresses option:

$ objcopy -I binary -O ihex --change-addresses=0x5555 asdf.txt asdf.hex $ head -n3 asdf.hex :105555000A546865207175657374696F6E206F668E :1055650020656D756C6174696E6720612073657265 :1055750069616C20706F727420696E207573657235

note that --change-addresses also changes the start address in addition to changing the load address:

:0A5815002D200A4772616E740A0A22 :04000003000055554F :00000001FF

Grant Edwards grante Yow! My face is new, my at license is expired, and I'm visi.com under a doctor's care!!!!

Grant Edwards ha scritto:

thank you Grant , this seems to be a quite right answer to the original question from Dohzer. please explain me how to obtain these two .hex records ( "qwerty" at address 0x22 ) from ascii .txt , under windows, avoiding record type

0x03 in I8HEX : it will be useful for me too.

:060022007177657274792C :00000001FF

regards

I don't see why you are about the start record, but it's trivial to delete it:

$ echo -n qwerty >qwerty.txt $ objcopy --change-address=0x22 -I binary -O ihex qwerty.txt qwerty.hex $ sed -i '/^:04000003.*$/d' qwerty.hex $ cat qwerty.hex :060022007177657274792C :00000001FF

You can put the objcopy and sed commands in a shell script so they can be used as a "single command" if you want. If you're crippled by Windows, you can install Cygwin to get a usable shell and set of command-line utilities.

You can do the same thing with srecord, but since objcopy "comes with" the Gnu toolchain and can also manipulate ELF files, I tend to use it more often.

Grant Edwards grante Yow! Sometime in 1993 at NANCY SINATRA will lead a visi.com BLOODLESS COUP on GUAM!!

Stick in a assembly source file (qwerty.s):

.section ".rodata" .ascii "qwerty" .end

Run it through an assembler, presumably a cross assembler for your target architecture or the same byte ordering as your target (to create a .o file), a linker with a linker script to set the rodata section origin to 0x22 (to create an .elf file) and run objdump using the -Oihex option (to create the .hex file).

Petter

A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required