[PATCH 12/18] ihex: add ihex2fw tool for converting HEX files into firmware images

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-kernel@...>
Date: Saturday, May 31, 2008 - 8:07 am

Not the straight conversion to binary which objcopy can do for us, but
actually representing each record with its original {addr, length},
because some drivers need that information preserved.

Fix up 'firmware_install' to be able to build $(hostprogs-y) too.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
---
 firmware/Makefile       |   14 +++
 firmware/ihex2fw.c      |  238 +++++++++++++++++++++++++++++++++++++++++++++++
 scripts/Makefile.fwinst |    7 +-
 3 files changed, 258 insertions(+), 1 deletions(-)
 create mode 100644 firmware/ihex2fw.c

diff --git a/firmware/Makefile b/firmware/Makefile
index 4e19ac1..2583aef 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -28,6 +28,9 @@ quiet_cmd_mkdir = MKDIR   $(patsubst $(objtree)/%,%,$@)
 quiet_cmd_ihex  = IHEX    $@
       cmd_ihex  = $(OBJCOPY) -Iihex -Obinary $< $@
 
+quiet_cmd_ihex2fw  = IHEX2FW $@
+      cmd_ihex2fw  = $(objtree)/$(obj)/ihex2fw $< $@
+
 quiet_cmd_fwbin = MK_FW   $@
       cmd_fwbin = FWNAME="$(patsubst firmware/%.gen.S,%,$@)";		     \
 		  FWSTR="$(subst /,_,$(subst .,_,$(subst -,_,$(patsubst	     \
@@ -80,9 +83,18 @@ $(patsubst %,$(obj)/%.gen.S, $(fw-external-y)): %: $(wordsize_deps) \
 $(patsubst %,$(obj)/%.gen.o, $(fw-shipped-y)): %.gen.o: %
 $(patsubst %,$(obj)/%.gen.o, $(fw-external-y)): $(obj)/%.gen.o: $(fwdir)/%
 
+# .ihex is used just as a simple way to hold binary files in a source tree
+# where binaries are frowned upon. They are directly converted with objcopy.
 $(obj)/%: $(obj)/%.ihex | $(objtree)/$(obj)/$$(dir %)
 	$(call cmd,ihex)
 
+# .HEX is also Intel HEX, but where the offset and length in each record
+# is actually meaninful, because the firmware has to be loaded in a certain
+# order rather than as a single binary blob. Thus, we convert them into our
+# more compact binary representation of ihex records (<linux/ihex.h>)
+$(obj)/%.fw: $(obj)/%.HEX $(obj)/ihex2fw | $(objtree)/$(obj)/$$(dir %)
+	$(call cmd,ihex2fw)
+
 $(firmware-dirs):
 	$(call cmd,mkdir)
 
@@ -96,3 +108,5 @@ targets := $(fw-shipped-) $(patsubst $(obj)/%,%, \
 # Without this, built-in.o won't be created when it's empty, and the
 # final vmlinux link will fail.
 obj-n := dummy
+
+hostprogs-y := ihex2fw
diff --git a/firmware/ihex2fw.c b/firmware/ihex2fw.c
new file mode 100644
index 0000000..31d963c
--- /dev/null
+++ b/firmware/ihex2fw.c
@@ -0,0 +1,238 @@
+/*
+ * Parser/loader for IHEX formatted data.
+ *
+ * Copyright
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH 00/18] firmware: moving drivers to request_firmwa..., Arkadiusz Miskiewicz, (Thu Jun 5, 6:07 am)
[PATCH 18/18] whiteheat: use request_firmware(), David Woodhouse, (Fri May 30, 6:35 pm)
[PATCH 17/18] ti_usb_3410_5052: use request_firmware(), David Woodhouse, (Fri May 30, 11:49 am)
[PATCH 14/18] keyspan_pda: use request_firmware(), David Woodhouse, (Fri May 30, 8:15 am)
[PATCH 12/18] ihex: add ihex2fw tool for converting HEX file..., David Woodhouse, (Sat May 31, 8:07 am)
[PATCH 10/18] ihex.h: binary representation of ihex records, David Woodhouse, (Fri May 30, 6:57 am)
[PATCH 09/18] ttusb-budget: use request_firmware(), David Woodhouse, (Thu May 29, 12:50 pm)
[PATCH 08/18] kaweth: use request_firmware(), David Woodhouse, (Thu May 29, 10:17 am)
[PATCH 07/18] smctr: use request_firmware(), David Woodhouse, (Thu May 29, 9:39 am)
[PATCH 03/18] firmware: Add 'firmware_install' make target, David Woodhouse, (Thu May 29, 4:01 am)
[PATCH 02/18] firmware: Add CONFIG_BUILTIN_FIRMWARE option, David Woodhouse, (Fri May 23, 8:58 am)