First versions
authorMichael Brown <mcb30@etherboot.org>
Mon, 9 May 2005 18:01:50 +0000 (18:01 +0000)
committerMichael Brown <mcb30@etherboot.org>
Mon, 9 May 2005 18:01:50 +0000 (18:01 +0000)
src/core/image.c [new file with mode: 0644]
src/include/image.h [new file with mode: 0644]

diff --git a/src/core/image.c b/src/core/image.c
new file mode 100644 (file)
index 0000000..31ea955
--- /dev/null
@@ -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 );
+}
diff --git a/src/include/image.h b/src/include/image.h
new file mode 100644 (file)
index 0000000..e8a34b3
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef IMAGE_H
+#define IMAGE_H
+
+#include "stdint.h"
+#include "io.h"
+#include "tables.h"
+
+#define IMAGE_HEADER_SIZE 512
+
+struct image_header {
+       char data[IMAGE_HEADER_SIZE];
+};
+
+struct image {
+       char *name;
+       int ( * probe ) ( struct image_header *header, off_t len );
+       int ( * boot ) ( physaddr_t start, off_t len );
+};
+
+#define __image_start          __table_start(image)
+#define __image                        __table(image,01)
+#define __default_image                __table(image,02)
+#define __image_end            __table_end(image)
+
+#endif /* IMAGE_H */