From df48e9e18d649f5305b701eb7c77c5a0bef9515d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 Nov 2009 16:25:50 +0100 Subject: [PATCH 01/63] REimport of videomask patch --- commands/videotest.c | 11 +- include/grub/video.h | 13 ++- loader/i386/linux.c | 4 +- loader/i386/pc/xnu.c | 22 ++-- term/gfxterm.c | 14 +-- video/i386/pc/vbe.c | 36 ++++--- video/video.c | 244 +++++++++++++++++++------------------------ 7 files changed, 166 insertions(+), 178 deletions(-) diff --git a/commands/videotest.c b/commands/videotest.c index 6fe4b9bd1..fe504ee7b 100644 --- a/commands/videotest.c +++ b/commands/videotest.c @@ -30,9 +30,7 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), char **args __attribute__ ((unused))) { - if (grub_video_set_mode ("1024x768;800x600;640x480", 0) != GRUB_ERR_NONE) - return grub_errno; - + grub_err_t err; grub_video_color_t color; unsigned int x; unsigned int y; @@ -49,6 +47,10 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)), const char *str; int texty; + err = grub_video_set_mode ("auto", GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); + if (err) + return err; + grub_video_get_viewport (&x, &y, &width, &height); grub_video_create_render_target (&text_layer, width, height, @@ -152,12 +154,13 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)), grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); - for (i = 0; i < 255; i++) + for (i = 0; i < 5; i++) { color = grub_video_map_rgb (i, 33, 77); grub_video_fill_rect (color, 0, 0, width, height); grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_BLEND, 0, 0, 0, 0, width, height); + grub_video_swap_buffers (); } grub_getkey (); diff --git a/include/grub/video.h b/include/grub/video.h index 4145db465..53fe67c4e 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -171,7 +171,7 @@ struct grub_video_adapter grub_err_t (*fini) (void); grub_err_t (*setup) (unsigned int width, unsigned int height, - unsigned int mode_type); + unsigned int mode_type, unsigned int mode_mask); grub_err_t (*get_info) (struct grub_video_mode_info *mode_info); @@ -307,7 +307,14 @@ grub_err_t grub_video_set_active_render_target (struct grub_video_render_target grub_err_t grub_video_get_active_render_target (struct grub_video_render_target **target); grub_err_t grub_video_set_mode (const char *modestring, - int NESTED_FUNC_ATTR (*hook) (grub_video_adapter_t p, - struct grub_video_mode_info *mode_info)); + unsigned int modemask, + unsigned int modevalue); + +static inline int +grub_video_check_mode_flag (unsigned int flags, unsigned int mask, + unsigned int flag, int def) +{ + return (flag & mask) ? !! (flags & flag) : def; +} #endif /* ! GRUB_VIDEO_HEADER */ diff --git a/loader/i386/linux.c b/loader/i386/linux.c index 4bdb09b24..8659e8245 100644 --- a/loader/i386/linux.c +++ b/loader/i386/linux.c @@ -523,11 +523,11 @@ grub_linux_boot (void) if (! tmp) return grub_errno; grub_sprintf (tmp, "%s;text", modevar); - err = grub_video_set_mode (tmp, 0); + err = grub_video_set_mode (tmp, 0, 0); grub_free (tmp); } else - err = grub_video_set_mode ("text", 0); + err = grub_video_set_mode ("text", 0, 0); if (err) { diff --git a/loader/i386/pc/xnu.c b/loader/i386/pc/xnu.c index ebb176bb4..839d0ad44 100644 --- a/loader/i386/pc/xnu.c +++ b/loader/i386/pc/xnu.c @@ -26,16 +26,7 @@ #define min(a,b) (((a) < (b)) ? (a) : (b)) #define max(a,b) (((a) > (b)) ? (a) : (b)) -#define DEFAULT_VIDEO_MODE "1024x768x32,800x600x32,640x480x32" - -static int NESTED_FUNC_ATTR video_hook (grub_video_adapter_t p __attribute__ ((unused)), - struct grub_video_mode_info *info) -{ - if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT) - return 0; - - return 1; -} +#define DEFAULT_VIDEO_MODE "auto" /* Setup video for xnu. */ grub_err_t @@ -48,8 +39,12 @@ grub_xnu_set_video (struct grub_xnu_boot_params *params) grub_err_t err; modevar = grub_env_get ("gfxpayload"); + /* Consider only graphical 32-bit deep modes. */ if (! modevar || *modevar == 0) - err = grub_video_set_mode (DEFAULT_VIDEO_MODE, video_hook); + err = grub_video_set_mode (DEFAULT_VIDEO_MODE, + GRUB_VIDEO_MODE_TYPE_PURE_TEXT + | GRUB_VIDEO_MODE_TYPE_DEPTH_MASK, + 32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS); else { tmp = grub_malloc (grub_strlen (modevar) @@ -58,7 +53,10 @@ grub_xnu_set_video (struct grub_xnu_boot_params *params) return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't allocate temporary storag"); grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar); - err = grub_video_set_mode (tmp, video_hook); + err = grub_video_set_mode (tmp, + GRUB_VIDEO_MODE_TYPE_PURE_TEXT + | GRUB_VIDEO_MODE_TYPE_DEPTH_MASK, + 32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS); grub_free (tmp); } diff --git a/term/gfxterm.c b/term/gfxterm.c index f161499e6..57c51cffa 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -27,7 +27,7 @@ #include #include -#define DEFAULT_VIDEO_MODE "1024x768,800x600,640x480" +#define DEFAULT_VIDEO_MODE "auto" #define DEFAULT_BORDER_WIDTH 10 #define DEFAULT_STANDARD_COLOR 0x07 @@ -244,12 +244,6 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y, return grub_errno; } -static int NESTED_FUNC_ATTR video_hook (grub_video_adapter_t p __attribute__ ((unused)), - struct grub_video_mode_info *info) -{ - return ! (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT); -} - static grub_err_t grub_gfxterm_init (void) { @@ -269,13 +263,15 @@ grub_gfxterm_init (void) /* Parse gfxmode environment variable if set. */ modevar = grub_env_get ("gfxmode"); if (! modevar || *modevar == 0) - err = grub_video_set_mode (DEFAULT_VIDEO_MODE, video_hook); + err = grub_video_set_mode (DEFAULT_VIDEO_MODE, + GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); else { tmp = grub_malloc (grub_strlen (modevar) + sizeof (DEFAULT_VIDEO_MODE) + 1); grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar); - err = grub_video_set_mode (tmp, video_hook); + err = grub_video_set_mode (tmp, + GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); grub_free (tmp); } diff --git a/video/i386/pc/vbe.c b/video/i386/pc/vbe.c index a285b26ba..8759ba652 100644 --- a/video/i386/pc/vbe.c +++ b/video/i386/pc/vbe.c @@ -362,7 +362,7 @@ grub_video_vbe_fini (void) static grub_err_t grub_video_vbe_setup (unsigned int width, unsigned int height, - unsigned int mode_type) + unsigned int mode_type, unsigned int mode_mask) { grub_uint16_t *p; struct grub_vbe_mode_info_block vbe_mode_info; @@ -412,32 +412,40 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, /* Not compatible memory model. */ continue; - if ((vbe_mode_info.x_resolution != width) - || (vbe_mode_info.y_resolution != height)) + if (((vbe_mode_info.x_resolution != width) + || (vbe_mode_info.y_resolution != height)) && width != 0 && height != 0) /* Non matching resolution. */ continue; /* Check if user requested RGB or index color mode. */ - if ((mode_type & GRUB_VIDEO_MODE_TYPE_COLOR_MASK) != 0) + if ((mode_mask & GRUB_VIDEO_MODE_TYPE_COLOR_MASK) != 0) { - if (((mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR) != 0) - && (vbe_mode_info.memory_model != GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL)) - /* Requested only index color modes. */ - continue; + unsigned my_mode_type = 0; - if (((mode_type & GRUB_VIDEO_MODE_TYPE_RGB) != 0) - && (vbe_mode_info.memory_model != GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR)) - /* Requested only RGB modes. */ - continue; + if (vbe_mode_info.memory_model == GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL) + my_mode_type |= GRUB_VIDEO_MODE_TYPE_INDEX_COLOR; + + if (vbe_mode_info.memory_model == GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR) + my_mode_type |= GRUB_VIDEO_MODE_TYPE_RGB; + + if ((my_mode_type & mode_mask + & (GRUB_VIDEO_MODE_TYPE_RGB | GRUB_VIDEO_MODE_TYPE_INDEX_COLOR)) + != (mode_type & mode_mask + & (GRUB_VIDEO_MODE_TYPE_RGB + | GRUB_VIDEO_MODE_TYPE_INDEX_COLOR))) + continue; } /* If there is a request for specific depth, ignore others. */ if ((depth != 0) && (vbe_mode_info.bits_per_pixel != depth)) continue; - /* Select mode with most number of bits per pixel. */ + /* Select mode with most of "volume" (size of framebuffer in bits). */ if (best_vbe_mode != 0) - if (vbe_mode_info.bits_per_pixel < best_vbe_mode_info.bits_per_pixel) + if ((grub_uint64_t) vbe_mode_info.bits_per_pixel + * vbe_mode_info.x_resolution * vbe_mode_info.y_resolution + < (grub_uint64_t) best_vbe_mode_info.bits_per_pixel + * best_vbe_mode_info.x_resolution * best_vbe_mode_info.y_resolution) continue; /* Save so far best mode information for later use. */ diff --git a/video/video.c b/video/video.c index c1d66bdd0..eff257122 100644 --- a/video/video.c +++ b/video/video.c @@ -399,21 +399,81 @@ grub_video_get_active_render_target (struct grub_video_render_target **target) return grub_video_adapter_active->get_active_render_target (target); } +/* Parse x[x]*/ +static grub_err_t +parse_modespec (const char *current_mode, int *width, int *height, int *depth) +{ + const char *value; + const char *param = current_mode; + + *width = *height = *depth = -1; + + if (grub_strcmp (param, "auto") == 0) + { + *width = *height = 0; + return GRUB_ERR_NONE; + } + + /* Find width value. */ + value = param; + param = grub_strchr(param, 'x'); + if (param == NULL) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Invalid mode: %s\n", + current_mode); + + param++; + + *width = grub_strtoul (value, 0, 0); + if (grub_errno != GRUB_ERR_NONE) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Invalid mode: %s\n", + current_mode); + + /* Find height value. */ + value = param; + param = grub_strchr(param, 'x'); + if (param == NULL) + { + *height = grub_strtoul (value, 0, 0); + if (grub_errno != GRUB_ERR_NONE) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Invalid mode: %s\n", + current_mode); + } + else + { + /* We have optional color depth value. */ + param++; + + *height = grub_strtoul (value, 0, 0); + if (grub_errno != GRUB_ERR_NONE) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Invalid mode: %s\n", + current_mode); + + /* Convert color depth value. */ + value = param; + *depth = grub_strtoul (value, 0, 0); + if (grub_errno != GRUB_ERR_NONE) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Invalid mode: %s\n", + current_mode); + } + return GRUB_ERR_NONE; +} + grub_err_t grub_video_set_mode (const char *modestring, - int NESTED_FUNC_ATTR (*hook) (grub_video_adapter_t p, - struct grub_video_mode_info *mode_info)) + unsigned int modemask, + unsigned int modevalue) { char *tmp; char *next_mode; char *current_mode; - char *param; - char *value; char *modevar; - int width = -1; - int height = -1; - int depth = -1; - int flags = 0; + + modevalue &= modemask; /* Take copy of env.var. as we don't want to modify that. */ modevar = grub_strdup (modestring); @@ -429,26 +489,26 @@ grub_video_set_mode (const char *modestring, || grub_memcmp (next_mode, "keep,", sizeof ("keep,") - 1) == 0 || grub_memcmp (next_mode, "keep;", sizeof ("keep;") - 1) == 0) { - struct grub_video_mode_info mode_info; int suitable = 1; grub_err_t err; - grub_memset (&mode_info, 0, sizeof (mode_info)); - if (grub_video_adapter_active) { + struct grub_video_mode_info mode_info; + grub_memset (&mode_info, 0, sizeof (mode_info)); err = grub_video_get_info (&mode_info); if (err) { suitable = 0; grub_errno = GRUB_ERR_NONE; } + if ((mode_info.mode_type & modemask) != modevalue) + suitable = 0; } - else - mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_PURE_TEXT; + else if (((GRUB_VIDEO_MODE_TYPE_PURE_TEXT & modemask) != 0) + && ((GRUB_VIDEO_MODE_TYPE_PURE_TEXT & modevalue) == 0)) + suitable = 0; - if (suitable && hook) - suitable = hook (grub_video_adapter_active, &mode_info); if (suitable) { grub_free (modevar); @@ -482,15 +542,16 @@ grub_video_set_mode (const char *modestring, /* Loop until all modes has been tested out. */ while (next_mode != NULL) { + int width = -1; + int height = -1; + int depth = -1; + grub_err_t err; + unsigned int flags = modevalue; + unsigned int flagmask = modemask; + /* Use last next_mode as current mode. */ tmp = next_mode; - /* Reset video mode settings. */ - width = -1; - height = -1; - depth = -1; - flags = 0; - /* Save position of next mode and separate modes. */ for (; *next_mode; next_mode++) if (*next_mode == ',' || *next_mode == ';') @@ -509,19 +570,16 @@ grub_video_set_mode (const char *modestring, /* Initialize token holders. */ current_mode = tmp; - param = tmp; - value = NULL; /* XXX: we assume that we're in pure text mode if no video mode is initialized. Is it always true? */ - if (grub_strcmp (param, "text") == 0) + if (grub_strcmp (current_mode, "text") == 0) { struct grub_video_mode_info mode_info; grub_memset (&mode_info, 0, sizeof (mode_info)); - mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_PURE_TEXT; - - if (! hook || hook (0, &mode_info)) + if (((GRUB_VIDEO_MODE_TYPE_PURE_TEXT & modemask) == 0) + || ((GRUB_VIDEO_MODE_TYPE_PURE_TEXT & modevalue) != 0)) { /* Valid mode found from adapter, and it has been activated. Specify it as active adapter. */ @@ -534,121 +592,31 @@ grub_video_set_mode (const char *modestring, } } - /* Parse x[x]*/ - - /* Find width value. */ - value = param; - param = grub_strchr(param, 'x'); - if (param == NULL) + err = parse_modespec (current_mode, &width, &height, &depth); + if (err) { - grub_err_t rc; - - /* First setup error message. */ - rc = grub_error (GRUB_ERR_BAD_ARGUMENT, - "Invalid mode: %s\n", - current_mode); - /* Free memory before returning. */ grub_free (modevar); - return rc; - } - - *param = 0; - param++; - - width = grub_strtoul (value, 0, 0); - if (grub_errno != GRUB_ERR_NONE) - { - grub_err_t rc; - - /* First setup error message. */ - rc = grub_error (GRUB_ERR_BAD_ARGUMENT, - "Invalid mode: %s\n", - current_mode); - - /* Free memory before returning. */ - grub_free (modevar); - - return rc; - } - - /* Find height value. */ - value = param; - param = grub_strchr(param, 'x'); - if (param == NULL) - { - height = grub_strtoul (value, 0, 0); - if (grub_errno != GRUB_ERR_NONE) - { - grub_err_t rc; - - /* First setup error message. */ - rc = grub_error (GRUB_ERR_BAD_ARGUMENT, - "Invalid mode: %s\n", - current_mode); - - /* Free memory before returning. */ - grub_free (modevar); - - return rc; - } - } - else - { - /* We have optional color depth value. */ - *param = 0; - param++; - - height = grub_strtoul (value, 0, 0); - if (grub_errno != GRUB_ERR_NONE) - { - grub_err_t rc; - - /* First setup error message. */ - rc = grub_error (GRUB_ERR_BAD_ARGUMENT, - "Invalid mode: %s\n", - current_mode); - - /* Free memory before returning. */ - grub_free (modevar); - - return rc; - } - - /* Convert color depth value. */ - value = param; - depth = grub_strtoul (value, 0, 0); - if (grub_errno != GRUB_ERR_NONE) - { - grub_err_t rc; - - /* First setup error message. */ - rc = grub_error (GRUB_ERR_BAD_ARGUMENT, - "Invalid mode: %s\n", - current_mode); - - /* Free memory before returning. */ - grub_free (modevar); - - return rc; - } + return err; } /* Try out video mode. */ - /* If we have 8 or less bits, then assume that it is indexed color mode. */ - if ((depth <= 8) && (depth != -1)) - flags |= GRUB_VIDEO_MODE_TYPE_INDEX_COLOR; + /* If user requested specific depth check if this depth is supported. */ + if (depth != -1 && (flagmask & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK) + && + (((flags & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK) + != ((depth << GRUB_VIDEO_MODE_TYPE_DEPTH_POS) + & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK)))) + continue; - /* We have more than 8 bits, then assume that it is RGB color mode. */ - if (depth > 8) - flags |= GRUB_VIDEO_MODE_TYPE_RGB; - - /* If user requested specific depth, forward that information to driver. */ if (depth != -1) - flags |= (depth << GRUB_VIDEO_MODE_TYPE_DEPTH_POS) - & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK; + { + flags |= (depth << GRUB_VIDEO_MODE_TYPE_DEPTH_POS) + & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK; + flagmask |= GRUB_VIDEO_MODE_TYPE_DEPTH_MASK; + } /* Try to initialize requested mode. Ignore any errors. */ grub_video_adapter_t p; @@ -670,7 +638,7 @@ grub_video_set_mode (const char *modestring, } /* Try to initialize video mode. */ - err = p->setup (width, height, flags); + err = p->setup (width, height, flags, flagmask); if (err != GRUB_ERR_NONE) { p->fini (); @@ -686,7 +654,15 @@ grub_video_set_mode (const char *modestring, continue; } - if (hook && ! hook (p, &mode_info)) + flags = mode_info.mode_type & ~GRUB_VIDEO_MODE_TYPE_DEPTH_MASK; + flags |= (mode_info.bpp << GRUB_VIDEO_MODE_TYPE_DEPTH_POS) + & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK; + + /* Check that mode is suitable for upper layer. */ + if ((flags & GRUB_VIDEO_MODE_TYPE_PURE_TEXT) + ? (((GRUB_VIDEO_MODE_TYPE_PURE_TEXT & modemask) != 0) + && ((GRUB_VIDEO_MODE_TYPE_PURE_TEXT & modevalue) == 0)) + : ((flags & modemask) != modevalue)) { p->fini (); grub_errno = GRUB_ERR_NONE; From 242f0731c7805a94d79eade8cb0cf928a526839c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 20 Nov 2009 09:41:20 +0100 Subject: [PATCH 02/63] reimported savedefault by cjwatson and myself Also-By: Vladimir 'phcoder' Serbinenko --- ChangeLog.savedefault | 29 +++++++ conf/common.rmk | 14 ++++ normal/menu.c | 2 + normal/menu_text.c | 26 ++++++- util/grub-install.in | 5 ++ util/grub-mkconfig_lib.in | 8 ++ util/grub-reboot.in | 104 ++++++++++++++++++++++++++ util/grub-set-default.in | 99 ++++++++++++++++++++++++ util/grub.d/00_header.in | 8 ++ util/grub.d/10_hurd.in | 1 + util/grub.d/10_kfreebsd.in | 1 + util/grub.d/10_linux.in | 1 + util/grub.d/10_windows.in | 1 + util/grub.d/30_os-prober.in | 3 + util/i386/efi/grub-install.in | 5 ++ util/ieee1275/grub-install.in | 5 ++ util/sparc64/ieee1275/grub-install.in | 5 ++ 17 files changed, 315 insertions(+), 2 deletions(-) create mode 100644 ChangeLog.savedefault create mode 100644 util/grub-reboot.in create mode 100644 util/grub-set-default.in diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault new file mode 100644 index 000000000..c18106bd5 --- /dev/null +++ b/ChangeLog.savedefault @@ -0,0 +1,29 @@ +2009-10-25 Vladimir Serbinenko +2009-10-25 Colin Watson + + * normal/menu.c (grub_menu_execute_entry): Save selected entry title + in `chosen' environment variable. + * normal/menu_text.c (get_entry_number): Check if the variable + matches the title of a menu entry. + (run_menu): Pass menu to get_entry_number. + + * util/grub-reboot.in: New file. + * util/grub-set-default.in: New file. + * conf/common.rmk (grub-reboot): New utility. + (grub-set-default): New utility. + + * util/grub-mkconfig_lib.in (save_default_entry): New function. + * util/grub.d/00_header.in: If GRUB_DEFAULT is `saved', set + default to `${saved_entry}'. If `${prev_saved_entry}' is non-empty, + move it to `saved_entry' for the next boot. Load environment on + initialisation. + * util/grub.d/10_kfreebsd.in: Call save_default_entry. + * util/grub.d/10_hurd.in: Likewise. + * util/grub.d/10_linux.in (linux_entry): Likewise. + * util/grub.d/10_windows.in: Likewise. + * util/grub.d/30_os-prober.in: Likewise. + + * util/grub-install.in: Create environment block. + * util/i386/efi/grub-install.in: Likewise. + * util/ieee1275/grub-install.in: Likewise. + * util/sparc64/ieee1275/grub-install.in: Likewise. diff --git a/conf/common.rmk b/conf/common.rmk index 173f24b62..881c72795 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -175,6 +175,20 @@ CLEANFILES += $(grub-mkconfig_SCRIPTS) grub-mkconfig_DATA += util/grub.d/README +# For grub-set-default. +grub-set-default: util/grub-set-default.in config.status + ./config.status --file=$@:$< + chmod +x $@ +sbin_SCRIPTS += grub-set-default +CLEANFILES += grub-set-default + +# For grub-reboot. +grub-reboot: util/grub-reboot.in config.status + ./config.status --file=$@:$< + chmod +x $@ +sbin_SCRIPTS += grub-reboot +CLEANFILES += grub-reboot + # Filing systems. pkglib_MODULES += fshelp.mod fat.mod ufs1.mod ufs2.mod ext2.mod ntfs.mod \ ntfscomp.mod minix.mod hfs.mod jfs.mod iso9660.mod xfs.mod \ diff --git a/normal/menu.c b/normal/menu.c index 8ee7d1c22..b9f74b7d7 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -137,6 +137,8 @@ grub_menu_execute_entry(grub_menu_entry_t entry) return; } + grub_env_set ("chosen", entry->title); + grub_parser_execute ((char *) entry->sourcecode); if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ()) diff --git a/normal/menu_text.c b/normal/menu_text.c index e0d96c47f..19f9cf756 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -237,7 +237,7 @@ grub_menu_init_page (int nested, int edit) /* Get the entry number from the variable NAME. */ static int -get_entry_number (const char *name) +get_entry_number (grub_menu_t menu, const char *name) { char *val; int entry; @@ -250,6 +250,28 @@ get_entry_number (const char *name) entry = (int) grub_strtoul (val, 0, 0); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + /* See if the variable matches the title of a menu entry. */ + grub_menu_entry_t e = menu->entry_list; + int i; + + grub_errno = GRUB_ERR_NONE; + + for (i = 0; e; i++) + { + if (grub_strcmp (e->title, val) == 0) + { + entry = i; + break; + } + e = e->next; + } + + if (! e) + entry = -1; + } + if (grub_errno != GRUB_ERR_NONE) { grub_errno = GRUB_ERR_NONE; @@ -291,7 +313,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) first = 0; - default_entry = get_entry_number ("default"); + default_entry = get_entry_number (menu, "default"); /* If DEFAULT_ENTRY is not within the menu entries, fall back to the first entry. */ diff --git a/util/grub-install.in b/util/grub-install.in index 356e161e7..1cf7135fd 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -39,6 +39,7 @@ else fi grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` rootdir= grub_prefix=`echo /boot/grub | sed ${transform}` modules= @@ -250,6 +251,10 @@ fi # Write device to a variable so we don't have to traverse /dev every time. grub_device=`$grub_probe --target=device ${grubdir}` +if ! test -f ${grubdir}/grubenv; then + $grub_editenv ${grubdir}/grubenv create +fi + # Create the core image. First, auto-detect the filesystem module. fs_module=`$grub_probe --target=fs --device ${grub_device}` if test "x$fs_module" = x -a "x$modules" = x; then diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index bb30cc475..8cdd1d470 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -130,6 +130,14 @@ convert_system_path_to_grub_path () echo ${drive}${relative_path} } +save_default_entry () +{ + if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then + echo 'saved_entry=${chosen}' + echo 'save_env saved_entry' + fi +} + prepare_grub_to_access_device () { device=$1 diff --git a/util/grub-reboot.in b/util/grub-reboot.in new file mode 100644 index 000000000..886d61770 --- /dev/null +++ b/util/grub-reboot.in @@ -0,0 +1,104 @@ +#! /bin/sh +# +# Set a default boot entry for GRUB, for the next boot only. +# Copyright (C) 2004,2009 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see . + +# Initialize some variables. +transform="@program_transform_name@" + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ + +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` +rootdir= + +# Usage: usage +# Print the usage. +usage () { + cat <. +EOF +} + +# Check the arguments. +for option in "$@"; do + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --root-directory=*) + rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; + -*) + echo "Unrecognized option \`$option'" 1>&2 + usage + exit 1 + ;; + *) + if test "x$entry" != x; then + echo "More than one entry?" 1>&2 + usage + exit 1 + fi + entry="${option}" ;; + esac +done + +if test "x$entry" = x; then + echo "entry not specified." 1>&2 + usage + exit 1 +fi + +# Initialize these directories here, since ROOTDIR was initialized. +case "$host_os" in +netbsd* | openbsd*) + # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub + # instead of /boot/grub. + grub_prefix=`echo /grub | sed ${transform}` + bootdir=${rootdir} + ;; +*) + # Use /boot/grub by default. + bootdir=${rootdir}/boot + ;; +esac + +grubdir=${bootdir}/`echo grub | sed ${transform}` + +prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry=//p'` +if [ "$prev_saved_entry" ]; then + $grub_editenv ${grubdir}/grubenv set prev_saved_entry="$prev_saved_entry" +else + $grub_editenv ${grubdir}/grubenv unset prev_saved_entry +fi +$grub_editenv ${grubdir}/grubenv set saved_entry="$entry" + +# Bye. +exit 0 diff --git a/util/grub-set-default.in b/util/grub-set-default.in new file mode 100644 index 000000000..6663d3fbd --- /dev/null +++ b/util/grub-set-default.in @@ -0,0 +1,99 @@ +#! /bin/sh +# +# Set a default boot entry for GRUB. +# Copyright (C) 2004,2009 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see . + +# Initialize some variables. +transform="@program_transform_name@" + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ + +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` +rootdir= + +# Usage: usage +# Print the usage. +usage () { + cat <. +EOF +} + +# Check the arguments. +for option in "$@"; do + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --root-directory=*) + rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; + -*) + echo "Unrecognized option \`$option'" 1>&2 + usage + exit 1 + ;; + *) + if test "x$entry" != x; then + echo "More than one entry?" 1>&2 + usage + exit 1 + fi + entry="${option}" ;; + esac +done + +if test "x$entry" = x; then + echo "entry not specified." 1>&2 + usage + exit 1 +fi + +# Initialize these directories here, since ROOTDIR was initialized. +case "$host_os" in +netbsd* | openbsd*) + # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub + # instead of /boot/grub. + grub_prefix=`echo /grub | sed ${transform}` + bootdir=${rootdir} + ;; +*) + # Use /boot/grub by default. + bootdir=${rootdir}/boot + ;; +esac + +grubdir=${bootdir}/`echo grub | sed ${transform}` + +$grub_editenv ${grubdir}/grubenv unset prev_saved_entry +$grub_editenv ${grubdir}/grubenv set saved_entry="$entry" + +# Bye. +exit 0 diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 9f421dc1c..7279469b7 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -32,11 +32,19 @@ for i in ${GRUB_PRELOAD_MODULES} ; do done if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi +if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi cat << EOF +load_env set default=${GRUB_DEFAULT} +if [ \${prev_saved_entry} ]; then + saved_entry=\${prev_saved_entry} + save_env saved_entry + prev_saved_entry= + save_env prev_saved_entry +fi EOF case ${GRUB_TERMINAL_INPUT}:${GRUB_TERMINAL_OUTPUT} in diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in index e693c7dfa..c1871e07a 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -75,6 +75,7 @@ prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" cat << EOF multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} EOF +save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" cat << EOF module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\ diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index c6712e32f..026f1d7ac 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -39,6 +39,7 @@ kfreebsd_entry () args="$4" # not used yet title="$(gettext "%s, with kFreeBSD %s")" printf "menuentry \"${title}\" {" ${os} ${version} + save_default_entry | sed -e "s/^/\t/" if [ -z "${prepare_boot_cache}" ]; then prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" fi diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 8803055cf..dc9696ec8 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -59,6 +59,7 @@ linux_entry () title="$(gettext "%s, with Linux %s")" fi printf "menuentry \"${title}\" {" ${os} ${version} + save_default_entry | sed -e "s/^/\t/" if [ -z "${prepare_boot_cache}" ]; then prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" fi diff --git a/util/grub.d/10_windows.in b/util/grub.d/10_windows.in index 055258e29..35dd4a4cc 100644 --- a/util/grub.d/10_windows.in +++ b/util/grub.d/10_windows.in @@ -73,6 +73,7 @@ for dir in $dirlist ; do menuentry "$OS" { EOF + save_default_entry | sed -e 's,^,\t,' prepare_grub_to_access_device "$dev" | sed 's,^,\t,' cat << EOF diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in index c5728866c..103785ed9 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -55,6 +55,7 @@ for OS in ${OSPROBED} ; do cat << EOF menuentry "${LONGNAME} (on ${DEVICE})" { EOF + save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" case ${LONGNAME} in @@ -113,6 +114,8 @@ EOF cat << EOF menuentry "${LONGNAME} (on ${DEVICE})" { EOF + save_default_entry | sed -e "s/^/\t/" + save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" cat << EOF insmod vbe diff --git a/util/i386/efi/grub-install.in b/util/i386/efi/grub-install.in index a5f97e346..e597c4eee 100644 --- a/util/i386/efi/grub-install.in +++ b/util/i386/efi/grub-install.in @@ -34,6 +34,7 @@ pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${t grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` rootdir= grub_prefix=`echo /boot/grub | sed ${transform}` modules= @@ -178,6 +179,10 @@ for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do cp -f $file ${grubdir} || exit 1 done +if ! test -f ${grubdir}/grubenv; then + $grub_editenv ${grubdir}/grubenv create +fi + # Create the core image. First, auto-detect the filesystem module. fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}` if test "x$fs_module" = xfat; then :; else diff --git a/util/ieee1275/grub-install.in b/util/ieee1275/grub-install.in index 710ed125b..9a26b0dca 100644 --- a/util/ieee1275/grub-install.in +++ b/util/ieee1275/grub-install.in @@ -37,6 +37,7 @@ pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${t grub_mkimage=${bindir}/`echo grub-mkelfimage | sed ${transform}` grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` rootdir= grub_prefix=`echo /boot/grub | sed ${transform}` modules= @@ -163,6 +164,10 @@ for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst ; do cp -f $file ${grubdir} || exit 1 done +if ! test -f ${grubdir}/grubenv; then + $grub_editenv ${grubdir}/grubenv create +fi + # Create the core image. First, auto-detect the filesystem module. fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}` if test "x$fs_module" = x -a "x$modules" = x; then diff --git a/util/sparc64/ieee1275/grub-install.in b/util/sparc64/ieee1275/grub-install.in index a03869cb3..f49157acd 100644 --- a/util/sparc64/ieee1275/grub-install.in +++ b/util/sparc64/ieee1275/grub-install.in @@ -38,6 +38,7 @@ grub_setup=${sbindir}/`echo grub-setup | sed ${transform}` grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` rootdir= grub_prefix=`echo /boot/grub | sed ${transform}` modules= @@ -206,6 +207,10 @@ for file in ${pkglibdir}/*.img; do cp -f $file ${grubdir} || exit 1 done +if ! test -f ${grubdir}/grubenv; then + $grub_editenv ${grubdir}/grubenv create +fi + # Write device to a variable so we don't have to traverse /dev every time. grub_device=`$grub_probe --target=device ${grubdir}` From 6e3ac954910d28d291b94c0fafb78337ba680bd1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 13:23:43 +0100 Subject: [PATCH 03/63] Fixed warning --- video/video.c | 1 - 1 file changed, 1 deletion(-) diff --git a/video/video.c b/video/video.c index eff257122..2e17ee7dc 100644 --- a/video/video.c +++ b/video/video.c @@ -624,7 +624,6 @@ grub_video_set_mode (const char *modestring, /* Loop thru all possible video adapter trying to find requested mode. */ for (p = grub_video_adapter_list; p; p = p->next) { - grub_err_t err; struct grub_video_mode_info mode_info; grub_memset (&mode_info, 0, sizeof (mode_info)); From d3d0094e17c628523fa51e7a4dcaa3fb0b596298 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 13:29:17 +0100 Subject: [PATCH 04/63] ChangeLog --- ChangeLog.videomask | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 ChangeLog.videomask diff --git a/ChangeLog.videomask b/ChangeLog.videomask new file mode 100644 index 000000000..7c58d0b57 --- /dev/null +++ b/ChangeLog.videomask @@ -0,0 +1,10 @@ +2009-11-20 Vladimir Serbinenko + + Use flag-based instead of hook-based video mode selection and "auto" + keyword. + + * include/grub/video.h (grub_video_adapter): Changed 'setup' member. + (grub_video_set_mode): Changed prototype. All users updated. + (grub_video_check_mode_flag): New inline function. + * video/video.c (parse_modespec): New function. + (grub_video_set_mode): Parse flags and keywords. From b824145a8f2f6435a62b6d127536078f6d3e136c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Dec 2009 00:56:39 +0000 Subject: [PATCH 05/63] 2009-12-08 Colin Watson * util/grub.d/30_os-prober.in: Fix merge error that moved a `save_default_entry' call from the macosx case to the linux case. --- ChangeLog.savedefault | 5 +++++ util/grub.d/30_os-prober.in | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index c18106bd5..0810274a3 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,8 @@ +2009-12-08 Colin Watson + + * util/grub.d/30_os-prober.in: Fix merge error that moved a + `save_default_entry' call from the macosx case to the linux case. + 2009-10-25 Vladimir Serbinenko 2009-10-25 Colin Watson diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in index 0e71096d1..f4a37d5f5 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -97,6 +97,7 @@ EOF cat << EOF menuentry "${LLABEL} (on ${DEVICE})" { EOF + save_default_entry | sed -e "s/^/\t/" if [ -z "${prepare_boot_cache}" ]; then prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")" fi @@ -119,7 +120,6 @@ EOF cat << EOF menuentry "${LONGNAME} (on ${DEVICE})" { EOF - save_default_entry | sed -e "s/^/\t/" save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" cat << EOF From 36cd6dd151db7b033fb3d0fd055f8c7d83feb928 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Dec 2009 00:57:46 +0000 Subject: [PATCH 06/63] 2009-12-08 Colin Watson * util/grub.d/00_header.in: Quote the value assigned to `default', in case it contains spaces. --- ChangeLog.savedefault | 5 +++++ util/grub.d/00_header.in | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 0810274a3..6f885a73f 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,8 @@ +2009-12-08 Colin Watson + + * util/grub.d/00_header.in: Quote the value assigned to `default', + in case it contains spaces. + 2009-12-08 Colin Watson * util/grub.d/30_os-prober.in: Fix merge error that moved a diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 577a12722..e8c3a14c4 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -40,7 +40,7 @@ if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi cat << EOF load_env -set default=${GRUB_DEFAULT} +set default="${GRUB_DEFAULT}" if [ \${prev_saved_entry} ]; then saved_entry=\${prev_saved_entry} save_env saved_entry From 42356b4d5e1ee06d9189b4b4001215585c62dc8a Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Dec 2009 00:59:26 +0000 Subject: [PATCH 07/63] 2009-12-08 Colin Watson * util/grub.d/00_header.in: Silently ignore zero-sized environment blocks. --- ChangeLog.savedefault | 5 +++++ util/grub.d/00_header.in | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 6f885a73f..cdeb05a87 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,8 @@ +2009-12-08 Colin Watson + + * util/grub.d/00_header.in: Silently ignore zero-sized environment + blocks. + 2009-12-08 Colin Watson * util/grub.d/00_header.in: Quote the value assigned to `default', diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index e8c3a14c4..2bcfe1d25 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -39,7 +39,9 @@ if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi cat << EOF -load_env +if [ -s \$prefix/grubenv ]; then + load_env +fi set default="${GRUB_DEFAULT}" if [ \${prev_saved_entry} ]; then saved_entry=\${prev_saved_entry} From 47075ea3c749f0d4ed082f7748387abc7f8a0717 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Dec 2009 01:00:26 +0000 Subject: [PATCH 08/63] 2009-12-08 Colin Watson * util/grub-reboot.in: Fix --version output. * util/grub-set-default.in: Likewise. --- ChangeLog.savedefault | 5 +++++ util/grub-reboot.in | 2 +- util/grub-set-default.in | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index cdeb05a87..55500a67c 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,8 @@ +2009-12-08 Colin Watson + + * util/grub-reboot.in: Fix --version output. + * util/grub-set-default.in: Likewise. + 2009-12-08 Colin Watson * util/grub.d/00_header.in: Silently ignore zero-sized environment diff --git a/util/grub-reboot.in b/util/grub-reboot.in index 886d61770..16abdf6f4 100644 --- a/util/grub-reboot.in +++ b/util/grub-reboot.in @@ -51,7 +51,7 @@ for option in "$@"; do usage exit 0 ;; -v | --version) - echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" + echo "grub-reboot (GNU GRUB ${PACKAGE_VERSION})" exit 0 ;; --root-directory=*) rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; diff --git a/util/grub-set-default.in b/util/grub-set-default.in index 6663d3fbd..4d7c10e8e 100644 --- a/util/grub-set-default.in +++ b/util/grub-set-default.in @@ -51,7 +51,7 @@ for option in "$@"; do usage exit 0 ;; -v | --version) - echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" + echo "grub-set-default (GNU GRUB ${PACKAGE_VERSION})" exit 0 ;; --root-directory=*) rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; From b967a04d5b398fcbe5e3a157432f8559ca41b087 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Dec 2009 01:01:21 +0000 Subject: [PATCH 09/63] 2009-12-08 Colin Watson * util/grub.d/00_header.in: Use `set var=val' rather than plain `var=val'. * util/grub-mkconfig_lib.in (save_default_entry): Likewise. --- ChangeLog.savedefault | 6 ++++++ util/grub-mkconfig_lib.in | 2 +- util/grub.d/00_header.in | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 55500a67c..25811c79b 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,9 @@ +2009-12-08 Colin Watson + + * util/grub.d/00_header.in: Use `set var=val' rather than plain + `var=val'. + * util/grub-mkconfig_lib.in (save_default_entry): Likewise. + 2009-12-08 Colin Watson * util/grub-reboot.in: Fix --version output. diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index d18002ce4..95fd02ad9 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -93,7 +93,7 @@ convert_system_path_to_grub_path () save_default_entry () { if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then - echo 'saved_entry=${chosen}' + echo 'set saved_entry=${chosen}' echo 'save_env saved_entry' fi } diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 2bcfe1d25..4cd8fd30c 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -44,9 +44,9 @@ if [ -s \$prefix/grubenv ]; then fi set default="${GRUB_DEFAULT}" if [ \${prev_saved_entry} ]; then - saved_entry=\${prev_saved_entry} + set saved_entry=\${prev_saved_entry} save_env saved_entry - prev_saved_entry= + set prev_saved_entry= save_env prev_saved_entry fi EOF From 6c1f8c1215b57cf404d103003d0becc74dbeed10 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Dec 2009 01:02:08 +0000 Subject: [PATCH 10/63] 2009-12-08 Colin Watson * util/grub.d/30_os-prober.in: Call save_default_entry for hurd. --- ChangeLog.savedefault | 4 ++++ util/grub.d/30_os-prober.in | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 25811c79b..7457c3f71 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,7 @@ +2009-12-08 Colin Watson + + * util/grub.d/30_os-prober.in: Call save_default_entry for hurd. + 2009-12-08 Colin Watson * util/grub.d/00_header.in: Use `set var=val' rather than plain diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in index f4a37d5f5..b91838782 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -170,6 +170,7 @@ EOF cat << EOF menuentry "${LONGNAME} (on ${DEVICE})" { EOF + save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" grub_device="`${grub_probe} --device ${DEVICE} --target=drive`" mach_device="`echo "${grub_device}" | tr -d '()' | tr , s`" From e6d8d32a946e7d8fefda8b3e55a8810b5b1039ae Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 16 Dec 2009 19:03:56 +0100 Subject: [PATCH 11/63] fix efi video drivers for video API change --- video/efi_gop.c | 2 +- video/efi_uga.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/video/efi_gop.c b/video/efi_gop.c index e2eb2f7ae..3143135d6 100644 --- a/video/efi_gop.c +++ b/video/efi_gop.c @@ -185,7 +185,7 @@ grub_video_gop_fill_mode_info (struct grub_efi_gop_mode_info *in, static grub_err_t grub_video_gop_setup (unsigned int width, unsigned int height, - unsigned int mode_type) + unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused))) { unsigned int depth; struct grub_efi_gop_mode_info *info = NULL; diff --git a/video/efi_uga.c b/video/efi_uga.c index 9bca64306..1fe0aa500 100644 --- a/video/efi_uga.c +++ b/video/efi_uga.c @@ -198,7 +198,7 @@ grub_video_uga_fini (void) static grub_err_t grub_video_uga_setup (unsigned int width, unsigned int height, - unsigned int mode_type) + unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused))) { unsigned int depth; int found = 0; From b445cfaa4dadc0ce15d9dddd9764e8db295feffb Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 5 Jan 2010 10:30:14 +0000 Subject: [PATCH 12/63] 2010-10-05 Jordan Uggla 2010-10-05 Colin Watson * util/grub-mkconfig_lib.in (save_default_entry): Only set saved_entry if boot_once is unset. * util/grub.d/00_header.in: Set boot_once to "true" if there was a previous saved entry (i.e. grub-reboot). --- ChangeLog.savedefault | 8 ++++++++ util/grub-mkconfig_lib.in | 8 ++++++-- util/grub.d/00_header.in | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 7457c3f71..f07bd6beb 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,11 @@ +2010-10-05 Jordan Uggla +2010-10-05 Colin Watson + + * util/grub-mkconfig_lib.in (save_default_entry): Only set + saved_entry if boot_once is unset. + * util/grub.d/00_header.in: Set boot_once to "true" if there was a + previous saved entry (i.e. grub-reboot). + 2009-12-08 Colin Watson * util/grub.d/30_os-prober.in: Call save_default_entry for hurd. diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 95fd02ad9..acfc9f6ea 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -93,8 +93,12 @@ convert_system_path_to_grub_path () save_default_entry () { if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then - echo 'set saved_entry=${chosen}' - echo 'save_env saved_entry' + cat << EOF +if [ -z \${boot_once} ]; then + set saved_entry=${chosen} + save_env saved_entry +fi +EOF fi } diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 4cd8fd30c..85ce0d4a0 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -48,6 +48,7 @@ if [ \${prev_saved_entry} ]; then save_env saved_entry set prev_saved_entry= save_env prev_saved_entry + set boot_once=true fi EOF From fcab4f04e5e32cd2d3247e25d2c629085fcb23bf Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 5 Jan 2010 10:39:30 +0000 Subject: [PATCH 13/63] missing backslash --- util/grub-mkconfig_lib.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index acfc9f6ea..72e0e38f9 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -95,7 +95,7 @@ save_default_entry () if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then cat << EOF if [ -z \${boot_once} ]; then - set saved_entry=${chosen} + set saved_entry=\${chosen} save_env saved_entry fi EOF From 5c23bb0f529f6b3d1577dbfa405338e3ec81fbf3 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 5 Jan 2010 10:41:51 +0000 Subject: [PATCH 14/63] 2010-10-05 Jordan Uggla 2010-10-05 Colin Watson * util/grub.d/00_header.in: Define a "savedefault" function for use in menu entries. * util/grub-mkconfig_lib.in (save_default_entry): Use it. --- ChangeLog.savedefault | 7 +++++++ util/grub-mkconfig_lib.in | 5 +---- util/grub.d/00_header.in | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index f07bd6beb..90875588e 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,10 @@ +2010-10-05 Jordan Uggla +2010-10-05 Colin Watson + + * util/grub.d/00_header.in: Define a "savedefault" function for use + in menu entries. + * util/grub-mkconfig_lib.in (save_default_entry): Use it. + 2010-10-05 Jordan Uggla 2010-10-05 Colin Watson diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 72e0e38f9..380ba1a48 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -94,10 +94,7 @@ save_default_entry () { if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then cat << EOF -if [ -z \${boot_once} ]; then - set saved_entry=\${chosen} - save_env saved_entry -fi +savedefault EOF fi } diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 85ce0d4a0..cfb8648ca 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -50,6 +50,13 @@ if [ \${prev_saved_entry} ]; then save_env prev_saved_entry set boot_once=true fi + +function savedefault { + if [ -z \${boot_once} ]; then + saved_entry=\${chosen} + save_env saved_entry + fi +} EOF case ${GRUB_TERMINAL_INPUT}:${GRUB_TERMINAL_OUTPUT} in From cf2fd2a6d1a58ad0c47cf8b968ff695d0073b57a Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 5 Jan 2010 11:16:42 +0000 Subject: [PATCH 15/63] 2010-10-05 Jordan Uggla 2010-10-05 Colin Watson * util/grub-reboot.in: Make sure prev_saved_entry always gets a non-empty value. --- ChangeLog.savedefault | 6 ++++++ util/grub-reboot.in | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 90875588e..722769776 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,9 @@ +2010-10-05 Jordan Uggla +2010-10-05 Colin Watson + + * util/grub-reboot.in: Make sure prev_saved_entry always gets a + non-empty value. + 2010-10-05 Jordan Uggla 2010-10-05 Colin Watson diff --git a/util/grub-reboot.in b/util/grub-reboot.in index 16abdf6f4..20f2b10bc 100644 --- a/util/grub-reboot.in +++ b/util/grub-reboot.in @@ -96,7 +96,11 @@ prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry if [ "$prev_saved_entry" ]; then $grub_editenv ${grubdir}/grubenv set prev_saved_entry="$prev_saved_entry" else - $grub_editenv ${grubdir}/grubenv unset prev_saved_entry + # We need some non-empty value for prev_saved_entry so that GRUB will + # recognise that grub-reboot has been used and restore the previous + # saved entry. "0" is the same as an empty value, i.e. the first menu + # entry. + $grub_editenv ${grubdir}/grubenv set prev_saved_entry=0 fi $grub_editenv ${grubdir}/grubenv set saved_entry="$entry" From 6fc804ffbb7d0163a3f6a73dbd2b6f7c5f954fff Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Fri, 8 Jan 2010 15:19:10 +0530 Subject: [PATCH 16/63] unit testing framework --- Makefile.in | 19 +++- conf/tests.rmk | 41 ++++++++ genmk.rb | 6 +- include/grub/test.h | 88 ++++++++++++++++++ tests/example_functional_test.c | 17 ++++ tests/example_grub_script_test.in | 3 + tests/example_scripted_test.in | 3 + tests/example_unit_test.c | 20 ++++ tests/lib/functional_test.c | 75 +++++++++++++++ tests/lib/test.c | 150 ++++++++++++++++++++++++++++++ tests/lib/unit_test.c | 122 ++++++++++++++++++++++++ tests/util/grub-shell-tester.in | 109 ++++++++++++++++++++++ tests/util/grub-shell.in | 125 +++++++++++++++++++++++++ 13 files changed, 774 insertions(+), 4 deletions(-) create mode 100644 conf/tests.rmk create mode 100644 include/grub/test.h create mode 100644 tests/example_functional_test.c create mode 100644 tests/example_grub_script_test.in create mode 100644 tests/example_scripted_test.in create mode 100644 tests/example_unit_test.c create mode 100644 tests/lib/functional_test.c create mode 100644 tests/lib/test.c create mode 100644 tests/lib/unit_test.c create mode 100644 tests/util/grub-shell-tester.in create mode 100644 tests/util/grub-shell.in diff --git a/Makefile.in b/Makefile.in index ffa8716ed..2358060f2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -141,6 +141,7 @@ PROGRAMS = $(bin_UTILITIES) $(sbin_UTILITIES) SCRIPTS = $(bin_SCRIPTS) $(sbin_SCRIPTS) $(grub-mkconfig_SCRIPTS) \ $(lib_SCRIPTS) INFOS = $(info_INFOS) +TESTS = $(check_UNITTESTS) $(check_FUNCTIONALTESTS) $(check_SCRIPTEDTESTS) CLEANFILES = MOSTLYCLEANFILES = @@ -167,6 +168,8 @@ ifeq ($(platform), emu) include $(srcdir)/conf/any-emu.mk else include $(srcdir)/conf/$(target_cpu)-$(platform).mk +# For tests. +include $(srcdir)/conf/tests.mk # For external modules. -include $(wildcard $(GRUB_CONTRIB)/*/conf/common.mk) endif @@ -458,7 +461,21 @@ distcheck: dist @echo "$(distdir).tar.gz is ready for distribution" | \ sed 'h;s/./=/g;p;x;p;x' -check: +$(TESTS): $(check_SCRIPTS) $(check_MODULES) $(check_PROGRAMS) +check: all $(TESTS) + @list="$(check_UNITTESTS) $(check_SCRIPTEDTESTS)"; \ + for file in $$list; do \ + if $(builddir)/$$file; then \ + echo "$$file: PASS"; \ + else \ + echo "$$file: FAIL"; \ + fi; \ + done + @list="$(check_FUNCTIONALTESTS)"; \ + for test in $$list; do \ + echo "insmod functional_test; insmod $test; functional_test" \ + | $(builddir)/grub-shell; \ + done .SUFFIX: .SUFFIX: .c .o .S .d diff --git a/conf/tests.rmk b/conf/tests.rmk new file mode 100644 index 000000000..03d6acbd1 --- /dev/null +++ b/conf/tests.rmk @@ -0,0 +1,41 @@ +# -*- makefile -*- + +# For grub-shell +grub-shell: tests/util/grub-shell.in config.status + ./config.status --file=$@:$< + chmod +x $@ +check_SCRIPTS += grub-shell +CLEANFILES += grub-shell + +# For grub-shell-tester +grub-shell-tester: tests/util/grub-shell-tester.in config.status + ./config.status --file=$@:$< + chmod +x $@ +check_SCRIPTS += grub-shell-tester +CLEANFILES += grub-shell-tester + +check_MODULES += functional_test.mod +functional_test_mod_SOURCES = tests/lib/functional_test.c tests/lib/test.c +functional_test_mod_CFLAGS = $(COMMON_CFLAGS) +functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# Unit tests + +check_UNITTESTS += example_unit_test +example_unit_test_SOURCES = tests/example_unit_test.c kern/list.c kern/misc.c tests/lib/test.c tests/lib/unit_test.c +example_unit_test_CFLAGS = -Wno-format + +# Functional tests + +check_FUNCTIONALTESTS += example_functional_test.mod +example_functional_test_mod_SOURCES = tests/example_functional_test.c +example_functional_test_mod_CFLAGS = -Wno-format $(COMMON_CFLAGS) +example_functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# Scripted tests + +check_SCRIPTEDTESTS += example_scripted_test +example_scripted_test_SOURCES = tests/example_scripted_test.in + +check_SCRIPTEDTESTS += example_grub_script_test +example_grub_script_test_SOURCES = tests/example_grub_script_test.in diff --git a/genmk.rb b/genmk.rb index b1cce3831..006fc3d29 100644 --- a/genmk.rb +++ b/genmk.rb @@ -407,12 +407,12 @@ while l = gets Image.new(prefix, img) end - when 'MODULES' + when 'MODULES', 'FUNCTIONALTESTS' pmodules += args.split(/\s+/).collect do |pmod| PModule.new(prefix, pmod) end - when 'UTILITIES' + when 'UTILITIES', 'UNITTESTS' utils += args.split(/\s+/).collect do |util| Utility.new(prefix, util) end @@ -422,7 +422,7 @@ while l = gets Program.new(prefix, prog) end - when 'SCRIPTS' + when 'SCRIPTS', 'SCRIPTEDTESTS' scripts += args.split(/\s+/).collect do |script| Script.new(prefix, script) end diff --git a/include/grub/test.h b/include/grub/test.h new file mode 100644 index 000000000..fbc2bff8c --- /dev/null +++ b/include/grub/test.h @@ -0,0 +1,88 @@ +#ifndef GRUB_TEST_HEADER +#define GRUB_TEST_HEADER + +#include +#include +#include +#include +#include + +struct grub_test +{ + /* The next test. */ + struct grub_test *next; + + /* The test name. */ + char *name; + + /* The test main function. */ + void (*main) (void); +}; +typedef struct grub_test *grub_test_t; + +extern grub_test_t EXPORT_VAR (grub_test_list); + +void EXPORT_FUNC (grub_test_register) (const char *name, void (*test) (void)); + +void EXPORT_FUNC (grub_test_unregister) (const char *name); + +/* Execute a test and print results. */ +int grub_test_run (const char *name); + +/* Test `cond' for nonzero; log failure otherwise. */ +void grub_test_nonzero (int cond, const char *file, + const char *func, grub_uint32_t line, + const char *fmt, ...) + __attribute__ ((format (printf, 5, 6))); + +#ifdef __STDC_VERSION__ +#if __STDC_VERSION__ < 199901L +# if __GNUC__ >= 2 +# define __func__ __FUNCTION__ +# else +# define __func__ "" +# endif +#endif +#else +#define __func__ "" +#endif + +/* Macro to fill in location details and an optional error message. */ +#define grub_test_assert(cond, ...) \ + grub_test_nonzero(cond, __FILE__, __func__, __LINE__, \ + ## __VA_ARGS__, \ + "assert failed: %s", #cond) + +/* Macro to define a unit test. */ +#define GRUB_UNIT_TEST(name, funp) \ + void grub_unit_test_init (void) \ + { \ + grub_test_register (name, funp); \ + } \ + \ + void grub_unit_test_fini (void) \ + { \ + grub_test_unregister (name); \ + } + +/* Macro to define a functional test. */ +#define GRUB_FUNCTIONAL_TEST(name, funp) \ + GRUB_MOD_INIT(functional_test_##funp) \ + { \ + grub_test_register (name, funp); \ + } \ + \ + GRUB_MOD_FINI(functional_test_##funp) \ + { \ + grub_test_unregister (name); \ + } + +/* Functions that are defined differently for unit and functional tests. */ +void *grub_test_malloc (grub_size_t size); +void grub_test_free (void *ptr); +char *grub_test_strdup (const char *str); +int grub_test_vsprintf (char *str, const char *fmt, va_list args); +int grub_test_printf (const char *fmt, ...) + __attribute__ ((format (printf, 1, 2))); + +#endif /* ! GRUB_TEST_HEADER */ diff --git a/tests/example_functional_test.c b/tests/example_functional_test.c new file mode 100644 index 000000000..475d1c7f0 --- /dev/null +++ b/tests/example_functional_test.c @@ -0,0 +1,17 @@ +/* All tests need to include test.h for GRUB testing framework. */ +#include + +/* Functional test main method. */ +static void +example_test (void) +{ + /* Check if 1st argument is true and report with default error message. */ + grub_test_assert (1 == 1); + + /* Check if 1st argument is true and report with custom error message. */ + grub_test_assert (2 == 2, "2 equal 2 expected"); + grub_test_assert (2 == 3, "2 is not equal to %d", 3); +} + +/* Register example_test method as a functional test. */ +GRUB_FUNCTIONAL_TEST ("example_functional_test", example_test); diff --git a/tests/example_grub_script_test.in b/tests/example_grub_script_test.in new file mode 100644 index 000000000..93a90a18e --- /dev/null +++ b/tests/example_grub_script_test.in @@ -0,0 +1,3 @@ +#! @builddir@/grub-shell-tester --modules=echo + +echo "hello world" diff --git a/tests/example_scripted_test.in b/tests/example_scripted_test.in new file mode 100644 index 000000000..9ac0424c0 --- /dev/null +++ b/tests/example_scripted_test.in @@ -0,0 +1,3 @@ +#!/bin/sh -e + +true diff --git a/tests/example_unit_test.c b/tests/example_unit_test.c new file mode 100644 index 000000000..e2fad06ff --- /dev/null +++ b/tests/example_unit_test.c @@ -0,0 +1,20 @@ +/* Unit tests are normal programs, so they can include C library. */ +#include + +/* All tests need to include test.h for GRUB testing framework. */ +#include + +/* Unit test main method. */ +static void +example_test (void) +{ + /* Check if 1st argument is true and report with default error message. */ + grub_test_assert (1 == 1); + + /* Check if 1st argument is true and report with custom error message. */ + grub_test_assert (2 == 2, "2 equal 2 expected"); + grub_test_assert (2 == 3, "2 is not equal to %d", 3); +} + +/* Register example_test method as a unit test. */ +GRUB_UNIT_TEST ("example_unit_test", example_test); diff --git a/tests/lib/functional_test.c b/tests/lib/functional_test.c new file mode 100644 index 000000000..24e82932e --- /dev/null +++ b/tests/lib/functional_test.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include + +void * +grub_test_malloc (grub_size_t size) +{ + return grub_malloc (size); +} + +void +grub_test_free (void *ptr) +{ + grub_free (ptr); +} + +int +grub_test_vsprintf (char *str, const char *fmt, va_list args) +{ + return grub_vsprintf (str, fmt, args); +} + +char * +grub_test_strdup (const char *str) +{ + return grub_strdup (str); +} + +int +grub_test_printf (const char *fmt, ...) +{ + int r; + va_list ap; + + va_start (ap, fmt); + r = grub_vprintf (fmt, ap); + va_end (ap); + + return r; +} + +static grub_err_t +grub_functional_test (struct grub_extcmd *cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) +{ + int i; + int status; + grub_test_t test; + + status = 0; + for (i = 0; i < argc; i++) + { + test = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_test_list), + args[i]); + status = grub_test_run (test->name) ? : status; + } + + return status; +} + +static grub_extcmd_t cmd; + +GRUB_MOD_INIT (functional_test) +{ + cmd = grub_register_extcmd ("functional_test", grub_functional_test, + GRUB_COMMAND_FLAG_CMDLINE, 0, + "Run all functional tests.", 0); +} + +GRUB_MOD_FINI (functional_test) +{ + grub_unregister_extcmd (cmd); +} diff --git a/tests/lib/test.c b/tests/lib/test.c new file mode 100644 index 000000000..37f8fff72 --- /dev/null +++ b/tests/lib/test.c @@ -0,0 +1,150 @@ +#include +#include + +struct grub_test_failure +{ + /* The next failure. */ + struct grub_test_failure *next; + + /* The test source file name. */ + char *file; + + /* The test function name. */ + char *funp; + + /* The test call line number. */ + grub_uint32_t line; + + /* The test failure message. */ + char *message; +}; +typedef struct grub_test_failure *grub_test_failure_t; + +grub_test_t grub_test_list; +static grub_test_failure_t failure_list; + +static void +add_failure (const char *file, + const char *funp, + grub_uint32_t line, const char *fmt, va_list args) +{ + char buf[1024]; + grub_test_failure_t failure; + + failure = (grub_test_failure_t) grub_test_malloc (sizeof (*failure)); + if (!failure) + return; + + grub_test_vsprintf (buf, fmt, args); + + failure->file = grub_test_strdup (file ? : ""); + failure->funp = grub_test_strdup (funp ? : ""); + failure->line = line; + failure->message = grub_test_strdup (buf); + + grub_list_push (GRUB_AS_LIST_P (&failure_list), GRUB_AS_LIST (failure)); +} + +static void +free_failures (void) +{ + grub_test_failure_t item; + + while ((item = grub_list_pop (GRUB_AS_LIST_P (&failure_list))) != 0) + { + if (item->message) + grub_test_free (item->message); + + if (item->funp) + grub_test_free (item->funp); + + if (item->file) + grub_test_free (item->file); + + grub_test_free (item); + } + failure_list = 0; +} + +void +grub_test_nonzero (int cond, + const char *file, + const char *funp, grub_uint32_t line, const char *fmt, ...) +{ + va_list ap; + + if (cond) + return; + + va_start (ap, fmt); + add_failure (file, funp, line, fmt, ap); + va_end (ap); +} + +void +grub_test_register (const char *name, void (*test_main) (void)) +{ + grub_test_t test; + + test = (grub_test_t) grub_test_malloc (sizeof (*test)); + if (!test) + return; + + test->name = grub_test_strdup (name); + test->main = test_main; + + grub_list_push (GRUB_AS_LIST_P (&grub_test_list), GRUB_AS_LIST (test)); +} + +void +grub_test_unregister (const char *name) +{ + grub_test_t test; + + test = (grub_test_t) grub_named_list_find + (GRUB_AS_NAMED_LIST (grub_test_list), name); + + if (test) + { + grub_list_remove (GRUB_AS_LIST_P (&grub_test_list), + GRUB_AS_LIST (test)); + + if (test->name) + grub_test_free (test->name); + + grub_test_free (test); + } +} + +int +grub_test_run (const char *name) +{ + grub_test_t test; + + auto int print_failure (grub_test_failure_t item); + int print_failure (grub_test_failure_t item) + { + grub_test_failure_t failure = (grub_test_failure_t) item; + + grub_test_printf (" %s:%s:%u: %s\n", + (failure->file ? : ""), + (failure->funp ? : ""), + failure->line, (failure->message ? : "")); + return 0; + } + + test = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_test_list), name); + if (!test) + return GRUB_ERR_FILE_NOT_FOUND; + + test->main (); + + if (!failure_list) + return GRUB_ERR_NONE; + + grub_test_printf ("%s:\n", test->name); + grub_list_iterate (GRUB_AS_LIST (failure_list), + (grub_list_hook_t) print_failure); + free_failures (); + return GRUB_ERR_TEST_FAILURE; +} diff --git a/tests/lib/unit_test.c b/tests/lib/unit_test.c new file mode 100644 index 000000000..15bb0da5d --- /dev/null +++ b/tests/lib/unit_test.c @@ -0,0 +1,122 @@ +#include +#include +#include +#include + +#include +#include +#include + +void * +grub_test_malloc (grub_size_t size) +{ + return malloc (size); +} + +void +grub_test_free (void *ptr) +{ + free (ptr); +} + +int +grub_test_vsprintf (char *str, const char *fmt, va_list args) +{ + return vsprintf (str, fmt, args); +} + +char * +grub_test_strdup (const char *str) +{ + return strdup (str); +} + +int +grub_test_printf (const char *fmt, ...) +{ + int r; + va_list ap; + + va_start (ap, fmt); + r = vprintf (fmt, ap); + va_end (ap); + + return r; +} + +int +main (int argc __attribute__ ((unused)), + char *argv[] __attribute__ ((unused))) +{ + int status = 0; + + extern void grub_unit_test_init (void); + extern void grub_unit_test_fini (void); + + auto int run_test (grub_test_t test); + int run_test (grub_test_t test) + { + status = grub_test_run (test->name) ? : status; + return 0; + } + + grub_unit_test_init (); + grub_list_iterate (GRUB_AS_LIST (grub_test_list), + (grub_list_hook_t) run_test); + grub_unit_test_fini (); + + exit (status); +} + +/* Other misc. functions necessary for successful linking. */ + +char * +grub_env_get (const char *name __attribute__ ((unused))) +{ + return NULL; +} + +grub_err_t +grub_error (grub_err_t n, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + vfprintf (stderr, fmt, ap); + va_end (ap); + + return n; +} + +void * +grub_malloc (grub_size_t size) +{ + return malloc (size); +} + +void +grub_refresh (void) +{ + fflush (stdout); +} + +void +grub_putchar (int c) +{ + putchar (c); +} + +int +grub_getkey (void) +{ + return -1; +} + +void +grub_exit (void) +{ + exit (1); +} + +struct grub_handler_class grub_term_input_class; +struct grub_handler_class grub_term_output_class; diff --git a/tests/util/grub-shell-tester.in b/tests/util/grub-shell-tester.in new file mode 100644 index 000000000..18f5e79b7 --- /dev/null +++ b/tests/util/grub-shell-tester.in @@ -0,0 +1,109 @@ +#! /bin/bash -e + +# Compares GRUB script output with BASH output. +# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see . + +# Initialize some variables. +transform="@program_transform_name@" + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ +libdir=@libdir@ +builddir=@builddir@ +PACKAGE_NAME=@PACKAGE_NAME@ +PACKAGE_TARNAME=@PACKAGE_TARNAME@ +PACKAGE_VERSION=@PACKAGE_VERSION@ +target_cpu=@target_cpu@ + +# Force build directory components +PATH=${builddir}:$PATH +export PATH + +# Usage: usage +# Print the usage. +usage () { + cat <. +EOF +} + +# Check the arguments. +for option in "$@"; do + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "$0 (GNU GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --modules=*) + ms=`echo "$option" | sed -e 's/--modules=//'` + modules="$modules,$ms" ;; + --qemu-opts=*) + qs=`echo "$option" | sed -e 's/--qemu-opts=//'` + qemuopts="$qemuopts $qs" ;; + -*) + echo "Unrecognized option \`$option'" 1>&2 + usage + exit 1 + ;; + *) + if [ "x${source}" != x ] ; then + echo "too many parameters at the end" 1>&2 + usage + exit 1 + fi + source="${option}" ;; + esac +done + +if [ "x${source}" = x ] ; then + tmpfile=`mktemp` + while read; do + echo $REPLY >> ${tmpfile} + done + source=${tmpfile} +fi + +outfile1=`mktemp` +@builddir@/grub-shell --qemu-opts="${qemuopts}" --modules=${modules} ${source} >${outfile1} + +outfile2=`mktemp` +bash ${source} >${outfile2} + +if ! diff -q ${outfile1} ${outfile2} >/dev/null +then + echo "$1: GRUB and BASH outputs (${outfile1}, ${outfile2}) did not match" + status=1 +else + rm -f ${outfile1} ${outfile2} +fi + +exit $status + + diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in new file mode 100644 index 000000000..c1b2ef258 --- /dev/null +++ b/tests/util/grub-shell.in @@ -0,0 +1,125 @@ +#! /bin/bash -e + +# Run GRUB script in a Qemu instance +# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see . + +# Initialize some variables. +transform="@program_transform_name@" + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ +libdir=@libdir@ +builddir=@builddir@ +PACKAGE_NAME=@PACKAGE_NAME@ +PACKAGE_TARNAME=@PACKAGE_TARNAME@ +PACKAGE_VERSION=@PACKAGE_VERSION@ +target_cpu=@target_cpu@ + +# Force build directory components +PATH=${builddir}:$PATH +export PATH + +# Usage: usage +# Print the usage. +usage () { + cat <. +EOF +} + +# Check the arguments. +for option in "$@"; do + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "$0 (GNU GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --modules=*) + ms=`echo "$option" | sed -e 's/--modules=//' -e 's/,/ /g'` + modules="$modules $ms" ;; + --qemu-opts=*) + qs=`echo "$option" | sed -e 's/--qemu-opts=//'` + qemuopts="$qemuopts $qs" ;; + -*) + echo "Unrecognized option \`$option'" 1>&2 + usage + exit 1 + ;; + *) + if [ "x${source}" != x ] ; then + echo "too many parameters at the end" 1>&2 + usage + exit 1 + fi + source="${option}" ;; + esac +done + +if [ "x${source}" = x ] ; then + tmpfile=`mktemp` + while read; do + echo $REPLY >> ${tmpfile} + done + source=${tmpfile} +fi + +cfgfile=`mktemp` +cat <${cfgfile} +grubshell=yes +insmod serial +serial +terminal_input serial +terminal_output serial +EOF + +for mod in ${modules} +do + echo "insmod ${mod}" >> ${cfgfile} +done + +cat <>${cfgfile} +source /boot/grub/testcase.cfg +halt +EOF + +isofile=`mktemp` +grub-mkrescue --output=${isofile} --override-directory=${builddir} \ + /boot/grub/grub.cfg=${cfgfile} /boot/grub/testcase.cfg=${source} \ + >/dev/null 2>&1 + +outfile=`mktemp` +qemu ${qemuopts} -nographic -serial stdio -cdrom ${isofile} -boot d | tr -d "\r" >${outfile} + +cat $outfile + +rm -f ${tmpfile} ${outfile} ${cfgfile} ${isofile} +exit 0 + + From 169b1cd2d87102670dfdb1717aef8723143d8c4b Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Fri, 8 Jan 2010 16:35:32 +0530 Subject: [PATCH 17/63] added functional tests to make-check --- Makefile.in | 19 +++++++++++++------ conf/tests.rmk | 14 +++++++------- genmk.rb | 6 +++--- include/grub/test.h | 2 +- tests/lib/functional_test.c | 21 +++++++++------------ tests/lib/test.c | 18 +++++++----------- tests/lib/unit_test.c | 2 +- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Makefile.in b/Makefile.in index 2358060f2..567571897 100644 --- a/Makefile.in +++ b/Makefile.in @@ -141,7 +141,6 @@ PROGRAMS = $(bin_UTILITIES) $(sbin_UTILITIES) SCRIPTS = $(bin_SCRIPTS) $(sbin_SCRIPTS) $(grub-mkconfig_SCRIPTS) \ $(lib_SCRIPTS) INFOS = $(info_INFOS) -TESTS = $(check_UNITTESTS) $(check_FUNCTIONALTESTS) $(check_SCRIPTEDTESTS) CLEANFILES = MOSTLYCLEANFILES = @@ -461,19 +460,27 @@ distcheck: dist @echo "$(distdir).tar.gz is ready for distribution" | \ sed 'h;s/./=/g;p;x;p;x' -$(TESTS): $(check_SCRIPTS) $(check_MODULES) $(check_PROGRAMS) +TESTS = $(check_UTILITIES) $(check_SCRIPTS) $(check_MODULES) +$(TESTS): $(test_framework_SCRIPTS) $(test_framework_MODULES) + check: all $(TESTS) - @list="$(check_UNITTESTS) $(check_SCRIPTEDTESTS)"; \ + @list="$(check_UTILITIES)"; \ for file in $$list; do \ + $(builddir)/$$file; \ + done + @list="$(check_SCRIPTS)"; \ + for file in $$list; do \ + echo "$$file:"; \ if $(builddir)/$$file; then \ echo "$$file: PASS"; \ else \ echo "$$file: FAIL"; \ fi; \ done - @list="$(check_FUNCTIONALTESTS)"; \ - for test in $$list; do \ - echo "insmod functional_test; insmod $test; functional_test" \ + @list="$(check_MODULES)"; \ + for file in $$list; do \ + mod=`basename $$file .mod`; \ + echo "insmod functional_test; insmod $$mod; functional_test" \ | $(builddir)/grub-shell; \ done diff --git a/conf/tests.rmk b/conf/tests.rmk index 03d6acbd1..c35ea0baa 100644 --- a/conf/tests.rmk +++ b/conf/tests.rmk @@ -4,38 +4,38 @@ grub-shell: tests/util/grub-shell.in config.status ./config.status --file=$@:$< chmod +x $@ -check_SCRIPTS += grub-shell +test_framework_SCRIPTS += grub-shell CLEANFILES += grub-shell # For grub-shell-tester grub-shell-tester: tests/util/grub-shell-tester.in config.status ./config.status --file=$@:$< chmod +x $@ -check_SCRIPTS += grub-shell-tester +test_framework_SCRIPTS += grub-shell-tester CLEANFILES += grub-shell-tester -check_MODULES += functional_test.mod +test_framework_MODULES += functional_test.mod functional_test_mod_SOURCES = tests/lib/functional_test.c tests/lib/test.c functional_test_mod_CFLAGS = $(COMMON_CFLAGS) functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) # Unit tests -check_UNITTESTS += example_unit_test +check_UTILITIES += example_unit_test example_unit_test_SOURCES = tests/example_unit_test.c kern/list.c kern/misc.c tests/lib/test.c tests/lib/unit_test.c example_unit_test_CFLAGS = -Wno-format # Functional tests -check_FUNCTIONALTESTS += example_functional_test.mod +check_MODULES += example_functional_test.mod example_functional_test_mod_SOURCES = tests/example_functional_test.c example_functional_test_mod_CFLAGS = -Wno-format $(COMMON_CFLAGS) example_functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) # Scripted tests -check_SCRIPTEDTESTS += example_scripted_test +check_SCRIPTS += example_scripted_test example_scripted_test_SOURCES = tests/example_scripted_test.in -check_SCRIPTEDTESTS += example_grub_script_test +check_SCRIPTS += example_grub_script_test example_grub_script_test_SOURCES = tests/example_grub_script_test.in diff --git a/genmk.rb b/genmk.rb index 006fc3d29..b1cce3831 100644 --- a/genmk.rb +++ b/genmk.rb @@ -407,12 +407,12 @@ while l = gets Image.new(prefix, img) end - when 'MODULES', 'FUNCTIONALTESTS' + when 'MODULES' pmodules += args.split(/\s+/).collect do |pmod| PModule.new(prefix, pmod) end - when 'UTILITIES', 'UNITTESTS' + when 'UTILITIES' utils += args.split(/\s+/).collect do |util| Utility.new(prefix, util) end @@ -422,7 +422,7 @@ while l = gets Program.new(prefix, prog) end - when 'SCRIPTS', 'SCRIPTEDTESTS' + when 'SCRIPTS' scripts += args.split(/\s+/).collect do |script| Script.new(prefix, script) end diff --git a/include/grub/test.h b/include/grub/test.h index fbc2bff8c..4b028371b 100644 --- a/include/grub/test.h +++ b/include/grub/test.h @@ -27,7 +27,7 @@ void EXPORT_FUNC (grub_test_register) (const char *name, void (*test) (void)); void EXPORT_FUNC (grub_test_unregister) (const char *name); /* Execute a test and print results. */ -int grub_test_run (const char *name); +int grub_test_run (grub_test_t test); /* Test `cond' for nonzero; log failure otherwise. */ void grub_test_nonzero (int cond, const char *file, diff --git a/tests/lib/functional_test.c b/tests/lib/functional_test.c index 24e82932e..2e03dabc4 100644 --- a/tests/lib/functional_test.c +++ b/tests/lib/functional_test.c @@ -45,19 +45,16 @@ grub_functional_test (struct grub_extcmd *cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), char **args __attribute__ ((unused))) { - int i; - int status; - grub_test_t test; + auto int run_test (grub_test_t test); + int run_test (grub_test_t test) + { + grub_test_run (test); + return 0; + } - status = 0; - for (i = 0; i < argc; i++) - { - test = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_test_list), - args[i]); - status = grub_test_run (test->name) ? : status; - } - - return status; + grub_list_iterate (GRUB_AS_LIST (grub_test_list), + (grub_list_hook_t) run_test); + return GRUB_ERR_NONE; } static grub_extcmd_t cmd; diff --git a/tests/lib/test.c b/tests/lib/test.c index 37f8fff72..562c2f6e4 100644 --- a/tests/lib/test.c +++ b/tests/lib/test.c @@ -117,10 +117,8 @@ grub_test_unregister (const char *name) } int -grub_test_run (const char *name) +grub_test_run (grub_test_t test) { - grub_test_t test; - auto int print_failure (grub_test_failure_t item); int print_failure (grub_test_failure_t item) { @@ -133,18 +131,16 @@ grub_test_run (const char *name) return 0; } - test = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_test_list), name); - if (!test) - return GRUB_ERR_FILE_NOT_FOUND; - test->main (); - if (!failure_list) - return GRUB_ERR_NONE; - grub_test_printf ("%s:\n", test->name); grub_list_iterate (GRUB_AS_LIST (failure_list), (grub_list_hook_t) print_failure); + if (!failure_list) + grub_test_printf ("%s: PASS\n", test->name); + else + grub_test_printf ("%s: FAIL\n", test->name); + free_failures (); - return GRUB_ERR_TEST_FAILURE; + return GRUB_ERR_NONE; } diff --git a/tests/lib/unit_test.c b/tests/lib/unit_test.c index 15bb0da5d..59931898a 100644 --- a/tests/lib/unit_test.c +++ b/tests/lib/unit_test.c @@ -56,7 +56,7 @@ main (int argc __attribute__ ((unused)), auto int run_test (grub_test_t test); int run_test (grub_test_t test) { - status = grub_test_run (test->name) ? : status; + status = grub_test_run (test) ? : status; return 0; } From 1afc27d06b9030b83f3398edd13344d8fbe81c24 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Fri, 8 Jan 2010 21:28:57 +0530 Subject: [PATCH 18/63] added changelog file --- ChangeLog.unit-testing-framework | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ChangeLog.unit-testing-framework diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework new file mode 100644 index 000000000..a451108c4 --- /dev/null +++ b/ChangeLog.unit-testing-framework @@ -0,0 +1,26 @@ +2010-01-08 BVK Chaitanya + + Unit testing framework for GRUB. + + * Makefile.in: Test framework build rules for 'make check'. + * conf/tests.rmk: Build rules for individual tests and framework. + + * include/grub/test.h: Header file for whitebox tests. + * tests/lib/functional_test.c: Framework support for whitebox + functional tests. + * tests/lib/test.c: Common whitebox testing code for unit and + functional tests. + * tests/lib/unit_test.c: Framework support for whitebox unit + tests. + + * tests/util/grub-shell-tester.in: Support utility for grub-script + tests. + * tests/util/grub-shell.in: Utility to execute grub-script + commands in a Qemu instance. + + * tests/example_functional_test.c: Example whitebox functional + test. + * tests/example_grub_script_test.in: Example grub-script test. + * tests/example_scripted_test.in: Example scripted test. + * tests/example_unit_test.c: Example whitebox unit test. + From 5cc318eb3532f333dc324627dc977fe2f5bef40a Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Fri, 8 Jan 2010 22:06:46 +0530 Subject: [PATCH 19/63] replaced __func__ with simpler __FUNCTION__ macro --- include/grub/test.h | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/include/grub/test.h b/include/grub/test.h index 4b028371b..b4851bbf6 100644 --- a/include/grub/test.h +++ b/include/grub/test.h @@ -35,22 +35,10 @@ void grub_test_nonzero (int cond, const char *file, const char *fmt, ...) __attribute__ ((format (printf, 5, 6))); -#ifdef __STDC_VERSION__ -#if __STDC_VERSION__ < 199901L -# if __GNUC__ >= 2 -# define __func__ __FUNCTION__ -# else -# define __func__ "" -# endif -#endif -#else -#define __func__ "" -#endif - /* Macro to fill in location details and an optional error message. */ -#define grub_test_assert(cond, ...) \ - grub_test_nonzero(cond, __FILE__, __func__, __LINE__, \ - ## __VA_ARGS__, \ +#define grub_test_assert(cond, ...) \ + grub_test_nonzero(cond, __FILE__, __FUNCTION__, __LINE__, \ + ## __VA_ARGS__, \ "assert failed: %s", #cond) /* Macro to define a unit test. */ From 21a99f580417062f9a79ee7ab4a05753f2a47571 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Sat, 9 Jan 2010 20:27:58 +0530 Subject: [PATCH 20/63] added grub-script-check tool --- conf/common.rmk | 21 ++++ util/grub-script-check.c | 254 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 275 insertions(+) create mode 100644 util/grub-script-check.c diff --git a/conf/common.rmk b/conf/common.rmk index c5e4fcecf..50a4d2111 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -88,11 +88,32 @@ endif bin_UTILITIES += grub-mkrelpath grub_mkrelpath_SOURCES = gnulib/progname.c util/grub-mkrelpath.c util/misc.c +# For grub-script-check. +bin_UTILITIES += grub-script-check +util/grub-script-check.c_DEPENDENCIES = grub_script_check_init.h +grub_script_check_SOURCES = gnulib/progname.c util/grub-script-check.c util/misc.c \ + script/main.c script/script.c script/function.c script/lexer.c \ + kern/handler.c kern/err.c kern/parser.c kern/list.c \ + kern/misc.c kern/env.c grub_script_check_init.c grub_script.tab.c + # For the parser. grub_script.tab.c grub_script.tab.h: script/parser.y $(YACC) -d -p grub_script_yy -b grub_script $(srcdir)/script/parser.y DISTCLEANFILES += grub_script.tab.c grub_script.tab.h +# For grub-check. +grub_script_check_init.lst: geninit.sh $(filter-out grub_script_check_init.c,$(grub_script_check_SOURCES)) + rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@ +DISTCLEANFILES += grub_script_check_init.lst + +grub_script_check_init.h: grub_script_check_init.lst $(filter-out grub_script_check_init.c,$(grub_script_check_SOURCES)) geninitheader.sh + rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@ +DISTCLEANFILES += grub_script_check_init.h + +grub_script_check_init.c: grub_script_check_init.lst $(filter-out grub_script_check_init.c,$(grub_script_check_SOURCES)) geninit.sh + rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@ +DISTCLEANFILES += grub_script_check_init.c + # For grub-probe. grub_probe_init.lst: geninit.sh $(filter-out grub_probe_init.c,$(grub_probe_SOURCES)) rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@ diff --git a/util/grub-script-check.c b/util/grub-script-check.c new file mode 100644 index 000000000..3136c6530 --- /dev/null +++ b/util/grub-script-check.c @@ -0,0 +1,254 @@ +/* grub-script-check.c - check grub script file for syntax errors */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define _GNU_SOURCE 1 + +#include +#include +#include +#include +#include +#include + +#include "progname.h" + +void +grub_putchar (int c) +{ + putchar (c); +} + +int +grub_getkey (void) +{ + return -1; +} + +void +grub_refresh (void) +{ + fflush (stdout); +} + +struct grub_handler_class grub_term_input_class; +struct grub_handler_class grub_term_output_class; + +char * +grub_script_execute_argument_to_string (struct grub_script_arg *arg __attribute__ ((unused))) +{ + return 0; +} + +grub_err_t +grub_script_execute_cmdline (struct grub_script_cmd *cmd __attribute__ ((unused))) +{ + return 0; +} + +grub_err_t +grub_script_execute_cmdblock (struct grub_script_cmd *cmd __attribute__ ((unused))) +{ + return 0; +} + +grub_err_t +grub_script_execute_cmdif (struct grub_script_cmd *cmd __attribute__ ((unused))) +{ + return 0; +} + +grub_err_t +grub_script_execute_menuentry (struct grub_script_cmd *cmd) +{ + struct grub_script_cmd_menuentry *menu; + menu = (struct grub_script_cmd_menuentry *)cmd; + + if (menu->sourcecode) + { + grub_free (menu->sourcecode); + menu->sourcecode = 0; + } + return 0; +} + +grub_err_t +grub_script_execute (struct grub_script *script) +{ + if (script == 0 || script->cmd == 0) + return 0; + + return script->cmd->exec (script->cmd); +} + +static struct option options[] = + { + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {"verbose", no_argument, 0, 'v'}, + {0, 0, 0, 0} + }; + +static void +usage (int status) +{ + if (status) + fprintf (stderr, + "Try ``%s --help'' for more information.\n", program_name); + else + printf ("\ +Usage: %s [PATH]\n\ +\n\ +Checks GRUB script configuration file for syntax errors.\n\ +\n\ + -h, --help display this message and exit\n\ + -V, --version print version information and exit\n\ + -v, --verbose print script being processed\n\ +\n\ +Report bugs to <%s>.\n\ +", program_name, + PACKAGE_BUGREPORT); + exit (status); +} + +int +main (int argc, char *argv[]) +{ + char *argument; + char *input; + FILE *file = 0; + int verbose = 0; + struct grub_script *script; + + auto grub_err_t get_config_line (char **line, int cont); + grub_err_t get_config_line (char **line, int cont __attribute__ ((unused))) + { + char *cmdline = 0; + size_t len = 0; + ssize_t read; + + read = getline(&cmdline, &len, (file ?: stdin)); + if (read == -1) + { + *line = 0; + grub_errno = GRUB_ERR_READ_ERROR; + + if (cmdline) + free (cmdline); + return grub_errno; + } + + if (verbose) + grub_printf("%s", cmdline); + + *line = grub_strdup (cmdline); + + free (cmdline); + return 0; + } + + set_program_name (argv[0]); + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + /* Check for options. */ + while (1) + { + int c = getopt_long (argc, argv, "hvV", options, 0); + + if (c == -1) + break; + else + switch (c) + { + case 'h': + usage (0); + break; + + case 'V': + printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION); + return 0; + + case 'v': + verbose = 1; + break; + + default: + usage (1); + break; + } + } + + /* Obtain ARGUMENT. */ + if (optind >= argc) + { + file = 0; // read from stdin + } + else if (optind + 1 != argc) + { + fprintf (stderr, "Unknown extra argument `%s'.\n", argv[optind + 1]); + usage (1); + } + else + { + argument = argv[optind]; + file = fopen (argument, "r"); + if (! file) + { + fprintf (stderr, "%s: %s: %s\n", program_name, argument, strerror(errno)); + usage (1); + } + } + + /* Initialize all modules. */ + grub_init_all (); + + do + { + input = 0; + get_config_line(&input, 0); + if (! input) + break; + + script = grub_script_parse (input, get_config_line); + if (script) + { + grub_script_execute (script); + grub_script_free (script); + } + + grub_free (input); + } while (script != 0); + + /* Free resources. */ + grub_fini_all (); + if (file) fclose (file); + + return (script == 0); +} From 58ad6b39c4f549eb6a268fba5ea25d48c25ebf43 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Sat, 9 Jan 2010 20:31:33 +0530 Subject: [PATCH 21/63] added changelog file --- conf/common.rmk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/common.rmk b/conf/common.rmk index 50a4d2111..83464d3dd 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -101,7 +101,7 @@ grub_script.tab.c grub_script.tab.h: script/parser.y $(YACC) -d -p grub_script_yy -b grub_script $(srcdir)/script/parser.y DISTCLEANFILES += grub_script.tab.c grub_script.tab.h -# For grub-check. +# For grub-script-check. grub_script_check_init.lst: geninit.sh $(filter-out grub_script_check_init.c,$(grub_script_check_SOURCES)) rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@ DISTCLEANFILES += grub_script_check_init.lst From 337470f1e1c427d52603e0ee3bb9e29aa886180b Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Sat, 9 Jan 2010 20:31:52 +0530 Subject: [PATCH 22/63] added changelog --- ChangeLog.grub-script-check | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 ChangeLog.grub-script-check diff --git a/ChangeLog.grub-script-check b/ChangeLog.grub-script-check new file mode 100644 index 000000000..6ed178d24 --- /dev/null +++ b/ChangeLog.grub-script-check @@ -0,0 +1,9 @@ +2010-01-09 BVK Chaitanya + + Added new tool, grub-scrit-check to verify grub.cfg syntax. + + * util/grub-script-check.c: grub-script-check tool. + * conf/common.rmk: Make rules for grub-script-check. + + + From cd0514794a7948f5166c26cf7383f430e6a04b6a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Jan 2010 18:58:18 +0100 Subject: [PATCH 23/63] MAnipulate mbi in abstract way --- ChangeLog.abstractmbi | 25 +++ conf/i386-coreboot.rmk | 6 +- conf/i386-pc.rmk | 4 +- include/grub/multiboot.h | 13 ++ loader/i386/multiboot.c | 320 +++++++------------------------- loader/i386/multiboot_elfxx.c | 5 +- loader/i386/multiboot_mbi.c | 336 ++++++++++++++++++++++++++++++++++ 7 files changed, 453 insertions(+), 256 deletions(-) create mode 100644 ChangeLog.abstractmbi create mode 100644 loader/i386/multiboot_mbi.c diff --git a/ChangeLog.abstractmbi b/ChangeLog.abstractmbi new file mode 100644 index 000000000..a5ff55b08 --- /dev/null +++ b/ChangeLog.abstractmbi @@ -0,0 +1,25 @@ +2010-01-10 Vladimir Serbinenko + + * conf/i386-coreboot.rmk (multiboot_mod_SOURCES): + Add loader/i386/multiboot_mbi.c. + (multiboot2_mod_SOURCES): Likewise. + * conf/i386-pc.rmk (multiboot_mod_SOURCES): Likewise. + (multiboot2_mod_SOURCES): Likewise. + * include/grub/multiboot.h (grub_multiboot_get_mbi_size): New proto. + (grub_multiboot_make_mbi): Likewise. + (grub_multiboot_free_mbi): Likewise. + (grub_multiboot_init_mbi): Likewise. + (grub_multiboot_add_module): Likewise. + (grub_multiboot_set_bootdev): Likewise. + * loader/i386/multiboot.c (mbi): Removed. + (mbi_dest): Likewise. + (alloc_mbi): New variable. + (grub_multiboot_payload_size): Removed. All users updated. + (grub_multiboot_pure_size): New variable. + (grub_multiboot_boot): Use grub_multiboot_make_mbi. + (grub_multiboot_unload): Use grub_multiboot_free_mbi. + (grub_get_multiboot_mmap_len): Moved to loader/i386/multiboot_mbi.c. + (grub_fill_multiboot_mmap): Likewise. + (grub_multiboot_get_bootdev): Likewise. + (grub_multiboot): Use multiboot_mbi functions. + * loader/i386/multiboot_mbi.c: New file. diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index 95ee79436..d73c9f0e2 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -142,14 +142,16 @@ serial_mod_LDFLAGS = $(COMMON_LDFLAGS) pkglib_MODULES += multiboot.mod multiboot_mod_SOURCES = loader/i386/multiboot.c \ - loader/multiboot_loader.c + loader/i386/multiboot_mbi.c \ + loader/multiboot_loader.c multiboot_mod_CFLAGS = $(COMMON_CFLAGS) multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) pkglib_MODULES += multiboot2.mod multiboot2_mod_SOURCES = loader/i386/multiboot.c \ - loader/multiboot_loader.c + loader/multiboot_loader.c \ + loader/i386/multiboot_mbi.c multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 4215f0a34..2a69571aa 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -203,6 +203,7 @@ serial_mod_LDFLAGS = $(COMMON_LDFLAGS) pkglib_MODULES += multiboot.mod multiboot_mod_SOURCES = loader/i386/multiboot.c \ + loader/i386/multiboot_mbi.c \ loader/multiboot_loader.c multiboot_mod_CFLAGS = $(COMMON_CFLAGS) multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) @@ -210,7 +211,8 @@ multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) pkglib_MODULES += multiboot2.mod multiboot2_mod_SOURCES = loader/i386/multiboot.c \ - loader/multiboot_loader.c + loader/i386/multiboot_mbi.c \ + loader/multiboot_loader.c multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h index 041ee1f18..f9edb0c59 100644 --- a/include/grub/multiboot.h +++ b/include/grub/multiboot.h @@ -29,7 +29,20 @@ #include #endif +#include +#include + void grub_multiboot (int argc, char *argv[]); void grub_module (int argc, char *argv[]); +grub_size_t grub_multiboot_get_mbi_size (void); +grub_err_t grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, + grub_off_t buf_off, grub_size_t bufsize); +void grub_multiboot_free_mbi (void); +grub_err_t grub_multiboot_init_mbi (int argc, char *argv[]); +grub_err_t grub_multiboot_add_module (grub_addr_t start, grub_size_t size, + int argc, char *argv[]); +void grub_multiboot_set_bootdev (void); + + #endif /* ! GRUB_MULTIBOOT_HEADER */ diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c index f4869594e..2a69327b4 100644 --- a/loader/i386/multiboot.c +++ b/loader/i386/multiboot.c @@ -45,31 +45,24 @@ #include #include #include -#ifdef GRUB_MACHINE_PCBIOS -#include -#include -#include -#include -#endif #include extern grub_dl_t my_mod; -static struct multiboot_info *mbi, *mbi_dest; - -static grub_size_t code_size; +static grub_size_t code_size, alloc_mbi; char *grub_multiboot_payload_orig; grub_addr_t grub_multiboot_payload_dest; -grub_size_t grub_multiboot_payload_size; +grub_size_t grub_multiboot_pure_size; grub_uint32_t grub_multiboot_payload_eip; static grub_err_t grub_multiboot_boot (void) { + grub_size_t mbi_size; + grub_err_t err; struct grub_relocator32_state state = { .eax = MULTIBOOT_BOOTLOADER_MAGIC, - .ebx = PTR_TO_UINT32 (mbi_dest), .ecx = 0, .edx = 0, .eip = grub_multiboot_payload_eip, @@ -78,6 +71,24 @@ grub_multiboot_boot (void) .esp = 0x7ff00 }; + mbi_size = grub_multiboot_get_mbi_size (); + if (alloc_mbi < mbi_size) + { + grub_multiboot_payload_orig + = grub_relocator32_realloc (grub_multiboot_payload_orig, + grub_multiboot_pure_size + mbi_size); + if (!grub_multiboot_payload_orig) + return grub_errno; + alloc_mbi = mbi_size; + } + + state.ebx = grub_multiboot_payload_dest + grub_multiboot_pure_size; + err = grub_multiboot_make_mbi (grub_multiboot_payload_orig, + grub_multiboot_payload_dest, + grub_multiboot_pure_size, mbi_size); + if (err) + return err; + grub_relocator32_boot (grub_multiboot_payload_orig, grub_multiboot_payload_dest, state); @@ -89,69 +100,18 @@ grub_multiboot_boot (void) static grub_err_t grub_multiboot_unload (void) { - if (mbi) - { - unsigned int i; - for (i = 0; i < mbi->mods_count; i++) - { - grub_free ((void *) - ((struct multiboot_mod_list *) mbi->mods_addr)[i].mod_start); - grub_free ((void *) - ((struct multiboot_mod_list *) mbi->mods_addr)[i].cmdline); - } - grub_free ((void *) mbi->mods_addr); - } + grub_multiboot_free_mbi (); + grub_relocator32_free (grub_multiboot_payload_orig); - mbi = NULL; + alloc_mbi = 0; + grub_multiboot_payload_orig = NULL; grub_dl_unref (my_mod); return GRUB_ERR_NONE; } -/* Return the length of the Multiboot mmap that will be needed to allocate - our platform's map. */ -static grub_uint32_t -grub_get_multiboot_mmap_len (void) -{ - grub_size_t count = 0; - - auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); - int NESTED_FUNC_ATTR hook (grub_uint64_t addr __attribute__ ((unused)), - grub_uint64_t size __attribute__ ((unused)), - grub_uint32_t type __attribute__ ((unused))) - { - count++; - return 0; - } - - grub_mmap_iterate (hook); - - return count * sizeof (struct multiboot_mmap_entry); -} - -/* Fill previously allocated Multiboot mmap. */ -static void -grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry) -{ - struct multiboot_mmap_entry *mmap_entry = (struct multiboot_mmap_entry *) first_entry; - - auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); - int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type) - { - mmap_entry->addr = addr; - mmap_entry->len = size; - mmap_entry->type = type; - mmap_entry->size = sizeof (struct multiboot_mmap_entry) - sizeof (mmap_entry->size); - mmap_entry++; - - return 0; - } - - grub_mmap_iterate (hook); -} - #define MULTIBOOT_LOAD_ELF64 #include "multiboot_elfxx.c" #undef MULTIBOOT_LOAD_ELF64 @@ -172,58 +132,13 @@ grub_multiboot_load_elf (grub_file_t file, void *buffer) return grub_error (GRUB_ERR_UNKNOWN_OS, "unknown ELF class"); } -static int -grub_multiboot_get_bootdev (grub_uint32_t *bootdev) -{ -#ifdef GRUB_MACHINE_PCBIOS - char *p; - grub_uint32_t biosdev, slice = ~0, part = ~0; - grub_device_t dev; - - biosdev = grub_get_root_biosnumber (); - - dev = grub_device_open (0); - if (dev && dev->disk && dev->disk->partition) - { - - p = dev->disk->partition->partmap->get_name (dev->disk->partition); - if (p) - { - if ((p[0] >= '0') && (p[0] <= '9')) - { - slice = grub_strtoul (p, &p, 0) - 1; - - if ((p) && (p[0] == ',')) - p++; - } - - if ((p[0] >= 'a') && (p[0] <= 'z')) - part = p[0] - 'a'; - } - } - if (dev) - grub_device_close (dev); - - *bootdev = ((biosdev & 0xff) << 24) | ((slice & 0xff) << 16) - | ((part & 0xff) << 8) | 0xff; - return (biosdev != ~0UL); -#else - *bootdev = 0xffffffff; - return 0; -#endif -} - void grub_multiboot (int argc, char *argv[]) { grub_file_t file = 0; - char buffer[MULTIBOOT_SEARCH], *cmdline = 0, *p; + char buffer[MULTIBOOT_SEARCH]; struct multiboot_header *header; - grub_ssize_t len, cmdline_length, boot_loader_name_length; - grub_uint32_t mmap_length; - int i; - int cmdline_argc; - char **cmdline_argv; + grub_ssize_t len; grub_loader_unset (); @@ -274,31 +189,8 @@ grub_multiboot (int argc, char *argv[]) grub_relocator32_free (grub_multiboot_payload_orig); grub_multiboot_payload_orig = NULL; - mmap_length = grub_get_multiboot_mmap_len (); - - /* Figure out cmdline length. */ /* Skip filename. */ - cmdline_argc = argc - 1; - cmdline_argv = argv + 1; - - for (i = 0, cmdline_length = 0; i < cmdline_argc; i++) - cmdline_length += grub_strlen (cmdline_argv[i]) + 1; - - if (cmdline_length == 0) - cmdline_length = 1; - - boot_loader_name_length = sizeof(PACKAGE_STRING); - -#define cmdline_addr(x) ((void *) ((x) + code_size)) -#define boot_loader_name_addr(x) \ - ((void *) ((x) + code_size + cmdline_length)) -#define mbi_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length)) -#define mmap_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length + sizeof (struct multiboot_info))) - - grub_multiboot_payload_size = cmdline_length - /* boot_loader_name_length might need to grow for mbi,etc to be aligned (see below) */ - + boot_loader_name_length + 3 - + sizeof (struct multiboot_info) + mmap_length; + grub_multiboot_init_mbi (argc - 1, argv + 1); if (header->flags & MULTIBOOT_AOUT_KLUDGE) { @@ -313,10 +205,12 @@ grub_multiboot (int argc, char *argv[]) code_size = load_size; grub_multiboot_payload_dest = header->load_addr; - grub_multiboot_payload_size += code_size; + grub_multiboot_pure_size += code_size; + /* Allocate a bit more to avoid relocations in most cases. */ + alloc_mbi = grub_multiboot_get_mbi_size () + 65536; grub_multiboot_payload_orig - = grub_relocator32_alloc (grub_multiboot_payload_size); + = grub_relocator32_alloc (grub_multiboot_pure_size + alloc_mbi); if (! grub_multiboot_payload_orig) goto fail; @@ -338,53 +232,35 @@ grub_multiboot (int argc, char *argv[]) else if (grub_multiboot_load_elf (file, buffer) != GRUB_ERR_NONE) goto fail; - /* This provides alignment for the MBI, the memory map and the backward relocator. */ - boot_loader_name_length += (0x04 - ((unsigned long) mbi_addr (grub_multiboot_payload_dest) & 0x03)); - - mbi = mbi_addr (grub_multiboot_payload_orig); - mbi_dest = mbi_addr (grub_multiboot_payload_dest); - grub_memset (mbi, 0, sizeof (struct multiboot_info)); - mbi->mmap_length = mmap_length; - - grub_fill_multiboot_mmap (mmap_addr (grub_multiboot_payload_orig)); - - /* FIXME: grub_uint32_t will break for addresses above 4 GiB, but is mandated - by the spec. Is there something we can do about it? */ - mbi->mmap_addr = (grub_uint32_t) mmap_addr (grub_multiboot_payload_dest); - mbi->flags |= MULTIBOOT_INFO_MEM_MAP; - - /* Convert from bytes to kilobytes. */ - mbi->mem_lower = grub_mmap_get_lower () / 1024; - mbi->mem_upper = grub_mmap_get_upper () / 1024; - mbi->flags |= MULTIBOOT_INFO_MEMORY; - - cmdline = p = cmdline_addr (grub_multiboot_payload_orig); - if (! cmdline) - goto fail; - - for (i = 0; i < cmdline_argc; i++) + if (header->flags & MULTIBOOT_VIDEO_MODE) { - p = grub_stpcpy (p, cmdline_argv[i]); - *(p++) = ' '; + switch (header->mode_type) + { + case 1: + grub_env_set ("gfxpayload", "text"); + break; + + case 0: + { + char buf[sizeof ("XXXXXXXXXXxXXXXXXXXXXxXXXXXXXXXX,XXXXXXXXXXxXXXXXXXXXX,auto")]; + if (header->depth && header->width && header->height) + grub_sprintf (buf, "%dx%dx%d,%dx%d,auto", header->width, + header->height, header->depth, header->width, + header->height); + else if (header->width && header->height) + grub_sprintf (buf, "%dx%d,auto", header->width, header->height); + else + grub_sprintf (buf, "auto"); + + grub_env_set ("gfxpayload", buf); + break; + } + } } - /* Remove the space after the last word. */ - if (p != cmdline) - p--; - *p = 0; + grub_multiboot_set_bootdev (); - mbi->flags |= MULTIBOOT_INFO_CMDLINE; - mbi->cmdline = (grub_uint32_t) cmdline_addr (grub_multiboot_payload_dest); - - - grub_strcpy (boot_loader_name_addr (grub_multiboot_payload_orig), PACKAGE_STRING); - mbi->flags |= MULTIBOOT_INFO_BOOT_LOADER_NAME; - mbi->boot_loader_name = (grub_uint32_t) boot_loader_name_addr (grub_multiboot_payload_dest); - - if (grub_multiboot_get_bootdev (&mbi->boot_device)) - mbi->flags |= MULTIBOOT_INFO_BOOTDEV; - - grub_loader_set (grub_multiboot_boot, grub_multiboot_unload, 1); + grub_loader_set (grub_multiboot_boot, grub_multiboot_unload, 0); fail: if (file) @@ -392,22 +268,18 @@ grub_multiboot (int argc, char *argv[]) if (grub_errno != GRUB_ERR_NONE) { - grub_free (cmdline); - grub_free (mbi); + grub_relocator32_free (grub_multiboot_payload_orig); grub_dl_unref (my_mod); } } - void grub_module (int argc, char *argv[]) { grub_file_t file = 0; - grub_ssize_t size, len = 0; - char *module = 0, *cmdline = 0, *p; - int i; - int cmdline_argc; - char **cmdline_argv; + grub_ssize_t size; + char *module = 0; + grub_err_t err; if (argc == 0) { @@ -415,7 +287,7 @@ grub_module (int argc, char *argv[]) goto fail; } - if (!mbi) + if (!grub_multiboot_payload_orig) { grub_error (GRUB_ERR_BAD_ARGUMENT, "you need to load the multiboot kernel first"); @@ -431,73 +303,19 @@ grub_module (int argc, char *argv[]) if (! module) goto fail; + err = grub_multiboot_add_module ((grub_addr_t) module, size, + argc - 1, argv + 1); + if (err) + goto fail; + if (grub_file_read (file, module, size) != size) { grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); goto fail; } - /* Skip module name. */ - cmdline_argc = argc - 1; - cmdline_argv = argv + 1; - - for (i = 0; i < cmdline_argc; i++) - len += grub_strlen (cmdline_argv[i]) + 1; - - if (len == 0) - len = 1; - - cmdline = p = grub_malloc (len); - if (! cmdline) - goto fail; - - for (i = 0; i < cmdline_argc; i++) - { - p = grub_stpcpy (p, cmdline_argv[i]); - *(p++) = ' '; - } - - /* Remove the space after the last word. */ - if (p != cmdline) - p--; - *p = '\0'; - - if (mbi->flags & MULTIBOOT_INFO_MODS) - { - struct multiboot_mod_list *modlist = (struct multiboot_mod_list *) mbi->mods_addr; - - modlist = grub_realloc (modlist, (mbi->mods_count + 1) - * sizeof (struct multiboot_mod_list)); - if (! modlist) - goto fail; - mbi->mods_addr = (grub_uint32_t) modlist; - modlist += mbi->mods_count; - modlist->mod_start = (grub_uint32_t) module; - modlist->mod_end = (grub_uint32_t) module + size; - modlist->cmdline = (grub_uint32_t) cmdline; - modlist->pad = 0; - mbi->mods_count++; - } - else - { - struct multiboot_mod_list *modlist = grub_zalloc (sizeof (struct multiboot_mod_list)); - if (! modlist) - goto fail; - modlist->mod_start = (grub_uint32_t) module; - modlist->mod_end = (grub_uint32_t) module + size; - modlist->cmdline = (grub_uint32_t) cmdline; - mbi->mods_count = 1; - mbi->mods_addr = (grub_uint32_t) modlist; - mbi->flags |= MULTIBOOT_INFO_MODS; - } - fail: if (file) grub_file_close (file); - - if (grub_errno != GRUB_ERR_NONE) - { - grub_free (module); - grub_free (cmdline); - } } + diff --git a/loader/i386/multiboot_elfxx.c b/loader/i386/multiboot_elfxx.c index 80db25144..8f6367432 100644 --- a/loader/i386/multiboot_elfxx.c +++ b/loader/i386/multiboot_elfxx.c @@ -100,10 +100,11 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer) code_size = (phdr(highest_segment)->p_paddr + phdr(highest_segment)->p_memsz) - phdr(lowest_segment)->p_paddr; grub_multiboot_payload_dest = phdr(lowest_segment)->p_paddr; - grub_multiboot_payload_size += code_size; + grub_multiboot_pure_size += code_size; + alloc_mbi = grub_multiboot_get_mbi_size (); grub_multiboot_payload_orig - = grub_relocator32_alloc (grub_multiboot_payload_size); + = grub_relocator32_alloc (grub_multiboot_pure_size + alloc_mbi); if (!grub_multiboot_payload_orig) return grub_errno; diff --git a/loader/i386/multiboot_mbi.c b/loader/i386/multiboot_mbi.c new file mode 100644 index 000000000..58802d44c --- /dev/null +++ b/loader/i386/multiboot_mbi.c @@ -0,0 +1,336 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#ifdef GRUB_MACHINE_PCBIOS +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +struct module +{ + struct module *next; + grub_addr_t start; + grub_size_t size; + char *cmdline; + int cmdline_size; +}; + +struct module *modules, *modules_last; +static grub_size_t cmdline_size; +static grub_size_t total_modcmd; +static unsigned modcnt; +static char *cmdline = NULL; +static grub_uint32_t bootdev; +static int bootdev_set; + +/* Return the length of the Multiboot mmap that will be needed to allocate + our platform's map. */ +static grub_uint32_t +grub_get_multiboot_mmap_len (void) +{ + grub_size_t count = 0; + + auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); + int NESTED_FUNC_ATTR hook (grub_uint64_t addr __attribute__ ((unused)), + grub_uint64_t size __attribute__ ((unused)), + grub_uint32_t type __attribute__ ((unused))) + { + count++; + return 0; + } + + grub_mmap_iterate (hook); + + return count * sizeof (struct multiboot_mmap_entry); +} + +grub_size_t +grub_multiboot_get_mbi_size (void) +{ + return sizeof (struct multiboot_info) + ALIGN_UP (cmdline_size, 4) + + modcnt * sizeof (struct multiboot_mod_list) + total_modcmd + + ALIGN_UP (sizeof(PACKAGE_STRING), 4) + grub_get_multiboot_mmap_len (); +} + +/* Fill previously allocated Multiboot mmap. */ +static void +grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry) +{ + struct multiboot_mmap_entry *mmap_entry = (struct multiboot_mmap_entry *) first_entry; + + auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); + int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type) + { + mmap_entry->addr = addr; + mmap_entry->len = size; + switch (type) + { + case GRUB_MACHINE_MEMORY_AVAILABLE: + mmap_entry->type = MULTIBOOT_MEMORY_AVAILABLE; + break; + + default: + mmap_entry->type = MULTIBOOT_MEMORY_RESERVED; + break; + } + mmap_entry->size = sizeof (struct multiboot_mmap_entry) - sizeof (mmap_entry->size); + mmap_entry++; + + return 0; + } + + grub_mmap_iterate (hook); +} + +grub_err_t +grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, grub_off_t buf_off, + grub_size_t bufsize) +{ + grub_uint8_t *ptrorig = (grub_uint8_t *) orig + buf_off; + grub_uint32_t ptrdest = dest + buf_off; + struct multiboot_info *mbi; + struct multiboot_mod_list *modlist; + unsigned i; + struct module *cur; + grub_size_t mmap_size; + + if (bufsize < grub_multiboot_get_mbi_size ()) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "mbi buffer is too small"); + + mbi = (struct multiboot_info *) ptrorig; + ptrorig += sizeof (*mbi); + ptrdest += sizeof (*mbi); + grub_memset (mbi, 0, sizeof (*mbi)); + + grub_memcpy (ptrorig, cmdline, cmdline_size); + mbi->flags |= MULTIBOOT_INFO_CMDLINE; + mbi->cmdline = ptrdest; + ptrorig += ALIGN_UP (cmdline_size, 4); + ptrdest += ALIGN_UP (cmdline_size, 4); + + grub_memcpy (ptrorig, PACKAGE_STRING, sizeof(PACKAGE_STRING)); + mbi->flags |= MULTIBOOT_INFO_BOOT_LOADER_NAME; + mbi->boot_loader_name = ptrdest; + ptrorig += ALIGN_UP (sizeof(PACKAGE_STRING), 4); + ptrdest += ALIGN_UP (sizeof(PACKAGE_STRING), 4); + + if (modcnt) + { + mbi->flags |= MULTIBOOT_INFO_MODS; + mbi->mods_addr = ptrdest; + mbi->mods_count = modcnt; + modlist = (struct multiboot_mod_list *) ptrorig; + ptrorig += modcnt * sizeof (struct multiboot_mod_list); + ptrdest += modcnt * sizeof (struct multiboot_mod_list); + + for (i = 0, cur = modules; i < modcnt; i++, cur = cur->next) + { + modlist[i].mod_start = cur->start; + modlist[i].mod_end = modlist[i].mod_start + cur->size; + modlist[i].cmdline = ptrdest; + grub_memcpy (ptrorig, cur->cmdline, cur->cmdline_size); + ptrorig += ALIGN_UP (cur->cmdline_size, 4); + ptrdest += ALIGN_UP (cur->cmdline_size, 4); + } + } + else + { + mbi->mods_addr = 0; + mbi->mods_count = 0; + } + + mmap_size = grub_get_multiboot_mmap_len (); + grub_fill_multiboot_mmap ((struct multiboot_mmap_entry *) ptrorig); + mbi->mmap_length = mmap_size; + mbi->mmap_addr = ptrdest; + mbi->flags |= MULTIBOOT_INFO_MEM_MAP; + ptrorig += mmap_size; + ptrdest += mmap_size; + + /* Convert from bytes to kilobytes. */ + mbi->mem_lower = grub_mmap_get_lower () / 1024; + mbi->mem_upper = grub_mmap_get_upper () / 1024; + mbi->flags |= MULTIBOOT_INFO_MEMORY; + + if (bootdev_set) + { + mbi->boot_device = bootdev; + mbi->flags |= MULTIBOOT_INFO_BOOTDEV; + } + + return GRUB_ERR_NONE; +} + +void +grub_multiboot_free_mbi (void) +{ + struct module *cur, *next; + + cmdline_size = 0; + total_modcmd = 0; + modcnt = 0; + grub_free (cmdline); + cmdline = NULL; + bootdev_set = 0; + + for (cur = modules; cur; cur = next) + { + next = cur->next; + grub_free (cur->cmdline); + grub_free (cur); + } + modules = NULL; + modules_last = NULL; +} + +grub_err_t +grub_multiboot_init_mbi (int argc, char *argv[]) +{ + grub_ssize_t len = 0; + char *p; + int i; + + grub_multiboot_free_mbi (); + + for (i = 0; i < argc; i++) + len += grub_strlen (argv[i]) + 1; + if (len == 0) + len = 1; + + cmdline = p = grub_malloc (len); + if (! cmdline) + return grub_errno; + cmdline_size = len; + + for (i = 0; i < argc; i++) + { + p = grub_stpcpy (p, argv[i]); + *(p++) = ' '; + } + + /* Remove the space after the last word. */ + if (p != cmdline) + p--; + *p = '\0'; + + return GRUB_ERR_NONE; +} + +grub_err_t +grub_multiboot_add_module (grub_addr_t start, grub_size_t size, + int argc, char *argv[]) +{ + struct module *newmod; + char *p; + grub_ssize_t len = 0; + int i; + + newmod = grub_malloc (sizeof (*newmod)); + if (!newmod) + return grub_errno; + newmod->start = start; + newmod->size = size; + + for (i = 0; i < argc; i++) + len += grub_strlen (argv[i]) + 1; + + if (len == 0) + len = 1; + + newmod->cmdline = p = grub_malloc (len); + if (! newmod->cmdline) + { + grub_free (newmod); + return grub_errno; + } + newmod->cmdline_size = len; + total_modcmd += ALIGN_UP (len, 4); + + for (i = 0; i < argc; i++) + { + p = grub_stpcpy (p, argv[i]); + *(p++) = ' '; + } + + /* Remove the space after the last word. */ + if (p != newmod->cmdline) + p--; + *p = '\0'; + + if (modules_last) + modules_last->next = newmod; + else + { + modules = newmod; + modules_last->next = NULL; + } + modules_last = newmod; + + modcnt++; + + return GRUB_ERR_NONE; +} + +void +grub_multiboot_set_bootdev (void) +{ + char *p; + grub_uint32_t biosdev, slice = ~0, part = ~0; + grub_device_t dev; + +#ifdef GRUB_MACHINE_PCBIOS + biosdev = grub_get_root_biosnumber (); +#else + biosdev = 0xffffffff; +#endif + + dev = grub_device_open (0); + if (dev && dev->disk && dev->disk->partition) + { + + p = dev->disk->partition->partmap->get_name (dev->disk->partition); + if (p) + { + if ((p[0] >= '0') && (p[0] <= '9')) + { + slice = grub_strtoul (p, &p, 0) - 1; + + if ((p) && (p[0] == ',')) + p++; + } + + if ((p[0] >= 'a') && (p[0] <= 'z')) + part = p[0] - 'a'; + } + } + if (dev) + grub_device_close (dev); + + bootdev = ((biosdev & 0xff) << 24) | ((slice & 0xff) << 16) + | ((part & 0xff) << 8) | 0xff; + bootdev_set = 1; +} From e9060a9d3b1509656241f9128480250ad6824543 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Jan 2010 22:34:25 +0100 Subject: [PATCH 24/63] 2010-01-10 Vladimir Serbinenko * normal/cmdline.c (grub_cmdline_get): Fix off-by-one error which resulted in garbled command line at the end of screen. --- ChangeLog | 5 +++++ normal/cmdline.c | 21 ++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5f141d6a5..65da2542d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-10 Vladimir Serbinenko + + * normal/cmdline.c (grub_cmdline_get): Fix off-by-one error + which resulted in garbled command line at the end of screen. + 2010-01-10 Robert Millan * loader/i386/ieee1275/linux.c (grub_linux_boot): Rework video position diff --git a/normal/cmdline.c b/normal/cmdline.c index 656b14c6a..429c84be7 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -254,21 +254,20 @@ grub_cmdline_get (const char *prompt) for (p = buf + pos; p < buf + llen; p++) { - if (cl_term->xpos++ > cl_term->width - 2) - { - grub_putcode ('\n', cl_term->term); - - cl_term->xpos = 1; - if (cl_term->ypos == (unsigned) (cl_term->height)) - cl_term->ystart--; - else - cl_term->ypos++; - } - if (c) grub_putcode (c, cl_term->term); else grub_putcode (*p, cl_term->term); + cl_term->xpos++; + if (cl_term->xpos >= cl_term->width - 1) + { + cl_term->xpos = 0; + if (cl_term->ypos >= (unsigned) (cl_term->height - 1)) + cl_term->ystart--; + else + cl_term->ypos++; + grub_putcode ('\n', cl_term->term); + } } } From ffa8e3d2775628355960eefa2d4433d15b13d5d8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Jan 2010 22:35:46 +0100 Subject: [PATCH 25/63] 2010-01-10 Vladimir Serbinenko * term/i386/pc/vga_text.c (inc_y): Fix off-by-one error which resulted in premature implicit newline. --- ChangeLog | 5 +++++ term/i386/pc/vga_text.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 65da2542d..321baa439 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-10 Vladimir Serbinenko + + * term/i386/pc/vga_text.c (inc_y): Fix off-by-one error which resulted + in premature implicit newline. + 2010-01-10 Vladimir Serbinenko * normal/cmdline.c (grub_cmdline_get): Fix off-by-one error diff --git a/term/i386/pc/vga_text.c b/term/i386/pc/vga_text.c index 170f74de8..f954cab43 100644 --- a/term/i386/pc/vga_text.c +++ b/term/i386/pc/vga_text.c @@ -77,7 +77,7 @@ inc_y (void) static void inc_x (void) { - if (grub_curr_x >= COLS - 2) + if (grub_curr_x >= COLS - 1) inc_y (); else grub_curr_x++; From a788afb626011e4fbf98d929a818735e9d2bdf1c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 11 Jan 2010 12:00:57 +0000 Subject: [PATCH 26/63] 2010-01-11 Colin Watson * util/grub-install.in (usage): Clarify meaning of --root-directory, and make it clearer that it's optional. Based on confusion witnessed on IRC. --- ChangeLog | 6 ++++++ util/grub-install.in | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 321baa439..42343a8b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-11 Colin Watson + + * util/grub-install.in (usage): Clarify meaning of --root-directory, + and make it clearer that it's optional. Based on confusion + witnessed on IRC. + 2010-01-10 Vladimir Serbinenko * term/i386/pc/vga_text.c (inc_y): Fix off-by-one error which resulted diff --git a/util/grub-install.in b/util/grub-install.in index 1fcfb1aca..f3fd88188 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -87,9 +87,11 @@ fi INSTALL_DEVICE can be a GRUB device name or a system device filename. -grub-install copies GRUB images into the DIR/boot directory specified by ---root-directory, and uses grub-setup to install grub into the boot -sector. +grub-install copies GRUB images into /boot/grub (or /grub on NetBSD and +OpenBSD), and uses grub-setup to install grub into the boot sector. + +If the --root-directory option is used, then grub-install will copy +images into the operating system installation rooted at that directory. Report bugs to . EOF From 92ab12b09225525d1e3ebd4deb9201f21cab82e8 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 11 Jan 2010 14:55:20 +0000 Subject: [PATCH 27/63] 2010-01-11 Robert Millan * util/misc.c (canonicalize_file_name): New function. (make_system_path_relative_to_its_root): Use canonicalize_file_name() instead of realpath(). --- ChangeLog | 6 ++++++ util/misc.c | 23 ++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 42343a8b6..768a65944 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-11 Robert Millan + + * util/misc.c (canonicalize_file_name): New function. + (make_system_path_relative_to_its_root): Use canonicalize_file_name() + instead of realpath(). + 2010-01-11 Colin Watson * util/grub-install.in (usage): Clarify meaning of --root-directory, diff --git a/util/misc.c b/util/misc.c index d8aa041be..47dd8c78d 100644 --- a/util/misc.c +++ b/util/misc.c @@ -479,6 +479,19 @@ fail: #endif /* __MINGW32__ */ +char * +canonicalize_file_name (const char *path) +{ + char *ret; +#ifdef PATH_MAX + ret = xmalloc (PATH_MAX); + (void) realpath (path, ret); +#else + ret = realpath (path, NULL); +#endif + return ret; +} + /* This function never prints trailing slashes (so that its output can be appended a slash unconditionally). */ char * @@ -491,15 +504,11 @@ make_system_path_relative_to_its_root (const char *path) size_t len; /* canonicalize. */ - p = realpath (path, NULL); + p = canonicalize_file_name (path); if (p == NULL) - { - if (errno != EINVAL) - grub_util_error ("failed to get realpath of %s", path); - else - grub_util_error ("realpath not supporting (path, NULL)"); - } + grub_util_error ("failed to get canonical path of %s", path); + len = strlen (p) + 1; buf = strdup (p); free (p); From afdc9ad0065bfa84b2d9a981c038a89aaba67f14 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Tue, 12 Jan 2010 09:00:55 +0530 Subject: [PATCH 28/63] fixed an error message --- ChangeLog.unit-testing-framework | 4 ++++ tests/util/grub-shell-tester.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index a451108c4..5fd7a2f28 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -1,3 +1,7 @@ +2010-01-12 BVK Chaitanya + + * tests/util/grub-shell-tester.in: Fix error message. + 2010-01-08 BVK Chaitanya Unit testing framework for GRUB. diff --git a/tests/util/grub-shell-tester.in b/tests/util/grub-shell-tester.in index 18f5e79b7..6ed4ebcac 100644 --- a/tests/util/grub-shell-tester.in +++ b/tests/util/grub-shell-tester.in @@ -98,7 +98,7 @@ bash ${source} >${outfile2} if ! diff -q ${outfile1} ${outfile2} >/dev/null then - echo "$1: GRUB and BASH outputs (${outfile1}, ${outfile2}) did not match" + echo "${source}: GRUB and BASH outputs did not match (see diff -u ${outfile1} ${outfile2})" status=1 else rm -f ${outfile1} ${outfile2} From 350285caaefc8384ca73263fe42f89f66ec28779 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Tue, 12 Jan 2010 09:23:24 +0530 Subject: [PATCH 29/63] removed unnecessary EXPORT_* macro usage --- ChangeLog.unit-testing-framework | 2 ++ include/grub/test.h | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index 5fd7a2f28..973a7c756 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -1,5 +1,7 @@ 2010-01-12 BVK Chaitanya + * include/grub/test.h: Removed EXPORT_* usage. + * tests/util/grub-shell-tester.in: Fix error message. 2010-01-08 BVK Chaitanya diff --git a/include/grub/test.h b/include/grub/test.h index b4851bbf6..bd5b7d806 100644 --- a/include/grub/test.h +++ b/include/grub/test.h @@ -20,11 +20,10 @@ struct grub_test }; typedef struct grub_test *grub_test_t; -extern grub_test_t EXPORT_VAR (grub_test_list); +extern grub_test_t grub_test_list; -void EXPORT_FUNC (grub_test_register) (const char *name, void (*test) (void)); - -void EXPORT_FUNC (grub_test_unregister) (const char *name); +void grub_test_register (const char *name, void (*test) (void)); +void grub_test_unregister (const char *name); /* Execute a test and print results. */ int grub_test_run (grub_test_t test); From c5431d4029cfe61dcdd3f28a3bd6d9f22a0b80ea Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Tue, 12 Jan 2010 10:16:17 +0530 Subject: [PATCH 30/63] build tests on make, but run on make check --- ChangeLog.unit-testing-framework | 5 ++++- Makefile.in | 21 +++++++++------------ conf/tests.rmk | 31 ++++++++++++++++++------------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index 973a7c756..620ac80cf 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -1,6 +1,9 @@ 2010-01-12 BVK Chaitanya - * include/grub/test.h: Removed EXPORT_* usage. + * conf/tests.rmk: Build tests on make. + * Makefile.in (check): Use new variables. + + * include/grub/test.h: Remove EXPORT_* usage. * tests/util/grub-shell-tester.in: Fix error message. diff --git a/Makefile.in b/Makefile.in index 567571897..45c6f3e45 100644 --- a/Makefile.in +++ b/Makefile.in @@ -460,15 +460,18 @@ distcheck: dist @echo "$(distdir).tar.gz is ready for distribution" | \ sed 'h;s/./=/g;p;x;p;x' -TESTS = $(check_UTILITIES) $(check_SCRIPTS) $(check_MODULES) -$(TESTS): $(test_framework_SCRIPTS) $(test_framework_MODULES) - -check: all $(TESTS) - @list="$(check_UTILITIES)"; \ +check: all $(UNIT_TESTS) $(FUNCTIONAL_TESTS) $(SCRIPTED_TESTS) + @list="$(UNIT_TESTS)"; \ for file in $$list; do \ $(builddir)/$$file; \ done - @list="$(check_SCRIPTS)"; \ + @list="$(FUNCTIONAL_TESTS)"; \ + for file in $$list; do \ + mod=`basename $$file .mod`; \ + echo "insmod functional_test; insmod $$mod; functional_test" \ + | $(builddir)/grub-shell; \ + done + @list="$(SCRIPTED_TESTS)"; \ for file in $$list; do \ echo "$$file:"; \ if $(builddir)/$$file; then \ @@ -477,12 +480,6 @@ check: all $(TESTS) echo "$$file: FAIL"; \ fi; \ done - @list="$(check_MODULES)"; \ - for file in $$list; do \ - mod=`basename $$file .mod`; \ - echo "insmod functional_test; insmod $$mod; functional_test" \ - | $(builddir)/grub-shell; \ - done .SUFFIX: .SUFFIX: .c .o .S .d diff --git a/conf/tests.rmk b/conf/tests.rmk index c35ea0baa..e894323ae 100644 --- a/conf/tests.rmk +++ b/conf/tests.rmk @@ -4,38 +4,43 @@ grub-shell: tests/util/grub-shell.in config.status ./config.status --file=$@:$< chmod +x $@ -test_framework_SCRIPTS += grub-shell +bin_SCRIPTS += grub-shell CLEANFILES += grub-shell # For grub-shell-tester grub-shell-tester: tests/util/grub-shell-tester.in config.status ./config.status --file=$@:$< chmod +x $@ -test_framework_SCRIPTS += grub-shell-tester +bin_SCRIPTS += grub-shell-tester CLEANFILES += grub-shell-tester -test_framework_MODULES += functional_test.mod +pkglib_MODULES += functional_test.mod functional_test_mod_SOURCES = tests/lib/functional_test.c tests/lib/test.c functional_test_mod_CFLAGS = $(COMMON_CFLAGS) functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) -# Unit tests - -check_UTILITIES += example_unit_test +# Rules for unit tests +bin_UTILITIES += example_unit_test example_unit_test_SOURCES = tests/example_unit_test.c kern/list.c kern/misc.c tests/lib/test.c tests/lib/unit_test.c example_unit_test_CFLAGS = -Wno-format -# Functional tests - -check_MODULES += example_functional_test.mod +# Rules for functional tests +pkglib_MODULES += example_functional_test.mod example_functional_test_mod_SOURCES = tests/example_functional_test.c example_functional_test_mod_CFLAGS = -Wno-format $(COMMON_CFLAGS) example_functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) -# Scripted tests - -check_SCRIPTS += example_scripted_test +# Rules for scripted tests +bin_SCRIPTS += example_scripted_test example_scripted_test_SOURCES = tests/example_scripted_test.in -check_SCRIPTS += example_grub_script_test +bin_SCRIPTS += example_grub_script_test example_grub_script_test_SOURCES = tests/example_grub_script_test.in + + +# List of tests to execute on "make check" + +SCRIPTED_TESTS = example_scripted_test +SCRIPTED_TESTS += example_grub_script_test +UNIT_TESTS = example_unit_test +FUNCTIONAL_TESTS = example_functional_test.mod From afafb37e9b56158454aeacc6072b368b8198e55f Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Tue, 12 Jan 2010 10:54:37 +0530 Subject: [PATCH 31/63] added boot device selection to grub-shell --- ChangeLog.unit-testing-framework | 2 ++ tests/util/grub-shell.in | 40 ++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index 620ac80cf..8641d09ee 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -1,5 +1,7 @@ 2010-01-12 BVK Chaitanya + * tests/util/grub-shell.in: New --boot option. + * conf/tests.rmk: Build tests on make. * Makefile.in (check): Use new variables. diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in index c1b2ef258..b103872ba 100644 --- a/tests/util/grub-shell.in +++ b/tests/util/grub-shell.in @@ -42,6 +42,7 @@ Run GRUB script in a Qemu instance. -h, --help print this message and exit -v, --version print the version information and exit + --boot=[fd|hd|cd] boot method for Qemu instance --modules=MODULES pre-load specified modules MODULES --qemu-opts=OPTIONS extra options to pass to Qemu instance @@ -67,11 +68,20 @@ for option in "$@"; do --qemu-opts=*) qs=`echo "$option" | sed -e 's/--qemu-opts=//'` qemuopts="$qemuopts $qs" ;; + --boot=*) + dev=`echo "$option" | sed -e 's/--boot=//'` + if [ "$dev" = "fd" ] ; then bootdev=a; + elif [ "$dev" = "hd" ] ; then bootdev=c; + elif [ "$dev" = "cd" ] ; then bootdev=d; + else + echo "Unrecognized boot method \`$dev'" 1>&2 + usage + exit 1 + fi ;; -*) echo "Unrecognized option \`$option'" 1>&2 usage - exit 1 - ;; + exit 1 ;; *) if [ "x${source}" != x ] ; then echo "too many parameters at the end" 1>&2 @@ -83,11 +93,15 @@ for option in "$@"; do done if [ "x${source}" = x ] ; then - tmpfile=`mktemp` - while read; do - echo $REPLY >> ${tmpfile} - done - source=${tmpfile} + tmpfile=`mktemp` + while read; do + echo $REPLY >> ${tmpfile} + done + source=${tmpfile} +fi + +if [ "x${bootdev}" = x ] ; then + bootdev=c # default is boot as disk image fi cfgfile=`mktemp` @@ -101,7 +115,7 @@ EOF for mod in ${modules} do - echo "insmod ${mod}" >> ${cfgfile} + echo "insmod ${mod}" >> ${cfgfile} done cat <>${cfgfile} @@ -114,12 +128,18 @@ grub-mkrescue --output=${isofile} --override-directory=${builddir} \ /boot/grub/grub.cfg=${cfgfile} /boot/grub/testcase.cfg=${source} \ >/dev/null 2>&1 +hdafile=`mktemp` +cp ${isofile} ${hdafile} + +fdafile=`mktemp` +cp ${isofile} ${fdafile} + outfile=`mktemp` -qemu ${qemuopts} -nographic -serial stdio -cdrom ${isofile} -boot d | tr -d "\r" >${outfile} +qemu ${qemuopts} -nographic -serial stdio -hda ${hdafile} -fda ${fdafile} -cdrom ${isofile} -boot ${bootdev} | tr -d "\r" >${outfile} cat $outfile -rm -f ${tmpfile} ${outfile} ${cfgfile} ${isofile} +rm -f ${tmpfile} ${outfile} ${cfgfile} ${isofile} ${hdafile} ${fdafile} exit 0 From 4d362fde5883655a9a0d5a56068e16d0e81bf9be Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Tue, 12 Jan 2010 15:49:40 +0530 Subject: [PATCH 32/63] build only functional tests on make --- ChangeLog.unit-testing-framework | 2 +- conf/tests.rmk | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index 8641d09ee..aa4d4fd03 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -2,7 +2,7 @@ * tests/util/grub-shell.in: New --boot option. - * conf/tests.rmk: Build tests on make. + * conf/tests.rmk: Build functional tests on make. * Makefile.in (check): Use new variables. * include/grub/test.h: Remove EXPORT_* usage. diff --git a/conf/tests.rmk b/conf/tests.rmk index e894323ae..18b23ff5a 100644 --- a/conf/tests.rmk +++ b/conf/tests.rmk @@ -4,14 +4,14 @@ grub-shell: tests/util/grub-shell.in config.status ./config.status --file=$@:$< chmod +x $@ -bin_SCRIPTS += grub-shell +check_SCRIPTS += grub-shell CLEANFILES += grub-shell # For grub-shell-tester grub-shell-tester: tests/util/grub-shell-tester.in config.status ./config.status --file=$@:$< chmod +x $@ -bin_SCRIPTS += grub-shell-tester +check_SCRIPTS += grub-shell-tester CLEANFILES += grub-shell-tester pkglib_MODULES += functional_test.mod @@ -20,7 +20,7 @@ functional_test_mod_CFLAGS = $(COMMON_CFLAGS) functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) # Rules for unit tests -bin_UTILITIES += example_unit_test +check_UTILITIES += example_unit_test example_unit_test_SOURCES = tests/example_unit_test.c kern/list.c kern/misc.c tests/lib/test.c tests/lib/unit_test.c example_unit_test_CFLAGS = -Wno-format @@ -31,16 +31,20 @@ example_functional_test_mod_CFLAGS = -Wno-format $(COMMON_CFLAGS) example_functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) # Rules for scripted tests -bin_SCRIPTS += example_scripted_test +check_SCRIPTS += example_scripted_test example_scripted_test_SOURCES = tests/example_scripted_test.in -bin_SCRIPTS += example_grub_script_test +check_SCRIPTS += example_grub_script_test example_grub_script_test_SOURCES = tests/example_grub_script_test.in # List of tests to execute on "make check" - SCRIPTED_TESTS = example_scripted_test SCRIPTED_TESTS += example_grub_script_test UNIT_TESTS = example_unit_test FUNCTIONAL_TESTS = example_functional_test.mod + +# dependencies between tests and testing-tools +$(SCRIPTED_TESTS): grub-shell grub-shell-tester +$(FUNCTIONAL_TESTS): functional_test.mod + From 0b8a223cb157791e7dde5e0bf40f3327e3ac537d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 12 Jan 2010 13:36:44 +0100 Subject: [PATCH 33/63] 2010-01-12 Vladimir Serbinenko MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * util/grub-mkpasswd-pbkdf2.c (main): Use grub_util_init_nls. Reported by: Grégoire Sutre --- ChangeLog | 5 +++++ util/grub-mkpasswd-pbkdf2.c | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 768a65944..86deb525f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-12 Vladimir Serbinenko + + * util/grub-mkpasswd-pbkdf2.c (main): Use grub_util_init_nls. + Reported by: Grégoire Sutre + 2010-01-11 Robert Millan * util/misc.c (canonicalize_file_name): New function. diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c index 2f7c5efaa..b27a4e893 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -123,9 +123,8 @@ main (int argc, char *argv[]) int tty_changed; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); /* Check for options. */ while (1) From 10891398fd51394ace8504f83af419820e45070b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 12 Jan 2010 17:56:05 +0100 Subject: [PATCH 34/63] 2010-01-12 Vladimir Serbinenko * loader/i386/pc/multiboot2.c: Removed stalled file. --- ChangeLog | 4 ++ loader/i386/pc/multiboot2.c | 122 ------------------------------------ 2 files changed, 4 insertions(+), 122 deletions(-) delete mode 100644 loader/i386/pc/multiboot2.c diff --git a/ChangeLog b/ChangeLog index 86deb525f..e2fd92f68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-12 Vladimir Serbinenko + + * loader/i386/pc/multiboot2.c: Removed stalled file. + 2010-01-12 Vladimir Serbinenko * util/grub-mkpasswd-pbkdf2.c (main): Use grub_util_init_nls. diff --git a/loader/i386/pc/multiboot2.c b/loader/i386/pc/multiboot2.c deleted file mode 100644 index 005c8a823..000000000 --- a/loader/i386/pc/multiboot2.c +++ /dev/null @@ -1,122 +0,0 @@ -/* multiboot2.c - boot a multiboot 2 OS image. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -grub_err_t -grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, - grub_addr_t *addr __attribute__ ((unused)), - int *do_load) -{ - Elf32_Addr paddr = phdr->p_paddr; - - if (phdr->p_type != PT_LOAD) - { - *do_load = 0; - return 0; - } - *do_load = 1; - - if ((paddr < grub_os_area_addr) - || (paddr + phdr->p_memsz > grub_os_area_addr + grub_os_area_size)) - return grub_error(GRUB_ERR_OUT_OF_RANGE,"address 0x%x is out of range", - paddr); - - return GRUB_ERR_NONE; -} - -grub_err_t -grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, - grub_addr_t *addr __attribute__ ((unused)), - int *do_load) -{ - Elf64_Addr paddr = phdr->p_paddr; - - if (phdr->p_type != PT_LOAD) - { - *do_load = 0; - return 0; - } - *do_load = 1; - - if ((paddr < grub_os_area_addr) - || (paddr + phdr->p_memsz > grub_os_area_addr + grub_os_area_size)) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "address 0x%x is out of range", - paddr); - - return GRUB_ERR_NONE; -} - -grub_err_t -grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr) -{ - grub_addr_t modaddr; - - modaddr = (grub_addr_t) grub_memalign (MULTIBOOT2_MOD_ALIGN, size); - if (! modaddr) - return grub_errno; - - *addr = modaddr; - return GRUB_ERR_NONE; -} - -grub_err_t -grub_mb2_arch_module_free (grub_addr_t addr, - grub_size_t size __attribute__ ((unused))) -{ - grub_free((void *) addr); - return GRUB_ERR_NONE; -} - -void -grub_mb2_arch_boot (grub_addr_t entry, void *tags) -{ - grub_multiboot2_real_boot (entry, tags); -} - -void -grub_mb2_arch_unload (struct multiboot2_tag_header *tags) -{ - struct multiboot2_tag_header *tag; - - /* Free all module memory in the tag list. */ - for_each_tag (tag, tags) - { - if (tag->key == MULTIBOOT2_TAG_MODULE) - { - struct multiboot2_tag_module *module = - (struct multiboot2_tag_module *) tag; - grub_free((void *) module->addr); - } - } -} - -grub_err_t -grub_mb2_tags_arch_create (void) -{ - /* XXX Create boot device et al. */ - return GRUB_ERR_NONE; -} From b16ff4662ea7a3d3187499c435c3b45a85af7563 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 12 Jan 2010 19:47:02 +0100 Subject: [PATCH 35/63] Small cleanup --- loader/i386/multiboot.c | 26 -------------------------- loader/i386/multiboot_elfxx.c | 2 +- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c index 2a69327b4..5dc304117 100644 --- a/loader/i386/multiboot.c +++ b/loader/i386/multiboot.c @@ -232,32 +232,6 @@ grub_multiboot (int argc, char *argv[]) else if (grub_multiboot_load_elf (file, buffer) != GRUB_ERR_NONE) goto fail; - if (header->flags & MULTIBOOT_VIDEO_MODE) - { - switch (header->mode_type) - { - case 1: - grub_env_set ("gfxpayload", "text"); - break; - - case 0: - { - char buf[sizeof ("XXXXXXXXXXxXXXXXXXXXXxXXXXXXXXXX,XXXXXXXXXXxXXXXXXXXXX,auto")]; - if (header->depth && header->width && header->height) - grub_sprintf (buf, "%dx%dx%d,%dx%d,auto", header->width, - header->height, header->depth, header->width, - header->height); - else if (header->width && header->height) - grub_sprintf (buf, "%dx%d,auto", header->width, header->height); - else - grub_sprintf (buf, "auto"); - - grub_env_set ("gfxpayload", buf); - break; - } - } - } - grub_multiboot_set_bootdev (); grub_loader_set (grub_multiboot_boot, grub_multiboot_unload, 0); diff --git a/loader/i386/multiboot_elfxx.c b/loader/i386/multiboot_elfxx.c index 8f6367432..2e35183a4 100644 --- a/loader/i386/multiboot_elfxx.c +++ b/loader/i386/multiboot_elfxx.c @@ -104,7 +104,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer) alloc_mbi = grub_multiboot_get_mbi_size (); grub_multiboot_payload_orig - = grub_relocator32_alloc (grub_multiboot_pure_size + alloc_mbi); + = grub_relocator32_alloc (grub_multiboot_pure_size + alloc_mbi + 65536); if (!grub_multiboot_payload_orig) return grub_errno; From 58655a160bd56ab3ca8ed9944639260eff21bfa8 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Wed, 13 Jan 2010 19:10:57 +0000 Subject: [PATCH 36/63] 2010-01-13 Robert Millan * util/mkisofs/rock.c (generate_rock_ridge_attributes): Fix a typo. --- ChangeLog | 4 ++++ util/mkisofs/rock.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e2fd92f68..788328502 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-13 Robert Millan + + * util/mkisofs/rock.c (generate_rock_ridge_attributes): Fix a typo. + 2010-01-12 Vladimir Serbinenko * loader/i386/pc/multiboot2.c: Removed stalled file. diff --git a/util/mkisofs/rock.c b/util/mkisofs/rock.c index a4cc27fa9..f18b0bd83 100644 --- a/util/mkisofs/rock.c +++ b/util/mkisofs/rock.c @@ -5,7 +5,7 @@ Copyright 1993 Yggdrasil Computing, Incorporated - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009,2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -306,7 +306,7 @@ int deep_opt; * the symbolic link won't fit into one SL System Use Field * print an error message and continue with splited one */ - fprintf(stderr, _("symbolic link ``%s'' to long for one SL System Use Field, splitting"), cpnt); + fprintf (stderr, _("symbolic link ``%s'' too long for one SL System Use Field, splitting"), cpnt); } if(MAYBE_ADD_CE_ENTRY(SL_SIZE + sl_bytes)) add_CE_entry(); } From c1f28820101867513d188fbe7354d5d35b0f08cb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 13 Jan 2010 20:43:48 +0100 Subject: [PATCH 37/63] 2010-01-13 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_putchar): Handle '\r'. (grub_ofconsole_getwh): Split to ... (grub_ofconsole_getwh): ... this. (grub_ofconsole_dimensions): ...and this. (grub_ofconsole_init_output): Call grub_ofconsole_dimensions. --- ChangeLog | 8 ++++++++ term/ieee1275/ofconsole.c | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 788328502..95eebe4b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-01-13 Vladimir Serbinenko + + * term/ieee1275/ofconsole.c (grub_ofconsole_putchar): Handle '\r'. + (grub_ofconsole_getwh): Split to ... + (grub_ofconsole_getwh): ... this. + (grub_ofconsole_dimensions): ...and this. + (grub_ofconsole_init_output): Call grub_ofconsole_dimensions. + 2010-01-13 Robert Millan * util/mkisofs/rock.c (generate_rock_ridge_attributes): Fix a typo. diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index 3977c6286..a9834e23e 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -83,12 +83,17 @@ grub_ofconsole_putchar (grub_uint32_t c) grub_curr_y++; grub_curr_x = 0; } + else if (c == '\r') + { + grub_curr_x = 0; + } else { grub_curr_x++; - if (grub_curr_x > grub_ofconsole_width) + if (grub_curr_x >= grub_ofconsole_width) { grub_ofconsole_putchar ('\n'); + grub_ofconsole_putchar ('\r'); grub_curr_x++; } } @@ -234,16 +239,13 @@ grub_ofconsole_getxy (void) return ((grub_curr_x - 1) << 8) | grub_curr_y; } -static grub_uint16_t -grub_ofconsole_getwh (void) +static void +grub_ofconsole_dimensions (void) { grub_ieee1275_ihandle_t options; char *val; grub_ssize_t lval; - if (grub_ofconsole_width && grub_ofconsole_height) - return (grub_ofconsole_width << 8) | grub_ofconsole_height; - if (! grub_ieee1275_finddevice ("/options", &options) && options != (grub_ieee1275_ihandle_t) -1) { @@ -280,7 +282,11 @@ grub_ofconsole_getwh (void) grub_ofconsole_width = 80; if (! grub_ofconsole_height) grub_ofconsole_height = 24; +} +static grub_uint16_t +grub_ofconsole_getwh (void) +{ return (grub_ofconsole_width << 8) | grub_ofconsole_height; } @@ -379,6 +385,8 @@ grub_ofconsole_init_output (void) grub_ofconsole_setcolorstate (GRUB_TERM_COLOR_NORMAL); } + grub_ofconsole_dimensions (); + return 0; } From 17383dfe962e366b2c77f70506a4438602619122 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 13 Jan 2010 22:53:12 +0100 Subject: [PATCH 38/63] 2010-01-13 Vladimir Serbinenko * kern/efi/init.c (grub_efi_fini): Don't call grub_efi_mm_fini as it would result in module crash. --- ChangeLog | 5 +++++ kern/efi/init.c | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 95eebe4b2..f86ff3ddd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-13 Vladimir Serbinenko + + * kern/efi/init.c (grub_efi_fini): Don't call grub_efi_mm_fini as + it would result in module crash. + 2010-01-13 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_putchar): Handle '\r'. diff --git a/kern/efi/init.c b/kern/efi/init.c index f9ba03852..8862eb2f9 100644 --- a/kern/efi/init.c +++ b/kern/efi/init.c @@ -82,6 +82,5 @@ void grub_efi_fini (void) { grub_efidisk_fini (); - grub_efi_mm_fini (); grub_console_fini (); } From 0b8891c276ae3b1f3d93ff881a13a405d6471269 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Thu, 14 Jan 2010 17:17:51 +0530 Subject: [PATCH 39/63] removed unnecessary grub_test_* wrappers --- ChangeLog.unit-testing-framework | 20 +++++++++++++++ include/grub/test.h | 8 ------ tests/lib/functional_test.c | 37 --------------------------- tests/lib/test.c | 44 ++++++++++++++++---------------- tests/lib/unit_test.c | 43 +++++-------------------------- 5 files changed, 48 insertions(+), 104 deletions(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index aa4d4fd03..6643e9989 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -1,3 +1,23 @@ +2010-01-14 BVK Chaitanya + + Removed unnecessary grub_test_* wrappers. + + * tests/lib/unit_test.c (grub_test_malloc): Removed. + (grub_test_vsprintf): Removed. + (grub_test_strdup): Removed. + (grub_test_printf): Removed. + (grub_test_free): Replaced with.... + (grub_free): ...new wrapper. + * tests/lib/functional_test.c (grub_test_malloc): Removed. + (grub_test_free): Removed. + (grub_test_vsprintf): Removed. + (grub_test_strdup): Removed. + (grub_test_printf): Removed. + * tests/lib/test.c: Replaced + grub_test_{malloc,free,strdup,printf,vsprintf} methods with + grub_{malloc,free,strdup,printf,vsprintf} methods. + * include/grub/test.h: Removed prototypes for the above. + 2010-01-12 BVK Chaitanya * tests/util/grub-shell.in: New --boot option. diff --git a/include/grub/test.h b/include/grub/test.h index bd5b7d806..544e1c817 100644 --- a/include/grub/test.h +++ b/include/grub/test.h @@ -64,12 +64,4 @@ void grub_test_nonzero (int cond, const char *file, grub_test_unregister (name); \ } -/* Functions that are defined differently for unit and functional tests. */ -void *grub_test_malloc (grub_size_t size); -void grub_test_free (void *ptr); -char *grub_test_strdup (const char *str); -int grub_test_vsprintf (char *str, const char *fmt, va_list args); -int grub_test_printf (const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); - #endif /* ! GRUB_TEST_HEADER */ diff --git a/tests/lib/functional_test.c b/tests/lib/functional_test.c index 2e03dabc4..8ad034503 100644 --- a/tests/lib/functional_test.c +++ b/tests/lib/functional_test.c @@ -3,43 +3,6 @@ #include #include -void * -grub_test_malloc (grub_size_t size) -{ - return grub_malloc (size); -} - -void -grub_test_free (void *ptr) -{ - grub_free (ptr); -} - -int -grub_test_vsprintf (char *str, const char *fmt, va_list args) -{ - return grub_vsprintf (str, fmt, args); -} - -char * -grub_test_strdup (const char *str) -{ - return grub_strdup (str); -} - -int -grub_test_printf (const char *fmt, ...) -{ - int r; - va_list ap; - - va_start (ap, fmt); - r = grub_vprintf (fmt, ap); - va_end (ap); - - return r; -} - static grub_err_t grub_functional_test (struct grub_extcmd *cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), diff --git a/tests/lib/test.c b/tests/lib/test.c index 562c2f6e4..aba2f4415 100644 --- a/tests/lib/test.c +++ b/tests/lib/test.c @@ -1,3 +1,4 @@ +#include #include #include @@ -31,16 +32,16 @@ add_failure (const char *file, char buf[1024]; grub_test_failure_t failure; - failure = (grub_test_failure_t) grub_test_malloc (sizeof (*failure)); + failure = (grub_test_failure_t) grub_malloc (sizeof (*failure)); if (!failure) return; - grub_test_vsprintf (buf, fmt, args); + grub_vsprintf (buf, fmt, args); - failure->file = grub_test_strdup (file ? : ""); - failure->funp = grub_test_strdup (funp ? : ""); + failure->file = grub_strdup (file ? : ""); + failure->funp = grub_strdup (funp ? : ""); failure->line = line; - failure->message = grub_test_strdup (buf); + failure->message = grub_strdup (buf); grub_list_push (GRUB_AS_LIST_P (&failure_list), GRUB_AS_LIST (failure)); } @@ -53,15 +54,15 @@ free_failures (void) while ((item = grub_list_pop (GRUB_AS_LIST_P (&failure_list))) != 0) { if (item->message) - grub_test_free (item->message); + grub_free (item->message); if (item->funp) - grub_test_free (item->funp); + grub_free (item->funp); if (item->file) - grub_test_free (item->file); + grub_free (item->file); - grub_test_free (item); + grub_free (item); } failure_list = 0; } @@ -86,11 +87,11 @@ grub_test_register (const char *name, void (*test_main) (void)) { grub_test_t test; - test = (grub_test_t) grub_test_malloc (sizeof (*test)); + test = (grub_test_t) grub_malloc (sizeof (*test)); if (!test) return; - test->name = grub_test_strdup (name); + test->name = grub_strdup (name); test->main = test_main; grub_list_push (GRUB_AS_LIST_P (&grub_test_list), GRUB_AS_LIST (test)); @@ -106,13 +107,12 @@ grub_test_unregister (const char *name) if (test) { - grub_list_remove (GRUB_AS_LIST_P (&grub_test_list), - GRUB_AS_LIST (test)); + grub_list_remove (GRUB_AS_LIST_P (&grub_test_list), GRUB_AS_LIST (test)); if (test->name) - grub_test_free (test->name); + grub_free (test->name); - grub_test_free (test); + grub_free (test); } } @@ -124,22 +124,22 @@ grub_test_run (grub_test_t test) { grub_test_failure_t failure = (grub_test_failure_t) item; - grub_test_printf (" %s:%s:%u: %s\n", - (failure->file ? : ""), - (failure->funp ? : ""), - failure->line, (failure->message ? : "")); + grub_printf (" %s:%s:%u: %s\n", + (failure->file ? : ""), + (failure->funp ? : ""), + failure->line, (failure->message ? : "")); return 0; } test->main (); - grub_test_printf ("%s:\n", test->name); + grub_printf ("%s:\n", test->name); grub_list_iterate (GRUB_AS_LIST (failure_list), (grub_list_hook_t) print_failure); if (!failure_list) - grub_test_printf ("%s: PASS\n", test->name); + grub_printf ("%s: PASS\n", test->name); else - grub_test_printf ("%s: FAIL\n", test->name); + grub_printf ("%s: FAIL\n", test->name); free_failures (); return GRUB_ERR_NONE; diff --git a/tests/lib/unit_test.c b/tests/lib/unit_test.c index 59931898a..2ca011433 100644 --- a/tests/lib/unit_test.c +++ b/tests/lib/unit_test.c @@ -7,43 +7,6 @@ #include #include -void * -grub_test_malloc (grub_size_t size) -{ - return malloc (size); -} - -void -grub_test_free (void *ptr) -{ - free (ptr); -} - -int -grub_test_vsprintf (char *str, const char *fmt, va_list args) -{ - return vsprintf (str, fmt, args); -} - -char * -grub_test_strdup (const char *str) -{ - return strdup (str); -} - -int -grub_test_printf (const char *fmt, ...) -{ - int r; - va_list ap; - - va_start (ap, fmt); - r = vprintf (fmt, ap); - va_end (ap); - - return r; -} - int main (int argc __attribute__ ((unused)), char *argv[] __attribute__ ((unused))) @@ -70,6 +33,12 @@ main (int argc __attribute__ ((unused)), /* Other misc. functions necessary for successful linking. */ +void +grub_free (void *ptr) +{ + free (ptr); +} + char * grub_env_get (const char *name __attribute__ ((unused))) { From 2285d4642a6a6177d6c9d9daa2658b347ba183c2 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Thu, 14 Jan 2010 18:39:12 +0530 Subject: [PATCH 40/63] use qemu-system-i386 instead of qemu --- ChangeLog.unit-testing-framework | 4 ++++ tests/util/grub-shell.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index 6643e9989..ba5ba8cc5 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -1,5 +1,9 @@ 2010-01-14 BVK Chaitanya + Use qemu-system-i386 instead of qemu. + + * tests/util/grub-shell.in (outfile): Use qemu-system-i386. + Removed unnecessary grub_test_* wrappers. * tests/lib/unit_test.c (grub_test_malloc): Removed. diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in index b103872ba..e6fef8313 100644 --- a/tests/util/grub-shell.in +++ b/tests/util/grub-shell.in @@ -135,7 +135,7 @@ fdafile=`mktemp` cp ${isofile} ${fdafile} outfile=`mktemp` -qemu ${qemuopts} -nographic -serial stdio -hda ${hdafile} -fda ${fdafile} -cdrom ${isofile} -boot ${bootdev} | tr -d "\r" >${outfile} +qemu-system-i386 ${qemuopts} -nographic -serial stdio -hda ${hdafile} -fda ${fdafile} -cdrom ${isofile} -boot ${bootdev} | tr -d "\r" >${outfile} cat $outfile From 6d1e76899b216af8e83516a93231bafc9570edf7 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 14 Jan 2010 14:06:36 +0000 Subject: [PATCH 41/63] fix changelog dates --- ChangeLog.savedefault | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 722769776..d68d75eab 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,18 +1,18 @@ -2010-10-05 Jordan Uggla -2010-10-05 Colin Watson +2010-01-05 Jordan Uggla +2010-01-05 Colin Watson * util/grub-reboot.in: Make sure prev_saved_entry always gets a non-empty value. -2010-10-05 Jordan Uggla -2010-10-05 Colin Watson +2010-01-05 Jordan Uggla +2010-01-05 Colin Watson * util/grub.d/00_header.in: Define a "savedefault" function for use in menu entries. * util/grub-mkconfig_lib.in (save_default_entry): Use it. -2010-10-05 Jordan Uggla -2010-10-05 Colin Watson +2010-01-05 Jordan Uggla +2010-01-05 Colin Watson * util/grub-mkconfig_lib.in (save_default_entry): Only set saved_entry if boot_once is unset. From 0a46429a55ee7701dfb450ac648b1d1a07e6287c Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 14 Jan 2010 21:08:31 +0000 Subject: [PATCH 42/63] 2010-01-14 Robert Millan * include/grub/i386/loader.h (grub_linux16_boot): Renamed to ... (grub_linux16_real_boot): ... this. * kern/i386/loader.S: Likewise. * loader/i386/pc/linux.c: Include `' and `'. (grub_linux16_boot): New function. Switches to text mode and calls grub_linux16_real_boot(). * loader/i386/bsd.c: Include `'. (grub_freebsd_boot, grub_openbsd_boot, grub_netbsd_boot): Switch to text mode before calling grub_unix_real_boot(). * loader/i386/multiboot.c: Include `'. (grub_multiboot_boot): Switch to text mode before calling grub_relocator32_boot(). * loader/i386/pc/chainloader.c: Include `'. (grub_chainloader_boot): Switch to text mode before calling grub_chainloader_real_boot(). --- ChangeLog | 21 +++++++++++++++++++++ include/grub/i386/loader.h | 4 ++-- kern/i386/loader.S | 2 +- loader/i386/bsd.c | 10 ++++++++-- loader/i386/multiboot.c | 5 ++++- loader/i386/pc/chainloader.c | 4 +++- loader/i386/pc/linux.c | 14 +++++++++++++- 7 files changed, 52 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0fa70ecf6..652cc145a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2010-01-14 Robert Millan + + * include/grub/i386/loader.h (grub_linux16_boot): Renamed to ... + (grub_linux16_real_boot): ... this. + * kern/i386/loader.S: Likewise. + * loader/i386/pc/linux.c: Include `' and `'. + (grub_linux16_boot): New function. Switches to text mode and calls + grub_linux16_real_boot(). + + * loader/i386/bsd.c: Include `'. + (grub_freebsd_boot, grub_openbsd_boot, grub_netbsd_boot): Switch to + text mode before calling grub_unix_real_boot(). + + * loader/i386/multiboot.c: Include `'. + (grub_multiboot_boot): Switch to text mode before calling + grub_relocator32_boot(). + + * loader/i386/pc/chainloader.c: Include `'. + (grub_chainloader_boot): Switch to text mode before calling + grub_chainloader_real_boot(). + 2010-01-05 Jordan Uggla 2010-01-05 Colin Watson diff --git a/include/grub/i386/loader.h b/include/grub/i386/loader.h index 0df5f757f..05954b6db 100644 --- a/include/grub/i386/loader.h +++ b/include/grub/i386/loader.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ extern grub_uint32_t EXPORT_VAR(grub_linux_prot_size); extern char *EXPORT_VAR(grub_linux_tmp_addr); extern char *EXPORT_VAR(grub_linux_real_addr); extern grub_int32_t EXPORT_VAR(grub_linux_is_bzimage); -grub_err_t EXPORT_FUNC(grub_linux16_boot) (void); +grub_err_t EXPORT_FUNC(grub_linux16_real_boot) (void); #endif #endif /* ! GRUB_LOADER_CPU_HEADER */ diff --git a/kern/i386/loader.S b/kern/i386/loader.S index 3e9c71327..ed57c43ca 100644 --- a/kern/i386/loader.S +++ b/kern/i386/loader.S @@ -59,7 +59,7 @@ VARIABLE(grub_linux_real_addr) VARIABLE(grub_linux_is_bzimage) .long 0 -FUNCTION(grub_linux16_boot) +FUNCTION(grub_linux16_real_boot) /* Must be done before zImage copy. */ call EXT_C(grub_dl_unload_all) diff --git a/loader/i386/bsd.c b/loader/i386/bsd.c index 0785a3fc1..49be758c6 100644 --- a/loader/i386/bsd.c +++ b/loader/i386/bsd.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008, 2009 Free Software Foundation, Inc. + * Copyright (C) 2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,7 +35,7 @@ #include #include #include - +#include #ifdef GRUB_MACHINE_PCBIOS #include #endif @@ -509,6 +509,8 @@ grub_freebsd_boot (void) bi.bi_kernend = kern_end; + grub_video_set_mode ("text", NULL); + if (is_64bit) { grub_uint32_t *gdt; @@ -617,6 +619,8 @@ grub_openbsd_boot (void) pa->ba_type = OPENBSD_BOOTARG_END; pa++; + grub_video_set_mode ("text", NULL); + grub_unix_real_boot (entry, bootflags, openbsd_root, OPENBSD_BOOTARG_APIVER, 0, (grub_uint32_t) (grub_mmap_get_upper () >> 10), (grub_uint32_t) (grub_mmap_get_lower () >> 10), @@ -713,6 +717,8 @@ grub_netbsd_boot (void) bootinfo->bi_data[0] = mmap; } + grub_video_set_mode ("text", NULL); + grub_unix_real_boot (entry, bootflags, 0, bootinfo, 0, (grub_uint32_t) (grub_mmap_get_upper () >> 10), (grub_uint32_t) (grub_mmap_get_lower () >> 10)); diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c index 5dc304117..4360e8a2c 100644 --- a/loader/i386/multiboot.c +++ b/loader/i386/multiboot.c @@ -1,7 +1,7 @@ /* multiboot.c - boot a multiboot OS image. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,6 +46,7 @@ #include #include #include +#include extern grub_dl_t my_mod; static grub_size_t code_size, alloc_mbi; @@ -89,6 +90,8 @@ grub_multiboot_boot (void) if (err) return err; + grub_video_set_mode ("text", NULL); + grub_relocator32_boot (grub_multiboot_payload_orig, grub_multiboot_payload_dest, state); diff --git a/loader/i386/pc/chainloader.c b/loader/i386/pc/chainloader.c index 81cfddac1..e28a4e7f9 100644 --- a/loader/i386/pc/chainloader.c +++ b/loader/i386/pc/chainloader.c @@ -1,7 +1,7 @@ /* chainloader.c - boot another boot loader */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2004,2007,2009 Free Software Foundation, Inc. + * Copyright (C) 2002,2004,2007,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ #include #include #include +#include static grub_dl_t my_mod; static int boot_drive; @@ -41,6 +42,7 @@ static void *boot_part_addr; static grub_err_t grub_chainloader_boot (void) { + grub_video_set_mode ("text", NULL); grub_chainloader_real_boot (boot_drive, boot_part_addr); /* Never reach here. */ diff --git a/loader/i386/pc/linux.c b/loader/i386/pc/linux.c index 24bb39555..96973adb9 100644 --- a/loader/i386/pc/linux.c +++ b/loader/i386/pc/linux.c @@ -1,7 +1,7 @@ /* linux.c - boot Linux zImage or bzImage */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,6 +31,8 @@ #include #include #include +#include +#include #define GRUB_LINUX_CL_OFFSET 0x9000 #define GRUB_LINUX_CL_END_OFFSET 0x90FF @@ -48,6 +50,16 @@ grub_linux_unload (void) return GRUB_ERR_NONE; } +static grub_err_t +grub_linux16_boot (void) +{ + grub_video_set_mode ("text", NULL); + grub_linux16_real_boot (); + + /* Not reached. */ + return GRUB_ERR_NONE; +} + static grub_err_t grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) From ba2f6848e06aa654bf8d6df02d5737aca73035b9 Mon Sep 17 00:00:00 2001 From: carles Date: Thu, 14 Jan 2010 22:31:06 +0000 Subject: [PATCH 43/63] 2010-01-14 Carles Pina i Estany * gettext/gettext.c (grub_gettext_translate): Push and pop grub_errno. (grub_gettext_delete_list): Change comment style. * kern/err.c (grub_error): Gettextizze. (grub_fatal): Gettextizze. --- ChangeLog | 8 ++++++++ gettext/gettext.c | 17 ++++++++++++++--- kern/err.c | 4 ++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 652cc145a..17083d1b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-01-14 Carles Pina i Estany + + * gettext/gettext.c (grub_gettext_translate): Push and pop + grub_errno. + (grub_gettext_delete_list): Change comment style. + * kern/err.c (grub_error): Gettextizze. + (grub_fatal): Gettextizze. + 2010-01-14 Robert Millan * include/grub/i386/loader.h (grub_linux16_boot): Renamed to ... diff --git a/gettext/gettext.c b/gettext/gettext.c index 6fa6271f2..83497b7f6 100644 --- a/gettext/gettext.c +++ b/gettext/gettext.c @@ -148,14 +148,24 @@ grub_gettext_translate (const char *orig) struct grub_gettext_msg *cur; + /* Make sure we can use grub_gettext_translate for error messages. Push + active error message to error stack and reset error message. */ + grub_error_push (); + cur = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_gettext_msg_list), orig); if (cur) - return cur->translated; + { + grub_error_pop (); + return cur->translated; + } if (fd_mo == 0) - return orig; + { + grub_error_pop (); + return orig; + } min = 0; max = grub_gettext_max; @@ -205,6 +215,7 @@ grub_gettext_translate (const char *orig) grub_errno = GRUB_ERR_NONE; } + grub_error_pop (); return ret; } @@ -308,7 +319,7 @@ grub_gettext_delete_list (void) char *original = (char *) ((struct grub_gettext_msg *) item)->name; grub_free (original); - // Don't delete the translated message because could be in use. + /* Don't delete the translated message because could be in use. */ } } diff --git a/kern/err.c b/kern/err.c index 02d7d879f..1a881db25 100644 --- a/kern/err.c +++ b/kern/err.c @@ -45,7 +45,7 @@ grub_error (grub_err_t n, const char *fmt, ...) grub_errno = n; va_start (ap, fmt); - grub_vsprintf (grub_errmsg, fmt, ap); + grub_vsprintf (grub_errmsg, _(fmt), ap); va_end (ap); return n; @@ -57,7 +57,7 @@ grub_fatal (const char *fmt, ...) va_list ap; va_start (ap, fmt); - grub_vprintf (fmt, ap); + grub_vprintf (_(fmt), ap); va_end (ap); grub_abort (); From c586fbb2064081efec63333dee9d73999e2c6f42 Mon Sep 17 00:00:00 2001 From: carles Date: Thu, 14 Jan 2010 23:04:49 +0000 Subject: [PATCH 44/63] 2001-01-14 Carles Pina i Estany * loader/i386/pc/chainloader.c: Include `'. --- ChangeLog | 4 ++++ loader/i386/pc/chainloader.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 17083d1b1..fe54d5c3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2001-01-14 Carles Pina i Estany + + * loader/i386/pc/chainloader.c: Include `'. + 2010-01-14 Carles Pina i Estany * gettext/gettext.c (grub_gettext_translate): Push and pop diff --git a/loader/i386/pc/chainloader.c b/loader/i386/pc/chainloader.c index e28a4e7f9..1d6de1de7 100644 --- a/loader/i386/pc/chainloader.c +++ b/loader/i386/pc/chainloader.c @@ -34,6 +34,7 @@ #include #include #include +#include static grub_dl_t my_mod; static int boot_drive; From cca15b52c11e5f469f2fce8ce61ff1ded3b20137 Mon Sep 17 00:00:00 2001 From: carles Date: Thu, 14 Jan 2010 23:07:44 +0000 Subject: [PATCH 45/63] 2010-01-14 Carles Pina i Estany * normal/cmdline.c (print_completion): Gettextizze. --- ChangeLog | 4 ++++ normal/cmdline.c | 19 +++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe54d5c3a..0478d6cb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-14 Carles Pina i Estany + + * normal/cmdline.c (print_completion): Gettextizze. + 2001-01-14 Carles Pina i Estany * loader/i386/pc/chainloader.c: Include `'. diff --git a/normal/cmdline.c b/normal/cmdline.c index 429c84be7..bcffffeab 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -166,31 +166,30 @@ print_completion (const char *item, grub_completion_type_t type, int count) if (count == 0) { /* If this is the first time, print a label. */ - const char *what; - + + grub_puts (""); switch (type) { case GRUB_COMPLETION_TYPE_COMMAND: - what = "commands"; + grub_puts_ (N_("Possible commands are:")); break; case GRUB_COMPLETION_TYPE_DEVICE: - what = "devices"; + grub_puts_ (N_("Possible devices are:")); break; case GRUB_COMPLETION_TYPE_FILE: - what = "files"; + grub_puts_ (N_("Possible files are:")); break; case GRUB_COMPLETION_TYPE_PARTITION: - what = "partitions"; + grub_puts_ (N_("Possible partitions are:")); break; case GRUB_COMPLETION_TYPE_ARGUMENT: - what = "arguments"; + grub_puts_ (N_("Possible arguments are:")); break; default: - what = "things"; + grub_puts_ (N_("Possible things are:")); break; } - - grub_printf ("\nPossible %s are:\n", what); + grub_puts (""); } if (type == GRUB_COMPLETION_TYPE_PARTITION) From 5c71db1b9ba1aee67cdee92cb2b7a71c9aadbf46 Mon Sep 17 00:00:00 2001 From: carles Date: Thu, 14 Jan 2010 23:20:13 +0000 Subject: [PATCH 46/63] 2010-01-14 Carles Pina i Estany * util/grub.d/30_os-prober.in: Use `set var=val' rather than plain `var=val'. --- ChangeLog | 5 +++++ util/grub.d/30_os-prober.in | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0478d6cb1..e2d8a81f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-14 Carles Pina i Estany + + * util/grub.d/30_os-prober.in: Use `set var=val' rather than plain + `var=val'. + 2010-01-14 Carles Pina i Estany * normal/cmdline.c (print_completion): Gettextizze. diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in index da6eea6b6..edef37e66 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -45,10 +45,10 @@ EOF prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" cat << EOF insmod ${GRUB_VIDEO_BACKEND} - do_resume=0 + set do_resume=0 if [ /var/vm/sleepimage -nt10 / ]; then if xnu_resume /var/vm/sleepimage; then - do_resume=1 + set do_resume=1 fi fi if [ \$do_resume == 0 ]; then From 0d90e8a6fb31c9d6b9200b3a34fa3b2ffa38214d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 15 Jan 2010 16:11:18 +0100 Subject: [PATCH 47/63] 2010-01-15 Vladimir Serbinenko Video driver ids. * include/grub/video.h (grub_video_driver_id): New type. (grub_video_adapter): New member 'id'. All users updated. (grub_video_get_driver_id): New proto. * video/video.c (grub_video_get_driver_id): New function. --- ChangeLog | 9 +++++++++ include/grub/video.h | 12 ++++++++++++ video/efi_gop.c | 1 + video/efi_uga.c | 1 + video/i386/pc/vbe.c | 1 + video/video.c | 8 ++++++++ 6 files changed, 32 insertions(+) diff --git a/ChangeLog b/ChangeLog index e2d8a81f5..dc123888b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-01-15 Vladimir Serbinenko + + Video driver ids. + + * include/grub/video.h (grub_video_driver_id): New type. + (grub_video_adapter): New member 'id'. All users updated. + (grub_video_get_driver_id): New proto. + * video/video.c (grub_video_get_driver_id): New function. + 2010-01-14 Carles Pina i Estany * util/grub.d/30_os-prober.in: Use `set var=val' rather than plain diff --git a/include/grub/video.h b/include/grub/video.h index 4145db465..437c98eb9 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -159,10 +159,19 @@ struct grub_video_palette_data grub_uint8_t a; /* Reserved bits value (0-255). */ }; +typedef enum grub_video_driver_id + { + GRUB_VIDEO_DRIVER_NONE, + GRUB_VIDEO_DRIVER_VBE, + GRUB_VIDEO_DRIVER_EFI_UGA, + GRUB_VIDEO_DRIVER_EFI_GOP + } grub_video_driver_id_t; + struct grub_video_adapter { /* The video adapter name. */ const char *name; + grub_video_driver_id_t id; /* Initialize the video adapter. */ grub_err_t (*init) (void); @@ -310,4 +319,7 @@ grub_err_t grub_video_set_mode (const char *modestring, int NESTED_FUNC_ATTR (*hook) (grub_video_adapter_t p, struct grub_video_mode_info *mode_info)); +grub_video_driver_id_t +grub_video_get_driver_id (void); + #endif /* ! GRUB_VIDEO_HEADER */ diff --git a/video/efi_gop.c b/video/efi_gop.c index 30863c1ed..13ef0ddae 100644 --- a/video/efi_gop.c +++ b/video/efi_gop.c @@ -353,6 +353,7 @@ grub_video_gop_get_info_and_fini (struct grub_video_mode_info *mode_info, static struct grub_video_adapter grub_video_gop_adapter = { .name = "EFI GOP driver", + .id = GRUB_VIDEO_DRIVER_EFI_GOP, .init = grub_video_gop_init, .fini = grub_video_gop_fini, diff --git a/video/efi_uga.c b/video/efi_uga.c index 12ca35cde..7ef7594cc 100644 --- a/video/efi_uga.c +++ b/video/efi_uga.c @@ -300,6 +300,7 @@ grub_video_uga_get_info_and_fini (struct grub_video_mode_info *mode_info, static struct grub_video_adapter grub_video_uga_adapter = { .name = "EFI UGA driver", + .id = GRUB_VIDEO_DRIVER_EFI_UGA, .init = grub_video_uga_init, .fini = grub_video_uga_fini, diff --git a/video/i386/pc/vbe.c b/video/i386/pc/vbe.c index 17d9b3282..918bab0b0 100644 --- a/video/i386/pc/vbe.c +++ b/video/i386/pc/vbe.c @@ -557,6 +557,7 @@ grub_video_vbe_get_info_and_fini (struct grub_video_mode_info *mode_info, static struct grub_video_adapter grub_video_vbe_adapter = { .name = "VESA BIOS Extension Video Driver", + .id = GRUB_VIDEO_DRIVER_VBE, .init = grub_video_vbe_init, .fini = grub_video_vbe_fini, diff --git a/video/video.c b/video/video.c index 682bebcbf..e678c2982 100644 --- a/video/video.c +++ b/video/video.c @@ -93,6 +93,14 @@ grub_video_get_info (struct grub_video_mode_info *mode_info) return grub_video_adapter_active->get_info (mode_info); } +grub_video_driver_id_t +grub_video_get_driver_id (void) +{ + if (! grub_video_adapter_active) + return GRUB_VIDEO_DRIVER_NONE; + return grub_video_adapter_active->id; +} + /* Get information about active video mode. */ grub_err_t grub_video_get_info_and_fini (struct grub_video_mode_info *mode_info, From 884ade56545bc515a13307e24a9694b0ef357a8a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 15 Jan 2010 16:30:57 +0100 Subject: [PATCH 48/63] 2010-01-15 Vladimir Serbinenko Video multiboot support. * include/grub/multiboot.h (grub_multiboot_set_accepts_video): New prototype. * include/multiboot.h: Resynced with multiboot specification. * include/multiboot2.h: Likewise. * loader/i386/multiboot.c (UNSUPPORTED_FLAGS): Support video flags. (grub_multiboot): Parse MULTIBOOT_VIDEO_MODE fields. * loader/i386/multiboot_mbi.c (DEFAULT_VIDEO_MODE): New constant. (HAS_VGA_TEXT): Likewise. (accepts_video): New variable. (grub_multiboot_set_accepts_video): New function. (grub_multiboot_get_mbi_size): Account for video structures. (set_video_mode): New function. (retrieve_video_parameters): Likewise. (grub_multiboot_make_mbi): Fill video fields. --- ChangeLog | 19 ++++++ include/grub/multiboot.h | 2 + include/multiboot.h | 38 ++++++++++- include/multiboot2.h | 38 ++++++++++- loader/i386/multiboot.c | 34 ++++++++-- loader/i386/multiboot_mbi.c | 129 +++++++++++++++++++++++++++++++++++- 6 files changed, 252 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index dc123888b..8d3245ea3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2010-01-15 Vladimir Serbinenko + + Video multiboot support. + + * include/grub/multiboot.h (grub_multiboot_set_accepts_video): + New prototype. + * include/multiboot.h: Resynced with multiboot specification. + * include/multiboot2.h: Likewise. + * loader/i386/multiboot.c (UNSUPPORTED_FLAGS): Support video flags. + (grub_multiboot): Parse MULTIBOOT_VIDEO_MODE fields. + * loader/i386/multiboot_mbi.c (DEFAULT_VIDEO_MODE): New constant. + (HAS_VGA_TEXT): Likewise. + (accepts_video): New variable. + (grub_multiboot_set_accepts_video): New function. + (grub_multiboot_get_mbi_size): Account for video structures. + (set_video_mode): New function. + (retrieve_video_parameters): Likewise. + (grub_multiboot_make_mbi): Fill video fields. + 2010-01-15 Vladimir Serbinenko Video driver ids. diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h index f9edb0c59..665292e33 100644 --- a/include/grub/multiboot.h +++ b/include/grub/multiboot.h @@ -35,6 +35,8 @@ void grub_multiboot (int argc, char *argv[]); void grub_module (int argc, char *argv[]); +void grub_multiboot_set_accepts_video (int val); + grub_size_t grub_multiboot_get_mbi_size (void); grub_err_t grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, grub_off_t buf_off, grub_size_t bufsize); diff --git a/include/multiboot.h b/include/multiboot.h index da7afd9b3..57c154c98 100644 --- a/include/multiboot.h +++ b/include/multiboot.h @@ -85,10 +85,12 @@ #define MULTIBOOT_INFO_APM_TABLE 0x00000400 /* Is there video information? */ -#define MULTIBOOT_INFO_VIDEO_INFO 0x00000800 +#define MULTIBOOT_INFO_VBE_INFO 0x00000800 +#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000 #ifndef ASM_FILE +typedef unsigned char multiboot_uint8_t; typedef unsigned short multiboot_uint16_t; typedef unsigned int multiboot_uint32_t; typedef unsigned long long multiboot_uint64_t; @@ -187,9 +189,43 @@ struct multiboot_info multiboot_uint16_t vbe_interface_seg; multiboot_uint16_t vbe_interface_off; multiboot_uint16_t vbe_interface_len; + + multiboot_uint64_t framebuffer_addr; + multiboot_uint32_t framebuffer_pitch; + multiboot_uint32_t framebuffer_width; + multiboot_uint32_t framebuffer_height; + multiboot_uint8_t framebuffer_bpp; +#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 +#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 +#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 + multiboot_uint8_t framebuffer_type; + union + { + struct + { + multiboot_uint32_t framebuffer_palette_addr; + multiboot_uint16_t framebuffer_palette_num_colors; + }; + struct + { + multiboot_uint8_t framebuffer_red_field_position; + multiboot_uint8_t framebuffer_red_mask_size; + multiboot_uint8_t framebuffer_green_field_position; + multiboot_uint8_t framebuffer_green_mask_size; + multiboot_uint8_t framebuffer_blue_field_position; + multiboot_uint8_t framebuffer_blue_mask_size; + }; + }; }; typedef struct multiboot_info multiboot_info_t; +struct multiboot_color +{ + multiboot_uint8_t red; + multiboot_uint8_t green; + multiboot_uint8_t blue; +}; + struct multiboot_mmap_entry { multiboot_uint32_t size; diff --git a/include/multiboot2.h b/include/multiboot2.h index 0488849d7..a241a70ad 100644 --- a/include/multiboot2.h +++ b/include/multiboot2.h @@ -85,10 +85,12 @@ #define MULTIBOOT_INFO_APM_TABLE 0x00000400 /* Is there video information? */ -#define MULTIBOOT_INFO_VIDEO_INFO 0x00000800 +#define MULTIBOOT_INFO_VBE_INFO 0x00000800 +#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000 #ifndef ASM_FILE +typedef unsigned char multiboot_uint8_t; typedef unsigned short multiboot_uint16_t; typedef unsigned int multiboot_uint32_t; typedef unsigned long long multiboot_uint64_t; @@ -187,9 +189,43 @@ struct multiboot_info multiboot_uint16_t vbe_interface_seg; multiboot_uint16_t vbe_interface_off; multiboot_uint16_t vbe_interface_len; + + multiboot_uint64_t framebuffer_addr; + multiboot_uint32_t framebuffer_pitch; + multiboot_uint32_t framebuffer_width; + multiboot_uint32_t framebuffer_height; + multiboot_uint8_t framebuffer_bpp; +#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 +#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 +#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 + multiboot_uint8_t framebuffer_type; + union + { + struct + { + multiboot_uint32_t framebuffer_palette_addr; + multiboot_uint16_t framebuffer_palette_num_colors; + }; + struct + { + multiboot_uint8_t framebuffer_red_field_position; + multiboot_uint8_t framebuffer_red_mask_size; + multiboot_uint8_t framebuffer_green_field_position; + multiboot_uint8_t framebuffer_green_mask_size; + multiboot_uint8_t framebuffer_blue_field_position; + multiboot_uint8_t framebuffer_blue_mask_size; + }; + }; }; typedef struct multiboot_info multiboot_info_t; +struct multiboot_color +{ + multiboot_uint8_t red; + multiboot_uint8_t green; + multiboot_uint8_t blue; +}; + struct multiboot_mmap_entry { multiboot_uint32_t size; diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c index 4360e8a2c..637bc5d49 100644 --- a/loader/i386/multiboot.c +++ b/loader/i386/multiboot.c @@ -28,13 +28,11 @@ */ /* The bits in the required part of flags field we don't support. */ -#define UNSUPPORTED_FLAGS 0x0000fffc +#define UNSUPPORTED_FLAGS 0x0000fff8 #include #include #include -#include -#include #include #include #include @@ -90,8 +88,6 @@ grub_multiboot_boot (void) if (err) return err; - grub_video_set_mode ("text", NULL); - grub_relocator32_boot (grub_multiboot_payload_orig, grub_multiboot_payload_dest, state); @@ -235,6 +231,34 @@ grub_multiboot (int argc, char *argv[]) else if (grub_multiboot_load_elf (file, buffer) != GRUB_ERR_NONE) goto fail; + if (header->flags & MULTIBOOT_VIDEO_MODE) + { + switch (header->mode_type) + { + case 1: + grub_env_set ("gfxpayload", "text"); + break; + + case 0: + { + char buf[sizeof ("XXXXXXXXXXxXXXXXXXXXXxXXXXXXXXXX,XXXXXXXXXXxXXXXXXXXXX,auto")]; + if (header->depth && header->width && header->height) + grub_sprintf (buf, "%dx%dx%d,%dx%d,auto", header->width, + header->height, header->depth, header->width, + header->height); + else if (header->width && header->height) + grub_sprintf (buf, "%dx%d,auto", header->width, header->height); + else + grub_sprintf (buf, "auto"); + + grub_env_set ("gfxpayload", buf); + break; + } + } + } + + grub_multiboot_set_accepts_video (!!(header->flags & MULTIBOOT_VIDEO_MODE)); + grub_multiboot_set_bootdev (); grub_loader_set (grub_multiboot_boot, grub_multiboot_unload, 0); diff --git a/loader/i386/multiboot_mbi.c b/loader/i386/multiboot_mbi.c index 58802d44c..5f33a7314 100644 --- a/loader/i386/multiboot_mbi.c +++ b/loader/i386/multiboot_mbi.c @@ -29,6 +29,16 @@ #include #include #include +#include + +#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) +#include +#define DEFAULT_VIDEO_MODE "text" +#define HAS_VGA_TEXT 1 +#else +#define DEFAULT_VIDEO_MODE "auto" +#define HAS_VGA_TEXT 0 +#endif struct module { @@ -46,6 +56,13 @@ static unsigned modcnt; static char *cmdline = NULL; static grub_uint32_t bootdev; static int bootdev_set; +static int accepts_video; + +void +grub_multiboot_set_accepts_video (int val) +{ + accepts_video = val; +} /* Return the length of the Multiboot mmap that will be needed to allocate our platform's map. */ @@ -73,7 +90,8 @@ grub_multiboot_get_mbi_size (void) { return sizeof (struct multiboot_info) + ALIGN_UP (cmdline_size, 4) + modcnt * sizeof (struct multiboot_mod_list) + total_modcmd - + ALIGN_UP (sizeof(PACKAGE_STRING), 4) + grub_get_multiboot_mmap_len (); + + ALIGN_UP (sizeof(PACKAGE_STRING), 4) + grub_get_multiboot_mmap_len () + + 256 * sizeof (struct multiboot_color); } /* Fill previously allocated Multiboot mmap. */ @@ -106,6 +124,107 @@ grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry) grub_mmap_iterate (hook); } +static grub_err_t +set_video_mode (void) +{ + grub_err_t err; + const char *modevar; + + if (accepts_video || !HAS_VGA_TEXT) + { + modevar = grub_env_get ("gfxpayload"); + if (! modevar || *modevar == 0) + err = grub_video_set_mode (DEFAULT_VIDEO_MODE, 0); + else + { + char *tmp; + tmp = grub_malloc (grub_strlen (modevar) + + sizeof (DEFAULT_VIDEO_MODE) + 1); + if (! tmp) + return grub_errno; + grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar); + err = grub_video_set_mode (tmp, 0); + grub_free (tmp); + } + } + else + err = grub_video_set_mode ("text", 0); + + return err; +} + +static grub_err_t +retrieve_video_parameters (struct multiboot_info *mbi, + grub_uint8_t *ptrorig, grub_uint32_t ptrdest) +{ + grub_err_t err; + struct grub_video_mode_info mode_info; + void *framebuffer; + grub_video_driver_id_t driv_id; + struct grub_video_palette_data palette[256]; + + err = set_video_mode (); + if (err) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + + grub_video_get_palette (0, ARRAY_SIZE (palette), palette); + + driv_id = grub_video_get_driver_id (); + if (driv_id == GRUB_VIDEO_DRIVER_NONE) + return GRUB_ERR_NONE; + + err = grub_video_get_info_and_fini (&mode_info, &framebuffer); + if (err) + return err; + + mbi->framebuffer_addr = (grub_addr_t) framebuffer; + mbi->framebuffer_pitch = mode_info.pitch; + + mbi->framebuffer_width = mode_info.width; + mbi->framebuffer_height = mode_info.height; + + mbi->framebuffer_bpp = mode_info.bpp; + + if (mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR) + { + struct multiboot_color *mb_palette; + unsigned i; + mbi->framebuffer_type = MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED; + mbi->framebuffer_palette_addr = ptrdest; + mbi->framebuffer_palette_num_colors = mode_info.number_of_colors; + if (mbi->framebuffer_palette_num_colors > ARRAY_SIZE (palette)) + mbi->framebuffer_palette_num_colors = ARRAY_SIZE (palette); + mb_palette = (struct multiboot_color *) ptrorig; + for (i = 0; i < mbi->framebuffer_palette_num_colors; i++) + { + mb_palette[i].red = palette[i].r; + mb_palette[i].green = palette[i].g; + mb_palette[i].blue = palette[i].b; + } + ptrorig += mbi->framebuffer_palette_num_colors + * sizeof (struct multiboot_color); + ptrdest += mbi->framebuffer_palette_num_colors + * sizeof (struct multiboot_color); + } + else + { + mbi->framebuffer_type = MULTIBOOT_FRAMEBUFFER_TYPE_RGB; + mbi->framebuffer_red_field_position = mode_info.green_field_pos; + mbi->framebuffer_red_mask_size = mode_info.green_mask_size; + mbi->framebuffer_green_field_position = mode_info.green_field_pos; + mbi->framebuffer_green_mask_size = mode_info.green_mask_size; + mbi->framebuffer_blue_field_position = mode_info.blue_field_pos; + mbi->framebuffer_blue_mask_size = mode_info.blue_mask_size; + } + + mbi->flags |= MULTIBOOT_INFO_FRAMEBUFFER_INFO; + + return GRUB_ERR_NONE; +} + grub_err_t grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, grub_off_t buf_off, grub_size_t bufsize) @@ -117,6 +236,7 @@ grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, grub_off_t buf_off, unsigned i; struct module *cur; grub_size_t mmap_size; + grub_err_t err; if (bufsize < grub_multiboot_get_mbi_size ()) return grub_error (GRUB_ERR_OUT_OF_MEMORY, "mbi buffer is too small"); @@ -182,6 +302,13 @@ grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, grub_off_t buf_off, mbi->flags |= MULTIBOOT_INFO_BOOTDEV; } + err = retrieve_video_parameters (mbi, ptrorig, ptrdest); + if (err) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + return GRUB_ERR_NONE; } From a0b766fc9b50388d12eb5ed08756f5c5ab0ad480 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 15 Jan 2010 21:11:51 +0100 Subject: [PATCH 49/63] 2010-01-15 Vladimir Serbinenko Enable multiboot on non-pc. * conf/i386-coreboot.rmk, conf/i386-pc.rmk (pkglib_MODULES): Move multiboot.mod and multiboot2.mod to ... * conf/i386.rmk (pkglib_MODULES): ... here. * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_SOURCES): Moved to ... * conf/i386.rmk (multiboot_mod_SOURCES): .. here. * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_CFLAGS): Moved to ... * conf/i386.rmk (multiboot_mod_CFLAGS): .. here. * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_ASFLAGS): Moved to ... * conf/i386.rmk (multiboot_mod_ASFLAGS): .. here. * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_LDFLAGS): Moved to ... * conf/i386.rmk (multiboot_mod_LDFLAGS): .. here. * conf/x86_64-efi.rmk (pkglib_MODULES): Remove ata.mod and relocator.mod. (ata_mod_SOURCES): Removed. (ata_mod_CFLAGS): Likewise. (ata_mod_LDFLAGS): Likewise. (relocator_mod_SOURCES): Removed. (relocator_mod_CFLAGS): Likewise. (relocator_mod_ASFLAGS): Likewise. (relocator_mod_LDFLAGS): Likewise. Include i386.mk. * include/grub/x86_64/multiboot.h: New file. * loader/i386/multiboot.c (grub_multiboot_boot) [GRUB_MACHINE_EFI]: Terminate EFI. --- ChangeLog | 33 +++++++++++++++++++++++++++++++++ conf/i386-coreboot.rmk | 16 ---------------- conf/i386-pc.rmk | 16 ---------------- conf/i386.rmk | 16 ++++++++++++++++ conf/x86_64-efi.rmk | 14 ++------------ include/grub/x86_64/multiboot.h | 1 + loader/i386/multiboot.c | 9 +++++++++ 7 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 include/grub/x86_64/multiboot.h diff --git a/ChangeLog b/ChangeLog index 8d3245ea3..3acc543d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,36 @@ +2010-01-15 Vladimir Serbinenko + + Enable multiboot on non-pc. + + * conf/i386-coreboot.rmk, conf/i386-pc.rmk (pkglib_MODULES): Move + multiboot.mod and multiboot2.mod to ... + * conf/i386.rmk (pkglib_MODULES): ... here. + * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_SOURCES): + Moved to ... + * conf/i386.rmk (multiboot_mod_SOURCES): .. here. + * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_CFLAGS): + Moved to ... + * conf/i386.rmk (multiboot_mod_CFLAGS): .. here. + * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_ASFLAGS): + Moved to ... + * conf/i386.rmk (multiboot_mod_ASFLAGS): .. here. + * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_LDFLAGS): + Moved to ... + * conf/i386.rmk (multiboot_mod_LDFLAGS): .. here. + * conf/x86_64-efi.rmk (pkglib_MODULES): Remove ata.mod and + relocator.mod. + (ata_mod_SOURCES): Removed. + (ata_mod_CFLAGS): Likewise. + (ata_mod_LDFLAGS): Likewise. + (relocator_mod_SOURCES): Removed. + (relocator_mod_CFLAGS): Likewise. + (relocator_mod_ASFLAGS): Likewise. + (relocator_mod_LDFLAGS): Likewise. + Include i386.mk. + * include/grub/x86_64/multiboot.h: New file. + * loader/i386/multiboot.c (grub_multiboot_boot) [GRUB_MACHINE_EFI]: + Terminate EFI. + 2010-01-15 Vladimir Serbinenko Video multiboot support. diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index d73c9f0e2..57fb3350c 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -140,22 +140,6 @@ serial_mod_SOURCES = term/i386/pc/serial.c serial_mod_CFLAGS = $(COMMON_CFLAGS) serial_mod_LDFLAGS = $(COMMON_LDFLAGS) -pkglib_MODULES += multiboot.mod -multiboot_mod_SOURCES = loader/i386/multiboot.c \ - loader/i386/multiboot_mbi.c \ - loader/multiboot_loader.c -multiboot_mod_CFLAGS = $(COMMON_CFLAGS) -multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) -multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += multiboot2.mod -multiboot2_mod_SOURCES = loader/i386/multiboot.c \ - loader/multiboot_loader.c \ - loader/i386/multiboot_mbi.c -multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 -multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) -multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) - # For aout.mod. aout_mod_SOURCES = loader/aout.c aout_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 2a69571aa..a89203dea 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -201,22 +201,6 @@ serial_mod_SOURCES = term/i386/pc/serial.c serial_mod_CFLAGS = $(COMMON_CFLAGS) serial_mod_LDFLAGS = $(COMMON_LDFLAGS) -pkglib_MODULES += multiboot.mod -multiboot_mod_SOURCES = loader/i386/multiboot.c \ - loader/i386/multiboot_mbi.c \ - loader/multiboot_loader.c -multiboot_mod_CFLAGS = $(COMMON_CFLAGS) -multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) -multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += multiboot2.mod -multiboot2_mod_SOURCES = loader/i386/multiboot.c \ - loader/i386/multiboot_mbi.c \ - loader/multiboot_loader.c -multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 -multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) -multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) - # For vbe.mod. vbe_mod_SOURCES = video/i386/pc/vbe.c vbe_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/i386.rmk b/conf/i386.rmk index c3f036d0f..7ef337c61 100644 --- a/conf/i386.rmk +++ b/conf/i386.rmk @@ -25,3 +25,19 @@ pkglib_MODULES += ata.mod ata_mod_SOURCES = disk/ata.c ata_mod_CFLAGS = $(COMMON_CFLAGS) ata_mod_LDFLAGS = $(COMMON_LDFLAGS) + +pkglib_MODULES += multiboot.mod +multiboot_mod_SOURCES = loader/i386/multiboot.c \ + loader/i386/multiboot_mbi.c \ + loader/multiboot_loader.c +multiboot_mod_CFLAGS = $(COMMON_CFLAGS) +multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) +multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) + +pkglib_MODULES += multiboot2.mod +multiboot2_mod_SOURCES = loader/i386/multiboot.c \ + loader/i386/multiboot_mbi.c \ + loader/multiboot_loader.c +multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 +multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) +multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index 4f6ace057..122700711 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -32,7 +32,7 @@ grub_install_SOURCES = util/i386/efi/grub-install.in pkglib_MODULES = kernel.img chain.mod appleldr.mod \ halt.mod reboot.mod linux.mod pci.mod lspci.mod \ datetime.mod date.mod datehook.mod loadbios.mod \ - fixvideo.mod mmap.mod acpi.mod ata.mod + fixvideo.mod mmap.mod acpi.mod # For kernel.img. kernel_img_EXPORTS = no @@ -77,11 +77,6 @@ acpi_mod_SOURCES = commands/acpi.c commands/efi/acpi.c acpi_mod_CFLAGS = $(COMMON_CFLAGS) acpi_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For ata.mod -ata_mod_SOURCES = disk/ata.c -ata_mod_CFLAGS = $(COMMON_CFLAGS) -ata_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For mmap.mod. mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c \ mmap/efi/mmap.c @@ -166,10 +161,5 @@ xnu_mod_CFLAGS = $(COMMON_CFLAGS) xnu_mod_LDFLAGS = $(COMMON_LDFLAGS) xnu_mod_ASFLAGS = $(COMMON_ASFLAGS) -pkglib_MODULES += relocator.mod -relocator_mod_SOURCES = lib/i386/relocator.c lib/i386/relocator_asm.S lib/i386/relocator_backward.S -relocator_mod_CFLAGS = $(COMMON_CFLAGS) -relocator_mod_ASFLAGS = $(COMMON_ASFLAGS) -relocator_mod_LDFLAGS = $(COMMON_LDFLAGS) - +include $(srcdir)/conf/i386.mk include $(srcdir)/conf/common.mk diff --git a/include/grub/x86_64/multiboot.h b/include/grub/x86_64/multiboot.h new file mode 100644 index 000000000..957c7a5ad --- /dev/null +++ b/include/grub/x86_64/multiboot.h @@ -0,0 +1 @@ +#include diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c index 637bc5d49..d06f18692 100644 --- a/loader/i386/multiboot.c +++ b/loader/i386/multiboot.c @@ -46,6 +46,10 @@ #include #include +#ifdef GRUB_MACHINE_EFI +#include +#endif + extern grub_dl_t my_mod; static grub_size_t code_size, alloc_mbi; @@ -88,6 +92,11 @@ grub_multiboot_boot (void) if (err) return err; +#ifdef GRUB_MACHINE_EFI + if (! grub_efi_finish_boot_services ()) + grub_fatal ("cannot exit boot services"); +#endif + grub_relocator32_boot (grub_multiboot_payload_orig, grub_multiboot_payload_dest, state); From 70a14d3d49985c98f60bcec788e9261ff5e2db16 Mon Sep 17 00:00:00 2001 From: carles Date: Sat, 16 Jan 2010 00:26:52 +0000 Subject: [PATCH 50/63] 2010-01-16 Carles Pina i Estany * util/misc.c (grub_util_warn): Gettextizze, print full stop after the message. (grub_util_info): Likewise. (grub_util_error): Likewise. * util/elf/grub-mkimage.c: Fix capitalisation, quotes, full stops and/or new lines in `grub_util_warna', `grub_util_info', `grub_util_error' calls. * util/getroot.c: Likewise. * util/grub-editenv.c: Likewise. * util/grub-emu.c: Likewise. * util/grub-fstest.c: Likewise. * util/grub-mkdevicemap.c: Likewise. * util/grub-mkfont.c: Likewise. * util/grub-mkpasswd-pbkdf2.c: Likewise. * util/grub-mkrelpath.c: Likewise. * util/grub-pe2elf.c: Likewise. * util/grub-probe.c: Likewise. * util/hostdisk.c: Likewise. * util/i386/efi/grub-mkimage.c: Likewise. * util/i386/pc/grub-mkimage.c: Likewise. * util/i386/pc/grub-setup.c: Likewise. * util/ieee1275/ofpath.c: Likewise. * util/mkisofs/eltorito.c: Likewise. * util/mkisofs/rock.c: Likewise. * util/mkisofs/write.c: Likewise. * util/raid.c: Likewise. * util/sparc64/ieee1275/grub-mkimage.c: Likewise. * util/sparc64/ieee1275/grub-setup.c: Likewise. --- ChangeLog | 31 +++++++++++++++++++++ util/elf/grub-mkimage.c | 2 +- util/getroot.c | 26 +++++++++--------- util/grub-editenv.c | 2 +- util/grub-emu.c | 6 ++--- util/grub-fstest.c | 34 +++++++++++------------ util/grub-mkdevicemap.c | 2 +- util/grub-mkfont.c | 12 ++++----- util/grub-mkpasswd-pbkdf2.c | 22 +++++++-------- util/grub-mkrelpath.c | 2 +- util/grub-pe2elf.c | 14 +++++----- util/grub-probe.c | 12 ++++----- util/hostdisk.c | 4 +-- util/i386/efi/grub-mkimage.c | 4 +-- util/i386/pc/grub-mkimage.c | 4 +-- util/i386/pc/grub-setup.c | 40 ++++++++++++++-------------- util/ieee1275/ofpath.c | 12 ++++----- util/misc.c | 15 ++++++----- util/mkisofs/eltorito.c | 6 ++--- util/mkisofs/rock.c | 2 +- util/mkisofs/write.c | 2 +- util/raid.c | 6 ++--- util/sparc64/ieee1275/grub-mkimage.c | 2 +- util/sparc64/ieee1275/grub-setup.c | 40 ++++++++++++++-------------- 24 files changed, 168 insertions(+), 134 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3acc543d4..0effe5e10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2010-01-16 Carles Pina i Estany + + * util/misc.c (grub_util_warn): Gettextizze, print full stop after + the message. + (grub_util_info): Likewise. + (grub_util_error): Likewise. + * util/elf/grub-mkimage.c: Fix capitalisation, quotes, full stops + and/or new lines in `grub_util_warna', `grub_util_info', + `grub_util_error' calls. + * util/getroot.c: Likewise. + * util/grub-editenv.c: Likewise. + * util/grub-emu.c: Likewise. + * util/grub-fstest.c: Likewise. + * util/grub-mkdevicemap.c: Likewise. + * util/grub-mkfont.c: Likewise. + * util/grub-mkpasswd-pbkdf2.c: Likewise. + * util/grub-mkrelpath.c: Likewise. + * util/grub-pe2elf.c: Likewise. + * util/grub-probe.c: Likewise. + * util/hostdisk.c: Likewise. + * util/i386/efi/grub-mkimage.c: Likewise. + * util/i386/pc/grub-mkimage.c: Likewise. + * util/i386/pc/grub-setup.c: Likewise. + * util/ieee1275/ofpath.c: Likewise. + * util/mkisofs/eltorito.c: Likewise. + * util/mkisofs/rock.c: Likewise. + * util/mkisofs/write.c: Likewise. + * util/raid.c: Likewise. + * util/sparc64/ieee1275/grub-mkimage.c: Likewise. + * util/sparc64/ieee1275/grub-setup.c: Likewise. + 2010-01-15 Vladimir Serbinenko Enable multiboot on non-pc. diff --git a/util/elf/grub-mkimage.c b/util/elf/grub-mkimage.c index 6ba8b1ae2..c0736b83f 100644 --- a/util/elf/grub-mkimage.c +++ b/util/elf/grub-mkimage.c @@ -328,7 +328,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s -o FILE [OPTION]... [MODULES]\n\ diff --git a/util/getroot.c b/util/getroot.c index 22ad7e967..6357c8a26 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -115,14 +115,14 @@ grub_get_prefix (const char *dir) saved_cwd = xgetcwd (); if (chdir (dir) < 0) - grub_util_error ("Cannot change directory to `%s'", dir); + grub_util_error ("cannot change directory to `%s'", dir); abs_dir = xgetcwd (); strip_extra_slashes (abs_dir); prev_dir = xstrdup (abs_dir); if (stat (".", &prev_st) < 0) - grub_util_error ("Cannot stat `%s'", dir); + grub_util_error ("cannot stat `%s'", dir); if (! S_ISDIR (prev_st.st_mode)) grub_util_error ("`%s' is not a directory", dir); @@ -130,13 +130,13 @@ grub_get_prefix (const char *dir) while (1) { if (chdir ("..") < 0) - grub_util_error ("Cannot change directory to the parent"); + grub_util_error ("cannot change directory to the parent"); if (stat (".", &st) < 0) - grub_util_error ("Cannot stat current directory"); + grub_util_error ("cannot stat current directory"); if (! S_ISDIR (st.st_mode)) - grub_util_error ("Current directory is not a directory???"); + grub_util_error ("current directory is not a directory???"); if (prev_st.st_dev != st.st_dev || prev_st.st_ino == st.st_ino) break; @@ -153,7 +153,7 @@ grub_get_prefix (const char *dir) strip_extra_slashes (prefix); if (chdir (saved_cwd) < 0) - grub_util_error ("Cannot change directory to `%s'", dir); + grub_util_error ("cannot change directory to `%s'", dir); #ifdef __CYGWIN__ if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16)) @@ -236,7 +236,7 @@ find_root_device (const char *dir, dev_t dev) if (res) { if (chdir (saved_cwd) < 0) - grub_util_error ("Cannot restore the original directory"); + grub_util_error ("cannot restore the original directory"); free (saved_cwd); closedir (dp); @@ -279,7 +279,7 @@ find_root_device (const char *dir, dev_t dev) continue; if (chdir (saved_cwd) < 0) - grub_util_error ("Cannot restore the original directory"); + grub_util_error ("cannot restore the original directory"); free (saved_cwd); closedir (dp); @@ -288,7 +288,7 @@ find_root_device (const char *dir, dev_t dev) } if (chdir (saved_cwd) < 0) - grub_util_error ("Cannot restore the original directory"); + grub_util_error ("cannot restore the original directory"); free (saved_cwd); closedir (dp); @@ -445,7 +445,7 @@ grub_guess_root_device (const char *dir) struct stat st; if (stat (dir, &st) < 0) - grub_util_error ("Cannot stat `%s'", dir); + grub_util_error ("cannot stat `%s'", dir); #ifdef __CYGWIN__ /* Cygwin specific function. */ @@ -591,7 +591,7 @@ grub_util_get_grub_dev (const char *os_dev) free (p); } else - grub_util_error ("Unknown kind of RAID device `%s'", os_dev); + grub_util_error ("unknown kind of RAID device `%s'", os_dev); break; @@ -608,7 +608,7 @@ grub_util_check_block_device (const char *blk_dev) struct stat st; if (stat (blk_dev, &st) < 0) - grub_util_error ("Cannot stat `%s'", blk_dev); + grub_util_error ("cannot stat `%s'", blk_dev); if (S_ISBLK (st.st_mode)) return (blk_dev); @@ -622,7 +622,7 @@ grub_util_check_char_device (const char *blk_dev) struct stat st; if (stat (blk_dev, &st) < 0) - grub_util_error ("Cannot stat `%s'", blk_dev); + grub_util_error ("cannot stat `%s'", blk_dev); if (S_ISCHR (st.st_mode)) return (blk_dev); diff --git a/util/grub-editenv.c b/util/grub-editenv.c index 1fb1422df..ea0e4da19 100644 --- a/util/grub-editenv.c +++ b/util/grub-editenv.c @@ -69,7 +69,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``grub-editenv --help'' for more information.\n"); + fprintf (stderr, "Try `grub-editenv --help' for more information.\n"); else printf ("\ Usage: grub-editenv [OPTIONS] [FILENAME] COMMAND\n\ diff --git a/util/grub-emu.c b/util/grub-emu.c index 3f2acaaec..a04aeae78 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -129,7 +129,7 @@ usage (int status) { if (status) fprintf (stderr, - "Try ``grub-emu --help'' for more information.\n"); + "Try `grub-emu --help' for more information.\n"); else printf ( "Usage: grub-emu [OPTION]...\n" @@ -220,14 +220,14 @@ main (int argc, char *argv[]) { char *device_name = grub_guess_root_device (dir); if (! device_name) - grub_util_error ("cannot find a device for %s.\n", dir); + grub_util_error ("cannot find a device for %s", dir); root_dev = grub_util_get_grub_dev (device_name); if (! root_dev) { grub_util_info ("guessing the root device failed, because of `%s'", grub_errmsg); - grub_util_error ("Cannot guess the root device. Specify the option ``--root-device''."); + grub_util_error ("cannot guess the root device. Specify the option `--root-device'"); } } diff --git a/util/grub-fstest.c b/util/grub-fstest.c index 586dda0f9..4470cbfa5 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -71,7 +71,7 @@ execute_command (char *name, int n, char **args) cmd = grub_command_find (name); if (! cmd) - grub_util_error ("Can\'t find command %s", name); + grub_util_error ("can\'t find command %s", name); return (cmd->func) (cmd, n, args); } @@ -100,9 +100,9 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) dev = grub_device_open (0); if ((! dev) || (! dev->disk)) - grub_util_error ("Can\'t open device."); + grub_util_error ("can\'t open device"); - grub_util_info ("total sectors : %lld.", + grub_util_info ("total sectors : %lld", (unsigned long long) dev->disk->total_sectors); if (! leng) @@ -115,7 +115,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) len = (leng > BUF_SIZE) ? BUF_SIZE : leng; if (grub_disk_read (dev->disk, 0, skip, len, buf)) - grub_util_error ("Disk read fails at offset %lld, length %d.", + grub_util_error ("disk read fails at offset %lld, length %d", skip, len); if (hook (skip, buf, len)) @@ -132,15 +132,15 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) file = grub_file_open (pathname); if (!file) { - grub_util_error ("cannot open file %s.", pathname); + grub_util_error ("cannot open file %s", pathname); return; } - grub_util_info ("file size : %lld.", (unsigned long long) file->size); + grub_util_info ("file size : %lld", (unsigned long long) file->size); if (skip > file->size) { - grub_util_error ("invalid skip value %lld.", (unsigned long long) skip); + grub_util_error ("invalid skip value %lld", (unsigned long long) skip); return; } @@ -158,7 +158,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) sz = grub_file_read (file, buf, (len > BUF_SIZE) ? BUF_SIZE : len); if (sz < 0) { - grub_util_error ("read error at offset %llu.", ofs); + grub_util_error ("read error at offset %llu", ofs); break; } @@ -184,7 +184,7 @@ cmd_cp (char *src, char *dest) if ((int) fwrite (buf, 1, len, ff) != len) { - grub_util_error ("write error."); + grub_util_error ("write error"); return 1; } @@ -194,7 +194,7 @@ cmd_cp (char *src, char *dest) ff = fopen (dest, "wb"); if (ff == NULL) { - grub_util_error ("open error."); + grub_util_error ("open error"); return; } read_file (src, cp_hook); @@ -212,7 +212,7 @@ cmd_cmp (char *src, char *dest) { if ((int) fread (buf_1, 1, len, ff) != len) { - grub_util_error ("read error at offset %llu.", ofs); + grub_util_error ("read error at offset %llu", ofs); return 1; } @@ -223,7 +223,7 @@ cmd_cmp (char *src, char *dest) for (i = 0; i < len; i++, ofs++) if (buf_1[i] != buf[i]) { - grub_util_error ("compare fail at offset %llu.", ofs); + grub_util_error ("compare fail at offset %llu", ofs); return 1; } } @@ -233,12 +233,12 @@ cmd_cmp (char *src, char *dest) ff = fopen (dest, "rb"); if (ff == NULL) { - grub_util_error ("open error."); + grub_util_error ("open error"); return; } if ((skip) && (fseeko (ff, skip, SEEK_SET))) - grub_util_error ("seek error."); + grub_util_error ("seek error"); read_file (src, cmp_hook); fclose (ff); @@ -286,13 +286,13 @@ fstest (char **images, int num_disks, int cmd, int n, char **args) for (i = 0; i < num_disks; i++) { if (grub_strlen (images[i]) + 7 > sizeof (host_file)) - grub_util_error ("Pathname %s too long.", images[i]); + grub_util_error ("pathname %s too long", images[i]); grub_sprintf (loop_name, "loop%d", i); grub_sprintf (host_file, "(host)%s", images[i]); if (execute_command ("loopback", 3, argv)) - grub_util_error ("loopback command fails."); + grub_util_error ("loopback command fails"); } grub_lvm_fini (); @@ -349,7 +349,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTION]... IMAGE_PATH COMMANDS\n\ diff --git a/util/grub-mkdevicemap.c b/util/grub-mkdevicemap.c index b4febbb8d..c68482af1 100644 --- a/util/grub-mkdevicemap.c +++ b/util/grub-mkdevicemap.c @@ -84,7 +84,7 @@ usage (int status) { if (status) fprintf (stderr, - "Try ``%s --help'' for more information.\n", program_name); + "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTION]...\n\ diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index 3d1c6faac..fcd35afd4 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -96,7 +96,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTIONS] FONT_FILES\n\ @@ -347,7 +347,7 @@ write_font (struct grub_font_info *font_info, char *output_file) file = fopen (output_file, "wb"); if (! file) - grub_util_error ("Can\'t write to file %s.", output_file); + grub_util_error ("can\'t write to file %s.", output_file); offset = 0; @@ -546,7 +546,7 @@ main (int argc, char *argv[]) a = strtoul (p, &p, 0); if (*p != '-') - grub_util_error ("Invalid font range"); + grub_util_error ("invalid font range"); b = strtoul (p + 1, &p, 0); if ((font_info.num_range & (GRUB_FONT_RANGE_BLOCK - 1)) == 0) font_info.ranges = xrealloc (font_info.ranges, @@ -561,7 +561,7 @@ main (int argc, char *argv[]) if (*p) { if (*p != ',') - grub_util_error ("Invalid font range"); + grub_util_error ("invalid font range"); else p++; } @@ -598,7 +598,7 @@ main (int argc, char *argv[]) } if (! output_file) - grub_util_error ("No output file is specified."); + grub_util_error ("no output file is specified"); if (FT_Init_FreeType (&ft_lib)) grub_util_error ("FT_Init_FreeType fails"); @@ -610,7 +610,7 @@ main (int argc, char *argv[]) if (FT_New_Face (ft_lib, argv[optind], font_index, &ft_face)) { - grub_util_info ("Can't open file %s, index %d\n", argv[optind], + grub_util_info ("can't open file %s, index %d", argv[optind], font_index); continue; } diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c index b27a4e893..f5fdcca96 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -74,7 +74,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``grub-scrypt --help'' for more information.\n"); + fprintf (stderr, "Try `grub-scrypt --help' for more information.\n"); else printf ("\ Usage: grub-scrypt [OPTIONS]\n\ @@ -165,12 +165,12 @@ main (int argc, char *argv[]) bufhex = malloc (buflen * 2 + 1); if (!bufhex) - grub_util_error ("Out of memory"); + grub_util_error ("out of memory"); buf = malloc (buflen); if (!buf) { free (bufhex); - grub_util_error ("Out of memory"); + grub_util_error ("out of memory"); } salt = malloc (saltlen); @@ -178,7 +178,7 @@ main (int argc, char *argv[]) { free (bufhex); free (buf); - grub_util_error ("Out of memory"); + grub_util_error ("out of memory"); } salthex = malloc (saltlen * 2 + 1); if (!salthex) @@ -186,7 +186,7 @@ main (int argc, char *argv[]) free (salt); free (bufhex); free (buf); - grub_util_error ("Out of memory"); + grub_util_error ("out of memory"); } /* Disable echoing. Based on glibc. */ @@ -225,7 +225,7 @@ main (int argc, char *argv[]) /* Restore the original setting. */ if (tty_changed) (void) tcsetattr (fileno (in), TCSAFLUSH, &s); - grub_util_error ("Failure to read password"); + grub_util_error ("failure to read password"); } if (nr >= 1 && pass1[nr-1] == '\n') pass1[nr-1] = 0; @@ -249,7 +249,7 @@ main (int argc, char *argv[]) free (bufhex); free (salthex); free (salt); - grub_util_error ("Failure to read password"); + grub_util_error ("failure to read password"); } if (nr >= 1 && pass2[nr-1] == '\n') pass2[nr-1] = 0; @@ -264,7 +264,7 @@ main (int argc, char *argv[]) free (bufhex); free (salthex); free (salt); - grub_util_error ("Passwords don't match"); + grub_util_error ("passwords don't match"); } memset (pass2, 0, strlen (pass2)); free (pass2); @@ -286,7 +286,7 @@ main (int argc, char *argv[]) free (salthex); free (salt); fclose (f); - grub_util_error ("Couldn't retrieve random data for salt"); + grub_util_error ("couldn't retrieve random data for salt"); } rd = fread (salt, 1, saltlen, f); if (rd != saltlen) @@ -299,7 +299,7 @@ main (int argc, char *argv[]) free (salthex); free (salt); fclose (f); - grub_util_error ("Couldn't retrieve random data for salt"); + grub_util_error ("couldn't retrieve random data for salt"); } fclose (f); } @@ -321,7 +321,7 @@ main (int argc, char *argv[]) memset (salthex, 0, 2 * saltlen); free (salt); free (salthex); - grub_util_error ("Cryptographic error number %d", gcry_err); + grub_util_error ("cryptographic error number %d", gcry_err); } hexify (bufhex, buf, buflen); diff --git a/util/grub-mkrelpath.c b/util/grub-mkrelpath.c index 62e400814..327f0c866 100644 --- a/util/grub-mkrelpath.c +++ b/util/grub-mkrelpath.c @@ -34,7 +34,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTIONS] PATH\n\ diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c index fb370d9ec..488ad9b23 100644 --- a/util/grub-pe2elf.c +++ b/util/grub-pe2elf.c @@ -40,7 +40,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTIONS] input [output]\n\ @@ -182,7 +182,7 @@ write_section_data (FILE* fp, char *image, char name[5 + strlen (pe_shdr->name)]; if (num_sections >= MAX_SECTIONS) - grub_util_error ("Too many sections"); + grub_util_error ("too many sections"); sprintf (name, ".rel%s", pe_shdr->name); @@ -230,14 +230,14 @@ write_reloc_section (FILE* fp, char *image, if ((pe_rel->symtab_index >= pe_chdr->num_symbols) || (symtab_map[pe_rel->symtab_index] == -1)) - grub_util_error ("Invalid symbol"); + grub_util_error ("invalid symbol"); if (pe_rel->type == GRUB_PE32_REL_I386_DIR32) type = R_386_32; else if (pe_rel->type == GRUB_PE32_REL_I386_REL32) type = R_386_PC32; else - grub_util_error ("Unknown pe relocation type %d\n", pe_rel->type); + grub_util_error ("unknown pe relocation type %d\n", pe_rel->type); ofs = pe_rel->offset - pe_sec->virtual_address; addr = (grub_uint32_t *)(image + pe_sec->raw_data_offset + ofs); @@ -248,14 +248,14 @@ write_reloc_section (FILE* fp, char *image, code = image[pe_sec->raw_data_offset + ofs - 1]; if (((code != 0xe8) && (code != 0xe9)) || (*addr)) - grub_util_error ("Invalid relocation (%x %x)", code, *addr); + grub_util_error ("invalid relocation (%x %x)", code, *addr); modified = 1; if (symtab[symtab_map[pe_rel->symtab_index]].st_shndx) { if (symtab[symtab_map[pe_rel->symtab_index]].st_shndx != shdr[i].sh_info) - grub_util_error ("Cross section call is not allowed"); + grub_util_error ("cross section call is not allowed"); *addr = (symtab[symtab_map[pe_rel->symtab_index]].st_value - ofs - 4); @@ -440,7 +440,7 @@ convert_pe (FILE* fp, char *image) pe_chdr = (struct grub_pe32_coff_header *) image; if (grub_le_to_cpu16 (pe_chdr->machine) != GRUB_PE32_MACHINE_I386) - grub_util_error ("Invalid coff image"); + grub_util_error ("invalid coff image"); strtab = xmalloc (STRTAB_BLOCK); strtab_max = STRTAB_BLOCK; diff --git a/util/grub-probe.c b/util/grub-probe.c index 4ba8a98e5..879098542 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -84,7 +84,7 @@ probe_partmap (grub_disk_t disk) { if (disk->partition == NULL) { - grub_util_info ("No partition map found for %s", disk->name); + grub_util_info ("no partition map found for %s", disk->name); return; } @@ -113,17 +113,17 @@ probe (const char *path, char *device_name) { #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) if (! grub_util_check_char_device (device_name)) - grub_util_error ("%s is not a character device.\n", device_name); + grub_util_error ("%s is not a character device", device_name); #else if (! grub_util_check_block_device (device_name)) - grub_util_error ("%s is not a block device.\n", device_name); + grub_util_error ("%s is not a block device", device_name); #endif } else device_name = grub_guess_root_device (path); if (! device_name) - grub_util_error ("cannot find a device for %s (is /dev mounted?).\n", path); + grub_util_error ("cannot find a device for %s (is /dev mounted?)", path); if (print == PRINT_DEVICE) { @@ -133,7 +133,7 @@ probe (const char *path, char *device_name) drive_name = grub_util_get_grub_dev (device_name); if (! drive_name) - grub_util_error ("Cannot find a GRUB drive for %s. Check your device.map.\n", device_name); + grub_util_error ("cannot find a GRUB drive for %s. Check your device.map", device_name); if (print == PRINT_DRIVE) { @@ -309,7 +309,7 @@ usage (int status) { if (status) fprintf (stderr, - "Try ``%s --help'' for more information.\n", program_name); + "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTION]... [PATH|DEVICE]\n\ diff --git a/util/hostdisk.c b/util/hostdisk.c index c94f4237e..603445801 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -568,7 +568,7 @@ read_device_map (const char *dev_map) fp = fopen (dev_map, "r"); if (! fp) { - grub_util_info (_("Cannot open `%s'"), dev_map); + grub_util_info (_("cannot open `%s'"), dev_map); return; } @@ -639,7 +639,7 @@ read_device_map (const char *dev_map) symbolic links. */ map[drive].device = xmalloc (PATH_MAX); if (! realpath (p, map[drive].device)) - grub_util_error ("Cannot get the real path of `%s'", p); + grub_util_error ("cannot get the real path of `%s'", p); #else map[drive].device = xstrdup (p); #endif diff --git a/util/i386/efi/grub-mkimage.c b/util/i386/efi/grub-mkimage.c index 7f5141531..8fee3e8d9 100644 --- a/util/i386/efi/grub-mkimage.c +++ b/util/i386/efi/grub-mkimage.c @@ -778,7 +778,7 @@ make_reloc_section (FILE *out, Elf_Addr current_address, Elf_Ehdr *e, if ((ELF_R_TYPE (info) == R_X86_64_32) || (ELF_R_TYPE (info) == R_X86_64_32S)) { - grub_util_error ("Can\'t add fixup entry for R_X86_64_32(S)"); + grub_util_error ("can\'t add fixup entry for R_X86_64_32(S)"); } else if (ELF_R_TYPE (info) == R_X86_64_64) { @@ -1029,7 +1029,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``grub-mkimage --help'' for more information.\n"); + fprintf (stderr, "Try `grub-mkimage --help' for more information.\n"); else printf ("\ Usage: grub-mkimage -o FILE [OPTION]... [MODULES]\n\ diff --git a/util/i386/pc/grub-mkimage.c b/util/i386/pc/grub-mkimage.c index ebf1bc7ff..08807b4d1 100644 --- a/util/i386/pc/grub-mkimage.c +++ b/util/i386/pc/grub-mkimage.c @@ -289,7 +289,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], #ifdef GRUB_MACHINE_PCBIOS if (GRUB_KERNEL_MACHINE_LINK_ADDR + core_size > GRUB_MEMORY_MACHINE_UPPER) - grub_util_error (_("Core image is too big (%p > %p)\n"), + grub_util_error (_("core image is too big (%p > %p)"), GRUB_KERNEL_MACHINE_LINK_ADDR + core_size, GRUB_MEMORY_MACHINE_UPPER); #endif @@ -326,7 +326,7 @@ static void usage (int status) { if (status) - fprintf (stderr, _("Try ``%s --help'' for more information.\n"), program_name); + fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); else printf (_("\ Usage: grub-mkimage [OPTION]... [MODULES]\n\ diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 909a521eb..64b017296 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -156,7 +156,7 @@ setup (const char *dir, sector, offset, length); if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("The first sector of the core file is not sector-aligned")); + grub_util_error (_("the first sector of the core file is not sector-aligned")); first_sector = sector; } @@ -170,7 +170,7 @@ setup (const char *dir, sector, offset, length, (unsigned) current_segment); if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("Non-sector-aligned data is found in the core file")); + grub_util_error (_("non-sector-aligned data is found in the core file")); if (block != first_block && (grub_le_to_cpu64 (prev->start) @@ -184,7 +184,7 @@ setup (const char *dir, block--; if (block->len) - grub_util_error (_("The sectors of the core file are too fragmented")); + grub_util_error (_("the sectors of the core file are too fragmented")); } last_length = length; @@ -195,7 +195,7 @@ setup (const char *dir, boot_path = grub_util_get_path (dir, boot_file); boot_size = grub_util_get_image_size (boot_path); if (boot_size != GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("The size of `%s' is not %u"), + grub_util_error (_("the size of `%s' is not %u"), boot_path, GRUB_DISK_SECTOR_SIZE); boot_img = grub_util_read_image (boot_path); free (boot_path); @@ -212,9 +212,9 @@ setup (const char *dir, core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); if (core_size < GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("The size of `%s' is too small"), core_path); + grub_util_error (_("the size of `%s' is too small"), core_path); else if (core_size > 0xFFFF * GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("The size of `%s' is too large"), core_path); + grub_util_error (_("the size of `%s' is too large"), core_path); core_img = grub_util_read_image (core_path); @@ -251,7 +251,7 @@ setup (const char *dir, grub_fs_t fs; fs = grub_fs_probe (dest_dev); if (! fs) - grub_util_error (_("Unable to identify a filesystem in %s; safety check can't be performed"), + grub_util_error (_("unable to identify a filesystem in %s; safety check can't be performed"), dest_dev->disk->name); if (! fs->reserved_first_sector) @@ -304,7 +304,7 @@ setup (const char *dir, bsd_part = -1; } else - grub_util_error (_("No DOS-style partitions found")); + grub_util_error (_("no DOS-style partitions found")); } else dos_part = bsd_part = -1; @@ -413,14 +413,14 @@ setup (const char *dir, unable_to_embed: if (must_embed) - grub_util_error (_("Embedding is not possible, but this is required when " - "the root device is on a RAID array or LVM volume.")); + grub_util_error (_("embedding is not possible, but this is required when " + "the root device is on a RAID array or LVM volume")); grub_util_warn (_("Embedding is not possible. GRUB can only be installed in this " "setup by using blocklists. However, blocklists are UNRELIABLE and " "its use is discouraged.")); if (! force) - grub_util_error (_("If you really want blocklists, use --force.")); + grub_util_error (_("if you really want blocklists, use --force")); /* Make sure that GRUB reads the identical image as the OS. */ tmp_img = xmalloc (core_size); @@ -495,7 +495,7 @@ unable_to_embed: } if (i == MAX_TRIES) - grub_util_error (_("Cannot read `%s' correctly"), core_path_dev); + grub_util_error (_("cannot read `%s' correctly"), core_path_dev); /* Clean out the blocklists. */ block = first_block; @@ -508,7 +508,7 @@ unable_to_embed: block--; if ((char *) block <= core_img) - grub_util_error (_("No terminator in the core image")); + grub_util_error (_("no terminator in the core image")); } /* Now read the core image to determine where the sectors are. */ @@ -519,13 +519,13 @@ unable_to_embed: file->read_hook = save_first_sector; if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("Failed to read the first sector of the core image")); + grub_util_error (_("failed to read the first sector of the core image")); block = first_block; file->read_hook = save_blocklists; if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE) != (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("Failed to read the rest sectors of the core image")); + grub_util_error (_("failed to read the rest sectors of the core image")); grub_file_close (file); @@ -544,7 +544,7 @@ unable_to_embed: grub_util_info ("opening the core image `%s'", core_path); fp = fopen (core_path, "r+b"); if (! fp) - grub_util_error (_("Cannot open `%s'"), core_path); + grub_util_error (_("cannot open `%s'"), core_path); grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp); fclose (fp); @@ -584,13 +584,13 @@ static void usage (int status) { if (status) - fprintf (stderr, _("Try ``%s --help'' for more information.\n"), program_name); + fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); else printf (_("\ Usage: grub-setup [OPTION]... DEVICE\n\ \n\ Set up images to boot from DEVICE.\n\ -DEVICE must be a GRUB device (e.g. ``(hd0,1)'').\n\ +DEVICE must be a GRUB device (e.g. `(hd0,1)').\n\ \n\ -b, --boot-image=FILE use FILE as the boot image [default=%s]\n\ -c, --core-image=FILE use FILE as the core image [default=%s]\n\ @@ -751,7 +751,7 @@ main (int argc, char *argv[]) char *tmp = get_device_name (root_dev); if (! tmp) - grub_util_error (_("Invalid root device `%s'"), root_dev); + grub_util_error (_("invalid root device `%s'"), root_dev); tmp = xstrdup (tmp); free (root_dev); @@ -764,7 +764,7 @@ main (int argc, char *argv[]) { grub_util_info ("guessing the root device failed, because of `%s'", grub_errmsg); - grub_util_error (_("Cannot guess the root device. Specify the option ``--root-device''.")); + grub_util_error (_("cannot guess the root device. Specify the option `--root-device'")); } } diff --git a/util/ieee1275/ofpath.c b/util/ieee1275/ofpath.c index e90488fc3..79a0e8be5 100644 --- a/util/ieee1275/ofpath.c +++ b/util/ieee1275/ofpath.c @@ -131,12 +131,12 @@ block_device_get_sysfs_path_and_link(const char *devicenode, snprintf(sysfs_path, sysfs_path_len, "/sys/block/%s", devicenode); if (!realpath (sysfs_path, rpath)) - grub_util_error ("Cannot get the real path of `%s'", sysfs_path); + grub_util_error ("cannot get the real path of `%s'", sysfs_path); strcat(rpath, "/device"); if (!realpath (rpath, sysfs_path)) - grub_util_error ("Cannot get the real path of `%s'", rpath); + grub_util_error ("cannot get the real path of `%s'", rpath); free (rpath); } @@ -247,12 +247,12 @@ vendor_is_ATA(const char *path) snprintf(buf, PATH_MAX, "%s/vendor", path); fd = open(buf, O_RDONLY); if (fd < 0) - grub_util_error ("Cannot open 'vendor' node of `%s'", path); + grub_util_error ("cannot open 'vendor' node of `%s'", path); memset(buf, 0, PATH_MAX); err = read(fd, buf, PATH_MAX); if (err < 0) - grub_util_error ("Cannot read 'vendor' node of `%s'", path); + grub_util_error ("cannot read 'vendor' node of `%s'", path); close(fd); @@ -288,7 +288,7 @@ check_sas (char *sysfs_path, int *tgt) fd = open(path, O_RDONLY); if (fd < 0) - grub_util_error("Cannot open SAS PHY ID '%s'\n", path); + grub_util_error("cannot open SAS PHY ID `%s'\n", path); memset (phy, 0, sizeof (phy)); read (fd, phy, sizeof (phy)); @@ -375,7 +375,7 @@ grub_util_devname_to_ofpath (char *devname) name_buf = xmalloc (PATH_MAX); name_buf = realpath (devname, name_buf); if (! name_buf) - grub_util_error ("Cannot get the real path of `%s'", devname); + grub_util_error ("cannot get the real path of `%s'", devname); device = get_basename (devname); devnode = strip_trailing_digits (devname); diff --git a/util/misc.c b/util/misc.c index 47dd8c78d..7f347c872 100644 --- a/util/misc.c +++ b/util/misc.c @@ -60,11 +60,12 @@ grub_util_warn (const char *fmt, ...) { va_list ap; - fprintf (stderr, "%s: warn: ", program_name); + fprintf (stderr, _("%s: warn:"), program_name); + fprintf (stderr, " "); va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); - fputc ('\n', stderr); + fprintf (stderr, ".\n"); fflush (stderr); } @@ -75,11 +76,12 @@ grub_util_info (const char *fmt, ...) { va_list ap; - fprintf (stderr, "%s: info: ", program_name); + fprintf (stderr, _("%s: info:"), program_name); + fprintf (stderr, " "); va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); - fputc ('\n', stderr); + fprintf (".\n", stderr); fflush (stderr); } } @@ -89,11 +91,12 @@ grub_util_error (const char *fmt, ...) { va_list ap; - fprintf (stderr, "%s: error: ", program_name); + fprintf (stderr, _("%s: error:"), program_name); + fprintf (stderr, " "); va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); - fputc ('\n', stderr); + fprintf (stderr, ".\n"); exit (1); } diff --git a/util/mkisofs/eltorito.c b/util/mkisofs/eltorito.c index a134dfc48..1d2a715e0 100644 --- a/util/mkisofs/eltorito.c +++ b/util/mkisofs/eltorito.c @@ -288,7 +288,7 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc) struct eltorito_boot_info bi_table; bootimage = fopen (de->whole_name, "r+b"); if (bootimage == NULL) - error (1, errno, _("Error opening boot image file '%s' for update"), + error (1, errno, _("Error opening boot image file `%s' for update"), de->whole_name); /* Compute checksum of boot image, sans 64 bytes */ total_len = 0; @@ -296,7 +296,7 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc) while ((len = fread (csum_buffer, 1, SECTOR_SIZE, bootimage)) > 0) { if (total_len & 3) - error (1, 0, _("Odd alignment at non-end-of-file in boot image '%s'"), + error (1, 0, _("Odd alignment at non-end-of-file in boot image `%s'"), de->whole_name); if (total_len < 64) memset (csum_buffer, 0, 64 - total_len); @@ -308,7 +308,7 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc) } if (total_len != de->size) - error (1, 0, _("Boot image file '%s' changed unexpectedly"), + error (1, 0, _("Boot image file `%s' changed unexpectedly"), de->whole_name); /* End of file, set position to byte 8 */ fseeko (bootimage, (off_t) 8, SEEK_SET); diff --git a/util/mkisofs/rock.c b/util/mkisofs/rock.c index f18b0bd83..a7a39f774 100644 --- a/util/mkisofs/rock.c +++ b/util/mkisofs/rock.c @@ -306,7 +306,7 @@ int deep_opt; * the symbolic link won't fit into one SL System Use Field * print an error message and continue with splited one */ - fprintf (stderr, _("symbolic link ``%s'' too long for one SL System Use Field, splitting"), cpnt); + fprintf (stderr, _("symbolic link `%s' too long for one SL System Use Field, splitting"), cpnt); } if(MAYBE_ADD_CE_ENTRY(SL_SIZE + sl_bytes)) add_CE_entry(); } diff --git a/util/mkisofs/write.c b/util/mkisofs/write.c index 5447229c8..e1cdd213e 100644 --- a/util/mkisofs/write.c +++ b/util/mkisofs/write.c @@ -158,7 +158,7 @@ void FDECL4(xfwrite, void *, buffer, uint64_t, count, uint64_t, size, FILE *, fi sprintf(nbuf, "%s_%02d", outfile, idx++); file = freopen(nbuf, "wb", file); if (file == NULL) - error (1, errno, _("Cannot open '%s'"), nbuf); + error (1, errno, _("Cannot open `%s'"), nbuf); } while(count) diff --git a/util/raid.c b/util/raid.c index 83a0ee6e2..ec3ecd26e 100644 --- a/util/raid.c +++ b/util/raid.c @@ -50,7 +50,7 @@ grub_util_getdiskname (int major, int minor) else if (major == SCSI_DISK0_MAJOR) sprintf (name, "/dev/sd%c", 'a' + minor / 16); else - grub_util_error ("Unknown device number: %d, %d", major, minor); + grub_util_error ("unknown device number: %d, %d", major, minor); return name; } @@ -72,7 +72,7 @@ grub_util_raid_getmembers (char *name) fd = open (devname, O_RDONLY); if (fd == -1) - grub_util_error ("Can't open %s: %s", devname, strerror (errno)); + grub_util_error ("can't open %s: %s", devname, strerror (errno)); free (devname); @@ -81,7 +81,7 @@ grub_util_raid_getmembers (char *name) grub_util_error ("ioctl RAID_VERSION error: %s", strerror (errno)); if (version.major != 0 || version.minor != 90) - grub_util_error ("Unsupported RAID version: %d.%d", + grub_util_error ("unsupported RAID version: %d.%d", version.major, version.minor); ret = ioctl (fd, GET_ARRAY_INFO, &info); diff --git a/util/sparc64/ieee1275/grub-mkimage.c b/util/sparc64/ieee1275/grub-mkimage.c index 96ddfe3d7..6907b8d8a 100644 --- a/util/sparc64/ieee1275/grub-mkimage.c +++ b/util/sparc64/ieee1275/grub-mkimage.c @@ -191,7 +191,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTION]... [MODULES]\n\ diff --git a/util/sparc64/ieee1275/grub-setup.c b/util/sparc64/ieee1275/grub-setup.c index 9d8e67562..c39ea853f 100644 --- a/util/sparc64/ieee1275/grub-setup.c +++ b/util/sparc64/ieee1275/grub-setup.c @@ -161,7 +161,7 @@ setup (const char *prefix, const char *dir, grub_util_info ("first sector is <%llu,%u,%u>", sector, offset, length); if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE) - grub_util_error ("The first sector of the core file " + grub_util_error ("the first sector of the core file " "is not sector-aligned"); first_sector = sector; @@ -176,7 +176,7 @@ setup (const char *prefix, const char *dir, grub_util_info ("saving <%llu,%u,%u>", sector, offset, length); if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE) - grub_util_error ("Non-sector-aligned data is found in the core file"); + grub_util_error ("non-sector-aligned data is found in the core file"); if (block != first_block && (grub_be_to_cpu64 (prev->start) @@ -189,7 +189,7 @@ setup (const char *prefix, const char *dir, block--; if (block->len) - grub_util_error ("The sectors of the core file are too fragmented"); + grub_util_error ("the sectors of the core file are too fragmented"); } last_length = length; @@ -201,7 +201,7 @@ setup (const char *prefix, const char *dir, boot_path = grub_util_get_path (dir, boot_file); boot_size = grub_util_get_image_size (boot_path); if (boot_size != GRUB_DISK_SECTOR_SIZE) - grub_util_error ("The size of `%s' is not %d", + grub_util_error ("the size of `%s' is not %d", boot_path, GRUB_DISK_SECTOR_SIZE); boot_img = grub_util_read_image (boot_path); free (boot_path); @@ -219,7 +219,7 @@ setup (const char *prefix, const char *dir, core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); if (core_size < GRUB_DISK_SECTOR_SIZE) - grub_util_error ("The size of `%s' is too small", core_path); + grub_util_error ("the size of `%s' is too small", core_path); core_img = grub_util_read_image (core_path); free (core_path); @@ -229,7 +229,7 @@ setup (const char *prefix, const char *dir, + GRUB_DISK_SECTOR_SIZE - sizeof (*block)); - grub_util_info ("root is '%s', dest is '%s', and dest_ofpath is '%s'", + grub_util_info ("root is `%s', dest is `%s', and dest_ofpath is `%s'", root, dest, dest_ofpath); /* Open the root device and the destination device. */ @@ -320,7 +320,7 @@ setup (const char *prefix, const char *dir, } if (i == MAX_TRIES) - grub_util_error ("Cannot read `%s' correctly", core_path); + grub_util_error ("cannot read `%s' correctly", core_path); /* Clean out the blocklists. */ block = first_block; @@ -332,7 +332,7 @@ setup (const char *prefix, const char *dir, block--; if ((char *) block <= core_img) - grub_util_error ("No terminator in the core image"); + grub_util_error ("no terminator in the core image"); } /* Now read the core image to determine where the sectors are. */ @@ -343,13 +343,13 @@ setup (const char *prefix, const char *dir, file->read_hook = save_first_sector; if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE) - grub_util_error ("Failed to read the first sector of the core image"); + grub_util_error ("failed to read the first sector of the core image"); block = first_block; file->read_hook = save_blocklists; if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE) != (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE) - grub_util_error ("Failed to read the rest sectors of the core image"); + grub_util_error ("failed to read the rest sectors of the core image"); grub_file_close (file); @@ -368,7 +368,7 @@ setup (const char *prefix, const char *dir, grub_util_info ("opening the core image `%s'", core_path); fp = fopen (core_path, "r+b"); if (! fp) - grub_util_error ("Cannot open `%s'", core_path); + grub_util_error ("cannot open `%s'", core_path); grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE, fp); fclose (fp); @@ -404,13 +404,13 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTION]... DEVICE\n\ \n\ Set up images to boot from DEVICE.\n\ -DEVICE must be a GRUB device (e.g. ``(hd0,1)'').\n\ +DEVICE must be a GRUB device (e.g. `(hd0,1)').\n\ \n\ -b, --boot-image=FILE use FILE as the boot image [default=%s]\n\ -c, --core-image=FILE use FILE as the core image [default=%s]\n\ @@ -559,14 +559,14 @@ find_dest_dev (struct grub_setup_info *gp, char *argv[]) fprintf (stderr, "Invalid device `%s'.\n", argv[optind]); usage (1); } - grub_util_info ("transformed OS device '%s' into GRUB device '%s'", + grub_util_info ("transformed OS device `%s' into GRUB device `%s'", argv[optind], gp->dest_dev); } else { /* For simplicity. */ gp->dest_dev = xstrdup (gp->dest_dev); - grub_util_info ("Using '%s' as GRUB device", gp->dest_dev); + grub_util_info ("Using `%s' as GRUB device", gp->dest_dev); } } @@ -578,7 +578,7 @@ check_root_dev (struct grub_setup_info *gp) char *tmp = get_device_name (gp->root_dev); if (! tmp) - grub_util_error ("Invalid root device `%s'", gp->root_dev); + grub_util_error ("invalid root device `%s'", gp->root_dev); tmp = xstrdup (tmp); free (gp->root_dev); @@ -594,11 +594,11 @@ check_root_dev (struct grub_setup_info *gp) { grub_util_info ("guessing the root device failed, because of `%s'", grub_errmsg); - grub_util_error ("Cannot guess the root device. " - "Specify the option ``--root-device''."); + grub_util_error ("cannot guess the root device. " + "Specify the option `--root-device'"); } - grub_util_info ("Guessed root device '%s' and root_dev '%s' from " - "dir '%s'", root_device, gp->root_dev, dir); + grub_util_info ("guessed root device `%s' and root_dev `%s' from " + "dir `%s'", root_device, gp->root_dev, dir); } } From 409ae1c92a9eb99a653adc3dba377ae2ed7b024e Mon Sep 17 00:00:00 2001 From: carles Date: Sat, 16 Jan 2010 00:39:14 +0000 Subject: [PATCH 51/63] 2010-01-16 Carles Pina i Estany * util/grub-editenv.c (usage): Use `program_name' instead of hardcoded string. * util/grub-emu.c (usage): Likewise. * util/grub-mkpasswd-pbkdf2.c (usage): Likewise. * util/i386/efi/grub-mkimage.c (usage): Likewise. * util/i386/pc/grub-mkimage.c (usage): Likewise. * util/i386/pc/grub-setup.c (usage): Likewise. --- ChangeLog | 10 ++++++++++ util/grub-editenv.c | 6 +++--- util/grub-emu.c | 6 +++--- util/grub-mkpasswd-pbkdf2.c | 6 +++--- util/i386/efi/grub-mkimage.c | 6 +++--- util/i386/pc/grub-mkimage.c | 4 ++-- util/i386/pc/grub-setup.c | 3 ++- 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0effe5e10..793746986 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-01-16 Carles Pina i Estany + + * util/grub-editenv.c (usage): Use `program_name' instead of hardcoded + string. + * util/grub-emu.c (usage): Likewise. + * util/grub-mkpasswd-pbkdf2.c (usage): Likewise. + * util/i386/efi/grub-mkimage.c (usage): Likewise. + * util/i386/pc/grub-mkimage.c (usage): Likewise. + * util/i386/pc/grub-setup.c (usage): Likewise. + 2010-01-16 Carles Pina i Estany * util/misc.c (grub_util_warn): Gettextizze, print full stop after diff --git a/util/grub-editenv.c b/util/grub-editenv.c index ea0e4da19..f21042c97 100644 --- a/util/grub-editenv.c +++ b/util/grub-editenv.c @@ -69,10 +69,10 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try `grub-editenv --help' for more information.\n"); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ -Usage: grub-editenv [OPTIONS] [FILENAME] COMMAND\n\ +Usage: %s [OPTIONS] [FILENAME] COMMAND\n\ \n\ Tool to edit environment block.\n\ \nCommands:\n\ @@ -88,7 +88,7 @@ Tool to edit environment block.\n\ If not given explicitly, FILENAME defaults to %s.\n\ \n\ Report bugs to <%s>.\n", -DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG, PACKAGE_BUGREPORT); +program_name, DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG, PACKAGE_BUGREPORT); exit (status); } diff --git a/util/grub-emu.c b/util/grub-emu.c index a04aeae78..21fc6fa09 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -129,10 +129,10 @@ usage (int status) { if (status) fprintf (stderr, - "Try `grub-emu --help' for more information.\n"); + "Try `%s --help' for more information.\n", program_name); else printf ( - "Usage: grub-emu [OPTION]...\n" + "Usage: %s [OPTION]...\n" "\n" "GRUB emulator.\n" "\n" @@ -144,7 +144,7 @@ usage (int status) " -h, --help display this message and exit\n" " -V, --version print version information and exit\n" "\n" - "Report bugs to <%s>.\n", DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); + "Report bugs to <%s>.\n", program_name, DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); return status; } diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c index f5fdcca96..82437fdca 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -74,16 +74,16 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try `grub-scrypt --help' for more information.\n"); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ -Usage: grub-scrypt [OPTIONS]\n\ +Usage: %s [OPTIONS]\n\ \nOptions:\n\ -c number, --iteration-count=number Number of PBKDF2 iterations\n\ -l number, --buflen=number Length of generated hash\n\ -s number, --salt=number Length of salt\n\ \n\ -Report bugs to <%s>.\n", PACKAGE_BUGREPORT); +Report bugs to <%s>.\n", program_name, PACKAGE_BUGREPORT); exit (status); } diff --git a/util/i386/efi/grub-mkimage.c b/util/i386/efi/grub-mkimage.c index 8fee3e8d9..f8c0f152e 100644 --- a/util/i386/efi/grub-mkimage.c +++ b/util/i386/efi/grub-mkimage.c @@ -1029,10 +1029,10 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try `grub-mkimage --help' for more information.\n"); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ -Usage: grub-mkimage -o FILE [OPTION]... [MODULES]\n\ +Usage: %s -o FILE [OPTION]... [MODULES]\n\ \n\ Make a bootable image of GRUB.\n\ \n\ @@ -1044,7 +1044,7 @@ Make a bootable image of GRUB.\n\ -v, --verbose print verbose messages\n\ \n\ Report bugs to <%s>.\n\ -", GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); +", program_name, GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); exit (status); } diff --git a/util/i386/pc/grub-mkimage.c b/util/i386/pc/grub-mkimage.c index 08807b4d1..16b2c6619 100644 --- a/util/i386/pc/grub-mkimage.c +++ b/util/i386/pc/grub-mkimage.c @@ -329,7 +329,7 @@ usage (int status) fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); else printf (_("\ -Usage: grub-mkimage [OPTION]... [MODULES]\n\ +Usage: %s [OPTION]... [MODULES]\n\ \n\ Make a bootable image of GRUB.\n\ \n\ @@ -343,7 +343,7 @@ Make a bootable image of GRUB.\n\ -v, --verbose print verbose messages\n\ \n\ Report bugs to <%s>.\n\ -"), GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); +"), program_name, GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); exit (status); } diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 64b017296..4e2517ef2 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -587,7 +587,7 @@ usage (int status) fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); else printf (_("\ -Usage: grub-setup [OPTION]... DEVICE\n\ +Usage: %s [OPTION]... DEVICE\n\ \n\ Set up images to boot from DEVICE.\n\ DEVICE must be a GRUB device (e.g. `(hd0,1)').\n\ @@ -605,6 +605,7 @@ DEVICE must be a GRUB device (e.g. `(hd0,1)').\n\ \n\ Report bugs to <%s>.\n\ "), + program_name, DEFAULT_BOOT_FILE, DEFAULT_CORE_FILE, DEFAULT_DIRECTORY, DEFAULT_DEVICE_MAP, PACKAGE_BUGREPORT); From e15c215ebd8df7096d114e84167b25a19f0fd9d0 Mon Sep 17 00:00:00 2001 From: Felix Zielcke Date: Sat, 16 Jan 2010 11:57:47 +0100 Subject: [PATCH 52/63] =?UTF-8?q?2010-01-16=20=20Gr=C3=A9goire=20Sutre=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * genmk.rb (class SCRIPT): Replace option -i of sed by a pipe. --- ChangeLog | 4 ++++ genmk.rb | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 793746986..e71c4ec0e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-16 Grégoire Sutre + + * genmk.rb (class SCRIPT): Replace option -i of sed by a pipe. + 2010-01-16 Carles Pina i Estany * util/grub-editenv.c (usage): Use `program_name' instead of hardcoded diff --git a/genmk.rb b/genmk.rb index 810a2f1be..afd1582aa 100644 --- a/genmk.rb +++ b/genmk.rb @@ -370,8 +370,7 @@ class Script "CLEANFILES += #{@name} #{@name}: #{src} $(#{src}_DEPENDENCIES) config.status - ./config.status --file=#{name}:#{src} - sed -i -e 's,@pkglib_DATA@,$(pkglib_DATA),g' $@ + ./config.status --file=-:#{src} | sed -e 's,@pkglib_DATA@,$(pkglib_DATA),g' > $@ chmod +x $@ " From ea379330f97a1a2157bb5165a94d72fb83d3ca29 Mon Sep 17 00:00:00 2001 From: carles Date: Sun, 17 Jan 2010 14:42:19 +0000 Subject: [PATCH 53/63] 2010-01-17 Carles Pina i Estany * util/misc.c (grub_util_info): Fix the order of the parameters in a fprintf call. --- ChangeLog | 5 +++++ util/misc.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e71c4ec0e..748a55565 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-17 Carles Pina i Estany + + * util/misc.c (grub_util_info): Fix the order of the parameters in a + fprintf call. + 2010-01-16 Grégoire Sutre * genmk.rb (class SCRIPT): Replace option -i of sed by a pipe. diff --git a/util/misc.c b/util/misc.c index 7f347c872..0b682c445 100644 --- a/util/misc.c +++ b/util/misc.c @@ -81,7 +81,7 @@ grub_util_info (const char *fmt, ...) va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); - fprintf (".\n", stderr); + fprintf (stderr, ".\n"); fflush (stderr); } } From a0c2a0f6ff17b99fc8de9a0e13dbdae31ba1533a Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 17 Jan 2010 17:29:57 +0000 Subject: [PATCH 54/63] 2010-01-17 Robert Millan * include/grub/test.h: Add license header. * tests/example_functional_test.c: Likewise. * tests/example_unit_test.c: Likewise. * tests/lib/functional_test.c: Likewise. * tests/lib/test.c: Likewise. * tests/lib/unit_test.c: Likewise. --- ChangeLog | 9 +++++++++ include/grub/test.h | 18 ++++++++++++++++++ tests/example_functional_test.c | 18 ++++++++++++++++++ tests/example_unit_test.c | 18 ++++++++++++++++++ tests/lib/functional_test.c | 18 ++++++++++++++++++ tests/lib/test.c | 18 ++++++++++++++++++ tests/lib/unit_test.c | 18 ++++++++++++++++++ 7 files changed, 117 insertions(+) diff --git a/ChangeLog b/ChangeLog index 41f9aeaa4..9ef3d3d42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-01-17 Robert Millan + + * include/grub/test.h: Add license header. + * tests/example_functional_test.c: Likewise. + * tests/example_unit_test.c: Likewise. + * tests/lib/functional_test.c: Likewise. + * tests/lib/test.c: Likewise. + * tests/lib/unit_test.c: Likewise. + 2010-01-17 Vladimir Serbinenko Use flag-based instead of hook-based video mode selection and "auto" diff --git a/include/grub/test.h b/include/grub/test.h index 544e1c817..a7d3a2399 100644 --- a/include/grub/test.h +++ b/include/grub/test.h @@ -1,3 +1,21 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + #ifndef GRUB_TEST_HEADER #define GRUB_TEST_HEADER diff --git a/tests/example_functional_test.c b/tests/example_functional_test.c index 475d1c7f0..f43c0f1ce 100644 --- a/tests/example_functional_test.c +++ b/tests/example_functional_test.c @@ -1,3 +1,21 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + /* All tests need to include test.h for GRUB testing framework. */ #include diff --git a/tests/example_unit_test.c b/tests/example_unit_test.c index e2fad06ff..4999f1412 100644 --- a/tests/example_unit_test.c +++ b/tests/example_unit_test.c @@ -1,3 +1,21 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + /* Unit tests are normal programs, so they can include C library. */ #include diff --git a/tests/lib/functional_test.c b/tests/lib/functional_test.c index 8ad034503..8ff08cf8a 100644 --- a/tests/lib/functional_test.c +++ b/tests/lib/functional_test.c @@ -1,3 +1,21 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + #include #include #include diff --git a/tests/lib/test.c b/tests/lib/test.c index aba2f4415..cd0799f56 100644 --- a/tests/lib/test.c +++ b/tests/lib/test.c @@ -1,3 +1,21 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + #include #include #include diff --git a/tests/lib/unit_test.c b/tests/lib/unit_test.c index 2ca011433..e461150de 100644 --- a/tests/lib/unit_test.c +++ b/tests/lib/unit_test.c @@ -1,3 +1,21 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + #include #include #include From 8040619d881d40059292ff7e8f92882eea77ac7d Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 07:49:50 +0000 Subject: [PATCH 55/63] 2010-01-18 Robert Millan * include/grub/i386/linux.h (GRUB_VIDEO_TYPE_TEXT): Rename to ... (GRUB_VIDEO_LINUX_TYPE_TEXT): ... this. Update all users. (GRUB_VIDEO_TYPE_VLFB): Rename to ... (GRUB_VIDEO_LINUX_TYPE_VESA): ... this. Update all users. (GRUB_VIDEO_TYPE_EFI): Rename to ... (GRUB_VIDEO_LINUX_TYPE_SIMPLE): ... this. Update all users. --- ChangeLog | 9 +++++++++ include/grub/i386/linux.h | 6 +++--- loader/i386/efi/linux.c | 4 ++-- loader/i386/linux.c | 6 +++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9ef3d3d42..a53cf9279 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-01-18 Robert Millan + + * include/grub/i386/linux.h (GRUB_VIDEO_TYPE_TEXT): Rename to ... + (GRUB_VIDEO_LINUX_TYPE_TEXT): ... this. Update all users. + (GRUB_VIDEO_TYPE_VLFB): Rename to ... + (GRUB_VIDEO_LINUX_TYPE_VESA): ... this. Update all users. + (GRUB_VIDEO_TYPE_EFI): Rename to ... + (GRUB_VIDEO_LINUX_TYPE_SIMPLE): ... this. Update all users. + 2010-01-17 Robert Millan * include/grub/test.h: Add license header. diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h index 8a5a84da3..f02a722d6 100644 --- a/include/grub/i386/linux.h +++ b/include/grub/i386/linux.h @@ -79,9 +79,9 @@ struct grub_e820_mmap grub_uint32_t type; } __attribute__((packed)); -#define GRUB_VIDEO_TYPE_TEXT 0x01 -#define GRUB_VIDEO_TYPE_VLFB 0x23 /* VESA VGA in graphic mode */ -#define GRUB_VIDEO_TYPE_EFI 0x70 +#define GRUB_VIDEO_LINUX_TYPE_TEXT 0x01 +#define GRUB_VIDEO_LINUX_TYPE_VESA 0x23 /* VESA VGA in graphic mode. */ +#define GRUB_VIDEO_LINUX_TYPE_SIMPLE 0x70 /* Linear framebuffer without any additional functions. */ /* For the Linux/i386 boot protocol version 2.03. */ struct linux_kernel_header diff --git a/loader/i386/efi/linux.c b/loader/i386/efi/linux.c index 1abcc06db..2e26f3929 100644 --- a/loader/i386/efi/linux.c +++ b/loader/i386/efi/linux.c @@ -587,7 +587,7 @@ grub_linux_setup_video (struct linux_kernel_params *params) params->reserved_mask_size = 8; params->reserved_field_pos = 24; - params->have_vga = GRUB_VIDEO_TYPE_VLFB; + params->have_vga = GRUB_VIDEO_LINUX_TYPE_VESA; params->vid_mode = 0x338; /* 1024x768x32 */ return 0; @@ -852,7 +852,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), else if (grub_memcmp (argv[i], "video=efifb", 11) == 0) { if (params->have_vga) - params->have_vga = GRUB_VIDEO_TYPE_EFI; + params->have_vga = GRUB_VIDEO_LINUX_TYPE_SIMPLE; } /* Specify the boot file. */ diff --git a/loader/i386/linux.c b/loader/i386/linux.c index 7712bf2bf..a81e84135 100644 --- a/loader/i386/linux.c +++ b/loader/i386/linux.c @@ -538,16 +538,16 @@ grub_linux_boot (void) } if (! grub_linux_setup_video (params)) - params->have_vga = GRUB_VIDEO_TYPE_VLFB; + params->have_vga = GRUB_VIDEO_LINUX_TYPE_VESA; else { - params->have_vga = GRUB_VIDEO_TYPE_TEXT; + params->have_vga = GRUB_VIDEO_LINUX_TYPE_TEXT; params->video_width = 80; params->video_height = 25; } /* Initialize these last, because terminal position could be affected by printfs above. */ - if (params->have_vga == GRUB_VIDEO_TYPE_TEXT) + if (params->have_vga == GRUB_VIDEO_LINUX_TYPE_TEXT) { grub_term_output_t term; int found = 0; From 2997c41ffd1bb3c27e9ed3dd0b3ae25da4986e39 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Mon, 18 Jan 2010 16:58:31 +0530 Subject: [PATCH 56/63] update copyright year --- util/grub-script-check.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/grub-script-check.c b/util/grub-script-check.c index bfb44c511..3bfd6a425 100644 --- a/util/grub-script-check.c +++ b/util/grub-script-check.c @@ -1,7 +1,7 @@ /* grub-script-check.c - check grub script file for syntax errors */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From 88d170128f13c6cd31c9e164fe6bc656d94ffb7c Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 13:45:40 +0000 Subject: [PATCH 57/63] 2010-01-18 Robert Millan Fix annoying UI bug in rescue mode. Thanks to Tristan Gingold for spotting it back in 2008. Shame on me for forgetting he did. * kern/rescue_reader.c (grub_rescue_run): Skip zero-length lines. --- ChangeLog | 7 +++++++ kern/rescue_reader.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a53cf9279..df7f90587 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-01-18 Robert Millan + + Fix annoying UI bug in rescue mode. Thanks to Tristan Gingold for + spotting it back in 2008. Shame on me for forgetting he did. + + * kern/rescue_reader.c (grub_rescue_run): Skip zero-length lines. + 2010-01-18 Robert Millan * include/grub/i386/linux.h (GRUB_VIDEO_TYPE_TEXT): Rename to ... diff --git a/kern/rescue_reader.c b/kern/rescue_reader.c index 732124b1a..f573cf41f 100644 --- a/kern/rescue_reader.c +++ b/kern/rescue_reader.c @@ -1,7 +1,7 @@ /* rescue_reader.c - rescue mode reader */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. + * Copyright (C) 2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -83,7 +83,7 @@ grub_rescue_run (void) grub_errno = GRUB_ERR_NONE; grub_rescue_read_line (&line, 0); - if (! line) + if (! line || line[0] == '\0') continue; grub_parser_get_current ()->parse_line (line, grub_rescue_read_line); From a2eaee157c8ccab8e7200fe1fb248dcf8dd74218 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Mon, 18 Jan 2010 19:49:19 +0530 Subject: [PATCH 58/63] Add missing ChangeLog entry for -r2078 --- ChangeLog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index df7f90587..963d91514 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-01-18 BVK Chaitanya + + Added new tool, grub-scrit-check to verify grub.cfg syntax. + + * util/grub-script-check.c: grub-script-check tool. + * conf/common.rmk: Make rules for grub-script-check. + 2010-01-18 Robert Millan Fix annoying UI bug in rescue mode. Thanks to Tristan Gingold for From 2cb6be4bc2f0b4e5ab366116698451f2d862c899 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 16:08:25 +0000 Subject: [PATCH 59/63] 2010-01-18 Robert Millan * loader/i386/efi/linux.c (grub_cmd_linux): Stop pretending we're ELILO. This is no longer necessary. --- ChangeLog | 5 +++++ loader/i386/efi/linux.c | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 963d91514..f44ecc714 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-18 Robert Millan + + * loader/i386/efi/linux.c (grub_cmd_linux): Stop pretending we're + ELILO. This is no longer necessary. + 2010-01-18 BVK Chaitanya Added new tool, grub-scrit-check to verify grub.cfg syntax. diff --git a/loader/i386/efi/linux.c b/loader/i386/efi/linux.c index 2e26f3929..053c3ed22 100644 --- a/loader/i386/efi/linux.c +++ b/loader/i386/efi/linux.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -676,8 +676,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } - /* XXX Linux assumes that only elilo can boot Linux on EFI!!! */ - params->type_of_loader = (LINUX_LOADER_ID_ELILO << 4); + params->type_of_loader = (LINUX_LOADER_ID_GRUB << 4); params->cl_magic = GRUB_LINUX_CL_MAGIC; params->cl_offset = 0x1000; From b2cab848777f66daa9fab089575805639d9eb213 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 16:22:03 +0000 Subject: [PATCH 60/63] 2010-01-18 Robert Millan * acinclude.m4: Remove `nop' assembly instruction; it's not implemented by all architectures. --- ChangeLog | 5 +++++ acinclude.m4 | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f44ecc714..8d117a5c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-18 Robert Millan + + * acinclude.m4: Remove `nop' assembly instruction; it's not + implemented by all architectures. + 2010-01-18 Robert Millan * loader/i386/efi/linux.c (grub_cmd_linux): Stop pretending we're diff --git a/acinclude.m4 b/acinclude.m4 index 6f9baf18f..36a3b3e08 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -18,7 +18,7 @@ AC_DEFUN(grub_PROG_TARGET_CC, [AC_MSG_CHECKING([whether target compiler is working]) AC_CACHE_VAL(grub_cv_prog_target_cc, [AC_LINK_IFELSE([AC_LANG_PROGRAM([[ -asm (".globl start; start: nop"); +asm (".globl start; start:"); int main (void); ]], [[]])], [grub_cv_prog_target_cc=yes], From 262bff8d83bed88171cc2002d700a6bae75ba885 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 18 Jan 2010 17:40:23 +0100 Subject: [PATCH 61/63] 2010-01-18 Vladimir Serbinenko Add missing *BSD copyright headers. * include/grub/aout.h: Add BSD licence. * include/grub/i386/bsd.h: Parts under different licences moved to ... * include/grub/i386/freebsd_linker.h: ... here, * include/grub/i386/freebsd_reboot.h: ... here, * include/grub/i386/netbsd_bootinfo.h: ... here, * include/grub/i386/netbsd_reboot.h: ... here, * include/grub/i386/openbsd_bootarg.h: ... here, * include/grub/i386/openbsd_reboot.h: ... and here. Added appropriate licence to each file. --- ChangeLog | 14 ++ include/grub/aout.h | 32 +++++ include/grub/i386/bsd.h | 193 ++-------------------------- include/grub/i386/freebsd_linker.h | 74 +++++++++++ include/grub/i386/freebsd_reboot.h | 77 +++++++++++ include/grub/i386/netbsd_bootinfo.h | 112 ++++++++++++++++ include/grub/i386/netbsd_reboot.h | 81 ++++++++++++ include/grub/i386/openbsd_bootarg.h | 72 +++++++++++ include/grub/i386/openbsd_reboot.h | 79 ++++++++++++ 9 files changed, 553 insertions(+), 181 deletions(-) create mode 100644 include/grub/i386/freebsd_linker.h create mode 100644 include/grub/i386/freebsd_reboot.h create mode 100644 include/grub/i386/netbsd_bootinfo.h create mode 100644 include/grub/i386/netbsd_reboot.h create mode 100644 include/grub/i386/openbsd_bootarg.h create mode 100644 include/grub/i386/openbsd_reboot.h diff --git a/ChangeLog b/ChangeLog index 8d117a5c4..633ebd62a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2010-01-18 Vladimir Serbinenko + + Add missing *BSD copyright headers. + + * include/grub/aout.h: Add BSD licence. + * include/grub/i386/bsd.h: Parts under different licences moved to ... + * include/grub/i386/freebsd_linker.h: ... here, + * include/grub/i386/freebsd_reboot.h: ... here, + * include/grub/i386/netbsd_bootinfo.h: ... here, + * include/grub/i386/netbsd_reboot.h: ... here, + * include/grub/i386/openbsd_bootarg.h: ... here, + * include/grub/i386/openbsd_reboot.h: ... and here. Added appropriate + licence to each file. + 2010-01-18 Robert Millan * acinclude.m4: Remove `nop' assembly instruction; it's not diff --git a/include/grub/aout.h b/include/grub/aout.h index c5650ddf8..04e85f8b0 100644 --- a/include/grub/aout.h +++ b/include/grub/aout.h @@ -16,6 +16,38 @@ * along with GRUB. If not, see . */ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)exec.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD$ + */ + #ifndef GRUB_AOUT_HEADER #define GRUB_AOUT_HEADER 1 diff --git a/include/grub/i386/bsd.h b/include/grub/i386/bsd.h index 8ffaf7d18..53db09e61 100644 --- a/include/grub/i386/bsd.h +++ b/include/grub/i386/bsd.h @@ -20,6 +20,13 @@ #define GRUB_BSD_CPU_HEADER 1 #include +#include +#include +#include +#include +#include +#include + enum bsd_kernel_types { @@ -31,62 +38,15 @@ enum bsd_kernel_types #define GRUB_BSD_TEMP_BUFFER 0x80000 -#define FREEBSD_RB_ASKNAME (1 << 0) /* ask for file name to reboot from */ -#define FREEBSD_RB_SINGLE (1 << 1) /* reboot to single user only */ -#define FREEBSD_RB_NOSYNC (1 << 2) /* dont sync before reboot */ -#define FREEBSD_RB_HALT (1 << 3) /* don't reboot, just halt */ -#define FREEBSD_RB_INITNAME (1 << 4) /* name given for /etc/init (unused) */ -#define FREEBSD_RB_DFLTROOT (1 << 5) /* use compiled-in rootdev */ -#define FREEBSD_RB_KDB (1 << 6) /* give control to kernel debugger */ -#define FREEBSD_RB_RDONLY (1 << 7) /* mount root fs read-only */ -#define FREEBSD_RB_DUMP (1 << 8) /* dump kernel memory before reboot */ -#define FREEBSD_RB_MINIROOT (1 << 9) /* mini-root present in memory at boot time */ -#define FREEBSD_RB_CONFIG (1 << 10) /* invoke user configuration routing */ -#define FREEBSD_RB_VERBOSE (1 << 11) /* print all potentially useful info */ -#define FREEBSD_RB_SERIAL (1 << 12) /* user serial port as console */ -#define FREEBSD_RB_CDROM (1 << 13) /* use cdrom as root */ -#define FREEBSD_RB_GDB (1 << 15) /* use GDB remote debugger instead of DDB */ -#define FREEBSD_RB_MUTE (1 << 16) /* Come up with the console muted */ -#define FREEBSD_RB_PAUSE (1 << 20) -#define FREEBSD_RB_QUIET (1 << 21) -#define FREEBSD_RB_NOINTR (1 << 28) -#define FREENSD_RB_MULTIPLE (1 << 29) /* Use multiple consoles */ -#define FREEBSD_RB_DUAL FREENSD_RB_MULTIPLE -#define FREEBSD_RB_BOOTINFO (1 << 31) /* have `struct bootinfo *' arg */ - -#define FREEBSD_B_DEVMAGIC 0xa0000000 -#define FREEBSD_B_SLICESHIFT 20 -#define FREEBSD_B_UNITSHIFT 16 -#define FREEBSD_B_PARTSHIFT 8 -#define FREEBSD_B_TYPESHIFT 0 +#define FREEBSD_B_DEVMAGIC OPENBSD_B_DEVMAGIC +#define FREEBSD_B_SLICESHIFT OPENBSD_B_CTRLSHIFT +#define FREEBSD_B_UNITSHIFT OPENBSD_B_UNITSHIFT +#define FREEBSD_B_PARTSHIFT OPENBSD_B_PARTSHIFT +#define FREEBSD_B_TYPESHIFT OPENBSD_B_TYPESHIFT #define FREEBSD_BOOTINFO_VERSION 1 #define FREEBSD_N_BIOS_GEOM 8 -#define FREEBSD_MODINFO_END 0x0000 /* End of list */ -#define FREEBSD_MODINFO_NAME 0x0001 /* Name of module (string) */ -#define FREEBSD_MODINFO_TYPE 0x0002 /* Type of module (string) */ -#define FREEBSD_MODINFO_ADDR 0x0003 /* Loaded address */ -#define FREEBSD_MODINFO_SIZE 0x0004 /* Size of module */ -#define FREEBSD_MODINFO_EMPTY 0x0005 /* Has been deleted */ -#define FREEBSD_MODINFO_ARGS 0x0006 /* Parameters string */ -#define FREEBSD_MODINFO_METADATA 0x8000 /* Module-specfic */ - -#define FREEBSD_MODINFOMD_AOUTEXEC 0x0001 /* a.out exec header */ -#define FREEBSD_MODINFOMD_ELFHDR 0x0002 /* ELF header */ -#define FREEBSD_MODINFOMD_SSYM 0x0003 /* start of symbols */ -#define FREEBSD_MODINFOMD_ESYM 0x0004 /* end of symbols */ -#define FREEBSD_MODINFOMD_DYNAMIC 0x0005 /* _DYNAMIC pointer */ -#define FREEBSD_MODINFOMD_ENVP 0x0006 /* envp[] */ -#define FREEBSD_MODINFOMD_HOWTO 0x0007 /* boothowto */ -#define FREEBSD_MODINFOMD_KERNEND 0x0008 /* kernend */ -#define FREEBSD_MODINFOMD_SHDR 0x0009 /* section header table */ -#define FREEBSD_MODINFOMD_NOCOPY 0x8000 /* don't copy this metadata to the kernel */ - -#define FREEBSD_MODINFOMD_SMAP 0x1001 - -#define FREEBSD_MODINFOMD_DEPLIST (0x4001 | FREEBSD_MODINFOMD_NOCOPY) /* depends on */ - #define FREEBSD_MODTYPE_KERNEL "elf kernel" #define FREEBSD_MODTYPE_KERNEL64 "elf64 kernel" #define FREEBSD_MODTYPE_ELF_MODULE "elf module" @@ -113,44 +73,6 @@ struct grub_freebsd_bootinfo grub_uint32_t bi_modulep; } __attribute__ ((packed)); -#define OPENBSD_RB_ASKNAME (1 << 0) /* ask for file name to reboot from */ -#define OPENBSD_RB_SINGLE (1 << 1) /* reboot to single user only */ -#define OPENBSD_RB_NOSYNC (1 << 2) /* dont sync before reboot */ -#define OPENBSD_RB_HALT (1 << 3) /* don't reboot, just halt */ -#define OPENBSD_RB_INITNAME (1 << 4) /* name given for /etc/init (unused) */ -#define OPENBSD_RB_DFLTROOT (1 << 5) /* use compiled-in rootdev */ -#define OPENBSD_RB_KDB (1 << 6) /* give control to kernel debugger */ -#define OPENBSD_RB_RDONLY (1 << 7) /* mount root fs read-only */ -#define OPENBSD_RB_DUMP (1 << 8) /* dump kernel memory before reboot */ -#define OPENBSD_RB_MINIROOT (1 << 9) /* mini-root present in memory at boot time */ -#define OPENBSD_RB_CONFIG (1 << 10) /* change configured devices */ -#define OPENBSD_RB_TIMEBAD (1 << 11) /* don't call resettodr() in boot() */ -#define OPENBSD_RB_POWERDOWN (1 << 12) /* attempt to power down machine */ -#define OPENBSD_RB_SERCONS (1 << 13) /* use serial console if available */ -#define OPENBSD_RB_USERREQ (1 << 14) /* boot() called at user request (e.g. ddb) */ - -#define OPENBSD_B_DEVMAGIC 0xa0000000 -#define OPENBSD_B_ADAPTORSHIFT 24 -#define OPENBSD_B_CTRLSHIFT 20 -#define OPENBSD_B_UNITSHIFT 16 -#define OPENBSD_B_PARTSHIFT 8 -#define OPENBSD_B_TYPESHIFT 0 - -#define OPENBSD_BOOTARG_APIVER (OPENBSD_BAPIV_VECTOR | \ - OPENBSD_BAPIV_ENV | \ - OPENBSD_BAPIV_BMEMMAP) - -#define OPENBSD_BAPIV_ANCIENT 0x0 /* MD old i386 bootblocks */ -#define OPENBSD_BAPIV_VARS 0x1 /* MD structure w/ add info passed */ -#define OPENBSD_BAPIV_VECTOR 0x2 /* MI vector of MD structures passed */ -#define OPENBSD_BAPIV_ENV 0x4 /* MI environment vars vector */ -#define OPENBSD_BAPIV_BMEMMAP 0x8 /* MI memory map passed is in bytes */ - -#define OPENBSD_BOOTARG_ENV 0x1000 -#define OPENBSD_BOOTARG_END -1 - -#define OPENBSD_BOOTARG_MMAP 0 - struct grub_openbsd_bios_mmap { grub_uint64_t addr; @@ -162,97 +84,6 @@ struct grub_openbsd_bios_mmap grub_uint32_t type; }; -struct grub_openbsd_bootargs -{ - int ba_type; - int ba_size; - struct grub_openbsd_bootargs *ba_next; -} __attribute__ ((packed)); - -#define NETBSD_RB_AUTOBOOT 0 /* flags for system auto-booting itself */ - -#define NETBSD_RB_ASKNAME (1 << 0) /* ask for file name to reboot from */ -#define NETBSD_RB_SINGLE (1 << 1) /* reboot to single user only */ -#define NETBSD_RB_NOSYNC (1 << 2) /* dont sync before reboot */ -#define NETBSD_RB_HALT (1 << 3) /* don't reboot, just halt */ -#define NETBSD_RB_INITNAME (1 << 4) /* name given for /etc/init (unused) */ -#define NETBSD_RB_UNUSED1 (1 << 5) /* was RB_DFLTROOT, obsolete */ -#define NETBSD_RB_KDB (1 << 6) /* give control to kernel debugger */ -#define NETBSD_RB_RDONLY (1 << 7) /* mount root fs read-only */ -#define NETBSD_RB_DUMP (1 << 8) /* dump kernel memory before reboot */ -#define NETBSD_RB_MINIROOT (1 << 9) /* mini-root present in memory at boot time */ -#define NETBSD_RB_STRING (1 << 10) /* use provided bootstr */ -#define NETBSD_RB_POWERDOWN ((1 << 11) | RB_HALT) /* turn power off (or at least halt) */ -#define NETBSD_RB_USERCONFIG (1 << 12) /* change configured devices */ - -#define NETBSD_AB_NORMAL 0 /* boot normally (default) */ - -#define NETBSD_AB_QUIET (1 << 16) /* boot quietly */ -#define NETBSD_AB_VERBOSE (1 << 17) /* boot verbosely */ -#define NETBSD_AB_SILENT (1 << 18) /* boot silently */ -#define NETBSD_AB_DEBUG (1 << 19) /* boot with debug messages */ -#define NETBSD_AB_NOSMP (1 << 28) /* Boot without SMP support. */ -#define NETBSD_AB_NOACPI (1 << 29) /* Boot without ACPI support. */ - -struct grub_netbsd_bootinfo -{ - grub_uint32_t bi_count; - void *bi_data[1]; -}; - -#define NETBSD_BTINFO_BOOTPATH 0 -#define NETBSD_BTINFO_ROOTDEVICE 1 -#define NETBSD_BTINFO_BOOTDISK 3 -#define NETBSD_BTINFO_MEMMAP 9 - -struct grub_netbsd_btinfo_common -{ - int len; - int type; -}; - -struct grub_netbsd_btinfo_mmap_header -{ - struct grub_netbsd_btinfo_common common; - grub_uint32_t count; -}; - -struct grub_netbsd_btinfo_mmap_entry -{ - grub_uint64_t addr; - grub_uint64_t len; -#define NETBSD_MMAP_AVAILABLE 1 -#define NETBSD_MMAP_RESERVED 2 -#define NETBSD_MMAP_ACPI 3 -#define NETBSD_MMAP_NVS 4 - grub_uint32_t type; -}; - -struct grub_netbsd_btinfo_bootpath -{ - struct grub_netbsd_btinfo_common common; - char bootpath[80]; -}; - -struct grub_netbsd_btinfo_rootdevice -{ - struct grub_netbsd_btinfo_common common; - char devname[16]; -}; - -struct grub_netbsd_btinfo_bootdisk -{ - struct grub_netbsd_btinfo_common common; - int labelsector; /* label valid if != -1 */ - struct - { - grub_uint16_t type, checksum; - char packname[16]; - } label; - int biosdev; - int partition; -}; - void grub_unix_real_boot (grub_addr_t entry, ...) __attribute__ ((cdecl,noreturn)); grub_err_t grub_freebsd_load_elfmodule32 (grub_file_t file, int argc, diff --git a/include/grub/i386/freebsd_linker.h b/include/grub/i386/freebsd_linker.h new file mode 100644 index 000000000..3c1eb64b6 --- /dev/null +++ b/include/grub/i386/freebsd_linker.h @@ -0,0 +1,74 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +/*- + * Copyright (c) 1997-2000 Doug Rabson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: stable/8/sys/sys/linker.h 199583 2009-11-20 15:27:52Z jhb $ + */ + +#ifndef GRUB_FREEBSD_LINKER_CPU_HEADER +#define GRUB_FREEBSD_LINKER_CPU_HEADER 1 + +#define FREEBSD_MODINFO_END 0x0000 /* End of list */ +#define FREEBSD_MODINFO_NAME 0x0001 /* Name of module (string) */ +#define FREEBSD_MODINFO_TYPE 0x0002 /* Type of module (string) */ +#define FREEBSD_MODINFO_ADDR 0x0003 /* Loaded address */ +#define FREEBSD_MODINFO_SIZE 0x0004 /* Size of module */ +#define FREEBSD_MODINFO_EMPTY 0x0005 /* Has been deleted */ +#define FREEBSD_MODINFO_ARGS 0x0006 /* Parameters string */ +#define FREEBSD_MODINFO_METADATA 0x8000 /* Module-specfic */ + +#define FREEBSD_MODINFOMD_AOUTEXEC 0x0001 /* a.out exec header */ +#define FREEBSD_MODINFOMD_ELFHDR 0x0002 /* ELF header */ +#define FREEBSD_MODINFOMD_SSYM 0x0003 /* start of symbols */ +#define FREEBSD_MODINFOMD_ESYM 0x0004 /* end of symbols */ +#define FREEBSD_MODINFOMD_DYNAMIC 0x0005 /* _DYNAMIC pointer */ +#define FREEBSD_MODINFOMD_ENVP 0x0006 /* envp[] */ +#define FREEBSD_MODINFOMD_HOWTO 0x0007 /* boothowto */ +#define FREEBSD_MODINFOMD_KERNEND 0x0008 /* kernend */ +#define FREEBSD_MODINFOMD_SHDR 0x0009 /* section header table */ +#define FREEBSD_MODINFOMD_NOCOPY 0x8000 /* don't copy this metadata to the kernel */ + +#define FREEBSD_MODINFOMD_SMAP 0x1001 + +#define FREEBSD_MODINFOMD_DEPLIST (0x4001 | FREEBSD_MODINFOMD_NOCOPY) /* depends on */ + +#endif diff --git a/include/grub/i386/freebsd_reboot.h b/include/grub/i386/freebsd_reboot.h new file mode 100644 index 000000000..9c17f6efa --- /dev/null +++ b/include/grub/i386/freebsd_reboot.h @@ -0,0 +1,77 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +/*- + * Copyright (c) 1982, 1986, 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)reboot.h 8.3 (Berkeley) 12/13/94 + * $FreeBSD: stable/8/sys/sys/reboot.h 199583 2009-11-20 15:27:52Z jhb $ + */ + +#ifndef GRUB_FREEBSD_REBOOT_CPU_HEADER +#define GRUB_FREEBSD_REBOOT_CPU_HEADER 1 + +#define FREEBSD_RB_ASKNAME (1 << 0) /* ask for file name to reboot from */ +#define FREEBSD_RB_SINGLE (1 << 1) /* reboot to single user only */ +#define FREEBSD_RB_NOSYNC (1 << 2) /* dont sync before reboot */ +#define FREEBSD_RB_HALT (1 << 3) /* don't reboot, just halt */ +#define FREEBSD_RB_INITNAME (1 << 4) /* name given for /etc/init (unused) */ +#define FREEBSD_RB_DFLTROOT (1 << 5) /* use compiled-in rootdev */ +#define FREEBSD_RB_KDB (1 << 6) /* give control to kernel debugger */ +#define FREEBSD_RB_RDONLY (1 << 7) /* mount root fs read-only */ +#define FREEBSD_RB_DUMP (1 << 8) /* dump kernel memory before reboot */ +#define FREEBSD_RB_MINIROOT (1 << 9) /* mini-root present in memory at boot time */ +#define FREEBSD_RB_CONFIG (1 << 10) /* invoke user configuration routing */ +#define FREEBSD_RB_VERBOSE (1 << 11) /* print all potentially useful info */ +#define FREEBSD_RB_SERIAL (1 << 12) /* user serial port as console */ +#define FREEBSD_RB_CDROM (1 << 13) /* use cdrom as root */ +#define FREEBSD_RB_GDB (1 << 15) /* use GDB remote debugger instead of DDB */ +#define FREEBSD_RB_MUTE (1 << 16) /* Come up with the console muted */ +#define FREEBSD_RB_PAUSE (1 << 20) +#define FREEBSD_RB_QUIET (1 << 21) +#define FREEBSD_RB_NOINTR (1 << 28) +#define FREENSD_RB_MULTIPLE (1 << 29) /* Use multiple consoles */ +#define FREEBSD_RB_DUAL FREENSD_RB_MULTIPLE +#define FREEBSD_RB_BOOTINFO (1 << 31) /* have `struct bootinfo *' arg */ + +#endif diff --git a/include/grub/i386/netbsd_bootinfo.h b/include/grub/i386/netbsd_bootinfo.h new file mode 100644 index 000000000..776ecf3b0 --- /dev/null +++ b/include/grub/i386/netbsd_bootinfo.h @@ -0,0 +1,112 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +/* $NetBSD: bootinfo.h,v 1.16 2009/08/24 02:15:46 jmcneill Exp $ */ + +/* + * Copyright (c) 1997 + * Matthias Drochner. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRUB_NETBSD_BOOTINFO_CPU_HEADER +#define GRUB_NETBSD_BOOTINFO_CPU_HEADER 1 + +#include + + +#define NETBSD_BTINFO_BOOTPATH 0 +#define NETBSD_BTINFO_ROOTDEVICE 1 +#define NETBSD_BTINFO_BOOTDISK 3 +#define NETBSD_BTINFO_MEMMAP 9 + +struct grub_netbsd_btinfo_common +{ + int len; + int type; +}; + +struct grub_netbsd_btinfo_mmap_header +{ + struct grub_netbsd_btinfo_common common; + grub_uint32_t count; +}; + +struct grub_netbsd_btinfo_mmap_entry +{ + grub_uint64_t addr; + grub_uint64_t len; +#define NETBSD_MMAP_AVAILABLE 1 +#define NETBSD_MMAP_RESERVED 2 +#define NETBSD_MMAP_ACPI 3 +#define NETBSD_MMAP_NVS 4 + grub_uint32_t type; +}; + +struct grub_netbsd_btinfo_bootpath +{ + struct grub_netbsd_btinfo_common common; + char bootpath[80]; +}; + +struct grub_netbsd_btinfo_rootdevice +{ + struct grub_netbsd_btinfo_common common; + char devname[16]; +}; + +struct grub_netbsd_btinfo_bootdisk +{ + struct grub_netbsd_btinfo_common common; + int labelsector; /* label valid if != -1 */ + struct + { + grub_uint16_t type, checksum; + char packname[16]; + } label; + int biosdev; + int partition; +}; + +struct grub_netbsd_bootinfo +{ + grub_uint32_t bi_count; + void *bi_data[1]; +}; + +#endif diff --git a/include/grub/i386/netbsd_reboot.h b/include/grub/i386/netbsd_reboot.h new file mode 100644 index 000000000..ee82455bc --- /dev/null +++ b/include/grub/i386/netbsd_reboot.h @@ -0,0 +1,81 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +/* $NetBSD: reboot.h,v 1.25 2007/12/25 18:33:48 perry Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)reboot.h 8.3 (Berkeley) 12/13/94 + */ + +#ifndef GRUB_NETBSD_REBOOT_CPU_HEADER +#define GRUB_NETBSD_REBOOT_CPU_HEADER 1 + +#define NETBSD_RB_AUTOBOOT 0 /* flags for system auto-booting itself */ + +#define NETBSD_RB_ASKNAME (1 << 0) /* ask for file name to reboot from */ +#define NETBSD_RB_SINGLE (1 << 1) /* reboot to single user only */ +#define NETBSD_RB_NOSYNC (1 << 2) /* dont sync before reboot */ +#define NETBSD_RB_HALT (1 << 3) /* don't reboot, just halt */ +#define NETBSD_RB_INITNAME (1 << 4) /* name given for /etc/init (unused) */ +#define NETBSD_RB_UNUSED1 (1 << 5) /* was RB_DFLTROOT, obsolete */ +#define NETBSD_RB_KDB (1 << 6) /* give control to kernel debugger */ +#define NETBSD_RB_RDONLY (1 << 7) /* mount root fs read-only */ +#define NETBSD_RB_DUMP (1 << 8) /* dump kernel memory before reboot */ +#define NETBSD_RB_MINIROOT (1 << 9) /* mini-root present in memory at boot time */ +#define NETBSD_RB_STRING (1 << 10) /* use provided bootstr */ +#define NETBSD_RB_POWERDOWN ((1 << 11) | RB_HALT) /* turn power off (or at least halt) */ +#define NETBSD_RB_USERCONFIG (1 << 12) /* change configured devices */ + +#define NETBSD_AB_NORMAL 0 /* boot normally (default) */ + +#define NETBSD_AB_QUIET (1 << 16) /* boot quietly */ +#define NETBSD_AB_VERBOSE (1 << 17) /* boot verbosely */ +#define NETBSD_AB_SILENT (1 << 18) /* boot silently */ +#define NETBSD_AB_DEBUG (1 << 19) /* boot with debug messages */ +#define NETBSD_AB_NOSMP (1 << 28) /* Boot without SMP support. */ +#define NETBSD_AB_NOACPI (1 << 29) /* Boot without ACPI support. */ + + +#endif diff --git a/include/grub/i386/openbsd_bootarg.h b/include/grub/i386/openbsd_bootarg.h new file mode 100644 index 000000000..ccbe1ca12 --- /dev/null +++ b/include/grub/i386/openbsd_bootarg.h @@ -0,0 +1,72 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +/* $OpenBSD: bootarg.h,v 1.11 2003/06/02 20:20:54 mickey Exp $ */ + +/* + * Copyright (c) 1996-1999 Michael Shalayeff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GRUB_OPENBSD_BOOTARG_CPU_HEADER +#define GRUB_OPENBSD_BOOTARG_CPU_HEADER 1 + +#define OPENBSD_BOOTARG_APIVER (OPENBSD_BAPIV_VECTOR | \ + OPENBSD_BAPIV_ENV | \ + OPENBSD_BAPIV_BMEMMAP) + +#define OPENBSD_BAPIV_ANCIENT 0x0 /* MD old i386 bootblocks */ +#define OPENBSD_BAPIV_VARS 0x1 /* MD structure w/ add info passed */ +#define OPENBSD_BAPIV_VECTOR 0x2 /* MI vector of MD structures passed */ +#define OPENBSD_BAPIV_ENV 0x4 /* MI environment vars vector */ +#define OPENBSD_BAPIV_BMEMMAP 0x8 /* MI memory map passed is in bytes */ + +#define OPENBSD_BOOTARG_ENV 0x1000 +#define OPENBSD_BOOTARG_END -1 + +#define OPENBSD_BOOTARG_MMAP 0 + +struct grub_openbsd_bootargs +{ + int ba_type; + int ba_size; + struct grub_openbsd_bootargs *ba_next; +} __attribute__ ((packed)); + +#endif diff --git a/include/grub/i386/openbsd_reboot.h b/include/grub/i386/openbsd_reboot.h new file mode 100644 index 000000000..3f6571a44 --- /dev/null +++ b/include/grub/i386/openbsd_reboot.h @@ -0,0 +1,79 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +/* $OpenBSD: reboot.h,v 1.13 2004/03/10 23:02:53 tom Exp $ */ +/* $NetBSD: reboot.h,v 1.9 1996/04/22 01:23:25 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)reboot.h 8.2 (Berkeley) 7/10/94 + */ + +#ifndef GRUB_OPENBSD_REBOOT_CPU_HEADER +#define GRUB_OPENBSD_REBOOT_CPU_HEADER 1 + +#define OPENBSD_RB_ASKNAME (1 << 0) /* ask for file name to reboot from */ +#define OPENBSD_RB_SINGLE (1 << 1) /* reboot to single user only */ +#define OPENBSD_RB_NOSYNC (1 << 2) /* dont sync before reboot */ +#define OPENBSD_RB_HALT (1 << 3) /* don't reboot, just halt */ +#define OPENBSD_RB_INITNAME (1 << 4) /* name given for /etc/init (unused) */ +#define OPENBSD_RB_DFLTROOT (1 << 5) /* use compiled-in rootdev */ +#define OPENBSD_RB_KDB (1 << 6) /* give control to kernel debugger */ +#define OPENBSD_RB_RDONLY (1 << 7) /* mount root fs read-only */ +#define OPENBSD_RB_DUMP (1 << 8) /* dump kernel memory before reboot */ +#define OPENBSD_RB_MINIROOT (1 << 9) /* mini-root present in memory at boot time */ +#define OPENBSD_RB_CONFIG (1 << 10) /* change configured devices */ +#define OPENBSD_RB_TIMEBAD (1 << 11) /* don't call resettodr() in boot() */ +#define OPENBSD_RB_POWERDOWN (1 << 12) /* attempt to power down machine */ +#define OPENBSD_RB_SERCONS (1 << 13) /* use serial console if available */ +#define OPENBSD_RB_USERREQ (1 << 14) /* boot() called at user request (e.g. ddb) */ + +#define OPENBSD_B_DEVMAGIC 0xa0000000 +#define OPENBSD_B_ADAPTORSHIFT 24 +#define OPENBSD_B_CTRLSHIFT 20 +#define OPENBSD_B_UNITSHIFT 16 +#define OPENBSD_B_PARTSHIFT 8 +#define OPENBSD_B_TYPESHIFT 0 + +#endif From 6f7db5d676bee808d78e9775747d06abebb280b6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 18 Jan 2010 19:25:20 +0100 Subject: [PATCH 62/63] 2010-01-18 Vladimir Serbinenko * include/grub/i386/bsd.h: Fix include pathes. --- ChangeLog | 4 ++++ include/grub/i386/bsd.h | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 633ebd62a..7b22a6aea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-18 Vladimir Serbinenko + + * include/grub/i386/bsd.h: Fix include pathes. + 2010-01-18 Vladimir Serbinenko Add missing *BSD copyright headers. diff --git a/include/grub/i386/bsd.h b/include/grub/i386/bsd.h index 53db09e61..e26c35652 100644 --- a/include/grub/i386/bsd.h +++ b/include/grub/i386/bsd.h @@ -20,12 +20,12 @@ #define GRUB_BSD_CPU_HEADER 1 #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include enum bsd_kernel_types From cba98e8dbc6744c7c947d7fa81949ec30f40442e Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 19:31:10 +0000 Subject: [PATCH 63/63] 2010-01-18 Robert Millan * commands/terminal.c (grub_cmd_terminal_input) (grub_cmd_terminal_output): Check return of terminal init() routines, and abort if errors are raised. --- ChangeLog | 6 ++++++ commands/terminal.c | 20 ++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b22a6aea..3111a9381 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-18 Robert Millan + + * commands/terminal.c (grub_cmd_terminal_input) + (grub_cmd_terminal_output): Check return of terminal init() + routines, and abort if errors are raised. + 2010-01-18 Vladimir Serbinenko * include/grub/i386/bsd.h: Fix include pathes. diff --git a/commands/terminal.c b/commands/terminal.c index b30f43130..bf4187180 100644 --- a/commands/terminal.c +++ b/commands/terminal.c @@ -112,10 +112,11 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), break; if (term) { + if (term->init && term->init () != GRUB_ERR_NONE) + return grub_errno; + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs_disabled)), GRUB_AS_LIST (term)); - if (term->init) - term->init (); grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); } @@ -152,10 +153,11 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), break; if (term) { + if (term->init && term->init () != GRUB_ERR_NONE) + return grub_errno; + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs_disabled)), GRUB_AS_LIST (term)); - if (term->init) - term->init (); grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); } @@ -269,10 +271,11 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), break; if (term) { + if (term->init && term->init () != GRUB_ERR_NONE) + return grub_errno; + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)), GRUB_AS_LIST (term)); - if (term->init) - term->init (); grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term)); } @@ -310,10 +313,11 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), break; if (term) { + if (term->init && term->init () != GRUB_ERR_NONE) + return grub_errno; + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)), GRUB_AS_LIST (term)); - if (term->init) - term->init (); grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term)); }