summaryrefslogtreecommitdiffstats
path: root/contrib/bin2intelhex
diff options
context:
space:
mode:
authorMichael Brown2005-05-17 18:44:57 +0200
committerMichael Brown2005-05-17 18:44:57 +0200
commit1097cf8685cd81f0003bd6f17d050e5174a85b90 (patch)
tree47a39f2a1e980cca43c28c4d1a6dfdf431b910b2 /contrib/bin2intelhex
parentQuickly hacked to use a buffer rather than a processor. (diff)
downloadipxe-1097cf8685cd81f0003bd6f17d050e5174a85b90.tar.gz
ipxe-1097cf8685cd81f0003bd6f17d050e5174a85b90.tar.xz
ipxe-1097cf8685cd81f0003bd6f17d050e5174a85b90.zip
Initial revision
Diffstat (limited to 'contrib/bin2intelhex')
-rw-r--r--contrib/bin2intelhex/Makefile9
-rw-r--r--contrib/bin2intelhex/bin2intelhex.c148
-rw-r--r--contrib/bin2intelhex/bin2intelhex.c.simple74
3 files changed, 231 insertions, 0 deletions
diff --git a/contrib/bin2intelhex/Makefile b/contrib/bin2intelhex/Makefile
new file mode 100644
index 00000000..74069688
--- /dev/null
+++ b/contrib/bin2intelhex/Makefile
@@ -0,0 +1,9 @@
+
+CC=gcc
+CFLAGS=-Wall -O2
+
+bin2intelhex:
+
+
+clean:
+ rm -f bin2intelhex core *.o
diff --git a/contrib/bin2intelhex/bin2intelhex.c b/contrib/bin2intelhex/bin2intelhex.c
new file mode 100644
index 00000000..75b88c15
--- /dev/null
+++ b/contrib/bin2intelhex/bin2intelhex.c
@@ -0,0 +1,148 @@
+/* name : bin2intelhex.c
+ * from : Jean Marc Lacroix <jeanmarc.lacroix@free.fr>
+ * date : 06/12/1997.
+ * abstract : Y have rewrite this program from ????? with some modifications
+ * to add :
+ * - the Intel specification.
+ * - correct a bug because my prom programmer don't understand the
+ * initial format. Y suspect a bug in the calcul of the lrc
+ * in the original program.
+ * - correct the format of printf . In the original program, it was
+ * %x, and it is in fact %X, because in the Intel Format, all the
+ * char are in upper case.
+ * - correct the lrc calculation.
+ * usage:
+ *-------
+ * this program read the standard input and put to the standard output
+ * the result of the conversion.
+ * an example of use :
+ * cat my_bin | bin2intelhex > my_bin.hex or.....
+ * bin2intelhex < my_bin > my_bin.hex
+ */
+
+
+/*
+ * $Id$
+ * $Log$
+ * Revision 1.1 2005/05/17 16:45:06 mcb30
+ * Initial revision
+ *
+ * Revision 1.9 1997/12/14 05:14:54 install
+ * - some documentation....
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+
+/* Intel Hex format specifications
+
+The 8-bit Intel Hex File Format is a printable ASCII format consisting of one
+ or more data records followed by an end of file record. Each
+record consists of one line of information. Data records may appear in any
+ order. Address and data values are represented as 2 or 4 hexadecimal
+digit values.
+
+Record Format
+:LLAAAARRDDDD......DDDDCC
+
+
+LL
+AAAA
+RR
+DD
+CC
+Length field. Number of data bytes.
+Address field. Address of first byte.
+Record type field. 00 for data and 01 for end of record.
+Data field.
+Checksum field. One's complement of length, address, record type and data
+ fields modulo 256.
+CC = LL + AAAA + RR + all DD = 0
+
+Example:
+:06010000010203040506E4
+:00000001FF
+
+The first line in the above example Intel Hex file is a data record addressed
+ at location 100H with data values 1 to 6. The second line is the end
+of file record, so that the LL field is 0
+
+*/
+
+
+typedef unsigned char t_u8;
+typedef unsigned short t_u16;
+/*
+ * the choice for the total length (16) of a line, but the specification
+ * can support an another value
+ */
+#define LL_MAX_LINE 16
+typedef struct
+{
+ t_u8 intel_lg_data;
+ t_u16 intel_adr;
+ t_u8 intel_type;
+ t_u8 intel_data [LL_MAX_LINE];
+ t_u8 intel_lrc;
+} t_one_line;
+#define INTEL_DATA_TYPE 0
+#define EXIT_OK 0
+int main (const int argc, const char ** const argv)
+{
+ t_one_line line;
+ /*
+ * init for the adress, please note that it is assume that the program begin at 0
+ */
+ line.intel_adr = 0;
+ line.intel_type = INTEL_DATA_TYPE;
+ /*
+ * read the data on the standard input
+ */
+ while ((line.intel_lg_data = read (0, &line.intel_data [0] ,LL_MAX_LINE )) > 0)
+ {
+ t_u8 i;
+ /*
+ * and now for this line, calculate the lrc.
+ */
+ line.intel_lrc = line.intel_lg_data;
+ line.intel_lrc += ((line.intel_adr >> 8) & 0xff);
+ line.intel_lrc += (line.intel_adr &0xff);
+ line.intel_lrc += line.intel_type;
+ /*
+ * the structure is ready, print it to stdout in the
+ * right format
+ */
+ (void) printf (":%02X%04X%02X",
+ line.intel_lg_data,
+ line.intel_adr,
+ line.intel_type);
+ /*
+ * edit all the data read
+ */
+ for (i=0; i<line.intel_lg_data; i++)
+ {
+ (void) printf ("%02X",
+ (line.intel_data [i] & 0xff));
+ /*
+ * add to the lrc the data print
+ */
+ line.intel_lrc +=line.intel_data [i];
+ }
+ /*
+ * edit the value of the lrc and new line for the next
+ */
+ (void) printf ("%02X\n",
+ (0x100 - line.intel_lrc) & 0xff);
+ /*
+ * prepare the new adress for the next line
+ */
+ line.intel_adr+=line.intel_lg_data;
+ }
+ /*
+ * print the last line with a length of 0 data, so that the lrc is easy to
+ * calculate (ff+01 =0)
+ */
+ printf (":00000001FF\n");
+ exit (EXIT_OK);
+}
diff --git a/contrib/bin2intelhex/bin2intelhex.c.simple b/contrib/bin2intelhex/bin2intelhex.c.simple
new file mode 100644
index 00000000..3cb279a7
--- /dev/null
+++ b/contrib/bin2intelhex/bin2intelhex.c.simple
@@ -0,0 +1,74 @@
+/*
+
+ Quick and dirty program to make intel-hex from a binary.
+
+ Written by R.E.Wolff@BitWizard.nl
+ This file is in the public domain
+
+ Typing started:
+
+ Mon Jun 16 00:24:15 MET DST 1997
+
+ programming stopped:
+
+ Mon Jun 16 00:31:27 MET DST 1997
+
+ debugging finished (2 bugs found):
+ Mon Jun 16 00:32:52 MET DST 1997
+
+---------------------------------------------------------
+
+ Doc written in timeout. Everything else in this file was done while
+ the timer was running.
+
+ I promised "Mark Kopecki" that writing the bin-to-intel-hex
+ converter would cost less than 15 minutes, and that it would be more
+ trouble to find a converter on the net than to write the converter
+ myself. I ended up spending over half an hour searching for
+ spec/converter/docs because of unreachable hosts on the internet. I
+ got a file with docs, after that it was 8 minutes.....
+
+---------------------------------------------------------
+
+*/
+
+
+#include <stdio.h>
+#include <unistd.h>
+
+/* Intel Hex format:
+
+ ll aaaa tt dd....dd cc
+
+ ll = length
+ aaaa = address
+ tt = type
+ dd....dd = data
+ cc = checksum.
+*/
+
+
+int main (int argc, char **argv)
+{
+ unsigned char buf[32];
+ int addr = 0;
+ int n,i;
+
+ while ((n = read (0, buf+4, 16)) > 0) {
+ buf[0] = n;
+ buf[1] = addr >> 8;
+ buf[2] = addr & 0xff;
+ buf[3] = 0x00;
+ buf[4+n] = 0x00;
+
+ for (i=0;i<4+n;i++)
+ buf[4+n] -= buf[i];
+ printf (":");
+ for (i=0;i<= 4+n;i++)
+ printf ("%02x", buf[i]);
+ printf ("\n");
+ addr += n;
+ }
+ printf (":0000000001ff\n");
+ exit (0);
+}