Index: boot/arch/mips32/loader/Makefile
===================================================================
--- boot/arch/mips32/loader/Makefile	(revision 33c058d38d41ac857965ed7cc15a2eb95d492a91)
+++ boot/arch/mips32/loader/Makefile	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
@@ -33,4 +33,12 @@
 #
 
+ifeq ($(IMAGE),binary)
+	BFD = binary
+endif
+ifeq ($(IMAGE),ecoff)
+	BFD = ecoff-littlemips
+endif
+BFD_NAME = elf32-tradlittlemips
+BFD_ARCH = mips
 TARGET = mipsel-linux-gnu
 TOOLCHAIN_DIR = /usr/local/mipsel/bin
@@ -73,4 +81,5 @@
 	main.c \
 	msim.c \
+	_components.c \
 	../../../generic/printf.c \
 	asm.S \
@@ -108,8 +117,8 @@
 
 clean:
-	-rm -f _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
+	-rm -f _components.h _components.c _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
 
-_components.h _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
-	./pack $(IMAGE) $(OBJCOPY) $(COMPONENTS)
+_components.h _components.c _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
+	../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD) $(BFD_ARCH) 4096 $(COMPONENTS)
 
 %.o: %.S
Index: boot/arch/mips32/loader/_link.ld.in
===================================================================
--- boot/arch/mips32/loader/_link.ld.in	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
+++ boot/arch/mips32/loader/_link.ld.in	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
@@ -0,0 +1,14 @@
+	.boot 0xbfc00000: AT (0) {
+		*(BOOTSTRAP);
+		*(.text);
+		
+		*(.rodata);
+		*(.rodata.*);
+		*(.data);		/* initialized data */
+		*(.sdata);
+		*(.sdata2);
+		*(.sbss);
+		*(.scommon);
+		*(.bss);		/* uninitialized static variables */	
+		*(COMMON); 		/* global variables */
+		*(.reginfo);
Index: boot/arch/mips32/loader/main.c
===================================================================
--- boot/arch/mips32/loader/main.c	(revision 33c058d38d41ac857965ed7cc15a2eb95d492a91)
+++ boot/arch/mips32/loader/main.c	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
@@ -60,6 +60,7 @@
 	
 	component_t components[COMPONENTS];
+	init_components(components);
+	
 	bootinfo_t bootinfo;
-	init_components(components);
 	
 	printf("\nMemory statistics\n");
Index: ot/arch/mips32/loader/pack
===================================================================
--- boot/arch/mips32/loader/pack	(revision 33c058d38d41ac857965ed7cc15a2eb95d492a91)
+++ 	(revision )
@@ -1,126 +1,0 @@
-#! /bin/sh
-
-#
-# Copyright (C) 2006 Martin Decky
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-[ "$#" -lt 1 ] && exit 1
-
-case "$1" in
-	"binary")
-		BFD="binary"
-		;;
-	"ecoff")
-		BFD="ecoff-littlemips"
-		;;
-	*)
-		echo "Undefined image format" >&1
-		exit 1
-		;;
-esac
-
-OBJCOPY="$2"
-LINK="_link.ld"
-HEADER="_components.h"
-
-shift 2
-
-echo "OUTPUT_FORMAT(\"${BFD}\")
-ENTRY(start)
-
-SECTIONS {
-	.boot 0xbfc00000: AT (0) {
-		*(BOOTSTRAP);
-		*(.text);
-		
-		*(.rodata);
-		*(.rodata.*);
-		*(.data);		/* initialized data */
-		*(.sdata);
-		*(.sdata2);
-		*(.sbss);
-		*(.scommon);
-		*(.bss);		/* uninitialized static variables */	
-		*(COMMON); 		/* global variables */
-		*(.reginfo);" > "$LINK"
-
-echo '#ifndef ___COMPONENTS_H__
-#define ___COMPONENTS_H__
-
-typedef struct {
-	char *name;
-	
-	void *start;
-	void *end;
-	unsigned int size;
-} component_t;' > "$HEADER"
-
-COUNT="0"
-DATA=""
-
-for TASK in "$@" ; do
-	BASENAME="`basename "$TASK" | sed 's/^\(.*\)\.[^.]*$/\1/'`"
-	OBJECT="${BASENAME}.o"
-	SYMBOL="`echo "_binary_$TASK" | tr "./" "__"`"
-	MACRO="`echo "$BASENAME" | tr [:lower:] [:upper:]`"
-	echo "$TASK -> $OBJECT"
-	
-	echo "
-		. = ALIGN(4096);
-		*(.${BASENAME}_image);" >> "$LINK"
-	
-	echo "
-extern int ${SYMBOL}_start;
-extern int ${SYMBOL}_end;
-
-#define ${MACRO}_START ((void *) &${SYMBOL}_start)
-#define ${MACRO}_END ((void *) &${SYMBOL}_end)
-#define ${MACRO}_SIZE ((unsigned int) ${MACRO}_END - (unsigned int) ${MACRO}_START)" >> "$HEADER"
-	
-	"$OBJCOPY" -I binary -O elf32-tradlittlemips -B mips --rename-section ".data=.${BASENAME}_image" "$TASK" "$OBJECT"
-		
-	DATA="${DATA}
-	components[$COUNT].name = \"${BASENAME}\";
-	components[$COUNT].start = ${MACRO}_START;
-	components[$COUNT].end = ${MACRO}_END;
-	components[$COUNT].size = ${MACRO}_SIZE;";
-	COUNT="`expr "$COUNT" + 1`"
-done
-
-echo '	}
-}' >> "$LINK"
-
-echo "
-#define COMPONENTS $COUNT
-
-static void init_components(component_t components[])
-{
-$DATA
-}
-
-#endif
-" >> "$HEADER"
Index: boot/arch/ppc32/loader/Makefile
===================================================================
--- boot/arch/ppc32/loader/Makefile	(revision 33c058d38d41ac857965ed7cc15a2eb95d492a91)
+++ boot/arch/ppc32/loader/Makefile	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
@@ -33,4 +33,7 @@
 #
 
+BFD = elf32-powerpc
+BFD_NAME = elf32-powerpc
+BFD_ARCH = powerpc:common
 TARGET = ppc-linux-gnu
 TOOLCHAIN_DIR = /usr/local/ppc/bin
@@ -73,4 +76,5 @@
 	main.c \
 	ofwarch.c \
+	_components.c \
 	../../../genarch/ofw.c \
 	../../../generic/printf.c \
@@ -109,8 +113,8 @@
 
 clean:
-	-rm -f _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
+	-rm -f _components.h _components.c _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
 
-_components.h _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
-	./pack $(OBJCOPY) $(COMPONENTS)
+_components.h _components.c _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
+	../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD) $(BFD_ARCH) 4096 $(COMPONENTS)
 
 %.o: %.S
Index: boot/arch/ppc32/loader/_link.ld.in
===================================================================
--- boot/arch/ppc32/loader/_link.ld.in	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
+++ boot/arch/ppc32/loader/_link.ld.in	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
@@ -0,0 +1,13 @@
+	.boot 0x10000000: AT (0) { 
+		*(BOOTSTRAP);
+		*(REALMODE);
+		*(.text);
+		
+		*(.rodata);
+		*(.rodata.*);
+		*(.data);		/* initialized data */
+		*(.sdata);
+		*(.sdata2);
+		*(.sbss);
+		*(.bss);		/* uninitialized static variables */	
+		*(COMMON); 		/* global variables */
Index: boot/arch/ppc32/loader/main.c
===================================================================
--- boot/arch/ppc32/loader/main.c	(revision 33c058d38d41ac857965ed7cc15a2eb95d492a91)
+++ boot/arch/ppc32/loader/main.c	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
@@ -97,8 +97,8 @@
 	version_print();
 	
-	init_components();
-	
+	component_t components[COMPONENTS];
+	init_components(components);
+		
 	unsigned int i;
-	
 	for (i = 0; i < COMPONENTS; i++)
 		check_align(components[i].start, components[i].name);
Index: ot/arch/ppc32/loader/pack
===================================================================
--- boot/arch/ppc32/loader/pack	(revision 33c058d38d41ac857965ed7cc15a2eb95d492a91)
+++ 	(revision )
@@ -1,115 +1,0 @@
-#! /bin/sh
-
-#
-# Copyright (C) 2006 Martin Decky
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-[ "$#" -lt 1 ] && exit 1
-
-OBJCOPY="$1"
-LINK="_link.ld"
-HEADER="_components.h"
-
-shift
-
-echo 'OUTPUT_FORMAT("elf32-powerpc")
-OUTPUT_ARCH(powerpc:common)
-ENTRY(start)
-
-SECTIONS {
-	.boot 0x10000000: AT (0) { 
-		*(BOOTSTRAP);
-		*(REALMODE);
-		*(.text);
-		
-		*(.rodata);
-		*(.rodata.*);
-		*(.data);		/* initialized data */
-		*(.sdata);
-		*(.sdata2);
-		*(.sbss);
-		*(.bss);		/* uninitialized static variables */	
-		*(COMMON); 		/* global variables */' > "$LINK"
-
-echo '#ifndef ___COMPONENTS_H__
-#define ___COMPONENTS_H__
-
-typedef struct {
-	char *name;
-	
-	void *start;
-	void *end;
-	unsigned int size;
-} component_t;' > "$HEADER"
-
-COUNT="0"
-DATA=""
-
-for TASK in "$@" ; do
-	BASENAME="`basename "$TASK" | sed 's/^\(.*\)\.[^.]*$/\1/'`"
-	OBJECT="${BASENAME}.o"
-	SYMBOL="`echo "_binary_$TASK" | tr "./" "__"`"
-	MACRO="`echo "$BASENAME" | tr [:lower:] [:upper:]`"
-	echo "$TASK -> $OBJECT"
-	
-	echo "
-		. = ALIGN(4096);
-		*(.${BASENAME}_image);" >> "$LINK"
-	
-	echo "
-extern int ${SYMBOL}_start;
-extern int ${SYMBOL}_end;
-
-#define ${MACRO}_START ((void *) &${SYMBOL}_start)
-#define ${MACRO}_END ((void *) &${SYMBOL}_end)
-#define ${MACRO}_SIZE ((unsigned int) ${MACRO}_END - (unsigned int) ${MACRO}_START)" >> "$HEADER"
-	
-	"$OBJCOPY" -I binary -O elf32-powerpc -B powerpc:common --rename-section ".data=.${BASENAME}_image" "$TASK" "$OBJECT"
-		
-	DATA="${DATA}
-	components[$COUNT].name = \"${BASENAME}\";
-	components[$COUNT].start = ${MACRO}_START;
-	components[$COUNT].end = ${MACRO}_END;
-	components[$COUNT].size = ${MACRO}_SIZE;";
-	COUNT="`expr "$COUNT" + 1`"
-done
-
-echo '	}
-}' >> "$LINK"
-
-echo "
-#define COMPONENTS $COUNT
-
-component_t components[COMPONENTS]; 
-
-static void init_components(void)
-{
-$DATA
-}
-
-#endif
-" >> "$HEADER"
Index: boot/arch/ppc64/loader/Makefile
===================================================================
--- boot/arch/ppc64/loader/Makefile	(revision 33c058d38d41ac857965ed7cc15a2eb95d492a91)
+++ boot/arch/ppc64/loader/Makefile	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
@@ -33,4 +33,7 @@
 #
 
+BFD = elf64-powerpc
+BFD_NAME = elf64-powerpc
+BFD_ARCH = powerpc:common64
 TARGET = ppc64-linux-gnu
 TOOLCHAIN_DIR = /usr/local/ppc64/bin
@@ -73,4 +76,5 @@
 	main.c \
 	ofwarch.c \
+	_components.c \
 	../../../genarch/ofw.c \
 	../../../generic/printf.c \
@@ -109,8 +113,8 @@
 
 clean:
-	-rm -f _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
+	-rm -f _components.h _components.c _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
 
-_components.h _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
-	./pack $(OBJCOPY) $(COMPONENTS)
+_components.h _components.c _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
+	../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD) $(BFD_ARCH) 4096 $(COMPONENTS)
 
 %.o: %.S
Index: boot/arch/ppc64/loader/_link.ld.in
===================================================================
--- boot/arch/ppc64/loader/_link.ld.in	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
+++ boot/arch/ppc64/loader/_link.ld.in	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
@@ -0,0 +1,15 @@
+	.boot 0x0000000010000000: AT (0) { 
+		*(BOOTSTRAP);
+		*(REALMODE);
+		*(.text);
+		*(.toc);
+		
+		*(.opd);
+		*(.rodata);
+		*(.rodata.*);
+		*(.data);		/* initialized data */
+		*(.sdata);
+		*(.sdata2);
+		*(.sbss);
+		*(.bss);		/* uninitialized static variables */	
+		*(COMMON); 		/* global variables */
Index: boot/arch/ppc64/loader/main.c
===================================================================
--- boot/arch/ppc64/loader/main.c	(revision 33c058d38d41ac857965ed7cc15a2eb95d492a91)
+++ boot/arch/ppc64/loader/main.c	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
@@ -97,6 +97,7 @@
 	version_print();
 	
-	init_components();
-	
+	component_t components[COMPONENTS];
+	init_components(components);
+		
 	unsigned int i;
 	
Index: ot/arch/ppc64/loader/pack
===================================================================
--- boot/arch/ppc64/loader/pack	(revision 33c058d38d41ac857965ed7cc15a2eb95d492a91)
+++ 	(revision )
@@ -1,124 +1,0 @@
-#! /bin/sh
-
-#
-# Copyright (C) 2006 Martin Decky
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-[ "$#" -lt 1 ] && exit 1
-
-OBJCOPY="$1"
-LINK="_link.ld"
-HEADER="_components.h"
-
-shift
-
-echo 'OUTPUT_FORMAT("elf64-powerpc")
-OUTPUT_ARCH(powerpc:common64)
-ENTRY(start)
-
-SECTIONS {
-	.boot 0x0000000010000000: AT (0) { 
-		*(BOOTSTRAP);
-		*(REALMODE);
-		*(.text);
-		*(.toc);
-		
-		*(.opd);
-		*(.rodata);
-		*(.rodata.*);
-		*(.data);		/* initialized data */
-		*(.sdata);
-		*(.sdata2);
-		*(.sbss);
-		*(.bss);		/* uninitialized static variables */	
-		*(COMMON); 		/* global variables */
-		
-		. = ALIGN(4096);
-		*(.kernel_image);' > "$LINK"
-
-echo '#ifndef ___COMPONENTS_H__
-#define ___COMPONENTS_H__
-
-typedef struct {
-	char *name;
-	
-	void *start;
-	void *end;
-	unsigned long size;
-} component_t;' > "$HEADER"
-
-COUNT="0"
-DATA=""
-
-for TASK in "$@" ; do
-	BASENAME="`basename "$TASK" | sed 's/^\(.*\)\.[^.]*$/\1/'`"
-	OBJECT="${BASENAME}.o"
-	SYMBOL="`echo "_binary_$TASK" | tr "./" "__"`"
-	MACRO="`echo "$BASENAME" | tr [:lower:] [:upper:]`"
-	echo "$TASK -> $OBJECT"
-	
-	echo "
-		. = ALIGN(4096);
-		*(.${BASENAME}_image);" >> "$LINK"
-	
-	echo "
-extern int ${SYMBOL}_start;
-extern int ${SYMBOL}_end;
-
-#define ${MACRO}_START ((void *) &${SYMBOL}_start)
-#define ${MACRO}_END ((void *) &${SYMBOL}_end)
-#define ${MACRO}_SIZE ((unsigned long) ${MACRO}_END - (unsigned long) ${MACRO}_START)" >> "$HEADER"
-	
-	"$OBJCOPY" -I binary -O elf64-powerpc -B powerpc:common64 --rename-section ".data=.${BASENAME}_image" "$TASK" "$OBJECT"
-		
-	DATA="${DATA}
-	components[$COUNT].name = \"${BASENAME}\";
-	components[$COUNT].start = ${MACRO}_START;
-	components[$COUNT].end = ${MACRO}_END;
-	components[$COUNT].size = ${MACRO}_SIZE;";
-	COUNT="`expr "$COUNT" + 1`"
-done
-
-echo '}
-
-	/DISCARD/ : {
-		*(*);
-	}
-}' >> "$LINK"
-
-echo "
-#define COMPONENTS $COUNT
-
-component_t components[COMPONENTS]; 
-
-static void init_components(void)
-{
-$DATA
-}
-
-#endif
-" >> "$HEADER"
Index: boot/tools/pack.py
===================================================================
--- boot/tools/pack.py	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
+++ boot/tools/pack.py	(revision e19d6679169d90e6f4384eed72d6cd3992334f1d)
@@ -0,0 +1,143 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2008 Martin Decky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+"""
+Binary package creator
+"""
+
+import sys
+import os
+import subprocess
+
+def usage(prname):
+	"Print usage syntax"
+	print prname + " <OBJCOPY> <FORMAT> <OUTPUT_FORMAT> <ARCH> <ALIGNMENT>"
+
+def main():
+	if (len(sys.argv) < 6):
+		usage(sys.argv[0])
+		return
+	
+	if (not sys.argv[5].isdigit()):
+		print "<ALIGNMENT> must be a number"
+		return
+	
+	templatename = "_link.ld.in"
+	workdir = os.getcwd()
+	objcopy = sys.argv[1]
+	format = sys.argv[2]
+	output_format = sys.argv[3]
+	arch = sys.argv[4]
+	align = int(sys.argv[5], 0)
+	
+	link = file("_link.ld", "w")
+	header = file("_components.h", "w")
+	data = file("_components.c", "w")
+	
+	link.write("OUTPUT_FORMAT(\"" + output_format + "\")\n")
+	link.write("OUTPUT_ARCH(" + arch + ")\n")
+	link.write("ENTRY(start)\n\n")
+	link.write("SECTIONS {\n")
+	
+	size = os.path.getsize(templatename)
+	rd = 0
+	template = file(templatename, "r")
+	
+	while (rd < size):
+		buf = template.read(4096)
+		link.write(buf)
+		rd += len(buf)
+	
+	template.close()
+	
+	link.write("\n")
+	
+	header.write("#ifndef ___COMPONENTS_H__\n")
+	header.write("#define ___COMPONENTS_H__\n\n")
+	
+	data.write("#include \"_components.h\"\n\n")
+	data.write("void init_components(component_t *components)\n")
+	data.write("{\n")
+	
+	cnt = 0
+	for task in sys.argv[6:]:
+		basename = os.path.basename(task)
+		plainname = os.path.splitext(basename)[0]
+		path = os.path.dirname(task)
+		object = plainname + ".o"
+		symbol = "_binary_" + basename.replace(".", "_")
+		macro = plainname.upper()
+		
+		print task + " -> " + object
+		
+		link.write("\t\t. = ALIGN(" + ("%d" % align) + ");\n")
+		link.write("\t\t*(." + plainname + "_image);\n\n")
+		
+		header.write("extern int " + symbol + "_start;\n")
+		header.write("extern int " + symbol + "_end;\n\n")
+		header.write("#define " + macro + "_START ((void *) &" + symbol + "_start)\n")
+		header.write("#define " + macro + "_END ((void *) &" + symbol + "_end)\n")
+		header.write("#define " + macro + "_SIZE ((unsigned int) " + macro + "_END - (unsigned int) " + macro + "_START)\n\n")
+		
+		data.write("\tcomponents[" + ("%d" % cnt) + "].name = \"" + plainname + "\";\n")
+		data.write("\tcomponents[" + ("%d" % cnt) + "].start = " + macro + "_START;\n")
+		data.write("\tcomponents[" + ("%d" % cnt) + "].end = " + macro + "_END;\n")
+		data.write("\tcomponents[" + ("%d" % cnt) + "].size = " + macro + "_SIZE;\n\n")
+		
+		os.chdir(path)
+		subprocess.call([objcopy,
+			"-I", "binary",
+			"-O", format,
+			"-B", arch,
+			"--rename-section", ".data=." + plainname + "_image",
+			basename, os.path.join(workdir, object)])
+		os.chdir(workdir)
+		
+		cnt = cnt + 1
+		
+	link.write("\t}\n")
+	link.write("}\n")
+	
+	header.write("#define COMPONENTS " + ("%d" % cnt) + "\n\n")
+	header.write("typedef struct {\n")
+	header.write("\tchar *name;\n\n")
+	header.write("\tvoid *start;\n")
+	header.write("\tvoid *end;\n")
+	header.write("\tunsigned int size;\n")
+	header.write("} component_t;\n\n")
+	header.write("extern void init_components(component_t *components);\n\n")
+	header.write("#endif\n")
+	
+	data.write("}\n")
+	
+	link.close()
+	header.close()
+	data.close()
+
+if __name__ == '__main__':
+	main()
