|
@@ -0,0 +1,49 @@
|
|
1
|
+#include "buffer.h"
|
|
2
|
+#include "image.h"
|
|
3
|
+
|
|
4
|
+static struct image images_start[0] __image_start;
|
|
5
|
+static struct image images_end[0] __image_end;
|
|
6
|
+
|
|
7
|
+/*
|
|
8
|
+ * Identify the image format
|
|
9
|
+ *
|
|
10
|
+ */
|
|
11
|
+static struct image * identify_image ( struct buffer *buffer ) {
|
|
12
|
+ struct image_header header;
|
|
13
|
+ int header_len = sizeof ( header );
|
|
14
|
+ off_t len;
|
|
15
|
+ struct image *image;
|
|
16
|
+
|
|
17
|
+ /* Copy first (up to) 512 bytes of image to easily-accessible
|
|
18
|
+ * buffer.
|
|
19
|
+ */
|
|
20
|
+ len = buffer->fill;
|
|
21
|
+ copy_from_phys ( &header, buffer->start,
|
|
22
|
+ len < header_len ? len : header_len );
|
|
23
|
+
|
|
24
|
+ for ( image = images_start ; image < images_end ; image++ ) {
|
|
25
|
+ if ( image->probe ( &header, len ) )
|
|
26
|
+ return image;
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ return NULL;
|
|
30
|
+}
|
|
31
|
+
|
|
32
|
+/*
|
|
33
|
+ * Boot a loaded image
|
|
34
|
+ *
|
|
35
|
+ */
|
|
36
|
+int boot_image ( struct buffer *buffer ) {
|
|
37
|
+ struct image *image;
|
|
38
|
+
|
|
39
|
+ image = identify_image ( buffer );
|
|
40
|
+ if ( ! image ) {
|
|
41
|
+ DBG ( "IMAGE could not identify image format\n" );
|
|
42
|
+ return 0;
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ DBG ( "IMAGE found %s image (length %d)\n",
|
|
46
|
+ image->name, buffer->fill );
|
|
47
|
+
|
|
48
|
+ return image->boot ( buffer->start, buffer->fill );
|
|
49
|
+}
|