Pārlūkot izejas kodu

Add the "initrd" command

tags/v0.9.3
Michael Brown 18 gadus atpakaļ
vecāks
revīzija
8edf8f6fa8
1 mainītis faili ar 57 papildinājumiem un 20 dzēšanām
  1. 57
    20
      src/hci/commands/image_cmd.c

+ 57
- 20
src/hci/commands/image_cmd.c Parādīt failu

@@ -18,11 +18,13 @@
18 18
 
19 19
 #include <stdint.h>
20 20
 #include <stdlib.h>
21
+#include <errno.h>
21 22
 #include <libgen.h>
22 23
 #include <getopt.h>
23 24
 #include <vsprintf.h>
24 25
 #include <gpxe/image.h>
25 26
 #include <gpxe/command.h>
27
+#include <gpxe/initrd.h>
26 28
 #include <usr/imgmgmt.h>
27 29
 
28 30
 /** @file
@@ -72,16 +74,17 @@ static void imgfetch_core_syntax ( char **argv, int load ) {
72 74
  *
73 75
  * @v argc		Argument count
74 76
  * @v argv		Argument list
75
- * @v load		Load image after fetching
76
- * @ret rc		Exit code
77
+ * @v load		Image will be automatically loaded after fetching
78
+ * @ret image		Fetched image
79
+ * @ret rc		Return status code
77 80
  */
78
-static int imgfetch_core_exec ( int argc, char **argv, int load ) {
81
+static int imgfetch_core_exec ( int argc, char **argv, int load,
82
+				struct image **image ) {
79 83
 	static struct option longopts[] = {
80 84
 		{ "help", 0, NULL, 'h' },
81 85
 		{ "name", required_argument, NULL, 'n' },
82 86
 		{ NULL, 0, NULL, 0 },
83 87
 	};
84
-	struct image *image;
85 88
 	const char *name = NULL;
86 89
 	char *filename;
87 90
 	int c;
@@ -100,36 +103,27 @@ static int imgfetch_core_exec ( int argc, char **argv, int load ) {
100 103
 		default:
101 104
 			/* Unrecognised/invalid option */
102 105
 			imgfetch_core_syntax ( argv, load );
103
-			return 1;
106
+			return -EINVAL;
104 107
 		}
105 108
 	}
106 109
 
107 110
 	/* Need at least a filename remaining after the options */
108 111
 	if ( optind == argc ) {
109 112
 		imgfetch_core_syntax ( argv, load );
110
-		return 1;
113
+		return -EINVAL;
111 114
 	}
112 115
 	filename = argv[optind++];
113 116
 	if ( ! name )
114 117
 		name = basename ( filename );
115 118
 
116 119
 	/* Fetch the image */
117
-	if ( ( rc = imgfetch ( filename, name, &image ) ) != 0 ) {
120
+	if ( ( rc = imgfetch ( filename, name, image ) ) != 0 ) {
118 121
 		printf ( "Could not fetch %s: %s\n", name, strerror ( rc ) );
119
-		return 1;
122
+		return rc;
120 123
 	}
121 124
 
122 125
 	/* Fill in command line */
123
-	imgfill_cmdline ( image, ( argc - optind ), &argv[optind] );
124
-
125
-	/* Load image if required */
126
-	if ( load ) {
127
-		if ( ( rc = imgload ( image ) ) != 0 ) {
128
-			printf ( "Could not load %s: %s\n", name,
129
-				 strerror ( rc ) );
130
-			return 1;
131
-		}
132
-	}
126
+	imgfill_cmdline ( *image, ( argc - optind ), &argv[optind] );
133 127
 
134 128
 	return 0;
135 129
 }
@@ -142,7 +136,13 @@ static int imgfetch_core_exec ( int argc, char **argv, int load ) {
142 136
  * @ret rc		Exit code
143 137
  */
144 138
 static int imgfetch_exec ( int argc, char **argv ) {
145
-	return imgfetch_core_exec ( argc, argv, 0 );
139
+	struct image *image;
140
+	int rc;
141
+
142
+	if ( ( rc = imgfetch_core_exec ( argc, argv, 0, &image ) ) != 0 )
143
+		return 1;
144
+
145
+	return 0;
146 146
 }
147 147
 
148 148
 /**
@@ -153,7 +153,40 @@ static int imgfetch_exec ( int argc, char **argv ) {
153 153
  * @ret rc		Exit code
154 154
  */
155 155
 static int kernel_exec ( int argc, char **argv ) {
156
-	return imgfetch_core_exec ( argc, argv, 1  );
156
+	struct image *image;
157
+	int rc;
158
+
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
+	}
168
+
169
+	return 0;
170
+}
171
+
172
+/**
173
+ * The "initrd" command
174
+ *
175
+ * @v argc		Argument count
176
+ * @v argv		Argument list
177
+ * @ret rc		Exit code
178
+ */
179
+static int initrd_exec ( int argc, char **argv ) {
180
+	struct image *image;
181
+	int rc;
182
+
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;
188
+
189
+	return 0;
157 190
 }
158 191
 
159 192
 /**
@@ -473,6 +506,10 @@ struct command image_commands[] __command = {
473 506
 		.name = "kernel",
474 507
 		.exec = kernel_exec,
475 508
 	},
509
+	{
510
+		.name = "initrd",
511
+		.exec = initrd_exec,
512
+	},
476 513
 	{
477 514
 		.name = "imgload",
478 515
 		.exec = imgload_exec,

Notiek ielāde…
Atcelt
Saglabāt