aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brown <mcb30@etherboot.org>2008-01-08 15:51:36 +0000
committerMichael Brown <mcb30@etherboot.org>2008-01-08 15:51:36 +0000
commit74fd544101c8f17f35dfc2cd16738ebd5228d366 (patch)
treeb813ee1138e4397ee557144739ede124f80c65a0
parent33111697075e60cec522848c0f04fd397bc9ea8d (diff)
downloadipxe-74fd544101c8f17f35dfc2cd16738ebd5228d366.zip
ipxe-74fd544101c8f17f35dfc2cd16738ebd5228d366.tar.gz
ipxe-74fd544101c8f17f35dfc2cd16738ebd5228d366.tar.bz2
Added the embedded pxelinux payload patch from hpa.
-rw-r--r--src/Makefile4
-rw-r--r--src/Makefile.housekeeping8
-rw-r--r--src/image/embed.S7
-rw-r--r--src/image/embedded.c49
-rw-r--r--src/include/gpxe/embedded.h9
-rw-r--r--src/usr/autoboot.c30
6 files changed, 107 insertions, 0 deletions
diff --git a/src/Makefile b/src/Makefile
index f74bd8b..0591bb0 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -101,6 +101,10 @@ CFLAGS += $(EXTRA_CFLAGS)
ASFLAGS += $(EXTRA_ASFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
+# Embedded image, if present
+#
+EMBEDDED_IMAGE ?= /dev/null
+
ifneq ($(NO_WERROR),1)
CFLAGS += -Werror
endif
diff --git a/src/Makefile.housekeeping b/src/Makefile.housekeeping
index 754c293..d4ae8e3 100644
--- a/src/Makefile.housekeeping
+++ b/src/Makefile.housekeeping
@@ -214,6 +214,14 @@ drivers :
roms :
@$(ECHO) $(ROMS)
+# Embedded binary
+$(BIN)/embedimg.bin: $(EMBEDDED_IMAGE)
+ $(QM)$(ECHO) " [COPY] $@"
+ $(Q)$(CP) -f $(EMBEDDED_IMAGE) $@
+
+$(BIN)/embed.o: $(BIN)/embedimg.bin
+CFLAGS_embed = -DEMBEDIMG=\"$(BIN)/embedimg.bin\"
+
# Generate the NIC file from the parsed source files. The NIC file is
# only for rom-o-matic.
#
diff --git a/src/image/embed.S b/src/image/embed.S
new file mode 100644
index 0000000..4541bfd
--- /dev/null
+++ b/src/image/embed.S
@@ -0,0 +1,7 @@
+ .section ".data", "aw"
+ .balign 4
+ .globl _embedded_image_start
+_embedded_image_start:
+ .incbin EMBEDIMG
+ .globl _embedded_image_end
+_embedded_image_end:
diff --git a/src/image/embedded.c b/src/image/embedded.c
new file mode 100644
index 0000000..e2782a4
--- /dev/null
+++ b/src/image/embedded.c
@@ -0,0 +1,49 @@
+/** @file
+ *
+ * Take a possible embedded image and put it in a struct image
+ * data structure.
+ */
+
+#include <stdio.h>
+#include <gpxe/image.h>
+#include <gpxe/malloc.h>
+#include <gpxe/uaccess.h>
+#include <gpxe/umalloc.h>
+#include <gpxe/embedded.h>
+
+extern char _embedded_image_start[], _embedded_image_end[];
+
+struct image *embedded_image(void)
+{
+ static int reclaimed = 0;
+ struct image *image;
+ size_t eisize = _embedded_image_end - _embedded_image_start;
+
+ if ( !eisize )
+ return NULL; /* No embedded image */
+
+ if ( reclaimed )
+ return NULL; /* Already reclaimed */
+
+ printf("Embedded image: %d bytes at %p\n",
+ eisize, _embedded_image_start);
+
+ image = alloc_image();
+ if (!image)
+ return NULL;
+
+ image->len = eisize;
+ image->data = umalloc(eisize);
+ if (image->data == UNULL) {
+ image_put(image);
+ return image = NULL;
+ }
+ copy_to_user(image->data, 0, _embedded_image_start, eisize);
+
+ /* Reclaim embedded image memory */
+ reclaimed = 1;
+ mpopulate(_embedded_image_start, eisize);
+
+ return image;
+}
+
diff --git a/src/include/gpxe/embedded.h b/src/include/gpxe/embedded.h
new file mode 100644
index 0000000..ec45705
--- /dev/null
+++ b/src/include/gpxe/embedded.h
@@ -0,0 +1,9 @@
+#ifndef _GPXE_EMBEDDED_H
+#define _GPXE_EMBEDDED_H
+
+#include <gpxe/image.h>
+
+struct image *embedded_image(void);
+
+#endif
+
diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c
index 9183697..c3b07e9 100644
--- a/src/usr/autoboot.c
+++ b/src/usr/autoboot.c
@@ -22,6 +22,7 @@
#include <gpxe/netdevice.h>
#include <gpxe/dhcp.h>
#include <gpxe/image.h>
+#include <gpxe/embedded.h>
#include <usr/ifmgmt.h>
#include <usr/route.h>
#include <usr/dhcpmgmt.h>
@@ -46,6 +47,30 @@ static struct net_device * find_boot_netdev ( void ) {
}
/**
+ * Boot embedded image
+ *
+ * @ret rc Return status code
+ */
+static int boot_embedded_image ( void ) {
+ struct image *image;
+ int rc;
+
+ image = embedded_image();
+ if ( !image )
+ return ENOENT;
+
+ if ( ( rc = imgload ( image ) ) != 0 ) {
+ printf ( "Could not load embedded image: %s\n",
+ strerror ( rc ) );
+ } else if ( ( rc = imgexec ( image ) ) != 0 ) {
+ printf ( "Could not boot embedded image: %s\n",
+ strerror ( rc ) );
+ }
+ image_put ( image );
+ return rc;
+}
+
+/**
* Boot using filename
*
* @v filename Boot filename
@@ -115,6 +140,11 @@ static int netboot ( struct net_device *netdev ) {
return rc;
route();
+ /* Try to boot an embedded image if we have one */
+ rc = boot_embedded_image ();
+ if ( rc != ENOENT )
+ return rc;
+
/* Try to download and boot whatever we are given as a filename */
dhcp_snprintf ( buf, sizeof ( buf ),
find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );