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
  *
23
  *
24
  */
24
  */
25
 
25
 
26
+#include <stdio.h>
26
 #include <errno.h>
27
 #include <errno.h>
27
 #include <assert.h>
28
 #include <assert.h>
28
 #include <realmode.h>
29
 #include <realmode.h>
51
  */
52
  */
52
 #define MAX_MODULES 8
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
 /** Multiboot flags that we support */
65
 /** Multiboot flags that we support */
55
 #define MB_SUPPORTED_FLAGS ( MB_FLAG_PGALIGN | MB_FLAG_MEMMAP | \
66
 #define MB_SUPPORTED_FLAGS ( MB_FLAG_PGALIGN | MB_FLAG_MEMMAP | \
56
 			     MB_FLAG_VIDMODE | MB_FLAG_RAW )
67
 			     MB_FLAG_VIDMODE | MB_FLAG_RAW )
77
 	size_t offset;
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
  * Build multiboot memory map
99
  * Build multiboot memory map
82
  *
100
  *
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
  * Build multiboot module list
166
  * Build multiboot module list
123
  *
167
  *
135
 	unsigned int insert;
179
 	unsigned int insert;
136
 	physaddr_t start;
180
 	physaddr_t start;
137
 	physaddr_t end;
181
 	physaddr_t end;
138
-	char *cmdline;
139
 	unsigned int i;
182
 	unsigned int i;
140
 
183
 
141
 	/* Add each image as a multiboot module */
184
 	/* Add each image as a multiboot module */
151
 		if ( module_image == image )
194
 		if ( module_image == image )
152
 			continue;
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
 		count++;
218
 		count++;
183
 	}
219
 	}
184
 
220
 
185
 	/* Dump module configuration */
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
 	return count;
228
 	return count;
225
  */
259
  */
226
 static int multiboot_exec ( struct image *image ) {
260
 static int multiboot_exec ( struct image *image ) {
227
 	physaddr_t entry = image->priv.phys;
261
 	physaddr_t entry = image->priv.phys;
228
-	char *cmdline;
229
 
262
 
230
 	/* Populate multiboot information structure */
263
 	/* Populate multiboot information structure */
231
 	memset ( &mbinfo, 0, sizeof ( mbinfo ) );
264
 	memset ( &mbinfo, 0, sizeof ( mbinfo ) );
233
 			 MBI_FLAG_CMDLINE | MBI_FLAG_MODS );
266
 			 MBI_FLAG_CMDLINE | MBI_FLAG_MODS );
234
 	multiboot_build_memmap ( image, &mbinfo, mbmemmap,
267
 	multiboot_build_memmap ( image, &mbinfo, mbmemmap,
235
 				 ( sizeof(mbmemmap) / sizeof(mbmemmap[0]) ) );
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
 	mbinfo.mods_count = multiboot_build_module_list ( image, mbmodules,
271
 	mbinfo.mods_count = multiboot_build_module_list ( image, mbmodules,
239
 				( sizeof(mbmodules) / sizeof(mbmodules[0]) ) );
272
 				( sizeof(mbmodules) / sizeof(mbmodules[0]) ) );
240
 	mbinfo.mods_addr = virt_to_phys ( mbmodules );
273
 	mbinfo.mods_addr = virt_to_phys ( mbmodules );

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

16
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
  */
17
  */
18
 
18
 
19
+#include <string.h>
20
+#include <stdio.h>
19
 #include <errno.h>
21
 #include <errno.h>
20
 #include <gpxe/process.h>
22
 #include <gpxe/process.h>
21
 #include <console.h>
23
 #include <console.h>
54
 /**
56
 /**
55
  * Wait for single foreground job to complete
57
  * Wait for single foreground job to complete
56
  *
58
  *
59
+ * @v string		Job description to display
57
  * @ret rc		Job final status code
60
  * @ret rc		Job final status code
58
  */
61
  */
59
-int monojob_wait ( void ) {
62
+int monojob_wait ( const char *string ) {
60
 	int key;
63
 	int key;
64
+	int rc;
61
 
65
 
66
+	printf ( "%s... ", string );
62
 	monojob_rc = -EINPROGRESS;
67
 	monojob_rc = -EINPROGRESS;
63
 	while ( monojob_rc == -EINPROGRESS ) {
68
 	while ( monojob_rc == -EINPROGRESS ) {
64
 		step();
69
 		step();
67
 			switch ( key ) {
72
 			switch ( key ) {
68
 			case CTRL_C:
73
 			case CTRL_C:
69
 				job_kill ( &monojob );
74
 				job_kill ( &monojob );
70
-				return -ECANCELED;
71
-				break;
75
+				rc = -ECANCELED;
76
+				goto done;
72
 			default:
77
 			default:
73
 				break;
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
 /** "help" command body */
62
 /** "help" command body */
63
 static int help_exec ( int argc __unused, char **argv __unused ) {
63
 static int help_exec ( int argc __unused, char **argv __unused ) {
64
 	struct command *command;
64
 	struct command *command;
65
+	unsigned int hpos = 0;
65
 
66
 
66
 	printf ( "\nAvailable commands:\n\n" );
67
 	printf ( "\nAvailable commands:\n\n" );
67
 	for ( command = commands ; command < commands_end ; command++ ) {
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
 	return 0;
81
 	return 0;
72
 }
82
 }
73
 
83
 

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

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

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

61
 		return -ENOMEM;
61
 		return -ENOMEM;
62
 	}
62
 	}
63
 	if ( ( rc = imgfetch ( image, filename,
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
 		printf ( "Could not boot %s: %s\n",
70
 		printf ( "Could not boot %s: %s\n",
66
 			 filename, strerror ( rc ) );
71
 			 filename, strerror ( rc ) );
67
-		image_put ( image );
68
-		return rc;
72
+		goto done;
69
 	}
73
 	}
70
 
74
 
75
+ done:
71
 	image_put ( image );
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
 	}
56
 	}
57
 
57
 
58
 	/* Perform DHCP */
58
 	/* Perform DHCP */
59
-	printf ( "DHCP (%s %s)...", netdev->name, netdev_hwaddr ( netdev ) );
59
+	printf ( "DHCP (%s %s)", netdev->name, netdev_hwaddr ( netdev ) );
60
 	if ( ( rc = start_dhcp ( &monojob, netdev, dhcp_success ) ) == 0 )
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
 	return rc;
63
 	return rc;
70
 }
64
 }

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

53
 
53
 
54
 	if ( ( rc = create_downloader ( &monojob, image, image_register,
54
 	if ( ( rc = create_downloader ( &monojob, image, image_register,
55
 					LOCATION_URI, uri ) ) == 0 )
55
 					LOCATION_URI, uri ) ) == 0 )
56
-		rc = monojob_wait();
56
+		rc = monojob_wait ( uri_string );
57
 
57
 
58
 	uri_put ( uri );
58
 	uri_put ( uri );
59
 	return rc;
59
 	return rc;

Loading…
Cancel
Save