|
@@ -1,28 +1,33 @@
|
|
1
|
+#include "dev.h"
|
1
|
2
|
#include "buffer.h"
|
|
3
|
+#include "load_buffer.h"
|
2
|
4
|
#include "image.h"
|
3
|
5
|
|
4
|
|
-static struct image images_start[0] __image_start;
|
|
6
|
+static struct image images[0] __image_start;
|
5
|
7
|
static struct image images_end[0] __image_end;
|
6
|
8
|
|
|
9
|
+/*
|
|
10
|
+ * Print all images
|
|
11
|
+ *
|
|
12
|
+ */
|
|
13
|
+void print_images ( void ) {
|
|
14
|
+ struct image *image;
|
|
15
|
+
|
|
16
|
+ for ( image = images ; image < images_end ; image++ ) {
|
|
17
|
+ printf ( "%s ", image->name );
|
|
18
|
+ }
|
|
19
|
+}
|
|
20
|
+
|
7
|
21
|
/*
|
8
|
22
|
* Identify the image format
|
9
|
23
|
*
|
10
|
24
|
*/
|
11
|
|
-static struct image * identify_image ( struct buffer *buffer ) {
|
12
|
|
- struct image_header header;
|
13
|
|
- int header_len = sizeof ( header );
|
14
|
|
- off_t len;
|
|
25
|
+static struct image * identify_image ( physaddr_t start, physaddr_t len,
|
|
26
|
+ void **context ) {
|
15
|
27
|
struct image *image;
|
16
|
28
|
|
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 ) )
|
|
29
|
+ for ( image = images ; image < images_end ; image++ ) {
|
|
30
|
+ if ( image->probe ( start, len, context ) )
|
26
|
31
|
return image;
|
27
|
32
|
}
|
28
|
33
|
|
|
@@ -30,20 +35,48 @@ static struct image * identify_image ( struct buffer *buffer ) {
|
30
|
35
|
}
|
31
|
36
|
|
32
|
37
|
/*
|
33
|
|
- * Boot a loaded image
|
|
38
|
+ * Load an image into memory at a location determined by the image
|
|
39
|
+ * format
|
34
|
40
|
*
|
35
|
41
|
*/
|
36
|
|
-int boot_image ( struct buffer *buffer ) {
|
37
|
|
- struct image *image;
|
|
42
|
+int autoload ( struct dev *dev, struct image **image, void **context ) {
|
|
43
|
+ struct buffer buffer;
|
|
44
|
+ int rc = 0;
|
|
45
|
+
|
|
46
|
+ /* Prepare the load buffer */
|
|
47
|
+ if ( ! init_load_buffer ( &buffer ) ) {
|
|
48
|
+ DBG ( "IMAGE could not initialise load buffer\n" );
|
|
49
|
+ goto out;
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ /* Load the image into the load buffer */
|
|
53
|
+ if ( ! load ( dev, &buffer ) ) {
|
|
54
|
+ DBG ( "IMAGE could not load image\n" );
|
|
55
|
+ goto out_free;
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ /* Shrink the load buffer */
|
|
59
|
+ trim_load_buffer ( &buffer );
|
|
60
|
+
|
|
61
|
+ /* Identify the image type */
|
|
62
|
+ *image = identify_image ( buffer.start, buffer.fill, context );
|
|
63
|
+ if ( ! *image ) {
|
|
64
|
+ DBG ( "IMAGE could not identify image type\n" );
|
|
65
|
+ goto out_free;
|
|
66
|
+ }
|
38
|
67
|
|
39
|
|
- image = identify_image ( buffer );
|
40
|
|
- if ( ! image ) {
|
41
|
|
- DBG ( "IMAGE could not identify image format\n" );
|
42
|
|
- return 0;
|
|
68
|
+ /* Move the image into the target location */
|
|
69
|
+ if ( ! (*image)->load ( buffer.start, buffer.fill, *context ) ) {
|
|
70
|
+ DBG ( "IMAGE could not move to target location\n" );
|
|
71
|
+ goto out_free;
|
43
|
72
|
}
|
44
|
73
|
|
45
|
|
- DBG ( "IMAGE found %s image (length %d)\n",
|
46
|
|
- image->name, buffer->fill );
|
|
74
|
+ /* Return success */
|
|
75
|
+ rc = 1;
|
47
|
76
|
|
48
|
|
- return image->boot ( buffer->start, buffer->fill );
|
|
77
|
+ out_free:
|
|
78
|
+ /* Free the load buffer */
|
|
79
|
+ done_load_buffer ( &buffer );
|
|
80
|
+ out:
|
|
81
|
+ return rc;
|
49
|
82
|
}
|