Ver código fonte

Quick hack to get image booting working again

tags/v0.9.3
Michael Brown 17 anos atrás
pai
commit
4b08f4cf0f

+ 35
- 28
src/hci/commands/image_cmd.c Ver arquivo

@@ -72,19 +72,20 @@ static void imgfetch_core_syntax ( char **argv, int load ) {
72 72
 /**
73 73
  * The "imgfetch"/"module"/"kernel" command body
74 74
  *
75
+ * @v image_type	Image type to assign (or NULL)
76
+ * @v load		Image will be automatically loaded after fetching
75 77
  * @v argc		Argument count
76 78
  * @v argv		Argument list
77
- * @v load		Image will be automatically loaded after fetching
78
- * @ret image		Fetched image
79 79
  * @ret rc		Return status code
80 80
  */
81
-static int imgfetch_core_exec ( int argc, char **argv, int load,
82
-				struct image **image ) {
81
+static int imgfetch_core_exec ( struct image_type *image_type, int load,
82
+				int argc, char **argv ) {
83 83
 	static struct option longopts[] = {
84 84
 		{ "help", 0, NULL, 'h' },
85 85
 		{ "name", required_argument, NULL, 'n' },
86 86
 		{ NULL, 0, NULL, 0 },
87 87
 	};
88
+	struct image *image;
88 89
 	const char *name = NULL;
89 90
 	char *filename;
90 91
 	int c;
@@ -116,15 +117,33 @@ static int imgfetch_core_exec ( int argc, char **argv, int load,
116 117
 	if ( ! name )
117 118
 		name = basename ( filename );
118 119
 
120
+	/* Allocate image */
121
+	image = alloc_image();
122
+	if ( ! image ) {
123
+		printf ( "%s\n", strerror ( -ENOMEM ) );
124
+		return -ENOMEM;
125
+	}
126
+
127
+	/* Fill in image name */
128
+	if ( name )
129
+		strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
130
+
131
+	/* Set image type (if specified) */
132
+	image->type = image_type;
133
+
134
+	/* Fill in command line */
135
+	imgfill_cmdline ( image, ( argc - optind ), &argv[optind] );
136
+
137
+	printf ( "name = %s, filename = %s\n", name, filename );
138
+	
119 139
 	/* Fetch the image */
120
-	if ( ( rc = imgfetch ( filename, name, image ) ) != 0 ) {
140
+	if ( ( rc = imgfetch ( image, filename, load ) ) != 0 ) {
121 141
 		printf ( "Could not fetch %s: %s\n", name, strerror ( rc ) );
142
+		image_put ( image );
122 143
 		return rc;
123 144
 	}
124 145
 
125
-	/* Fill in command line */
126
-	imgfill_cmdline ( *image, ( argc - optind ), &argv[optind] );
127
-
146
+	image_put ( image );
128 147
 	return 0;
129 148
 }
130 149
 
@@ -136,11 +155,10 @@ static int imgfetch_core_exec ( int argc, char **argv, int load,
136 155
  * @ret rc		Exit code
137 156
  */
138 157
 static int imgfetch_exec ( int argc, char **argv ) {
139
-	struct image *image;
140 158
 	int rc;
141 159
 
142
-	if ( ( rc = imgfetch_core_exec ( argc, argv, 0, &image ) ) != 0 )
143
-		return 1;
160
+	if ( ( rc = imgfetch_core_exec ( NULL, 0, argc, argv ) ) != 0 )
161
+		return rc;
144 162
 
145 163
 	return 0;
146 164
 }
@@ -153,18 +171,10 @@ static int imgfetch_exec ( int argc, char **argv ) {
153 171
  * @ret rc		Exit code
154 172
  */
155 173
 static int kernel_exec ( int argc, char **argv ) {
156
-	struct image *image;
157 174
 	int rc;
158 175
 
159
-	if ( ( rc = imgfetch_core_exec ( argc, argv, 1, &image ) ) != 0 )
160
-		return 1;
161
-
162
-	/* Load image */
163
-	if ( ( rc = imgload ( image ) ) != 0 ) {
164
-		printf ( "Could not load %s: %s\n", image->name,
165
-			 strerror ( rc ) );
166
-		return 1;
167
-	}
176
+	if ( ( rc = imgfetch_core_exec ( NULL, 1, argc, argv ) ) != 0 )
177
+		return rc;
168 178
 
169 179
 	return 0;
170 180
 }
@@ -177,14 +187,11 @@ static int kernel_exec ( int argc, char **argv ) {
177 187
  * @ret rc		Exit code
178 188
  */
179 189
 static int initrd_exec ( int argc, char **argv ) {
180
-	struct image *image;
181 190
 	int rc;
182 191
 
183
-	if ( ( rc = imgfetch_core_exec ( argc, argv, 0, &image ) ) != 0 )
184
-		return 1;
185
-
186
-	/* Mark image as an intird */
187
-	image->type = &initrd_image_type;
192
+	if ( ( rc = imgfetch_core_exec ( &initrd_image_type, 0,
193
+					 argc, argv ) ) != 0 )
194
+		return rc;
188 195
 
189 196
 	return 0;
190 197
 }
@@ -246,7 +253,7 @@ static int imgload_exec ( int argc, char **argv ) {
246 253
 	}
247 254
 	if ( ( rc = imgload ( image ) ) != 0 ) {
248 255
 		printf ( "Could not load %s: %s\n", name, strerror ( rc ) );
249
-		return 1;
256
+		return rc;
250 257
 	}
251 258
 
252 259
 	return 0;

+ 1
- 0
src/include/gpxe/image.h Ver arquivo

@@ -113,6 +113,7 @@ extern struct list_head images;
113 113
 #define for_each_image( image ) \
114 114
 	list_for_each_entry ( (image), &images, list )
115 115
 
116
+extern struct image * alloc_image ( void );
116 117
 extern int register_image ( struct image *image );
117 118
 extern void unregister_image ( struct image *image );
118 119
 extern void promote_image ( struct image *image );

+ 1
- 2
src/include/usr/imgmgmt.h Ver arquivo

@@ -9,8 +9,7 @@
9 9
 
10 10
 struct image;
11 11
 
12
-extern int imgfetch ( const char *filename, const char *name,
13
-		      struct image **new_image );
12
+extern int imgfetch ( struct image *image, const char *filename, int load );
14 13
 extern int imgload ( struct image *image );
15 14
 extern int imgexec ( struct image *image );
16 15
 extern struct image * imgautoselect ( void );

+ 9
- 1
src/usr/autoboot.c Ver arquivo

@@ -99,19 +99,27 @@ void netboot ( struct net_device *netdev ) {
99 99
 		return;
100 100
 	}
101 101
 	printf ( "Booting \"%s\"\n", filename );
102
-	if ( ( rc = imgfetch ( filename, NULL, &image ) ) != 0 ) {
102
+	image = alloc_image();
103
+	if ( ! image ) {
104
+		printf ( "Out of memory\n" );
105
+		return;
106
+	}
107
+	if ( ( rc = imgfetch ( image, filename, 0 ) ) != 0 ) {
103 108
 		printf ( "Could not retrieve %s: %s\n",
104 109
 			 filename, strerror ( rc ) );
110
+		image_put ( image );
105 111
 		return;
106 112
 	}
107 113
 	if ( ( rc = imgload ( image ) ) != 0 ) {
108 114
 		printf ( "Could not load %s: %s\n", image->name,
109 115
 			 strerror ( rc ) );
116
+		image_put ( image );
110 117
 		return;
111 118
 	}
112 119
 	if ( ( rc = imgexec ( image ) ) != 0 ) {
113 120
 		printf ( "Could not execute %s: %s\n", image->name,
114 121
 			 strerror ( rc ) );
122
+		image_put ( image );
115 123
 		return;
116 124
 	}
117 125
 }

+ 23
- 37
src/usr/imgmgmt.c Ver arquivo

@@ -21,8 +21,9 @@
21 21
 #include <stdio.h>
22 22
 #include <errno.h>
23 23
 #include <gpxe/image.h>
24
-#include <gpxe/umalloc.h>
25
-#include <gpxe/download.h>
24
+#include <gpxe/downloader.h>
25
+#include <gpxe/monojob.h>
26
+#include <gpxe/open.h>
26 27
 #include <usr/imgmgmt.h>
27 28
 
28 29
 /** @file
@@ -31,6 +32,18 @@
31 32
  *
32 33
  */
33 34
 
35
+static int imgfetch_autoload ( struct image *image ) {
36
+	int rc;
37
+
38
+	if ( ( rc = register_image ( image ) ) != 0 )
39
+		return rc;
40
+
41
+	if ( ( rc = image_autoload ( image ) ) != 0 )
42
+		return rc;
43
+
44
+	return 0;
45
+}
46
+
34 47
 /**
35 48
  * Fetch an image
36 49
  *
@@ -39,39 +52,18 @@
39 52
  * @ret new_image	Newly created image
40 53
  * @ret rc		Return status code
41 54
  */
42
-int imgfetch ( const char *uri_string, const char *name,
43
-	       struct image **new_image ) {
44
-	struct image *image;
45
-	struct async async;
55
+int imgfetch ( struct image *image, const char *uri_string, int load ) {
46 56
 	int rc;
47 57
 
48
-	/* Allocate new image */
49
-	image = malloc ( sizeof ( *image ) );
50
-	if ( ! image )
51
-		return -ENOMEM;
52
-	memset ( image, 0, sizeof ( *image ) );
58
+	printf ( "uri_string = %s\n", uri_string );
53 59
 
54
-	/* Fill in image name */
55
-	if ( name )
56
-		strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
60
+	if ( ( rc = create_downloader ( &monojob, image, 
61
+					( load ? imgfetch_autoload :
62
+					  register_image ),
63
+					LOCATION_URI_STRING,
64
+					uri_string ) ) == 0 )
65
+		rc = monojob_wait();
57 66
 
58
-	/* Download the file */
59
-	if ( ( rc = async_block_progress ( &async,
60
-					   start_download ( uri_string, &async,
61
-							    &image->data,
62
-							    &image->len )))!=0)
63
-		goto err;
64
-
65
-	/* Register the image */
66
-	if ( ( rc = register_image ( image ) ) != 0 )
67
-		goto err;
68
-
69
-	*new_image = image;
70
-	return 0;
71
-
72
- err:
73
-	ufree ( image->data );
74
-	free ( image );
75 67
 	return rc;
76 68
 }
77 69
 
@@ -88,10 +80,6 @@ int imgload ( struct image *image ) {
88 80
 	if ( ( rc = image_autoload ( image ) ) != 0 )
89 81
 		return rc;
90 82
 
91
-	/* If we succeed, move the image to the start of the list */
92
-#warning "No longer exists"
93
-	//	promote_image ( image );
94
-
95 83
 	return 0;
96 84
 }
97 85
 
@@ -144,6 +132,4 @@ void imgstat ( struct image *image ) {
144 132
  */
145 133
 void imgfree ( struct image *image ) {
146 134
 	unregister_image ( image );
147
-	ufree ( image->data );
148
-	free ( image );
149 135
 }

Carregando…
Cancelar
Salvar