#! /bin/sh -e
## loader.dpatch by Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de>
##
## DP: patches to sibyl

[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
patch_opts="${patch_opts:--f --no-backup-if-mismatch ${2:+-d $2}}"

if [ $# -lt 1 ]; then
	echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
	exit 1
fi

case "$1" in
	-patch) patch $patch_opts -p1 < $0;;
	-unpatch) patch $patch_opts -p1 -R < $0;;
	*)
		echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
		exit 1;;
esac

exit 0
@DPATCH@

diff -wurN orig/loader/BUILD debian/loader/BUILD
--- orig/loader/BUILD	2002-11-21 18:17:57.000000000 +0100
+++ debian/loader/BUILD	1970-01-01 01:00:00.000000000 +0100
@@ -1,31 +0,0 @@
-#!/bin/sh -e
-# $Id: BUILD,v 1.2 2002/11/21 17:17:57 kwalker Exp $
-
-sb_tool_prefix=`sbtoolinfo prefix`
-sb_target=`sbtoolinfo target`
-if [ -z "$sb_tool_prefix" ] || [ -z "$sb_target" ]; then
-	echo "$0: sbtoolinfo providing bogus information" 1>&2
-	exit 1
-fi
-sb_target_prefix=$sb_tool_prefix/$sb_target
-sb_tool_env=$sb_target-env
-sb_tool_make=$sb_target-make
-
-case ${1:-all} in
-all)
-	$sb_tool_make
-	;;
-clean)
-	$sb_tool_make -k clean
-	;;
-cmdname)
-	cd `dirname $0`
-	pwdname=`pwd`
-	cmdname=`basename $pwdname`
-	echo $cmdname
-	;;
-*)
-	echo "usage: $0 all|clean|cmdname" 1>&2
-	false
-	;;
-esac
diff -wurN orig/loader/config.h debian/loader/config.h
--- orig/loader/config.h	1970-01-01 01:00:00.000000000 +0100
+++ debian/loader/config.h	2004-07-25 14:10:59.000000000 +0200
@@ -0,0 +1,47 @@
+/* $Id: config.h,v 1.4 2003/05/30 00:42:38 cgd Exp $ */
+
+/*
+ * Copyright 2001, 2003
+ * Broadcom Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and copied only
+ * in accordance with the following terms and conditions.  Subject to these
+ * conditions, you may download, copy, install, use, modify and distribute
+ * modified or unmodified copies of this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce and
+ *    retain this copyright notice and list of conditions as they appear in
+ *    the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
+ *    used to endorse or promote products derived from this software
+ *    without the prior written permission of Broadcom Corporation.
+ *
+ * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
+ *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
+ *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+ *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
+ *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
+ *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+
+/* Network support */
+#ifndef CONFIG_BLOCKDEV
+#define CONFIG_NETWORK
+#endif
+
+/* Support for booting from block devices (Currently broken) */
+//#define CONFIG_BLOCKDEV
+
+#endif
+
diff -wurN orig/loader/console.h debian/loader/console.h
--- orig/loader/console.h	1970-01-01 01:00:00.000000000 +0100
+++ debian/loader/console.h	2004-07-25 14:10:59.000000000 +0200
@@ -0,0 +1,41 @@
+/* $Id: console.h,v 1.3 2003/05/30 00:42:38 cgd Exp $ */
+
+/*
+ * Copyright 2001, 2003
+ * Broadcom Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and copied only
+ * in accordance with the following terms and conditions.  Subject to these
+ * conditions, you may download, copy, install, use, modify and distribute
+ * modified or unmodified copies of this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce and
+ *    retain this copyright notice and list of conditions as they appear in
+ *    the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
+ *    used to endorse or promote products derived from this software
+ *    without the prior written permission of Broadcom Corporation.
+ *
+ * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
+ *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
+ *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+ *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
+ *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
+ *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _CONSOLE_H
+#define _CONSOLE_H
+
+void console_print(char *string);
+int open_console();
+
+#endif
diff -wurN orig/loader/elf.h debian/loader/elf.h
--- orig/loader/elf.h	1970-01-01 01:00:00.000000000 +0100
+++ debian/loader/elf.h	2004-07-25 14:10:59.000000000 +0200
@@ -0,0 +1,177 @@
+/* $Id: elf.h,v 1.4 2003/05/30 00:42:38 cgd Exp $ */
+
+/*
+ * Copyright 2001, 2003
+ * Broadcom Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and copied only
+ * in accordance with the following terms and conditions.  Subject to these
+ * conditions, you may download, copy, install, use, modify and distribute
+ * modified or unmodified copies of this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce and
+ *    retain this copyright notice and list of conditions as they appear in
+ *    the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
+ *    used to endorse or promote products derived from this software
+ *    without the prior written permission of Broadcom Corporation.
+ *
+ * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
+ *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
+ *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+ *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
+ *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
+ *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ELF_H
+#define ELF_H
+
+#include "port.h"
+
+/* Elf types */
+typedef uint8_t  Elf_Byte;
+
+typedef uint16_t Elf32_Half;
+typedef uint32_t Elf32_Word;
+typedef  int32_t Elf32_Sword;
+typedef uint32_t Elf32_Off;
+typedef uint32_t Elf32_Addr;
+
+typedef uint16_t Elf64_Quarter;
+typedef uint32_t Elf64_Half;
+typedef  int32_t Elf64_Shalf;
+typedef uint64_t Elf64_Word;
+typedef  int64_t Elf64_Sword;
+typedef uint64_t Elf64_Addr;
+typedef uint64_t Elf64_Off;
+
+
+/* ELF Header */
+#define EI_NIDENT    16
+
+/* Quick rant: Why, oh why, do these all have to start with e_?  Isn't
+   it enough to see they're elements of an Ehdr struct?  Maybe there's
+   a worldwide conspiracy to increase the number of 'e's in existance. 
+   The truth is out there, and I'm REALLY tired right now  - JDC */
+
+typedef struct {
+	Elf_Byte       e_ident[EI_NIDENT] ;   /* ID.  Elf0x7f+              */
+	Elf32_Half     e_type             ;   /* File type                  */
+	Elf32_Half     e_machine          ;   /* Machine type               */
+	Elf32_Word     e_version          ;   /* Version (Duh!)             */
+	Elf32_Addr     e_entry            ;   /* Execution entry point      */
+	Elf32_Off      e_phoff            ;   /* Program header offset      */
+	Elf32_Off      e_shoff            ;   /* Section header offset      */
+	Elf32_Word     e_flags            ;   /* Processor flags            */
+	Elf32_Half     e_ehsize           ;   /* Ehder size                 */
+	Elf32_Half     e_phentsize        ;   /* Prog header entry size     */
+	Elf32_Half     e_phnum            ;   /* Prog header count          */
+	Elf32_Half     e_shentsize        ;   /* Section header entry size  */
+	Elf32_Half     e_shnum            ;   /* Number of section headers  */
+	Elf32_Half     e_shstrndx         ;   /* String table index         */
+} Elf32_Ehdr;
+
+
+typedef struct {
+	Elf_Byte       e_ident[EI_NIDENT] ;   /* ID.  Elf0x7f+              */
+	Elf64_Quarter  e_type             ;   /* File type                  */
+	Elf64_Quarter  e_machine          ;   /* Machine type               */
+	Elf64_Half     e_version          ;   /* Version (Duh!)             */
+	Elf64_Addr     e_entry            ;   /* Execution entry point      */
+	Elf64_Off      e_phoff            ;   /* Program header offset      */
+	Elf64_Off      e_shoff            ;   /* Section header offset      */
+	Elf64_Half     e_flags            ;   /* Processor flags            */
+	Elf64_Quarter  e_ehsize           ;   /* Ehder size                 */
+	Elf64_Quarter  e_phentsize        ;   /* Prog header entry size     */
+	Elf64_Quarter  e_phnum            ;   /* Prog header count          */
+	Elf64_Quarter  e_shentsize        ;   /* Section header entry size  */
+	Elf64_Quarter  e_shnum            ;   /* Number of section headers  */
+	Elf64_Quarter  e_shstrndx         ;   /* String table index         */
+} Elf64_Ehdr;
+
+
+/* e_ident offsets */
+#define EI_MAG0            0                  /* File identification        */
+#define EI_MAG1            1                  /* File identification        */
+#define EI_MAG2            2                  /* File identification        */
+#define EI_MAG3            3                  /* File identification        */
+#define EI_CLASS           4                  /* Class (Duh!)               */
+#define EI_DATA            5                  /* Encoding                   */
+#define EI_VERSION         6                  /* Version                    */
+#define EI_PAD             7                  /* Start of padding           */
+
+/* e_ident magic cookie */
+#define ELFMAG0         0x7f
+#define ELFMAG1          'E'
+#define ELFMAG2          'L'
+#define ELFMAG3          'F'
+#define ELFMAG     "\177ELF"
+
+/* e_ident[EI_CLASS] values */
+#define ELFCLASSNONE       0
+#define ELFCLASS32         1
+#define ELFCLASS64         2                  
+
+/* e_ident[EI_DATA] values */
+#define ELFDATANONE        0                  /* straight out!              */
+#define ELFDATA2LSB        1                  /* little-endian              */
+#define ELFDATA2MSB        2                  /* big-endian                 */
+
+/* e_type values */
+#define ET_NONE            0                  /* Go away!                   */
+#define ET_REL             1                  /* Relocatable                */
+#define ET_EXEC            2                  /* Executable                 */
+#define ET_DYN             3                  /* Shared object              */
+#define ET_CORE            4                  /* Core (Not Arm)             */
+#define ET_LOPROC     0xff00                  /* Processor specific         */
+#define ET_HIPROC     0xffff                  /* Processor specific         */
+
+
+typedef struct {
+	Elf32_Word     p_type             ;   /* Segment type               */
+	Elf32_Off      p_offset           ;   /* Offset to segment data     */
+	Elf32_Addr     p_vaddr            ;   /* Virt addr of segment       */
+	Elf32_Addr     p_paddr            ;   /* Ignored segment phys addr  */
+	Elf32_Word     p_filesz           ;   /* Segment file image size    */
+	Elf32_Word     p_memsz            ;   /* Segment memory image size  */
+	Elf32_Word     p_flags            ;   /* Flags for segment          */
+	Elf32_Word     p_align            ;   /* Segment alignment enforced */
+} Elf32_Phdr;
+
+typedef struct {
+	Elf64_Half     p_type             ;   /* Segment type               */
+	Elf64_Half     p_flags            ;   /* Flags for segment          */
+	Elf64_Off      p_offset           ;   /* Offset to segment data     */
+	Elf64_Addr     p_vaddr            ;   /* Virt addr of segment       */
+	Elf64_Addr     p_paddr            ;   /* Ignored segment phys addr  */
+	Elf64_Word     p_filesz           ;   /* Segment file image size    */
+	Elf64_Word     p_memsz            ;   /* Segment memory image size  */
+	Elf64_Word     p_align            ;   /* Segment alignment enforced */
+} Elf64_Phdr;
+
+/* p_type values */
+#define PT_NULL            0                  /* Ignore                     */
+#define PT_LOAD            1                  /* Loadable segment           */
+#define PT_DYNAMIC         2                  /* Dynamic linking info       */
+#define PT_INTERP          3                  /* Program interpreter        */
+#define PT_NOTE            4                  /* Auxilliary info location   */
+#define PT_SHLIB           5                  /* Reserved                   */
+#define PT_PHDR            6                  /* Location of phdr table (?) */
+#define PT_LOPROC 0x70000000                  /* Proc specific range low    */
+#define PT_HIPROV 0x7fffffff                  /* Proc specific range high   */
+
+/* p_flags vaules  (Not related to PFLAG...:) */
+#define PHP_X            0x1                  /* Execute                    */
+#define PHP_W            0x2                  /* Write                      */
+#define PHP_R            0x4                  /* Read                       */
+
+#endif
diff -wurN orig/loader/ext2_fileops.c debian/loader/ext2_fileops.c
--- orig/loader/ext2_fileops.c	2003-05-30 02:42:37.000000000 +0200
+++ debian/loader/ext2_fileops.c	2004-07-25 14:10:59.000000000 +0200
@@ -33,6 +33,7 @@
  */
 
 #include <stdio.h> /* To make ext2lib happy.  We don't actually use anything from it */
+#include "port.h"
 #include "getfile.h"
 #include "libc.h"
 #include "partition.h"
@@ -40,13 +41,17 @@
 #include "ext2_fs.h"  /* From linux kernel */
 #include "ext2fs.h"   /* From e2fsprogs    */
 
+extern unsigned long long my_strtoull(const char *ptr);
 
 typedef struct {
-//	int32_t offset;
 	ext2_filsys fs;
         ext2_file_t file;
 } ext2_ops_data_t;
 
+typedef struct cfe_private_data_struct {
+	int handle;
+	unsigned long linear_offset;
+} cfe_channel_private_t;
 
 /*
  * I/O Manager Glue
@@ -58,7 +63,7 @@
 static errcode_t cfe_manager_write_blk(io_channel channel, unsigned long block, int count, const void *buf);
 static errcode_t cfe_manager_flush(io_channel channel);
 
-static struct struct_io_manager struct_cfe_manager = {
+static struct struct_io_manager cfe_io_manager = {
 	EXT2_ET_MAGIC_IO_MANAGER,
 	"CFE I/O Manager",
 	cfe_manager_open,
@@ -66,165 +71,115 @@
 	cfe_manager_set_blksize,
 	cfe_manager_read_blk,
 	cfe_manager_write_blk,
-	cfe_manager_flush
-};
-
-io_manager cfe_io_manager = &struct_cfe_manager;
-
-/* This is probably a big no-no, but I'm 99% sure we don't need reentrancy for 
-   the intended use, and we've not good way of allocating memory from the firmware...*/
-
-#define CFE_CHANNEL_NAME_SIZE 64
-static char cfe_channel_name[CFE_CHANNEL_NAME_SIZE];
-
-typedef struct cfe_private_data_struct {
-	int handle;
-	unsigned long linear_offset;
-} cfe_channel_private_t;
-
-static cfe_channel_private_t cfe_channel_private = {
-    handle: 0,
-    linear_offset: 0
+	cfe_manager_flush,
+	NULL,
+	{0, }
 };
 
-static struct struct_io_channel cfe_channel = {
-	magic:        EXT2_ET_MAGIC_IO_CHANNEL,
-	manager:      &struct_cfe_manager,
-	name:         cfe_channel_name,
-	block_size:   1024,
-	read_error:   NULL,
-	write_error:  NULL,
-	refcount:     0,
-	private_data: (void *)&cfe_channel_private,
-	app_data:     NULL
-};
-
-
-
-static unsigned long long my_strtoull(char *ptr) 
-{
-	unsigned long long retval = 0;
-	unsigned int newdigit;
-	while(*ptr) {
-		if (*ptr >= 'a' &&  *ptr <= 'f') {
-			newdigit = *ptr - ('a' - 10);
-		} else if (*ptr >= 'A' && *ptr <= 'F') {
-			newdigit = *ptr - ('A' - 10);
-		} else if (*ptr >= '0' && *ptr <= '9') {
-			newdigit = *ptr - '0';
-		} else if (*ptr == ' ' 
-			   || *ptr == '\t'
-			   || *ptr == '\n') {
-			/* Just skip it */
-		} else {
-			return -1UL;
-		}
-		retval <<= 4;
-		retval |= newdigit;
-		ptr++;
-	}
-	return retval;
-}
-
 static errcode_t cfe_manager_open(const char *name, int flags, io_channel *channel)
 {
+	io_channel io;
     char *tmp;
     cfe_channel_private_t *priv;
-    (*channel) = &cfe_channel;
 
-    if ((*channel)->refcount) {
-	return -1;
-	}
+	io = (io_channel)lib_malloc(sizeof(struct struct_io_channel));
+	if (!io)
+		lib_die("Out of memory");
+	lib_memset(io, 0, sizeof(struct struct_io_channel));
+
+	io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
+	io->manager = &cfe_io_manager;
+	io->block_size = 1024;
+
+	priv = (cfe_channel_private_t *)lib_malloc(sizeof(cfe_channel_private_t));
+	if (!priv)
+		lib_die("Out of memory");
+	lib_memset(priv, 0, sizeof(cfe_channel_private_t));
+	io->private_data = priv;
 
-    priv = (cfe_channel_private_t *)((*channel)->private_data);
     for (tmp = (char *) name; *tmp; tmp++) {
 	if (*tmp == '@') {
 	    *tmp = '\0';
 	    tmp++;
 	    priv->linear_offset = my_strtoull(tmp);
-	    if (priv->linear_offset == -1UL) {
+			if (priv->linear_offset == -1UL)
 		return -1;
-		}
+
 	    break;
 	    }
 	}
 	
-    lib_strncpy(cfe_channel_name, (char *) name, CFE_CHANNEL_NAME_SIZE-1);
-    cfe_channel_name[CFE_CHANNEL_NAME_SIZE-1] = '\0';
-    priv->handle = cfe_open(cfe_channel_name);
-
-    (*channel)->refcount++;
+	io->name = (char *)lib_strdup(name);
+	if (!io->name)
+		lib_die("Out of memory");
 	
-    if (priv->handle < 0) {
+	priv->handle = cfe_open(io->name);
+	if (priv->handle < 0)
 	return -1;
-	}
+
+	*channel = io;
     return 0;
 }
 
-
 static errcode_t cfe_manager_close(io_channel channel)
 {
 	cfe_channel_private_t *priv;
 
-	/* Should only have exactly 1 open when close is called */
-	if (channel->refcount != 1 ) {
-		return -1;
-	}
 	priv = (cfe_channel_private_t *)channel->private_data;
 	cfe_close(priv->handle);
-	channel->refcount--;
 	return 0;
 }
 
-
 static errcode_t cfe_manager_set_blksize(io_channel channel, int blksize)
 {
 	channel->block_size = blksize;
 	return 0;
 }
 
-
 static errcode_t cfe_manager_read_blk(io_channel channel, unsigned long block, int count, void *buf)
 {
 	int retval;
 	long size;
+	long offset;
 	cfe_channel_private_t *priv;
+
 	priv = (cfe_channel_private_t *)channel->private_data;
-	size = (count & 1<<((sizeof(long)*8)-1))?((~count) + 1):(count * channel->block_size);
+	offset = priv->linear_offset + block * channel->block_size;
 
-	retval = cfe_readblk(priv->handle, priv->linear_offset + (block * channel->block_size), 
-			     (unsigned char *)buf, size);
+	/* If it is negative count means bytes -- positive -> blocks */
+	size = (count < 0) ? -count : count * channel->block_size;
+
+	retval = cfe_readblk(priv->handle, offset, (unsigned char *)buf, size);
 
 	return (retval < 0)?-1:0;
 }
 
-
 static errcode_t cfe_manager_write_blk(io_channel channel, unsigned long block, int count, const void *buf)
 {
 	int retval; 
 	long size;
+	long offset;
 	cfe_channel_private_t *priv;
-	size = (count & 1<<((sizeof(long)*8)-1))?((~count) + 1):(count * channel->block_size);
+
 	priv = (cfe_channel_private_t *)channel->private_data;
+	offset = priv->linear_offset + block * channel->block_size;
+
+	/* If it is negative count means bytes -- positive -> blocks */
+	size = (count < 0) ? -count : count * channel->block_size;
 
 	retval = -1;
-	return retval;
 #if 0
 	/* XXX we don't support writing. */
-	retval = cfe_writeblk(priv->handle, priv->linear_offset + (block * channel->block_size), 
-			      (unsigned char *)buf, size);
-	return (retval < 0)?-1:0;
+	retval = cfe_writeblk(priv->handle, offset, (unsigned char *)buf, size);
 #endif
+	return (retval < 0) ? -1 : 0;
 }
 
-
 static errcode_t cfe_manager_flush(io_channel channel)
 {
 	return 0;
 }
 
-
-
 /* Print an ascii version of val in buf.  return the number of characters written */
 static  int hexprint(char *buf, unsigned long long val)
 {
@@ -261,12 +216,12 @@
     int cfe_handle;
     int partition;
     part_entry_t part_info;
-    ino_t ino;
+    ext2_ino_t ino;
     char *name;
 
-    if (lib_strncmp(loc, "ext2:", 5)) {
+    if (lib_strncmp(loc, "ext2:", 5))
 	return 0;
-	}
+
     loc += 5;
     /* OK, we think it's for us.  Next field should be a cfe device name */
 
@@ -286,10 +241,6 @@
 	
     /* Then a partition number */
     partition = (part[0] == '*') ? -1 :  lib_atoi(part);
-    ret = lib_malloc(sizeof(ext2_ops_data_t));
-    if (!ret) {
-	lib_die("Out of memory");
-	}
     cfe_handle = cfe_open(dev);
     if (cfe_handle < 0) {
 	lib_printf("CFE open of %s failed: %d\n", dev,cfe_handle);
@@ -307,30 +258,33 @@
     tok++;
     hexprint(tok, le_to_cpu32(part_info.start_sector) * 512);
 
-    if (ext2fs_open(buf, 0, 0, 0, cfe_io_manager, &(ret->fs))) {
+    ret = lib_malloc(sizeof(ext2_ops_data_t));
+    if (!ret)
+	lib_die("Out of memory");
+
+    if (ext2fs_open(buf, 0, 0, 0, &cfe_io_manager, &(ret->fs))) {
 	lib_printf("Failed to open ext2 filesystem on partition %i of device %s\n", partition, dev);
 	goto fail;
 	}
 
-
     /* ex2fs_lookup expects the name *not* to start with a slash. */
-
     if (*name == '/') name++;
 
     ino = 0;
     if (ext2fs_lookup(ret->fs,EXT2_ROOT_INO,name,lib_strlen(name),0,&ino)) {
 	lib_printf("Could not find inode for file %s\n",name);
-	ext2fs_close(ret->fs);
-	goto fail;
+	goto fail2;
 	}
 
     if (ext2fs_file_open(ret->fs,ino,0,&(ret->file))) {
-	ext2fs_close(ret->fs);
-	goto fail;
+	lib_printf("Failed to open file %s\n",name);
+	goto fail2;
 	}
 
     return ret;
 	
+fail2:
+    ext2fs_close(ret->fs);
 fail:
     lib_free(ret);
     return 0;
@@ -360,9 +314,8 @@
 	ext2_ops_data_t *data = (ext2_ops_data_t *)private;
 	unsigned int retval = 0;
 
-	if (ext2fs_file_read(data->file,buf,(unsigned int) amount,&retval)) {
+	if (ext2fs_file_read(data->file, buf, (unsigned int)amount, &retval))
 	    return -1;
-	    }
 
 	return (int32_t) retval;
 }
@@ -377,12 +330,9 @@
     lib_free(data);
 }
 
-
 file_ops_t ext2_ops = { 
 	ext2_op_open,
 	ext2_op_seek,
 	ext2_op_read,
 	ext2_op_close
 };
-
-
diff -wurN orig/loader/getfile.c debian/loader/getfile.c
--- orig/loader/getfile.c	2003-05-30 02:42:37.000000000 +0200
+++ debian/loader/getfile.c	2004-07-25 14:10:59.000000000 +0200
@@ -32,6 +32,8 @@
  *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdlib.h>
+
 #include "libc.h"
 #include "getfile.h"
 
@@ -47,14 +49,16 @@
 {
 	file_handler_node_t *tmp;
 	void *priv;
+
 	for (tmp = handler_chain; tmp; tmp = tmp->next) {
 		priv = (*(tmp->ops->open))(name);
 		if (priv) {
-			(*data) = priv;
+			*data = priv;
 			return tmp->ops;
 		}
 	}
-	return 0;
+
+	return NULL;
 }
 
 void file_handler_close(file_ops_t *ops,void *priv)
@@ -66,9 +70,9 @@
 {
 	file_handler_node_t *new_node;
 	new_node = lib_malloc(sizeof(file_handler_node_t));
-	if (!new_node) {
+	if (!new_node)
 		return -1;
-	}
+
 	new_node->ops = ops;
 	new_node->next = handler_chain;
 	handler_chain = new_node;
diff -wurN orig/loader/getfile.h debian/loader/getfile.h
--- orig/loader/getfile.h	1970-01-01 01:00:00.000000000 +0100
+++ debian/loader/getfile.h	2004-07-25 14:10:59.000000000 +0200
@@ -0,0 +1,60 @@
+/* $Id: getfile.h,v 1.6 2003/05/30 00:42:38 cgd Exp $ */
+
+/*
+ * Copyright 2001, 2003
+ * Broadcom Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and copied only
+ * in accordance with the following terms and conditions.  Subject to these
+ * conditions, you may download, copy, install, use, modify and distribute
+ * modified or unmodified copies of this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce and
+ *    retain this copyright notice and list of conditions as they appear in
+ *    the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
+ *    used to endorse or promote products derived from this software
+ *    without the prior written permission of Broadcom Corporation.
+ *
+ * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
+ *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
+ *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+ *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
+ *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
+ *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GETFILE_H
+#define _GETFILE_H
+
+#include "port.h"
+
+typedef enum {
+	GF_SEEK_SET,
+	GF_SEEK_CUR
+} file_handler_whence_t;
+
+
+typedef struct {
+	void *(*open)(char *loc);
+	int32_t (*seek)(void *private, int32_t ofs, file_handler_whence_t whence);
+	int32_t (*read)(void *private, void *buf, int32_t amount);
+	void (*close)(void *private);
+} file_ops_t;
+
+
+int file_handler_add(file_ops_t *ops);
+void file_handler_del(file_ops_t *ops);
+file_ops_t *file_handler_find(char *name, void **data);
+void file_handler_close(file_ops_t *ops,void *priv);
+
+
+#endif
diff -wurN orig/loader/include/config.h debian/loader/include/config.h
--- orig/loader/include/config.h	2003-05-30 02:42:38.000000000 +0200
+++ debian/loader/include/config.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,47 +0,0 @@
-/* $Id: config.h,v 1.4 2003/05/30 00:42:38 cgd Exp $ */
-
-/*
- * Copyright 2001, 2003
- * Broadcom Corporation. All rights reserved.
- *
- * This software is furnished under license and may be used and copied only
- * in accordance with the following terms and conditions.  Subject to these
- * conditions, you may download, copy, install, use, modify and distribute
- * modified or unmodified copies of this software in source and/or binary
- * form. No title or ownership is transferred hereby.
- *
- * 1) Any source code used, modified or distributed must reproduce and
- *    retain this copyright notice and list of conditions as they appear in
- *    the source file.
- *
- * 2) No right is granted to use any trade name, trademark, or logo of
- *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
- *    used to endorse or promote products derived from this software
- *    without the prior written permission of Broadcom Corporation.
- *
- * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
- *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
- *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
- *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
- *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
- *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _CONFIG_H
-#define _CONFIG_H
-
-/* Network support */
-#ifndef CONFIG_BLOCKDEV
-#define CONFIG_NETWORK
-#endif
-
-/* Support for booting from block devices (Currently broken) */
-//#define CONFIG_BLOCKDEV
-
-#endif
-
diff -wurN orig/loader/include/console.h debian/loader/include/console.h
--- orig/loader/include/console.h	2003-05-30 02:42:38.000000000 +0200
+++ debian/loader/include/console.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,41 +0,0 @@
-/* $Id: console.h,v 1.3 2003/05/30 00:42:38 cgd Exp $ */
-
-/*
- * Copyright 2001, 2003
- * Broadcom Corporation. All rights reserved.
- *
- * This software is furnished under license and may be used and copied only
- * in accordance with the following terms and conditions.  Subject to these
- * conditions, you may download, copy, install, use, modify and distribute
- * modified or unmodified copies of this software in source and/or binary
- * form. No title or ownership is transferred hereby.
- *
- * 1) Any source code used, modified or distributed must reproduce and
- *    retain this copyright notice and list of conditions as they appear in
- *    the source file.
- *
- * 2) No right is granted to use any trade name, trademark, or logo of
- *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
- *    used to endorse or promote products derived from this software
- *    without the prior written permission of Broadcom Corporation.
- *
- * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
- *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
- *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
- *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
- *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
- *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _CONSOLE_H
-#define _CONSOLE_H
-
-void console_print(char *string);
-int open_console();
-
-#endif
diff -wurN orig/loader/include/elf.h debian/loader/include/elf.h
--- orig/loader/include/elf.h	2003-05-30 02:42:38.000000000 +0200
+++ debian/loader/include/elf.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,177 +0,0 @@
-/* $Id: elf.h,v 1.4 2003/05/30 00:42:38 cgd Exp $ */
-
-/*
- * Copyright 2001, 2003
- * Broadcom Corporation. All rights reserved.
- *
- * This software is furnished under license and may be used and copied only
- * in accordance with the following terms and conditions.  Subject to these
- * conditions, you may download, copy, install, use, modify and distribute
- * modified or unmodified copies of this software in source and/or binary
- * form. No title or ownership is transferred hereby.
- *
- * 1) Any source code used, modified or distributed must reproduce and
- *    retain this copyright notice and list of conditions as they appear in
- *    the source file.
- *
- * 2) No right is granted to use any trade name, trademark, or logo of
- *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
- *    used to endorse or promote products derived from this software
- *    without the prior written permission of Broadcom Corporation.
- *
- * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
- *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
- *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
- *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
- *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
- *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef ELF_H
-#define ELF_H
-
-#include "port.h"
-
-/* Elf types */
-typedef uint8_t  Elf_Byte;
-
-typedef uint16_t Elf32_Half;
-typedef uint32_t Elf32_Word;
-typedef  int32_t Elf32_Sword;
-typedef uint32_t Elf32_Off;
-typedef uint32_t Elf32_Addr;
-
-typedef uint16_t Elf64_Quarter;
-typedef uint32_t Elf64_Half;
-typedef  int32_t Elf64_Shalf;
-typedef uint64_t Elf64_Word;
-typedef  int64_t Elf64_Sword;
-typedef uint64_t Elf64_Addr;
-typedef uint64_t Elf64_Off;
-
-
-/* ELF Header */
-#define EI_NIDENT    16
-
-/* Quick rant: Why, oh why, do these all have to start with e_?  Isn't
-   it enough to see they're elements of an Ehdr struct?  Maybe there's
-   a worldwide conspiracy to increase the number of 'e's in existance. 
-   The truth is out there, and I'm REALLY tired right now  - JDC */
-
-typedef struct {
-	Elf_Byte       e_ident[EI_NIDENT] ;   /* ID.  Elf0x7f+              */
-	Elf32_Half     e_type             ;   /* File type                  */
-	Elf32_Half     e_machine          ;   /* Machine type               */
-	Elf32_Word     e_version          ;   /* Version (Duh!)             */
-	Elf32_Addr     e_entry            ;   /* Execution entry point      */
-	Elf32_Off      e_phoff            ;   /* Program header offset      */
-	Elf32_Off      e_shoff            ;   /* Section header offset      */
-	Elf32_Word     e_flags            ;   /* Processor flags            */
-	Elf32_Half     e_ehsize           ;   /* Ehder size                 */
-	Elf32_Half     e_phentsize        ;   /* Prog header entry size     */
-	Elf32_Half     e_phnum            ;   /* Prog header count          */
-	Elf32_Half     e_shentsize        ;   /* Section header entry size  */
-	Elf32_Half     e_shnum            ;   /* Number of section headers  */
-	Elf32_Half     e_shstrndx         ;   /* String table index         */
-} Elf32_Ehdr;
-
-
-typedef struct {
-	Elf_Byte       e_ident[EI_NIDENT] ;   /* ID.  Elf0x7f+              */
-	Elf64_Quarter  e_type             ;   /* File type                  */
-	Elf64_Quarter  e_machine          ;   /* Machine type               */
-	Elf64_Half     e_version          ;   /* Version (Duh!)             */
-	Elf64_Addr     e_entry            ;   /* Execution entry point      */
-	Elf64_Off      e_phoff            ;   /* Program header offset      */
-	Elf64_Off      e_shoff            ;   /* Section header offset      */
-	Elf64_Half     e_flags            ;   /* Processor flags            */
-	Elf64_Quarter  e_ehsize           ;   /* Ehder size                 */
-	Elf64_Quarter  e_phentsize        ;   /* Prog header entry size     */
-	Elf64_Quarter  e_phnum            ;   /* Prog header count          */
-	Elf64_Quarter  e_shentsize        ;   /* Section header entry size  */
-	Elf64_Quarter  e_shnum            ;   /* Number of section headers  */
-	Elf64_Quarter  e_shstrndx         ;   /* String table index         */
-} Elf64_Ehdr;
-
-
-/* e_ident offsets */
-#define EI_MAG0            0                  /* File identification        */
-#define EI_MAG1            1                  /* File identification        */
-#define EI_MAG2            2                  /* File identification        */
-#define EI_MAG3            3                  /* File identification        */
-#define EI_CLASS           4                  /* Class (Duh!)               */
-#define EI_DATA            5                  /* Encoding                   */
-#define EI_VERSION         6                  /* Version                    */
-#define EI_PAD             7                  /* Start of padding           */
-
-/* e_ident magic cookie */
-#define ELFMAG0         0x7f
-#define ELFMAG1          'E'
-#define ELFMAG2          'L'
-#define ELFMAG3          'F'
-#define ELFMAG     "\177ELF"
-
-/* e_ident[EI_CLASS] values */
-#define ELFCLASSNONE       0
-#define ELFCLASS32         1
-#define ELFCLASS64         2                  
-
-/* e_ident[EI_DATA] values */
-#define ELFDATANONE        0                  /* straight out!              */
-#define ELFDATA2LSB        1                  /* little-endian              */
-#define ELFDATA2MSB        2                  /* big-endian                 */
-
-/* e_type values */
-#define ET_NONE            0                  /* Go away!                   */
-#define ET_REL             1                  /* Relocatable                */
-#define ET_EXEC            2                  /* Executable                 */
-#define ET_DYN             3                  /* Shared object              */
-#define ET_CORE            4                  /* Core (Not Arm)             */
-#define ET_LOPROC     0xff00                  /* Processor specific         */
-#define ET_HIPROC     0xffff                  /* Processor specific         */
-
-
-typedef struct {
-	Elf32_Word     p_type             ;   /* Segment type               */
-	Elf32_Off      p_offset           ;   /* Offset to segment data     */
-	Elf32_Addr     p_vaddr            ;   /* Virt addr of segment       */
-	Elf32_Addr     p_paddr            ;   /* Ignored segment phys addr  */
-	Elf32_Word     p_filesz           ;   /* Segment file image size    */
-	Elf32_Word     p_memsz            ;   /* Segment memory image size  */
-	Elf32_Word     p_flags            ;   /* Flags for segment          */
-	Elf32_Word     p_align            ;   /* Segment alignment enforced */
-} Elf32_Phdr;
-
-typedef struct {
-	Elf64_Half     p_type             ;   /* Segment type               */
-	Elf64_Half     p_flags            ;   /* Flags for segment          */
-	Elf64_Off      p_offset           ;   /* Offset to segment data     */
-	Elf64_Addr     p_vaddr            ;   /* Virt addr of segment       */
-	Elf64_Addr     p_paddr            ;   /* Ignored segment phys addr  */
-	Elf64_Word     p_filesz           ;   /* Segment file image size    */
-	Elf64_Word     p_memsz            ;   /* Segment memory image size  */
-	Elf64_Word     p_align            ;   /* Segment alignment enforced */
-} Elf64_Phdr;
-
-/* p_type values */
-#define PT_NULL            0                  /* Ignore                     */
-#define PT_LOAD            1                  /* Loadable segment           */
-#define PT_DYNAMIC         2                  /* Dynamic linking info       */
-#define PT_INTERP          3                  /* Program interpreter        */
-#define PT_NOTE            4                  /* Auxilliary info location   */
-#define PT_SHLIB           5                  /* Reserved                   */
-#define PT_PHDR            6                  /* Location of phdr table (?) */
-#define PT_LOPROC 0x70000000                  /* Proc specific range low    */
-#define PT_HIPROV 0x7fffffff                  /* Proc specific range high   */
-
-/* p_flags vaules  (Not related to PFLAG...:) */
-#define PHP_X            0x1                  /* Execute                    */
-#define PHP_W            0x2                  /* Write                      */
-#define PHP_R            0x4                  /* Read                       */
-
-#endif
diff -wurN orig/loader/include/getfile.h debian/loader/include/getfile.h
--- orig/loader/include/getfile.h	2003-05-30 02:42:38.000000000 +0200
+++ debian/loader/include/getfile.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,60 +0,0 @@
-/* $Id: getfile.h,v 1.6 2003/05/30 00:42:38 cgd Exp $ */
-
-/*
- * Copyright 2001, 2003
- * Broadcom Corporation. All rights reserved.
- *
- * This software is furnished under license and may be used and copied only
- * in accordance with the following terms and conditions.  Subject to these
- * conditions, you may download, copy, install, use, modify and distribute
- * modified or unmodified copies of this software in source and/or binary
- * form. No title or ownership is transferred hereby.
- *
- * 1) Any source code used, modified or distributed must reproduce and
- *    retain this copyright notice and list of conditions as they appear in
- *    the source file.
- *
- * 2) No right is granted to use any trade name, trademark, or logo of
- *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
- *    used to endorse or promote products derived from this software
- *    without the prior written permission of Broadcom Corporation.
- *
- * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
- *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
- *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
- *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
- *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
- *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _GETFILE_H
-#define _GETFILE_H
-
-#include "port.h"
-
-typedef enum {
-	GF_SEEK_SET,
-	GF_SEEK_CUR
-} file_handler_whence_t;
-
-
-typedef struct {
-	void *(*open)(char *loc);
-	int32_t (*seek)(void *private, int32_t ofs, file_handler_whence_t whence);
-	int32_t (*read)(void *private, void *buf, int32_t amount);
-	void (*close)(void *private);
-} file_ops_t;
-
-
-int file_handler_add(file_ops_t *ops);
-void file_handler_del(file_ops_t *ops);
-file_ops_t *file_handler_find(char *name, void **data);
-void file_handler_close(file_ops_t *ops,void *priv);
-
-
-#endif
diff -wurN orig/loader/include/parse_config.h debian/loader/include/parse_config.h
--- orig/loader/include/parse_config.h	2003-05-30 02:42:38.000000000 +0200
+++ debian/loader/include/parse_config.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,53 +0,0 @@
-/* $Id: parse_config.h,v 1.4 2003/05/30 00:42:38 cgd Exp $ */
-
-/*
- * Copyright 2001, 2003
- * Broadcom Corporation. All rights reserved.
- *
- * This software is furnished under license and may be used and copied only
- * in accordance with the following terms and conditions.  Subject to these
- * conditions, you may download, copy, install, use, modify and distribute
- * modified or unmodified copies of this software in source and/or binary
- * form. No title or ownership is transferred hereby.
- *
- * 1) Any source code used, modified or distributed must reproduce and
- *    retain this copyright notice and list of conditions as they appear in
- *    the source file.
- *
- * 2) No right is granted to use any trade name, trademark, or logo of
- *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
- *    used to endorse or promote products derived from this software
- *    without the prior written permission of Broadcom Corporation.
- *
- * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
- *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
- *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
- *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
- *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
- *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Parse a config file.  
- */
-
-#ifndef _PARSE_CONFIG_H
-#define _PARSE_CONFIG_H
-
-typedef struct boot_config_struct {
-	char *kernel;
-	char *initrd;
-	char *extra_args;
-	char *root_dev;
-} boot_config_t;
-
-extern boot_config_t *boot_config;
-
-void parse_config_buf(char *buf);
-
-#endif
diff -wurN orig/loader/include/partition.h debian/loader/include/partition.h
--- orig/loader/include/partition.h	2003-05-30 02:42:38.000000000 +0200
+++ debian/loader/include/partition.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,61 +0,0 @@
-/* $Id: partition.h,v 1.3 2003/05/30 00:42:38 cgd Exp $ */
-
-/*
- * Copyright 2001, 2003
- * Broadcom Corporation. All rights reserved.
- *
- * This software is furnished under license and may be used and copied only
- * in accordance with the following terms and conditions.  Subject to these
- * conditions, you may download, copy, install, use, modify and distribute
- * modified or unmodified copies of this software in source and/or binary
- * form. No title or ownership is transferred hereby.
- *
- * 1) Any source code used, modified or distributed must reproduce and
- *    retain this copyright notice and list of conditions as they appear in
- *    the source file.
- *
- * 2) No right is granted to use any trade name, trademark, or logo of
- *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
- *    used to endorse or promote products derived from this software
- *    without the prior written permission of Broadcom Corporation.
- *
- * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
- *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
- *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
- *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
- *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
- *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _PARTITION_H
-#define _PARTITION_H
-
-/*
- *  Routines for dealing with partitions
- */
-
-#include <stdint.h>
-
-typedef struct {
-	unsigned char active;
-	unsigned char start_chs[3];
-	unsigned char id;
-	unsigned char end_chs[3];
-	uint32_t start_sector;
-	uint32_t size;
-} part_entry_t;
-
-
-/* Take a CFE handle and read the partition table, returning
-   the linear offset of the desired partion or -1 for failure
-*/
-int part_get_info(int handle, int partno, part_entry_t *part_info);
-
-
-
-#endif
diff -wurN orig/loader/include/port.h debian/loader/include/port.h
--- orig/loader/include/port.h	2004-07-25 01:46:15.000000000 +0200
+++ debian/loader/include/port.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,65 +0,0 @@
-/* $Id: port.h,v 1.10 2003/11/17 20:54:52 kwalker Exp $ */
-
-/*
- * Copyright 2001, 2003
- * Broadcom Corporation. All rights reserved.
- *
- * This software is furnished under license and may be used and copied only
- * in accordance with the following terms and conditions.  Subject to these
- * conditions, you may download, copy, install, use, modify and distribute
- * modified or unmodified copies of this software in source and/or binary
- * form. No title or ownership is transferred hereby.
- *
- * 1) Any source code used, modified or distributed must reproduce and
- *    retain this copyright notice and list of conditions as they appear in
- *    the source file.
- *
- * 2) No right is granted to use any trade name, trademark, or logo of
- *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
- *    used to endorse or promote products derived from this software
- *    without the prior written permission of Broadcom Corporation.
- *
- * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
- *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
- *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
- *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
- *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
- *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef PORT_H
-#define PORT_H
-
-#ifdef __linux__
-#include <stdint.h>
-#else /* !__linux__ */
-typedef   unsigned char         uint8_t;
-typedef     signed char          int8_t;
-typedef   unsigned short       uint16_t;
-typedef     signed short        int16_t; 
-typedef   unsigned int         uint32_t;
-typedef     signed int          int32_t;
-typedef   unsigned long long   uint64_t;
-typedef     signed long long    int64_t;
-
-#define unsigned signed		/* Kludge to get unsigned size-shaped type. */
-typedef __SIZE_TYPE__ intptr_t;
-#undef unsigned
-typedef __SIZE_TYPE__ uintptr_t;
-
-#define UINT64_C(arg) (arg ## ULL)
-#define UINT32_MAX (0xffffffffU)
-
-#endif /* __linux__ */
-
-
-uint16_t port_swap_16(uint16_t src);
-uint32_t port_swap_32(uint32_t src);
-uint64_t port_swap_64(uint64_t src);
-
-#endif
diff -wurN orig/loader/include/tftp_fileops.h debian/loader/include/tftp_fileops.h
--- orig/loader/include/tftp_fileops.h	2003-05-30 02:42:38.000000000 +0200
+++ debian/loader/include/tftp_fileops.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,42 +0,0 @@
-/* $Id: tftp_fileops.h,v 1.4 2003/05/30 00:42:38 cgd Exp $ */
-
-/*
- * Copyright 2001, 2003
- * Broadcom Corporation. All rights reserved.
- *
- * This software is furnished under license and may be used and copied only
- * in accordance with the following terms and conditions.  Subject to these
- * conditions, you may download, copy, install, use, modify and distribute
- * modified or unmodified copies of this software in source and/or binary
- * form. No title or ownership is transferred hereby.
- *
- * 1) Any source code used, modified or distributed must reproduce and
- *    retain this copyright notice and list of conditions as they appear in
- *    the source file.
- *
- * 2) No right is granted to use any trade name, trademark, or logo of
- *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
- *    used to endorse or promote products derived from this software
- *    without the prior written permission of Broadcom Corporation.
- *
- * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
- *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
- *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
- *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
- *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
- *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _TFTP_FILEOPS_H
-#define _TFTP_FILEOPS_H
-
-#include "getfile.h"
-
-extern file_ops_t tftp_ops;
-
-#endif
diff -wurN orig/loader/init.S debian/loader/init.S
--- orig/loader/init.S	2003-05-30 02:42:37.000000000 +0200
+++ debian/loader/init.S	2004-07-25 14:10:59.000000000 +0200
@@ -1,43 +1,48 @@
-/* $Id: init.S,v 1.4 2003/05/30 00:42:37 cgd Exp $ */
+#include <regdef.h>
 
-/*
- * Copyright 2001, 2003
- * Broadcom Corporation. All rights reserved.
- *
- * This software is furnished under license and may be used and copied only
- * in accordance with the following terms and conditions.  Subject to these
- * conditions, you may download, copy, install, use, modify and distribute
- * modified or unmodified copies of this software in source and/or binary
- * form. No title or ownership is transferred hereby.
- *
- * 1) Any source code used, modified or distributed must reproduce and
- *    retain this copyright notice and list of conditions as they appear in
- *    the source file.
- *
- * 2) No right is granted to use any trade name, trademark, or logo of
- *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
- *    used to endorse or promote products derived from this software
- *    without the prior written permission of Broadcom Corporation.
- *
- * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
- *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
- *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
- *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
- *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
- *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-.globl entry
 .text
+	.globl	__start
+	.ent	__start
+__start:
+	# Set up gp (for PIC code)
+	.frame	fp, 32, ra
+ 	.set noreorder
+	bltzal	zero, 1f
+	 nop
+1:
+	.cpload ra
+	.set reorder
+
+	# Set up sp
+# Already done by firmware?
+#	la	sp, _stack_start - 32
+	addiu	sp, -32
+	sw	ra, 20(sp)
+	.cprestore 16
+	move	fp, sp
+
+	# Clear .bss before compiler generated code uses it.
+	la	t0, _fbss
+	la	t1, _end
+clearbss:
+	sw	zero, (t0)
+	addiu	t0, 4
+	bne	t0, t1, clearbss
+
+	la	t9, sibylmain
+	jalr	t9
+
+	# If we ever return, jump to the reset vector.
+	lw	t9, 0xbfc00000
+	jalr	t9
+	.end	__start
+
+
+
+
 	
 
 	
-entry:
 	/* Grumble grumble.  This wouldn't be necessary,
 	   but the abi expects the address of the function
 	   to be in $t9.  So we do that for start() here
diff -wurN orig/loader/instimage.c debian/loader/instimage.c
--- orig/loader/instimage.c	2003-05-30 02:42:37.000000000 +0200
+++ debian/loader/instimage.c	2004-07-25 14:10:59.000000000 +0200
@@ -39,18 +39,15 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <linux/unistd.h>
-
-#define le_to_cpu32(val) (val)
-
-typedef unsigned int u32;
+#include "port.h"
 
 typedef struct {
-	unsigned char active;
-	unsigned char start_chs[3];
-	unsigned char id;
-	unsigned char end_chs[3];
-	u32 start_sector;
-	u32 size;
+	uint8_t active;
+	uint8_t start_chs[3];
+	uint8_t id;
+	uint8_t end_chs[3];
+	uint32_t start_sector;
+	uint32_t size;
 } part_entry_t;
 
 #define VERSION_MAJOR 0
@@ -119,8 +116,9 @@
 	}
 }
 
-static int read_table(int fd, int *entry_num, unsigned long ext_part_sector, unsigned long sector_offset, 
-	       unsigned long *start_sector, unsigned long *size)
+static int read_table(int fd, int *entry_num, uint32_t ext_part_sector,
+		      uint32_t sector_offset, uint32_t *start_sector,
+		      uint32_t *size)
 {
 	int i;
 	part_entry_t entry;
diff -wurN orig/loader/ld.script debian/loader/ld.script
--- orig/loader/ld.script	2003-05-30 02:42:37.000000000 +0200
+++ debian/loader/ld.script	2004-07-25 14:10:59.000000000 +0200
@@ -33,7 +33,7 @@
  */
 
 OUTPUT_ARCH(mips)
-ENTRY(entry)
+ENTRY(__start)
 /* Do we need any of these for elf?
    __DYNAMIC = 0;    */
 SECTIONS
diff -wurN orig/loader/lib/c/libc.c debian/loader/lib/c/libc.c
--- orig/loader/lib/c/libc.c	2003-05-30 02:42:39.000000000 +0200
+++ debian/loader/lib/c/libc.c	2004-07-25 14:10:59.000000000 +0200
@@ -139,7 +139,7 @@
 	}
 }
 
-void lib_vprintf(char *format, va_list arg)
+void lib_vprintf(const char *format, va_list arg)
 {
 	char c;
 	while ((c = *format++) != '\0') {
@@ -262,7 +262,7 @@
 	}
 }
 
-void lib_printf(char *fmt, ...)
+void lib_printf(const char *fmt, ...)
 {
 	va_list ap;
 	va_start(ap, fmt);
@@ -270,9 +270,6 @@
 	va_end(ap);
 }
 
-
-
-
 void *lib_malloc(unsigned int amount)
 {
 	unsigned int cur_block_size;
@@ -355,9 +352,9 @@
 	return s;
 }
 
-int lib_memcmp(void *s1, void *s2, unsigned int n)
+int lib_memcmp(const void *s1, const void *s2, unsigned int n)
 {
-	unsigned char *tmp1 = s1, *tmp2 = s2;
+	const unsigned char *tmp1 = s1, *tmp2 = s2;
 	while (n--) {
 		if (*tmp1 < *tmp2) {
 			return -1;
@@ -375,7 +372,7 @@
 	lib_memset(s, 0, n);
 }
 
-void *lib_memcpy(void *dest, void *src, unsigned int n)
+void *lib_memcpy(void *dest, const void *src, unsigned int n)
 {
 	unsigned char *s1 = (unsigned char *)dest; 
 	unsigned char *s2 = (unsigned char *)src;
@@ -387,7 +384,7 @@
 	return dest;
 }
 
-char *lib_strncpy(char *dest, char *src, unsigned int amount)
+char *lib_strncpy(char *dest, const char *src, unsigned int amount)
 {
 	char *retval = dest;
 	while (amount && *src) {
@@ -402,14 +399,14 @@
 	return retval;
 }
 
-int lib_strlen(char *s) 
+int lib_strlen(const char *s) 
 {
 	int retval = 0;
 	while (*s++) retval++;
 	return retval;
 }
 
-char *lib_strcpy(char *dest, char *src)
+char *lib_strcpy(char *dest, const char *src)
 {
 	char *tmp = dest;
 	while (*src) {
@@ -421,7 +418,7 @@
 	return dest;
 }
 
-int   lib_strnlen(char *str, unsigned int maxlen)
+int lib_strnlen(const char *str, unsigned int maxlen)
 {
 	unsigned int retval = 0;
 	while ((retval < maxlen) 
@@ -441,7 +438,7 @@
 		
 }
 
-char *lib_strdup(char *src)
+char *lib_strdup(const char *src)
 {
 	char *retval = lib_malloc(lib_strlen(src)+1);
 	if (!retval) {
@@ -451,7 +448,7 @@
 	return retval;
 }
 
-char *lib_strchr(char *str,char c)
+const char *lib_strchr(const char *str, char c)
 {
     while (*str && (*str != c)) str++;
     if (*str) return str;
@@ -495,7 +492,7 @@
 		|| (c >= 'a' && (c <= 'z'));
 }
 
-int lib_strncmp(char *s1, char *s2, unsigned long n)
+int lib_strncmp(const char *s1, const char *s2, unsigned long n)
 {
 	while (n && *s1 && (*s1 == *s2)) {
 		n--;
@@ -512,7 +509,7 @@
 	return 0;
 }
 
-int lib_strcmp(char *s1, char *s2)
+int lib_strcmp(const char *s1, const char *s2)
 {
 //	if (!(s1 && s2)) {
 //	lib_printf("strcmp\n");
@@ -520,7 +517,7 @@
 	return lib_strncmp(s1, s2, UINT32_MAX);
 }
 
-char *lib_strcat(char *s1, char *s2)
+char *lib_strcat(char *s1, const char *s2)
 {
 	char *tmp = s1 + lib_strlen(s1);
 	lib_strcpy(tmp, s2);
@@ -685,7 +682,7 @@
 	return retval;
 }
 
-void lib_die(char *fmt, ...)
+void lib_die(const char *fmt, ...)
 {
 	va_list ap;
 	va_start(ap, fmt);
@@ -711,7 +708,7 @@
 		   (int)(addr & 0xff));
 }
 
-int lib_atoi(char *str) 
+int lib_atoi(const char *str) 
 {
 	int retval = 0;
 	while ((*str >= '0') && ((*str <= '9'))) {
diff -wurN orig/loader/lib/c/libc.h debian/loader/lib/c/libc.h
--- orig/loader/lib/c/libc.h	2003-05-30 02:42:39.000000000 +0200
+++ debian/loader/lib/c/libc.h	2004-07-25 14:10:59.000000000 +0200
@@ -51,24 +51,23 @@
  */
 void lib_init(void *backend_data);
 
-
 void *lib_malloc(unsigned int size);
 void  lib_free(void *alloc);
-void  lib_vprintf(char *fmt, va_list ap);
-void  lib_printf(char *fmt, ...);
+void lib_vprintf(const char *fmt, va_list ap);
+void lib_printf(const char *fmt, ...);
 void *lib_memset(void *s, int c, unsigned int n);
 void  lib_bzero(void *s, unsigned int n);
-void *lib_memcpy(void *dest, void *src, unsigned int n);
-int   lib_memcmp(void *s1, void *s2, unsigned int n);
-char *lib_strncpy(char *dest, char *src, unsigned int n);
-char *lib_strcpy(char *dest, char *src);
-char *lib_strdup(char *src);
-char *lib_strchr(char *src,char c);
-int   lib_strlen(char *str);
-int   lib_strncmp(char *s1, char *s2, unsigned long n);
-int   lib_strcmp(char *s1, char *s2);
-char *lib_strcat(char *s1, char *s2);
-int   lib_strnlen(char *str, unsigned int maxlen);
+void *lib_memcpy(void *dest, const void *src, unsigned int n);
+int lib_memcmp(const void *s1, const void *s2, unsigned int n);
+char *lib_strncpy(char *dest, const char *src, unsigned int n);
+char *lib_strcpy(char *dest, const char *src);
+char *lib_strdup(const char *src);
+const char *lib_strchr(const char *src, char c);
+int lib_strlen(const char *str);
+int lib_strncmp(const char *s1, const char *s2, unsigned long n);
+int lib_strcmp(const char *s1, const char *s2);
+char *lib_strcat(char *s1, const char *s2);
+int lib_strnlen(const char *str, unsigned int maxlen);
 void  lib_usleep(unsigned long usec);
 void  lib_putc(char c);
 void  lib_exit(void);
@@ -86,10 +85,8 @@
 uint32_t lib_parse_ip(char *str);
 void  lib_print_ip(uint32_t ip);
 void  lib_print_mac_addr(uint64_t mac_addr);
-int lib_atoi(char *str);
-
-void lib_die(char *msg, ...);
-
+int lib_atoi(const char *str);
 
+void lib_die(const char *msg, ...);
 
 #endif
diff -wurN orig/loader/lib/c/Makefile debian/loader/lib/c/Makefile
--- orig/loader/lib/c/Makefile	2003-05-28 08:35:35.000000000 +0200
+++ debian/loader/lib/c/Makefile	2004-07-25 14:10:59.000000000 +0200
@@ -39,10 +39,25 @@
 all: $(LIBNAME)
 	@echo "Built standalone library"
 
-include ../../make.config
+CFLAGS   = -Wall -g  -O0 -fno-builtin
+
+%.o: %.c Makefile 
+	$(CC) -MMD -c -o $*.o $(CPPFLAGS) $(CFLAGS) $<
+
+%.o: %.S
+	$(CC) -MMD -c -o $*.o $(CPPFLAGS) $(CFLAGS) $<
+
+%.d: %.c 
+	$(CC) -MM $(CPPFLAGS) $< > $*.d
+
+
+.PHONY: clean common_clean
+
+common_clean:
+	rm -f *.o *~ *.d *\#
 
 # Preprocessor flags we need
-CPPFLAGS += -I../cfe -I ../../include
+CPPFLAGS += -I../cfe -I../..
 CFLAGS   += 
 
 
@@ -61,6 +76,5 @@
 	rm -f $(LIBNAME)
 
 ifneq ($(MAKECMDGOALS),clean)
-sinclude $(ALL_OBJS:.o=.d)
+include $(ALL_OBJS:.o=.d)
 endif
-
diff -wurN orig/loader/lib/cfe/Makefile debian/loader/lib/cfe/Makefile
--- orig/loader/lib/cfe/Makefile	2003-05-28 08:35:36.000000000 +0200
+++ debian/loader/lib/cfe/Makefile	2004-07-25 14:10:59.000000000 +0200
@@ -33,9 +33,24 @@
 LIBNAME = libcfe.a
 all: $(LIBNAME)
 
-include ../../make.config
+CFLAGS   = -Wall -g  -O0 -fno-builtin
 
-CPPFLAGS += -I../../include
+%.o: %.c Makefile 
+	$(CC) -MMD -c -o $*.o $(CPPFLAGS) $(CFLAGS) $<
+
+%.o: %.S
+	$(CC) -MMD -c -o $*.o $(CPPFLAGS) $(CFLAGS) $<
+
+%.d: %.c 
+	$(CC) -MM $(CPPFLAGS) $< > $*.d
+
+
+.PHONY: clean common_clean
+
+common_clean:
+	rm -f *.o *~ *.d *\#
+
+CPPFLAGS += -I../..
 CFLAGS   += 
 
 CFILES = \
diff -wurN orig/loader/lib/Makefile debian/loader/lib/Makefile
--- orig/loader/lib/Makefile	2003-05-28 08:35:34.000000000 +0200
+++ debian/loader/lib/Makefile	2004-07-25 14:10:59.000000000 +0200
@@ -32,17 +32,16 @@
 
 SUBDIRS = c net cfe
 
-all:
-	for dir in $(SUBDIRS);        \
-	  do                          \
-	    (cd $$dir && $(MAKE) all);\
-	  done
-
-clean:
-	for dir in $(SUBDIRS);        \
-	  do                          \
-	    (cd $$dir && $(MAKE) clean);\
-	  done
-
-
+.PHONY: all
+all: $(SUBDIRS)
 
+.PHONY: $(SUBDIRS)
+$(SUBDIRS):
+	$(MAKE) -C $@ all
+
+.PHONY: clean
+clean: $(patsubst %,clean_%,$(SUBDIRS))
+
+.PHONY: $(patsubst %,clean_%,$(SUBDIRS))
+$(patsubst %,clean_%,$(SUBDIRS)):
+	$(MAKE) -C $(patsubst clean_%,%,$@) clean
diff -wurN orig/loader/lib/net/Makefile debian/loader/lib/net/Makefile
--- orig/loader/lib/net/Makefile	2003-05-28 08:35:37.000000000 +0200
+++ debian/loader/lib/net/Makefile	2004-07-25 14:10:59.000000000 +0200
@@ -40,9 +40,24 @@
 all: $(LIBNAME)
 	@echo "Built network library"
 
-include ../../make.config
+CFLAGS   = -Wall -g  -O0 -fno-builtin
 
-CPPFLAGS += -I../c -I../cfe -I../../include
+%.o: %.c Makefile 
+	$(CC) -MMD -c -o $*.o $(CPPFLAGS) $(CFLAGS) $<
+
+%.o: %.S
+	$(CC) -MMD -c -o $*.o $(CPPFLAGS) $(CFLAGS) $<
+
+%.d: %.c 
+	$(CC) -MM $(CPPFLAGS) $< > $*.d
+
+
+.PHONY: clean common_clean
+
+common_clean:
+	rm -f *.o *~ *.d *\#
+
+CPPFLAGS += -I../c -I../cfe -I../..
 
 CFILES = \
 	arp.c                 \
diff -wurN orig/loader/main.c debian/loader/main.c
--- orig/loader/main.c	2004-07-25 01:46:15.000000000 +0200
+++ debian/loader/main.c	2004-07-25 14:10:59.000000000 +0200
@@ -32,6 +32,9 @@
  *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdlib.h>
+#include <stdint.h>
+
 #include "libc.h"
 #include "cfe_api.h"
 #include "elf.h"
@@ -43,10 +46,10 @@
 #include "port.h"
 
 typedef struct {
-	unsigned char active;
-	unsigned char start_chs[3];
-	unsigned char id;
-	unsigned char end_chs[3];
+	uint8_t active;
+	uint8_t start_chs[3];
+	uint8_t id;
+	uint8_t end_chs[3];
 	uint32_t start_sector;
 	uint32_t size;
 } part_entry_t;
@@ -54,47 +57,26 @@
 /* Don't set this too large; we do have to allocate a buffer this size */
 #define MAX_CONFIG_FILE_SIZE (32 * 1024)
 
-#define PAGE_SIZE (4*1024)
+#define PAGE_SIZE (1 << 12)
 
-static void elf32_ehdr_swap(Elf32_Ehdr *ehdr_ptr);
+static void init_libs(char *,int);
+static void uninit_libs(void);
+extern void my_gets(char *,int,int);
+static void fatal_error(char *str);
 static int get_config_file(char *loc, char *buf, int32_t buf_size);
-static void elf32_phdr_swap(Elf32_Phdr *phdr_ptr);
 static void *load_kernel(char *loc);
 static int32_t load_ramdisk(char *loc, char *mem_start);
-static void zero_bss(void);
-extern int _fbss;
-extern int _end;
+
 typedef void kernel_entry_fn_t(int, unsigned char **, char **, long *);
-kernel_entry_fn_t *kernel_entry;
+static kernel_entry_fn_t *kernel_entry;
 
 static int swap;
 
-#ifndef SILENT
-#define msg(str) lib_printf str
-#else
-#define msg(str) do {} while(0)
-#endif
-
 #ifdef CONFIG_BLOCKDEV
 extern file_ops_t ext2_ops;
 #endif
 
-
-static void init_libs(char *,int);
-static void uninit_libs(void);
-
-extern void gets(char *,int,int);
-
-static void fatal_error(char *str);
-
-/* 
- * We end up here after init.S is done setting
- * up some sane environment .  
- * Massive trickery here -- we actually *fall into* this
- * routine, so main.c must be linked immediately after init.S.
- * gross!
- */
-void start(long handle, long reserved, long ept, long eptseal)
+void sibylmain(long handle, long reserved, long ept, long eptseal)
 {
     char *tmp;
     char *config_file;
@@ -103,7 +85,6 @@
     int bootdev_type;
     long *linux_args;
 
-    zero_bss();
     cfe_init(handle, ept);
     lib_init(0);
     lib_printf("SiByte Loader, version %i.%i.%i\n", 
@@ -176,7 +157,7 @@
     if (config_file[0] == 0) {
 	lib_printf("BOOT_CONFIG not defined.\n"
 		   "Enter config file location: ");
-	gets(config_file,128,0);
+	my_gets(config_file,128,0);
 	}
 
     config_file[127] = 0;
@@ -187,10 +168,11 @@
     lib_printf("Getting configuration file %s...\n", config_file);
 
     for (;;) {
-	if (get_config_file(config_file, tmp, MAX_CONFIG_FILE_SIZE) == 0) break;
+	if (!get_config_file(config_file, tmp, MAX_CONFIG_FILE_SIZE))
+	    break;
 	lib_printf("Failed to get configuration file.\n"
 	    "Enter configuration file location: ");
-	gets(config_file,128,0);
+	my_gets(config_file,128,0);
 	}
     lib_printf("Config file retrieved.\n");
     parse_config_buf(tmp);
@@ -256,14 +238,12 @@
     kernel_entry(0, 0, 0, linux_args);
 }
 
-
-void fatal_error(char *str)
+static void fatal_error(char *str)
 {
     uninit_libs();
     lib_die(str);
 }
 
-
 static void init_libs(char *bootdev_name,int bootdev_type)
 {
 #ifdef CONFIG_NETWORK
@@ -315,6 +295,13 @@
 #endif
 }
 
+static void uninit_libs(void)
+{
+#ifdef CONFIG_NETWORK
+	net_uninit();
+#endif
+}
+
 static int get_config_file(char *loc, char *buf, int32_t buf_size)
 {
     file_ops_t *ops;
@@ -322,17 +309,14 @@
     int32_t file_len;
 
     ops = file_handler_find(loc, &ops_data);
-
     if (!ops) {
 	lib_printf("No handler found for this: %s\n", loc);
 	return -1;
 	}
 
     file_len = ops->read(ops_data, buf, buf_size);
-
-    if (file_len == MAX_CONFIG_FILE_SIZE) {
+    if (file_len >= buf_size)
 	fatal_error("Config file too large\n");
-	}
 
     file_handler_close(ops,ops_data);
 
@@ -401,16 +385,18 @@
 	phdr_ptr->p_align = port_swap_64(phdr_ptr->p_align);
 }
 
-
 static void *load_kernel_elf32(Elf32_Ehdr *ehdr,
 			       file_ops_t *ops,
 			       void *ops_data)
 {
 	unsigned long initrd_start_loc = 0;
 	Elf32_Phdr *phdrs;
-	int32_t readlen;
+	uint32_t readlen;
 	int i;
 
+	if (swap)
+		elf32_ehdr_swap(ehdr);
+
 	phdrs = lib_malloc(sizeof(Elf32_Phdr) * ehdr->e_phnum);
 	if (!phdrs) {
 		fatal_error("Out of memory");
@@ -454,7 +440,6 @@
 		}
 	}
 	lib_printf("done\n");
-	file_handler_close(ops,ops_data);
 	kernel_entry = (kernel_entry_fn_t *) (
 #ifndef __linux__
 		(int64_t)
@@ -469,7 +454,7 @@
 	unsigned long initrd_start_loc = 0;
 	Elf64_Ehdr ehdr;
 	Elf64_Phdr *phdrs;
-	int32_t readlen;
+	uint32_t readlen;
 	int i;
 
 	ops->seek(ops_data, 0, GF_SEEK_SET);
@@ -477,9 +462,9 @@
 	if (readlen != sizeof(ehdr)) {
 		lib_die("ELF header read failed\n");
 	}
-
 	if (swap)
 		elf64_ehdr_swap(&ehdr);
+
 	phdrs = lib_malloc(sizeof(Elf64_Phdr) * ehdr.e_phnum);
 	if (!phdrs) {
 		fatal_error("Out of memory");
@@ -521,7 +506,6 @@
 		}
 	}
 	lib_printf("done\n");
-	file_handler_close(ops,ops_data);
 	kernel_entry = (kernel_entry_fn_t *) (
 #ifndef __linux__
 		(int64_t)
@@ -540,6 +524,7 @@
 	void *ops_data;
 	Elf32_Ehdr ehdr;
 	int32_t readlen;
+	void *ret = NULL;
 
 	ops = file_handler_find(loc, &ops_data);
 	if (!ops) {
@@ -550,23 +535,24 @@
 	if (readlen != sizeof(ehdr)) {
 		lib_die("ELF header read failed\n");
 	}
-	if (lib_memcmp(ehdr.e_ident, ELFMAG, 4)) {
-		fatal_error("Elf magic number not present in kernel\n");
-	}
 #ifdef __MIPSEL__
 	swap = (ehdr.e_ident[EI_DATA] == ELFDATA2MSB);
 #else
 	swap = (ehdr.e_ident[EI_DATA] == ELFDATA2LSB);
 #endif
-	if (swap)
-		elf32_ehdr_swap(&ehdr);
-	if (ehdr.e_ident[EI_CLASS] == ELFCLASS32) {
-		return load_kernel_elf32(&ehdr, ops, ops_data);
-	} else {
-//		fatal_error("Elf64 not supported");
-		return load_kernel_elf64(ops, ops_data);
-	}
-	return 0;
+	if (lib_memcmp(ehdr.e_ident, ELFMAG, 4))
+		fatal_error("ELF magic number not present in kernel\n");
+
+	if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
+		ret = load_kernel_elf32(&ehdr, ops, ops_data);
+	else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64)
+		ret = load_kernel_elf64(ops, ops_data);
+	else
+		fatal_error("Unknown ELF class in kernel\n");
+
+	file_handler_close(ops, ops_data);
+
+	return ret;
 }
 
 static int32_t load_ramdisk(char *loc, char *mem_start)
@@ -585,23 +571,6 @@
 	return readlen;
 }
 
-static void uninit_libs(void)
-{
-#ifdef CONFIG_NETWORK
-	net_uninit();
-#endif
-}
-
-static void zero_bss(void)
-{
-    int *ptr,*eptr;
-
-    ptr = &_fbss;
-    eptr = &_end;
-
-    while (ptr < eptr) *ptr++ = 0;
-}
-
 #ifdef CONFIG_BLOCKDEV
 /* libext2fs wants this defined when you compile with -O0.  Must
    be inlined at -O2 or some such */
@@ -614,6 +583,7 @@
     lib_strcpy(dest,arg);
     return lib_strlen(dest);
 }
-#endif
-
 
+//void __udivdi3() {};
+//void __umoddi3() {};
+#endif
diff -wurN orig/loader/make.config debian/loader/make.config
--- orig/loader/make.config	2003-05-28 08:35:31.000000000 +0200
+++ debian/loader/make.config	1970-01-01 01:00:00.000000000 +0100
@@ -1,54 +0,0 @@
-# $Id: make.config,v 1.7 2003/05/28 06:35:31 cgd Exp $
-
-# Copyright 2001, 2003
-# Broadcom Corporation. All rights reserved.
-#
-# This software is furnished under license and may be used and copied only
-# in accordance with the following terms and conditions.  Subject to these
-# conditions, you may download, copy, install, use, modify and distribute
-# modified or unmodified copies of this software in source and/or binary
-# form. No title or ownership is transferred hereby.
-#
-# 1) Any source code used, modified or distributed must reproduce and
-#    retain this copyright notice and list of conditions as they appear in
-#    the source file.
-#
-# 2) No right is granted to use any trade name, trademark, or logo of
-#    Broadcom Corporation.  The "Broadcom Corporation" name may not be
-#    used to endorse or promote products derived from this software
-#    without the prior written permission of Broadcom Corporation.
-#
-# 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
-#    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
-#    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
-#    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
-#    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
-#    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-# Global configuration for make
-
-CPPFLAGS = 
-CFLAGS   = -Wall -g  -O0 -fno-builtin
-LDFLAGS  = 
-
-%.o: %.c Makefile 
-	$(CC) -MMD -c -o $*.o $(CPPFLAGS) $(CFLAGS) $<
-
-%.o: %.S
-	$(CC) -MMD -c -o $*.o $(CPPFLAGS) $(CFLAGS) $<
-
-%.d: %.c 
-	$(CC) -MM $(CPPFLAGS) $< > $*.d
-
-
-.PHONY: clean common_clean
-
-common_clean:
-	rm -f *.o *~ *.d *\#
-
-	
diff -wurN orig/loader/Makefile debian/loader/Makefile
--- orig/loader/Makefile	2003-06-27 19:12:48.000000000 +0200
+++ debian/loader/Makefile	2004-07-25 14:10:59.000000000 +0200
@@ -34,36 +34,33 @@
 VERSION_MINOR = 4
 VERSION_MINUTE = 2
 
-DISK_SUPPORT=0
+#DISK_SUPPORT=0
+DISK_SUPPORT=1
 
-all: sibyl sibyl.bin
+all: sibyl.bin
 
-include make.config
-
-CPPFLAGS += -Ilib/c -Ilib/net -Ilib/cfe -I./include -DVERSION_MAJOR=$(VERSION_MAJOR) \
--DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_MINUTE=$(VERSION_MINUTE)
+CFLAGS += -W -Wall -g -O0 -ffreestanding
+CPPFLAGS += -I. -Ilib/c -Ilib/net -Ilib/cfe \
+	-DVERSION_MAJOR=$(VERSION_MAJOR) \
+	-DVERSION_MINOR=$(VERSION_MINOR) \
+	-DVERSION_MINUTE=$(VERSION_MINUTE)
 LDFLAGS  += -Llib/net -Llib/c -Llib/cfe
 
-
-
+OBJCOPY = objcopy
+OBJDUMP = objdump
 
 # all objects built in this directory 
-ALL_OBJS =             \
-	init.o         \
-	main.o         \
-	getfile.o      \
-	parse_config.o \
-	port.o         
+OBJS = init.o main.o malloc.o stringops.o getfile.o parse_config.o port.o
 
 ifeq ($(strip ${DISK_SUPPORT}),1)
-ALL_OBJS += partition.o ext2_fileops.o
-CPPFLAGS += -DCONFIG_BLOCKDEV -I../e2fsprogs/lib/ext2fs -I../e2fsprogs/lib -I../e2fsprogs/include/linux
-DISKLIB = ../e2fsprogs/lib/libembext2fs.a
-LDFLAGS += -L../e2fsprogs/lib -lembext2fs
+OBJS += partition.o ext2_fileops.o
+CPPFLAGS += -DCONFIG_BLOCKDEV -I/usr/include/ext2fs
+LDFLAGS += -lext2fs -lstandalone -lnet -lcfe $$($(CC) -print-libgcc-file-name)
 else
-ALL_OBJS += tftp_fileops.o
+OBJS += tftp_fileops.o
 endif
 
+.PHONY: disk
 disk: sibyl.bin
 	mkbootimage -S 1 sibyl.bin disk.img
 
@@ -75,26 +72,33 @@
 	$(OBJCOPY) --remove-section=reginfo --output-target=binary $^ $@
 
 
-sibyl: $(ALL_OBJS) libs 
-	$(LD) -T ld.script -Map sibyl.map -static -o $@ $(ALL_OBJS) $(LDFLAGS) -lstandalone -lnet -lcfe ${DISKLIB}
+sibyl: $(OBJS) libs
+	$(LD) -T ld.script -Map sibyl.map -static -o $@ $(OBJS) $(LDFLAGS)
 
 instimage: instimage.c Makefile
 	gcc -o instimage instimage.c
 
-../e2fsprogs/lib/libembext2fs.a:
-	(cd ../e2fsprogs && BUILD)
-
 .PHONY: libs
-
 libs:
-	(cd lib && $(MAKE)) 
+	$(MAKE) -C lib
 
+%.o: %.c Makefile
+	$(CC) -MMD -c -o $*.o $(CPPFLAGS) $(CFLAGS) $<
 
-clean: common_clean
-	rm -f sibyl sibyl.bin sibyl.dis sibyl.map instimage
-	(cd lib && $(MAKE) clean)
+%.o: %.S
+	$(CC) -MMD -c -o $*.o $(CPPFLAGS) $(CFLAGS) $<
+
+%.d: %.c
+	$(CC) -MM $(CPPFLAGS) $< > $*.d
+
+%.d: %.S
+	$(CC) -MM $(CPPFLAGS) $< > $*.d
+
+.PHONY: clean
+clean:
+	rm -f *.o *~ *.d *\# sibyl sibyl.bin sibyl.dis sibyl.map instimage
+	$(MAKE) -C lib clean
 
 ifneq ($(MAKECMDGOALS),clean)
-sinclude $(ALL_OBJS:.o=.d)
+include $(OBJS:.o=.d)
 endif
-
diff -wurN orig/loader/malloc.c debian/loader/malloc.c
--- orig/loader/malloc.c	1970-01-01 01:00:00.000000000 +0100
+++ debian/loader/malloc.c	2004-07-25 14:10:59.000000000 +0200
@@ -0,0 +1,16 @@
+#include "libc.h"
+
+void *malloc(unsigned long size)
+{
+	return lib_malloc(size);
+}
+
+void free(void *ptr)
+{
+	lib_free(ptr);
+}
+
+void *realloc(void *ptr, unsigned long size)
+{
+	return 0; /* not supported */
+}
diff -wurN orig/loader/parse_config.c debian/loader/parse_config.c
--- orig/loader/parse_config.c	2003-05-30 02:42:37.000000000 +0200
+++ debian/loader/parse_config.c	2004-07-25 14:10:59.000000000 +0200
@@ -262,6 +262,7 @@
 {
 	char *ptr, *ptr2;
 	char saved_char;
+
 	ptr = buf;
 	skip_whitespace(&ptr);
 	for ( ; *ptr; skip_whitespace(&ptr)) {
@@ -338,7 +339,7 @@
 	}
 }
 
-void gets(char *buf,int buflen,int timeout)
+void my_gets(char *buf, int buflen, int timeout)
 {
     int got_choice;
     int buf_ptr;
@@ -352,7 +353,7 @@
 	char foo;
 	if (timeout && 
 	    (((lib_get_time() - timeout_start)>>20) 
-	     >= timeout)) {
+	     >= (unsigned int)timeout)) {
 	    got_choice = 1;
 	    buf[0] = 0;
 	    }
@@ -409,7 +410,7 @@
 	}
     if (!tmp) {
 	lib_printf("Default configuration %s doesn't exist.  Using"
-		   " %s instead\n", default_name);
+		   " %s instead\n", default_name, config_chain->name);
 	lib_free(default_name);
 	default_name = lib_strdup(config_chain->name);
 	if (!default_name) {
@@ -425,7 +426,7 @@
 	    lib_printf("  %s\n", tmp->name);
 	    }
 	lib_printf("Boot which configuration [%s]: ", default_name);
-	gets(buf,sizeof(buf),timeout);
+	my_gets(buf,sizeof(buf),timeout);
 
 	if (buf[0] == 0) {
 	    prompt = 0;
diff -wurN orig/loader/parse_config.h debian/loader/parse_config.h
--- orig/loader/parse_config.h	1970-01-01 01:00:00.000000000 +0100
+++ debian/loader/parse_config.h	2004-07-25 14:10:59.000000000 +0200
@@ -0,0 +1,53 @@
+/* $Id: parse_config.h,v 1.4 2003/05/30 00:42:38 cgd Exp $ */
+
+/*
+ * Copyright 2001, 2003
+ * Broadcom Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and copied only
+ * in accordance with the following terms and conditions.  Subject to these
+ * conditions, you may download, copy, install, use, modify and distribute
+ * modified or unmodified copies of this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce and
+ *    retain this copyright notice and list of conditions as they appear in
+ *    the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
+ *    used to endorse or promote products derived from this software
+ *    without the prior written permission of Broadcom Corporation.
+ *
+ * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
+ *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
+ *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+ *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
+ *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
+ *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Parse a config file.  
+ */
+
+#ifndef _PARSE_CONFIG_H
+#define _PARSE_CONFIG_H
+
+typedef struct boot_config_struct {
+	char *kernel;
+	char *initrd;
+	char *extra_args;
+	char *root_dev;
+} boot_config_t;
+
+extern boot_config_t *boot_config;
+
+void parse_config_buf(char *buf);
+
+#endif
diff -wurN orig/loader/partition.c debian/loader/partition.c
--- orig/loader/partition.c	2003-05-30 02:42:37.000000000 +0200
+++ debian/loader/partition.c	2004-07-25 14:10:59.000000000 +0200
@@ -33,10 +33,10 @@
  */
 
 #include "partition.h"
+#include "port.h"
 #include "cfe_api.h"
 #include "libc.h"
 
-
 /*
  * Recurse down the current chain of partitions.  Return 0 if found, nonzero otherwise
  */
diff -wurN orig/loader/partition.h debian/loader/partition.h
--- orig/loader/partition.h	1970-01-01 01:00:00.000000000 +0100
+++ debian/loader/partition.h	2004-07-25 14:10:59.000000000 +0200
@@ -0,0 +1,61 @@
+/* $Id: partition.h,v 1.3 2003/05/30 00:42:38 cgd Exp $ */
+
+/*
+ * Copyright 2001, 2003
+ * Broadcom Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and copied only
+ * in accordance with the following terms and conditions.  Subject to these
+ * conditions, you may download, copy, install, use, modify and distribute
+ * modified or unmodified copies of this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce and
+ *    retain this copyright notice and list of conditions as they appear in
+ *    the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
+ *    used to endorse or promote products derived from this software
+ *    without the prior written permission of Broadcom Corporation.
+ *
+ * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
+ *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
+ *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+ *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
+ *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
+ *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _PARTITION_H
+#define _PARTITION_H
+
+/*
+ *  Routines for dealing with partitions
+ */
+
+#include <stdint.h>
+
+typedef struct {
+	unsigned char active;
+	unsigned char start_chs[3];
+	unsigned char id;
+	unsigned char end_chs[3];
+	uint32_t start_sector;
+	uint32_t size;
+} part_entry_t;
+
+
+/* Take a CFE handle and read the partition table, returning
+   the linear offset of the desired partion or -1 for failure
+*/
+int part_get_info(int handle, int partno, part_entry_t *part_info);
+
+
+
+#endif
diff -wurN orig/loader/port.h debian/loader/port.h
--- orig/loader/port.h	1970-01-01 01:00:00.000000000 +0100
+++ debian/loader/port.h	2004-07-25 14:10:59.000000000 +0200
@@ -0,0 +1,93 @@
+/* $Id: port.h,v 1.10 2003/11/17 20:54:52 kwalker Exp $ */
+
+/*
+ * Copyright 2001, 2003
+ * Broadcom Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and copied only
+ * in accordance with the following terms and conditions.  Subject to these
+ * conditions, you may download, copy, install, use, modify and distribute
+ * modified or unmodified copies of this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce and
+ *    retain this copyright notice and list of conditions as they appear in
+ *    the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
+ *    used to endorse or promote products derived from this software
+ *    without the prior written permission of Broadcom Corporation.
+ *
+ * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
+ *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
+ *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+ *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
+ *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
+ *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PORT_H
+#define PORT_H
+
+#ifdef __linux__
+#include <stdint.h>
+#else /* !__linux__ */
+typedef   unsigned char         uint8_t;
+typedef     signed char          int8_t;
+typedef   unsigned short       uint16_t;
+typedef     signed short        int16_t; 
+typedef   unsigned int         uint32_t;
+typedef     signed int          int32_t;
+typedef   unsigned long long   uint64_t;
+typedef     signed long long    int64_t;
+
+#define unsigned signed		/* Kludge to get unsigned size-shaped type. */
+typedef __SIZE_TYPE__ intptr_t;
+#undef unsigned
+typedef __SIZE_TYPE__ uintptr_t;
+
+#define UINT64_C(arg) (arg ## ULL)
+#define UINT32_MAX (0xffffffffU)
+
+#endif /* __linux__ */
+
+
+uint16_t port_swap_16(uint16_t src);
+uint32_t port_swap_32(uint32_t src);
+uint64_t port_swap_64(uint64_t src);
+
+#ifdef __MIPSEL__
+#define cpu_to_le16(foo) (foo)
+#define cpu_to_le32(foo) (foo)
+#define cpu_to_le64(foo) (foo)
+#define cpu_to_be16(foo) port_swap_16(foo)
+#define cpu_to_be32(foo) port_swap_32(foo)
+#define cpu_to_be64(foo) port_swap_64(foo)
+#define le_to_cpu16(foo) (foo)
+#define le_to_cpu32(foo) (foo)
+#define le_to_cpu64(foo) (foo)
+#define be_to_cpu16(foo) port_swap_16(foo)
+#define be_to_cpu32(foo) port_swap_32(foo)
+#define be_to_cpu64(foo) port_swap_64(foo)
+#else
+#define cpu_to_le16(foo) port_swap_16(foo)
+#define cpu_to_le32(foo) port_swap_32(foo)
+#define cpu_to_le64(foo) port_swap_64(foo)
+#define cpu_to_be16(foo) (foo)
+#define cpu_to_be32(foo) (foo)
+#define cpu_to_be64(foo) (foo)
+#define le_to_cpu16(foo) port_swap_16(foo)
+#define le_to_cpu32(foo) port_swap_32(foo)
+#define le_to_cpu64(foo) port_swap_64(foo)
+#define be_to_cpu16(foo) (foo)
+#define be_to_cpu32(foo) (foo)
+#define be_to_cpu64(foo) (foo)
+#endif
+
+#endif
diff -wurN orig/loader/stringops.c debian/loader/stringops.c
--- orig/loader/stringops.c	1970-01-01 01:00:00.000000000 +0100
+++ debian/loader/stringops.c	2004-07-25 14:10:59.000000000 +0200
@@ -0,0 +1,216 @@
+/*
+ * This file is licensed under the terms of the GNU General Public License,
+ * version 2. See the file COPYING in the main directory for details.
+ * 
+ * Slooow, but small string operations, so that we don't have to link lib in.
+ * Originally from linux/lib/string.c, which is
+ *	Copyright (C) 1991, 1992  Linus Torvalds
+ *
+ * Added I/O functions for libcom_err.
+ *
+ *  Copyright (C) 2003,2004  Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
+ */
+
+#include "libc.h"
+
+void *memset(void *s, int c, unsigned long count)
+{
+	return lib_memset(s, c, count);
+}
+
+void *memcpy(void *dest, const void *src, unsigned long count)
+{
+	return lib_memcpy(dest, src, count);
+}
+
+int memcmp(const void *cs, const void *ct, unsigned long count)
+{
+	return lib_memcmp(cs, ct, count);
+}
+
+char *strcpy(char *dest, const char *src)
+{
+	return lib_strcpy(dest, src);
+}
+
+char *strncpy(char *dest, const char *src, int count)
+{
+	return lib_strncpy(dest, src, count);
+}
+
+char *strcat(char *dest, const char *src)
+{
+	return lib_strcat(dest, src);
+}
+
+char *strncat(char *dest, const char *src, int n)
+{
+	char *tmp = dest;
+	while (*dest) dest++;
+	while (n && (*dest++ = *src++) != '\0') n--;
+	if (!n) *dest = 0;
+	return tmp;
+}
+
+int strcmp(const char *cs, const char *ct)
+{
+	return lib_strcmp(cs, ct);
+}
+
+int strncmp(const char *cs, const char *ct, int count)
+{
+	return lib_strncmp(cs, ct, count);
+}
+
+char *strchr(const char *s, int c)
+{
+	for(; *s != (char) c; ++s)
+		if (*s == '\0')
+			return 0;
+	return (char *) s;
+}
+
+char *strrchr(const char *s, int c)
+{
+	const char *p = s + lib_strlen(s);
+	do {
+		if (*p == (char)c)
+			return (char *)p;
+	} while (--p >= s);
+	return 0;
+}
+
+unsigned int strlen(const char *s)
+{
+	return lib_strlen(s);
+}
+
+char *strdup(const char *str)
+{
+	return lib_strdup(str);
+}
+
+int tolower(int c)
+{
+	return lib_tolower(c);
+}
+
+int strcasecmp(const char *cs, const char *ct)
+{
+	register signed char __res;
+	while (1)
+		if ((__res = lib_tolower(*cs) - lib_tolower(*ct++)) != 0 || !*cs++)
+			break;
+	return __res;
+}
+
+int strncasecmp(const char *cs, const char *ct, unsigned long n)
+{
+	register signed char __res = 0;
+	while (n--)
+		if ((__res = lib_tolower(*cs) - lib_tolower(*ct++)) != 0 || !*cs++)
+			break;
+	return __res;
+}
+
+char *strstr(const char *s1, const char *s2)
+{
+	int l1, l2;
+
+	l2 = lib_strlen(s2);
+	if (!l2)
+		return (char *) s1;
+	l1 = lib_strlen(s1);
+	while (l1 >= l2) {
+		l1--;
+		if (!lib_memcmp(s1,s2,l2))
+			return (char *) s1;
+		s1++;
+	}
+	return 0;
+}
+
+int isdigit(char c)
+{
+	return lib_isdigit(c);
+}
+
+/* Not a string op, and we don't support it. */
+typedef int time_t;
+
+time_t time(time_t *result)
+{
+	if (result)
+		*result = -1;
+	return -1;
+}
+
+/* libcom_err wants to have some stdio functions. */
+typedef int FILE;
+FILE *stderr;
+
+int fputc(int c, FILE *stream)
+{
+	lib_putc(c);
+	return 0;
+}
+
+int fputs(const char *s, FILE *stream)
+{
+	lib_printf("%s", s);
+	return 1;
+}
+
+unsigned long fwrite(const void *ptr, unsigned long size, unsigned long nmemb, FILE *stream)
+{
+	unsigned long i;
+	const char *p = (char *)ptr;
+
+	for (i = 0; i < (size * nmemb); i++)
+		lib_putc(*p++);
+
+	return nmemb;
+}
+
+int vfprintf(FILE *stream, const char *format, va_list ap)
+{
+	lib_vprintf(format, ap);
+	return 0;
+}
+
+int fflush(FILE *stream)
+{
+	return 0;
+}
+
+/* We don't support this */
+char *strerror(int errno)
+{
+	return 0;
+}
+
+unsigned long long my_strtoull(const char *ptr)
+{
+	unsigned long long retval = 0;
+	unsigned int newdigit;
+
+	while(*ptr) {
+		if (*ptr >= 'a' &&  *ptr <= 'f') {
+			newdigit = *ptr - ('a' - 10);
+		} else if (*ptr >= 'A' && *ptr <= 'F') {
+			newdigit = *ptr - ('A' - 10);
+		} else if (*ptr >= '0' && *ptr <= '9') {
+			newdigit = *ptr - '0';
+		} else if (*ptr == ' ' 
+			   || *ptr == '\t'
+			   || *ptr == '\n') {
+			/* Just skip it */
+		} else {
+			return -1UL;
+		}
+		retval <<= 4;
+		retval |= newdigit;
+		ptr++;
+	}
+	return retval;
+}
diff -wurN orig/loader/tftp_fileops.h debian/loader/tftp_fileops.h
--- orig/loader/tftp_fileops.h	1970-01-01 01:00:00.000000000 +0100
+++ debian/loader/tftp_fileops.h	2004-07-25 14:10:59.000000000 +0200
@@ -0,0 +1,42 @@
+/* $Id: tftp_fileops.h,v 1.4 2003/05/30 00:42:38 cgd Exp $ */
+
+/*
+ * Copyright 2001, 2003
+ * Broadcom Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and copied only
+ * in accordance with the following terms and conditions.  Subject to these
+ * conditions, you may download, copy, install, use, modify and distribute
+ * modified or unmodified copies of this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce and
+ *    retain this copyright notice and list of conditions as they appear in
+ *    the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
+ *    used to endorse or promote products derived from this software
+ *    without the prior written permission of Broadcom Corporation.
+ *
+ * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
+ *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
+ *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+ *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
+ *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
+ *    LIABLE FOR 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), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _TFTP_FILEOPS_H
+#define _TFTP_FILEOPS_H
+
+#include "getfile.h"
+
+extern file_ops_t tftp_ops;
+
+#endif
