Yet Another Hex to bin converter

It can handle the extended Intel hex format in segmented and linear address
modes. Records need not be sorted and there can be gaps between records. 

Some hex files are produced by compilers. They generate objects files for each
module in a project, and when the linker generates the final hex file, the
object files are stored within the hex files, but modules can appear not
necessary in order of address.

How does it work?

It allocates a one meg buffer and just place the converted bytes in its
buffer. At the end, the buffer is written to disk. Using a buffer eliminates
the need to sort records.


1. Compiling on Linux

	make
	
	then 
	
	make install
	
	This will install the program to /usr/local/bin.
	
2. Using hex2bin

	hex2bin example.hex
	
	hex2bin will generate a binary file example.bin starting at the 
	lowest address in the hex file.
	
3. Notes

	If the lowest address isn't 0000, 
	    ex: 0100: (the first record begins with :nn010000xxx ) 
	    
	there will be problems when using the binary file to program a EPROM 
	since the first byte supposed to be at 0100 is stored in the binary file
	at 0000.

	you can specify a starting address on the command line:
		
	hex2bin -s 0000 start_at_0100.hex

		This start address is not the same thing as the start address record in
		the hex file. The start address record is used to specify the starting
		address for execution of the binary code.		

	The bytes will be stored in the binary file with a padding from 0000
	to the lowest address minus 1 (00FF in this case). Padding bytes are all FF
	so an EPROM programmer can skip these bytes when programming.

	EPROM, EEPROM and Flash memories contain all FF when erased.

	This program does minimal error checking since many hex files are
	generated by known good assemblers.

	When the source file name is 
		for-example.test.hex
	the binary created will have the name 
		for-example.bin
	the ".test" part will be dropped.

4. Checksum

	By default, it ignores checksum errors, so that someone can change
	by hand some bytes allowing quick and dirty changes.
	If you want checksum error reporting, specify the option -c.

	hex2bin -c example.hex

	If there is a checksum error somewhere, the program will continue the
	conversion anyway.
	
	The example file example.hex contains some records with checksum errors.

5. Motorola S files
	
	mot2bin example.s19

	Options for mot2bin are the same as hex2bin. Executing the program
	without argument will display available options.

	This program will handle S19 files generated for Motorola micropro-
	cessors. Since I use this program for an EPROM programmer, I will 
	rarely need to have more than 1 Meg, I limited the source program for
	24 bits or 16 bits address records.
	
	32 bits records are now supported, but obviously I can't allocate all
	the memory for the binary target. What I did is simply assume that the
	binary file will occupy less than 1 Meg

6. Compiling on DOS

	I didn't check this, but it should be relatively easy. The only problem
	may be to allocate a 1 Meg memory block. On recent DOS c compilers
	this should not be a problem anymore.

7. Goodies

	Description of the file formats is included.
	Added examples files for extended addressing.

8. Error messages

	"Data record skipped at ..."
	
	This means that the records are falling outside my 1M buffer. You may 
	try to increase the buffer size to 2M or 4M. There is a define at the
	beginning of the file.

9. History

        See ChangeLog

10. To do
	Maybe do a library for accessing files, I often need this.
	Change the code for putting an extension.
	Add an option for changing the buffer size for other than 1 Meg.
	Formatting and programming with GNU standards.

Finally, if you have any idea about hex tools that I could do, or anything
that may improve my programs,

send me an email at
	jpellet@ieee.org
