Browse Source

Merge branch 'master' of git://git.etherboot.org/scm/gpxe

tags/v0.9.3
Holger Lubitz 17 years ago
parent
commit
4f66879653
7 changed files with 111 additions and 56 deletions
  1. 69
    36
      src/arch/i386/image/multiboot.c
  2. 17
    4
      src/core/monojob.c
  3. 12
    2
      src/hci/shell.c
  4. 1
    1
      src/include/gpxe/monojob.h
  5. 9
    4
      src/usr/autoboot.c
  6. 2
    8
      src/usr/dhcpmgmt.c
  7. 1
    1
      src/usr/imgmgmt.c

+ 69
- 36
src/arch/i386/image/multiboot.c View File

@@ -23,6 +23,7 @@
23 23
  *
24 24
  */
25 25
 
26
+#include <stdio.h>
26 27
 #include <errno.h>
27 28
 #include <assert.h>
28 29
 #include <realmode.h>
@@ -51,6 +52,16 @@ struct image_type multiboot_image_type __image_type ( PROBE_MULTIBOOT );
51 52
  */
52 53
 #define MAX_MODULES 8
53 54
 
55
+/**
56
+ * Maximum combined length of command lines
57
+ *
58
+ * Again; sorry.  Some broken OSes zero out any non-base memory that
59
+ * isn't part of the loaded module set, so we can't just use
60
+ * virt_to_phys(cmdline) to point to the command lines, even though
61
+ * this would comply with the Multiboot spec.
62
+ */
63
+#define MB_MAX_CMDLINE 512
64
+
54 65
 /** Multiboot flags that we support */
55 66
 #define MB_SUPPORTED_FLAGS ( MB_FLAG_PGALIGN | MB_FLAG_MEMMAP | \
56 67
 			     MB_FLAG_VIDMODE | MB_FLAG_RAW )
@@ -77,6 +88,13 @@ struct multiboot_header_info {
77 88
 	size_t offset;
78 89
 };
79 90
 
91
+/** Multiboot module command lines */
92
+static char __bss16_array ( mb_cmdlines, [MB_MAX_CMDLINE] );
93
+#define mb_cmdlines __use_data16 ( mb_cmdlines )
94
+
95
+/** Offset within module command lines */
96
+static unsigned int mb_cmdline_offset;
97
+
80 98
 /**
81 99
  * Build multiboot memory map
82 100
  *
@@ -118,6 +136,32 @@ static void multiboot_build_memmap ( struct image *image,
118 136
 	}
119 137
 }
120 138
 
139
+/**
140
+ * Add command line in base memory
141
+ *
142
+ * @v cmdline		Command line
143
+ * @ret physaddr	Physical address of command line
144
+ */
145
+physaddr_t multiboot_add_cmdline ( const char *cmdline ) {
146
+	char *mb_cmdline;
147
+
148
+	if ( ! cmdline )
149
+		cmdline = "";
150
+
151
+	/* Copy command line to base memory buffer */
152
+	mb_cmdline = ( mb_cmdlines + mb_cmdline_offset );
153
+	mb_cmdline_offset +=
154
+		( snprintf ( mb_cmdline,
155
+			     ( sizeof ( mb_cmdlines ) - mb_cmdline_offset ),
156
+			     "%s", cmdline ) + 1 );
157
+
158
+	/* Truncate to terminating NUL in buffer if necessary */
159
+	if ( mb_cmdline_offset > sizeof ( mb_cmdlines ) )
160
+		mb_cmdline_offset = ( sizeof ( mb_cmdlines ) - 1 );
161
+
162
+	return virt_to_phys ( mb_cmdline );
163
+}
164
+
121 165
 /**
122 166
  * Build multiboot module list
123 167
  *
@@ -135,7 +179,6 @@ multiboot_build_module_list ( struct image *image,
135 179
 	unsigned int insert;
136 180
 	physaddr_t start;
137 181
 	physaddr_t end;
138
-	char *cmdline;
139 182
 	unsigned int i;
140 183
 
141 184
 	/* Add each image as a multiboot module */
@@ -151,44 +194,35 @@ multiboot_build_module_list ( struct image *image,
151 194
 		if ( module_image == image )
152 195
 			continue;
153 196
 
154
-		/* If we don't have a data structure to populate, just count */
155
-		if ( modules ) {
156
-			
157
-			/* At least some OSes expect the multiboot
158
-			 * modules to be in ascending order, so we
159
-			 * have to support it.
160
-			 */
161
-			start = user_to_phys ( module_image->data, 0 );
162
-			end = user_to_phys ( module_image->data,
163
-					     module_image->len );
164
-			for ( insert = 0 ; insert < count ; insert++ ) {
165
-				if ( start < modules[insert].mod_start )
166
-					break;
167
-			}
168
-			module = &modules[insert];
169
-			memmove ( ( module + 1 ), module,
170
-				  ( ( count - insert ) * sizeof ( *module ) ));
171
-			module->mod_start = start;
172
-			module->mod_end = end;
173
-			cmdline = ( module_image->cmdline ?
174
-				    module_image->cmdline : "" );
175
-			module->string = virt_to_phys ( cmdline );
176
-			module->reserved = 0;
177
-			
178
-			/* We promise to page-align modules */
179
-			assert ( ( module->mod_start & 0xfff ) == 0 );
197
+		/* At least some OSes expect the multiboot modules to
198
+		 * be in ascending order, so we have to support it.
199
+		 */
200
+		start = user_to_phys ( module_image->data, 0 );
201
+		end = user_to_phys ( module_image->data, module_image->len );
202
+		for ( insert = 0 ; insert < count ; insert++ ) {
203
+			if ( start < modules[insert].mod_start )
204
+				break;
180 205
 		}
206
+		module = &modules[insert];
207
+		memmove ( ( module + 1 ), module,
208
+			  ( ( count - insert ) * sizeof ( *module ) ) );
209
+		module->mod_start = start;
210
+		module->mod_end = end;
211
+		module->string =
212
+			multiboot_add_cmdline ( module_image->cmdline );
213
+		module->reserved = 0;
214
+		
215
+		/* We promise to page-align modules */
216
+		assert ( ( module->mod_start & 0xfff ) == 0 );
181 217
 
182 218
 		count++;
183 219
 	}
184 220
 
185 221
 	/* Dump module configuration */
186
-	if ( modules ) {
187
-		for ( i = 0 ; i < count ; i++ ) {
188
-			DBGC ( image, "MULTIBOOT %p module %d is [%lx,%lx)\n",
189
-			       image, i, modules[i].mod_start,
190
-			       modules[i].mod_end );
191
-		}
222
+	for ( i = 0 ; i < count ; i++ ) {
223
+		DBGC ( image, "MULTIBOOT %p module %d is [%lx,%lx)\n",
224
+		       image, i, modules[i].mod_start,
225
+		       modules[i].mod_end );
192 226
 	}
193 227
 
194 228
 	return count;
@@ -225,7 +259,6 @@ static struct multiboot_module __bss16_array ( mbmodules, [MAX_MODULES] );
225 259
  */
226 260
 static int multiboot_exec ( struct image *image ) {
227 261
 	physaddr_t entry = image->priv.phys;
228
-	char *cmdline;
229 262
 
230 263
 	/* Populate multiboot information structure */
231 264
 	memset ( &mbinfo, 0, sizeof ( mbinfo ) );
@@ -233,8 +266,8 @@ static int multiboot_exec ( struct image *image ) {
233 266
 			 MBI_FLAG_CMDLINE | MBI_FLAG_MODS );
234 267
 	multiboot_build_memmap ( image, &mbinfo, mbmemmap,
235 268
 				 ( sizeof(mbmemmap) / sizeof(mbmemmap[0]) ) );
236
-	cmdline = ( image->cmdline ? image->cmdline : "" );
237
-	mbinfo.cmdline = virt_to_phys ( cmdline );
269
+	mb_cmdline_offset = 0;
270
+	mbinfo.cmdline = multiboot_add_cmdline ( image->cmdline );
238 271
 	mbinfo.mods_count = multiboot_build_module_list ( image, mbmodules,
239 272
 				( sizeof(mbmodules) / sizeof(mbmodules[0]) ) );
240 273
 	mbinfo.mods_addr = virt_to_phys ( mbmodules );

+ 17
- 4
src/core/monojob.c View File

@@ -16,6 +16,8 @@
16 16
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  */
18 18
 
19
+#include <string.h>
20
+#include <stdio.h>
19 21
 #include <errno.h>
20 22
 #include <gpxe/process.h>
21 23
 #include <console.h>
@@ -54,11 +56,14 @@ struct job_interface monojob = {
54 56
 /**
55 57
  * Wait for single foreground job to complete
56 58
  *
59
+ * @v string		Job description to display
57 60
  * @ret rc		Job final status code
58 61
  */
59
-int monojob_wait ( void ) {
62
+int monojob_wait ( const char *string ) {
60 63
 	int key;
64
+	int rc;
61 65
 
66
+	printf ( "%s... ", string );
62 67
 	monojob_rc = -EINPROGRESS;
63 68
 	while ( monojob_rc == -EINPROGRESS ) {
64 69
 		step();
@@ -67,12 +72,20 @@ int monojob_wait ( void ) {
67 72
 			switch ( key ) {
68 73
 			case CTRL_C:
69 74
 				job_kill ( &monojob );
70
-				return -ECANCELED;
71
-				break;
75
+				rc = -ECANCELED;
76
+				goto done;
72 77
 			default:
73 78
 				break;
74 79
 			}
75 80
 		}
76 81
 	}
77
-	return monojob_rc;
82
+	rc = monojob_rc;
83
+
84
+done:
85
+	if ( rc ) {
86
+		printf ( "%s\n", strerror ( rc ) );
87
+	} else {
88
+		printf ( "ok\n" );
89
+	}
90
+	return rc;
78 91
 }

+ 12
- 2
src/hci/shell.c View File

@@ -62,12 +62,22 @@ struct command exit_command __command = {
62 62
 /** "help" command body */
63 63
 static int help_exec ( int argc __unused, char **argv __unused ) {
64 64
 	struct command *command;
65
+	unsigned int hpos = 0;
65 66
 
66 67
 	printf ( "\nAvailable commands:\n\n" );
67 68
 	for ( command = commands ; command < commands_end ; command++ ) {
68
-		printf ( "  %s\n", command->name );
69
+		hpos += printf ( "  %s", command->name );
70
+		if ( hpos > ( 16 * 4 ) ) {
71
+			printf ( "\n" );
72
+			hpos = 0;
73
+		} else {
74
+			while ( hpos % 16 ) {
75
+				printf ( " " );
76
+				hpos++;
77
+			}
78
+		}
69 79
 	}
70
-	printf ( "\nType \"<command> --help\" for further information\n\n" );
80
+	printf ( "\n\nType \"<command> --help\" for further information\n\n" );
71 81
 	return 0;
72 82
 }
73 83
 

+ 1
- 1
src/include/gpxe/monojob.h View File

@@ -10,6 +10,6 @@
10 10
 struct job_interface;
11 11
 
12 12
 extern struct job_interface monojob;
13
-extern int monojob_wait ( void );
13
+extern int monojob_wait ( const char *string );
14 14
 
15 15
 #endif /* _GPXE_MONOJOB_H */

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

@@ -61,15 +61,20 @@ static int boot_filename ( const char *filename ) {
61 61
 		return -ENOMEM;
62 62
 	}
63 63
 	if ( ( rc = imgfetch ( image, filename,
64
-			       register_and_autoexec_image ) ) != 0 ) {
64
+			       register_and_autoload_image ) ) != 0 ) {
65
+		printf ( "Could not load %s: %s\n",
66
+			 filename, strerror ( rc ) );
67
+		goto done;
68
+	}
69
+	if ( ( rc = imgexec ( image ) ) != 0 ) {
65 70
 		printf ( "Could not boot %s: %s\n",
66 71
 			 filename, strerror ( rc ) );
67
-		image_put ( image );
68
-		return rc;
72
+		goto done;
69 73
 	}
70 74
 
75
+ done:
71 76
 	image_put ( image );
72
-	return 0;
77
+	return rc;
73 78
 }
74 79
 
75 80
 /**

+ 2
- 8
src/usr/dhcpmgmt.c View File

@@ -56,15 +56,9 @@ int dhcp ( struct net_device *netdev ) {
56 56
 	}
57 57
 
58 58
 	/* Perform DHCP */
59
-	printf ( "DHCP (%s %s)...", netdev->name, netdev_hwaddr ( netdev ) );
59
+	printf ( "DHCP (%s %s)", netdev->name, netdev_hwaddr ( netdev ) );
60 60
 	if ( ( rc = start_dhcp ( &monojob, netdev, dhcp_success ) ) == 0 )
61
-		rc = monojob_wait();
62
-
63
-	if ( rc == 0 ) {
64
-		printf ( "done\n" );
65
-	} else {
66
-		printf ( "failed (%s)\n", strerror ( rc ) );
67
-	}
61
+		rc = monojob_wait ( "" );
68 62
 
69 63
 	return rc;
70 64
 }

+ 1
- 1
src/usr/imgmgmt.c View File

@@ -53,7 +53,7 @@ int imgfetch ( struct image *image, const char *uri_string,
53 53
 
54 54
 	if ( ( rc = create_downloader ( &monojob, image, image_register,
55 55
 					LOCATION_URI, uri ) ) == 0 )
56
-		rc = monojob_wait();
56
+		rc = monojob_wait ( uri_string );
57 57
 
58 58
 	uri_put ( uri );
59 59
 	return rc;

Loading…
Cancel
Save