Browse Source

Quick hack to get image booting working again

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
4b08f4cf0f
5 changed files with 69 additions and 68 deletions
  1. 35
    28
      src/hci/commands/image_cmd.c
  2. 1
    0
      src/include/gpxe/image.h
  3. 1
    2
      src/include/usr/imgmgmt.h
  4. 9
    1
      src/usr/autoboot.c
  5. 23
    37
      src/usr/imgmgmt.c

+ 35
- 28
src/hci/commands/image_cmd.c View File

72
 /**
72
 /**
73
  * The "imgfetch"/"module"/"kernel" command body
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
  * @v argc		Argument count
77
  * @v argc		Argument count
76
  * @v argv		Argument list
78
  * @v argv		Argument list
77
- * @v load		Image will be automatically loaded after fetching
78
- * @ret image		Fetched image
79
  * @ret rc		Return status code
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
 	static struct option longopts[] = {
83
 	static struct option longopts[] = {
84
 		{ "help", 0, NULL, 'h' },
84
 		{ "help", 0, NULL, 'h' },
85
 		{ "name", required_argument, NULL, 'n' },
85
 		{ "name", required_argument, NULL, 'n' },
86
 		{ NULL, 0, NULL, 0 },
86
 		{ NULL, 0, NULL, 0 },
87
 	};
87
 	};
88
+	struct image *image;
88
 	const char *name = NULL;
89
 	const char *name = NULL;
89
 	char *filename;
90
 	char *filename;
90
 	int c;
91
 	int c;
116
 	if ( ! name )
117
 	if ( ! name )
117
 		name = basename ( filename );
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
 	/* Fetch the image */
139
 	/* Fetch the image */
120
-	if ( ( rc = imgfetch ( filename, name, image ) ) != 0 ) {
140
+	if ( ( rc = imgfetch ( image, filename, load ) ) != 0 ) {
121
 		printf ( "Could not fetch %s: %s\n", name, strerror ( rc ) );
141
 		printf ( "Could not fetch %s: %s\n", name, strerror ( rc ) );
142
+		image_put ( image );
122
 		return rc;
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
 	return 0;
147
 	return 0;
129
 }
148
 }
130
 
149
 
136
  * @ret rc		Exit code
155
  * @ret rc		Exit code
137
  */
156
  */
138
 static int imgfetch_exec ( int argc, char **argv ) {
157
 static int imgfetch_exec ( int argc, char **argv ) {
139
-	struct image *image;
140
 	int rc;
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
 	return 0;
163
 	return 0;
146
 }
164
 }
153
  * @ret rc		Exit code
171
  * @ret rc		Exit code
154
  */
172
  */
155
 static int kernel_exec ( int argc, char **argv ) {
173
 static int kernel_exec ( int argc, char **argv ) {
156
-	struct image *image;
157
 	int rc;
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
 	return 0;
179
 	return 0;
170
 }
180
 }
177
  * @ret rc		Exit code
187
  * @ret rc		Exit code
178
  */
188
  */
179
 static int initrd_exec ( int argc, char **argv ) {
189
 static int initrd_exec ( int argc, char **argv ) {
180
-	struct image *image;
181
 	int rc;
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
 	return 0;
196
 	return 0;
190
 }
197
 }
246
 	}
253
 	}
247
 	if ( ( rc = imgload ( image ) ) != 0 ) {
254
 	if ( ( rc = imgload ( image ) ) != 0 ) {
248
 		printf ( "Could not load %s: %s\n", name, strerror ( rc ) );
255
 		printf ( "Could not load %s: %s\n", name, strerror ( rc ) );
249
-		return 1;
256
+		return rc;
250
 	}
257
 	}
251
 
258
 
252
 	return 0;
259
 	return 0;

+ 1
- 0
src/include/gpxe/image.h View File

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

+ 1
- 2
src/include/usr/imgmgmt.h View File

9
 
9
 
10
 struct image;
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
 extern int imgload ( struct image *image );
13
 extern int imgload ( struct image *image );
15
 extern int imgexec ( struct image *image );
14
 extern int imgexec ( struct image *image );
16
 extern struct image * imgautoselect ( void );
15
 extern struct image * imgautoselect ( void );

+ 9
- 1
src/usr/autoboot.c View File

99
 		return;
99
 		return;
100
 	}
100
 	}
101
 	printf ( "Booting \"%s\"\n", filename );
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
 		printf ( "Could not retrieve %s: %s\n",
108
 		printf ( "Could not retrieve %s: %s\n",
104
 			 filename, strerror ( rc ) );
109
 			 filename, strerror ( rc ) );
110
+		image_put ( image );
105
 		return;
111
 		return;
106
 	}
112
 	}
107
 	if ( ( rc = imgload ( image ) ) != 0 ) {
113
 	if ( ( rc = imgload ( image ) ) != 0 ) {
108
 		printf ( "Could not load %s: %s\n", image->name,
114
 		printf ( "Could not load %s: %s\n", image->name,
109
 			 strerror ( rc ) );
115
 			 strerror ( rc ) );
116
+		image_put ( image );
110
 		return;
117
 		return;
111
 	}
118
 	}
112
 	if ( ( rc = imgexec ( image ) ) != 0 ) {
119
 	if ( ( rc = imgexec ( image ) ) != 0 ) {
113
 		printf ( "Could not execute %s: %s\n", image->name,
120
 		printf ( "Could not execute %s: %s\n", image->name,
114
 			 strerror ( rc ) );
121
 			 strerror ( rc ) );
122
+		image_put ( image );
115
 		return;
123
 		return;
116
 	}
124
 	}
117
 }
125
 }

+ 23
- 37
src/usr/imgmgmt.c View File

21
 #include <stdio.h>
21
 #include <stdio.h>
22
 #include <errno.h>
22
 #include <errno.h>
23
 #include <gpxe/image.h>
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
 #include <usr/imgmgmt.h>
27
 #include <usr/imgmgmt.h>
27
 
28
 
28
 /** @file
29
 /** @file
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
  * Fetch an image
48
  * Fetch an image
36
  *
49
  *
39
  * @ret new_image	Newly created image
52
  * @ret new_image	Newly created image
40
  * @ret rc		Return status code
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
 	int rc;
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
 	return rc;
67
 	return rc;
76
 }
68
 }
77
 
69
 
88
 	if ( ( rc = image_autoload ( image ) ) != 0 )
80
 	if ( ( rc = image_autoload ( image ) ) != 0 )
89
 		return rc;
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
 	return 0;
83
 	return 0;
96
 }
84
 }
97
 
85
 
144
  */
132
  */
145
 void imgfree ( struct image *image ) {
133
 void imgfree ( struct image *image ) {
146
 	unregister_image ( image );
134
 	unregister_image ( image );
147
-	ufree ( image->data );
148
-	free ( image );
149
 }
135
 }

Loading…
Cancel
Save