From 688bac16567f4765fb391b8b1457a42048a1df38 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 2 Aug 2007 23:09:03 +0100 Subject: [PATCH 1/3] Place multiboot command lines in base memory; Xen won't pick them up otherwise. :( --- src/arch/i386/image/multiboot.c | 105 +++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 36 deletions(-) diff --git a/src/arch/i386/image/multiboot.c b/src/arch/i386/image/multiboot.c index dfd872cb..fbaebd5c 100644 --- a/src/arch/i386/image/multiboot.c +++ b/src/arch/i386/image/multiboot.c @@ -23,6 +23,7 @@ * */ +#include #include #include #include @@ -51,6 +52,16 @@ struct image_type multiboot_image_type __image_type ( PROBE_MULTIBOOT ); */ #define MAX_MODULES 8 +/** + * Maximum combined length of command lines + * + * Again; sorry. Some broken OSes zero out any non-base memory that + * isn't part of the loaded module set, so we can't just use + * virt_to_phys(cmdline) to point to the command lines, even though + * this would comply with the Multiboot spec. + */ +#define MB_MAX_CMDLINE 512 + /** Multiboot flags that we support */ #define MB_SUPPORTED_FLAGS ( MB_FLAG_PGALIGN | MB_FLAG_MEMMAP | \ MB_FLAG_VIDMODE | MB_FLAG_RAW ) @@ -77,6 +88,13 @@ struct multiboot_header_info { size_t offset; }; +/** Multiboot module command lines */ +static char __bss16_array ( mb_cmdlines, [MB_MAX_CMDLINE] ); +#define mb_cmdlines __use_data16 ( mb_cmdlines ) + +/** Offset within module command lines */ +static unsigned int mb_cmdline_offset; + /** * Build multiboot memory map * @@ -118,6 +136,32 @@ static void multiboot_build_memmap ( struct image *image, } } +/** + * Add command line in base memory + * + * @v cmdline Command line + * @ret physaddr Physical address of command line + */ +physaddr_t multiboot_add_cmdline ( const char *cmdline ) { + char *mb_cmdline; + + if ( ! cmdline ) + cmdline = ""; + + /* Copy command line to base memory buffer */ + mb_cmdline = ( mb_cmdlines + mb_cmdline_offset ); + mb_cmdline_offset += + ( snprintf ( mb_cmdline, + ( sizeof ( mb_cmdlines ) - mb_cmdline_offset ), + "%s", cmdline ) + 1 ); + + /* Truncate to terminating NUL in buffer if necessary */ + if ( mb_cmdline_offset > sizeof ( mb_cmdlines ) ) + mb_cmdline_offset = ( sizeof ( mb_cmdlines ) - 1 ); + + return virt_to_phys ( mb_cmdline ); +} + /** * Build multiboot module list * @@ -135,7 +179,6 @@ multiboot_build_module_list ( struct image *image, unsigned int insert; physaddr_t start; physaddr_t end; - char *cmdline; unsigned int i; /* Add each image as a multiboot module */ @@ -151,44 +194,35 @@ multiboot_build_module_list ( struct image *image, if ( module_image == image ) continue; - /* If we don't have a data structure to populate, just count */ - if ( modules ) { - - /* At least some OSes expect the multiboot - * modules to be in ascending order, so we - * have to support it. - */ - start = user_to_phys ( module_image->data, 0 ); - end = user_to_phys ( module_image->data, - module_image->len ); - for ( insert = 0 ; insert < count ; insert++ ) { - if ( start < modules[insert].mod_start ) - break; - } - module = &modules[insert]; - memmove ( ( module + 1 ), module, - ( ( count - insert ) * sizeof ( *module ) )); - module->mod_start = start; - module->mod_end = end; - cmdline = ( module_image->cmdline ? - module_image->cmdline : "" ); - module->string = virt_to_phys ( cmdline ); - module->reserved = 0; - - /* We promise to page-align modules */ - assert ( ( module->mod_start & 0xfff ) == 0 ); + /* At least some OSes expect the multiboot modules to + * be in ascending order, so we have to support it. + */ + start = user_to_phys ( module_image->data, 0 ); + end = user_to_phys ( module_image->data, module_image->len ); + for ( insert = 0 ; insert < count ; insert++ ) { + if ( start < modules[insert].mod_start ) + break; } + module = &modules[insert]; + memmove ( ( module + 1 ), module, + ( ( count - insert ) * sizeof ( *module ) ) ); + module->mod_start = start; + module->mod_end = end; + module->string = + multiboot_add_cmdline ( module_image->cmdline ); + module->reserved = 0; + + /* We promise to page-align modules */ + assert ( ( module->mod_start & 0xfff ) == 0 ); count++; } /* Dump module configuration */ - if ( modules ) { - for ( i = 0 ; i < count ; i++ ) { - DBGC ( image, "MULTIBOOT %p module %d is [%lx,%lx)\n", - image, i, modules[i].mod_start, - modules[i].mod_end ); - } + for ( i = 0 ; i < count ; i++ ) { + DBGC ( image, "MULTIBOOT %p module %d is [%lx,%lx)\n", + image, i, modules[i].mod_start, + modules[i].mod_end ); } return count; @@ -225,7 +259,6 @@ static struct multiboot_module __bss16_array ( mbmodules, [MAX_MODULES] ); */ static int multiboot_exec ( struct image *image ) { physaddr_t entry = image->priv.phys; - char *cmdline; /* Populate multiboot information structure */ memset ( &mbinfo, 0, sizeof ( mbinfo ) ); @@ -233,8 +266,8 @@ static int multiboot_exec ( struct image *image ) { MBI_FLAG_CMDLINE | MBI_FLAG_MODS ); multiboot_build_memmap ( image, &mbinfo, mbmemmap, ( sizeof(mbmemmap) / sizeof(mbmemmap[0]) ) ); - cmdline = ( image->cmdline ? image->cmdline : "" ); - mbinfo.cmdline = virt_to_phys ( cmdline ); + mb_cmdline_offset = 0; + mbinfo.cmdline = multiboot_add_cmdline ( image->cmdline ); mbinfo.mods_count = multiboot_build_module_list ( image, mbmodules, ( sizeof(mbmodules) / sizeof(mbmodules[0]) ) ); mbinfo.mods_addr = virt_to_phys ( mbmodules ); From 6e46dddc2c7521a076a4d274e4a89a69e9c1981d Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 3 Aug 2007 01:03:21 +0100 Subject: [PATCH 2/3] Print multiple commands per line in help --- src/hci/shell.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/hci/shell.c b/src/hci/shell.c index b14af542..18b1068e 100644 --- a/src/hci/shell.c +++ b/src/hci/shell.c @@ -62,12 +62,22 @@ struct command exit_command __command = { /** "help" command body */ static int help_exec ( int argc __unused, char **argv __unused ) { struct command *command; + unsigned int hpos = 0; printf ( "\nAvailable commands:\n\n" ); for ( command = commands ; command < commands_end ; command++ ) { - printf ( " %s\n", command->name ); + hpos += printf ( " %s", command->name ); + if ( hpos > ( 16 * 4 ) ) { + printf ( "\n" ); + hpos = 0; + } else { + while ( hpos % 16 ) { + printf ( " " ); + hpos++; + } + } } - printf ( "\nType \" --help\" for further information\n\n" ); + printf ( "\n\nType \" --help\" for further information\n\n" ); return 0; } From 218651e1259da924a19db66e7cb9ae885075892f Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 3 Aug 2007 12:49:21 +0100 Subject: [PATCH 3/3] Display name and status of each file as it is downloaded. --- src/core/monojob.c | 21 +++++++++++++++++---- src/include/gpxe/monojob.h | 2 +- src/usr/autoboot.c | 13 +++++++++---- src/usr/dhcpmgmt.c | 10 ++-------- src/usr/imgmgmt.c | 2 +- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/core/monojob.c b/src/core/monojob.c index b4042a3d..ea9bc834 100644 --- a/src/core/monojob.c +++ b/src/core/monojob.c @@ -16,6 +16,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include +#include #include #include #include @@ -54,11 +56,14 @@ struct job_interface monojob = { /** * Wait for single foreground job to complete * + * @v string Job description to display * @ret rc Job final status code */ -int monojob_wait ( void ) { +int monojob_wait ( const char *string ) { int key; + int rc; + printf ( "%s... ", string ); monojob_rc = -EINPROGRESS; while ( monojob_rc == -EINPROGRESS ) { step(); @@ -67,12 +72,20 @@ int monojob_wait ( void ) { switch ( key ) { case CTRL_C: job_kill ( &monojob ); - return -ECANCELED; - break; + rc = -ECANCELED; + goto done; default: break; } } } - return monojob_rc; + rc = monojob_rc; + +done: + if ( rc ) { + printf ( "%s\n", strerror ( rc ) ); + } else { + printf ( "ok\n" ); + } + return rc; } diff --git a/src/include/gpxe/monojob.h b/src/include/gpxe/monojob.h index f6cebb6b..aaa38d03 100644 --- a/src/include/gpxe/monojob.h +++ b/src/include/gpxe/monojob.h @@ -10,6 +10,6 @@ struct job_interface; extern struct job_interface monojob; -extern int monojob_wait ( void ); +extern int monojob_wait ( const char *string ); #endif /* _GPXE_MONOJOB_H */ diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c index 2afe596e..91836978 100644 --- a/src/usr/autoboot.c +++ b/src/usr/autoboot.c @@ -61,15 +61,20 @@ static int boot_filename ( const char *filename ) { return -ENOMEM; } if ( ( rc = imgfetch ( image, filename, - register_and_autoexec_image ) ) != 0 ) { + register_and_autoload_image ) ) != 0 ) { + printf ( "Could not load %s: %s\n", + filename, strerror ( rc ) ); + goto done; + } + if ( ( rc = imgexec ( image ) ) != 0 ) { printf ( "Could not boot %s: %s\n", filename, strerror ( rc ) ); - image_put ( image ); - return rc; + goto done; } + done: image_put ( image ); - return 0; + return rc; } /** diff --git a/src/usr/dhcpmgmt.c b/src/usr/dhcpmgmt.c index f1eb2d63..bd05c5ee 100644 --- a/src/usr/dhcpmgmt.c +++ b/src/usr/dhcpmgmt.c @@ -56,15 +56,9 @@ int dhcp ( struct net_device *netdev ) { } /* Perform DHCP */ - printf ( "DHCP (%s %s)...", netdev->name, netdev_hwaddr ( netdev ) ); + printf ( "DHCP (%s %s)", netdev->name, netdev_hwaddr ( netdev ) ); if ( ( rc = start_dhcp ( &monojob, netdev, dhcp_success ) ) == 0 ) - rc = monojob_wait(); - - if ( rc == 0 ) { - printf ( "done\n" ); - } else { - printf ( "failed (%s)\n", strerror ( rc ) ); - } + rc = monojob_wait ( "" ); return rc; } diff --git a/src/usr/imgmgmt.c b/src/usr/imgmgmt.c index 0a77469a..bead4867 100644 --- a/src/usr/imgmgmt.c +++ b/src/usr/imgmgmt.c @@ -53,7 +53,7 @@ int imgfetch ( struct image *image, const char *uri_string, if ( ( rc = create_downloader ( &monojob, image, image_register, LOCATION_URI, uri ) ) == 0 ) - rc = monojob_wait(); + rc = monojob_wait ( uri_string ); uri_put ( uri ); return rc;