summaryrefslogtreecommitdiffstats
path: root/src/core/image.c
diff options
context:
space:
mode:
authorMichael Brown2005-05-09 20:01:50 +0200
committerMichael Brown2005-05-09 20:01:50 +0200
commit58ee2c4b2ecf30add8c6f3831225621613e13210 (patch)
tree7062763f417e799e6fb0f33f97e186c0f06a1cbc /src/core/image.c
parentProtocols now load data into a buffer; they don't execute it. (diff)
downloadipxe-58ee2c4b2ecf30add8c6f3831225621613e13210.tar.gz
ipxe-58ee2c4b2ecf30add8c6f3831225621613e13210.tar.xz
ipxe-58ee2c4b2ecf30add8c6f3831225621613e13210.zip
First versions
Diffstat (limited to 'src/core/image.c')
-rw-r--r--src/core/image.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/core/image.c b/src/core/image.c
new file mode 100644
index 00000000..31ea9557
--- /dev/null
+++ b/src/core/image.c
@@ -0,0 +1,49 @@
+#include "buffer.h"
+#include "image.h"
+
+static struct image images_start[0] __image_start;
+static struct image images_end[0] __image_end;
+
+/*
+ * Identify the image format
+ *
+ */
+static struct image * identify_image ( struct buffer *buffer ) {
+ struct image_header header;
+ int header_len = sizeof ( header );
+ off_t len;
+ struct image *image;
+
+ /* Copy first (up to) 512 bytes of image to easily-accessible
+ * buffer.
+ */
+ len = buffer->fill;
+ copy_from_phys ( &header, buffer->start,
+ len < header_len ? len : header_len );
+
+ for ( image = images_start ; image < images_end ; image++ ) {
+ if ( image->probe ( &header, len ) )
+ return image;
+ }
+
+ return NULL;
+}
+
+/*
+ * Boot a loaded image
+ *
+ */
+int boot_image ( struct buffer *buffer ) {
+ struct image *image;
+
+ image = identify_image ( buffer );
+ if ( ! image ) {
+ DBG ( "IMAGE could not identify image format\n" );
+ return 0;
+ }
+
+ DBG ( "IMAGE found %s image (length %d)\n",
+ image->name, buffer->fill );
+
+ return image->boot ( buffer->start, buffer->fill );
+}