Index: boot/Makefile
===================================================================
--- boot/Makefile	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/Makefile	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -27,26 +27,12 @@
 #
 
-.PHONY: all build_dist build_comps clean_dist clean
+.PHONY: all build_dist clean_dist clean
 
 include Makefile.common
 
-all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(PREBUILD)
+all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(PREBUILD) build_dist
 	$(MAKE) -r -f $(BUILD) PRECHECK=$(PRECHECK)
 ifneq ($(POSTBUILD),)
 	$(MAKE) -r -f $(POSTBUILD) PRECHECK=$(PRECHECK)
-endif
-
-build_comps: $(COMPONENTS) $(LINK).in
-	$(PACK) $(OBJCOPY) $(BFD_NAME) $(BFD_ARCH) arch/$(KARCH) $(COMPONENTS)
-
-$(INITRD).img: build_dist
-ifeq ($(RDFMT),tmpfs)
-	$(MKTMPFS) $(DIST_PATH) $@
-endif
-ifeq ($(RDFMT),fat)
-	$(MKFAT) 1048576 $(DIST_PATH) $@
-endif
-ifeq ($(RDFMT),ext4fs)
-	$(MKEXT4) 1048576 $(DIST_PATH) $@
 endif
 
@@ -132,10 +118,9 @@
 	$(MAKE) -r -f $(POSTBUILD) clean PRECHECK=$(PRECHECK)
 endif
-	rm -fr $(SANDBOX)
 	rm -f $(POST_OUTPUT) $(BOOT_OUTPUT) $(DEPEND) $(DEPEND_PREV) arch/*/include/common.h
 	find generic/src/ arch/*/src/ genarch/src/ -name '*.o' -follow -exec rm \{\} \;
 
 clean_dist:
-	rm -f $(INITRD).img $(COMPS_H) $(COMPS_C) $(LINK) $(LINK).comp *.co
+	rm -f $(INITRD).img $(COMPS).s $(COMPS).h $(COMPS)_desc.c $(COMPS).o $(COMPS)_desc.o $(COMPS).zip $(LINK)
 	find $(USPACE_PATH)/dist -mindepth 1 -maxdepth 1 -type f -exec rm \{\} \;
 	rm -f $(USPACE_PATH)/dist/srv/*
Index: boot/Makefile.build
===================================================================
--- boot/Makefile.build	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/Makefile.build	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -94,5 +94,4 @@
 
 OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
-COMPONENT_OBJECTS := $(addsuffix .co,$(basename $(MODULES)))
 
 all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(BOOT_OUTPUT)
@@ -102,14 +101,16 @@
 	rm -f $(RAW) $(MAP) $(ARCH_INCLUDE) $(GENARCH_INCLUDE)
 
+ifneq ($(MAKECMDGOALS),clean)
 -include $(DEPEND)
+endif
 
 $(BOOT_OUTPUT): $(RAW)
 	$(OBJCOPY) -O $(BFD_OUTPUT) $< $@
 
-$(RAW): $(OBJECTS) $(COMPONENT_OBJECTS) $(LINK)
-	$(LD) -n $(LFLAGS) -T $(LINK) -M -Map $(MAP) -o $@ $(COMPONENT_OBJECTS) $(OBJECTS)
+$(RAW): $(OBJECTS) $(LINK)
+	$(LD) -n $(LFLAGS) -T $(LINK) -M -Map $(MAP) -o $@ $(OBJECTS)
 
-$(LINK): $(LINK).comp $(DEPEND)
-	$(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $(LINK).comp | grep -v "^\#" > $(LINK)
+$(LINK): $(DEPEND)
+	$(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $(LINK).in | grep -v "^\#" > $(LINK)
 
 %.o: %.S $(DEPEND)
@@ -125,7 +126,36 @@
 endif
 
-$(DEPEND): $(ARCH_INCLUDE) $(GENARCH_INCLUDE) $(COMMON_HEADER_ARCH)
+%.o: %.s $(DEPEND)
+	$(AS) $(AFLAGS) -o $@ $<
+ifeq ($(PRECHECK),y)
+	$(JOBFILE) $(JOB) $< $@ as asm
+endif
+
+$(DEPEND): $(ARCH_INCLUDE) $(GENARCH_INCLUDE) $(COMMON_HEADER_ARCH) $(PRE_DEPEND)
 	makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(SOURCES) > $@ 2> /dev/null
 	-[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
+
+$(COMPS).s: $(COMPS).zip
+	unzip -p $< $@ > $@
+
+$(COMPS).h: $(COMPS).zip
+	unzip -p $< $@ > $@
+
+$(COMPS)_desc.c: $(COMPS).zip
+	unzip -p $< $@ > $@
+
+$(COMPS).zip: $(COMPONENTS)
+	$(MKARRAY) --deflate $(COMPS) $(COMP) "$(AS_PROLOG)" ".section .components, \"a\"" $^
+
+$(INITRD).img:
+ifeq ($(RDFMT),tmpfs)
+	$(MKTMPFS) $(DIST_PATH) $@
+endif
+ifeq ($(RDFMT),fat)
+	$(MKFAT) 1048576 $(DIST_PATH) $@
+endif
+ifeq ($(RDFMT),ext4fs)
+	$(MKEXT4) 1048576 $(DIST_PATH) $@
+endif
 
 $(ARCH_INCLUDE): arch/$(KARCH)/include/
Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/Makefile.common	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -52,6 +52,5 @@
 DRVS_PATH = drv
 
-SANDBOX = pack
-PACK = $(TOOLS_PATH)/pack.py
+MKARRAY = $(TOOLS_PATH)/mkarray.py
 MKTMPFS = $(TOOLS_PATH)/mktmpfs.py
 MKFAT = $(TOOLS_PATH)/mkfat.py
@@ -251,6 +250,6 @@
 
 LINK = arch/$(BARCH)/_link.ld
-COMPS_H = arch/$(BARCH)/include/_components.h
-COMPS_C = arch/$(BARCH)/src/_components.c
+COMP = component
+COMPS = $(COMP)s
 
 -include arch/$(BARCH)/Makefile.inc
@@ -276,4 +275,3 @@
 JOB ?= image.job
 MAP ?= image.map
-PREBUILD ?= build_comps
 BUILD ?= Makefile.build
Index: boot/arch/arm32/Makefile.inc
===================================================================
--- boot/arch/arm32/Makefile.inc	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/arm32/Makefile.inc	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -96,5 +96,6 @@
 	arch/$(BARCH)/src/mm.c \
 	arch/$(BARCH)/src/putchar.c \
-	$(COMPS_C) \
+	$(COMPS).s \
+	$(COMPS)_desc.c \
 	genarch/src/division.c \
 	generic/src/memstr.c \
@@ -105,2 +106,4 @@
 	generic/src/version.c \
 	generic/src/inflate.c
+
+PRE_DEPEND = $(COMPS).s $(COMPS).h $(COMPS)_desc.c
Index: boot/arch/arm32/_link.ld.in
===================================================================
--- boot/arch/arm32/_link.ld.in	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/arm32/_link.ld.in	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -23,5 +23,5 @@
 		*(.bss);        /* uninitialized static variables */
 		*(COMMON);      /* global variables */
-[[COMPONENTS]]
+		*(.components);
 	}
 	bdata_end = .;
Index: boot/arch/arm32/src/main.c
===================================================================
--- boot/arch/arm32/src/main.c	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/arm32/src/main.c	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -37,5 +37,4 @@
 #include <arch/asm.h>
 #include <arch/mm.h>
-#include <arch/_components.h>
 #include <halt.h>
 #include <printf.h>
@@ -49,4 +48,5 @@
 #include <inflate.h>
 #include <arch/cp15.h>
+#include "../../components.h"
 
 #define TOP2ADDR(top)  (((void *) PA2KA(BOOT_OFFSET)) + (top))
@@ -99,6 +99,6 @@
 	
 	for (size_t i = 0; i < COMPONENTS; i++) {
-		printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].start,
-		    components[i].start, components[i].name, components[i].inflated,
+		printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].addr,
+		    components[i].addr, components[i].name, components[i].inflated,
 		    components[i].size);
 	}
@@ -129,5 +129,5 @@
 	
 	for (size_t i = cnt; i > 0; i--) {
-		void *tail = components[i - 1].start + components[i - 1].size;
+		void *tail = components[i - 1].addr + components[i - 1].size;
 		if (tail >= dest[i - 1]) {
 			printf("\n%s: Image too large to fit (%p >= %p), halting.\n",
@@ -138,5 +138,5 @@
 		printf("%s ", components[i - 1].name);
 		
-		int err = inflate(components[i - 1].start, components[i - 1].size,
+		int err = inflate(components[i - 1].addr, components[i - 1].size,
 		    dest[i - 1], components[i - 1].inflated);
 		if (err != EOK) {
Index: boot/arch/ia64/Makefile.inc
===================================================================
--- boot/arch/ia64/Makefile.inc	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/ia64/Makefile.inc	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -48,5 +48,6 @@
 	arch/$(BARCH)/src/pal_asm.S \
 	arch/$(BARCH)/src/putchar.c \
-	$(COMPS_C) \
+	$(COMPS).s \
+	$(COMPS)_desc.c \
 	genarch/src/efi.c \
 	genarch/src/division.c \
@@ -88,2 +89,3 @@
 	bus/isa
 
+PRE_DEPEND = $(COMPS).s $(COMPS).h $(COMPS)_desc.c
Index: boot/arch/ia64/_link.ld.in
===================================================================
--- boot/arch/ia64/_link.ld.in	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/ia64/_link.ld.in	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -16,7 +16,7 @@
 		*(.bss);                /* uninitialized static variables */
 		*(COMMON);
-[[COMPONENTS]]
+		*(.components);
 	}
-
+	
 	/DISCARD/ : {
 		*(.*);
Index: boot/arch/ia64/src/main.c
===================================================================
--- boot/arch/ia64/src/main.c	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/ia64/src/main.c	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -33,5 +33,4 @@
 #include <arch/arch.h>
 #include <arch/asm.h>
-#include <arch/_components.h>
 #include <genarch/efi.h>
 #include <arch/sal.h>
@@ -46,4 +45,5 @@
 #include <errno.h>
 #include <inflate.h>
+#include "../../components.h"
 
 #define DEFAULT_MEMORY_BASE		0x4000000ULL
@@ -78,5 +78,5 @@
 		memmap[items].size = DEFAULT_LEGACY_IO_SIZE;
 		memmap[items].type = MEMMAP_IO_PORTS;
-		items++;		 
+		items++;
 	} else {
 		char *cur, *mm_base = (char *) bootpar->efi_memmap;
@@ -159,6 +159,6 @@
 	size_t i;
 	for (i = 0; i < COMPONENTS; i++)
-		printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].start,
-		    components[i].start, components[i].name,
+		printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].addr,
+		    components[i].addr, components[i].name,
 		    components[i].inflated, components[i].size);
 	
@@ -202,5 +202,5 @@
 		 * overlap with the destination for inflate().
 		 */
-		memmove((void *) top, components[i - 1].start, components[i - 1].size);
+		memmove((void *) top, components[i - 1].addr, components[i - 1].size);
 		
 		int err = inflate((void *) top, components[i - 1].size,
Index: boot/arch/mips32/Makefile.inc
===================================================================
--- boot/arch/mips32/Makefile.inc	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/mips32/Makefile.inc	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -30,4 +30,5 @@
 BITS = 32
 EXTRA_CFLAGS = -msoft-float -mno-abicalls -G 0 -fno-zero-initialized-in-bss -mabi=32
+AS_PROLOG = .module softfloat;
 
 ifeq ($(MACHINE),msim)
@@ -74,5 +75,6 @@
 	arch/$(BARCH)/src/main.c \
 	arch/$(BARCH)/src/putchar.c \
-	$(COMPS_C) \
+	$(COMPS).s \
+	$(COMPS)_desc.c \
 	genarch/src/division.c \
 	genarch/src/multiplication.c \
@@ -84,2 +86,4 @@
 	generic/src/version.c \
 	generic/src/inflate.c
+
+PRE_DEPEND = $(COMPS).s $(COMPS).h $(COMPS)_desc.c
Index: boot/arch/mips32/_link.ld.in
===================================================================
--- boot/arch/mips32/_link.ld.in	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/mips32/_link.ld.in	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -21,5 +21,5 @@
 		*(.bss);        /* uninitialized static variables */
 		*(COMMON);      /* global variables */
-[[COMPONENTS]]
+		*(.components);
 	}
 	
Index: boot/arch/mips32/src/main.c
===================================================================
--- boot/arch/mips32/src/main.c	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/mips32/src/main.c	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -30,5 +30,4 @@
 #include <arch/arch.h>
 #include <arch/asm.h>
-#include <arch/_components.h>
 #include <halt.h>
 #include <printf.h>
@@ -40,4 +39,5 @@
 #include <errno.h>
 #include <inflate.h>
+#include "../../components.h"
 
 #define TOP2ADDR(top)  (((void *) PA2KA(BOOT_OFFSET)) + (top))
@@ -64,8 +64,8 @@
 	size_t i;
 	for (i = 0; i < COMPONENTS; i++)
-		printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].start,
-		    (uintptr_t) components[i].start >= PA2KSEG(0) ?
-		    (void *) KSEG2PA(components[i].start) :
-		    (void *) KA2PA(components[i].start),
+		printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].addr,
+		    (uintptr_t) components[i].addr >= PA2KSEG(0) ?
+		    (void *) KSEG2PA(components[i].addr) :
+		    (void *) KA2PA(components[i].addr),
 		    components[i].name, components[i].inflated,
 		    components[i].size);
@@ -107,5 +107,5 @@
 		printf("%s ", components[i - 1].name);
 		
-		int err = inflate(components[i - 1].start, components[i - 1].size,
+		int err = inflate(components[i - 1].addr, components[i - 1].size,
 		    dest[i - 1], components[i - 1].inflated);
 		
Index: boot/arch/ppc32/Makefile.inc
===================================================================
--- boot/arch/ppc32/Makefile.inc	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/ppc32/Makefile.inc	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -57,5 +57,6 @@
 	arch/$(BARCH)/src/main.c \
 	arch/$(BARCH)/src/ofw.c \
-	$(COMPS_C) \
+	$(COMPS).s \
+	$(COMPS)_desc.c \
 	genarch/src/ofw.c \
 	genarch/src/ofw_tree.c \
@@ -70,2 +71,4 @@
 	generic/src/version.c \
 	generic/src/inflate.c
+
+PRE_DEPEND = $(COMPS).s $(COMPS).h $(COMPS)_desc.c
Index: boot/arch/ppc32/_link.ld.in
===================================================================
--- boot/arch/ppc32/_link.ld.in	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/ppc32/_link.ld.in	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -18,5 +18,5 @@
 		*(.bss);        /* uninitialized static variables */
 		*(COMMON);      /* global variables */
-[[COMPONENTS]]
+		*(.components);
 	}
 	
Index: boot/arch/ppc32/src/main.c
===================================================================
--- boot/arch/ppc32/src/main.c	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/ppc32/src/main.c	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -30,5 +30,4 @@
 #include <arch/arch.h>
 #include <arch/asm.h>
-#include <arch/_components.h>
 #include <genarch/ofw.h>
 #include <genarch/ofw_tree.h>
@@ -42,4 +41,5 @@
 #include <errno.h>
 #include <inflate.h>
+#include "../../components.h"
 
 #define BALLOC_MAX_SIZE  131072
@@ -75,6 +75,6 @@
 	size_t i;
 	for (i = 0; i < COMPONENTS; i++)
-		printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].start,
-		    ofw_translate(components[i].start), components[i].name,
+		printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].addr,
+		    ofw_translate(components[i].addr), components[i].name,
 		    components[i].inflated, components[i].size);
 	
@@ -139,5 +139,5 @@
 		printf("%s ", components[i - 1].name);
 		
-		int err = inflate(components[i - 1].start, components[i - 1].size,
+		int err = inflate(components[i - 1].addr, components[i - 1].size,
 		    inflate_base + dest[i - 1], components[i - 1].inflated);
 		
Index: boot/arch/riscv64/_link.ld.in
===================================================================
--- boot/arch/riscv64/_link.ld.in	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/riscv64/_link.ld.in	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -17,5 +17,4 @@
 		*(.bss);        /* uninitialized static variables */
 		*(COMMON);      /* global variables */
-[[COMPONENTS]]
 	}
 	
Index: boot/arch/sparc64/Makefile.inc
===================================================================
--- boot/arch/sparc64/Makefile.inc	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/sparc64/Makefile.inc	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -57,5 +57,6 @@
 	arch/$(BARCH)/src/main.c \
 	arch/$(BARCH)/src/ofw.c \
-	$(COMPS_C) \
+	$(COMPS).s \
+	$(COMPS)_desc.c \
 	genarch/src/ofw.c \
 	genarch/src/ofw_tree.c \
@@ -68,2 +69,4 @@
 	generic/src/version.c \
 	generic/src/inflate.c
+
+PRE_DEPEND = $(COMPS).s $(COMPS).h $(COMPS)_desc.c
Index: boot/arch/sparc64/_link.ld.in
===================================================================
--- boot/arch/sparc64/_link.ld.in	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/sparc64/_link.ld.in	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -15,5 +15,5 @@
 		*(.bss);        /* uninitialized static variables */
 		*(COMMON);      /* global variables */
-[[COMPONENTS]]
+		*(.components);
 	}
 	
Index: boot/arch/sparc64/src/main.c
===================================================================
--- boot/arch/sparc64/src/main.c	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ boot/arch/sparc64/src/main.c	(revision 4646710d9ea7943ec02c77020e7b60258fd30d8b)
@@ -32,5 +32,4 @@
 #include <arch/asm.h>
 #include <arch/ofw.h>
-#include <arch/_components.h>
 #include <genarch/ofw.h>
 #include <genarch/ofw_tree.h>
@@ -44,4 +43,5 @@
 #include <errno.h>
 #include <inflate.h>
+#include "../../components.h"
 
 /* The lowest ID (read from the VER register) of some US3 CPU model */
@@ -220,6 +220,6 @@
 	size_t i;
 	for (i = 0; i < COMPONENTS; i++)
-		printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].start,
-		    ofw_translate(components[i].start), components[i].name,
+		printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].addr,
+		    ofw_translate(components[i].addr), components[i].name,
 		    components[i].inflated, components[i].size);
 	
@@ -267,5 +267,5 @@
 		    ALIGN_UP(components[i - 1].inflated, PAGE_SIZE), -1);
 		
-		int err = inflate(components[i - 1].start, components[i - 1].size,
+		int err = inflate(components[i - 1].addr, components[i - 1].size,
 		    dest[i - 1], components[i - 1].inflated);
 		
Index: ols/pack.py
===================================================================
--- tools/pack.py	(revision 22299ed9a3c298d5c73fceaefb6a619c975bdee1)
+++ 	(revision )
@@ -1,200 +1,0 @@
-#!/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
-import zlib
-import shutil
-
-SANDBOX = 'pack'
-LINK = '_link.ld'
-COMPONENTS = '_components'
-
-def usage(prname):
-	"Print usage syntax"
-	print("%s <OBJCOPY> <FORMAT> <ARCH> <ARCH_PATH> [COMPONENTS ...]" % prname)
-
-def deflate(data):
-	"Compress using deflate algorithm (without any headers)"
-	return zlib.compress(data, 9)[2:-4]
-
-def print_error(msg):
-	"Print a bold error message"
-	
-	sys.stderr.write("\n")
-	sys.stderr.write("######################################################################\n")
-	sys.stderr.write("HelenOS build sanity check error:\n")
-	sys.stderr.write("\n")
-	sys.stderr.write("%s\n" % "\n".join(msg))
-	sys.stderr.write("######################################################################\n")
-	sys.stderr.write("\n")
-	
-	sys.exit(1)
-
-def sandbox_enter():
-	"Create a temporal sandbox directory for packing"
-	
-	if (os.path.exists(SANDBOX)):
-		if (os.path.isdir(SANDBOX)):
-			try:
-				shutil.rmtree(SANDBOX)
-			except:
-				print_error(["Unable to cleanup the directory \"%s\"." % SANDBOX])
-		else:
-			print_error(["Please inspect and remove unexpected directory,",
-			             "entry \"%s\"." % SANDBOX])
-	
-	try:
-		os.mkdir(SANDBOX)
-	except:
-		print_error(["Unable to create sandbox directory \"%s\"." % SANDBOX])
-	
-	owd = os.getcwd()
-	os.chdir(SANDBOX)
-	
-	return owd
-
-def sandbox_leave(owd):
-	"Leave the temporal sandbox directory"
-	
-	os.chdir(owd)
-
-def main():
-	if (len(sys.argv) < 5):
-		usage(sys.argv[0])
-		return
-	
-	objcopy = sys.argv[1]
-	format = sys.argv[2]
-	arch = sys.argv[3]
-	arch_path = sys.argv[4]
-	
-	header_ctx = []
-	data_ctx = []
-	link_ctx = []
-	cnt = 0
-	for component in sys.argv[5:]:
-		basename = os.path.basename(component)
-		plainname = os.path.splitext(basename)[0]
-		obj = "%s.co" % plainname
-		symbol = "_binary_%s" % basename.replace(".", "_")
-		
-		print("%s -> %s" % (component, obj))
-		
-		comp_in = open(component, "rb")
-		comp_data = comp_in.read()
-		comp_in.close()
-		
-		comp_deflate = deflate(comp_data)
-		
-		owd = sandbox_enter()
-		
-		try:
-			comp_out = open(basename, "wb")
-			comp_out.write(comp_deflate)
-			comp_out.close()
-			
-			subprocess.call([objcopy,
-				"-I", "binary",
-				"-O", format,
-				"-B", arch,
-				"--rename-section", ".data=.%s_image" % plainname,
-				basename, os.path.join(owd, obj)])
-			
-		finally:
-			sandbox_leave(owd)
-		
-		link_ctx.append("\t\t*(.%s_image);" % plainname)
-		
-		header_rec = "extern int %s_start;\n" % symbol
-		header_rec += "extern int %s_size;\n" % symbol
-		header_ctx.append(header_rec)
-		
-		data_rec = "\t{\n"
-		data_rec += "\t\t.name = \"%s\",\n" % plainname
-		data_rec += "\t\t.start = (void *) &%s_start,\n" % symbol
-		data_rec += "\t\t.size = (size_t) &%s_size,\n" % symbol
-		data_rec += "\t\t.inflated = %d\n" % len(comp_data)
-		data_rec += "\t}"
-		data_ctx.append(data_rec)
-		
-		cnt += 1
-	
-	header = open(os.path.join(arch_path, "include", "%s.h" % COMPONENTS), "w")
-	
-	header.write('/***************************************\n')
-	header.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
-	header.write(' * Generated by: tools/pack.py         *\n')
-	header.write(' ***************************************/\n\n')
-	header.write("#ifndef BOOT_COMPONENTS_H_\n")
-	header.write("#define BOOT_COMPONENTS_H_\n\n")
-	header.write("#include <stddef.h>\n\n")
-	header.write("#define COMPONENTS  %d\n\n" % cnt)
-	header.write("typedef struct {\n")
-	header.write("\tconst char *name;\n")
-	header.write("\tvoid *start;\n")
-	header.write("\tsize_t size;\n")
-	header.write("\tsize_t inflated;\n")
-	header.write("} component_t;\n\n")
-	header.write("extern component_t components[];\n\n")
-	header.write("\n".join(header_ctx))
-	header.write("\n")
-	header.write("#endif\n")
-	
-	header.close()
-	
-	data = open(os.path.join(arch_path, "src", "%s.c" % COMPONENTS), "w")
-	
-	data.write('/***************************************\n')
-	data.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
-	data.write(' * Generated by: tools/pack.py         *\n')
-	data.write(' ***************************************/\n\n')
-	data.write("#include <stddef.h>\n")
-	data.write("#include <arch/%s.h>\n\n" % COMPONENTS)
-	data.write("component_t components[] = {\n")
-	data.write(",\n".join(data_ctx))
-	data.write("\n")
-	data.write("};\n")
-	
-	data.close()
-	
-	link_in = open(os.path.join(arch_path, "%s.in" % LINK), "r")
-	template = link_in.read()
-	link_in.close()
-	
-	link_out = open(os.path.join(arch_path, "%s.comp" % LINK), "w")
-	link_out.write(template.replace("[[COMPONENTS]]", "\n".join(link_ctx)))
-	link_out.close()
-
-if __name__ == '__main__':
-	main()
