Browse Source

Added print_images() and autoload().

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
0571dcdb05
2 changed files with 66 additions and 32 deletions
  1. 57
    24
      src/core/image.c
  2. 9
    8
      src/include/image.h

+ 57
- 24
src/core/image.c View File

@@ -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
 }

+ 9
- 8
src/include/image.h View File

@@ -4,17 +4,13 @@
4 4
 #include "stdint.h"
5 5
 #include "io.h"
6 6
 #include "tables.h"
7
-
8
-#define IMAGE_HEADER_SIZE 512
9
-
10
-struct image_header {
11
-	char data[IMAGE_HEADER_SIZE];
12
-};
7
+#include "dev.h"
13 8
 
14 9
 struct image {
15 10
 	char *name;
16
-	int ( * probe ) ( struct image_header *header, off_t len );
17
-	int ( * boot ) ( physaddr_t start, off_t len );
11
+	int ( * probe ) ( physaddr_t data, off_t len, void **context );
12
+	int ( * load ) ( physaddr_t data, off_t len, void *context );
13
+	int ( * boot ) ( void *context );
18 14
 };
19 15
 
20 16
 #define __image_start		__table_start(image)
@@ -22,4 +18,9 @@ struct image {
22 18
 #define __default_image		__table(image,02)
23 19
 #define __image_end		__table_end(image)
24 20
 
21
+/* Functions in image.c */
22
+
23
+extern void print_images ( void );
24
+extern int autoload ( struct dev *dev, struct image **image, void **context );
25
+
25 26
 #endif /* IMAGE_H */

Loading…
Cancel
Save