From 1f56d837883e066a8791af4c297bc809934e7409 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 Nov 2009 17:00:39 +0100 Subject: [PATCH 001/237] Initial reimport of double buffering --- ChangeLog.video | 31 ++++++ commands/minicmd.c | 1 - include/grub/video.h | 5 + include/grub/video_fb.h | 11 ++ kern/misc.c | 4 - kern/term.c | 1 + normal/cmdline.c | 10 +- term/gfxterm.c | 7 ++ video/fb/video_fb.c | 52 ++++++++++ video/i386/pc/vbe.c | 219 +++++++++++++++++++++++++++++++++++++--- 10 files changed, 318 insertions(+), 23 deletions(-) create mode 100644 ChangeLog.video diff --git a/ChangeLog.video b/ChangeLog.video new file mode 100644 index 000000000..c088b7f36 --- /dev/null +++ b/ChangeLog.video @@ -0,0 +1,31 @@ +2009-08-24 Colin D Bennett +2009-08-24 Vladimir Serbinenko + + Double buffering support. + + * commands/i386/pc/videotest.c (grub_cmd_videotest): Swap doublebuffers. + * include/grub/video.h: Update comment. + * include/grub/video_fb.h (grub_video_fb_doublebuf_update_screen_t): + New type. + (grub_video_fb_doublebuf_blit_init): New prototype. + * term/gfxterm.c (scroll_up): Support double buffering. + (grub_gfxterm_refresh): Likewise. + * video/fb/video_fb.c (doublebuf_blit_update_screen): New function. + (grub_video_fb_doublebuf_blit_init): Likewise. + * video/i386/pc/vbe.c (framebuffer): Remove 'render_target'. Add + 'front_target', 'back_target', 'offscreen_buffer', 'page_size', + 'displayed_page', 'render_page' and 'update_screen'. + (grub_video_vbe_fini): Free offscreen buffer. + (doublebuf_pageflipping_commit): New function. + (doublebuf_pageflipping_update_screen): Likewise. + (doublebuf_pageflipping_init): Likewise. + (double_buffering_init): Likewise. + (grub_video_vbe_setup): Enable doublebuffering. + (grub_video_vbe_swap_buffers): Implement. + (grub_video_vbe_set_active_render_target): Handle double buffering. + (grub_video_vbe_get_active_render_target): Likewise. + (grub_video_vbe_get_info_and_fini): Likewise. Free offscreen_buffer. + (grub_video_vbe_adapter): Use grub_video_vbe_get_active_render_target. + (grub_video_vbe_enable_double_buffering): Likewise. + (grub_video_vbe_swap_buffers): Use update_screen. + (grub_video_set_mode): Use double buffering. diff --git a/commands/minicmd.c b/commands/minicmd.c index 6c9c33a0e..7a1695838 100644 --- a/commands/minicmd.c +++ b/commands/minicmd.c @@ -315,7 +315,6 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)), grub_printf ("%s", dep->mod->name); } grub_putchar ('\n'); - grub_refresh (); return 0; } diff --git a/include/grub/video.h b/include/grub/video.h index 53fe67c4e..4f8b5cf7b 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -34,6 +34,9 @@ struct grub_video_render_target; struct grub_video_bitmap; /* Defines used to describe video mode or rendering target. */ +/* If following is set render target contains previously displayed image + after swapping buffers (otherwise it contains newly displayedd image). + */ #define GRUB_VIDEO_MODE_TYPE_PURE_TEXT 0x00000040 #define GRUB_VIDEO_MODE_TYPE_ALPHA 0x00000020 #define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED 0x00000010 @@ -48,6 +51,8 @@ struct grub_video_bitmap; #define GRUB_VIDEO_MODE_TYPE_DEPTH_MASK 0x0000ff00 #define GRUB_VIDEO_MODE_TYPE_DEPTH_POS 8 +/* The basic render target representing the whole display. This always + renders to the back buffer when double-buffering is in use. */ #define GRUB_VIDEO_RENDER_TARGET_DISPLAY \ ((struct grub_video_render_target *) 0) diff --git a/include/grub/video_fb.h b/include/grub/video_fb.h index 17debd69f..3046a597b 100644 --- a/include/grub/video_fb.h +++ b/include/grub/video_fb.h @@ -115,4 +115,15 @@ grub_video_fb_get_active_render_target (struct grub_video_fbrender_target **targ grub_err_t grub_video_fb_set_active_render_target (struct grub_video_fbrender_target *target); +typedef grub_err_t +(*grub_video_fb_doublebuf_update_screen_t) (struct grub_video_fbrender_target *front, + struct grub_video_fbrender_target *back); + +grub_err_t +grub_video_fb_doublebuf_blit_init (struct grub_video_fbrender_target **front, + struct grub_video_fbrender_target **back, + grub_video_fb_doublebuf_update_screen_t *update_screen, + struct grub_video_mode_info mode_info, + void *framebuf); + #endif /* ! GRUB_VIDEO_FB_HEADER */ diff --git a/kern/misc.c b/kern/misc.c index cacfbc753..38a5638b3 100644 --- a/kern/misc.c +++ b/kern/misc.c @@ -161,7 +161,6 @@ grub_vprintf (const char *fmt, va_list args) int ret; ret = grub_vsprintf (0, fmt, args); - grub_refresh (); return ret; } @@ -818,9 +817,6 @@ grub_vsprintf (char *str, const char *fmt, va_list args) if (str) *str = '\0'; - if (count && !str) - grub_refresh (); - return count; } diff --git a/kern/term.c b/kern/term.c index 94d5a9e1d..8c4e1e339 100644 --- a/kern/term.c +++ b/kern/term.c @@ -131,6 +131,7 @@ grub_getcharwidth (grub_uint32_t code) int grub_getkey (void) { + grub_refresh (); return (grub_cur_term_input->getkey) (); } diff --git a/normal/cmdline.c b/normal/cmdline.c index 7a5b6ec84..3816ce9d6 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -199,8 +199,6 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, xpos = (plen + lpos) % 79; ypos = ystart + (plen + lpos) / 79; grub_gotoxy (xpos, ypos); - - grub_refresh (); } void cl_print (int pos, int c) @@ -241,8 +239,6 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, cl_print (lpos - len, echo_char); cl_set_pos (); } - - grub_refresh (); } void cl_delete (unsigned len) @@ -262,8 +258,6 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, cl_print (lpos, echo_char); cl_set_pos (); } - - grub_refresh (); } plen = grub_strlen (prompt); @@ -283,6 +277,8 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, if (history && hist_used == 0) grub_history_add (buf); + grub_refresh (); + while ((key = GRUB_TERM_ASCII_CHAR (grub_getkey ())) != '\n' && key != '\r') { if (readline) @@ -457,6 +453,8 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, } break; } + + grub_refresh (); } grub_putchar ('\n'); diff --git a/term/gfxterm.c b/term/gfxterm.c index 57c51cffa..1a46a867d 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -124,6 +124,8 @@ static unsigned int calculate_normal_character_width (grub_font_t font); static unsigned char calculate_character_width (struct grub_font_glyph *glyph); +static void grub_gfxterm_refresh (void); + static void set_term_color (grub_uint8_t term_color) { @@ -815,6 +817,9 @@ grub_gfxterm_cls (void) /* Mark virtual screen to be redrawn. */ dirty_region_add_virtualscreen (); + + dirty_region_redraw (); + grub_gfxterm_refresh (); } static void @@ -877,6 +882,8 @@ grub_gfxterm_refresh (void) { /* Redraw only changed regions. */ dirty_region_redraw (); + + grub_video_swap_buffers (); } static grub_err_t diff --git a/video/fb/video_fb.c b/video/fb/video_fb.c index 5f2917da6..b7323b5b7 100644 --- a/video/fb/video_fb.c +++ b/video/fb/video_fb.c @@ -66,6 +66,8 @@ grub_video_fb_init (void) grub_err_t grub_video_fb_fini (void) { + /* TODO: destroy render targets. */ + grub_free (palette); render_target = 0; palette = 0; @@ -1182,3 +1184,53 @@ grub_video_fb_get_active_render_target (struct grub_video_fbrender_target **targ return GRUB_ERR_NONE; } + +static grub_err_t +doublebuf_blit_update_screen (struct grub_video_fbrender_target *front, + struct grub_video_fbrender_target *back) +{ + grub_memcpy (front->data, back->data, + front->mode_info.pitch * front->mode_info.height); + return GRUB_ERR_NONE; +} + +grub_err_t +grub_video_fb_doublebuf_blit_init (struct grub_video_fbrender_target **front, + struct grub_video_fbrender_target **back, + grub_video_fb_doublebuf_update_screen_t *update_screen, + struct grub_video_mode_info mode_info, + void *framebuf) +{ + grub_err_t err; + int page_size = mode_info.pitch * mode_info.height; + void *offscreen_buffer; + + err = grub_video_fb_create_render_target_from_pointer (front, &mode_info, + framebuf); + if (err) + return err; + + offscreen_buffer = grub_malloc (page_size); + if (! offscreen_buffer) + { + grub_video_fb_delete_render_target (*front); + *front = 0; + return grub_errno; + } + + err = grub_video_fb_create_render_target_from_pointer (back, &mode_info, + offscreen_buffer); + + if (err) + { + grub_video_fb_delete_render_target (*front); + grub_free (offscreen_buffer); + *front = 0; + return grub_errno; + } + (*back)->is_allocated = 1; + + *update_screen = doublebuf_blit_update_screen; + + return GRUB_ERR_NONE; +} diff --git a/video/i386/pc/vbe.c b/video/i386/pc/vbe.c index 8759ba652..f2c414a99 100644 --- a/video/i386/pc/vbe.c +++ b/video/i386/pc/vbe.c @@ -36,13 +36,25 @@ static struct grub_vbe_mode_info_block active_vbe_mode_info; static struct { struct grub_video_mode_info mode_info; - struct grub_video_render_target *render_target; + struct grub_video_render_target *front_target; + struct grub_video_render_target *back_target; unsigned int bytes_per_scan_line; unsigned int bytes_per_pixel; grub_uint32_t active_vbe_mode; grub_uint8_t *ptr; int index_color_mode; + + char *offscreen_buffer; + + grub_size_t page_size; /* The size of a page in bytes. */ + + /* For page flipping strategy. */ + int displayed_page; /* The page # that is the front buffer. */ + int render_page; /* The page # that is the back buffer. */ + + /* Virtual functions. */ + grub_video_fb_doublebuf_update_screen_t update_screen; } framebuffer; static grub_uint32_t initial_vbe_mode; @@ -344,6 +356,7 @@ static grub_err_t grub_video_vbe_fini (void) { grub_vbe_status_t status; + grub_err_t err; /* Restore old video mode. */ status = grub_vbe_bios_set_mode (initial_vbe_mode, 0); @@ -355,11 +368,170 @@ grub_video_vbe_fini (void) grub_free (vbe_mode_list); vbe_mode_list = NULL; - /* TODO: destroy render targets. */ - - return grub_video_fb_fini (); + err = grub_video_fb_fini (); + grub_free (framebuffer.offscreen_buffer); + return err; } +/* + Set framebuffer render target page and display the proper page, based on + `doublebuf_state.render_page' and `doublebuf_state.displayed_page', + respectively. +*/ +static grub_err_t +doublebuf_pageflipping_commit (void) +{ + /* Tell the video adapter to display the new front page. */ + int display_start_line + = framebuffer.mode_info.height * framebuffer.displayed_page; + + grub_vbe_status_t vbe_err = + grub_vbe_bios_set_display_start (0, display_start_line); + + if (vbe_err != GRUB_VBE_STATUS_OK) + return grub_error (GRUB_ERR_IO, "couldn't commit pageflip"); + + return 0; +} + +static grub_err_t +doublebuf_pageflipping_update_screen (struct grub_video_fbrender_target *front + __attribute__ ((unused)), + struct grub_video_fbrender_target *back + __attribute__ ((unused))) +{ + int new_displayed_page; + struct grub_video_fbrender_target *target; + grub_err_t err; + + /* Swap the page numbers in the framebuffer struct. */ + new_displayed_page = framebuffer.render_page; + framebuffer.render_page = framebuffer.displayed_page; + framebuffer.displayed_page = new_displayed_page; + + err = doublebuf_pageflipping_commit (); + if (err) + { + /* Restore previous state. */ + framebuffer.render_page = framebuffer.displayed_page; + framebuffer.displayed_page = new_displayed_page; + return err; + } + + grub_memcpy (framebuffer.ptr + framebuffer.render_page + * framebuffer.page_size, framebuffer.ptr + + framebuffer.displayed_page * framebuffer.page_size, + framebuffer.page_size); + + target = framebuffer.back_target; + framebuffer.back_target = framebuffer.front_target; + framebuffer.front_target = target; + + err = grub_video_fb_get_active_render_target (&target); + if (err) + return err; + + if (target == framebuffer.back_target) + err = grub_video_fb_set_active_render_target (framebuffer.front_target); + else if (target == framebuffer.front_target) + err = grub_video_fb_set_active_render_target (framebuffer.back_target); + + return err; +} + +static grub_err_t +doublebuf_pageflipping_init (void) +{ + /* Get video RAM size in bytes. */ + grub_size_t vram_size = controller_info.total_memory << 16; + grub_err_t err; + + framebuffer.page_size = + framebuffer.mode_info.pitch * framebuffer.mode_info.height; + + if (2 * framebuffer.page_size > vram_size) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, + "Not enough video memory for double buffering."); + + framebuffer.displayed_page = 0; + framebuffer.render_page = 1; + + framebuffer.update_screen = doublebuf_pageflipping_update_screen; + + err = grub_video_fb_create_render_target_from_pointer (&framebuffer.front_target, &framebuffer.mode_info, framebuffer.ptr); + if (err) + return err; + + err = grub_video_fb_create_render_target_from_pointer (&framebuffer.back_target, &framebuffer.mode_info, framebuffer.ptr + framebuffer.page_size); + if (err) + { + grub_video_fb_delete_render_target (framebuffer.front_target); + return err; + } + + /* Set the framebuffer memory data pointer and display the right page. */ + err = doublebuf_pageflipping_commit (); + if (err) + { + grub_video_fb_delete_render_target (framebuffer.front_target); + grub_video_fb_delete_render_target (framebuffer.back_target); + return err; + } + + return GRUB_ERR_NONE; +} + +/* Select the best double buffering mode available. */ +static grub_err_t +double_buffering_init (unsigned int mode_type, unsigned int mode_mask) +{ + grub_err_t err; + + if (grub_video_check_mode_flag (mode_type, mode_mask, + GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED, 1)) + { + err = doublebuf_pageflipping_init (); + if (!err) + { + framebuffer.mode_info.mode_type + |= GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED; + return GRUB_ERR_NONE; + } + + grub_errno = GRUB_ERR_NONE; + + err = grub_video_fb_doublebuf_blit_init (&framebuffer.front_target, + &framebuffer.back_target, + &framebuffer.update_screen, + framebuffer.mode_info, + framebuffer.ptr); + + if (!err) + { + framebuffer.mode_info.mode_type + |= GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED; + return GRUB_ERR_NONE; + } + + grub_errno = GRUB_ERR_NONE; + } + + /* Fall back to no double buffering. */ + err = grub_video_fb_create_render_target_from_pointer (&framebuffer.front_target, &framebuffer.mode_info, framebuffer.ptr); + + if (err) + return err; + + framebuffer.back_target = framebuffer.front_target; + framebuffer.update_screen = 0; + + framebuffer.mode_info.mode_type &= ~GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED; + + return GRUB_ERR_NONE; +} + + + static grub_err_t grub_video_vbe_setup (unsigned int width, unsigned int height, unsigned int mode_type, unsigned int mode_mask) @@ -488,12 +660,12 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info); - err = grub_video_fb_create_render_target_from_pointer (&framebuffer.render_target, &framebuffer.mode_info, framebuffer.ptr); - + /* Set up double buffering and targets. */ + err = double_buffering_init (mode_type, mode_mask); if (err) return err; - err = grub_video_fb_set_active_render_target (framebuffer.render_target); + err = grub_video_fb_set_active_render_target (framebuffer.back_target); if (err) return err; @@ -530,7 +702,15 @@ grub_video_vbe_set_palette (unsigned int start, unsigned int count, static grub_err_t grub_video_vbe_swap_buffers (void) { - /* TODO: Implement buffer swapping. */ + grub_err_t err; + if (!framebuffer.update_screen) + return GRUB_ERR_NONE; + + err = framebuffer.update_screen (framebuffer.front_target, + framebuffer.back_target); + if (err) + return err; + return GRUB_ERR_NONE; } @@ -538,27 +718,42 @@ static grub_err_t grub_video_vbe_set_active_render_target (struct grub_video_render_target *target) { if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY) - target = framebuffer.render_target; + target = framebuffer.back_target; return grub_video_fb_set_active_render_target (target); } +static grub_err_t +grub_video_vbe_get_active_render_target (struct grub_video_render_target **target) +{ + grub_err_t err; + err = grub_video_fb_get_active_render_target (target); + if (err) + return err; + + if (*target == framebuffer.back_target) + *target = GRUB_VIDEO_RENDER_TARGET_DISPLAY; + + return GRUB_ERR_NONE; +} + static grub_err_t grub_video_vbe_get_info_and_fini (struct grub_video_mode_info *mode_info, void **framebuf) { grub_memcpy (mode_info, &(framebuffer.mode_info), sizeof (*mode_info)); - *framebuf = (char *) framebuffer.ptr; + *framebuf = (char *) framebuffer.ptr + + framebuffer.displayed_page * framebuffer.page_size; grub_free (vbe_mode_list); vbe_mode_list = NULL; grub_video_fb_fini (); + grub_free (framebuffer.offscreen_buffer); return GRUB_ERR_NONE; } - static struct grub_video_adapter grub_video_vbe_adapter = { .name = "VESA BIOS Extension Video Driver", @@ -584,7 +779,7 @@ static struct grub_video_adapter grub_video_vbe_adapter = .create_render_target = grub_video_fb_create_render_target, .delete_render_target = grub_video_fb_delete_render_target, .set_active_render_target = grub_video_vbe_set_active_render_target, - .get_active_render_target = grub_video_fb_get_active_render_target, + .get_active_render_target = grub_video_vbe_get_active_render_target, .next = 0 }; From bbe73b09954b3d82a039c6a88bd5a58114354b13 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 Nov 2009 17:59:11 +0100 Subject: [PATCH 002/237] Improved performance by not requiring updating swap in gfxterm --- include/grub/video.h | 5 ++-- term/gfxterm.c | 55 +++++++++++++++++++++++++++++++------------- video/i386/pc/vbe.c | 50 ++++++++++++++++++++++++++++------------ 3 files changed, 77 insertions(+), 33 deletions(-) diff --git a/include/grub/video.h b/include/grub/video.h index 4f8b5cf7b..a1882f57b 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -34,9 +34,10 @@ struct grub_video_render_target; struct grub_video_bitmap; /* Defines used to describe video mode or rendering target. */ -/* If following is set render target contains previously displayed image - after swapping buffers (otherwise it contains newly displayedd image). +/* If following is set render target contains currenly displayed image + after swapping buffers (otherwise it contains previously displayed image). */ +#define GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP 0x00000080 #define GRUB_VIDEO_MODE_TYPE_PURE_TEXT 0x00000040 #define GRUB_VIDEO_MODE_TYPE_ALPHA 0x00000020 #define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED 0x00000010 diff --git a/term/gfxterm.c b/term/gfxterm.c index 1a46a867d..6906b77a1 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -474,8 +474,6 @@ dirty_region_redraw (void) height = dirty_region.bottom_right_y - y + 1; redraw_screen_rect (x, y, width, height); - - dirty_region_reset (); } static void @@ -566,9 +564,6 @@ scroll_up (void) { /* Remove cursor. */ draw_cursor (0); - - /* Redraw only changed regions. */ - dirty_region_redraw (); } /* Scroll text buffer with one line to up. */ @@ -584,28 +579,52 @@ scroll_up (void) i++) clear_char (&(virtual_screen.text_buffer[i])); - /* Scroll physical screen. */ - grub_video_set_active_render_target (text_layer); - color = virtual_screen.bg_color; - grub_video_scroll (color, 0, -virtual_screen.normal_char_height); - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); - /* If we have bitmap, re-draw screen, otherwise scroll physical screen too. */ if (bitmap) { + /* Scroll physical screen. */ + grub_video_set_active_render_target (text_layer); + color = virtual_screen.bg_color; + grub_video_scroll (color, 0, -virtual_screen.normal_char_height); + /* Mark virtual screen to be redrawn. */ dirty_region_add_virtualscreen (); } else { - /* Clear new border area. */ - grub_video_fill_rect (color, - virtual_screen.offset_x, virtual_screen.offset_y, - virtual_screen.width, virtual_screen.normal_char_height); + int i = 1; + if (mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED + && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP)) + i++; + + color = virtual_screen.bg_color; + + while (i--) + { + /* Clear new border area. */ + grub_video_fill_rect (color, + virtual_screen.offset_x, + virtual_screen.offset_y, + virtual_screen.width, + virtual_screen.normal_char_height); + + grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + dirty_region_redraw (); + + /* Scroll physical screen. */ + grub_video_scroll (color, 0, -virtual_screen.normal_char_height); + + if (i) + grub_video_swap_buffers (); + } + dirty_region_reset (); /* Scroll physical screen. */ + grub_video_set_active_render_target (text_layer); + color = virtual_screen.bg_color; grub_video_scroll (color, 0, -virtual_screen.normal_char_height); + /* Draw cursor if visible. */ if (virtual_screen.cursor_state) draw_cursor (1); @@ -818,7 +837,6 @@ grub_gfxterm_cls (void) /* Mark virtual screen to be redrawn. */ dirty_region_add_virtualscreen (); - dirty_region_redraw (); grub_gfxterm_refresh (); } @@ -884,6 +902,11 @@ grub_gfxterm_refresh (void) dirty_region_redraw (); grub_video_swap_buffers (); + + if (mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED + && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP)) + dirty_region_redraw (); + dirty_region_reset (); } static grub_err_t diff --git a/video/i386/pc/vbe.c b/video/i386/pc/vbe.c index f2c414a99..a039710a2 100644 --- a/video/i386/pc/vbe.c +++ b/video/i386/pc/vbe.c @@ -418,10 +418,11 @@ doublebuf_pageflipping_update_screen (struct grub_video_fbrender_target *front return err; } - grub_memcpy (framebuffer.ptr + framebuffer.render_page - * framebuffer.page_size, framebuffer.ptr - + framebuffer.displayed_page * framebuffer.page_size, - framebuffer.page_size); + if (framebuffer.mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP) + grub_memcpy (framebuffer.ptr + framebuffer.render_page + * framebuffer.page_size, framebuffer.ptr + + framebuffer.displayed_page * framebuffer.page_size, + framebuffer.page_size); target = framebuffer.back_target; framebuffer.back_target = framebuffer.front_target; @@ -486,19 +487,38 @@ static grub_err_t double_buffering_init (unsigned int mode_type, unsigned int mode_mask) { grub_err_t err; + int updating_swap_needed; + updating_swap_needed + = grub_video_check_mode_flag (mode_type, mode_mask, + GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP, 0); + + /* Do double buffering only if it's either requested or efficient. */ if (grub_video_check_mode_flag (mode_type, mode_mask, - GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED, 1)) + GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED, + !updating_swap_needed)) { + framebuffer.mode_info.mode_type |= GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED; + if (updating_swap_needed) + framebuffer.mode_info.mode_type |= GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP; err = doublebuf_pageflipping_init (); if (!err) - { - framebuffer.mode_info.mode_type - |= GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED; - return GRUB_ERR_NONE; - } + return GRUB_ERR_NONE; + + framebuffer.mode_info.mode_type + &= ~(GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED + | GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); grub_errno = GRUB_ERR_NONE; + } + + if (grub_video_check_mode_flag (mode_type, mode_mask, + GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED, + 0)) + { + framebuffer.mode_info.mode_type + |= (GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED + | GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); err = grub_video_fb_doublebuf_blit_init (&framebuffer.front_target, &framebuffer.back_target, @@ -507,11 +527,11 @@ double_buffering_init (unsigned int mode_type, unsigned int mode_mask) framebuffer.ptr); if (!err) - { - framebuffer.mode_info.mode_type - |= GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED; - return GRUB_ERR_NONE; - } + return GRUB_ERR_NONE; + + framebuffer.mode_info.mode_type + &= ~(GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED + | GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); grub_errno = GRUB_ERR_NONE; } From 85536ab717ff52e6d0b6e146811b923f367e1853 Mon Sep 17 00:00:00 2001 From: Colin D Bennet Date: Sat, 14 Nov 2009 23:11:55 +0100 Subject: [PATCH 003/237] 2009-11-14 Colin D Bennet Trigonometry support. * include/grub/trig.h: New file. * lib/trig.c: Likewise. * maintainance/gentrigtables.py: Likewise. * conf/common.rmk (pkglib_MODULES): Add trig.mod. (trig_mod_SOURCES): New variable. (trig_mod_CFLAGS): Likewise. (trig_mod_LDFLAGS): Likewise. --- conf/common.rmk | 6 +++ include/grub/trig.h | 44 +++++++++++++++++++ lib/trig.c | 83 +++++++++++++++++++++++++++++++++++ maintainance/gentrigtables.py | 58 ++++++++++++++++++++++++ 4 files changed, 191 insertions(+) create mode 100644 include/grub/trig.h create mode 100644 lib/trig.c create mode 100644 maintainance/gentrigtables.py diff --git a/conf/common.rmk b/conf/common.rmk index 3dddeb66d..4ec0dab1e 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -638,6 +638,12 @@ xnu_uuid_mod_SOURCES = commands/xnu_uuid.c xnu_uuid_mod_CFLAGS = $(COMMON_CFLAGS) xnu_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For trig.mod. +pkglib_MODULES += trig.mod +trig_mod_SOURCES = lib/trig.c +trig_mod_CFLAGS = $(COMMON_CFLAGS) +trig_mod_LDFLAGS = $(COMMON_LDFLAGS) + pkglib_MODULES += setjmp.mod setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS) diff --git a/include/grub/trig.h b/include/grub/trig.h new file mode 100644 index 000000000..2512a5f07 --- /dev/null +++ b/include/grub/trig.h @@ -0,0 +1,44 @@ +/* trig.h - Trigonometric function support. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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_TRIG_HEADER +#define GRUB_TRIG_HEADER 1 + +#define GRUB_TRIG_ANGLE_MAX 256 +#define GRUB_TRIG_ANGLE_MASK 255 +#define GRUB_TRIG_FRACTION_SCALE 16384 + +extern short grub_trig_sintab[]; +extern short grub_trig_costab[]; + +static __inline int +grub_sin (int x) +{ + x &= GRUB_TRIG_ANGLE_MASK; + return grub_trig_sintab[x]; +} + +static __inline int +grub_cos (int x) +{ + x &= GRUB_TRIG_ANGLE_MASK; + return grub_trig_costab[x]; +} + +#endif /* ! GRUB_TRIG_HEADER */ diff --git a/lib/trig.c b/lib/trig.c new file mode 100644 index 000000000..e36aa38ef --- /dev/null +++ b/lib/trig.c @@ -0,0 +1,83 @@ +/* trig.c - Trigonometric table definitions. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 + +/* These tables were generated with `gentrigtables.py'. */ + +short grub_trig_sintab[] = +{ + 0,402,804,1205,1606,2006,2404,2801,3196,3590, + 3981,4370,4756,5139,5520,5897,6270,6639,7005,7366, + 7723,8076,8423,8765,9102,9434,9760,10080,10394,10702, + 11003,11297,11585,11866,12140,12406,12665,12916,13160,13395, + 13623,13842,14053,14256,14449,14635,14811,14978,15137,15286, + 15426,15557,15679,15791,15893,15986,16069,16143,16207,16261, + 16305,16340,16364,16379,16384,16379,16364,16340,16305,16261, + 16207,16143,16069,15986,15893,15791,15679,15557,15426,15286, + 15137,14978,14811,14635,14449,14256,14053,13842,13623,13395, + 13160,12916,12665,12406,12140,11866,11585,11297,11003,10702, + 10394,10080,9760,9434,9102,8765,8423,8076,7723,7366, + 7005,6639,6270,5897,5520,5139,4756,4370,3981,3590, + 3196,2801,2404,2006,1606,1205,804,402,0,-402, + -804,-1205,-1606,-2006,-2404,-2801,-3196,-3590,-3981,-4370, + -4756,-5139,-5520,-5897,-6270,-6639,-7005,-7366,-7723,-8076, + -8423,-8765,-9102,-9434,-9760,-10080,-10394,-10702,-11003,-11297, + -11585,-11866,-12140,-12406,-12665,-12916,-13160,-13395,-13623,-13842, + -14053,-14256,-14449,-14635,-14811,-14978,-15137,-15286,-15426,-15557, + -15679,-15791,-15893,-15986,-16069,-16143,-16207,-16261,-16305,-16340, + -16364,-16379,-16384,-16379,-16364,-16340,-16305,-16261,-16207,-16143, + -16069,-15986,-15893,-15791,-15679,-15557,-15426,-15286,-15137,-14978, + -14811,-14635,-14449,-14256,-14053,-13842,-13623,-13395,-13160,-12916, + -12665,-12406,-12140,-11866,-11585,-11297,-11003,-10702,-10394,-10080, + -9760,-9434,-9102,-8765,-8423,-8076,-7723,-7366,-7005,-6639, + -6270,-5897,-5520,-5139,-4756,-4370,-3981,-3590,-3196,-2801, + -2404,-2006,-1606,-1205,-804,-402 +}; + +short grub_trig_costab[] = +{ + 16384,16379,16364,16340,16305,16261,16207,16143,16069,15986, + 15893,15791,15679,15557,15426,15286,15137,14978,14811,14635, + 14449,14256,14053,13842,13623,13395,13160,12916,12665,12406, + 12140,11866,11585,11297,11003,10702,10394,10080,9760,9434, + 9102,8765,8423,8076,7723,7366,7005,6639,6270,5897, + 5520,5139,4756,4370,3981,3590,3196,2801,2404,2006, + 1606,1205,804,402,0,-402,-804,-1205,-1606,-2006, + -2404,-2801,-3196,-3590,-3981,-4370,-4756,-5139,-5520,-5897, + -6270,-6639,-7005,-7366,-7723,-8076,-8423,-8765,-9102,-9434, + -9760,-10080,-10394,-10702,-11003,-11297,-11585,-11866,-12140,-12406, + -12665,-12916,-13160,-13395,-13623,-13842,-14053,-14256,-14449,-14635, + -14811,-14978,-15137,-15286,-15426,-15557,-15679,-15791,-15893,-15986, + -16069,-16143,-16207,-16261,-16305,-16340,-16364,-16379,-16384,-16379, + -16364,-16340,-16305,-16261,-16207,-16143,-16069,-15986,-15893,-15791, + -15679,-15557,-15426,-15286,-15137,-14978,-14811,-14635,-14449,-14256, + -14053,-13842,-13623,-13395,-13160,-12916,-12665,-12406,-12140,-11866, + -11585,-11297,-11003,-10702,-10394,-10080,-9760,-9434,-9102,-8765, + -8423,-8076,-7723,-7366,-7005,-6639,-6270,-5897,-5520,-5139, + -4756,-4370,-3981,-3590,-3196,-2801,-2404,-2006,-1606,-1205, + -804,-402,0,402,804,1205,1606,2006,2404,2801, + 3196,3590,3981,4370,4756,5139,5520,5897,6270,6639, + 7005,7366,7723,8076,8423,8765,9102,9434,9760,10080, + 10394,10702,11003,11297,11585,11866,12140,12406,12665,12916, + 13160,13395,13623,13842,14053,14256,14449,14635,14811,14978, + 15137,15286,15426,15557,15679,15791,15893,15986,16069,16143, + 16207,16261,16305,16340,16364,16379 +}; + diff --git a/maintainance/gentrigtables.py b/maintainance/gentrigtables.py new file mode 100644 index 000000000..7c069f833 --- /dev/null +++ b/maintainance/gentrigtables.py @@ -0,0 +1,58 @@ +#!/usr/bin/python +# Script to generate trigonometric function tables. +# +# GRUB -- GRand Unified Bootloader +# Copyright (C) 2008 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 . + +from math import * +from sys import stdout + +def write(x): + stdout.write(x) + +def writeTable(arr, name): + indent = ' ' * 4 + write("short ") + write(name) + write("[] =\n{\n") + write(indent) + for i in range(len(arr)): + if i != 0: + write(",") + if i % 10 == 0: + write("\n") + write(indent) + write("%d" % arr[i]) + write("\n};\n") + +def main(): + sintab = [] + costab = [] + for i in range(256): + # Convert to an angle in 1/256 of a circle. + x = i * 2 * pi / 256 + sintab.append(int(round(sin(x) * 16384))) + costab.append(int(round(cos(x) * 16384))) + + write("#define TRIG_ANGLE_MAX 256\n") + write("#define TRIG_FRACTION_SCALE 16384\n") + writeTable(sintab, "sintab") + writeTable(costab, "costab") + +if __name__ == "__main__": + main() + +# vim:ai et sw=4 ts=4 From c51a5caeab7dcbc9f9f49b923543bbb1645de70e Mon Sep 17 00:00:00 2001 From: Colin D Bennet Date: Sun, 15 Nov 2009 00:03:03 +0100 Subject: [PATCH 004/237] 2009-11-14 Colin D Bennet 2009-11-14 Vladimir Serbinenko Support for gfxterm in a window. * include/grub/gfxterm.h: New file. * include/grub/video.h (struct grub_video_rect): New declaration. (grub_video_rect_t): Likewise. * term/gfxterm.c (struct grub_gfxterm_window): New type. (refcount): New variable. (render_target): Likewise. (window): Likewise. (repaint_callback): Likewise. (grub_virtual_screen_setup): Use 'render_target'. (init_window): New function. (grub_gfxterm_init_window): Likewise. (grub_gfxterm_init): Check reference counter. Use init_window. (destroy_window): New function. (grub_gfxterm_destroy_window): Likewise. (grub_gfxterm_fini): Check reference counter. Use destroy_window. (redraw_screen_rect): Restore viewport. Use 'render_target' and 'window'. Call 'repaint_callback'. (write_char): Use 'render_target'. (draw_cursor): Likewise. (scroll_up): Restore viewport. Use 'render_target' and 'window'. Call 'repaint_callback'. (grub_gfxterm_cls): Likewise. (grub_gfxterm_refresh): Use 'window'. (grub_gfxterm_set_repaint_callback): New function. (grub_gfxterm_background_image_cmd): Use 'window'. (grub_gfxterm_get_term): New function. (GRUB_MOD_INIT(term_gfxterm)): Set 'refcount' to 0. Also-By: Vladimir Serbinenko --- ChangeLog.gfxtermwindow | 36 +++++++ include/grub/gfxterm.h | 42 ++++++++ include/grub/video.h | 10 ++ term/gfxterm.c | 226 ++++++++++++++++++++++++++++++++-------- 4 files changed, 269 insertions(+), 45 deletions(-) create mode 100644 ChangeLog.gfxtermwindow create mode 100644 include/grub/gfxterm.h diff --git a/ChangeLog.gfxtermwindow b/ChangeLog.gfxtermwindow new file mode 100644 index 000000000..d23038ba7 --- /dev/null +++ b/ChangeLog.gfxtermwindow @@ -0,0 +1,36 @@ +2009-11-14 Colin D Bennet +2009-11-14 Vladimir Serbinenko + + Support for gfxterm in a window. + + * include/grub/gfxterm.h: New file. + * include/grub/video.h (struct grub_video_rect): New declaration. + (grub_video_rect_t): Likewise. + * term/gfxterm.c (struct grub_gfxterm_window): New type. + (refcount): New variable. + (render_target): Likewise. + (window): Likewise. + (repaint_callback): Likewise. + (grub_virtual_screen_setup): Use 'render_target'. + (init_window): New function. + (grub_gfxterm_init_window): Likewise. + (grub_gfxterm_init): Check reference counter. + Use init_window. + (destroy_window): New function. + (grub_gfxterm_destroy_window): Likewise. + (grub_gfxterm_fini): Check reference counter. + Use destroy_window. + (redraw_screen_rect): Restore viewport. + Use 'render_target' and 'window'. + Call 'repaint_callback'. + (write_char): Use 'render_target'. + (draw_cursor): Likewise. + (scroll_up): Restore viewport. + Use 'render_target' and 'window'. + Call 'repaint_callback'. + (grub_gfxterm_cls): Likewise. + (grub_gfxterm_refresh): Use 'window'. + (grub_gfxterm_set_repaint_callback): New function. + (grub_gfxterm_background_image_cmd): Use 'window'. + (grub_gfxterm_get_term): New function. + (GRUB_MOD_INIT(term_gfxterm)): Set 'refcount' to 0. diff --git a/include/grub/gfxterm.h b/include/grub/gfxterm.h new file mode 100644 index 000000000..e607bd5e1 --- /dev/null +++ b/include/grub/gfxterm.h @@ -0,0 +1,42 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2006,2007,2008 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_GFXTERM_HEADER +#define GRUB_GFXTERM_HEADER 1 + +#include +#include +#include +#include + +grub_err_t +grub_gfxterm_init_window (struct grub_video_render_target *target, + int x, int y, int width, int height, + int double_repaint, + const char *font_name, int border_width); + +void grub_gfxterm_destroy_window (void); + +const struct grub_term_output *grub_gfxterm_get_term (void); + +typedef void (*grub_gfxterm_repaint_callback_t)(int x, int y, + int width, int height); + +void grub_gfxterm_set_repaint_callback (grub_gfxterm_repaint_callback_t func); + +#endif /* ! GRUB_GFXTERM_HEADER */ diff --git a/include/grub/video.h b/include/grub/video.h index a1882f57b..833df04c8 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -157,6 +157,16 @@ struct grub_video_mode_info grub_uint8_t fg_alpha; }; +/* A 2D rectangle type. */ +struct grub_video_rect +{ + int x; + int y; + int width; + int height; +}; +typedef struct grub_video_rect grub_video_rect_t; + struct grub_video_palette_data { grub_uint8_t r; /* Red color value (0-255). */ diff --git a/term/gfxterm.c b/term/gfxterm.c index 62cf98416..3fc151c8b 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -103,9 +104,28 @@ struct grub_virtual_screen struct grub_colored_char *text_buffer; }; -static struct grub_virtual_screen virtual_screen; +struct grub_gfxterm_window +{ + unsigned x; + unsigned y; + unsigned width; + unsigned height; + int double_repaint; +}; + +static int refcount; +static struct grub_video_render_target *render_target; +static struct grub_gfxterm_window window; +static struct grub_virtual_screen virtual_screen; +static grub_gfxterm_repaint_callback_t repaint_callback; + +static grub_err_t init_window (struct grub_video_render_target *target, + int x, int y, int width, int height, + int double_repaint, + const char *font_name, int border_width); + +static void destroy_window (void); -static struct grub_video_mode_info mode_info; static struct grub_video_render_target *text_layer; @@ -239,7 +259,7 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y, set_term_color (virtual_screen.term_color); - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + grub_video_set_active_render_target (render_target); /* Clear out text buffer. */ for (i = 0; i < virtual_screen.columns * virtual_screen.rows; i++) @@ -248,21 +268,71 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y, return grub_errno; } +static grub_err_t +init_window (struct grub_video_render_target *target, + int x, int y, int width, int height, int double_repaint, + const char *font_name, int border_width) +{ + /* Clean up any prior instance. */ + destroy_window (); + + /* Set the render target. */ + render_target = target; + + /* Create virtual screen. */ + if (grub_virtual_screen_setup (border_width, border_width, + width - 2 * border_width, + height - 2 * border_width, + font_name) + != GRUB_ERR_NONE) + { + return grub_errno; + } + + /* Set window bounds. */ + window.x = x; + window.y = y; + window.width = width; + window.height = height; + window.double_repaint = double_repaint; + + /* Mark whole window as dirty. */ + dirty_region_reset (); + dirty_region_add (0, 0, width, height); + + return grub_errno; +} + +grub_err_t +grub_gfxterm_init_window (struct grub_video_render_target *target, + int x, int y, int width, int height, + int double_repaint, + const char *font_name, int border_width) +{ + if (refcount++ == 0) + init_window (target, x, y, width, height, double_repaint, + font_name, border_width); + return grub_errno; +} + static grub_err_t grub_gfxterm_init (void) { - char *font_name; - char *modevar; + const char *font_name; + const char *modevar; + struct grub_video_mode_info mode_info; char *tmp; - grub_video_color_t color; - int width; - int height; grub_err_t err; - /* Select the font to use. */ + /* If gfxterm has already been initialized by calling the init_window + function, then leave it alone when it is set as the current terminal. */ + if (refcount++ != 0) + return GRUB_ERR_NONE; + + /* Select the font to use. */ font_name = grub_env_get ("gfxterm_font"); if (! font_name) - font_name = ""; /* Allow fallback to any font. */ + font_name = ""; /* Allow fallback to any font. */ /* Parse gfxmode environment variable if set. */ modevar = grub_env_get ("gfxmode"); @@ -273,6 +343,8 @@ grub_gfxterm_init (void) { 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, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); @@ -292,27 +364,29 @@ grub_gfxterm_init (void) grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height); bitmap = 0; - /* Leave borders for virtual screen. */ - width = mode_info.width - (2 * DEFAULT_BORDER_WIDTH); - height = mode_info.height - (2 * DEFAULT_BORDER_WIDTH); + /* Select the font to use. */ + font_name = grub_env_get ("gfxterm_font"); + if (! font_name) + font_name = ""; /* Allow fallback to any font. */ - /* Create virtual screen. */ - if (grub_virtual_screen_setup (DEFAULT_BORDER_WIDTH, DEFAULT_BORDER_WIDTH, - width, height, font_name) != GRUB_ERR_NONE) + /* Leave borders for virtual screen. */ + if (init_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY, + 0, 0, mode_info.width, mode_info.height, + mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED + && !(mode_info.mode_type + & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP), + font_name, + DEFAULT_BORDER_WIDTH) != GRUB_ERR_NONE) { grub_video_restore (); return grub_errno; } - /* Mark whole screen as dirty. */ - dirty_region_reset (); - dirty_region_add (0, 0, mode_info.width, mode_info.height); - - return (grub_errno = GRUB_ERR_NONE); + return grub_errno; } -static grub_err_t -grub_gfxterm_fini (void) +static void +destroy_window (void) { if (bitmap) { @@ -320,11 +394,30 @@ grub_gfxterm_fini (void) bitmap = 0; } + repaint_callback = 0; grub_virtual_screen_free (); +} - grub_video_restore (); +void +grub_gfxterm_destroy_window (void) +{ + if (--refcount == 0) + destroy_window (); +} - return GRUB_ERR_NONE; +static grub_err_t +grub_gfxterm_fini (void) +{ + /* Don't destroy an explicitly initialized terminal instance when it is + unset as the current terminal. */ + if (--refcount == 0) + { + destroy_window (); + grub_video_restore (); + } + + /* Clear error state. */ + return (grub_errno = GRUB_ERR_NONE); } static void @@ -332,9 +425,15 @@ redraw_screen_rect (unsigned int x, unsigned int y, unsigned int width, unsigned int height) { grub_video_color_t color; + grub_video_rect_t saved_view; - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); - + grub_video_set_active_render_target (render_target); + /* Save viewport and set it to our window. */ + grub_video_get_viewport ((unsigned *) &saved_view.x, + (unsigned *) &saved_view.y, + (unsigned *) &saved_view.width, + (unsigned *) &saved_view.height); + grub_video_set_viewport (window.x, window.y, window.width, window.height); if (bitmap) { @@ -401,6 +500,14 @@ redraw_screen_rect (unsigned int x, unsigned int y, y - virtual_screen.offset_y, width, height); } + + /* Restore saved viewport. */ + grub_video_set_viewport (saved_view.x, saved_view.y, + saved_view.width, saved_view.height); + grub_video_set_active_render_target (render_target); + + if (repaint_callback) + repaint_callback (x, y, width, height); } static void @@ -515,7 +622,7 @@ write_char (void) grub_video_set_active_render_target (text_layer); grub_video_fill_rect (bgcolor, x, y, width, height); grub_font_draw_glyph (glyph, color, x, y + ascent); - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + grub_video_set_active_render_target (render_target); /* Mark character to be drawn. */ dirty_region_add (virtual_screen.offset_x + x, virtual_screen.offset_y + y, @@ -546,7 +653,7 @@ draw_cursor (int show) /* Render cursor to text layer. */ grub_video_set_active_render_target (text_layer); grub_video_fill_rect (color, x, y, width, height); - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + grub_video_set_active_render_target (render_target); /* Mark cursor to be redrawn. */ dirty_region_add (virtual_screen.offset_x + x, @@ -594,10 +701,18 @@ scroll_up (void) } else { - int i = 1; - if (mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED - && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP)) - i++; + grub_video_rect_t saved_view; + int i; + + grub_video_set_active_render_target (render_target); + /* Save viewport and set it to our window. */ + grub_video_get_viewport ((unsigned *) &saved_view.x, + (unsigned *) &saved_view.y, + (unsigned *) &saved_view.width, + (unsigned *) &saved_view.height); + grub_video_set_viewport (window.x, window.y, window.width, window.height); + + i = window.double_repaint ? 2 : 1; color = virtual_screen.bg_color; @@ -610,7 +725,7 @@ scroll_up (void) virtual_screen.width, virtual_screen.normal_char_height); - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + grub_video_set_active_render_target (render_target); dirty_region_redraw (); /* Scroll physical screen. */ @@ -626,11 +741,18 @@ scroll_up (void) color = virtual_screen.bg_color; grub_video_scroll (color, 0, -virtual_screen.normal_char_height); + /* Restore saved viewport. */ + grub_video_set_viewport (saved_view.x, saved_view.y, + saved_view.width, saved_view.height); + grub_video_set_active_render_target (render_target); /* Draw cursor if visible. */ if (virtual_screen.cursor_state) draw_cursor (1); } + + if (repaint_callback) + repaint_callback (window.x, window.y, window.width, window.height); } static void @@ -833,8 +955,9 @@ grub_gfxterm_cls (void) /* Clear text layer. */ grub_video_set_active_render_target (text_layer); color = virtual_screen.bg_color; - grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height); - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + grub_video_fill_rect (color, 0, 0, + virtual_screen.width, virtual_screen.height); + grub_video_set_active_render_target (render_target); /* Mark virtual screen to be redrawn. */ dirty_region_add_virtualscreen (); @@ -905,12 +1028,17 @@ grub_gfxterm_refresh (void) grub_video_swap_buffers (); - if (mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED - && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP)) + if (window.double_repaint) dirty_region_redraw (); dirty_region_reset (); } +void +grub_gfxterm_set_repaint_callback (grub_gfxterm_repaint_callback_t func) +{ + repaint_callback = func; +} + /* Option array indices. */ #define BACKGROUND_CMD_ARGINDEX_MODE 0 @@ -940,7 +1068,7 @@ grub_gfxterm_background_image_cmd (grub_extcmd_t cmd __attribute__ ((unused)), /* Mark whole screen as dirty. */ dirty_region_reset (); - dirty_region_add (0, 0, mode_info.width, mode_info.height); + dirty_region_add (0, 0, window.width, window.height); } /* If filename was provided, try to load that. */ @@ -956,13 +1084,13 @@ grub_gfxterm_background_image_cmd (grub_extcmd_t cmd __attribute__ ((unused)), || grub_strcmp (state[BACKGROUND_CMD_ARGINDEX_MODE].arg, "stretch") == 0) { - if (mode_info.width != grub_video_bitmap_get_width (bitmap) - || mode_info.height != grub_video_bitmap_get_height (bitmap)) + if (window.width != grub_video_bitmap_get_width (bitmap) + || window.height != grub_video_bitmap_get_height (bitmap)) { struct grub_video_bitmap *scaled_bitmap; grub_video_bitmap_create_scaled (&scaled_bitmap, - mode_info.width, - mode_info.height, + window.width, + window.height, bitmap, GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST); if (grub_errno == GRUB_ERR_NONE) @@ -979,11 +1107,11 @@ grub_gfxterm_background_image_cmd (grub_extcmd_t cmd __attribute__ ((unused)), { /* Determine bitmap dimensions. */ bitmap_width = grub_video_bitmap_get_width (bitmap); - bitmap_height = grub_video_bitmap_get_width (bitmap); + bitmap_height = grub_video_bitmap_get_height (bitmap); /* Mark whole screen as dirty. */ dirty_region_reset (); - dirty_region_add (0, 0, mode_info.width, mode_info.height); + dirty_region_add (0, 0, window.width, window.height); } } @@ -1012,10 +1140,18 @@ static struct grub_term_output grub_video_term = .next = 0 }; +const struct grub_term_output * +grub_gfxterm_get_term (void) +{ + return &grub_video_term; +} + static grub_extcmd_t background_image_cmd_handle; GRUB_MOD_INIT(term_gfxterm) { + refcount = 0; + grub_term_register_output ("gfxterm", &grub_video_term); background_image_cmd_handle = grub_register_extcmd ("background_image", From 927d0134c72432fd1cdff4591cc5eee6a509d60f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 10:28:42 +0100 Subject: [PATCH 005/237] SDL --- Makefile.in | 2 + conf/i386-pc.rmk | 6 ++ configure.ac | 34 ++++++ util/sdl.c | 263 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 305 insertions(+) create mode 100644 util/sdl.c diff --git a/Makefile.in b/Makefile.in index 7706cd26b..f2b4e7fc0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -107,12 +107,14 @@ endif AWK = @AWK@ LIBCURSES = @LIBCURSES@ LIBUSB = @LIBUSB@ +LIBSDL = @LIBSDL@ YACC = @YACC@ UNIFONT_BDF = @UNIFONT_BDF@ # Options. enable_grub_emu = @enable_grub_emu@ enable_grub_emu_usb = @enable_grub_emu_usb@ +enable_grub_emu_sdl = @enable_grub_emu_sdl@ enable_grub_fstest = @enable_grub_fstest@ enable_grub_pe2elf = @enable_grub_pe2elf@ enable_grub_mkfont = @enable_grub_mkfont@ diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index e1688ccd5..382c45ca3 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -153,6 +153,12 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/afs_be.c \ fs/befs.c fs/befs_be.c fs/tar.c \ \ + video/video.c video/fb/video_fb.c video/fb/fbblit.c \ + video/fb/fbfill.c video/fb/fbutil.c commands/videotest.c \ + video/bitmap.c video/readers/tga.c video/readers/jpeg.c \ + video/readers/png.c font/font_cmd.c font/font.c term/gfxterm.c \ + io/bufio.c \ + \ util/console.c util/hostfs.c util/grub-emu.c util/misc.c \ util/hostdisk.c util/getroot.c \ \ diff --git a/configure.ac b/configure.ac index 587f2118d..d2b281639 100644 --- a/configure.ac +++ b/configure.ac @@ -519,6 +519,10 @@ if test x"$enable_grub_emu" = xno ; then grub_emu_excuse="explicitly disabled" fi +AC_ARG_ENABLE([grub-emu-sdl], + [AS_HELP_STRING([--enable-grub-emu-sdl], + [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])]) + [# Check for curses libraries.] [if [ x"$grub_emu_excuse" = x ]; then ] AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"], @@ -567,6 +571,31 @@ enable_grub_emu_usb=no fi AC_SUBST([enable_grub_emu]) + +if test x"$enable_grub_emu_sdl" = xno ; then + grub_emu_sdl_excuse="explicitely disabled" +fi +[if [ x"$grub_emu_sdl_excuse" = x ]; then + # Check for libSDL libraries.] +AC_CHECK_LIB([SDL], [SDL_Init], [LIBSDL="-lSDL"], + [grub_emu_sdl_excuse=["libSDL libraries are required to build \`grub-emu' with SDL support"]]) + AC_SUBST([LIBSDL]) +[fi] +[if [ x"$grub_emu_sdl_excuse" = x ]; then + # Check for headers.] + AC_CHECK_HEADERS([SDL/SDL.h], [], + [grub_emu_sdl_excuse=["libSDL header file is required to build \`grub-emu' with SDL support"]]) +[fi] +if test x"enable_grub_emu_sdl" = xyes && test x"$grub_emu_sdl_excuse" != x ; then + AC_MSG_ERROR([SDL support for grub-emu was explicitely requested but can't be compiled]) +fi +if test x"$grub_emu_sdl_excuse" = x ; then +enable_grub_emu_sdl=yes +else +enable_grub_emu_sdl=no +fi + +AC_SUBST([enable_grub_emu_sdl]) AC_SUBST([enable_grub_emu_usb]) AC_ARG_ENABLE([grub-fstest], @@ -641,6 +670,11 @@ echo USB support for grub-emu: Yes else echo USB support for grub-emu: No "($grub_emu_usb_excuse)" fi +if [ x"$grub_emu_sdl_excuse" = x ]; then +echo SDL support for grub-emu: Yes +else +echo SDL support for grub-emu: No "($grub_emu_sdl_excuse)" +fi if [ x"$enable_mm_debug" = xyes ]; then echo With memory debugging: Yes else diff --git a/util/sdl.c b/util/sdl.c new file mode 100644 index 000000000..a5a310518 --- /dev/null +++ b/util/sdl.c @@ -0,0 +1,263 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 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 . + */ + +#define grub_video_render_target grub_video_fbrender_target + +#include +#include +#include +#include +#include +#include +#include +#include + +static SDL_Surface *window = 0; +static struct grub_video_render_target *sdl_render_target; +static struct grub_video_mode_info mode_info; + +static grub_err_t +grub_video_sdl_set_palette (unsigned int start, unsigned int count, + struct grub_video_palette_data *palette_data); + +static grub_err_t +grub_video_sdl_init (void) +{ + window = 0; + + if (SDL_Init (SDL_INIT_VIDEO) < 0) + return grub_error (GRUB_ERR_BAD_DEVICE, "Couldn't init SDL: %s", + SDL_GetError ()); + + grub_memset (&mode_info, 0, sizeof (mode_info)); + + return grub_video_fb_init (); +} + +static grub_err_t +grub_video_sdl_fini (void) +{ + SDL_Quit (); + window = 0; + + grub_memset (&mode_info, 0, sizeof (mode_info)); + + return grub_video_fb_fini (); +} + +static inline unsigned int +get_mask_size (grub_uint32_t mask) +{ + unsigned i; + for (i = 0; mask > 1U << i; i++); + return i; +} + +static grub_err_t +grub_video_sdl_setup (unsigned int width, unsigned int height, + unsigned int mode_type, unsigned int mode_mask) +{ + int depth; + int flags = 0; + grub_err_t err; + + /* Decode depth from mode_type. If it is zero, then autodetect. */ + depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK) + >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS; + + if (depth == 0) + depth = 32; + + if (width == 0 && height == 0) + { + width = 800; + height = 600; + } + + if ((mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED) + || !(mode_mask & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED)) + flags |= SDL_DOUBLEBUF; + + window = SDL_SetVideoMode (width, height, depth, flags | SDL_HWSURFACE); + if (! window) + window = SDL_SetVideoMode (width, height, depth, flags | SDL_SWSURFACE); + if (! window) + return grub_error (GRUB_ERR_BAD_DEVICE, "Couldn't open window: %s", + SDL_GetError ()); + + grub_memset (&sdl_render_target, 0, sizeof (sdl_render_target)); + + mode_info.width = window->w; + mode_info.height = window->h; + mode_info.mode_type = 0; + if (window->flags & SDL_DOUBLEBUF) + mode_info.mode_type + |= GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED; + if (window->format->palette) + mode_info.mode_type |= GRUB_VIDEO_MODE_TYPE_INDEX_COLOR; + else + mode_info.mode_type |= GRUB_VIDEO_MODE_TYPE_RGB; + + mode_info.bpp = window->format->BitsPerPixel; + mode_info.bytes_per_pixel = window->format->BytesPerPixel; + mode_info.pitch = window->pitch; + + /* In index color mode, number of colors. In RGB mode this is 256. */ + if (window->format->palette) + mode_info.number_of_colors + = 1 << window->format->BitsPerPixel; + else + mode_info.number_of_colors = 256; + + if (! window->format->palette) + { + mode_info.red_mask_size + = get_mask_size (window->format->Rmask >> window->format->Rshift); + mode_info.red_field_pos = window->format->Rshift; + mode_info.green_mask_size + = get_mask_size (window->format->Gmask >> window->format->Gshift); + mode_info.green_field_pos = window->format->Gshift; + mode_info.blue_mask_size + = get_mask_size (window->format->Bmask >> window->format->Bshift); + mode_info.blue_field_pos = window->format->Bshift; + mode_info.reserved_mask_size + = get_mask_size (window->format->Amask >> window->format->Ashift); + mode_info.reserved_field_pos = window->format->Ashift; + mode_info.blit_format + = grub_video_get_blit_format (&mode_info); + } + + err = grub_video_fb_create_render_target_from_pointer (&sdl_render_target, + &mode_info, + window->pixels); + if (err) + return err; + + /* Copy default palette to initialize emulated palette. */ + grub_video_sdl_set_palette (0, (sizeof (grub_video_fbstd_colors) + / sizeof (grub_video_fbstd_colors[0])), + grub_video_fbstd_colors); + + /* Reset render target to SDL one. */ + return grub_video_fb_set_active_render_target (sdl_render_target); +} + +static grub_err_t +grub_video_sdl_set_palette (unsigned int start, unsigned int count, + struct grub_video_palette_data *palette_data) +{ + unsigned i; + if (window->format->palette) + { + SDL_Color *tmp = grub_malloc (count * sizeof (tmp[0])); + for (i = 0; i < count; i++) + { + tmp[i].r = palette_data[i].r; + tmp[i].g = palette_data[i].g; + tmp[i].b = palette_data[i].b; + tmp[i].unused = palette_data[i].a; + } + SDL_SetColors (window, tmp, start, count); + grub_free (tmp); + } + + return grub_video_fb_set_palette (start, count, palette_data); +} + +grub_err_t +grub_video_sdl_set_viewport (unsigned int x, unsigned int y, + unsigned int width, unsigned int height) +{ + /* Make sure viewport is withing screen dimensions. If viewport was set + to be out of the region, mark its size as zero. */ + if (x > (unsigned) window->w) + { + x = 0; + width = 0; + } + + if (y > (unsigned) window->h) + { + y = 0; + height = 0; + } + + if (x + width > (unsigned) window->w) + width = window->w - x; + + if (y + height > (unsigned) window->h) + height = window->h - y; + return grub_video_fb_set_viewport (x, y, width, height); +} + +static grub_err_t +grub_video_sdl_swap_buffers (void) +{ + if (SDL_Flip (window) < 0) + return grub_error (GRUB_ERR_BAD_DEVICE, "couldn't swap buffers: %s", + SDL_GetError ()); + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_video_sdl_set_active_render_target (struct grub_video_render_target *target) +{ + if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY) + return grub_video_fb_set_active_render_target (sdl_render_target); + + return grub_video_fb_set_active_render_target (target); +} + +static struct grub_video_adapter grub_video_sdl_adapter = + { + .name = "SDL Video Driver", + + .init = grub_video_sdl_init, + .fini = grub_video_sdl_fini, + .setup = grub_video_sdl_setup, + .get_info = grub_video_fb_get_info, + .set_palette = grub_video_sdl_set_palette, + .get_palette = grub_video_fb_get_palette, + .set_viewport = grub_video_fb_set_viewport, + .get_viewport = grub_video_fb_get_viewport, + .map_color = grub_video_fb_map_color, + .map_rgb = grub_video_fb_map_rgb, + .map_rgba = grub_video_fb_map_rgba, + .unmap_color = grub_video_fb_unmap_color, + .fill_rect = grub_video_fb_fill_rect, + .blit_bitmap = grub_video_fb_blit_bitmap, + .blit_render_target = grub_video_fb_blit_render_target, + .scroll = grub_video_fb_scroll, + .swap_buffers = grub_video_sdl_swap_buffers, + .create_render_target = grub_video_fb_create_render_target, + .delete_render_target = grub_video_fb_delete_render_target, + .set_active_render_target = grub_video_sdl_set_active_render_target, + .get_active_render_target = grub_video_fb_get_active_render_target, + + .next = 0 + }; + +GRUB_MOD_INIT(sdl) +{ + grub_video_register (&grub_video_sdl_adapter); +} + +GRUB_MOD_FINI(sdl) +{ + grub_video_unregister (&grub_video_sdl_adapter); +} From a9d407a81e6761a24f4816d43035e7accdc1ad4d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 10:46:30 +0100 Subject: [PATCH 006/237] Reimported scaling --- ChangeLog.scale | 16 ++ conf/common.rmk | 6 + include/grub/bitmap_scale.h | 48 ++++++ include/grub/xnu.h | 3 + loader/i386/pc/xnu.c | 45 ++++-- loader/xnu.c | 37 ++++- term/gfxterm.c | 53 ++++++- video/bitmap_scale.c | 308 ++++++++++++++++++++++++++++++++++++ 8 files changed, 490 insertions(+), 26 deletions(-) create mode 100644 ChangeLog.scale create mode 100644 include/grub/bitmap_scale.h create mode 100644 video/bitmap_scale.c diff --git a/ChangeLog.scale b/ChangeLog.scale new file mode 100644 index 000000000..eb12d3b21 --- /dev/null +++ b/ChangeLog.scale @@ -0,0 +1,16 @@ +2009-08-24 Colin D Bennett + + Bitmap scaling support. + + * conf/common.rmk (pkglib_MODULES): Add bitmap_scale.mod. + (bitmap_scale_mod_SOURCES): New variable. + (bitmap_scale_mod_CFLAGS): Likewise. + (bitmap_scale_mod_LDFLAGS): Likewise. + * include/grub/bitmap_scale.h: New file. + * term/gfxterm.c (BACKGROUND_CMD_ARGINDEX_MODE): New definiton. + (background_image_cmd_options): New variable. + (grub_gfxterm_background_image_cmd): Support bitmap stretching. + (cmd): Rename and change type to ... + (background_image_cmd_handle): ... this. All users updated. + (GRUB_MOD_INIT(term_gfxterm)): Make background_image extended command. + * video/bitmap_scale.c: New file. diff --git a/conf/common.rmk b/conf/common.rmk index 173f24b62..98681bc1c 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -567,6 +567,12 @@ bitmap_mod_SOURCES = video/bitmap.c bitmap_mod_CFLAGS = $(COMMON_CFLAGS) bitmap_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For bitmap_scale.mod +pkglib_MODULES += bitmap_scale.mod +bitmap_scale_mod_SOURCES = video/bitmap_scale.c +bitmap_scale_mod_CFLAGS = $(COMMON_CFLAGS) +bitmap_scale_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For tga.mod tga_mod_SOURCES = video/readers/tga.c tga_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/include/grub/bitmap_scale.h b/include/grub/bitmap_scale.h new file mode 100644 index 000000000..7ea9d7914 --- /dev/null +++ b/include/grub/bitmap_scale.h @@ -0,0 +1,48 @@ +/* bitmap_scale.h - Bitmap scaling functions. */ +/* + * 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 . + */ + +#ifndef GRUB_BITMAP_SCALE_HEADER +#define GRUB_BITMAP_SCALE_HEADER 1 + +#include +#include +#include + +enum grub_video_bitmap_scale_method +{ + /* Choose the fastest interpolation algorithm. */ + GRUB_VIDEO_BITMAP_SCALE_METHOD_FASTEST, + /* Choose the highest quality interpolation algorithm. */ + GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST, + + /* Specific algorithms: */ + /* Nearest neighbor interpolation. */ + GRUB_VIDEO_BITMAP_SCALE_METHOD_NEAREST, + /* Bilinear interpolation. */ + GRUB_VIDEO_BITMAP_SCALE_METHOD_BILINEAR +}; + +grub_err_t +grub_video_bitmap_create_scaled (struct grub_video_bitmap **dst, + int dst_width, int dst_height, + struct grub_video_bitmap *src, + enum + grub_video_bitmap_scale_method scale_method); + +#endif /* ! GRUB_BITMAP_SCALE_HEADER */ diff --git a/include/grub/xnu.h b/include/grub/xnu.h index c3902e670..b058bd1b9 100644 --- a/include/grub/xnu.h +++ b/include/grub/xnu.h @@ -104,4 +104,7 @@ extern grub_uint32_t grub_xnu_heap_real_start; extern grub_size_t grub_xnu_heap_size; extern char *grub_xnu_heap_start; extern struct grub_video_bitmap *grub_xnu_bitmap; +typedef enum {GRUB_XNU_BITMAP_CENTER, GRUB_XNU_BITMAP_STRETCH} + grub_xnu_bitmap_mode_t; +extern grub_xnu_bitmap_mode_t grub_xnu_bitmap_mode; #endif diff --git a/loader/i386/pc/xnu.c b/loader/i386/pc/xnu.c index 839d0ad44..1a222e6e5 100644 --- a/loader/i386/pc/xnu.c +++ b/loader/i386/pc/xnu.c @@ -22,6 +22,7 @@ #include #include #include +#include #define min(a,b) (((a) < (b)) ? (a) : (b)) #define max(a,b) (((a) > (b)) ? (a) : (b)) @@ -37,6 +38,7 @@ grub_xnu_set_video (struct grub_xnu_boot_params *params) char *tmp, *modevar; void *framebuffer; grub_err_t err; + struct grub_video_bitmap *bitmap = NULL; modevar = grub_env_get ("gfxpayload"); /* Consider only graphical 32-bit deep modes. */ @@ -63,31 +65,46 @@ grub_xnu_set_video (struct grub_xnu_boot_params *params) if (err) return err; + ret = grub_video_get_info (&mode_info); + if (ret) + return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters"); + if (grub_xnu_bitmap) + { + if (grub_xnu_bitmap_mode == GRUB_XNU_BITMAP_STRETCH) + err = grub_video_bitmap_create_scaled (&bitmap, + mode_info.width, + mode_info.height, + grub_xnu_bitmap, + GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST); + else + bitmap = grub_xnu_bitmap; + } + + if (bitmap) { int x, y; - x = mode_info.width - grub_xnu_bitmap->mode_info.width; + x = mode_info.width - bitmap->mode_info.width; x /= 2; - y = mode_info.height - grub_xnu_bitmap->mode_info.height; + y = mode_info.height - bitmap->mode_info.height; y /= 2; - err = grub_video_blit_bitmap (grub_xnu_bitmap, + err = grub_video_blit_bitmap (bitmap, GRUB_VIDEO_BLIT_REPLACE, x > 0 ? x : 0, y > 0 ? y : 0, x < 0 ? -x : 0, y < 0 ? -y : 0, - min (grub_xnu_bitmap->mode_info.width, + min (bitmap->mode_info.width, mode_info.width), - min (grub_xnu_bitmap->mode_info.height, + min (bitmap->mode_info.height, mode_info.height)); - if (err) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - grub_xnu_bitmap = 0; - } - err = GRUB_ERR_NONE; + } + if (err) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + bitmap = 0; } ret = grub_video_get_info_and_fini (&mode_info, &framebuffer); @@ -100,8 +117,8 @@ grub_xnu_set_video (struct grub_xnu_boot_params *params) params->lfb_line_len = mode_info.pitch; params->lfb_base = PTR_TO_UINT32 (framebuffer); - params->lfb_mode = grub_xnu_bitmap - ? GRUB_XNU_VIDEO_SPLASH : GRUB_XNU_VIDEO_TEXT_IN_VIDEO; + params->lfb_mode = bitmap ? GRUB_XNU_VIDEO_SPLASH + : GRUB_XNU_VIDEO_TEXT_IN_VIDEO; return GRUB_ERR_NONE; } diff --git a/loader/xnu.c b/loader/xnu.c index aac4ae372..e0ae9cefe 100644 --- a/loader/xnu.c +++ b/loader/xnu.c @@ -31,6 +31,7 @@ #include #include #include +#include struct grub_xnu_devtree_key *grub_xnu_devtree_root = 0; static int driverspackagenum = 0; @@ -1272,18 +1273,37 @@ grub_cmd_xnu_kextdir (grub_command_t cmd __attribute__ ((unused)), } struct grub_video_bitmap *grub_xnu_bitmap = 0; +grub_xnu_bitmap_mode_t grub_xnu_bitmap_mode; + +/* Option array indices. */ +#define XNU_SPLASH_CMD_ARGINDEX_MODE 0 + +static const struct grub_arg_option xnu_splash_cmd_options[] = + { + {"mode", 'm', 0, "Background image mode.", "stretch|normal", + ARG_TYPE_STRING}, + {0, 0, 0, 0, 0, 0} + }; static grub_err_t -grub_cmd_xnu_splash (grub_command_t cmd __attribute__ ((unused)), +grub_cmd_xnu_splash (grub_extcmd_t cmd, int argc, char *args[]) { grub_err_t err; if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required"); + if (cmd->state[XNU_SPLASH_CMD_ARGINDEX_MODE].set && + grub_strcmp (cmd->state[XNU_SPLASH_CMD_ARGINDEX_MODE].arg, + "stretch") == 0) + grub_xnu_bitmap_mode = GRUB_XNU_BITMAP_STRETCH; + else + grub_xnu_bitmap_mode = GRUB_XNU_BITMAP_CENTER; + err = grub_video_bitmap_load (&grub_xnu_bitmap, args[0]); if (err) grub_xnu_bitmap = 0; + return err; } @@ -1316,8 +1336,10 @@ grub_xnu_unlock () locked = 0; } -static grub_command_t cmd_kernel, cmd_mkext, cmd_kext, cmd_kextdir, - cmd_ramdisk, cmd_devtree, cmd_resume, cmd_splash; +static grub_command_t cmd_kernel, cmd_mkext, cmd_kext, ; +static grub_command_t cmd_devtree; +static grub_command_t cmd_kextdir, cmd_ramdisk, cmd_resume; +static grub_extcmd_t cmd_splash; GRUB_MOD_INIT(xnu) { @@ -1335,8 +1357,11 @@ GRUB_MOD_INIT(xnu) "It will be seen as md0"); cmd_devtree = grub_register_command ("xnu_devtree", grub_cmd_xnu_devtree, 0, "Load XNU devtree"); - cmd_splash = grub_register_command ("xnu_splash", grub_cmd_xnu_splash, 0, - "Load a splash image for XNU"); + cmd_splash = grub_register_extcmd ("xnu_splash", + grub_cmd_xnu_splash, + GRUB_COMMAND_FLAG_BOTH, 0, + "Load a splash image for XNU", + xnu_splash_cmd_options); #ifndef GRUB_UTIL cmd_resume = grub_register_command ("xnu_resume", grub_cmd_xnu_resume, @@ -1356,5 +1381,5 @@ GRUB_MOD_FINI(xnu) grub_unregister_command (cmd_devtree); grub_unregister_command (cmd_ramdisk); grub_unregister_command (cmd_kernel); - grub_unregister_command (cmd_splash); + grub_unregister_extcmd (cmd_splash); } diff --git a/term/gfxterm.c b/term/gfxterm.c index 6906b77a1..62cf98416 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #define DEFAULT_VIDEO_MODE "auto" #define DEFAULT_BORDER_WIDTH 10 @@ -909,11 +911,23 @@ grub_gfxterm_refresh (void) dirty_region_reset (); } +/* Option array indices. */ +#define BACKGROUND_CMD_ARGINDEX_MODE 0 + +static const struct grub_arg_option background_image_cmd_options[] = + { + {"mode", 'm', 0, "Background image mode.", "stretch|normal", + ARG_TYPE_STRING}, + {0, 0, 0, 0, 0, 0} + }; + static grub_err_t -grub_gfxterm_background_image_cmd (grub_command_t cmd __attribute__ ((unused)), +grub_gfxterm_background_image_cmd (grub_extcmd_t cmd __attribute__ ((unused)), int argc, char **args) { + struct grub_arg_list *state = cmd->state; + /* Check that we have video adapter active. */ if (grub_video_get_info(NULL) != GRUB_ERR_NONE) return grub_errno; @@ -937,6 +951,29 @@ grub_gfxterm_background_image_cmd (grub_command_t cmd __attribute__ ((unused)), if (grub_errno != GRUB_ERR_NONE) return grub_errno; + /* Determine if the bitmap should be scaled to fit the screen. */ + if (!state[BACKGROUND_CMD_ARGINDEX_MODE].set + || grub_strcmp (state[BACKGROUND_CMD_ARGINDEX_MODE].arg, + "stretch") == 0) + { + if (mode_info.width != grub_video_bitmap_get_width (bitmap) + || mode_info.height != grub_video_bitmap_get_height (bitmap)) + { + struct grub_video_bitmap *scaled_bitmap; + grub_video_bitmap_create_scaled (&scaled_bitmap, + mode_info.width, + mode_info.height, + bitmap, + GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST); + if (grub_errno == GRUB_ERR_NONE) + { + /* Replace the original bitmap with the scaled one. */ + grub_video_bitmap_destroy (bitmap); + bitmap = scaled_bitmap; + } + } + } + /* If bitmap was loaded correctly, display it. */ if (bitmap) { @@ -975,18 +1012,22 @@ static struct grub_term_output grub_video_term = .next = 0 }; -static grub_command_t cmd; +static grub_extcmd_t background_image_cmd_handle; GRUB_MOD_INIT(term_gfxterm) { grub_term_register_output ("gfxterm", &grub_video_term); - cmd = grub_register_command ("background_image", - grub_gfxterm_background_image_cmd, - 0, "Load background image for active terminal"); + background_image_cmd_handle = + grub_register_extcmd ("background_image", + grub_gfxterm_background_image_cmd, + GRUB_COMMAND_FLAG_BOTH, + "background_image [-m (stretch|normal)] FILE", + "Load background image for active terminal.", + background_image_cmd_options); } GRUB_MOD_FINI(term_gfxterm) { - grub_unregister_command (cmd); + grub_unregister_extcmd (background_image_cmd_handle); grub_term_unregister_output (&grub_video_term); } diff --git a/video/bitmap_scale.c b/video/bitmap_scale.c new file mode 100644 index 000000000..6f8ff247e --- /dev/null +++ b/video/bitmap_scale.c @@ -0,0 +1,308 @@ +/* bitmap_scale.c - Bitmap scaling. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 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 + +/* Prototypes for module-local functions. */ +static grub_err_t scale_nn (struct grub_video_bitmap *dst, + struct grub_video_bitmap *src); +static grub_err_t scale_bilinear (struct grub_video_bitmap *dst, + struct grub_video_bitmap *src); + +/* This function creates a new scaled version of the bitmap SRC. The new + bitmap has dimensions DST_WIDTH by DST_HEIGHT. The scaling algorithm + is given by SCALE_METHOD. If an error is encountered, the return code is + not equal to GRUB_ERR_NONE, and the bitmap DST is either not created, or + it is destroyed before this function returns. + + Supports only direct color modes which have components separated + into bytes (e.g., RGBA 8:8:8:8 or BGR 8:8:8 true color). + But because of this simplifying assumption, the implementation is + greatly simplified. */ +grub_err_t +grub_video_bitmap_create_scaled (struct grub_video_bitmap **dst, + int dst_width, int dst_height, + struct grub_video_bitmap *src, + enum grub_video_bitmap_scale_method + scale_method) +{ + *dst = 0; + + /* Verify the simplifying assumptions. */ + if (src == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "null src bitmap in grub_video_bitmap_create_scaled"); + if (src->mode_info.red_field_pos % 8 != 0 + || src->mode_info.green_field_pos % 8 != 0 + || src->mode_info.blue_field_pos % 8 != 0 + || src->mode_info.reserved_field_pos % 8 != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "src format not supported for scale"); + if (src->mode_info.width == 0 || src->mode_info.height == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "source bitmap has a zero dimension"); + if (dst_width <= 0 || dst_height <= 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "requested to scale to a size w/ a zero dimension"); + if (src->mode_info.bytes_per_pixel * 8 != src->mode_info.bpp) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "bitmap to scale has inconsistent Bpp and bpp"); + + /* Create the new bitmap. */ + grub_err_t ret; + ret = grub_video_bitmap_create (dst, dst_width, dst_height, + src->mode_info.blit_format); + if (ret != GRUB_ERR_NONE) + return ret; /* Error. */ + + switch (scale_method) + { + case GRUB_VIDEO_BITMAP_SCALE_METHOD_FASTEST: + case GRUB_VIDEO_BITMAP_SCALE_METHOD_NEAREST: + ret = scale_nn (*dst, src); + break; + case GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST: + case GRUB_VIDEO_BITMAP_SCALE_METHOD_BILINEAR: + ret = scale_bilinear (*dst, src); + break; + default: + ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid scale_method value"); + break; + } + + if (ret == GRUB_ERR_NONE) + { + /* Success: *dst is now a pointer to the scaled bitmap. */ + return GRUB_ERR_NONE; + } + else + { + /* Destroy the bitmap and return the error code. */ + grub_video_bitmap_destroy (*dst); + *dst = 0; + return ret; + } +} + +/* Nearest neighbor bitmap scaling algorithm. + + Copy the bitmap SRC to the bitmap DST, scaling the bitmap to fit the + dimensions of DST. This function uses the nearest neighbor algorithm to + interpolate the pixels. + + Supports only direct color modes which have components separated + into bytes (e.g., RGBA 8:8:8:8 or BGR 8:8:8 true color). + But because of this simplifying assumption, the implementation is + greatly simplified. */ +static grub_err_t +scale_nn (struct grub_video_bitmap *dst, struct grub_video_bitmap *src) +{ + /* Verify the simplifying assumptions. */ + if (dst == 0 || src == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "null bitmap in scale_nn"); + if (dst->mode_info.red_field_pos % 8 != 0 + || dst->mode_info.green_field_pos % 8 != 0 + || dst->mode_info.blue_field_pos % 8 != 0 + || dst->mode_info.reserved_field_pos % 8 != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "dst format not supported"); + if (src->mode_info.red_field_pos % 8 != 0 + || src->mode_info.green_field_pos % 8 != 0 + || src->mode_info.blue_field_pos % 8 != 0 + || src->mode_info.reserved_field_pos % 8 != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "src format not supported"); + if (dst->mode_info.red_field_pos != src->mode_info.red_field_pos + || dst->mode_info.red_mask_size != src->mode_info.red_mask_size + || dst->mode_info.green_field_pos != src->mode_info.green_field_pos + || dst->mode_info.green_mask_size != src->mode_info.green_mask_size + || dst->mode_info.blue_field_pos != src->mode_info.blue_field_pos + || dst->mode_info.blue_mask_size != src->mode_info.blue_mask_size + || dst->mode_info.reserved_field_pos != + src->mode_info.reserved_field_pos + || dst->mode_info.reserved_mask_size != + src->mode_info.reserved_mask_size) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "dst and src not compatible"); + if (dst->mode_info.bytes_per_pixel != src->mode_info.bytes_per_pixel) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "dst and src not compatible"); + if (dst->mode_info.width == 0 || dst->mode_info.height == 0 + || src->mode_info.width == 0 || src->mode_info.height == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "bitmap has a zero dimension"); + + grub_uint8_t *ddata = dst->data; + grub_uint8_t *sdata = src->data; + int dw = dst->mode_info.width; + int dh = dst->mode_info.height; + int sw = src->mode_info.width; + int sh = src->mode_info.height; + int dstride = dst->mode_info.pitch; + int sstride = src->mode_info.pitch; + /* bytes_per_pixel is the same for both src and dst. */ + int bytes_per_pixel = dst->mode_info.bytes_per_pixel; + + int dy; + for (dy = 0; dy < dh; dy++) + { + int dx; + for (dx = 0; dx < dw; dx++) + { + grub_uint8_t *dptr; + grub_uint8_t *sptr; + int sx; + int sy; + int comp; + + /* Compute the source coordinate that the destination coordinate + maps to. Note: sx/sw = dx/dw => sx = sw*dx/dw. */ + sx = sw * dx / dw; + sy = sh * dy / dh; + + /* Get the address of the pixels in src and dst. */ + dptr = ddata + dy * dstride + dx * bytes_per_pixel; + sptr = sdata + sy * sstride + sx * bytes_per_pixel; + + /* Copy the pixel color value. */ + for (comp = 0; comp < bytes_per_pixel; comp++) + dptr[comp] = sptr[comp]; + } + } + return GRUB_ERR_NONE; +} + +/* Bilinear interpolation image scaling algorithm. + + Copy the bitmap SRC to the bitmap DST, scaling the bitmap to fit the + dimensions of DST. This function uses the bilinear interpolation algorithm + to interpolate the pixels. + + Supports only direct color modes which have components separated + into bytes (e.g., RGBA 8:8:8:8 or BGR 8:8:8 true color). + But because of this simplifying assumption, the implementation is + greatly simplified. */ +static grub_err_t +scale_bilinear (struct grub_video_bitmap *dst, struct grub_video_bitmap *src) +{ + /* Verify the simplifying assumptions. */ + if (dst == 0 || src == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "null bitmap in scale func"); + if (dst->mode_info.red_field_pos % 8 != 0 + || dst->mode_info.green_field_pos % 8 != 0 + || dst->mode_info.blue_field_pos % 8 != 0 + || dst->mode_info.reserved_field_pos % 8 != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "dst format not supported"); + if (src->mode_info.red_field_pos % 8 != 0 + || src->mode_info.green_field_pos % 8 != 0 + || src->mode_info.blue_field_pos % 8 != 0 + || src->mode_info.reserved_field_pos % 8 != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "src format not supported"); + if (dst->mode_info.red_field_pos != src->mode_info.red_field_pos + || dst->mode_info.red_mask_size != src->mode_info.red_mask_size + || dst->mode_info.green_field_pos != src->mode_info.green_field_pos + || dst->mode_info.green_mask_size != src->mode_info.green_mask_size + || dst->mode_info.blue_field_pos != src->mode_info.blue_field_pos + || dst->mode_info.blue_mask_size != src->mode_info.blue_mask_size + || dst->mode_info.reserved_field_pos != + src->mode_info.reserved_field_pos + || dst->mode_info.reserved_mask_size != + src->mode_info.reserved_mask_size) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "dst and src not compatible"); + if (dst->mode_info.bytes_per_pixel != src->mode_info.bytes_per_pixel) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "dst and src not compatible"); + if (dst->mode_info.width == 0 || dst->mode_info.height == 0 + || src->mode_info.width == 0 || src->mode_info.height == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "bitmap has a zero dimension"); + + grub_uint8_t *ddata = dst->data; + grub_uint8_t *sdata = src->data; + int dw = dst->mode_info.width; + int dh = dst->mode_info.height; + int sw = src->mode_info.width; + int sh = src->mode_info.height; + int dstride = dst->mode_info.pitch; + int sstride = src->mode_info.pitch; + /* bytes_per_pixel is the same for both src and dst. */ + int bytes_per_pixel = dst->mode_info.bytes_per_pixel; + + int dy; + for (dy = 0; dy < dh; dy++) + { + int dx; + for (dx = 0; dx < dw; dx++) + { + grub_uint8_t *dptr; + grub_uint8_t *sptr; + int sx; + int sy; + int comp; + + /* Compute the source coordinate that the destination coordinate + maps to. Note: sx/sw = dx/dw => sx = sw*dx/dw. */ + sx = sw * dx / dw; + sy = sh * dy / dh; + + /* Get the address of the pixels in src and dst. */ + dptr = ddata + dy * dstride + dx * bytes_per_pixel; + sptr = sdata + sy * sstride + sx * bytes_per_pixel; + + /* If we have enough space to do so, use bilinear interpolation. + Otherwise, fall back to nearest neighbor for this pixel. */ + if (sx < sw - 1 && sy < sh - 1) + { + /* Do bilinear interpolation. */ + + /* Fixed-point .8 numbers representing the fraction of the + distance in the x (u) and y (v) direction within the + box of 4 pixels in the source. */ + int u = (256 * sw * dx / dw) - (sx * 256); + int v = (256 * sh * dy / dh) - (sy * 256); + + for (comp = 0; comp < bytes_per_pixel; comp++) + { + /* Get the component's values for the + four source corner pixels. */ + grub_uint8_t f00 = sptr[comp]; + grub_uint8_t f10 = sptr[comp + bytes_per_pixel]; + grub_uint8_t f01 = sptr[comp + sstride]; + grub_uint8_t f11 = sptr[comp + sstride + bytes_per_pixel]; + + /* Do linear interpolations along the top and bottom + rows of the box. */ + grub_uint8_t f0y = (256 - v) * f00 / 256 + v * f01 / 256; + grub_uint8_t f1y = (256 - v) * f10 / 256 + v * f11 / 256; + + /* Interpolate vertically. */ + grub_uint8_t fxy = (256 - u) * f0y / 256 + u * f1y / 256; + + dptr[comp] = fxy; + } + } + else + { + /* Fall back to nearest neighbor interpolation. */ + /* Copy the pixel color value. */ + for (comp = 0; comp < bytes_per_pixel; comp++) + dptr[comp] = sptr[comp]; + } + } + } + return GRUB_ERR_NONE; +} From 1488fac7ef235d579972822b1cbc6e2e2932fc8b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 13:53:36 +0100 Subject: [PATCH 007/237] Fixed missing make directives --- conf/i386-pc.rmk | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 382c45ca3..4c2aec617 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -155,7 +155,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ \ video/video.c video/fb/video_fb.c video/fb/fbblit.c \ video/fb/fbfill.c video/fb/fbutil.c commands/videotest.c \ - video/bitmap.c video/readers/tga.c video/readers/jpeg.c \ + video/bitmap.c video/bitmap_scale.c video/readers/tga.c video/readers/jpeg.c \ video/readers/png.c font/font_cmd.c font/font.c term/gfxterm.c \ io/bufio.c \ \ @@ -175,6 +175,11 @@ grub_emu_SOURCES += disk/usbms.c util/usb.c bus/usb/usb.c \ grub_emu_LDFLAGS += $(LIBCURSES) $(LIBUSB) endif +ifeq ($(enable_grub_emu_sdl), yes) +grub_emu_SOURCES += util/sdl.c +grub_emu_LDFLAGS += $(LIBSDL) +endif + sbin_SCRIPTS += grub-install grub_install_SOURCES = util/grub-install.in From 71bc82683468a4c3bfd63aedbf0155bd5957eea2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 13:55:43 +0100 Subject: [PATCH 008/237] Fixed syntax error --- loader/xnu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loader/xnu.c b/loader/xnu.c index e0ae9cefe..ab88317d2 100644 --- a/loader/xnu.c +++ b/loader/xnu.c @@ -1336,7 +1336,7 @@ grub_xnu_unlock () locked = 0; } -static grub_command_t cmd_kernel, cmd_mkext, cmd_kext, ; +static grub_command_t cmd_kernel, cmd_mkext, cmd_kext; static grub_command_t cmd_devtree; static grub_command_t cmd_kextdir, cmd_ramdisk, cmd_resume; static grub_extcmd_t cmd_splash; From a8287184e360c8f198fc3174f99e8032df44881a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 14:19:20 +0100 Subject: [PATCH 009/237] renamed ChangeLog --- ChangeLog.video => ChangeLog.doublebuf | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ChangeLog.video => ChangeLog.doublebuf (100%) diff --git a/ChangeLog.video b/ChangeLog.doublebuf similarity index 100% rename from ChangeLog.video rename to ChangeLog.doublebuf From b49991d823c428b4daf69c877d15fcc31e99c950 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 14:27:52 +0100 Subject: [PATCH 010/237] ChangeLog --- ChangeLog.sdl | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 ChangeLog.sdl diff --git a/ChangeLog.sdl b/ChangeLog.sdl new file mode 100644 index 000000000..8bf8c082a --- /dev/null +++ b/ChangeLog.sdl @@ -0,0 +1,11 @@ +2009-11-20 Vladimir Serbinenko + + SDL support. + + * Makefile.in (LIBSDL): New variable. + (enable_grub_emu_sdl): Likewise. + * conf/i386-pc.rmk (grub_emu_SOURCES): Add video files. + (grub_emu_SOURCES) [enable_grub_emu_sdl]: Add util/sdl.c. + (grub_emu_LDFLAGS) [enable_grub_emu_sdl]: Add $(LIBSDL). + * configure.ac: Detect SDL availability and add --enable-grub-emu-sdl + * util/sdl.c: New file. From b4dae692eb6afc9aed7bd7d6ee47824086def7e4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 14:30:58 +0100 Subject: [PATCH 011/237] Fixed variable declarations --- term/gfxterm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/term/gfxterm.c b/term/gfxterm.c index 3fc151c8b..5330c4ac4 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -323,6 +323,7 @@ grub_gfxterm_init (void) struct grub_video_mode_info mode_info; char *tmp; grub_err_t err; + grub_video_color_t color; /* If gfxterm has already been initialized by calling the init_window function, then leave it alone when it is set as the current terminal. */ @@ -702,7 +703,6 @@ scroll_up (void) else { grub_video_rect_t saved_view; - int i; grub_video_set_active_render_target (render_target); /* Save viewport and set it to our window. */ From ac3b7128d6d7e89fd103d6ad4054ce3db56195d6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 14:45:33 +0100 Subject: [PATCH 012/237] 2009-11-20 Colin D Bennett * normal/menu_text.c (get_entry_number): Move from here ... * normal/menu.c (get_entry_number): ... moved here. * include/grub/menu.h (grub_menu_get_default_entry_index): New prototype. * normal/menu.c (grub_menu_get_default_entry_index): New function. * normal/menu_text.c (run_menu): Use grub_menu_get_default_entry_index. --- ChangeLog.menu | 9 ++++++++ include/grub/menu.h | 1 + normal/menu.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ normal/menu_text.c | 50 +---------------------------------------- 4 files changed, 65 insertions(+), 49 deletions(-) create mode 100644 ChangeLog.menu diff --git a/ChangeLog.menu b/ChangeLog.menu new file mode 100644 index 000000000..cb048bc9f --- /dev/null +++ b/ChangeLog.menu @@ -0,0 +1,9 @@ +2009-11-20 Colin D Bennett + + * normal/menu_text.c (get_entry_number): Move from here ... + * normal/menu.c (get_entry_number): ... moved here. + * include/grub/menu.h (grub_menu_get_default_entry_index): + New prototype. + * normal/menu.c (grub_menu_get_default_entry_index): New function. + * normal/menu_text.c (run_menu): Use grub_menu_get_default_entry_index. + diff --git a/include/grub/menu.h b/include/grub/menu.h index c7114a93b..cfe7e7cec 100644 --- a/include/grub/menu.h +++ b/include/grub/menu.h @@ -93,5 +93,6 @@ void grub_menu_execute_with_fallback (grub_menu_t menu, grub_menu_execute_callback_t callback, void *callback_data); void grub_menu_entry_run (grub_menu_entry_t entry); +int grub_menu_get_default_entry_index (grub_menu_t menu); #endif /* GRUB_MENU_HEADER */ diff --git a/normal/menu.c b/normal/menu.c index b9f74b7d7..282dddae5 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -180,3 +180,57 @@ grub_menu_execute_with_fallback (grub_menu_t menu, callback->notify_failure (callback_data); } + +/* Get the entry number from the variable NAME. */ +static int +get_entry_number (grub_menu_t menu, const char *name) +{ + char *val; + int entry; + + val = grub_env_get (name); + if (! val) + return -1; + + grub_error_push (); + + 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; + entry = -1; + } + + grub_error_pop (); + + return entry; +} + +int +grub_menu_get_default_entry_index (grub_menu_t menu) +{ + return get_entry_number (menu, "default"); +} diff --git a/normal/menu_text.c b/normal/menu_text.c index 19f9cf756..d02230a8f 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -235,54 +235,6 @@ grub_menu_init_page (int nested, int edit) print_message (nested, edit); } -/* Get the entry number from the variable NAME. */ -static int -get_entry_number (grub_menu_t menu, const char *name) -{ - char *val; - int entry; - - val = grub_env_get (name); - if (! val) - return -1; - - grub_error_push (); - - 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; - entry = -1; - } - - grub_error_pop (); - - return entry; -} - static void print_timeout (int timeout, int offset, int second_stage) { @@ -313,7 +265,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) first = 0; - default_entry = get_entry_number (menu, "default"); + default_entry = grub_menu_get_default_entry_index (menu); /* If DEFAULT_ENTRY is not within the menu entries, fall back to the first entry. */ From cbf97a87d9d63c46e8057f163238cec42fa4ec43 Mon Sep 17 00:00:00 2001 From: Colin D Bennett Date: Fri, 20 Nov 2009 14:51:01 +0100 Subject: [PATCH 013/237] * include/grub/menu_viewer.h (grub_menu_viewer_init): New prototype. (grub_menu_viewer_should_return): Likewise. * normal/main.c (GRUB_MOD_INIT (normal)): Call grub_menu_viewer_init. * normal/menu_text.c (run_menu): Enable menu switching. * normal/menu_viewer.c (should_return): New variable. (menu_viewer_changed): Likewise. (grub_menu_viewer_show_menu): Handle menu viewer changes. (grub_menu_viewer_should_return): New function. (menuviewer_write_hook): Likewise. (grub_menu_viewer_init): Likewise. --- ChangeLog.menu | 10 ++++++++++ include/grub/menu_viewer.h | 5 +++++ normal/main.c | 2 ++ normal/menu_text.c | 9 +++++++-- normal/menu_viewer.c | 37 ++++++++++++++++++++++++++++++++++--- 5 files changed, 58 insertions(+), 5 deletions(-) diff --git a/ChangeLog.menu b/ChangeLog.menu index cb048bc9f..32c0a85d5 100644 --- a/ChangeLog.menu +++ b/ChangeLog.menu @@ -6,4 +6,14 @@ New prototype. * normal/menu.c (grub_menu_get_default_entry_index): New function. * normal/menu_text.c (run_menu): Use grub_menu_get_default_entry_index. + * include/grub/menu_viewer.h (grub_menu_viewer_init): New prototype. + (grub_menu_viewer_should_return): Likewise. + * normal/main.c (GRUB_MOD_INIT (normal)): Call grub_menu_viewer_init. + * normal/menu_text.c (run_menu): Enable menu switching. + * normal/menu_viewer.c (should_return): New variable. + (menu_viewer_changed): Likewise. + (grub_menu_viewer_show_menu): Handle menu viewer changes. + (grub_menu_viewer_should_return): New function. + (menuviewer_write_hook): Likewise. + (grub_menu_viewer_init): Likewise. diff --git a/include/grub/menu_viewer.h b/include/grub/menu_viewer.h index 725c97548..211f6e3e9 100644 --- a/include/grub/menu_viewer.h +++ b/include/grub/menu_viewer.h @@ -36,8 +36,13 @@ struct grub_menu_viewer }; typedef struct grub_menu_viewer *grub_menu_viewer_t; +void grub_menu_viewer_init (void); + void grub_menu_viewer_register (grub_menu_viewer_t viewer); grub_err_t grub_menu_viewer_show_menu (grub_menu_t menu, int nested); +/* Return nonzero iff the menu viewer should clean up and return ASAP. */ +int grub_menu_viewer_should_return (void); + #endif /* GRUB_MENU_VIEWER_HEADER */ diff --git a/normal/main.c b/normal/main.c index 748eef805..736c20e47 100644 --- a/normal/main.c +++ b/normal/main.c @@ -584,6 +584,8 @@ GRUB_MOD_INIT(normal) /* Preserve hooks after context changes. */ grub_env_export ("color_normal"); grub_env_export ("color_highlight"); + + grub_menu_viewer_init (); } GRUB_MOD_FINI(normal) diff --git a/normal/menu_text.c b/normal/menu_text.c index d02230a8f..68c7afeee 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -300,7 +300,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) if (timeout > 0) print_timeout (timeout, offset, 0); - while (1) + while (! grub_menu_viewer_should_return ()) { int c; timeout = grub_menu_get_timeout (); @@ -473,6 +473,10 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) } goto refresh; + case 't': + grub_env_set ("menuviewer", "gfxmenu"); + goto refresh; + default: break; } @@ -481,7 +485,8 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) } } - /* Never reach here. */ + /* Exit menu without activating an item. This occurs if the user presses + * 't', switching to the graphical menu viewer. */ return -1; } diff --git a/normal/menu_viewer.c b/normal/menu_viewer.c index 1bd271a21..7a547a764 100644 --- a/normal/menu_viewer.c +++ b/normal/menu_viewer.c @@ -26,6 +26,9 @@ /* The list of menu viewers. */ static grub_menu_viewer_t menu_viewer_list; +static int should_return; +static int menu_viewer_changed; + void grub_menu_viewer_register (grub_menu_viewer_t viewer) { @@ -55,16 +58,23 @@ static grub_menu_viewer_t get_current_menu_viewer (void) grub_err_t grub_menu_viewer_show_menu (grub_menu_t menu, int nested) { - grub_menu_viewer_t cur = get_current_menu_viewer (); grub_err_t err1, err2; - if (!cur) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "No menu viewer available."); while (1) { + grub_menu_viewer_t cur = get_current_menu_viewer (); + if (!cur) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "No menu viewer available."); + + menu_viewer_changed = 0; + should_return = 0; + err1 = cur->show_menu (menu, nested); grub_print_error (); + if (menu_viewer_changed) + continue; + err2 = grub_auth_check_authentication (NULL); if (err2) { @@ -79,3 +89,24 @@ grub_menu_viewer_show_menu (grub_menu_t menu, int nested) return err1; } +int +grub_menu_viewer_should_return (void) +{ + return should_return; +} + +static char * +menuviewer_write_hook (struct grub_env_var *var __attribute__ ((unused)), + const char *val) +{ + menu_viewer_changed = 1; + should_return = 1; + return grub_strdup (val); +} + +void +grub_menu_viewer_init (void) +{ + grub_register_variable_hook ("menuviewer", 0, menuviewer_write_hook); +} + From bd86691a07c81cab2ba6f364cdfdedb34914ef37 Mon Sep 17 00:00:00 2001 From: Colin D Bennett Date: Fri, 20 Nov 2009 15:09:48 +0100 Subject: [PATCH 014/237] 2009-11-20 Colin D Bennett * include/grub/misc.h (grub_iscntrl): New inline function. (grub_isalnum): Likewise. (grub_strtol): Likewise. --- ChangeLog.gfxmenumisc | 6 ++++++ include/grub/misc.h | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 ChangeLog.gfxmenumisc diff --git a/ChangeLog.gfxmenumisc b/ChangeLog.gfxmenumisc new file mode 100644 index 000000000..ace9862ba --- /dev/null +++ b/ChangeLog.gfxmenumisc @@ -0,0 +1,6 @@ +2009-11-20 Colin D Bennett + + * include/grub/misc.h (grub_iscntrl): New inline function. + (grub_isalnum): Likewise. + (grub_strtol): Likewise. + diff --git a/include/grub/misc.h b/include/grub/misc.h index faa2d5c42..b843b9202 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -94,6 +94,12 @@ char *EXPORT_FUNC(grub_strstr) (const char *haystack, const char *needle); int EXPORT_FUNC(grub_isspace) (int c); int EXPORT_FUNC(grub_isprint) (int c); +static inline int +grub_iscntrl (int c) +{ + return (c >= 0x00 && c <= 0x1F) || c == 0x7F; +} + static inline int grub_isalpha (int c) { @@ -112,6 +118,12 @@ grub_isdigit (int c) return (c >= '0' && c <= '9'); } +static inline int +grub_isalnum (int c) +{ + return grub_isalpha (c) || grub_isdigit (c); +} + static inline int grub_tolower (int c) { @@ -166,6 +178,43 @@ grub_strncasecmp (const char *s1, const char *s2, grub_size_t n) unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base); unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, char **end, int base); + +static inline long +grub_strtol (const char *str, char **end, int base) +{ + int negative = 0; + unsigned long magnitude; + + while (*str && grub_isspace (*str)) + str++; + + if (*str == '-') + { + negative = 1; + str++; + } + + magnitude = grub_strtoull (str, end, base); + if (negative) + { + if (magnitude > (unsigned long) GRUB_LONG_MAX + 1) + { + grub_error (GRUB_ERR_OUT_OF_RANGE, "negative overflow"); + return GRUB_LONG_MIN; + } + return -((long) magnitude); + } + else + { + if (magnitude > GRUB_LONG_MAX) + { + grub_error (GRUB_ERR_OUT_OF_RANGE, "positive overflow"); + return GRUB_LONG_MAX; + } + return (long) magnitude; + } +} + char *EXPORT_FUNC(grub_strdup) (const char *s); char *EXPORT_FUNC(grub_strndup) (const char *s, grub_size_t n); void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n); From 1f1551457faf627f0c310f514c597da93138f0c1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 16:00:13 +0100 Subject: [PATCH 015/237] ChangeLog --- ChangeLog.trig | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 ChangeLog.trig diff --git a/ChangeLog.trig b/ChangeLog.trig new file mode 100644 index 000000000..c3cd73594 --- /dev/null +++ b/ChangeLog.trig @@ -0,0 +1,11 @@ +2009-11-14 Colin D Bennet + + Trigonometry support. + + * include/grub/trig.h: New file. + * lib/trig.c: Likewise. + * maintainance/gentrigtables.py: Likewise. + * conf/common.rmk (pkglib_MODULES): Add trig.mod. + (trig_mod_SOURCES): New variable. + (trig_mod_CFLAGS): Likewise. + (trig_mod_LDFLAGS): Likewise. From d920a32ab688df7cce1667434cc6785ebc840386 Mon Sep 17 00:00:00 2001 From: Colin D Bennett Date: Fri, 20 Nov 2009 16:02:58 +0100 Subject: [PATCH 016/237] gfxmenu import --- conf/common.rmk | 22 + docs/gfxmenu-theme-example.txt | 128 ++++++ gfxmenu/gfxmenu.c | 235 +++++++++++ gfxmenu/gui_box.c | 372 +++++++++++++++++ gfxmenu/gui_canvas.c | 268 ++++++++++++ gfxmenu/gui_circular_progress.c | 339 +++++++++++++++ gfxmenu/gui_image.c | 270 ++++++++++++ gfxmenu/gui_label.c | 248 +++++++++++ gfxmenu/gui_list.c | 625 +++++++++++++++++++++++++++ gfxmenu/gui_progress_bar.c | 378 +++++++++++++++++ gfxmenu/gui_string_util.c | 358 ++++++++++++++++ gfxmenu/gui_util.c | 101 +++++ gfxmenu/icon_manager.c | 258 ++++++++++++ gfxmenu/model.c | 191 +++++++++ gfxmenu/named_colors.c | 209 +++++++++ gfxmenu/theme_loader.c | 720 ++++++++++++++++++++++++++++++++ gfxmenu/view.c | 497 ++++++++++++++++++++++ gfxmenu/widget-box.c | 313 ++++++++++++++ include/grub/gfxmenu_model.h | 59 +++ include/grub/gfxmenu_view.h | 91 ++++ include/grub/gfxwidgets.h | 49 +++ include/grub/gui.h | 165 ++++++++ include/grub/gui_string_util.h | 39 ++ include/grub/icon_manager.h | 41 ++ include/grub/term.h | 2 +- 25 files changed, 5977 insertions(+), 1 deletion(-) create mode 100644 docs/gfxmenu-theme-example.txt create mode 100644 gfxmenu/gfxmenu.c create mode 100644 gfxmenu/gui_box.c create mode 100644 gfxmenu/gui_canvas.c create mode 100644 gfxmenu/gui_circular_progress.c create mode 100644 gfxmenu/gui_image.c create mode 100644 gfxmenu/gui_label.c create mode 100644 gfxmenu/gui_list.c create mode 100644 gfxmenu/gui_progress_bar.c create mode 100644 gfxmenu/gui_string_util.c create mode 100644 gfxmenu/gui_util.c create mode 100644 gfxmenu/icon_manager.c create mode 100644 gfxmenu/model.c create mode 100644 gfxmenu/named_colors.c create mode 100644 gfxmenu/theme_loader.c create mode 100644 gfxmenu/view.c create mode 100644 gfxmenu/widget-box.c create mode 100644 include/grub/gfxmenu_model.h create mode 100644 include/grub/gfxmenu_view.h create mode 100644 include/grub/gfxwidgets.h create mode 100644 include/grub/gui.h create mode 100644 include/grub/gui_string_util.h create mode 100644 include/grub/icon_manager.h diff --git a/conf/common.rmk b/conf/common.rmk index 3dddeb66d..4c1b845df 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -417,6 +417,28 @@ hello_mod_SOURCES = hello/hello.c hello_mod_CFLAGS = $(COMMON_CFLAGS) hello_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For gfxmenu.mod. +pkglib_MODULES += gfxmenu.mod +gfxmenu_mod_SOURCES = \ + gfxmenu/gfxmenu.c \ + gfxmenu/model.c \ + gfxmenu/view.c \ + gfxmenu/icon_manager.c \ + gfxmenu/theme_loader.c \ + gfxmenu/widget-box.c \ + gfxmenu/gui_canvas.c \ + gfxmenu/gui_circular_progress.c \ + gfxmenu/gui_box.c \ + gfxmenu/gui_label.c \ + gfxmenu/gui_list.c \ + gfxmenu/gui_image.c \ + gfxmenu/gui_progress_bar.c \ + gfxmenu/gui_util.c \ + gfxmenu/gui_string_util.c \ + gfxmenu/named_colors.c +gfxmenu_mod_CFLAGS = $(COMMON_CFLAGS) +gfxmenu_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For parttool.mod. parttool_mod_SOURCES = commands/parttool.c parttool_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/docs/gfxmenu-theme-example.txt b/docs/gfxmenu-theme-example.txt new file mode 100644 index 000000000..4363dc8df --- /dev/null +++ b/docs/gfxmenu-theme-example.txt @@ -0,0 +1,128 @@ +# GRUB gfxmenu theme "winter". +# Uses background image from: +# http://www.cyberpunkcafe.com/e107_plugins/autogallery/autogallery.php?show=1.Open%20Source%20Wallpaper +# "without-leaves.png" was called "Without Leafs in Winter.png" + +lua-script: "winter.lua" +title-text: "" +title-font: "Helvetica Bold 18" +status-font: "Helvetica 8" +terminal-font: "Fixed 9" +title-color: "40, 40, 40" +status-color: "#FFF" +status-bg-color: "0, 166, 183, 128" +desktop-image: "without-leaves.png" +desktop-color: "0, 154, 183" +terminal-box: "terminal_*.png" + ++ boot_menu { + position = (120, 60) + preferred_size = (400, -1) + item_font = "Helvetica Bold 14" + selected_item_font = "Helvetica Bold 14" + item_color = "0, 0, 0" + selected_item_color = "203, 251, 255" + menu_pixmap_style = "menu_*.png" + selected_item_pixmap_style = "select_*.png" + icon_width = 44 + icon_height = 44 + item_height = 32 + item_padding = 0 + item_icon_space = 3 + item_spacing = 11 +} + +# You can add text at arbitrary locations on the screen. +# The specification within the "+label {...}" block is free-form, +# so you can use as much or as little white space as you like. + ++ label { + position = (170, 50) + font = "smoothansi 13" + color = "0,0,128" + text = "This is the Winter theme ... brought to you by GRUB!" +} + +# Show the text alignment supported by labels. ++ vbox { + position = (220, 347) + preferred_size = (200, -1) # A preferred size of -1 means automatic. + + label { text="Text alignment demo" align="center" font="aqui 11" } + + label { text="Left" align="left" font="cure 11" } + + label { text="Center" align="center" font="cure 11" } + + label { text="Right" align="right" font="cure 11" } +} + ++ vbox { + position = (580, 10) + + label { text="GNU" font="gelly 11" color="0, 0, 0" } + + label { text="GRUB" font="aqui 11" color="0, 0, 0" } + + label { text="boot loader" font="cure 11" color="0, 0, 0" } +} + ++ hbox { + position = (80, 10) + + label { text="GNU" font="gelly 11" color="0, 0, 0" } + + label { text="GRUB" font="aqui 11" color="0, 0, 0" } + + label { text="boot loader" font="cure 11" color="0, 0, 0" } +} + +# Demonstration of a compound layout: boxes within boxes. ++ hbox +{ + position = (480, 3) + + + vbox + { + # Note: We can't just use 'size' to set the image's size, + # since the vbox will resize the component according to its + # preferred size, which for images is the native image size. + + + image { file="/boot/grub/themes/icons/ubuntu.png" + preferred_size = (20, 20) } + + image { file="/boot/grub/themes/icons/gentoo.png" + preferred_size = (20, 20) } + } + + + vbox + { + + label { text="GRand" font="cure 11" color=#99F } + + label { text="Unified" font="cure 11" color=#BBF } + + label { text="Bootloader" font="cure 11" color=#DDF } + } +} + +# By defining a 'progress_bar' type component with an ID of '__timeout__', +# the progress bar will be used to display the time remaining before an +# the default entry is automatically booted. ++ progress_bar +{ + id = "__timeout__" + position = (80, 393) + preferred_size = (500, 24) + font = "cure 11" + text_color = #000 + fg_color = #CCF + bg_color = #66B + border_color = #006 + show_text = false +} + +# Although the progress_bar component is normally used to indicate the +# time remaining, it's also possible to create other components with an ID +# of '__timeout__'. All components with and ID of 'timeout_bar' will have +# the following properties set based on the timeout value: +# text, value, start, end, visible. +# In this case, we have set 'show_text=false' on the progress bar, and use +# the following label's 'text' property to display the message. ++ label +{ + id = "__timeout__" + position = (80, 420) + preferred_size = (500, 24) + font = "lime 11" + color = #117 + align = "center" +} + + diff --git a/gfxmenu/gfxmenu.c b/gfxmenu/gfxmenu.c new file mode 100644 index 000000000..85ce5879d --- /dev/null +++ b/gfxmenu/gfxmenu.c @@ -0,0 +1,235 @@ +/* gfxmenu.c - Graphical menu interface controller. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void switch_to_text_menu (void) +{ + grub_env_set ("menuviewer", "text"); +} + +static void +process_key_press (int c, + grub_gfxmenu_model_t model, + grub_gfxmenu_view_t view, + int nested, + int *should_exit) +{ + /* When a key is pressed, stop the timeout. */ + grub_gfxmenu_model_clear_timeout (model); + + if (c == 'j' || c == GRUB_TERM_DOWN) + { + int i = grub_gfxmenu_model_get_selected_index (model); + int num_items = grub_gfxmenu_model_get_num_entries (model); + if (i < num_items - 1) + { + i++; + grub_gfxmenu_model_set_selected_index (model, i); + } + } + else if (c == 'k' || c == GRUB_TERM_UP) + { + int i = grub_gfxmenu_model_get_selected_index (model); + if (i > 0) + { + i--; + grub_gfxmenu_model_set_selected_index (model, i); + } + } + else if (c == '\r' || c == '\n' || c == GRUB_TERM_RIGHT) + { + int selected = grub_gfxmenu_model_get_selected_index (model); + int num_entries = grub_gfxmenu_model_get_num_entries (model); + if (selected >= 0 && selected < num_entries) + { + grub_menu_entry_t entry = + grub_gfxmenu_model_get_entry (model, selected); + grub_gfxmenu_view_execute_entry (view, entry); + } + } + else if (c == 'c') + { + grub_gfxmenu_view_run_terminal (view); + } + else if (c == 't') + { + /* The write hook for 'menuviewer' will cause + * grub_menu_viewer_should_return to return nonzero. */ + switch_to_text_menu (); + *should_exit = 1; + } + else if (c == '1') + { + grub_gfxmenu_view_load_theme (view, + "/boot/grub/themes/proto/theme.txt"); + } + else if (c == '2') + { + grub_gfxmenu_view_load_theme (view, + "/boot/grub/themes/winter/theme.txt"); + } + else if (c == '3') + { + grub_gfxmenu_view_load_theme (view, + "/boot/grub/themes/ubuntu1/theme.txt"); + } + else if (c == '4') + { + grub_gfxmenu_view_load_theme (view, + "/boot/grub/themes/ubuntu2/theme.txt"); + } + else if (nested && c == GRUB_TERM_ESC) + { + *should_exit = 1; + } + + if (grub_errno != GRUB_ERR_NONE) + *should_exit = 1; +} + +static void +handle_key_events (grub_gfxmenu_model_t model, + grub_gfxmenu_view_t view, + int nested, + int *should_exit) +{ + while ((! *should_exit) && (grub_checkkey () != -1)) + { + int key = grub_getkey (); + int c = GRUB_TERM_ASCII_CHAR (key); + process_key_press (c, model, view, nested, should_exit); + } +} + +static grub_err_t +show_menu (grub_menu_t menu, int nested) +{ + grub_gfxmenu_model_t model; + + model = grub_gfxmenu_model_new (menu); + if (! model) + { + grub_print_error (); + grub_printf ("Initializing menu data for graphical menu failed;\n" + "falling back to text based menu.\n"); + grub_wait_after_message (); + switch_to_text_menu (); + return grub_errno; + } + + grub_gfxmenu_view_t view; + + /* Create the view. */ + const char *theme_path = grub_env_get ("theme"); + if (! theme_path) + theme_path = "/boot/grub/themes/proto/theme.txt"; + + view = grub_gfxmenu_view_new (theme_path, model); + if (! view) + { + grub_print_error (); + grub_printf ("Starting graphical menu failed;\n" + "falling back to text based menu.\n"); + grub_wait_after_message (); + grub_gfxmenu_model_destroy (model); + switch_to_text_menu (); + return grub_errno; + } + + /* Initially select the default menu entry. */ + int default_index = grub_menu_get_default_entry_index (menu); + grub_gfxmenu_model_set_selected_index (model, default_index); + + /* Start the timer to execute the default entry. */ + grub_gfxmenu_model_set_timeout (model); + + /* Main event loop. */ + int exit_requested = 0; + while ((! exit_requested) && (! grub_menu_viewer_should_return ())) + { + if (grub_gfxmenu_model_timeout_expired (model)) + { + grub_gfxmenu_model_clear_timeout (model); + int i = grub_gfxmenu_model_get_selected_index (model); + grub_menu_entry_t e = grub_gfxmenu_model_get_entry (model, i); + grub_gfxmenu_view_execute_with_fallback (view, e); + continue; + } + + grub_gfxmenu_view_draw (view); + grub_video_swap_buffers (); + handle_key_events (model, view, nested, &exit_requested); + } + + grub_gfxmenu_view_destroy (view); + grub_gfxmenu_model_destroy (model); + + return grub_errno; +} + +static grub_err_t +grub_cmd_gfxmenu (grub_command_t cmd UNUSED, + int argc UNUSED, char **args UNUSED) +{ + grub_menu_t menu = grub_env_get_data_slot ("menu"); + if (! menu) + return grub_error (GRUB_ERR_MENU, "no menu context"); + + return show_menu (menu, 1); +} + +static struct grub_menu_viewer menu_viewer = +{ + .name = "gfxmenu", + .show_menu = show_menu +}; + +static grub_command_t cmd; + +GRUB_MOD_INIT (gfxmenu) +{ + (void) mod; /* To stop warning. */ + grub_menu_viewer_register (&menu_viewer); + cmd = grub_register_command ("gfxmenu", grub_cmd_gfxmenu, + "gfxmenu", + "Show graphical menu interface"); +} + +GRUB_MOD_FINI (gfxmenu) +{ + grub_unregister_command (cmd); +} diff --git a/gfxmenu/gui_box.c b/gfxmenu/gui_box.c new file mode 100644 index 000000000..876d0733f --- /dev/null +++ b/gfxmenu/gui_box.c @@ -0,0 +1,372 @@ +/* gui_box.c - GUI container that stack components. */ +/* + * 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 . + */ + +#include +#include +#include +#include + +struct component_node +{ + grub_gui_component_t component; + struct component_node *next; + struct component_node *prev; +}; + +typedef struct grub_gui_box *grub_gui_box_t; + +typedef void (*layout_func_t) (grub_gui_box_t self, int modify_layout, + int *width, int *height); + +struct grub_gui_box +{ + struct grub_gui_container_ops *container; + + grub_gui_container_t parent; + grub_video_rect_t bounds; + char *id; + int preferred_width; + int preferred_height; + + /* Doubly linked list of components with dummy head & tail nodes. */ + struct component_node chead; + struct component_node ctail; + + /* The layout function: differs for vertical and horizontal boxes. */ + layout_func_t layout_func; +}; + +static void +box_destroy (void *vself) +{ + grub_gui_box_t self = vself; + struct component_node *cur; + struct component_node *next; + for (cur = self->chead.next; cur != &self->ctail; cur = next) + { + /* Copy the 'next' pointer, since we need it for the next iteration, + and we're going to free the memory it is stored in. */ + next = cur->next; + /* Destroy the child component. */ + cur->component->ops->destroy (cur->component); + /* Free the linked list node. */ + grub_free (cur); + } + grub_free (self); +} + +static const char * +box_get_id (void *vself) +{ + grub_gui_box_t self = vself; + return self->id; +} + +static int +box_is_instance (void *vself __attribute__((unused)), const char *type) +{ + return (grub_strcmp (type, "component") == 0 + || grub_strcmp (type, "container") == 0); +} + +static void +layout_horizontally (grub_gui_box_t self, int modify_layout, + int *width, int *height) +{ + /* Start at the left (chead) and set the x coordinates as we go right. */ + /* All components have their width set to the box's width. */ + + struct component_node *cur; + int x = 0; + if (height) + *height = 0; + for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) + { + grub_gui_component_t c = cur->component; + grub_video_rect_t r; + + c->ops->get_preferred_size (c, &r.width, &r.height); + + /* Check and possibly update the maximum width, if non-null. */ + if (height && r.height > *height) + *height = r.height; + + /* Set the component's bounds, if the flag is set. */ + if (modify_layout) + { + r.x = x; + r.y = 0; + /* Width comes from the component's preferred size. */ + r.height = self->bounds.height; + c->ops->set_bounds (c, &r); + } + + x += r.width; + } + + /* Return the sum of the children's preferred widths. */ + if (width) + *width = x; +} + +static void +layout_vertically (grub_gui_box_t self, int modify_layout, + int *width, int *height) +{ + /* Start at the top (chead) and set the y coordinates as we go down. */ + /* All components have their width set to the vbox's width. */ + + struct component_node *cur; + int y = 0; + if (width) + *width = 0; + for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) + { + grub_gui_component_t c = cur->component; + grub_video_rect_t r; + + c->ops->get_preferred_size (c, &r.width, &r.height); + + /* Check and possibly update the maximum width, if non-null. */ + if (width && r.width > *width) + *width = r.width; + + /* Set the component's bounds, if the flag is set. */ + if (modify_layout) + { + r.x = 0; + r.y = y; + r.width = self->bounds.width; + /* Height comes from the component's preferred size. */ + c->ops->set_bounds (c, &r); + } + + y += r.height; + } + + /* Return the sum of the children's preferred heights. */ + if (height) + *height = y; +} + +static void +box_paint (void *vself) +{ + grub_gui_box_t self = vself; + struct component_node *cur; + grub_video_rect_t vpsave; + + grub_gui_set_viewport (&self->bounds, &vpsave); + for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) + { + grub_gui_component_t comp = cur->component; + comp->ops->paint (comp); + } + grub_gui_restore_viewport (&vpsave); +} + +static void +box_set_parent (void *vself, grub_gui_container_t parent) +{ + grub_gui_box_t self = vself; + self->parent = parent; +} + +static grub_gui_container_t +box_get_parent (void *vself) +{ + grub_gui_box_t self = vself; + return self->parent; +} + +static void +box_set_bounds (void *vself, const grub_video_rect_t *bounds) +{ + grub_gui_box_t self = vself; + self->bounds = *bounds; + self->layout_func (self, 1, 0, 0); /* Relayout the children. */ +} + +static void +box_get_bounds (void *vself, grub_video_rect_t *bounds) +{ + grub_gui_box_t self = vself; + *bounds = self->bounds; +} + +/* The box's preferred size is based on the preferred sizes + of its children. */ +static void +box_get_preferred_size (void *vself, int *width, int *height) +{ + grub_gui_box_t self = vself; + self->layout_func (self, 0, width, height); /* Just calculate the size. */ + + /* Allow preferred dimensions to override the computed dimensions. */ + if (self->preferred_width >= 0) + *width = self->preferred_width; + if (self->preferred_height >= 0) + *height = self->preferred_height; +} + +static grub_err_t +box_set_property (void *vself, const char *name, const char *value) +{ + grub_gui_box_t self = vself; + if (grub_strcmp (name, "id") == 0) + { + grub_free (self->id); + if (value) + { + self->id = grub_strdup (value); + if (! self->id) + return grub_errno; + } + else + self->id = 0; + } + else if (grub_strcmp (name, "preferred_size") == 0) + { + int w; + int h; + if (grub_gui_parse_2_tuple (value, &w, &h) != GRUB_ERR_NONE) + return grub_errno; + self->preferred_width = w; + self->preferred_height = h; + } + + return grub_errno; +} + +static void +box_add (void *vself, grub_gui_component_t comp) +{ + grub_gui_box_t self = vself; + struct component_node *node; + node = grub_malloc (sizeof (*node)); + if (! node) + return; /* Note: probably should handle the error. */ + node->component = comp; + /* Insert the node before the tail. */ + node->prev = self->ctail.prev; + node->prev->next = node; + node->next = &self->ctail; + node->next->prev = node; + + comp->ops->set_parent (comp, (grub_gui_container_t) self); + self->layout_func (self, 1, 0, 0); /* Relayout the children. */ +} + +static void +box_remove (void *vself, grub_gui_component_t comp) +{ + grub_gui_box_t self = vself; + struct component_node *cur; + for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) + { + if (cur->component == comp) + { + /* Unlink 'cur' from the list. */ + cur->prev->next = cur->next; + cur->next->prev = cur->prev; + /* Free the node's memory (but don't destroy the component). */ + grub_free (cur); + /* Must not loop again, since 'cur' would be dereferenced! */ + return; + } + } +} + +static void +box_iterate_children (void *vself, + grub_gui_component_callback cb, void *userdata) +{ + grub_gui_box_t self = vself; + struct component_node *cur; + for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) + cb (cur->component, userdata); +} + +static struct grub_gui_container_ops box_ops = +{ + .component = + { + .destroy = box_destroy, + .get_id = box_get_id, + .is_instance = box_is_instance, + .paint = box_paint, + .set_parent = box_set_parent, + .get_parent = box_get_parent, + .set_bounds = box_set_bounds, + .get_bounds = box_get_bounds, + .get_preferred_size = box_get_preferred_size, + .set_property = box_set_property + }, + .add = box_add, + .remove = box_remove, + .iterate_children = box_iterate_children +}; + +/* Box constructor. Specify the appropriate layout function to create + a horizontal or vertical stacking box. */ +static grub_gui_box_t +box_new (layout_func_t layout_func) +{ + grub_gui_box_t box; + box = grub_malloc (sizeof (*box)); + if (! box) + return 0; + box->container = &box_ops; + box->parent = 0; + box->bounds.x = 0; + box->bounds.y = 0; + box->bounds.width = 0; + box->bounds.height = 0; + box->id = 0; + box->preferred_width = -1; + box->preferred_height = -1; + box->chead.component = 0; + box->chead.prev = 0; + box->chead.next = &box->ctail; + box->ctail.component = 0; + box->ctail.prev = &box->chead; + box->ctail.next = 0; + box->layout_func = layout_func; + return box; +} + +/* Create a new container that stacks its child components horizontally, + from left to right. Each child get a width corresponding to its + preferred width. The height of each child is set the maximum of the + preferred heights of all children. */ +grub_gui_container_t +grub_gui_hbox_new (void) +{ + return (grub_gui_container_t) box_new (layout_horizontally); +} + +/* Create a new container that stacks its child components verticallyj, + from top to bottom. Each child get a height corresponding to its + preferred height. The width of each child is set the maximum of the + preferred widths of all children. */ +grub_gui_container_t +grub_gui_vbox_new (void) +{ + return (grub_gui_container_t) box_new (layout_vertically); +} diff --git a/gfxmenu/gui_canvas.c b/gfxmenu/gui_canvas.c new file mode 100644 index 000000000..a2cd77df6 --- /dev/null +++ b/gfxmenu/gui_canvas.c @@ -0,0 +1,268 @@ +/* gui_canvas.c - GUI container allowing manually placed components. */ +/* + * 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 . + */ + +#include +#include +#include +#include + +/* TODO Add layering so that components can be properly overlaid. */ + +struct component_node +{ + grub_gui_component_t component; + struct component_node *next; +}; + +struct grub_gui_canvas +{ + struct grub_gui_container_ops *container; + + grub_gui_container_t parent; + grub_video_rect_t bounds; + char *id; + int preferred_width; + int preferred_height; + /* Component list (dummy head node). */ + struct component_node components; +}; + +typedef struct grub_gui_canvas *grub_gui_canvas_t; + +static void +canvas_destroy (void *vself) +{ + grub_gui_canvas_t self = vself; + struct component_node *cur; + struct component_node *next; + for (cur = self->components.next; cur; cur = next) + { + /* Copy the 'next' pointer, since we need it for the next iteration, + and we're going to free the memory it is stored in. */ + next = cur->next; + /* Destroy the child component. */ + cur->component->ops->destroy (cur->component); + /* Free the linked list node. */ + grub_free (cur); + } + grub_free (self); +} + +static const char * +canvas_get_id (void *vself) +{ + grub_gui_canvas_t self = vself; + return self->id; +} + +static int +canvas_is_instance (void *vself __attribute__((unused)), const char *type) +{ + return (grub_strcmp (type, "component") == 0 + || grub_strcmp (type, "container") == 0); +} + +static void +canvas_paint (void *vself) +{ + grub_gui_canvas_t self = vself; + struct component_node *cur; + grub_video_rect_t vpsave; + + grub_gui_set_viewport (&self->bounds, &vpsave); + for (cur = self->components.next; cur; cur = cur->next) + { + int pw; + int ph; + grub_video_rect_t r; + grub_gui_component_t comp; + + comp = cur->component; + + /* Give the child its preferred size. */ + comp->ops->get_preferred_size (comp, &pw, &ph); + comp->ops->get_bounds (comp, &r); + if (r.width != pw || r.height != ph) + { + r.width = pw; + r.height = ph; + comp->ops->set_bounds (comp, &r); + } + + /* Paint the child. */ + comp->ops->paint (comp); + } + grub_gui_restore_viewport (&vpsave); +} + +static void +canvas_set_parent (void *vself, grub_gui_container_t parent) +{ + grub_gui_canvas_t self = vself; + self->parent = parent; +} + +static grub_gui_container_t +canvas_get_parent (void *vself) +{ + grub_gui_canvas_t self = vself; + return self->parent; +} + +static void +canvas_set_bounds (void *vself, const grub_video_rect_t *bounds) +{ + grub_gui_canvas_t self = vself; + self->bounds = *bounds; +} + +static void +canvas_get_bounds (void *vself, grub_video_rect_t *bounds) +{ + grub_gui_canvas_t self = vself; + *bounds = self->bounds; +} + +static void +canvas_get_preferred_size (void *vself, int *width, int *height) +{ + grub_gui_canvas_t self = vself; + *width = 0; + *height = 0; + + /* Allow preferred dimensions to override the empty dimensions. */ + if (self->preferred_width >= 0) + *width = self->preferred_width; + if (self->preferred_height >= 0) + *height = self->preferred_height; +} + +static grub_err_t +canvas_set_property (void *vself, const char *name, const char *value) +{ + grub_gui_canvas_t self = vself; + if (grub_strcmp (name, "id") == 0) + { + grub_free (self->id); + if (value) + { + self->id = grub_strdup (value); + if (! self->id) + return grub_errno; + } + else + self->id = 0; + } + else if (grub_strcmp (name, "preferred_size") == 0) + { + int w; + int h; + if (grub_gui_parse_2_tuple (value, &w, &h) != GRUB_ERR_NONE) + return grub_errno; + self->preferred_width = w; + self->preferred_height = h; + } + return grub_errno; +} + +static void +canvas_add (void *vself, grub_gui_component_t comp) +{ + grub_gui_canvas_t self = vself; + struct component_node *node; + node = grub_malloc (sizeof (*node)); + if (! node) + return; /* Note: probably should handle the error. */ + node->component = comp; + node->next = self->components.next; + self->components.next = node; + comp->ops->set_parent (comp, (grub_gui_container_t) self); +} + +static void +canvas_remove (void *vself, grub_gui_component_t comp) +{ + grub_gui_canvas_t self = vself; + struct component_node *cur; + struct component_node *prev; + prev = &self->components; + for (cur = self->components.next; cur; prev = cur, cur = cur->next) + { + if (cur->component == comp) + { + /* Unlink 'cur' from the list. */ + prev->next = cur->next; + /* Free the node's memory (but don't destroy the component). */ + grub_free (cur); + /* Must not loop again, since 'cur' would be dereferenced! */ + return; + } + } +} + +static void +canvas_iterate_children (void *vself, + grub_gui_component_callback cb, void *userdata) +{ + grub_gui_canvas_t self = vself; + struct component_node *cur; + for (cur = self->components.next; cur; cur = cur->next) + cb (cur->component, userdata); +} + +static struct grub_gui_container_ops canvas_ops = +{ + .component = + { + .destroy = canvas_destroy, + .get_id = canvas_get_id, + .is_instance = canvas_is_instance, + .paint = canvas_paint, + .set_parent = canvas_set_parent, + .get_parent = canvas_get_parent, + .set_bounds = canvas_set_bounds, + .get_bounds = canvas_get_bounds, + .get_preferred_size = canvas_get_preferred_size, + .set_property = canvas_set_property + }, + .add = canvas_add, + .remove = canvas_remove, + .iterate_children = canvas_iterate_children +}; + +grub_gui_container_t +grub_gui_canvas_new (void) +{ + grub_gui_canvas_t canvas; + canvas = grub_malloc (sizeof (*canvas)); + if (! canvas) + return 0; + canvas->container = &canvas_ops; + canvas->parent = 0; + canvas->bounds.x = 0; + canvas->bounds.y = 0; + canvas->bounds.width = 0; + canvas->bounds.height = 0; + canvas->id = 0; + canvas->preferred_width = -1; + canvas->preferred_height = -1; + canvas->components.component = 0; + canvas->components.next = 0; + return (grub_gui_container_t) canvas; +} diff --git a/gfxmenu/gui_circular_progress.c b/gfxmenu/gui_circular_progress.c new file mode 100644 index 000000000..cd95c51f9 --- /dev/null +++ b/gfxmenu/gui_circular_progress.c @@ -0,0 +1,339 @@ +/* gui_circular_process.c - GUI circular progress indicator component. */ +/* + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct grub_gui_circular_progress +{ + struct grub_gui_component_ops *circprog_ops; + + grub_gui_container_t parent; + grub_video_rect_t bounds; + char *id; + int preferred_width; + int preferred_height; + int visible; + int start; + int end; + int value; + int num_ticks; + int start_angle; + int ticks_disappear; + char *theme_dir; + int need_to_load_pixmaps; + char *center_file; + char *tick_file; + struct grub_video_bitmap *center_bitmap; + struct grub_video_bitmap *tick_bitmap; +}; + +typedef struct grub_gui_circular_progress *circular_progress_t; + +static void +circprog_destroy (void *vself) +{ + circular_progress_t self = vself; + grub_free (self); +} + +static const char * +circprog_get_id (void *vself) +{ + circular_progress_t self = vself; + return self->id; +} + +static int +circprog_is_instance (void *vself __attribute__((unused)), const char *type) +{ + return grub_strcmp (type, "component") == 0; +} + +static struct grub_video_bitmap * +load_bitmap (const char *dir, const char *file) +{ + struct grub_video_bitmap *bitmap; + char *abspath; + + /* Check arguments. */ + if (! dir || ! file) + return 0; + + /* Resolve to an absolute path. */ + abspath = grub_resolve_relative_path (dir, file); + if (! abspath) + return 0; + + /* Load the image. */ + grub_errno = GRUB_ERR_NONE; + grub_video_bitmap_load (&bitmap, abspath); + grub_errno = GRUB_ERR_NONE; + + grub_free (abspath); + return bitmap; +} + +static int +check_pixmaps (circular_progress_t self) +{ + if (self->need_to_load_pixmaps) + { + if (self->center_bitmap) + grub_video_bitmap_destroy (self->center_bitmap); + self->center_bitmap = load_bitmap (self->theme_dir, self->center_file); + self->tick_bitmap = load_bitmap (self->theme_dir, self->tick_file); + self->need_to_load_pixmaps = 0; + } + + return (self->center_bitmap != 0 && self->tick_bitmap != 0); +} + +static void +circprog_paint (void *vself) +{ + circular_progress_t self = vself; + + if (! self->visible) + return; + if (! check_pixmaps (self)) + return; + + grub_video_rect_t vpsave; + grub_gui_set_viewport (&self->bounds, &vpsave); + + int width = self->bounds.width; + int height = self->bounds.height; + int center_width = grub_video_bitmap_get_width (self->center_bitmap); + int center_height = grub_video_bitmap_get_height (self->center_bitmap); + int tick_width = grub_video_bitmap_get_width (self->tick_bitmap); + int tick_height = grub_video_bitmap_get_height (self->tick_bitmap); + grub_video_blit_bitmap (self->center_bitmap, GRUB_VIDEO_BLIT_BLEND, + (width - center_width) / 2, + (height - center_height) / 2, 0, 0, + center_width, center_height); + + int radius = width / 2 - tick_width / 2 - 1; + int nticks = (self->num_ticks + * (self->value - self->start) + / (self->end - self->start)); + int tick_begin; + int tick_end; + /* Do ticks appear or disappear as the value approached the end? */ + if (self->ticks_disappear) + { + tick_begin = nticks; + tick_end = self->num_ticks - 1; + } + else + { + tick_begin = 0; + tick_end = nticks - 1; + } + + int i; + for (i = tick_begin; i < tick_end; i++) + { + int x; + int y; + int angle; + + /* Calculate the location of the tick. */ + angle = self->start_angle + i * GRUB_TRIG_ANGLE_MAX / self->num_ticks; + x = width / 2 + (grub_cos (angle) * radius / GRUB_TRIG_FRACTION_SCALE); + y = height / 2 + (grub_sin (angle) * radius / GRUB_TRIG_FRACTION_SCALE); + + /* Adjust (x,y) so the tick is centered. */ + x -= tick_width / 2; + y -= tick_height / 2; + + /* Draw the tick. */ + grub_video_blit_bitmap (self->tick_bitmap, GRUB_VIDEO_BLIT_BLEND, + x, y, 0, 0, tick_width, tick_height); + } + + grub_gui_restore_viewport (&vpsave); +} + +static void +circprog_set_parent (void *vself, grub_gui_container_t parent) +{ + circular_progress_t self = vself; + self->parent = parent; +} + +static grub_gui_container_t +circprog_get_parent (void *vself) +{ + circular_progress_t self = vself; + return self->parent; +} + +static void +circprog_set_bounds (void *vself, const grub_video_rect_t *bounds) +{ + circular_progress_t self = vself; + self->bounds = *bounds; +} + +static void +circprog_get_bounds (void *vself, grub_video_rect_t *bounds) +{ + circular_progress_t self = vself; + *bounds = self->bounds; +} + +static void +circprog_get_preferred_size (void *vself, int *width, int *height) +{ + circular_progress_t self = vself; + + *width = 0; + *height = 0; + + /* Allow preferred dimensions to override the circprog dimensions. */ + if (self->preferred_width >= 0) + *width = self->preferred_width; + if (self->preferred_height >= 0) + *height = self->preferred_height; +} + +static grub_err_t +circprog_set_property (void *vself, const char *name, const char *value) +{ + circular_progress_t self = vself; + if (grub_strcmp (name, "value") == 0) + { + self->value = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "start") == 0) + { + self->start = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "end") == 0) + { + self->end = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "num_ticks") == 0) + { + self->num_ticks = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "start_angle") == 0) + { + self->start_angle = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "ticks_disappear") == 0) + { + self->ticks_disappear = grub_strcmp (value, "false") != 0; + } + else if (grub_strcmp (name, "center_bitmap") == 0) + { + self->need_to_load_pixmaps = 1; + grub_free (self->center_file); + self->center_file = value ? grub_strdup (value) : 0; + } + else if (grub_strcmp (name, "tick_bitmap") == 0) + { + self->need_to_load_pixmaps = 1; + grub_free (self->tick_file); + self->tick_file = value ? grub_strdup (value) : 0; + } + else if (grub_strcmp (name, "theme_dir") == 0) + { + self->need_to_load_pixmaps = 1; + grub_free (self->theme_dir); + self->theme_dir = value ? grub_strdup (value) : 0; + } + else if (grub_strcmp (name, "preferred_size") == 0) + { + int w; + int h; + if (grub_gui_parse_2_tuple (value, &w, &h) != GRUB_ERR_NONE) + return grub_errno; + self->preferred_width = w; + self->preferred_height = h; + } + else if (grub_strcmp (name, "visible") == 0) + { + self->visible = grub_strcmp (value, "false") != 0; + } + else if (grub_strcmp (name, "id") == 0) + { + grub_free (self->id); + if (value) + self->id = grub_strdup (value); + else + self->id = 0; + } + return grub_errno; +} + +static struct grub_gui_component_ops circprog_ops = +{ + .destroy = circprog_destroy, + .get_id = circprog_get_id, + .is_instance = circprog_is_instance, + .paint = circprog_paint, + .set_parent = circprog_set_parent, + .get_parent = circprog_get_parent, + .set_bounds = circprog_set_bounds, + .get_bounds = circprog_get_bounds, + .get_preferred_size = circprog_get_preferred_size, + .set_property = circprog_set_property +}; + +grub_gui_component_t +grub_gui_circular_progress_new (void) +{ + circular_progress_t self; + self = grub_malloc (sizeof (*self)); + if (! self) + return 0; + self->circprog_ops = &circprog_ops; + self->parent = 0; + self->bounds.x = 0; + self->bounds.y = 0; + self->bounds.width = 0; + self->bounds.height = 0; + self->id = 0; + self->preferred_width = -1; + self->preferred_height = -1; + self->visible = 1; + self->start = 0; + self->end = 0; + self->value = 0; + self->num_ticks = 64; + self->start_angle = -64; + self->ticks_disappear = 0; + + self->theme_dir = 0; + self->need_to_load_pixmaps = 0; + self->center_file = 0; + self->tick_file = 0; + self->center_bitmap = 0; + self->tick_bitmap = 0; + + return (grub_gui_component_t) self; +} diff --git a/gfxmenu/gui_image.c b/gfxmenu/gui_image.c new file mode 100644 index 000000000..1c58a535b --- /dev/null +++ b/gfxmenu/gui_image.c @@ -0,0 +1,270 @@ +/* gui_image.c - GUI component to display an image. */ +/* + * 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 . + */ + +#include +#include +#include +#include +#include +#include + +struct grub_gui_image +{ + struct grub_gui_component_ops *image; + + grub_gui_container_t parent; + grub_video_rect_t bounds; + char *id; + int preferred_width; + int preferred_height; + struct grub_video_bitmap *raw_bitmap; + struct grub_video_bitmap *bitmap; +}; + +typedef struct grub_gui_image *grub_gui_image_t; + +static void +image_destroy (void *vself) +{ + grub_gui_image_t self = vself; + + /* Free the scaled bitmap, unless it's a reference to the raw bitmap. */ + if (self->bitmap && (self->bitmap != self->raw_bitmap)) + grub_video_bitmap_destroy (self->bitmap); + if (self->raw_bitmap) + grub_video_bitmap_destroy (self->raw_bitmap); + + grub_free (self); +} + +static const char * +image_get_id (void *vself) +{ + grub_gui_image_t self = vself; + return self->id; +} + +static int +image_is_instance (void *vself __attribute__((unused)), const char *type) +{ + return grub_strcmp (type, "component") == 0; +} + +static void +image_paint (void *vself) +{ + grub_gui_image_t self = vself; + if (! self->bitmap) + return; + grub_video_rect_t vpsave; + grub_gui_set_viewport (&self->bounds, &vpsave); + grub_video_blit_bitmap (self->bitmap, GRUB_VIDEO_BLIT_BLEND, + 0, 0, 0, 0, + grub_video_bitmap_get_width (self->bitmap), + grub_video_bitmap_get_height (self->bitmap)); + grub_gui_restore_viewport (&vpsave); +} + +static void +image_set_parent (void *vself, grub_gui_container_t parent) +{ + grub_gui_image_t self = vself; + self->parent = parent; +} + +static grub_gui_container_t +image_get_parent (void *vself) +{ + grub_gui_image_t self = vself; + return self->parent; +} + +static grub_err_t +rescale_image (grub_gui_image_t self) +{ + if (! self->raw_bitmap) + { + if (self->bitmap) + { + grub_video_bitmap_destroy (self->bitmap); + self->bitmap = 0; + } + return grub_errno; + } + + unsigned width = self->bounds.width; + unsigned height = self->bounds.height; + + if (self->bitmap + && (grub_video_bitmap_get_width (self->bitmap) == width) + && (grub_video_bitmap_get_height (self->bitmap) == height)) + { + /* Nothing to do; already the right size. */ + return grub_errno; + } + + /* Free any old scaled bitmap, + *unless* it's a reference to the raw bitmap. */ + if (self->bitmap && (self->bitmap != self->raw_bitmap)) + grub_video_bitmap_destroy (self->bitmap); + + self->bitmap = 0; + + /* Create a scaled bitmap, unless the requested size is the same + as the raw size -- in that case a reference is made. */ + if (grub_video_bitmap_get_width (self->raw_bitmap) == width + && grub_video_bitmap_get_height (self->raw_bitmap) == height) + { + self->bitmap = self->raw_bitmap; + return grub_errno; + } + + /* Don't scale to an invalid size. */ + if (width == 0 || height == 0) + return grub_errno; + + /* Create the scaled bitmap. */ + grub_video_bitmap_create_scaled (&self->bitmap, + width, + height, + self->raw_bitmap, + GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST); + if (grub_errno != GRUB_ERR_NONE) + { + grub_error_push (); + grub_error (grub_errno, "failed to scale bitmap for image component"); + } + return grub_errno; +} + +static void +image_set_bounds (void *vself, const grub_video_rect_t *bounds) +{ + grub_gui_image_t self = vself; + self->bounds = *bounds; + rescale_image (self); +} + +static void +image_get_bounds (void *vself, grub_video_rect_t *bounds) +{ + grub_gui_image_t self = vself; + *bounds = self->bounds; +} + +static void +image_get_preferred_size (void *vself, int *width, int *height) +{ + grub_gui_image_t self = vself; + + if (self->raw_bitmap) + { + *width = grub_video_bitmap_get_width (self->raw_bitmap); + *height = grub_video_bitmap_get_height (self->raw_bitmap); + } + else + { + *width = 0; + *height = 0; + } + + /* Allow preferred dimensions to override the image dimensions. */ + if (self->preferred_width >= 0) + *width = self->preferred_width; + if (self->preferred_height >= 0) + *height = self->preferred_height; +} + +static grub_err_t +load_image (grub_gui_image_t self, const char *path) +{ + struct grub_video_bitmap *bitmap; + if (grub_video_bitmap_load (&bitmap, path) != GRUB_ERR_NONE) + return grub_errno; + + if (self->bitmap && (self->bitmap != self->raw_bitmap)) + grub_video_bitmap_destroy (self->bitmap); + if (self->raw_bitmap) + grub_video_bitmap_destroy (self->raw_bitmap); + + self->raw_bitmap = bitmap; + return rescale_image (self); +} + +static grub_err_t +image_set_property (void *vself, const char *name, const char *value) +{ + grub_gui_image_t self = vself; + if (grub_strcmp (name, "file") == 0) + return load_image (self, value); + else if (grub_strcmp (name, "preferred_size") == 0) + { + int w; + int h; + if (grub_gui_parse_2_tuple (value, &w, &h) != GRUB_ERR_NONE) + return grub_errno; + self->preferred_width = w; + self->preferred_height = h; + } + else if (grub_strcmp (name, "id") == 0) + { + grub_free (self->id); + if (value) + self->id = grub_strdup (value); + else + self->id = 0; + } + return grub_errno; +} + +static struct grub_gui_component_ops image_ops = +{ + .destroy = image_destroy, + .get_id = image_get_id, + .is_instance = image_is_instance, + .paint = image_paint, + .set_parent = image_set_parent, + .get_parent = image_get_parent, + .set_bounds = image_set_bounds, + .get_bounds = image_get_bounds, + .get_preferred_size = image_get_preferred_size, + .set_property = image_set_property +}; + +grub_gui_component_t +grub_gui_image_new (void) +{ + grub_gui_image_t image; + image = grub_malloc (sizeof (*image)); + if (! image) + return 0; + image->image = &image_ops; + image->parent = 0; + image->bounds.x = 0; + image->bounds.y = 0; + image->bounds.width = 0; + image->bounds.height = 0; + image->id = 0; + image->preferred_width = -1; + image->preferred_height = -1; + image->raw_bitmap = 0; + image->bitmap = 0; + return (grub_gui_component_t) image; +} + diff --git a/gfxmenu/gui_label.c b/gfxmenu/gui_label.c new file mode 100644 index 000000000..2e49c787e --- /dev/null +++ b/gfxmenu/gui_label.c @@ -0,0 +1,248 @@ +/* gui_label.c - GUI component to display a line of text. */ +/* + * 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 . + */ + +#include +#include +#include +#include +#include + +static const char *align_options[] = +{ + "left", + "center", + "right", + 0 +}; + +enum align_mode { + align_left, + align_center, + align_right +}; + +struct grub_gui_label +{ + struct grub_gui_component_ops *label; + + grub_gui_container_t parent; + grub_video_rect_t bounds; + char *id; + int preferred_width; + int preferred_height; + int visible; + char *text; + grub_font_t font; + grub_gui_color_t color; + enum align_mode align; +}; + +typedef struct grub_gui_label *grub_gui_label_t; + +static void +label_destroy (void *vself) +{ + grub_gui_label_t self = vself; + grub_free (self->text); + grub_free (self); +} + +static const char * +label_get_id (void *vself) +{ + grub_gui_label_t self = vself; + return self->id; +} + +static int +label_is_instance (void *vself __attribute__((unused)), const char *type) +{ + return grub_strcmp (type, "component") == 0; +} + +static void +label_paint (void *vself) +{ + grub_gui_label_t self = vself; + + if (! self->visible) + return; + + /* Calculate the starting x coordinate. */ + int left_x; + if (self->align == align_left) + left_x = 0; + else if (self->align == align_center) + left_x = ((self->bounds.width + - grub_font_get_string_width (self->font, self->text)) + ) / 2; + else if (self->align == align_right) + left_x = (self->bounds.width + - grub_font_get_string_width (self->font, self->text)); + else + return; /* Invalid alignment. */ + + grub_video_rect_t vpsave; + grub_gui_set_viewport (&self->bounds, &vpsave); + grub_font_draw_string (self->text, + self->font, + grub_gui_map_color (self->color), + left_x, + grub_font_get_ascent (self->font)); + grub_gui_restore_viewport (&vpsave); +} + +static void +label_set_parent (void *vself, grub_gui_container_t parent) +{ + grub_gui_label_t self = vself; + self->parent = parent; +} + +static grub_gui_container_t +label_get_parent (void *vself) +{ + grub_gui_label_t self = vself; + return self->parent; +} + +static void +label_set_bounds (void *vself, const grub_video_rect_t *bounds) +{ + grub_gui_label_t self = vself; + self->bounds = *bounds; +} + +static void +label_get_bounds (void *vself, grub_video_rect_t *bounds) +{ + grub_gui_label_t self = vself; + *bounds = self->bounds; +} + +static void +label_get_preferred_size (void *vself, int *width, int *height) +{ + grub_gui_label_t self = vself; + *width = grub_font_get_string_width (self->font, self->text); + *height = (grub_font_get_ascent (self->font) + + grub_font_get_descent (self->font)); + + /* Allow preferred dimensions to override the computed dimensions. */ + if (self->preferred_width >= 0) + *width = self->preferred_width; + if (self->preferred_height >= 0) + *height = self->preferred_height; +} + +static void +label_set_property (void *vself, const char *name, const char *value) +{ + grub_gui_label_t self = vself; + if (grub_strcmp (name, "text") == 0) + { + grub_free (self->text); + if (! value) + value = ""; + self->text = grub_strdup (value); + } + else if (grub_strcmp (name, "font") == 0) + { + self->font = grub_font_get (value); + } + else if (grub_strcmp (name, "color") == 0) + { + grub_gui_parse_color (value, &self->color); + } + else if (grub_strcmp (name, "align") == 0) + { + int i; + for (i = 0; align_options[i]; i++) + { + if (grub_strcmp (align_options[i], value) == 0) + { + self->align = i; /* Set the alignment mode. */ + break; + } + } + } + else if (grub_strcmp (name, "visible") == 0) + { + self->visible = grub_strcmp (value, "false") != 0; + } + else if (grub_strcmp (name, "preferred_size") == 0) + { + int w; + int h; + if (grub_gui_parse_2_tuple (value, &w, &h) == GRUB_ERR_NONE) + { + self->preferred_width = w; + self->preferred_height = h; + } + } + else if (grub_strcmp (name, "id") == 0) + { + grub_free (self->id); + if (value) + self->id = grub_strdup (value); + else + self->id = 0; + } +} + +static struct grub_gui_component_ops label_ops = +{ + .destroy = label_destroy, + .get_id = label_get_id, + .is_instance = label_is_instance, + .paint = label_paint, + .set_parent = label_set_parent, + .get_parent = label_get_parent, + .set_bounds = label_set_bounds, + .get_bounds = label_get_bounds, + .get_preferred_size = label_get_preferred_size, + .set_property = label_set_property +}; + +grub_gui_component_t +grub_gui_label_new (void) +{ + grub_gui_label_t label; + label = grub_malloc (sizeof (*label)); + if (! label) + return 0; + label->label = &label_ops; + label->parent = 0; + label->bounds.x = 0; + label->bounds.y = 0; + label->bounds.width = 0; + label->bounds.height = 0; + label->id = 0; + label->preferred_width = -1; + label->preferred_height = -1; + label->visible = 1; + label->text = grub_strdup (""); + label->font = grub_font_get ("Helvetica 10"); + label->color.red = 0; + label->color.green = 0; + label->color.blue = 0; + label->color.alpha = 255; + label->align = align_left; + return (grub_gui_component_t) label; +} diff --git a/gfxmenu/gui_list.c b/gfxmenu/gui_list.c new file mode 100644 index 000000000..aa9655b45 --- /dev/null +++ b/gfxmenu/gui_list.c @@ -0,0 +1,625 @@ +/* gui_list.c - GUI component to display a selectable list of items. */ +/* + * 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 . + */ + +#include +#include +#include +#include +#include +#include + +struct grub_gui_list_impl +{ + struct grub_gui_list_ops *list_ops; + + grub_gui_container_t parent; + grub_video_rect_t bounds; + char *id; + int preferred_width; + int preferred_height; + int visible; + + int icon_width; + int icon_height; + int item_height; + int item_padding; + int item_icon_space; + int item_spacing; + grub_font_t item_font; + grub_font_t selected_item_font; + grub_gui_color_t item_color; + int selected_item_color_set; + grub_gui_color_t selected_item_color; + + int draw_scrollbar; + int need_to_recreate_scrollbar; + char *scrollbar_frame_pattern; + char *scrollbar_thumb_pattern; + grub_gfxmenu_box_t scrollbar_frame; + grub_gfxmenu_box_t scrollbar_thumb; + int scrollbar_width; + + int min_items_shown; + int max_items_shown; + int first_shown_index; + + int need_to_recreate_boxes; + char *theme_dir; + char *menu_box_pattern; + char *selected_item_box_pattern; + grub_gfxmenu_box_t menu_box; + grub_gfxmenu_box_t selected_item_box; + + grub_gfxmenu_icon_manager_t icon_manager; + grub_gfxmenu_model_t menu; +}; + +typedef struct grub_gui_list_impl *list_impl_t; + +static void +list_destroy (void *vself) +{ + list_impl_t self = vself; + + grub_free (self->theme_dir); + grub_free (self->menu_box_pattern); + grub_free (self->selected_item_box_pattern); + if (self->menu_box) + self->menu_box->destroy (self->menu_box); + if (self->selected_item_box) + self->selected_item_box->destroy (self->selected_item_box); + if (self->icon_manager) + grub_gfxmenu_icon_manager_destroy (self->icon_manager); + + grub_free (self); +} + +static int +get_num_shown_items (list_impl_t self) +{ + int n = grub_gfxmenu_model_get_num_entries (self->menu); + if (self->min_items_shown != -1 && n < self->min_items_shown) + n = self->min_items_shown; + if (self->max_items_shown != -1 && n > self->max_items_shown) + n = self->max_items_shown; + return n; +} + +static int +check_boxes (list_impl_t self) +{ + if (self->need_to_recreate_boxes) + { + grub_gui_recreate_box (&self->menu_box, + self->menu_box_pattern, + self->theme_dir); + + grub_gui_recreate_box (&self->selected_item_box, + self->selected_item_box_pattern, + self->theme_dir); + + self->need_to_recreate_boxes = 0; + } + + return (self->menu_box != 0 && self->selected_item_box != 0); +} + +static int +check_scrollbar (list_impl_t self) +{ + if (self->need_to_recreate_scrollbar) + { + grub_gui_recreate_box (&self->scrollbar_frame, + self->scrollbar_frame_pattern, + self->theme_dir); + + grub_gui_recreate_box (&self->scrollbar_thumb, + self->scrollbar_thumb_pattern, + self->theme_dir); + + self->need_to_recreate_scrollbar = 0; + } + + return (self->scrollbar_frame != 0 && self->scrollbar_thumb != 0); +} + +static const char * +list_get_id (void *vself) +{ + list_impl_t self = vself; + return self->id; +} + +static int +list_is_instance (void *vself __attribute__((unused)), const char *type) +{ + return (grub_strcmp (type, "component") == 0 + || grub_strcmp (type, "list") == 0); +} + +static struct grub_video_bitmap * +get_item_icon (list_impl_t self, int item_index) +{ + grub_menu_entry_t entry; + entry = grub_gfxmenu_model_get_entry (self->menu, item_index); + if (! entry) + return 0; + + return grub_gfxmenu_icon_manager_get_icon (self->icon_manager, entry); +} + +static void +make_selected_item_visible (list_impl_t self) +{ + int selected_index = grub_gfxmenu_model_get_selected_index (self->menu); + if (selected_index < 0) + return; /* No item is selected. */ + int num_shown_items = get_num_shown_items (self); + int last_shown_index = self->first_shown_index + (num_shown_items - 1); + if (selected_index < self->first_shown_index) + self->first_shown_index = selected_index; + else if (selected_index > last_shown_index) + self->first_shown_index = selected_index - (num_shown_items - 1); +} + +/* Draw a scrollbar on the menu. */ +static void +draw_scrollbar (list_impl_t self, + int value, int extent, int min, int max, + int rightx, int topy, int height) +{ + grub_gfxmenu_box_t frame = self->scrollbar_frame; + grub_gfxmenu_box_t thumb = self->scrollbar_thumb; + int frame_vertical_pad = (frame->get_top_pad (frame) + + frame->get_bottom_pad (frame)); + int frame_horizontal_pad = (frame->get_left_pad (frame) + + frame->get_right_pad (frame)); + int tracktop = topy + frame->get_top_pad (frame); + int tracklen = height - frame_vertical_pad; + frame->set_content_size (frame, self->scrollbar_width, tracklen); + int thumby = tracktop + tracklen * (value - min) / (max - min); + int thumbheight = tracklen * extent / (max - min) + 1; + thumb->set_content_size (thumb, + self->scrollbar_width - frame_horizontal_pad, + thumbheight - (thumb->get_top_pad (thumb) + + thumb->get_bottom_pad (thumb))); + frame->draw (frame, + rightx - (self->scrollbar_width + frame_horizontal_pad), + topy); + thumb->draw (thumb, + rightx - (self->scrollbar_width - frame->get_right_pad (frame)), + thumby); +} + +/* Draw the list of items. */ +static void +draw_menu (list_impl_t self) +{ + if (! self->menu_box || ! self->selected_item_box) + return; + + int boxpad = self->item_padding; + int icon_text_space = self->item_icon_space; + int item_vspace = self->item_spacing; + + int ascent = grub_font_get_ascent (self->item_font); + int descent = grub_font_get_descent (self->item_font); + int item_height = self->item_height; + + int total_num_items = grub_gfxmenu_model_get_num_entries (self->menu); + int num_shown_items = get_num_shown_items (self); + grub_gfxmenu_box_t box = self->menu_box; + int width = self->bounds.width; + int height = self->bounds.height; + + int box_left_pad = box->get_left_pad (box); + int box_top_pad = box->get_top_pad (box); + int box_right_pad = box->get_right_pad (box); + int box_bottom_pad = box->get_bottom_pad (box); + + box->set_content_size (box, + width - box_left_pad - box_right_pad, + height - box_top_pad - box_bottom_pad); + + box->draw (box, 0, 0); + + make_selected_item_visible (self); + + int drawing_scrollbar = (self->draw_scrollbar + && (num_shown_items < total_num_items) + && check_scrollbar (self)); + + int scrollbar_h_space = drawing_scrollbar ? self->scrollbar_width : 0; + + int item_top = box_top_pad + boxpad; + int item_left = box_left_pad + boxpad; + int menu_index; + int visible_index; + + for (visible_index = 0, menu_index = self->first_shown_index; + visible_index < num_shown_items && menu_index < total_num_items; + visible_index++, menu_index++) + { + int is_selected = + (menu_index == grub_gfxmenu_model_get_selected_index (self->menu)); + + if (is_selected) + { + grub_gfxmenu_box_t selbox = self->selected_item_box; + int sel_leftpad = selbox->get_left_pad (selbox); + int sel_toppad = selbox->get_top_pad (selbox); + selbox->set_content_size (selbox, + (width - 2 * boxpad + - box_left_pad - box_right_pad + - scrollbar_h_space), + item_height); + selbox->draw (selbox, + item_left - sel_leftpad, + item_top - sel_toppad); + } + + struct grub_video_bitmap *icon; + if ((icon = get_item_icon (self, menu_index)) != 0) + grub_video_blit_bitmap (icon, GRUB_VIDEO_BLIT_BLEND, + item_left, + item_top + (item_height - self->icon_height) / 2, + 0, 0, self->icon_width, self->icon_height); + + const char *item_title = + grub_gfxmenu_model_get_entry_title (self->menu, menu_index); + grub_font_t font = + (is_selected && self->selected_item_font + ? self->selected_item_font + : self->item_font); + grub_gui_color_t text_color = + ((is_selected && self->selected_item_color_set) + ? self->selected_item_color + : self->item_color); + grub_font_draw_string (item_title, + font, + grub_gui_map_color (text_color), + item_left + self->icon_width + icon_text_space, + (item_top + (item_height - (ascent + descent)) + / 2 + ascent)); + + item_top += item_height + item_vspace; + } + + if (drawing_scrollbar) + draw_scrollbar (self, + self->first_shown_index, num_shown_items, + 0, total_num_items, + width - box_right_pad + self->scrollbar_width, + box_top_pad + boxpad, + height - box_top_pad - box_bottom_pad); +} + +static void +list_paint (void *vself) +{ + list_impl_t self = vself; + + if (! self->visible) + return; + + check_boxes (self); + + grub_video_rect_t vpsave; + grub_gui_set_viewport (&self->bounds, &vpsave); + draw_menu (self); + grub_gui_restore_viewport (&vpsave); +} + +static void +list_set_parent (void *vself, grub_gui_container_t parent) +{ + list_impl_t self = vself; + self->parent = parent; +} + +static grub_gui_container_t +list_get_parent (void *vself) +{ + list_impl_t self = vself; + return self->parent; +} + +static void +list_set_bounds (void *vself, const grub_video_rect_t *bounds) +{ + list_impl_t self = vself; + self->bounds = *bounds; +} + +static void +list_get_bounds (void *vself, grub_video_rect_t *bounds) +{ + list_impl_t self = vself; + *bounds = self->bounds; +} + +static void +list_get_preferred_size (void *vself, int *width, int *height) +{ + list_impl_t self = vself; + + if (check_boxes (self)) + { + int boxpad = self->item_padding; + int item_vspace = self->item_spacing; + int item_height = self->item_height; + int num_items = get_num_shown_items (self); + + grub_gfxmenu_box_t box = self->menu_box; + int box_left_pad = box->get_left_pad (box); + int box_top_pad = box->get_top_pad (box); + int box_right_pad = box->get_right_pad (box); + int box_bottom_pad = box->get_bottom_pad (box); + + *width = 400 + 2 * boxpad + box_left_pad + box_right_pad; + + /* Set the menu box height to fit the items. */ + *height = (item_height * num_items + + item_vspace * (num_items - 1) + + 2 * boxpad + + box_top_pad + box_bottom_pad); + } + else + { + *width = 0; + *height = 0; + } + + /* Allow preferred dimensions to override the computed dimensions. */ + if (self->preferred_width >= 0) + *width = self->preferred_width; + if (self->preferred_height >= 0) + *height = self->preferred_height; +} + +static grub_err_t +list_set_property (void *vself, const char *name, const char *value) +{ + list_impl_t self = vself; + if (grub_strcmp (name, "item_font") == 0) + { + self->item_font = grub_font_get (value); + } + else if (grub_strcmp (name, "selected_item_font") == 0) + { + if (! value || grub_strcmp (value, "inherit") == 0) + self->selected_item_font = 0; + else + self->selected_item_font = grub_font_get (value); + } + else if (grub_strcmp (name, "item_color") == 0) + { + grub_gui_parse_color (value, &self->item_color); + } + else if (grub_strcmp (name, "selected_item_color") == 0) + { + if (! value || grub_strcmp (value, "inherit") == 0) + { + self->selected_item_color_set = 0; + } + else + { + if (grub_gui_parse_color (value, &self->selected_item_color) + == GRUB_ERR_NONE) + self->selected_item_color_set = 1; + } + } + else if (grub_strcmp (name, "icon_width") == 0) + { + self->icon_width = grub_strtol (value, 0, 10); + grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager, + self->icon_width, + self->icon_height); + } + else if (grub_strcmp (name, "icon_height") == 0) + { + self->icon_height = grub_strtol (value, 0, 10); + grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager, + self->icon_width, + self->icon_height); + } + else if (grub_strcmp (name, "item_height") == 0) + { + self->item_height = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "item_padding") == 0) + { + self->item_padding = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "item_icon_space") == 0) + { + self->item_icon_space = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "item_spacing") == 0) + { + self->item_spacing = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "visible") == 0) + { + self->visible = grub_strcmp (value, "false") != 0; + } + else if (grub_strcmp (name, "menu_pixmap_style") == 0) + { + self->need_to_recreate_boxes = 1; + grub_free (self->menu_box_pattern); + self->menu_box_pattern = value ? grub_strdup (value) : 0; + } + else if (grub_strcmp (name, "selected_item_pixmap_style") == 0) + { + self->need_to_recreate_boxes = 1; + grub_free (self->selected_item_box_pattern); + self->selected_item_box_pattern = value ? grub_strdup (value) : 0; + } + else if (grub_strcmp (name, "scrollbar_frame") == 0) + { + self->need_to_recreate_scrollbar = 1; + grub_free (self->scrollbar_frame_pattern); + self->scrollbar_frame_pattern = value ? grub_strdup (value) : 0; + } + else if (grub_strcmp (name, "scrollbar_thumb") == 0) + { + self->need_to_recreate_scrollbar = 1; + grub_free (self->scrollbar_thumb_pattern); + self->scrollbar_thumb_pattern = value ? grub_strdup (value) : 0; + } + else if (grub_strcmp (name, "scrollbar_width") == 0) + { + self->scrollbar_width = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "scrollbar") == 0) + { + self->draw_scrollbar = grub_strcmp (value, "false") != 0; + } + else if (grub_strcmp (name, "min_items_shown") == 0) + { + self->min_items_shown = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "max_items_shown") == 0) + { + self->max_items_shown = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "theme_dir") == 0) + { + self->need_to_recreate_boxes = 1; + grub_free (self->theme_dir); + self->theme_dir = value ? grub_strdup (value) : 0; + } + else if (grub_strcmp (name, "preferred_size") == 0) + { + int w; + int h; + if (grub_gui_parse_2_tuple (value, &w, &h) != GRUB_ERR_NONE) + return grub_errno; + self->preferred_width = w; + self->preferred_height = h; + } + else if (grub_strcmp (name, "id") == 0) + { + grub_free (self->id); + if (value) + self->id = grub_strdup (value); + else + self->id = 0; + } + return grub_errno; +} + +/* Set necessary information that the gfxmenu view provides. */ +static void +list_set_view_info (void *vself, + const char *theme_path, + grub_gfxmenu_model_t menu) +{ + list_impl_t self = vself; + grub_gfxmenu_icon_manager_set_theme_path (self->icon_manager, theme_path); + self->menu = menu; +} + +static struct grub_gui_list_ops list_ops = +{ + .component_ops = + { + .destroy = list_destroy, + .get_id = list_get_id, + .is_instance = list_is_instance, + .paint = list_paint, + .set_parent = list_set_parent, + .get_parent = list_get_parent, + .set_bounds = list_set_bounds, + .get_bounds = list_get_bounds, + .get_preferred_size = list_get_preferred_size, + .set_property = list_set_property + }, + .set_view_info = list_set_view_info +}; + +grub_gui_component_t +grub_gui_list_new (void) +{ + list_impl_t self; + grub_font_t default_font; + grub_gui_color_t default_fg_color; + grub_gui_color_t default_bg_color; + + self = grub_malloc (sizeof (*self)); + if (! self) + return 0; + + self->list_ops = &list_ops; + self->parent = 0; + self->bounds.x = 0; + self->bounds.y = 0; + self->bounds.width = 0; + self->bounds.height = 0; + self->id = 0; + self->preferred_width = -1; + self->preferred_height = -1; + self->visible = 1; + + default_font = grub_font_get ("Helvetica 12"); + default_fg_color = grub_gui_color_rgb (0, 0, 0); + default_bg_color = grub_gui_color_rgb (255, 255, 255); + + self->icon_width = 32; + self->icon_height = 32; + self->item_height = 42; + self->item_padding = 14; + self->item_icon_space = 4; + self->item_spacing = 16; + self->item_font = default_font; + self->selected_item_font = 0; /* Default to using the item_font. */ + self->item_color = default_fg_color; + self->selected_item_color_set = 0; /* Default to using the item_color. */ + self->selected_item_color = default_fg_color; + + self->draw_scrollbar = 1; + self->need_to_recreate_scrollbar = 1; + self->scrollbar_frame = 0; + self->scrollbar_thumb = 0; + self->scrollbar_frame_pattern = 0; + self->scrollbar_thumb_pattern = 0; + self->scrollbar_width = 16; + + self->min_items_shown = -1; + self->max_items_shown = -1; + self->first_shown_index = 0; + + self->need_to_recreate_boxes = 0; + self->theme_dir = 0; + self->menu_box_pattern = 0; + self->selected_item_box_pattern = 0; + self->menu_box = grub_gfxmenu_create_box (0, 0); + self->selected_item_box = grub_gfxmenu_create_box (0, 0); + + self->icon_manager = grub_gfxmenu_icon_manager_new (); + if (! self->icon_manager) + { + self->list_ops->component_ops.destroy (self); + return 0; + } + grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager, + self->icon_width, + self->icon_height); + return (grub_gui_component_t) self; +} diff --git a/gfxmenu/gui_progress_bar.c b/gfxmenu/gui_progress_bar.c new file mode 100644 index 000000000..440d4b2fc --- /dev/null +++ b/gfxmenu/gui_progress_bar.c @@ -0,0 +1,378 @@ +/* gui_progress_bar.c - GUI progress bar component. */ +/* + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include + +struct grub_gui_progress_bar +{ + struct grub_gui_component_ops *progress_bar; + + grub_gui_container_t parent; + grub_video_rect_t bounds; + char *id; + int preferred_width; + int preferred_height; + int visible; + int start; + int end; + int value; + int show_text; + char *text; + grub_font_t font; + grub_gui_color_t text_color; + grub_gui_color_t border_color; + grub_gui_color_t bg_color; + grub_gui_color_t fg_color; + + char *theme_dir; + int need_to_recreate_pixmaps; + char *bar_pattern; + char *highlight_pattern; + grub_gfxmenu_box_t bar_box; + grub_gfxmenu_box_t highlight_box; +}; + +typedef struct grub_gui_progress_bar *grub_gui_progress_bar_t; + +static void +progress_bar_destroy (void *vself) +{ + grub_gui_progress_bar_t self = vself; + grub_free (self); +} + +static const char * +progress_bar_get_id (void *vself) +{ + grub_gui_progress_bar_t self = vself; + return self->id; +} + +static int +progress_bar_is_instance (void *vself __attribute__((unused)), const char *type) +{ + return grub_strcmp (type, "component") == 0; +} + +static int +check_pixmaps (grub_gui_progress_bar_t self) +{ + if (self->need_to_recreate_pixmaps) + { + grub_gui_recreate_box (&self->bar_box, + self->bar_pattern, + self->theme_dir); + + grub_gui_recreate_box (&self->highlight_box, + self->highlight_pattern, + self->theme_dir); + + self->need_to_recreate_pixmaps = 0; + } + + return (self->bar_box != 0 && self->highlight_box != 0); +} + +static void +draw_filled_rect_bar (grub_gui_progress_bar_t self) +{ + /* Set the progress bar's frame. */ + grub_video_rect_t f; + f.x = 1; + f.y = 1; + f.width = self->bounds.width - 2; + f.height = self->bounds.height - 2; + + /* Border. */ + grub_video_fill_rect (grub_gui_map_color (self->border_color), + f.x - 1, f.y - 1, + f.width + 2, f.height + 2); + + /* Bar background. */ + int barwidth = (f.width + * (self->value - self->start) + / (self->end - self->start)); + grub_video_fill_rect (grub_gui_map_color (self->bg_color), + f.x + barwidth, f.y, + f.width - barwidth, f.height); + + /* Bar foreground. */ + grub_video_fill_rect (grub_gui_map_color (self->fg_color), + f.x, f.y, + barwidth, f.height); +} + +static void +draw_pixmap_bar (grub_gui_progress_bar_t self) +{ + grub_gfxmenu_box_t bar = self->bar_box; + grub_gfxmenu_box_t hl = self->highlight_box; + int w = self->bounds.width; + int h = self->bounds.height; + int bar_l_pad = bar->get_left_pad (bar); + int bar_r_pad = bar->get_right_pad (bar); + int bar_t_pad = bar->get_top_pad (bar); + int bar_b_pad = bar->get_bottom_pad (bar); + int bar_h_pad = bar_l_pad + bar_r_pad; + int bar_v_pad = bar_t_pad + bar_b_pad; + int tracklen = w - bar_h_pad; + int trackheight = h - bar_v_pad; + bar->set_content_size (bar, tracklen, trackheight); + + int barwidth = (tracklen + * (self->value - self->start) + / (self->end - self->start)); + hl->set_content_size (hl, barwidth, h - bar_v_pad); + + bar->draw (bar, 0, 0); + hl->draw (hl, bar_l_pad, bar_t_pad); +} + +static void +draw_text (grub_gui_progress_bar_t self) +{ + const char *text = self->text; + if (text && self->show_text) + { + grub_font_t font = self->font; + grub_video_color_t text_color = grub_gui_map_color (self->text_color); + int width = self->bounds.width; + int height = self->bounds.height; + + /* Center the text. */ + int text_width = grub_font_get_string_width (font, text); + int x = (width - text_width) / 2; + int y = ((height - grub_font_get_descent (font)) / 2 + + grub_font_get_ascent (font) / 2); + grub_font_draw_string (text, font, text_color, x, y); + } +} + +static void +progress_bar_paint (void *vself) +{ + grub_gui_progress_bar_t self = vself; + if (! self->visible) + return; + + grub_video_rect_t vpsave; + grub_gui_set_viewport (&self->bounds, &vpsave); + + if (check_pixmaps (self)) + draw_pixmap_bar (self); + else + draw_filled_rect_bar (self); + + draw_text (self); + + grub_gui_restore_viewport (&vpsave); +} + +static void +progress_bar_set_parent (void *vself, grub_gui_container_t parent) +{ + grub_gui_progress_bar_t self = vself; + self->parent = parent; +} + +static grub_gui_container_t +progress_bar_get_parent (void *vself) +{ + grub_gui_progress_bar_t self = vself; + return self->parent; +} + +static void +progress_bar_set_bounds (void *vself, const grub_video_rect_t *bounds) +{ + grub_gui_progress_bar_t self = vself; + self->bounds = *bounds; +} + +static void +progress_bar_get_bounds (void *vself, grub_video_rect_t *bounds) +{ + grub_gui_progress_bar_t self = vself; + *bounds = self->bounds; +} + +static void +progress_bar_get_preferred_size (void *vself, int *width, int *height) +{ + grub_gui_progress_bar_t self = vself; + + *width = 200; + *height = 28; + + /* Allow preferred dimensions to override the progress_bar dimensions. */ + if (self->preferred_width >= 0) + *width = self->preferred_width; + if (self->preferred_height >= 0) + *height = self->preferred_height; +} + +static grub_err_t +progress_bar_set_property (void *vself, const char *name, const char *value) +{ + grub_gui_progress_bar_t self = vself; + if (grub_strcmp (name, "value") == 0) + { + self->value = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "start") == 0) + { + self->start = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "end") == 0) + { + self->end = grub_strtol (value, 0, 10); + } + else if (grub_strcmp (name, "text") == 0) + { + grub_free (self->text); + if (! value) + value = ""; + self->text = grub_strdup (value); + } + else if (grub_strcmp (name, "font") == 0) + { + self->font = grub_font_get (value); + } + else if (grub_strcmp (name, "text_color") == 0) + { + grub_gui_parse_color (value, &self->text_color); + } + else if (grub_strcmp (name, "border_color") == 0) + { + grub_gui_parse_color (value, &self->border_color); + } + else if (grub_strcmp (name, "bg_color") == 0) + { + grub_gui_parse_color (value, &self->bg_color); + } + else if (grub_strcmp (name, "fg_color") == 0) + { + grub_gui_parse_color (value, &self->fg_color); + } + else if (grub_strcmp (name, "bar_style") == 0) + { + self->need_to_recreate_pixmaps = 1; + grub_free (self->bar_pattern); + self->bar_pattern = value ? grub_strdup (value) : 0; + } + else if (grub_strcmp (name, "highlight_style") == 0) + { + self->need_to_recreate_pixmaps = 1; + grub_free (self->highlight_pattern); + self->highlight_pattern = value ? grub_strdup (value) : 0; + } + else if (grub_strcmp (name, "theme_dir") == 0) + { + self->need_to_recreate_pixmaps = 1; + grub_free (self->theme_dir); + self->theme_dir = value ? grub_strdup (value) : 0; + } + else if (grub_strcmp (name, "preferred_size") == 0) + { + int w; + int h; + if (grub_gui_parse_2_tuple (value, &w, &h) != GRUB_ERR_NONE) + return grub_errno; + self->preferred_width = w; + self->preferred_height = h; + } + else if (grub_strcmp (name, "visible") == 0) + { + self->visible = grub_strcmp (value, "false") != 0; + } + else if (grub_strcmp (name, "show_text") == 0) + { + self->show_text = grub_strcmp (value, "false") != 0; + } + else if (grub_strcmp (name, "id") == 0) + { + grub_free (self->id); + if (value) + self->id = grub_strdup (value); + else + self->id = 0; + } + return grub_errno; +} + +static struct grub_gui_component_ops progress_bar_ops = +{ + .destroy = progress_bar_destroy, + .get_id = progress_bar_get_id, + .is_instance = progress_bar_is_instance, + .paint = progress_bar_paint, + .set_parent = progress_bar_set_parent, + .get_parent = progress_bar_get_parent, + .set_bounds = progress_bar_set_bounds, + .get_bounds = progress_bar_get_bounds, + .get_preferred_size = progress_bar_get_preferred_size, + .set_property = progress_bar_set_property +}; + +grub_gui_component_t +grub_gui_progress_bar_new (void) +{ + grub_gui_progress_bar_t self; + self = grub_malloc (sizeof (*self)); + if (! self) + return 0; + self->progress_bar = &progress_bar_ops; + self->parent = 0; + self->bounds.x = 0; + self->bounds.y = 0; + self->bounds.width = 0; + self->bounds.height = 0; + self->id = 0; + self->preferred_width = -1; + self->preferred_height = -1; + self->visible = 1; + self->start = 0; + self->end = 0; + self->value = 0; + self->show_text = 1; + self->text = grub_strdup (""); + self->font = grub_font_get ("Helvetica 10"); + grub_gui_color_t black = { .red = 0, .green = 0, .blue = 0, .alpha = 255 }; + grub_gui_color_t gray = { .red = 128, .green = 128, .blue = 128, .alpha = 255 }; + grub_gui_color_t lightgray = { .red = 200, .green = 200, .blue = 200, .alpha = 255 }; + self->text_color = black; + self->border_color = black; + self->bg_color = gray; + self->fg_color = lightgray; + + self->theme_dir = 0; + self->need_to_recreate_pixmaps = 0; + self->bar_pattern = 0; + self->highlight_pattern = 0; + self->bar_box = 0; + self->highlight_box = 0; + + return (grub_gui_component_t) self; +} diff --git a/gfxmenu/gui_string_util.c b/gfxmenu/gui_string_util.c new file mode 100644 index 000000000..41170d724 --- /dev/null +++ b/gfxmenu/gui_string_util.c @@ -0,0 +1,358 @@ +/* gui_string_util.c - String utilities used by the GUI system. */ +/* + * 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 . + */ + +#include +#include +#include +#include + +/* Create a new NUL-terminated string on the heap as a substring of BUF. + The range of buf included is the half-open interval [START,END). + The index START is inclusive, END is exclusive. */ +char * +grub_new_substring (const char *buf, + grub_size_t start, grub_size_t end) +{ + if (end < start) + return 0; + grub_size_t len = end - start; + char *s = grub_malloc (len + 1); + if (! s) + return 0; + grub_memcpy (s, buf + start, len); + s[len] = '\0'; + return s; +} + +/* Eliminate "." and ".." path elements from PATH. A new heap-allocated + string is returned. */ +static char * +canonicalize_path (const char *path) +{ + int i; + const char *p; + char *newpath = 0; + + /* Count the path components in path. */ + int components = 1; + for (p = path; *p; p++) + if (*p == '/') + components++; + + char **path_array = grub_malloc (components * sizeof (*path_array)); + if (! path_array) + return 0; + + /* Initialize array elements to NULL pointers; in case once of the + allocations fails, the cleanup code can just call grub_free() for all + pointers in the array. */ + for (i = 0; i < components; i++) + path_array[i] = 0; + + /* Parse the path into path_array. */ + p = path; + for (i = 0; i < components && p; i++) + { + /* Find the end of the path element. */ + const char *end = grub_strchr (p, '/'); + if (!end) + end = p + grub_strlen (p); + + /* Copy the element. */ + path_array[i] = grub_new_substring (p, 0, end - p); + if (! path_array[i]) + goto cleanup; + + /* Advance p to point to the start of the next element, or NULL. */ + if (*end) + p = end + 1; + else + p = 0; + } + + /* Eliminate '.' and '..' elements from the path array. */ + int newpath_length = 0; + for (i = components - 1; i >= 0; --i) + { + if (! grub_strcmp (path_array[i], ".")) + { + grub_free (path_array[i]); + path_array[i] = 0; + } + else if (! grub_strcmp (path_array[i], "..") + && i > 0) + { + /* Delete the '..' and the prior path element. */ + grub_free (path_array[i]); + path_array[i] = 0; + --i; + grub_free (path_array[i]); + path_array[i] = 0; + } + else + { + newpath_length += grub_strlen (path_array[i]) + 1; + } + } + + /* Construct a new path string. */ + newpath = grub_malloc (newpath_length + 1); + if (! newpath) + goto cleanup; + + newpath[0] = '\0'; + char *newpath_end = newpath; + int first = 1; + for (i = 0; i < components; i++) + { + char *element = path_array[i]; + if (element) + { + /* For all components but the first, prefix with a slash. */ + if (! first) + newpath_end = grub_stpcpy (newpath_end, "/"); + newpath_end = grub_stpcpy (newpath_end, element); + first = 0; + } + } + +cleanup: + for (i = 0; i < components; i++) + grub_free (path_array[i]); + grub_free (path_array); + + return newpath; +} + +/* Return a new heap-allocated string representing to absolute path + to the file referred to by PATH. If PATH is an absolute path, then + the returned path is a copy of PATH. If PATH is a relative path, then + BASE is with PATH used to construct the absolute path. */ +char * +grub_resolve_relative_path (const char *base, const char *path) +{ + char *abspath; + char *canonpath; + char *p; + + /* If PATH is an absolute path, then just use it as is. */ + if (path[0] == '/' || path[0] == '(') + return canonicalize_path (path); + + abspath = grub_malloc (grub_strlen (base) + grub_strlen (path) + 1); + if (! abspath) + return 0; + + /* Concatenate BASE and PATH. + Note that BASE is expected to have a trailing slash. */ + p = grub_stpcpy (abspath, base); + grub_stpcpy (p, path); + + canonpath = canonicalize_path (abspath); + if (! canonpath) + return abspath; + + grub_free (abspath); + return canonpath; +} + +/* Get the path of the directory where the file at FILE_PATH is located. + FILE_PATH should refer to a file, not a directory. The returned path + includes a trailing slash. + This does not handle GRUB "(hd0,0)" paths properly yet since it only + looks at slashes. */ +char * +grub_get_dirname (const char *file_path) +{ + int i; + int last_slash; + + last_slash = -1; + for (i = grub_strlen (file_path) - 1; i >= 0; --i) + { + if (file_path[i] == '/') + { + last_slash = i; + break; + } + } + if (last_slash == -1) + return grub_strdup ("/"); + + return grub_new_substring (file_path, 0, last_slash + 1); +} + +static __inline int +isxdigit (char c) +{ + return ((c >= '0' && c <= '9') + || (c >= 'a' && c <= 'f') + || (c >= 'A' && c <= 'F')); +} + +static int +parse_hex_color_component (const char *s, unsigned start, unsigned end) +{ + unsigned len; + char buf[3]; + + len = end - start; + /* Check the limits so we don't overrun the buffer. */ + if (len < 1 || len > 2) + return 0; + + if (len == 1) + { + buf[0] = s[start]; /* Get the first and only hex digit. */ + buf[1] = buf[0]; /* Duplicate the hex digit. */ + } + else if (len == 2) + { + buf[0] = s[start]; + buf[1] = s[start + 1]; + } + + buf[2] = '\0'; + + return grub_strtoul (buf, 0, 16); +} + +/* Parse a color string of the form "r, g, b", "#RGB", "#RGBA", + "#RRGGBB", or "#RRGGBBAA". */ +grub_err_t +grub_gui_parse_color (const char *s, grub_gui_color_t *color) +{ + grub_gui_color_t c; + + /* Skip whitespace. */ + while (*s && grub_isspace (*s)) + s++; + + if (*s == '#') + { + /* HTML-style. Number if hex digits: + [6] #RRGGBB [3] #RGB + [8] #RRGGBBAA [4] #RGBA */ + + s++; /* Skip the '#'. */ + /* Count the hexits to determine the format. */ + int hexits = 0; + const char *end = s; + while (isxdigit (*end)) + { + end++; + hexits++; + } + + /* Parse the color components based on the format. */ + if (hexits == 3 || hexits == 4) + { + c.red = parse_hex_color_component (s, 0, 1); + c.green = parse_hex_color_component (s, 1, 2); + c.blue = parse_hex_color_component (s, 2, 3); + if (hexits == 4) + c.alpha = parse_hex_color_component (s, 3, 4); + else + c.alpha = 255; + } + else if (hexits == 6 || hexits == 8) + { + c.red = parse_hex_color_component (s, 0, 2); + c.green = parse_hex_color_component (s, 2, 4); + c.blue = parse_hex_color_component (s, 4, 6); + if (hexits == 8) + c.alpha = parse_hex_color_component (s, 6, 8); + else + c.alpha = 255; + } + else + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "invalid HTML-type color string `%s'", s); + } + else if (grub_isdigit (*s)) + { + /* Comma separated decimal values. */ + c.red = grub_strtoul (s, 0, 0); + if ((s = grub_strchr (s, ',')) == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "missing 1st comma separator in color `%s'", s); + s++; + c.green = grub_strtoul (s, 0, 0); + if ((s = grub_strchr (s, ',')) == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "missing 2nd comma separator in color `%s'", s); + s++; + c.blue = grub_strtoul (s, 0, 0); + if ((s = grub_strchr (s, ',')) == 0) + c.alpha = 255; + else + { + s++; + c.alpha = grub_strtoul (s, 0, 0); + } + } + else + { + if (! grub_gui_get_named_color (s, &c)) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "invalid named color `%s'", s); + } + + if (grub_errno == GRUB_ERR_NONE) + *color = c; + return grub_errno; +} + +/* Parse a value in the form "(x, y)", storing the first element (x) into + *PX and the second element (y) into *PY. + Returns GRUB_ERR_NONE if successfully parsed. */ +grub_err_t +grub_gui_parse_2_tuple (const char *s, int *px, int *py) +{ + int x; + int y; + + while (*s && grub_isspace (*s)) + s++; + if (*s != '(') + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "missing `(' in 2-tuple `%s'", s); + + /* Skip the opening parentheses. */ + s++; + if (*s == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "unexpected end of 2-tuple after `(' in `%s'", s); + + /* Parse the first element. */ + x = grub_strtol (s, 0, 10); + if ((s = grub_strchr (s, ',')) == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "missing comma in 2-tuple `%s'", s); + + /* Skip the element separator (the comma). */ + s++; + /* Parse the second element. */ + y = grub_strtol (s, 0, 10); + + *px = x; + *py = y; + + return grub_errno; +} diff --git a/gfxmenu/gui_util.c b/gfxmenu/gui_util.c new file mode 100644 index 000000000..eba7bb39e --- /dev/null +++ b/gfxmenu/gui_util.c @@ -0,0 +1,101 @@ +/* gui_util.c - GUI utility functions. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 + + +struct find_by_id_state +{ + const char *match_id; + grub_gui_component_callback match_callback; + void *match_userdata; +}; + +static void +find_by_id_recursively (grub_gui_component_t component, void *userdata) +{ + struct find_by_id_state *state; + const char *id; + + state = (struct find_by_id_state *) userdata; + id = component->ops->get_id (component); + if (id && grub_strcmp (id, state->match_id) == 0) + state->match_callback (component, state->match_userdata); + + if (component->ops->is_instance (component, "container")) + { + grub_gui_container_t container; + container = (grub_gui_container_t) component; + container->ops->iterate_children (container, + find_by_id_recursively, + state); + } +} + +void +grub_gui_find_by_id (grub_gui_component_t root, + const char *id, + grub_gui_component_callback cb, + void *userdata) +{ + struct find_by_id_state state; + state.match_id = id; + state.match_callback = cb; + state.match_userdata = userdata; + find_by_id_recursively (root, &state); +} + + +struct iterate_recursively_state +{ + grub_gui_component_callback callback; + void *userdata; +}; + +static +void iterate_recursively_cb (grub_gui_component_t component, void *userdata) +{ + struct iterate_recursively_state *state; + + state = (struct iterate_recursively_state *) userdata; + state->callback (component, state->userdata); + + if (component->ops->is_instance (component, "container")) + { + grub_gui_container_t container; + container = (grub_gui_container_t) component; + container->ops->iterate_children (container, + iterate_recursively_cb, + state); + } +} + +void +grub_gui_iterate_recursively (grub_gui_component_t root, + grub_gui_component_callback cb, + void *userdata) +{ + struct iterate_recursively_state state; + state.callback = cb; + state.userdata = userdata; + iterate_recursively_cb (root, &state); +} diff --git a/gfxmenu/icon_manager.c b/gfxmenu/icon_manager.c new file mode 100644 index 000000000..a362882e1 --- /dev/null +++ b/gfxmenu/icon_manager.c @@ -0,0 +1,258 @@ +/* icon_manager.c - gfxmenu icon manager. */ +/* + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Currently hard coded to '.png' extension. */ +static const char icon_extension[] = ".png"; + +typedef struct icon_entry +{ + char *class_name; + struct grub_video_bitmap *bitmap; + struct icon_entry *next; +} *icon_entry_t; + +struct grub_gfxmenu_icon_manager +{ + char *theme_path; + int icon_width; + int icon_height; + + /* Icon cache: linked list w/ dummy head node. */ + struct icon_entry cache; +}; + + +/* Create a new icon manager and return a point to it. */ +grub_gfxmenu_icon_manager_t +grub_gfxmenu_icon_manager_new (void) +{ + grub_gfxmenu_icon_manager_t mgr; + mgr = grub_malloc (sizeof (*mgr)); + if (! mgr) + return 0; + + mgr->theme_path = 0; + mgr->icon_width = 0; + mgr->icon_height = 0; + + /* Initialize the dummy head node. */ + mgr->cache.class_name = 0; + mgr->cache.bitmap = 0; + mgr->cache.next = 0; + + return mgr; +} + +/* Destroy the icon manager MGR, freeing all resources used by it. + +Note: Any bitmaps returned by grub_gfxmenu_icon_manager_get_icon() +are destroyed and must not be used by the caller after this function +is called. */ +void +grub_gfxmenu_icon_manager_destroy (grub_gfxmenu_icon_manager_t mgr) +{ + grub_gfxmenu_icon_manager_clear_cache (mgr); + grub_free (mgr->theme_path); + grub_free (mgr); +} + +/* Clear the icon cache. */ +void +grub_gfxmenu_icon_manager_clear_cache (grub_gfxmenu_icon_manager_t mgr) +{ + icon_entry_t cur; + icon_entry_t next; + for (cur = mgr->cache.next; cur; cur = next) + { + next = cur->next; + grub_free (cur->class_name); + grub_video_bitmap_destroy (cur->bitmap); + grub_free (cur); + } + mgr->cache.next = 0; +} + +/* Set the theme path. If the theme path is changed, the icon cache + is cleared. */ +void +grub_gfxmenu_icon_manager_set_theme_path (grub_gfxmenu_icon_manager_t mgr, + const char *path) +{ + /* Clear the cache if the theme path has changed. */ + if (((mgr->theme_path == 0) != (path == 0)) + || (grub_strcmp (mgr->theme_path, path) != 0)) + grub_gfxmenu_icon_manager_clear_cache (mgr); + + grub_free (mgr->theme_path); + mgr->theme_path = path ? grub_strdup (path) : 0; +} + +/* Set the icon size. When icons are requested from the icon manager, + they are scaled to this size before being returned. If the size is + changed, the icon cache is cleared. */ +void +grub_gfxmenu_icon_manager_set_icon_size (grub_gfxmenu_icon_manager_t mgr, + int width, int height) +{ + /* If the width or height is changed, we must clear the cache, since the + scaled bitmaps are stored in the cache. */ + if (width != mgr->icon_width || height != mgr->icon_height) + grub_gfxmenu_icon_manager_clear_cache (mgr); + + mgr->icon_width = width; + mgr->icon_height = height; +} + +/* Try to load an icon for the specified CLASS_NAME in the directory DIR. + Returns 0 if the icon could not be loaded, or returns a pointer to a new + bitmap if it was successful. */ +static struct grub_video_bitmap * +try_loading_icon (grub_gfxmenu_icon_manager_t mgr, + const char *dir, const char *class_name) +{ + char *path = grub_malloc (grub_strlen (dir) + + grub_strlen (class_name) + + grub_strlen (icon_extension) + + 1); + if (! path) + return 0; + + grub_strcpy (path, dir); + grub_strcat (path, class_name); + grub_strcat (path, icon_extension); + + struct grub_video_bitmap *raw_bitmap; + grub_video_bitmap_load (&raw_bitmap, path); + grub_free (path); + grub_errno = GRUB_ERR_NONE; /* Critical to clear the error!! */ + if (! raw_bitmap) + return 0; + + struct grub_video_bitmap *scaled_bitmap; + grub_video_bitmap_create_scaled (&scaled_bitmap, + mgr->icon_width, mgr->icon_height, + raw_bitmap, + GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST); + grub_video_bitmap_destroy (raw_bitmap); + if (! scaled_bitmap) + { + grub_error_push (); + grub_error (grub_errno, "failed to scale icon"); + return 0; + } + + return scaled_bitmap; +} + +/* Get the icon for the specified class CLASS_NAME. If an icon for + CLASS_NAME already exists in the cache, then a reference to the cached + bitmap is returned. If it is not cached, then it is loaded and cached. + If no icon could be could for CLASS_NAME, then 0 is returned. */ +static struct grub_video_bitmap * +get_icon_by_class (grub_gfxmenu_icon_manager_t mgr, const char *class_name) +{ + /* First check the icon cache. */ + icon_entry_t entry; + for (entry = mgr->cache.next; entry; entry = entry->next) + { + if (grub_strcmp (entry->class_name, class_name) == 0) + return entry->bitmap; + } + + if (! mgr->theme_path) + return 0; + + /* Otherwise, we search for an icon to load. */ + char *theme_dir = grub_get_dirname (mgr->theme_path); + char *icons_dir; + struct grub_video_bitmap *icon; + icon = 0; + /* First try the theme's own icons, from "grub/themes/NAME/icons/" */ + icons_dir = grub_resolve_relative_path (theme_dir, "icons/"); + if (icons_dir) + { + icon = try_loading_icon (mgr, icons_dir, class_name); + grub_free (icons_dir); + } + if (! icon) + { + /* If the theme doesn't have an appropriate icon, check in + "grub/themes/icons". */ + /* TODO use GRUB prefix "/icons" */ + icons_dir = grub_resolve_relative_path (theme_dir, "../icons/"); + if (icons_dir) + { + icon = try_loading_icon (mgr, icons_dir, class_name); + grub_free (icons_dir); + } + } + grub_free (theme_dir); + + /* No icon was found. */ + /* This should probably be noted in the cache, so that a search is not + performed each time an icon for CLASS_NAME is requested. */ + if (! icon) + return 0; + + /* Insert a new cache entry for this icon. */ + entry = grub_malloc (sizeof (*entry)); + if (! entry) + { + grub_video_bitmap_destroy (icon); + return 0; + } + entry->class_name = grub_strdup (class_name); + entry->bitmap = icon; + entry->next = mgr->cache.next; + mgr->cache.next = entry; /* Link it into the cache. */ + return entry->bitmap; +} + +/* Get the best available icon for ENTRY. Beginning with the first class + listed in the menu entry and proceeding forward, an icon for each class + is searched for. The first icon found is returned. The returned icon + is scaled to the size specified by + grub_gfxmenu_icon_manager_set_icon_size(). + + Note: Bitmaps returned by this function are destroyed when the + icon manager is destroyed. + */ +struct grub_video_bitmap * +grub_gfxmenu_icon_manager_get_icon (grub_gfxmenu_icon_manager_t mgr, + grub_menu_entry_t entry) +{ + struct grub_menu_entry_class *c; + struct grub_video_bitmap *icon; + + /* Try each class in succession. */ + icon = 0; + for (c = entry->classes->next; c && ! icon; c = c->next) + icon = get_icon_by_class (mgr, c->name); + return icon; +} diff --git a/gfxmenu/model.c b/gfxmenu/model.c new file mode 100644 index 000000000..26490ea1f --- /dev/null +++ b/gfxmenu/model.c @@ -0,0 +1,191 @@ +/* model.c - Graphical menu interface MVC model. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 + +/* Model type definition. */ +struct grub_gfxmenu_model +{ + grub_menu_t menu; + int num_entries; + grub_menu_entry_t *entries; + int selected_entry_index; + int timeout_set; + grub_uint64_t timeout_start; + grub_uint64_t timeout_at; +}; + + +grub_gfxmenu_model_t +grub_gfxmenu_model_new (grub_menu_t menu) +{ + grub_gfxmenu_model_t model; + + model = grub_malloc (sizeof (*model)); + if (! model) + return 0; + + model->menu = menu; + model->num_entries = menu->size; + model->entries = 0; + model->selected_entry_index = 0; + model->timeout_set = 0; + model->timeout_at = 0; + if (model->num_entries > 0) + { + model->entries = grub_malloc (model->num_entries + * sizeof (*model->entries)); + if (! model->entries) + goto fail_and_free; + + int i; + grub_menu_entry_t cur; + for (i = 0, cur = menu->entry_list; + i < model->num_entries; + i++, cur = cur->next) + { + model->entries[i] = cur; + } + } + + return model; + +fail_and_free: + grub_free (model->entries); + grub_free (model); + return 0; +} + +void +grub_gfxmenu_model_destroy (grub_gfxmenu_model_t model) +{ + if (! model) + return; + + grub_free (model->entries); + model->entries = 0; + + grub_free (model); +} + +grub_menu_t +grub_gfxmenu_model_get_menu (grub_gfxmenu_model_t model) +{ + return model->menu; +} + +void +grub_gfxmenu_model_set_timeout (grub_gfxmenu_model_t model) +{ + int timeout_sec = grub_menu_get_timeout (); + if (timeout_sec >= 0) + { + model->timeout_start = grub_get_time_ms (); + model->timeout_at = model->timeout_start + timeout_sec * 1000; + model->timeout_set = 1; + } + else + { + model->timeout_set = 0; + } +} + +void +grub_gfxmenu_model_clear_timeout (grub_gfxmenu_model_t model) +{ + model->timeout_set = 0; + grub_menu_set_timeout (-1); +} + +int +grub_gfxmenu_model_get_timeout_ms (grub_gfxmenu_model_t model) +{ + if (!model->timeout_set) + return -1; + + return model->timeout_at - model->timeout_start; +} + +int +grub_gfxmenu_model_get_timeout_remaining_ms (grub_gfxmenu_model_t model) +{ + if (!model->timeout_set) + return -1; + + return model->timeout_at - grub_get_time_ms (); +} + +int +grub_gfxmenu_model_timeout_expired (grub_gfxmenu_model_t model) +{ + if (model->timeout_set + && grub_get_time_ms () >= model->timeout_at) + return 1; + + return 0; +} + +int +grub_gfxmenu_model_get_num_entries (grub_gfxmenu_model_t model) +{ + return model->num_entries; +} + +int +grub_gfxmenu_model_get_selected_index (grub_gfxmenu_model_t model) +{ + return model->selected_entry_index; +} + +void +grub_gfxmenu_model_set_selected_index (grub_gfxmenu_model_t model, int index) +{ + model->selected_entry_index = index; +} + +const char * +grub_gfxmenu_model_get_entry_title (grub_gfxmenu_model_t model, int index) +{ + if (index < 0 || index >= model->num_entries) + { + grub_error (GRUB_ERR_OUT_OF_RANGE, "invalid menu index"); + return 0; + } + + return model->entries[index]->title; +} + +grub_menu_entry_t +grub_gfxmenu_model_get_entry (grub_gfxmenu_model_t model, int index) +{ + if (index < 0 || index >= model->num_entries) + { + grub_error (GRUB_ERR_OUT_OF_RANGE, "invalid menu index"); + return 0; + } + + return model->entries[index]; +} diff --git a/gfxmenu/named_colors.c b/gfxmenu/named_colors.c new file mode 100644 index 000000000..eedbc47fb --- /dev/null +++ b/gfxmenu/named_colors.c @@ -0,0 +1,209 @@ +/* named_colors.c - Named color values. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 + +struct named_color +{ + const char *name; + grub_gui_color_t color; +}; + +/* + Named color list generated from the list of SVG color keywords from + , + processed through the following Perl command: + perl -ne 'chomp;split;print "{ \"$_[0]\", RGB_COLOR($_[2]) },\n"' + */ + +#define RGB_COLOR(r,g,b) {.red = r, .green = g, .blue = b, .alpha = 255} + +static struct named_color named_colors[] = +{ + { "aliceblue", RGB_COLOR(240,248,255) }, + { "antiquewhite", RGB_COLOR(250,235,215) }, + { "aqua", RGB_COLOR(0,255,255) }, + { "aquamarine", RGB_COLOR(127,255,212) }, + { "azure", RGB_COLOR(240,255,255) }, + { "beige", RGB_COLOR(245,245,220) }, + { "bisque", RGB_COLOR(255,228,196) }, + { "black", RGB_COLOR(0,0,0) }, + { "blanchedalmond", RGB_COLOR(255,235,205) }, + { "blue", RGB_COLOR(0,0,255) }, + { "blueviolet", RGB_COLOR(138,43,226) }, + { "brown", RGB_COLOR(165,42,42) }, + { "burlywood", RGB_COLOR(222,184,135) }, + { "cadetblue", RGB_COLOR(95,158,160) }, + { "chartreuse", RGB_COLOR(127,255,0) }, + { "chocolate", RGB_COLOR(210,105,30) }, + { "coral", RGB_COLOR(255,127,80) }, + { "cornflowerblue", RGB_COLOR(100,149,237) }, + { "cornsilk", RGB_COLOR(255,248,220) }, + { "crimson", RGB_COLOR(220,20,60) }, + { "cyan", RGB_COLOR(0,255,255) }, + { "darkblue", RGB_COLOR(0,0,139) }, + { "darkcyan", RGB_COLOR(0,139,139) }, + { "darkgoldenrod", RGB_COLOR(184,134,11) }, + { "darkgray", RGB_COLOR(169,169,169) }, + { "darkgreen", RGB_COLOR(0,100,0) }, + { "darkgrey", RGB_COLOR(169,169,169) }, + { "darkkhaki", RGB_COLOR(189,183,107) }, + { "darkmagenta", RGB_COLOR(139,0,139) }, + { "darkolivegreen", RGB_COLOR(85,107,47) }, + { "darkorange", RGB_COLOR(255,140,0) }, + { "darkorchid", RGB_COLOR(153,50,204) }, + { "darkred", RGB_COLOR(139,0,0) }, + { "darksalmon", RGB_COLOR(233,150,122) }, + { "darkseagreen", RGB_COLOR(143,188,143) }, + { "darkslateblue", RGB_COLOR(72,61,139) }, + { "darkslategray", RGB_COLOR(47,79,79) }, + { "darkslategrey", RGB_COLOR(47,79,79) }, + { "darkturquoise", RGB_COLOR(0,206,209) }, + { "darkviolet", RGB_COLOR(148,0,211) }, + { "deeppink", RGB_COLOR(255,20,147) }, + { "deepskyblue", RGB_COLOR(0,191,255) }, + { "dimgray", RGB_COLOR(105,105,105) }, + { "dimgrey", RGB_COLOR(105,105,105) }, + { "dodgerblue", RGB_COLOR(30,144,255) }, + { "firebrick", RGB_COLOR(178,34,34) }, + { "floralwhite", RGB_COLOR(255,250,240) }, + { "forestgreen", RGB_COLOR(34,139,34) }, + { "fuchsia", RGB_COLOR(255,0,255) }, + { "gainsboro", RGB_COLOR(220,220,220) }, + { "ghostwhite", RGB_COLOR(248,248,255) }, + { "gold", RGB_COLOR(255,215,0) }, + { "goldenrod", RGB_COLOR(218,165,32) }, + { "gray", RGB_COLOR(128,128,128) }, + { "green", RGB_COLOR(0,128,0) }, + { "greenyellow", RGB_COLOR(173,255,47) }, + { "grey", RGB_COLOR(128,128,128) }, + { "honeydew", RGB_COLOR(240,255,240) }, + { "hotpink", RGB_COLOR(255,105,180) }, + { "indianred", RGB_COLOR(205,92,92) }, + { "indigo", RGB_COLOR(75,0,130) }, + { "ivory", RGB_COLOR(255,255,240) }, + { "khaki", RGB_COLOR(240,230,140) }, + { "lavender", RGB_COLOR(230,230,250) }, + { "lavenderblush", RGB_COLOR(255,240,245) }, + { "lawngreen", RGB_COLOR(124,252,0) }, + { "lemonchiffon", RGB_COLOR(255,250,205) }, + { "lightblue", RGB_COLOR(173,216,230) }, + { "lightcoral", RGB_COLOR(240,128,128) }, + { "lightcyan", RGB_COLOR(224,255,255) }, + { "lightgoldenrodyellow", RGB_COLOR(250,250,210) }, + { "lightgray", RGB_COLOR(211,211,211) }, + { "lightgreen", RGB_COLOR(144,238,144) }, + { "lightgrey", RGB_COLOR(211,211,211) }, + { "lightpink", RGB_COLOR(255,182,193) }, + { "lightsalmon", RGB_COLOR(255,160,122) }, + { "lightseagreen", RGB_COLOR(32,178,170) }, + { "lightskyblue", RGB_COLOR(135,206,250) }, + { "lightslategray", RGB_COLOR(119,136,153) }, + { "lightslategrey", RGB_COLOR(119,136,153) }, + { "lightsteelblue", RGB_COLOR(176,196,222) }, + { "lightyellow", RGB_COLOR(255,255,224) }, + { "lime", RGB_COLOR(0,255,0) }, + { "limegreen", RGB_COLOR(50,205,50) }, + { "linen", RGB_COLOR(250,240,230) }, + { "magenta", RGB_COLOR(255,0,255) }, + { "maroon", RGB_COLOR(128,0,0) }, + { "mediumaquamarine", RGB_COLOR(102,205,170) }, + { "mediumblue", RGB_COLOR(0,0,205) }, + { "mediumorchid", RGB_COLOR(186,85,211) }, + { "mediumpurple", RGB_COLOR(147,112,219) }, + { "mediumseagreen", RGB_COLOR(60,179,113) }, + { "mediumslateblue", RGB_COLOR(123,104,238) }, + { "mediumspringgreen", RGB_COLOR(0,250,154) }, + { "mediumturquoise", RGB_COLOR(72,209,204) }, + { "mediumvioletred", RGB_COLOR(199,21,133) }, + { "midnightblue", RGB_COLOR(25,25,112) }, + { "mintcream", RGB_COLOR(245,255,250) }, + { "mistyrose", RGB_COLOR(255,228,225) }, + { "moccasin", RGB_COLOR(255,228,181) }, + { "navajowhite", RGB_COLOR(255,222,173) }, + { "navy", RGB_COLOR(0,0,128) }, + { "oldlace", RGB_COLOR(253,245,230) }, + { "olive", RGB_COLOR(128,128,0) }, + { "olivedrab", RGB_COLOR(107,142,35) }, + { "orange", RGB_COLOR(255,165,0) }, + { "orangered", RGB_COLOR(255,69,0) }, + { "orchid", RGB_COLOR(218,112,214) }, + { "palegoldenrod", RGB_COLOR(238,232,170) }, + { "palegreen", RGB_COLOR(152,251,152) }, + { "paleturquoise", RGB_COLOR(175,238,238) }, + { "palevioletred", RGB_COLOR(219,112,147) }, + { "papayawhip", RGB_COLOR(255,239,213) }, + { "peachpuff", RGB_COLOR(255,218,185) }, + { "peru", RGB_COLOR(205,133,63) }, + { "pink", RGB_COLOR(255,192,203) }, + { "plum", RGB_COLOR(221,160,221) }, + { "powderblue", RGB_COLOR(176,224,230) }, + { "purple", RGB_COLOR(128,0,128) }, + { "red", RGB_COLOR(255,0,0) }, + { "rosybrown", RGB_COLOR(188,143,143) }, + { "royalblue", RGB_COLOR(65,105,225) }, + { "saddlebrown", RGB_COLOR(139,69,19) }, + { "salmon", RGB_COLOR(250,128,114) }, + { "sandybrown", RGB_COLOR(244,164,96) }, + { "seagreen", RGB_COLOR(46,139,87) }, + { "seashell", RGB_COLOR(255,245,238) }, + { "sienna", RGB_COLOR(160,82,45) }, + { "silver", RGB_COLOR(192,192,192) }, + { "skyblue", RGB_COLOR(135,206,235) }, + { "slateblue", RGB_COLOR(106,90,205) }, + { "slategray", RGB_COLOR(112,128,144) }, + { "slategrey", RGB_COLOR(112,128,144) }, + { "snow", RGB_COLOR(255,250,250) }, + { "springgreen", RGB_COLOR(0,255,127) }, + { "steelblue", RGB_COLOR(70,130,180) }, + { "tan", RGB_COLOR(210,180,140) }, + { "teal", RGB_COLOR(0,128,128) }, + { "thistle", RGB_COLOR(216,191,216) }, + { "tomato", RGB_COLOR(255,99,71) }, + { "turquoise", RGB_COLOR(64,224,208) }, + { "violet", RGB_COLOR(238,130,238) }, + { "wheat", RGB_COLOR(245,222,179) }, + { "white", RGB_COLOR(255,255,255) }, + { "whitesmoke", RGB_COLOR(245,245,245) }, + { "yellow", RGB_COLOR(255,255,0) }, + { "yellowgreen", RGB_COLOR(154,205,50) }, + { 0, { 0, 0, 0, 0 } } /* Terminator. */ +}; + +/* Get the color named NAME. If the color was found, returns 1 and + stores the color into *COLOR. If the color was not found, returns 0 and + does not modify *COLOR. */ +int +grub_gui_get_named_color (const char *name, + grub_gui_color_t *color) +{ + int i; + for (i = 0; named_colors[i].name; i++) + { + if (grub_strcmp (named_colors[i].name, name) == 0) + { + *color = named_colors[i].color; + return 1; + } + } + return 0; +} diff --git a/gfxmenu/theme_loader.c b/gfxmenu/theme_loader.c new file mode 100644 index 000000000..3512c7bf1 --- /dev/null +++ b/gfxmenu/theme_loader.c @@ -0,0 +1,720 @@ +/* theme_loader.c - Theme file loader for gfxmenu. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 +#include +#include +#include +#include +#include + +/* Construct a new box widget using ABSPATTERN to find the pixmap files for + it, storing the new box instance at *BOXPTR. + PATTERN should be of the form: "(hd0,0)/somewhere/style*.png". + The '*' then gets substituted with the various pixmap names that the + box uses. */ +static grub_err_t +recreate_box_absolute (grub_gfxmenu_box_t *boxptr, const char *abspattern) +{ + char *prefix; + char *suffix; + char *star; + grub_gfxmenu_box_t box; + + star = grub_strchr (abspattern, '*'); + if (! star) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "missing `*' in box pixmap pattern `%s'", abspattern); + + /* Prefix: Get the part before the '*'. */ + prefix = grub_malloc (star - abspattern + 1); + if (! prefix) + return grub_errno; + + grub_memcpy (prefix, abspattern, star - abspattern); + prefix[star - abspattern] = '\0'; + + /* Suffix: Everything after the '*' is the suffix. */ + suffix = star + 1; + + box = grub_gfxmenu_create_box (prefix, suffix); + grub_free (prefix); + if (! box) + return grub_errno; + + if (*boxptr) + (*boxptr)->destroy (*boxptr); + *boxptr = box; + return grub_errno; +} + + +/* Construct a new box widget using PATTERN to find the pixmap files for it, + storing the new widget at *BOXPTR. PATTERN should be of the form: + "somewhere/style*.png". The '*' then gets substituted with the various + pixmap names that the widget uses. + + Important! The value of *BOXPTR must be initialized! It must either + (1) Be 0 (a NULL pointer), or + (2) Be a pointer to a valid 'grub_gfxmenu_box_t' instance. + In this case, the previous instance is destroyed. */ +grub_err_t +grub_gui_recreate_box (grub_gfxmenu_box_t *boxptr, + const char *pattern, const char *theme_dir) +{ + char *abspattern; + + /* Check arguments. */ + if (! pattern) + { + /* If no pixmap pattern is given, then just create an empty box. */ + if (*boxptr) + (*boxptr)->destroy (*boxptr); + *boxptr = grub_gfxmenu_create_box (0, 0); + return grub_errno; + } + + if (! theme_dir) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "styled box missing theme directory"); + + /* Resolve to an absolute path. */ + abspattern = grub_resolve_relative_path (theme_dir, pattern); + if (! abspattern) + return grub_errno; + + /* Create the box. */ + recreate_box_absolute (boxptr, abspattern); + grub_free (abspattern); + return grub_errno; +} + +/* Set the specified property NAME on the view to the given string VALUE. + The caller is responsible for the lifetimes of NAME and VALUE. */ +static grub_err_t +theme_set_string (grub_gfxmenu_view_t view, + const char *name, + const char *value, + const char *theme_dir, + const char *filename, + int line_num, + int col_num) +{ + if (! grub_strcmp ("title-font", name)) + view->title_font = grub_font_get (value); + else if (! grub_strcmp ("message-font", name)) + view->message_font = grub_font_get (value); + else if (! grub_strcmp ("terminal-font", name)) + { + grub_free (view->terminal_font_name); + view->terminal_font_name = grub_strdup (value); + if (! view->terminal_font_name) + return grub_errno; + } + else if (! grub_strcmp ("title-color", name)) + grub_gui_parse_color (value, &view->title_color); + else if (! grub_strcmp ("message-color", name)) + grub_gui_parse_color (value, &view->message_color); + else if (! grub_strcmp ("message-bg-color", name)) + grub_gui_parse_color (value, &view->message_bg_color); + else if (! grub_strcmp ("desktop-image", name)) + { + struct grub_video_bitmap *raw_bitmap; + struct grub_video_bitmap *scaled_bitmap; + char *path; + path = grub_resolve_relative_path (theme_dir, value); + if (! path) + return grub_errno; + if (grub_video_bitmap_load (&raw_bitmap, path) != GRUB_ERR_NONE) + { + grub_free (path); + return grub_errno; + } + grub_free(path); + grub_video_bitmap_create_scaled (&scaled_bitmap, + view->screen.width, + view->screen.height, + raw_bitmap, + GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST); + grub_video_bitmap_destroy (raw_bitmap); + if (! scaled_bitmap) + { + grub_error_push (); + return grub_error (grub_errno, "error scaling desktop image"); + } + + grub_video_bitmap_destroy (view->desktop_image); + view->desktop_image = scaled_bitmap; + } + else if (! grub_strcmp ("desktop-color", name)) + grub_gui_parse_color (value, &view->desktop_color); + else if (! grub_strcmp ("terminal-box", name)) + { + grub_err_t err; + err = grub_gui_recreate_box (&view->terminal_box, value, theme_dir); + if (err != GRUB_ERR_NONE) + return err; + } + else if (! grub_strcmp ("title-text", name)) + { + grub_free (view->title_text); + view->title_text = grub_strdup (value); + if (! view->title_text) + return grub_errno; + } + else + { + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "%s:%d:%d unknown property `%s'", + filename, line_num, col_num, name); + } + return grub_errno; +} + +struct parsebuf +{ + char *buf; + int pos; + int len; + int line_num; + int col_num; + const char *filename; + char *theme_dir; + grub_gfxmenu_view_t view; +}; + +static int +has_more (struct parsebuf *p) +{ + return p->pos < p->len; +} + +static int +read_char (struct parsebuf *p) +{ + if (has_more (p)) + { + char c; + c = p->buf[p->pos++]; + if (c == '\n') + { + p->line_num++; + p->col_num = 1; + } + else + { + p->col_num++; + } + return c; + } + else + return -1; +} + +static int +peek_char (struct parsebuf *p) +{ + if (has_more (p)) + return p->buf[p->pos]; + else + return -1; +} + +static int +is_whitespace (char c) +{ + return (c == ' ' + || c == '\t' + || c == '\r' + || c == '\n' + || c == '\f'); +} + +static void +skip_whitespace (struct parsebuf *p) +{ + while (has_more (p) && is_whitespace(peek_char (p))) + read_char (p); +} + +static void +advance_to_next_line (struct parsebuf *p) +{ + int c; + + /* Eat characters up to the newline. */ + do + { + c = read_char (p); + } + while (c != -1 && c != '\n'); +} + +static int +is_identifier_char (int c) +{ + return (c != -1 + && (grub_isalpha(c) + || grub_isdigit(c) + || c == '_' + || c == '-')); +} + +static char * +read_identifier (struct parsebuf *p) +{ + /* Index of the first character of the identifier in p->buf. */ + int start; + /* Next index after the last character of the identifer in p->buf. */ + int end; + + skip_whitespace (p); + + /* Capture the start of the identifier. */ + start = p->pos; + + /* Scan for the end. */ + while (is_identifier_char (peek_char (p))) + read_char (p); + end = p->pos; + + if (end - start < 1) + return 0; + + return grub_new_substring (p->buf, start, end); +} + +static char * +read_expression (struct parsebuf *p) +{ + int start; + int end; + + skip_whitespace (p); + if (peek_char (p) == '"') + { + /* Read as a quoted string. + The quotation marks are not included in the expression value. */ + /* Skip opening quotation mark. */ + read_char (p); + start = p->pos; + while (has_more (p) && peek_char (p) != '"') + read_char (p); + end = p->pos; + /* Skip the terminating quotation mark. */ + read_char (p); + } + else if (peek_char (p) == '(') + { + /* Read as a parenthesized string -- for tuples/coordinates. */ + /* The parentheses are included in the expression value. */ + int c; + + start = p->pos; + do + { + c = read_char (p); + } + while (c != -1 && c != ')'); + end = p->pos; + } + else if (has_more (p)) + { + /* Read as a single word -- for numeric values or words without + whitespace. */ + start = p->pos; + while (has_more (p) && ! is_whitespace (peek_char (p))) + read_char (p); + end = p->pos; + } + else + { + /* The end of the theme file has been reached. */ + grub_error (GRUB_ERR_IO, "%s:%d:%d expression expected in theme file", + p->filename, p->line_num, p->col_num); + return 0; + } + + return grub_new_substring (p->buf, start, end); +} + +/* Read a GUI object specification from the theme file. + Any components created will be added to the GUI container PARENT. */ +static grub_err_t +read_object (struct parsebuf *p, grub_gui_container_t parent) +{ + grub_video_rect_t bounds; + + char *name; + name = read_identifier (p); + if (! name) + goto cleanup; + + grub_gui_component_t component = 0; + if (grub_strcmp (name, "label") == 0) + { + component = grub_gui_label_new (); + } + else if (grub_strcmp (name, "image") == 0) + { + component = grub_gui_image_new (); + } + else if (grub_strcmp (name, "vbox") == 0) + { + component = (grub_gui_component_t) grub_gui_vbox_new (); + } + else if (grub_strcmp (name, "hbox") == 0) + { + component = (grub_gui_component_t) grub_gui_hbox_new (); + } + else if (grub_strcmp (name, "canvas") == 0) + { + component = (grub_gui_component_t) grub_gui_canvas_new (); + } + else if (grub_strcmp (name, "progress_bar") == 0) + { + component = grub_gui_progress_bar_new (); + } + else if (grub_strcmp (name, "circular_progress") == 0) + { + component = grub_gui_circular_progress_new (); + } + else if (grub_strcmp (name, "boot_menu") == 0) + { + component = grub_gui_list_new (); + } + else + { + /* Unknown type. */ + grub_error (GRUB_ERR_IO, "%s:%d:%d unknown object type `%s'", + p->filename, p->line_num, p->col_num, name); + goto cleanup; + } + + if (! component) + goto cleanup; + + /* Inform the component about the theme so it can find its resources. */ + component->ops->set_property (component, "theme_dir", p->theme_dir); + component->ops->set_property (component, "theme_path", p->filename); + + /* Add the component as a child of PARENT. */ + bounds.x = 0; + bounds.y = 0; + bounds.width = -1; + bounds.height = -1; + component->ops->set_bounds (component, &bounds); + parent->ops->add (parent, component); + + skip_whitespace (p); + if (read_char (p) != '{') + { + grub_error (GRUB_ERR_IO, + "%s:%d:%d expected `{' after object type name `%s'", + p->filename, p->line_num, p->col_num, name); + goto cleanup; + } + + while (has_more (p)) + { + skip_whitespace (p); + + /* Check whether the end has been encountered. */ + if (peek_char (p) == '}') + { + /* Skip the closing brace. */ + read_char (p); + break; + } + + if (peek_char (p) == '#') + { + /* Skip comments. */ + advance_to_next_line (p); + continue; + } + + if (peek_char (p) == '+') + { + /* Skip the '+'. */ + read_char (p); + + /* Check whether this component is a container. */ + if (component->ops->is_instance (component, "container")) + { + /* Read the sub-object recursively and add it as a child. */ + if (read_object (p, (grub_gui_container_t) component) != 0) + goto cleanup; + /* After reading the sub-object, resume parsing, expecting + another property assignment or sub-object definition. */ + continue; + } + else + { + grub_error (GRUB_ERR_IO, + "%s:%d:%d attempted to add object to non-container", + p->filename, p->line_num, p->col_num); + goto cleanup; + } + } + + char *property; + property = read_identifier (p); + if (! property) + { + grub_error (GRUB_ERR_IO, "%s:%d:%d identifier expected in theme file", + p->filename, p->line_num, p->col_num); + goto cleanup; + } + + skip_whitespace (p); + if (read_char (p) != '=') + { + grub_error (GRUB_ERR_IO, + "%s:%d:%d expected `=' after property name `%s'", + p->filename, p->line_num, p->col_num, property); + grub_free (property); + goto cleanup; + } + skip_whitespace (p); + + char *value; + value = read_expression (p); + if (! value) + { + grub_free (property); + goto cleanup; + } + + /* Handle the property value. */ + if (grub_strcmp (property, "position") == 0) + { + /* Special case for position value. */ + int x; + int y; + + if (grub_gui_parse_2_tuple (value, &x, &y) == GRUB_ERR_NONE) + { + grub_video_rect_t r; + component->ops->get_bounds (component, &r); + r.x = x; + r.y = y; + component->ops->set_bounds (component, &r); + } + } + else if (grub_strcmp (property, "size") == 0) + { + /* Special case for size value. */ + int w; + int h; + + if (grub_gui_parse_2_tuple (value, &w, &h) == GRUB_ERR_NONE) + { + grub_video_rect_t r; + component->ops->get_bounds (component, &r); + r.width = w; + r.height = h; + component->ops->set_bounds (component, &r); + } + } + else + { + /* General property handling. */ + component->ops->set_property (component, property, value); + } + + grub_free (value); + grub_free (property); + if (grub_errno != GRUB_ERR_NONE) + goto cleanup; + } + + /* Set the object's size to its preferred size unless the user has + explicitly specified the size. */ + component->ops->get_bounds (component, &bounds); + if (bounds.width == -1 || bounds.height == -1) + { + component->ops->get_preferred_size (component, + &bounds.width, &bounds.height); + component->ops->set_bounds (component, &bounds); + } + +cleanup: + grub_free (name); + return grub_errno; +} + +static grub_err_t +read_property (struct parsebuf *p) +{ + char *name; + + /* Read the property name. */ + name = read_identifier (p); + if (! name) + { + advance_to_next_line (p); + return grub_errno; + } + + /* Skip whitespace before separator. */ + skip_whitespace (p); + + /* Read separator. */ + if (read_char (p) != ':') + { + grub_error (GRUB_ERR_IO, + "%s:%d:%d missing separator after property name `%s'", + p->filename, p->line_num, p->col_num, name); + goto done; + } + + /* Skip whitespace after separator. */ + skip_whitespace (p); + + /* Get the value based on its type. */ + if (peek_char (p) == '"') + { + /* String value (e.g., '"My string"'). */ + char *value = read_expression (p); + if (! value) + { + grub_error (GRUB_ERR_IO, "%s:%d:%d missing property value", + p->filename, p->line_num, p->col_num); + goto done; + } + /* If theme_set_string results in an error, grub_errno will be returned + below. */ + theme_set_string (p->view, name, value, p->theme_dir, + p->filename, p->line_num, p->col_num); + grub_free (value); + } + else + { + grub_error (GRUB_ERR_IO, + "%s:%d:%d property value invalid; " + "enclose literal values in quotes (\")", + p->filename, p->line_num, p->col_num); + goto done; + } + +done: + grub_free (name); + return grub_errno; +} + +/* Set properties on the view based on settings from the specified + theme file. */ +grub_err_t +grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path) +{ + grub_file_t file; + struct parsebuf p; + + p.view = view; + p.theme_dir = grub_get_dirname (theme_path); + + file = grub_file_open (theme_path); + if (! file) + { + grub_free (p.theme_dir); + return grub_errno; + } + + p.len = grub_file_size (file); + p.buf = grub_malloc (p.len); + p.pos = 0; + p.line_num = 1; + p.col_num = 1; + p.filename = theme_path; + if (! p.buf) + { + grub_file_close (file); + grub_free (p.theme_dir); + return grub_errno; + } + if (grub_file_read (file, p.buf, p.len) != p.len) + { + grub_free (p.buf); + grub_file_close (file); + grub_free (p.theme_dir); + return grub_errno; + } + + if (view->canvas) + view->canvas->ops->component.destroy (view->canvas); + + view->canvas = grub_gui_canvas_new (); + ((grub_gui_component_t) view->canvas) + ->ops->set_bounds ((grub_gui_component_t) view->canvas, + &view->screen); + + while (has_more (&p)) + { + /* Skip comments (lines beginning with #). */ + if (peek_char (&p) == '#') + { + advance_to_next_line (&p); + continue; + } + + /* Find the first non-whitespace character. */ + skip_whitespace (&p); + + /* Handle the content. */ + if (peek_char (&p) == '+') + { + /* Skip the '+'. */ + read_char (&p); + read_object (&p, view->canvas); + } + else + { + read_property (&p); + } + + if (grub_errno != GRUB_ERR_NONE) + goto fail; + } + + /* Set the new theme path. */ + grub_free (view->theme_path); + view->theme_path = grub_strdup (theme_path); + goto cleanup; + +fail: + if (view->canvas) + { + view->canvas->ops->component.destroy (view->canvas); + view->canvas = 0; + } + +cleanup: + grub_free (p.buf); + grub_file_close (file); + grub_free (p.theme_dir); + return grub_errno; +} diff --git a/gfxmenu/view.c b/gfxmenu/view.c new file mode 100644 index 000000000..56edc86cf --- /dev/null +++ b/gfxmenu/view.c @@ -0,0 +1,497 @@ +/* view.c - Graphical menu interface MVC view. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* The component ID identifying GUI components to be updated as the timeout + status changes. */ +#define TIMEOUT_COMPONENT_ID "__timeout__" + +static void init_terminal (grub_gfxmenu_view_t view); +static void destroy_terminal (void); +static grub_err_t set_graphics_mode (void); +static grub_err_t set_text_mode (void); + +/* Create a new view object, loading the theme specified by THEME_PATH and + associating MODEL with the view. */ +grub_gfxmenu_view_t +grub_gfxmenu_view_new (const char *theme_path, grub_gfxmenu_model_t model) +{ + grub_gfxmenu_view_t view; + + view = grub_malloc (sizeof (*view)); + if (! view) + return 0; + + set_graphics_mode (); + grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + grub_video_get_viewport ((unsigned *) &view->screen.x, + (unsigned *) &view->screen.y, + (unsigned *) &view->screen.width, + (unsigned *) &view->screen.height); + + /* Clear the screen; there may be garbage left over in video memory, and + loading the menu style (particularly the background) can take a while. */ + grub_video_fill_rect (grub_video_map_rgb (0, 0, 0), + view->screen.x, view->screen.y, + view->screen.width, view->screen.height); + grub_video_swap_buffers (); + + grub_font_t default_font; + grub_gui_color_t default_fg_color; + grub_gui_color_t default_bg_color; + + default_font = grub_font_get ("Helvetica 12"); + default_fg_color = grub_gui_color_rgb (0, 0, 0); + default_bg_color = grub_gui_color_rgb (255, 255, 255); + + view->model = model; + view->canvas = 0; + + view->title_font = default_font; + view->message_font = default_font; + view->terminal_font_name = grub_strdup ("Fixed 10"); + view->title_color = default_fg_color; + view->message_color = default_bg_color; + view->message_bg_color = default_fg_color; + view->desktop_image = 0; + view->desktop_color = default_bg_color; + view->terminal_box = grub_gfxmenu_create_box (0, 0); + view->title_text = grub_strdup ("GRUB Boot Menu"); + view->progress_message_text = 0; + view->theme_path = 0; + + if (grub_gfxmenu_view_load_theme (view, theme_path) != 0) + { + grub_gfxmenu_view_destroy (view); + return 0; + } + + init_terminal (view); + + return view; +} + +/* Destroy the view object. All used memory is freed. */ +void +grub_gfxmenu_view_destroy (grub_gfxmenu_view_t view) +{ + grub_video_bitmap_destroy (view->desktop_image); + if (view->terminal_box) + view->terminal_box->destroy (view->terminal_box); + grub_free (view->terminal_font_name); + grub_free (view->title_text); + grub_free (view->progress_message_text); + grub_free (view->theme_path); + if (view->canvas) + view->canvas->ops->component.destroy (view->canvas); + grub_free (view); + + set_text_mode (); + destroy_terminal (); +} + +/* Sets MESSAGE as the progress message for the view. + MESSAGE can be 0, in which case no message is displayed. */ +static void +set_progress_message (grub_gfxmenu_view_t view, const char *message) +{ + grub_free (view->progress_message_text); + if (message) + view->progress_message_text = grub_strdup (message); + else + view->progress_message_text = 0; +} + +static void +draw_background (grub_gfxmenu_view_t view) +{ + if (view->desktop_image) + { + struct grub_video_bitmap *img = view->desktop_image; + grub_video_blit_bitmap (img, GRUB_VIDEO_BLIT_REPLACE, + view->screen.x, view->screen.y, 0, 0, + grub_video_bitmap_get_width (img), + grub_video_bitmap_get_height (img)); + } + else + { + grub_video_fill_rect (grub_gui_map_color (view->desktop_color), + view->screen.x, view->screen.y, + view->screen.width, view->screen.height); + } +} + +static void +draw_title (grub_gfxmenu_view_t view) +{ + if (! view->title_text) + return; + + /* Center the title. */ + int title_width = grub_font_get_string_width (view->title_font, + view->title_text); + int x = (view->screen.width - title_width) / 2; + int y = 40 + grub_font_get_ascent (view->title_font); + grub_font_draw_string (view->title_text, + view->title_font, + grub_gui_map_color (view->title_color), + x, y); +} + +struct progress_value_data +{ + const char *visible; + const char *start; + const char *end; + const char *value; + const char *text; +}; + +static void +update_timeout_visit (grub_gui_component_t component, + void *userdata) +{ + struct progress_value_data *pv; + pv = (struct progress_value_data *) userdata; + component->ops->set_property (component, "visible", pv->visible); + component->ops->set_property (component, "start", pv->start); + component->ops->set_property (component, "end", pv->end); + component->ops->set_property (component, "value", pv->value); + component->ops->set_property (component, "text", pv->text); +} + +static void +update_timeout (grub_gfxmenu_view_t view) +{ + char startbuf[20]; + char valuebuf[20]; + char msgbuf[120]; + + int timeout = grub_gfxmenu_model_get_timeout_ms (view->model); + int remaining = grub_gfxmenu_model_get_timeout_remaining_ms (view->model); + struct progress_value_data pv; + + pv.visible = timeout > 0 ? "true" : "false"; + grub_sprintf (startbuf, "%d", -timeout); + pv.start = startbuf; + pv.end = "0"; + grub_sprintf (valuebuf, "%d", remaining > 0 ? -remaining : 0); + pv.value = valuebuf; + + int seconds_remaining_rounded_up = (remaining + 999) / 1000; + grub_sprintf (msgbuf, + "The highlighted entry will be booted automatically in %d s.", + seconds_remaining_rounded_up); + pv.text = msgbuf; + + grub_gui_find_by_id ((grub_gui_component_t) view->canvas, + TIMEOUT_COMPONENT_ID, update_timeout_visit, &pv); +} + +static void +update_menu_visit (grub_gui_component_t component, + void *userdata) +{ + grub_gfxmenu_view_t view; + view = userdata; + if (component->ops->is_instance (component, "list")) + { + grub_gui_list_t list = (grub_gui_list_t) component; + list->ops->set_view_info (list, view->theme_path, view->model); + } +} + +/* Update any boot menu components with the current menu model and + theme path. */ +static void +update_menu_components (grub_gfxmenu_view_t view) +{ + grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas, + update_menu_visit, view); +} + +static void +draw_message (grub_gfxmenu_view_t view) +{ + char *text = view->progress_message_text; + if (! text) + return; + + grub_font_t font = view->message_font; + grub_video_color_t color = grub_gui_map_color (view->message_color); + + /* Set the timeout bar's frame. */ + grub_video_rect_t f; + f.width = view->screen.width * 4 / 5; + f.height = 50; + f.x = view->screen.x + (view->screen.width - f.width) / 2; + f.y = view->screen.y + view->screen.height - 90 - 20 - f.height; + + /* Border. */ + grub_video_fill_rect (color, + f.x-1, f.y-1, f.width+2, f.height+2); + /* Fill. */ + grub_video_fill_rect (grub_gui_map_color (view->message_bg_color), + f.x, f.y, f.width, f.height); + + /* Center the text. */ + int text_width = grub_font_get_string_width (font, text); + int x = f.x + (f.width - text_width) / 2; + int y = (f.y + (f.height - grub_font_get_descent (font)) / 2 + + grub_font_get_ascent (font) / 2); + grub_font_draw_string (text, font, color, x, y); +} + + +void +grub_gfxmenu_view_draw (grub_gfxmenu_view_t view) +{ + grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + update_timeout (view); + update_menu_components (view); + + draw_background (view); + if (view->canvas) + view->canvas->ops->component.paint (view->canvas); + draw_title (view); + draw_message (view); +} + +static grub_err_t +set_graphics_mode (void) +{ + const char *modestr = grub_env_get ("gfxmode"); + if (!modestr || !modestr[0]) + modestr = "auto"; + return grub_video_set_mode (modestr, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); +} + +static grub_err_t +set_text_mode (void) +{ + return grub_video_restore (); +} + +static int term_target_width; +static int term_target_height; +static struct grub_video_render_target *term_target; +static int term_initialized; +static grub_term_output_t term_original; +static grub_gfxmenu_view_t term_view; + +static void +repaint_terminal (int x __attribute ((unused)), + int y __attribute ((unused)), + int width __attribute ((unused)), + int height __attribute ((unused))) +{ + if (! term_view) + return; + + grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + grub_gfxmenu_view_draw (term_view); + grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + + int termx = term_view->screen.x + + term_view->screen.width * (10 - 7) / 10 / 2; + int termy = term_view->screen.y + + term_view->screen.height * (10 - 7) / 10 / 2; + + grub_gfxmenu_box_t term_box = term_view->terminal_box; + if (term_box) + { + term_box->set_content_size (term_box, + term_target_width, term_target_height); + + term_box->draw (term_box, + termx - term_box->get_left_pad (term_box), + termy - term_box->get_top_pad (term_box)); + } + + grub_video_blit_render_target (term_target, GRUB_VIDEO_BLIT_REPLACE, + termx, termy, + 0, 0, term_target_width, term_target_height); + grub_video_swap_buffers (); +} + +static void +init_terminal (grub_gfxmenu_view_t view) +{ + term_original = grub_term_get_current_output (); + + term_target_width = view->screen.width * 7 / 10; + term_target_height = view->screen.height * 7 / 10; + + grub_video_create_render_target (&term_target, + term_target_width, + term_target_height, + GRUB_VIDEO_MODE_TYPE_RGB + | GRUB_VIDEO_MODE_TYPE_ALPHA); + if (grub_errno != GRUB_ERR_NONE) + return; + + /* Note: currently there is no API for changing the gfxterm font + on the fly, so whatever font the initially loaded theme specifies + will be permanent. */ + grub_gfxterm_init_window (term_target, 0, 0, + term_target_width, term_target_height, 0, + view->terminal_font_name, 3); + if (grub_errno != GRUB_ERR_NONE) + return; + term_initialized = 1; + + /* XXX: store static pointer to the 'view' object so the repaint callback can access it. */ + term_view = view; + grub_gfxterm_set_repaint_callback (repaint_terminal); + grub_term_set_current_output (grub_gfxterm_get_term ()); +} + +static void destroy_terminal (void) +{ + term_view = 0; + if (term_initialized) + grub_gfxterm_destroy_window (); + grub_gfxterm_set_repaint_callback (0); + if (term_target) + grub_video_delete_render_target (term_target); + if (term_original) + grub_term_set_current_output (term_original); +} + + +static void +notify_booting (grub_menu_entry_t entry, void *userdata) +{ + grub_gfxmenu_view_t view = (grub_gfxmenu_view_t) userdata; + + char *s = grub_malloc (100 + grub_strlen (entry->title)); + if (!s) + return; + + grub_sprintf (s, "Booting '%s'", entry->title); + set_progress_message (view, s); + grub_free (s); + grub_gfxmenu_view_draw (view); + grub_video_swap_buffers (); +} + +static void +notify_fallback (grub_menu_entry_t entry, void *userdata) +{ + grub_gfxmenu_view_t view = (grub_gfxmenu_view_t) userdata; + + char *s = grub_malloc (100 + grub_strlen (entry->title)); + if (!s) + return; + + grub_sprintf (s, "Falling back to '%s'", entry->title); + set_progress_message (view, s); + grub_free (s); + grub_gfxmenu_view_draw (view); + grub_video_swap_buffers (); +} + +static void +notify_execution_failure (void *userdata __attribute__ ((unused))) +{ +} + + +static struct grub_menu_execute_callback execute_callback = +{ + .notify_booting = notify_booting, + .notify_fallback = notify_fallback, + .notify_failure = notify_execution_failure +}; + +int +grub_gfxmenu_view_execute_with_fallback (grub_gfxmenu_view_t view, + grub_menu_entry_t entry) +{ + grub_menu_execute_with_fallback (grub_gfxmenu_model_get_menu (view->model), + entry, &execute_callback, (void *) view); + + if (set_graphics_mode () != GRUB_ERR_NONE) + return 0; /* Failure. */ + + /* If we returned, there was a failure. */ + set_progress_message (view, + "Unable to automatically boot. " + "Press SPACE to continue."); + grub_gfxmenu_view_draw (view); + grub_video_swap_buffers (); + while (GRUB_TERM_ASCII_CHAR(grub_getkey ()) != ' ') + { + /* Wait for SPACE to be pressed. */ + } + + set_progress_message (view, 0); /* Clear the message. */ + + return 1; /* Ok. */ +} + +int +grub_gfxmenu_view_execute_entry (grub_gfxmenu_view_t view, + grub_menu_entry_t entry) +{ + /* Currently we switch back to text mode by restoring + the original terminal before executing the menu entry. + It is hard to make it work when executing a menu entry + that switches video modes -- it using gfxterm in a + window, the repaint callback seems to crash GRUB. */ + /* TODO: Determine if this works when 'gfxterm' was set as + the current terminal before invoking the gfxmenu. */ + destroy_terminal (); + + grub_menu_execute_entry (entry); + if (grub_errno != GRUB_ERR_NONE) + grub_wait_after_message (); + + if (set_graphics_mode () != GRUB_ERR_NONE) + return 0; /* Failure. */ + + init_terminal (view); + return 1; /* Ok. */ +} + +void +grub_gfxmenu_view_run_terminal (grub_gfxmenu_view_t view __attribute__((unused))) +{ + grub_cmdline_run (1); +} diff --git a/gfxmenu/widget-box.c b/gfxmenu/widget-box.c new file mode 100644 index 000000000..079fd66d4 --- /dev/null +++ b/gfxmenu/widget-box.c @@ -0,0 +1,313 @@ +/* widget_box.c - Pixmap-stylized box widget. */ +/* + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +enum box_pixmaps +{ + BOX_PIXMAP_NW, BOX_PIXMAP_NE, BOX_PIXMAP_SE, BOX_PIXMAP_SW, + BOX_PIXMAP_N, BOX_PIXMAP_E, BOX_PIXMAP_S, BOX_PIXMAP_W, + BOX_PIXMAP_CENTER +}; + +static const char *box_pixmap_names[] = { + /* Corners: */ + "nw", "ne", "se", "sw", + /* Sides: */ + "n", "e", "s", "w", + /* Center: */ + "c" +}; + +#define BOX_NUM_PIXMAPS (sizeof(box_pixmap_names)/sizeof(*box_pixmap_names)) + +static int +get_height (struct grub_video_bitmap *bitmap) +{ + if (bitmap) + return grub_video_bitmap_get_height (bitmap); + else + return 0; +} + +static int +get_width (struct grub_video_bitmap *bitmap) +{ + if (bitmap) + return grub_video_bitmap_get_width (bitmap); + else + return 0; +} + +static void +blit (grub_gfxmenu_box_t self, int pixmap_index, int x, int y) +{ + struct grub_video_bitmap *bitmap; + bitmap = self->scaled_pixmaps[pixmap_index]; + if (! bitmap) + return; + grub_video_blit_bitmap (bitmap, GRUB_VIDEO_BLIT_BLEND, + x, y, 0, 0, + grub_video_bitmap_get_width (bitmap), + grub_video_bitmap_get_height (bitmap)); +} + +static void +draw (grub_gfxmenu_box_t self, int x, int y) +{ + int height_n; + int height_s; + int height_e; + int height_w; + int width_n; + int width_s; + int width_e; + int width_w; + + height_n = get_height (self->scaled_pixmaps[BOX_PIXMAP_N]); + height_s = get_height (self->scaled_pixmaps[BOX_PIXMAP_S]); + height_e = get_height (self->scaled_pixmaps[BOX_PIXMAP_E]); + height_w = get_height (self->scaled_pixmaps[BOX_PIXMAP_W]); + width_n = get_width (self->scaled_pixmaps[BOX_PIXMAP_N]); + width_s = get_width (self->scaled_pixmaps[BOX_PIXMAP_S]); + width_e = get_width (self->scaled_pixmaps[BOX_PIXMAP_E]); + width_w = get_width (self->scaled_pixmaps[BOX_PIXMAP_W]); + + /* Draw sides. */ + blit (self, BOX_PIXMAP_N, x + width_w, y); + blit (self, BOX_PIXMAP_S, x + width_w, y + height_n + self->content_height); + blit (self, BOX_PIXMAP_E, x + width_w + self->content_width, y + height_n); + blit (self, BOX_PIXMAP_W, x, y + height_n); + + /* Draw corners. */ + blit (self, BOX_PIXMAP_NW, x, y); + blit (self, BOX_PIXMAP_NE, x + width_w + self->content_width, y); + blit (self, BOX_PIXMAP_SE, + x + width_w + self->content_width, + y + height_n + self->content_height); + blit (self, BOX_PIXMAP_SW, x, y + height_n + self->content_height); + + /* Draw center. */ + blit (self, BOX_PIXMAP_CENTER, x + width_w, y + height_n); +} + +static grub_err_t +scale_pixmap (grub_gfxmenu_box_t self, int i, int w, int h) +{ + struct grub_video_bitmap **scaled = &self->scaled_pixmaps[i]; + struct grub_video_bitmap *raw = self->raw_pixmaps[i]; + + if (raw == 0) + return grub_errno; + + if (w == -1) + w = grub_video_bitmap_get_width (raw); + if (h == -1) + h = grub_video_bitmap_get_height (raw); + + if (*scaled == 0 + || ((int) grub_video_bitmap_get_width (*scaled) != w) + || ((int) grub_video_bitmap_get_height (*scaled) != h)) + { + if (*scaled) + { + grub_video_bitmap_destroy (*scaled); + *scaled = 0; + } + + /* Don't try to create a bitmap with a zero dimension. */ + if (w != 0 && h != 0) + grub_video_bitmap_create_scaled (scaled, w, h, raw, + GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST); + if (grub_errno != GRUB_ERR_NONE) + { + grub_error_push (); + grub_error (grub_errno, + "failed to scale bitmap for styled box pixmap #%d", i); + } + } + + return grub_errno; +} + +static void +set_content_size (grub_gfxmenu_box_t self, + int width, int height) +{ + self->content_width = width; + self->content_height = height; + + /* Resize sides to match the width and height. */ + /* It is assumed that the corners width/height match the adjacent sides. */ + + /* Resize N and S sides to match width. */ + if (scale_pixmap(self, BOX_PIXMAP_N, width, -1) != GRUB_ERR_NONE) + return; + if (scale_pixmap(self, BOX_PIXMAP_S, width, -1) != GRUB_ERR_NONE) + return; + + /* Resize E and W sides to match height. */ + if (scale_pixmap(self, BOX_PIXMAP_E, -1, height) != GRUB_ERR_NONE) + return; + if (scale_pixmap(self, BOX_PIXMAP_W, -1, height) != GRUB_ERR_NONE) + return; + + /* Don't scale the corners--they are assumed to match the sides. */ + if (scale_pixmap(self, BOX_PIXMAP_NW, -1, -1) != GRUB_ERR_NONE) + return; + if (scale_pixmap(self, BOX_PIXMAP_SW, -1, -1) != GRUB_ERR_NONE) + return; + if (scale_pixmap(self, BOX_PIXMAP_NE, -1, -1) != GRUB_ERR_NONE) + return; + if (scale_pixmap(self, BOX_PIXMAP_SE, -1, -1) != GRUB_ERR_NONE) + return; + + /* Scale the center area. */ + if (scale_pixmap(self, BOX_PIXMAP_CENTER, width, height) != GRUB_ERR_NONE) + return; +} + +static int +get_left_pad (grub_gfxmenu_box_t self) +{ + return get_width (self->raw_pixmaps[BOX_PIXMAP_W]); +} + +static int +get_top_pad (grub_gfxmenu_box_t self) +{ + return get_height (self->raw_pixmaps[BOX_PIXMAP_N]); +} + +static int +get_right_pad (grub_gfxmenu_box_t self) +{ + return get_width (self->raw_pixmaps[BOX_PIXMAP_E]); +} + +static int +get_bottom_pad (grub_gfxmenu_box_t self) +{ + return get_height (self->raw_pixmaps[BOX_PIXMAP_S]); +} + +static void +destroy (grub_gfxmenu_box_t self) +{ + unsigned i; + for (i = 0; i < BOX_NUM_PIXMAPS; i++) + { + if (self->raw_pixmaps[i]) + grub_video_bitmap_destroy(self->raw_pixmaps[i]); + self->raw_pixmaps[i] = 0; + + if (self->scaled_pixmaps[i]) + grub_video_bitmap_destroy(self->scaled_pixmaps[i]); + self->scaled_pixmaps[i] = 0; + } + grub_free (self->raw_pixmaps); + self->raw_pixmaps = 0; + grub_free (self->scaled_pixmaps); + self->scaled_pixmaps = 0; + + /* Free self: must be the last step! */ + grub_free (self); +} + + +/* Create a new box. If PIXMAPS_PREFIX and PIXMAPS_SUFFIX are both non-null, + then an attempt is made to load the north, south, east, west, northwest, + northeast, southeast, southwest, and center pixmaps. + If either PIXMAPS_PREFIX or PIXMAPS_SUFFIX is 0, then no pixmaps are + loaded, and the box has zero-width borders and is drawn transparent. */ +grub_gfxmenu_box_t +grub_gfxmenu_create_box (const char *pixmaps_prefix, + const char *pixmaps_suffix) +{ + unsigned i; + grub_gfxmenu_box_t box; + + box = (grub_gfxmenu_box_t) grub_malloc (sizeof (*box)); + if (! box) + return 0; + + box->content_width = 0; + box->content_height = 0; + box->raw_pixmaps = + (struct grub_video_bitmap **) + grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); + box->scaled_pixmaps = + (struct grub_video_bitmap **) + grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); + + /* Initialize all pixmap pointers to NULL so that proper destruction can + be performed if an error is encountered partway through construction. */ + for (i = 0; i < BOX_NUM_PIXMAPS; i++) + box->raw_pixmaps[i] = 0; + for (i = 0; i < BOX_NUM_PIXMAPS; i++) + box->scaled_pixmaps[i] = 0; + + /* Load the pixmaps. */ + for (i = 0; i < BOX_NUM_PIXMAPS; i++) + { + if (pixmaps_prefix && pixmaps_suffix) + { + char *path; + char *path_end; + + path = grub_malloc (grub_strlen (pixmaps_prefix) + + grub_strlen (box_pixmap_names[i]) + + grub_strlen (pixmaps_suffix) + + 1); + if (! path) + goto fail_and_destroy; + + /* Construct the specific path for this pixmap. */ + path_end = grub_stpcpy (path, pixmaps_prefix); + path_end = grub_stpcpy (path_end, box_pixmap_names[i]); + path_end = grub_stpcpy (path_end, pixmaps_suffix); + + grub_video_bitmap_load (&box->raw_pixmaps[i], path); + grub_free (path); + + /* Ignore missing pixmaps. */ + grub_errno = GRUB_ERR_NONE; + } + } + + box->draw = draw; + box->set_content_size = set_content_size; + box->get_left_pad = get_left_pad; + box->get_top_pad = get_top_pad; + box->get_right_pad = get_right_pad; + box->get_bottom_pad = get_bottom_pad; + box->destroy = destroy; + return box; + +fail_and_destroy: + destroy (box); + return 0; +} diff --git a/include/grub/gfxmenu_model.h b/include/grub/gfxmenu_model.h new file mode 100644 index 000000000..e5c7da3ac --- /dev/null +++ b/include/grub/gfxmenu_model.h @@ -0,0 +1,59 @@ +/* gfxmenu_model.h - gfxmenu model interface. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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_GFXMENU_MODEL_HEADER +#define GRUB_GFXMENU_MODEL_HEADER 1 + +#include + +struct grub_gfxmenu_model; /* Forward declaration of opaque type. */ +typedef struct grub_gfxmenu_model *grub_gfxmenu_model_t; + + +grub_gfxmenu_model_t grub_gfxmenu_model_new (grub_menu_t menu); + +void grub_gfxmenu_model_destroy (grub_gfxmenu_model_t model); + +grub_menu_t grub_gfxmenu_model_get_menu (grub_gfxmenu_model_t model); + +void grub_gfxmenu_model_set_timeout (grub_gfxmenu_model_t model); + +void grub_gfxmenu_model_clear_timeout (grub_gfxmenu_model_t model); + +int grub_gfxmenu_model_get_timeout_ms (grub_gfxmenu_model_t model); + +int grub_gfxmenu_model_get_timeout_remaining_ms (grub_gfxmenu_model_t model); + +int grub_gfxmenu_model_timeout_expired (grub_gfxmenu_model_t model); + +int grub_gfxmenu_model_get_num_entries (grub_gfxmenu_model_t model); + +int grub_gfxmenu_model_get_selected_index (grub_gfxmenu_model_t model); + +void grub_gfxmenu_model_set_selected_index (grub_gfxmenu_model_t model, + int index); + +const char *grub_gfxmenu_model_get_entry_title (grub_gfxmenu_model_t model, + int index); + +grub_menu_entry_t grub_gfxmenu_model_get_entry (grub_gfxmenu_model_t model, + int index); + +#endif /* GRUB_GFXMENU_MODEL_HEADER */ + diff --git a/include/grub/gfxmenu_view.h b/include/grub/gfxmenu_view.h new file mode 100644 index 000000000..1144382f2 --- /dev/null +++ b/include/grub/gfxmenu_view.h @@ -0,0 +1,91 @@ +/* gfxmenu_view.h - gfxmenu view interface. */ +/* + * 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 . + */ + +#ifndef GRUB_GFXMENU_VIEW_HEADER +#define GRUB_GFXMENU_VIEW_HEADER 1 + +#include +#include +#include +#include +#include +#include + +struct grub_gfxmenu_view; /* Forward declaration of opaque type. */ +typedef struct grub_gfxmenu_view *grub_gfxmenu_view_t; + + +grub_gfxmenu_view_t grub_gfxmenu_view_new (const char *theme_path, + grub_gfxmenu_model_t model); + +void grub_gfxmenu_view_destroy (grub_gfxmenu_view_t view); + +/* Set properties on the view based on settings from the specified + theme file. */ +grub_err_t grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, + const char *theme_path); + +grub_err_t grub_gui_recreate_box (grub_gfxmenu_box_t *boxptr, + const char *pattern, const char *theme_dir); + +void grub_gfxmenu_view_draw (grub_gfxmenu_view_t view); + +int grub_gfxmenu_view_execute_with_fallback (grub_gfxmenu_view_t view, + grub_menu_entry_t entry); + +int grub_gfxmenu_view_execute_entry (grub_gfxmenu_view_t view, + grub_menu_entry_t entry); + +void grub_gfxmenu_view_run_terminal (grub_gfxmenu_view_t view); + + + +/* Implementation details -- this should not be used outside of the + view itself. */ + +#include +#include +#include +#include +#include + +/* Definition of the private representation of the view. */ +struct grub_gfxmenu_view +{ + grub_video_rect_t screen; + + grub_font_t title_font; + grub_font_t message_font; + char *terminal_font_name; + grub_gui_color_t title_color; + grub_gui_color_t message_color; + grub_gui_color_t message_bg_color; + struct grub_video_bitmap *desktop_image; + grub_gui_color_t desktop_color; + grub_gfxmenu_box_t terminal_box; + char *title_text; + char *progress_message_text; + char *theme_path; + + grub_gui_container_t canvas; + + grub_gfxmenu_model_t model; +}; + +#endif /* ! GRUB_GFXMENU_VIEW_HEADER */ diff --git a/include/grub/gfxwidgets.h b/include/grub/gfxwidgets.h new file mode 100644 index 000000000..f9678bf9e --- /dev/null +++ b/include/grub/gfxwidgets.h @@ -0,0 +1,49 @@ +/* gfxwidgets.h - Widgets for the graphical menu (gfxmenu). */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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_GFXWIDGETS_HEADER +#define GRUB_GFXWIDGETS_HEADER 1 + +#include + +typedef struct grub_gfxmenu_box *grub_gfxmenu_box_t; + +struct grub_gfxmenu_box +{ + /* The size of the content. */ + int content_width; + int content_height; + + struct grub_video_bitmap **raw_pixmaps; + struct grub_video_bitmap **scaled_pixmaps; + + void (*draw) (grub_gfxmenu_box_t self, int x, int y); + void (*set_content_size) (grub_gfxmenu_box_t self, + int width, int height); + int (*get_left_pad) (grub_gfxmenu_box_t self); + int (*get_top_pad) (grub_gfxmenu_box_t self); + int (*get_right_pad) (grub_gfxmenu_box_t self); + int (*get_bottom_pad) (grub_gfxmenu_box_t self); + void (*destroy) (grub_gfxmenu_box_t self); +}; + +grub_gfxmenu_box_t grub_gfxmenu_create_box (const char *pixmaps_prefix, + const char *pixmaps_suffix); + +#endif /* ! GRUB_GFXWIDGETS_HEADER */ diff --git a/include/grub/gui.h b/include/grub/gui.h new file mode 100644 index 000000000..5b785dbb5 --- /dev/null +++ b/include/grub/gui.h @@ -0,0 +1,165 @@ +/* gui.h - GUI components header file. */ +/* + * 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 . + */ + +#include +#include +#include +#include +#include + +#ifndef GRUB_GUI_H +#define GRUB_GUI_H 1 + +/* A representation of a color. Unlike grub_video_color_t, this + representation is independent of any video mode specifics. */ +typedef struct grub_gui_color +{ + grub_uint8_t red; + grub_uint8_t green; + grub_uint8_t blue; + grub_uint8_t alpha; +} grub_gui_color_t; + +typedef struct grub_gui_component *grub_gui_component_t; +typedef struct grub_gui_container *grub_gui_container_t; +typedef struct grub_gui_list *grub_gui_list_t; + +typedef void (*grub_gui_component_callback) (grub_gui_component_t component, + void *userdata); + +/* Component interface. */ + +struct grub_gui_component_ops +{ + void (*destroy) (void *self); + const char * (*get_id) (void *self); + int (*is_instance) (void *self, const char *type); + void (*paint) (void *self); + void (*set_parent) (void *self, grub_gui_container_t parent); + grub_gui_container_t (*get_parent) (void *self); + void (*set_bounds) (void *self, const grub_video_rect_t *bounds); + void (*get_bounds) (void *self, grub_video_rect_t *bounds); + void (*get_preferred_size) (void *self, int *width, int *height); + grub_err_t (*set_property) (void *self, const char *name, const char *value); +}; + +struct grub_gui_container_ops +{ + struct grub_gui_component_ops component; + void (*add) (void *self, grub_gui_component_t comp); + void (*remove) (void *self, grub_gui_component_t comp); + void (*iterate_children) (void *self, + grub_gui_component_callback cb, void *userdata); +}; + +struct grub_gui_list_ops +{ + struct grub_gui_component_ops component_ops; + void (*set_view_info) (void *self, + const char *theme_path, + grub_gfxmenu_model_t menu); +}; + +struct grub_gui_component +{ + struct grub_gui_component_ops *ops; +}; + +struct grub_gui_container +{ + struct grub_gui_container_ops *ops; +}; + +struct grub_gui_list +{ + struct grub_gui_list_ops *ops; +}; + + +/* Interfaces to concrete component classes. */ + +grub_gui_container_t grub_gui_canvas_new (void); +grub_gui_container_t grub_gui_vbox_new (void); +grub_gui_container_t grub_gui_hbox_new (void); +grub_gui_component_t grub_gui_label_new (void); +grub_gui_component_t grub_gui_image_new (void); +grub_gui_component_t grub_gui_progress_bar_new (void); +grub_gui_component_t grub_gui_list_new (void); +grub_gui_component_t grub_gui_circular_progress_new (void); + +/* Manipulation functions. */ + +/* Visit all components with the specified ID. */ +void grub_gui_find_by_id (grub_gui_component_t root, + const char *id, + grub_gui_component_callback cb, + void *userdata); + +/* Visit all components. */ +void grub_gui_iterate_recursively (grub_gui_component_t root, + grub_gui_component_callback cb, + void *userdata); + +/* Helper functions. */ + +static __inline void +grub_gui_save_viewport (grub_video_rect_t *r) +{ + grub_video_get_viewport ((unsigned *) &r->x, + (unsigned *) &r->y, + (unsigned *) &r->width, + (unsigned *) &r->height); +} + +static __inline void +grub_gui_restore_viewport (const grub_video_rect_t *r) +{ + grub_video_set_viewport (r->x, r->y, r->width, r->height); +} + +/* Set a new viewport relative the the current one, saving the current + viewport in OLD so it can be later restored. */ +static __inline void +grub_gui_set_viewport (const grub_video_rect_t *r, grub_video_rect_t *old) +{ + grub_gui_save_viewport (old); + grub_video_set_viewport (old->x + r->x, + old->y + r->y, + r->width, + r->height); +} + +static __inline grub_gui_color_t +grub_gui_color_rgb (int r, int g, int b) +{ + grub_gui_color_t c; + c.red = r; + c.green = g; + c.blue = b; + c.alpha = 255; + return c; +} + +static __inline grub_video_color_t +grub_gui_map_color (grub_gui_color_t c) +{ + return grub_video_map_rgba (c.red, c.green, c.blue, c.alpha); +} + +#endif /* ! GRUB_GUI_H */ diff --git a/include/grub/gui_string_util.h b/include/grub/gui_string_util.h new file mode 100644 index 000000000..7b5fbb3ea --- /dev/null +++ b/include/grub/gui_string_util.h @@ -0,0 +1,39 @@ +/* gui_string_util.h - String utilities for the graphical menu interface. */ +/* + * 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 . + */ + +#ifndef GRUB_GUI_STRING_UTIL_HEADER +#define GRUB_GUI_STRING_UTIL_HEADER 1 + +#include +#include + +char *grub_new_substring (const char *buf, + grub_size_t start, grub_size_t end); + +char *grub_resolve_relative_path (const char *base, const char *path); + +char *grub_get_dirname (const char *file_path); + +int grub_gui_get_named_color (const char *name, grub_gui_color_t *color); + +grub_err_t grub_gui_parse_color (const char *s, grub_gui_color_t *color); + +grub_err_t grub_gui_parse_2_tuple (const char *s, int *px, int *py); + +#endif /* GRUB_GUI_STRING_UTIL_HEADER */ diff --git a/include/grub/icon_manager.h b/include/grub/icon_manager.h new file mode 100644 index 000000000..81c488416 --- /dev/null +++ b/include/grub/icon_manager.h @@ -0,0 +1,41 @@ +/* icon_manager.h - gfxmenu icon manager. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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_ICON_MANAGER_HEADER +#define GRUB_ICON_MANAGER_HEADER 1 + +#include +#include + +/* Forward declaration of opaque structure handle type. */ +typedef struct grub_gfxmenu_icon_manager *grub_gfxmenu_icon_manager_t; + +grub_gfxmenu_icon_manager_t grub_gfxmenu_icon_manager_new (void); +void grub_gfxmenu_icon_manager_destroy (grub_gfxmenu_icon_manager_t mgr); +void grub_gfxmenu_icon_manager_clear_cache (grub_gfxmenu_icon_manager_t mgr); +void grub_gfxmenu_icon_manager_set_theme_path (grub_gfxmenu_icon_manager_t mgr, + const char *path); +void grub_gfxmenu_icon_manager_set_icon_size (grub_gfxmenu_icon_manager_t mgr, + int width, int height); +struct grub_video_bitmap * +grub_gfxmenu_icon_manager_get_icon (grub_gfxmenu_icon_manager_t mgr, + grub_menu_entry_t entry); + +#endif /* GRUB_ICON_MANAGER_HEADER */ + diff --git a/include/grub/term.h b/include/grub/term.h index 316d75390..20b85d1cd 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -261,7 +261,7 @@ grub_term_set_current_input (grub_term_input_t term) } static inline grub_err_t -grub_term_set_current_output (grub_term_output_t term) +grub_term_set_current_output (const struct grub_term_output *term) { return grub_handler_set_current (&grub_term_output_class, GRUB_AS_HANDLER (term)); From 704e21180ed65e96111383a8b780eff614e0e035 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 16:07:16 +0100 Subject: [PATCH 017/237] At least it compiles now --- gfxmenu/gui_label.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gfxmenu/gui_label.c b/gfxmenu/gui_label.c index 2e49c787e..eb2a495ff 100644 --- a/gfxmenu/gui_label.c +++ b/gfxmenu/gui_label.c @@ -151,7 +151,7 @@ label_get_preferred_size (void *vself, int *width, int *height) *height = self->preferred_height; } -static void +static grub_err_t label_set_property (void *vself, const char *name, const char *value) { grub_gui_label_t self = vself; @@ -204,6 +204,7 @@ label_set_property (void *vself, const char *name, const char *value) else self->id = 0; } + return GRUB_ERR_NONE; } static struct grub_gui_component_ops label_ops = From 8dec533a1cdeafd13c239121d36ffd507575bc47 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 22:26:08 +0100 Subject: [PATCH 018/237] ChangeLog --- ChangeLog.gfxmenu | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 ChangeLog.gfxmenu diff --git a/ChangeLog.gfxmenu b/ChangeLog.gfxmenu new file mode 100644 index 000000000..bc9db7170 --- /dev/null +++ b/ChangeLog.gfxmenu @@ -0,0 +1,31 @@ +2009-11-20 Colin D Bennett + + * conf/common.rmk (pkglib_MODULES): Add gfxmenu.mod. + (gfxmenu_mod_SOURCES): New variable. + (gfxmenu_mod_CFLAGS): Likewise. + (gfxmenu_mod_LDFLAGS): Likewise. + * include/grub/term.h (grub_term_set_current_output): Declare + argument as const. + * docs/gfxmenu-theme-example.txt: New file. + * gfxmenu/gfxmenu.c: Likewise. + * gfxmenu/gui_box.c: Likewise. + * gfxmenu/gui_canvas.c: Likewise. + * gfxmenu/gui_circular_progress.c: Likewise. + * gfxmenu/gui_image.c: Likewise. + * gfxmenu/gui_label.c: Likewise. + * gfxmenu/gui_list.c: Likewise. + * gfxmenu/gui_progress_bar.c: Likewise. + * gfxmenu/gui_string_util.c: Likewise. + * gfxmenu/gui_util.c: Likewise. + * gfxmenu/icon_manager.c: Likewise. + * gfxmenu/model.c: Likewise. + * gfxmenu/named_colors.c: Likewise. + * gfxmenu/theme_loader.c: Likewise. + * gfxmenu/view.c: Likewise. + * gfxmenu/widget-box.c: Likewise. + * include/grub/gfxmenu_model.h: Likewise. + * include/grub/gfxmenu_view.h: Likewise. + * include/grub/gfxwidgets.h: Likewise. + * include/grub/gui.h: Likewise. + * include/grub/gui_string_util.h: Likewise. + * include/grub/icon_manager.h: Likewise. From aff798d6f4ae597c6b887abc8977d63bc434aa10 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 21 Nov 2009 15:29:12 +0100 Subject: [PATCH 019/237] icondir support --- gfxmenu/gui_string_util.c | 13 ++++++++++--- gfxmenu/icon_manager.c | 18 ++++++++---------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/gfxmenu/gui_string_util.c b/gfxmenu/gui_string_util.c index 41170d724..31b2f0aca 100644 --- a/gfxmenu/gui_string_util.c +++ b/gfxmenu/gui_string_util.c @@ -150,18 +150,25 @@ grub_resolve_relative_path (const char *base, const char *path) char *abspath; char *canonpath; char *p; + grub_size_t l; /* If PATH is an absolute path, then just use it as is. */ if (path[0] == '/' || path[0] == '(') return canonicalize_path (path); - abspath = grub_malloc (grub_strlen (base) + grub_strlen (path) + 1); + abspath = grub_malloc (grub_strlen (base) + grub_strlen (path) + 3); if (! abspath) return 0; - /* Concatenate BASE and PATH. - Note that BASE is expected to have a trailing slash. */ + /* Concatenate BASE and PATH. */ p = grub_stpcpy (abspath, base); + l = grub_strlen (abspath); + if (l == 0 || abspath[l-1] != '/') + { + *p = '/'; + p++; + *p = 0; + } grub_stpcpy (p, path); canonpath = canonicalize_path (abspath); diff --git a/gfxmenu/icon_manager.c b/gfxmenu/icon_manager.c index a362882e1..b7b891991 100644 --- a/gfxmenu/icon_manager.c +++ b/gfxmenu/icon_manager.c @@ -26,6 +26,7 @@ #include #include #include +#include /* Currently hard coded to '.png' extension. */ static const char icon_extension[] = ".png"; @@ -200,19 +201,16 @@ get_icon_by_class (grub_gfxmenu_icon_manager_t mgr, const char *class_name) icon = try_loading_icon (mgr, icons_dir, class_name); grub_free (icons_dir); } + + grub_free (theme_dir); if (! icon) { - /* If the theme doesn't have an appropriate icon, check in - "grub/themes/icons". */ - /* TODO use GRUB prefix "/icons" */ - icons_dir = grub_resolve_relative_path (theme_dir, "../icons/"); - if (icons_dir) - { - icon = try_loading_icon (mgr, icons_dir, class_name); - grub_free (icons_dir); - } + const char *icondir; + + icondir = grub_env_get ("icondir"); + if (icondir) + icon = try_loading_icon (mgr, icondir, class_name); } - grub_free (theme_dir); /* No icon was found. */ /* This should probably be noted in the cache, so that a search is not From 87efa251d5ff7474bc5827d6aa1957a12880e3a4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 21 Nov 2009 17:48:05 +0100 Subject: [PATCH 020/237] Fix a bug in icondir handling --- gfxmenu/icon_manager.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gfxmenu/icon_manager.c b/gfxmenu/icon_manager.c index b7b891991..0c304ede0 100644 --- a/gfxmenu/icon_manager.c +++ b/gfxmenu/icon_manager.c @@ -137,14 +137,21 @@ static struct grub_video_bitmap * try_loading_icon (grub_gfxmenu_icon_manager_t mgr, const char *dir, const char *class_name) { - char *path = grub_malloc (grub_strlen (dir) - + grub_strlen (class_name) - + grub_strlen (icon_extension) - + 1); + char *path; + int l; + + path = grub_malloc (grub_strlen (dir) + grub_strlen (class_name) + + grub_strlen (icon_extension) + 3); if (! path) return 0; grub_strcpy (path, dir); + l = grub_strlen (path); + if (path[l-1] != '/') + { + path[l] = '/'; + path[l+1] = 0; + } grub_strcat (path, class_name); grub_strcat (path, icon_extension); From f5b23252e2f071650bce4cb9e39ef18f211e95a2 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sat, 21 Nov 2009 20:59:48 +0000 Subject: [PATCH 021/237] 2009-11-21 Robert Millan * maintainance/gentrigtables.py: Avoid duplicate hardcoding of integer constants. --- ChangeLog.trig | 5 +++++ maintainance/gentrigtables.py | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ChangeLog.trig b/ChangeLog.trig index c3cd73594..725e67859 100644 --- a/ChangeLog.trig +++ b/ChangeLog.trig @@ -1,3 +1,8 @@ +2009-11-21 Robert Millan + + * maintainance/gentrigtables.py: Avoid duplicate hardcoding of + integer constants. + 2009-11-14 Colin D Bennet Trigonometry support. diff --git a/maintainance/gentrigtables.py b/maintainance/gentrigtables.py index 7c069f833..81b7bd058 100644 --- a/maintainance/gentrigtables.py +++ b/maintainance/gentrigtables.py @@ -2,7 +2,7 @@ # Script to generate trigonometric function tables. # # GRUB -- GRand Unified Bootloader -# Copyright (C) 2008 Free Software Foundation, Inc. +# 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 @@ -41,14 +41,16 @@ def writeTable(arr, name): def main(): sintab = [] costab = [] - for i in range(256): + angle_max = 256 + fraction_scale = 16384 + for i in range(angle_max): # Convert to an angle in 1/256 of a circle. - x = i * 2 * pi / 256 - sintab.append(int(round(sin(x) * 16384))) - costab.append(int(round(cos(x) * 16384))) + x = i * 2 * pi / angle_max + sintab.append(int(round(sin(x) * fraction_scale))) + costab.append(int(round(cos(x) * fraction_scale))) - write("#define TRIG_ANGLE_MAX 256\n") - write("#define TRIG_FRACTION_SCALE 16384\n") + write("#define TRIG_ANGLE_MAX " + str (angle_max) + "\n") + write("#define TRIG_FRACTION_SCALE " + str (fraction_scale) + "\n") writeTable(sintab, "sintab") writeTable(costab, "costab") From d2be7481856e8c8296a230ed91c410dac81fb207 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sat, 21 Nov 2009 21:44:08 +0000 Subject: [PATCH 022/237] 2009-11-21 Robert Millan * maintainance/gentrigtables.py: Remove. * lib/trig.c: Likewise. * gentrigtables.c: New file. C rewrite of gentrigtables.py. * conf/common.rmk (trig_mod_SOURCES): Replace `lib/trig.c' with `trigtables.c'. (trigtables.c): New rule. (gentrigtables): Likewise. (DISTCLEANFILES): Add `trigtables.c' and `gentrigtables'. --- ChangeLog.trig | 13 ++++++ conf/common.rmk | 10 ++++- gentrigtables.c | 48 ++++++++++++++++++++ lib/trig.c | 83 ----------------------------------- maintainance/gentrigtables.py | 60 ------------------------- 5 files changed, 69 insertions(+), 145 deletions(-) create mode 100644 gentrigtables.c delete mode 100644 lib/trig.c delete mode 100644 maintainance/gentrigtables.py diff --git a/ChangeLog.trig b/ChangeLog.trig index 725e67859..6aef8f894 100644 --- a/ChangeLog.trig +++ b/ChangeLog.trig @@ -1,3 +1,16 @@ +2009-11-21 Robert Millan + + * maintainance/gentrigtables.py: Remove. + * lib/trig.c: Likewise. + + * gentrigtables.c: New file. C rewrite of gentrigtables.py. + + * conf/common.rmk (trig_mod_SOURCES): Replace `lib/trig.c' with + `trigtables.c'. + (trigtables.c): New rule. + (gentrigtables): Likewise. + (DISTCLEANFILES): Add `trigtables.c' and `gentrigtables'. + 2009-11-21 Robert Millan * maintainance/gentrigtables.py: Avoid duplicate hardcoding of diff --git a/conf/common.rmk b/conf/common.rmk index 439f468dd..e841d5608 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -660,12 +660,18 @@ xnu_uuid_mod_SOURCES = commands/xnu_uuid.c xnu_uuid_mod_CFLAGS = $(COMMON_CFLAGS) xnu_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For trig.mod. pkglib_MODULES += trig.mod -trig_mod_SOURCES = lib/trig.c +trig_mod_SOURCES = trigtables.c trig_mod_CFLAGS = $(COMMON_CFLAGS) trig_mod_LDFLAGS = $(COMMON_LDFLAGS) +trigtables.c: gentrigtables + ./gentrigtables > $@ +DISTCLEANFILES += trigtables.c +gentrigtables: gentrigtables.c + $(CC) -o $@ $^ $(CPPFLAGS) -lm +DISTCLEANFILES += gentrigtables + pkglib_MODULES += setjmp.mod setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS) diff --git a/gentrigtables.c b/gentrigtables.c new file mode 100644 index 000000000..3ef6d08f7 --- /dev/null +++ b/gentrigtables.c @@ -0,0 +1,48 @@ +/* Generate trigonometric function tables. */ +/* + * 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 . + */ + +#define _GNU_SOURCE 1 + +#include +#include +#include + +int +main () +{ + int i; + + printf ("#include \n"); + +#define TAB(op) \ + printf ("grub_int16_t grub_trig_" #op "tab[] =\n{"); \ + for (i = 0; i < GRUB_TRIG_ANGLE_MAX; i++) \ + { \ + double x = i * 2 * M_PI / GRUB_TRIG_ANGLE_MAX; \ + if (i % 10 == 0) \ + printf ("\n "); \ + printf ("%d,", (int) (round (op (x) * GRUB_TRIG_FRACTION_SCALE))); \ + } \ + printf ("\n};\n") + + TAB(sin); + TAB(cos); + + exit (0); +} diff --git a/lib/trig.c b/lib/trig.c deleted file mode 100644 index e36aa38ef..000000000 --- a/lib/trig.c +++ /dev/null @@ -1,83 +0,0 @@ -/* trig.c - Trigonometric table definitions. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 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 - -/* These tables were generated with `gentrigtables.py'. */ - -short grub_trig_sintab[] = -{ - 0,402,804,1205,1606,2006,2404,2801,3196,3590, - 3981,4370,4756,5139,5520,5897,6270,6639,7005,7366, - 7723,8076,8423,8765,9102,9434,9760,10080,10394,10702, - 11003,11297,11585,11866,12140,12406,12665,12916,13160,13395, - 13623,13842,14053,14256,14449,14635,14811,14978,15137,15286, - 15426,15557,15679,15791,15893,15986,16069,16143,16207,16261, - 16305,16340,16364,16379,16384,16379,16364,16340,16305,16261, - 16207,16143,16069,15986,15893,15791,15679,15557,15426,15286, - 15137,14978,14811,14635,14449,14256,14053,13842,13623,13395, - 13160,12916,12665,12406,12140,11866,11585,11297,11003,10702, - 10394,10080,9760,9434,9102,8765,8423,8076,7723,7366, - 7005,6639,6270,5897,5520,5139,4756,4370,3981,3590, - 3196,2801,2404,2006,1606,1205,804,402,0,-402, - -804,-1205,-1606,-2006,-2404,-2801,-3196,-3590,-3981,-4370, - -4756,-5139,-5520,-5897,-6270,-6639,-7005,-7366,-7723,-8076, - -8423,-8765,-9102,-9434,-9760,-10080,-10394,-10702,-11003,-11297, - -11585,-11866,-12140,-12406,-12665,-12916,-13160,-13395,-13623,-13842, - -14053,-14256,-14449,-14635,-14811,-14978,-15137,-15286,-15426,-15557, - -15679,-15791,-15893,-15986,-16069,-16143,-16207,-16261,-16305,-16340, - -16364,-16379,-16384,-16379,-16364,-16340,-16305,-16261,-16207,-16143, - -16069,-15986,-15893,-15791,-15679,-15557,-15426,-15286,-15137,-14978, - -14811,-14635,-14449,-14256,-14053,-13842,-13623,-13395,-13160,-12916, - -12665,-12406,-12140,-11866,-11585,-11297,-11003,-10702,-10394,-10080, - -9760,-9434,-9102,-8765,-8423,-8076,-7723,-7366,-7005,-6639, - -6270,-5897,-5520,-5139,-4756,-4370,-3981,-3590,-3196,-2801, - -2404,-2006,-1606,-1205,-804,-402 -}; - -short grub_trig_costab[] = -{ - 16384,16379,16364,16340,16305,16261,16207,16143,16069,15986, - 15893,15791,15679,15557,15426,15286,15137,14978,14811,14635, - 14449,14256,14053,13842,13623,13395,13160,12916,12665,12406, - 12140,11866,11585,11297,11003,10702,10394,10080,9760,9434, - 9102,8765,8423,8076,7723,7366,7005,6639,6270,5897, - 5520,5139,4756,4370,3981,3590,3196,2801,2404,2006, - 1606,1205,804,402,0,-402,-804,-1205,-1606,-2006, - -2404,-2801,-3196,-3590,-3981,-4370,-4756,-5139,-5520,-5897, - -6270,-6639,-7005,-7366,-7723,-8076,-8423,-8765,-9102,-9434, - -9760,-10080,-10394,-10702,-11003,-11297,-11585,-11866,-12140,-12406, - -12665,-12916,-13160,-13395,-13623,-13842,-14053,-14256,-14449,-14635, - -14811,-14978,-15137,-15286,-15426,-15557,-15679,-15791,-15893,-15986, - -16069,-16143,-16207,-16261,-16305,-16340,-16364,-16379,-16384,-16379, - -16364,-16340,-16305,-16261,-16207,-16143,-16069,-15986,-15893,-15791, - -15679,-15557,-15426,-15286,-15137,-14978,-14811,-14635,-14449,-14256, - -14053,-13842,-13623,-13395,-13160,-12916,-12665,-12406,-12140,-11866, - -11585,-11297,-11003,-10702,-10394,-10080,-9760,-9434,-9102,-8765, - -8423,-8076,-7723,-7366,-7005,-6639,-6270,-5897,-5520,-5139, - -4756,-4370,-3981,-3590,-3196,-2801,-2404,-2006,-1606,-1205, - -804,-402,0,402,804,1205,1606,2006,2404,2801, - 3196,3590,3981,4370,4756,5139,5520,5897,6270,6639, - 7005,7366,7723,8076,8423,8765,9102,9434,9760,10080, - 10394,10702,11003,11297,11585,11866,12140,12406,12665,12916, - 13160,13395,13623,13842,14053,14256,14449,14635,14811,14978, - 15137,15286,15426,15557,15679,15791,15893,15986,16069,16143, - 16207,16261,16305,16340,16364,16379 -}; - diff --git a/maintainance/gentrigtables.py b/maintainance/gentrigtables.py deleted file mode 100644 index 81b7bd058..000000000 --- a/maintainance/gentrigtables.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/python -# Script to generate trigonometric function tables. -# -# 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 . - -from math import * -from sys import stdout - -def write(x): - stdout.write(x) - -def writeTable(arr, name): - indent = ' ' * 4 - write("short ") - write(name) - write("[] =\n{\n") - write(indent) - for i in range(len(arr)): - if i != 0: - write(",") - if i % 10 == 0: - write("\n") - write(indent) - write("%d" % arr[i]) - write("\n};\n") - -def main(): - sintab = [] - costab = [] - angle_max = 256 - fraction_scale = 16384 - for i in range(angle_max): - # Convert to an angle in 1/256 of a circle. - x = i * 2 * pi / angle_max - sintab.append(int(round(sin(x) * fraction_scale))) - costab.append(int(round(cos(x) * fraction_scale))) - - write("#define TRIG_ANGLE_MAX " + str (angle_max) + "\n") - write("#define TRIG_FRACTION_SCALE " + str (fraction_scale) + "\n") - writeTable(sintab, "sintab") - writeTable(costab, "costab") - -if __name__ == "__main__": - main() - -# vim:ai et sw=4 ts=4 From a5c894bcd986b2ad3bba9d17d732d5542b39e168 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 24 Nov 2009 04:19:33 +0100 Subject: [PATCH 023/237] Enable gfxmenu on grub-emu --- conf/any-emu.rmk | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 82e297986..d79ec542b 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -45,6 +45,14 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ video/readers/jpeg.c video/readers/png.c font/font_cmd.c \ font/font.c term/gfxterm.c io/bufio.c \ \ + gfxmenu/gfxmenu.c gfxmenu/model.c gfxmenu/view.c \ + gfxmenu/icon_manager.c gfxmenu/theme_loader.c \ + gfxmenu/widget-box.c gfxmenu/gui_canvas.c \ + gfxmenu/gui_circular_progress.c gfxmenu/gui_box.c \ + gfxmenu/gui_label.c gfxmenu/gui_list.c gfxmenu/gui_image.c \ + gfxmenu/gui_progress_bar.c gfxmenu/gui_util.c \ + gfxmenu/gui_string_util.c gfxmenu/named_colors.c trigtables.c \ + \ util/console.c util/hostfs.c util/grub-emu.c util/misc.c \ util/hostdisk.c util/getroot.c \ \ @@ -87,6 +95,13 @@ DISTCLEANFILES += grub_emu_init.c # FIXME: this could be shared with common.rmk +trigtables.c: gentrigtables + ./gentrigtables > $@ +DISTCLEANFILES += trigtables.c +gentrigtables: gentrigtables.c + $(CC) -o $@ $^ $(CPPFLAGS) -lm +DISTCLEANFILES += gentrigtables + # For grub-mkfont. ifeq ($(enable_grub_mkfont), yes) bin_UTILITIES += grub-mkfont From a9c12f853332e801a4a300ace7fadfc8d9d5738f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 24 Nov 2009 04:20:18 +0100 Subject: [PATCH 024/237] Remove hardcoded hotkeys --- gfxmenu/gfxmenu.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/gfxmenu/gfxmenu.c b/gfxmenu/gfxmenu.c index 85ce5879d..c854c68da 100644 --- a/gfxmenu/gfxmenu.c +++ b/gfxmenu/gfxmenu.c @@ -92,26 +92,6 @@ process_key_press (int c, switch_to_text_menu (); *should_exit = 1; } - else if (c == '1') - { - grub_gfxmenu_view_load_theme (view, - "/boot/grub/themes/proto/theme.txt"); - } - else if (c == '2') - { - grub_gfxmenu_view_load_theme (view, - "/boot/grub/themes/winter/theme.txt"); - } - else if (c == '3') - { - grub_gfxmenu_view_load_theme (view, - "/boot/grub/themes/ubuntu1/theme.txt"); - } - else if (c == '4') - { - grub_gfxmenu_view_load_theme (view, - "/boot/grub/themes/ubuntu2/theme.txt"); - } else if (nested && c == GRUB_TERM_ESC) { *should_exit = 1; From 8f41eb558284ffca53d8e80a98a6924b286f09ab Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 24 Nov 2009 04:21:07 +0100 Subject: [PATCH 025/237] Use return instead of exit () in gentrigtables.c --- gentrigtables.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gentrigtables.c b/gentrigtables.c index 3ef6d08f7..772cd6224 100644 --- a/gentrigtables.c +++ b/gentrigtables.c @@ -44,5 +44,5 @@ main () TAB(sin); TAB(cos); - exit (0); + return 0; } From 93fd2dd8095288fd823b746a30a3f8430d9c11fd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 24 Nov 2009 04:22:22 +0100 Subject: [PATCH 026/237] Optimise gfxterm in gfxmenu by avoiding indirect repainting --- gfxmenu/view.c | 93 +++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/gfxmenu/view.c b/gfxmenu/view.c index 56edc86cf..e807d3838 100644 --- a/gfxmenu/view.c +++ b/gfxmenu/view.c @@ -42,6 +42,8 @@ status changes. */ #define TIMEOUT_COMPONENT_ID "__timeout__" +static grub_gfxmenu_view_t term_view; + static void init_terminal (grub_gfxmenu_view_t view); static void destroy_terminal (void); static grub_err_t set_graphics_mode (void); @@ -310,86 +312,82 @@ set_text_mode (void) static int term_target_width; static int term_target_height; -static struct grub_video_render_target *term_target; static int term_initialized; static grub_term_output_t term_original; -static grub_gfxmenu_view_t term_view; static void -repaint_terminal (int x __attribute ((unused)), - int y __attribute ((unused)), - int width __attribute ((unused)), - int height __attribute ((unused))) +draw_terminal_box (void) { - if (! term_view) + grub_gfxmenu_box_t term_box; + int termx; + int termy; + + term_box = term_view->terminal_box; + if (!term_box) return; - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); - grub_gfxmenu_view_draw (term_view); - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); - - int termx = term_view->screen.x - + term_view->screen.width * (10 - 7) / 10 / 2; - int termy = term_view->screen.y - + term_view->screen.height * (10 - 7) / 10 / 2; - - grub_gfxmenu_box_t term_box = term_view->terminal_box; - if (term_box) - { - term_box->set_content_size (term_box, - term_target_width, term_target_height); - - term_box->draw (term_box, - termx - term_box->get_left_pad (term_box), - termy - term_box->get_top_pad (term_box)); - } - - grub_video_blit_render_target (term_target, GRUB_VIDEO_BLIT_REPLACE, - termx, termy, - 0, 0, term_target_width, term_target_height); - grub_video_swap_buffers (); + termx = term_view->screen.x + term_view->screen.width * (10 - 7) / 10 / 2; + termy = term_view->screen.y + term_view->screen.height * (10 - 7) / 10 / 2; + + term_box->set_content_size (term_box, term_target_width, + term_target_height); + + term_box->draw (term_box, + termx - term_box->get_left_pad (term_box), + termy - term_box->get_top_pad (term_box)); } static void init_terminal (grub_gfxmenu_view_t view) { + int termx; + int termy; + struct grub_video_mode_info mode_info; + grub_err_t err; + int double_repaint; + term_original = grub_term_get_current_output (); term_target_width = view->screen.width * 7 / 10; term_target_height = view->screen.height * 7 / 10; - grub_video_create_render_target (&term_target, - term_target_width, - term_target_height, - GRUB_VIDEO_MODE_TYPE_RGB - | GRUB_VIDEO_MODE_TYPE_ALPHA); - if (grub_errno != GRUB_ERR_NONE) - return; + termx = view->screen.x + view->screen.width * (10 - 7) / 10 / 2; + termy = view->screen.y + view->screen.height * (10 - 7) / 10 / 2; + + err = grub_video_get_info (&mode_info); + if (err) + { + grub_errno = GRUB_ERR_NONE; + double_repaint = 1; + } + else + double_repaint = (mode_info.mode_type + & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED) + && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); /* Note: currently there is no API for changing the gfxterm font on the fly, so whatever font the initially loaded theme specifies will be permanent. */ - grub_gfxterm_init_window (term_target, 0, 0, - term_target_width, term_target_height, 0, - view->terminal_font_name, 3); + grub_gfxterm_init_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY, termx, termy, + term_target_width, term_target_height, + double_repaint, view->terminal_font_name, 3); if (grub_errno != GRUB_ERR_NONE) return; term_initialized = 1; - /* XXX: store static pointer to the 'view' object so the repaint callback can access it. */ + grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + grub_gfxmenu_view_draw (view); + grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + term_view = view; - grub_gfxterm_set_repaint_callback (repaint_terminal); + grub_term_set_current_output (grub_gfxterm_get_term ()); } static void destroy_terminal (void) { - term_view = 0; if (term_initialized) grub_gfxterm_destroy_window (); - grub_gfxterm_set_repaint_callback (0); - if (term_target) - grub_video_delete_render_target (term_target); if (term_original) grub_term_set_current_output (term_original); } @@ -493,5 +491,6 @@ grub_gfxmenu_view_execute_entry (grub_gfxmenu_view_t view, void grub_gfxmenu_view_run_terminal (grub_gfxmenu_view_t view __attribute__((unused))) { + draw_terminal_box (); grub_cmdline_run (1); } From 4545f150f38e536b38d54f2a578671f578918fcf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 24 Nov 2009 05:02:30 +0100 Subject: [PATCH 027/237] Various cleanups --- gfxmenu/gfxmenu.c | 113 +++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 51 deletions(-) diff --git a/gfxmenu/gfxmenu.c b/gfxmenu/gfxmenu.c index c854c68da..6f7382c18 100644 --- a/gfxmenu/gfxmenu.c +++ b/gfxmenu/gfxmenu.c @@ -51,50 +51,63 @@ process_key_press (int c, /* When a key is pressed, stop the timeout. */ grub_gfxmenu_model_clear_timeout (model); - if (c == 'j' || c == GRUB_TERM_DOWN) - { - int i = grub_gfxmenu_model_get_selected_index (model); - int num_items = grub_gfxmenu_model_get_num_entries (model); - if (i < num_items - 1) - { - i++; - grub_gfxmenu_model_set_selected_index (model, i); - } - } - else if (c == 'k' || c == GRUB_TERM_UP) - { - int i = grub_gfxmenu_model_get_selected_index (model); - if (i > 0) - { - i--; - grub_gfxmenu_model_set_selected_index (model, i); - } - } - else if (c == '\r' || c == '\n' || c == GRUB_TERM_RIGHT) - { - int selected = grub_gfxmenu_model_get_selected_index (model); - int num_entries = grub_gfxmenu_model_get_num_entries (model); - if (selected >= 0 && selected < num_entries) - { - grub_menu_entry_t entry = - grub_gfxmenu_model_get_entry (model, selected); - grub_gfxmenu_view_execute_entry (view, entry); - } - } - else if (c == 'c') + switch (c) { + case 'j': + case GRUB_TERM_DOWN: + { + int i = grub_gfxmenu_model_get_selected_index (model); + int num_items = grub_gfxmenu_model_get_num_entries (model); + if (i < num_items - 1) + { + i++; + grub_gfxmenu_model_set_selected_index (model, i); + } + } + break; + + case 'k': + case GRUB_TERM_UP: + { + int i = grub_gfxmenu_model_get_selected_index (model); + if (i > 0) + { + i--; + grub_gfxmenu_model_set_selected_index (model, i); + } + } + break; + + case '\r': + case '\n': + case GRUB_TERM_RIGHT: + { + int selected = grub_gfxmenu_model_get_selected_index (model); + int num_entries = grub_gfxmenu_model_get_num_entries (model); + if (selected >= 0 && selected < num_entries) + { + grub_menu_entry_t entry = + grub_gfxmenu_model_get_entry (model, selected); + grub_gfxmenu_view_execute_entry (view, entry); + } + } + break; + + case 'c': grub_gfxmenu_view_run_terminal (view); - } - else if (c == 't') - { + break; + + case 't': /* The write hook for 'menuviewer' will cause * grub_menu_viewer_should_return to return nonzero. */ switch_to_text_menu (); *should_exit = 1; - } - else if (nested && c == GRUB_TERM_ESC) - { - *should_exit = 1; + break; + + case GRUB_TERM_ESC: + if (nested) + *should_exit = 1; + break; } if (grub_errno != GRUB_ERR_NONE) @@ -119,32 +132,29 @@ static grub_err_t show_menu (grub_menu_t menu, int nested) { grub_gfxmenu_model_t model; + grub_gfxmenu_view_t view; + const char *theme_path; + + theme_path = grub_env_get ("theme"); + if (! theme_path) + { + switch_to_text_menu (); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "no theme specified"); + } model = grub_gfxmenu_model_new (menu); if (! model) { - grub_print_error (); - grub_printf ("Initializing menu data for graphical menu failed;\n" - "falling back to text based menu.\n"); - grub_wait_after_message (); switch_to_text_menu (); return grub_errno; } - grub_gfxmenu_view_t view; - /* Create the view. */ - const char *theme_path = grub_env_get ("theme"); - if (! theme_path) - theme_path = "/boot/grub/themes/proto/theme.txt"; - view = grub_gfxmenu_view_new (theme_path, model); + if (! view) { grub_print_error (); - grub_printf ("Starting graphical menu failed;\n" - "falling back to text based menu.\n"); - grub_wait_after_message (); grub_gfxmenu_model_destroy (model); switch_to_text_menu (); return grub_errno; @@ -159,6 +169,7 @@ show_menu (grub_menu_t menu, int nested) /* Main event loop. */ int exit_requested = 0; + while ((! exit_requested) && (! grub_menu_viewer_should_return ())) { if (grub_gfxmenu_model_timeout_expired (model)) From 947fa16c8b8bf6a0f91ca7b01da8c47f8cc9361c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 24 Nov 2009 07:17:18 +0100 Subject: [PATCH 028/237] Important speedup by not redrawing too much --- gfxmenu/gfxmenu.c | 12 +- gfxmenu/gui_box.c | 4 +- gfxmenu/gui_canvas.c | 5 +- gfxmenu/gui_circular_progress.c | 6 +- gfxmenu/gui_image.c | 8 +- gfxmenu/gui_label.c | 5 +- gfxmenu/gui_list.c | 6 +- gfxmenu/gui_progress_bar.c | 4 +- gfxmenu/view.c | 214 +++++++++++++++++++++++--------- include/grub/gfxmenu_view.h | 14 +++ include/grub/gui.h | 16 ++- 11 files changed, 221 insertions(+), 73 deletions(-) diff --git a/gfxmenu/gfxmenu.c b/gfxmenu/gfxmenu.c index 6f7382c18..ab1c8befb 100644 --- a/gfxmenu/gfxmenu.c +++ b/gfxmenu/gfxmenu.c @@ -35,6 +35,7 @@ #include #include #include +#include static void switch_to_text_menu (void) { @@ -62,6 +63,7 @@ process_key_press (int c, { i++; grub_gfxmenu_model_set_selected_index (model, i); + grub_gfxmenu_redraw_menu (view); } } break; @@ -74,6 +76,7 @@ process_key_press (int c, { i--; grub_gfxmenu_model_set_selected_index (model, i); + grub_gfxmenu_redraw_menu (view); } } break; @@ -170,8 +173,14 @@ show_menu (grub_menu_t menu, int nested) /* Main event loop. */ int exit_requested = 0; + grub_gfxmenu_view_draw (view); + grub_video_swap_buffers (); + if (view->double_repaint) + grub_gfxmenu_view_draw (view); + while ((! exit_requested) && (! grub_menu_viewer_should_return ())) { + grub_gfxmenu_redraw_timeout (view); if (grub_gfxmenu_model_timeout_expired (model)) { grub_gfxmenu_model_clear_timeout (model); @@ -181,9 +190,8 @@ show_menu (grub_menu_t menu, int nested) continue; } - grub_gfxmenu_view_draw (view); - grub_video_swap_buffers (); handle_key_events (model, view, nested, &exit_requested); + grub_cpu_idle (); } grub_gfxmenu_view_destroy (view); diff --git a/gfxmenu/gui_box.c b/gfxmenu/gui_box.c index 876d0733f..4fe131f98 100644 --- a/gfxmenu/gui_box.c +++ b/gfxmenu/gui_box.c @@ -166,7 +166,7 @@ layout_vertically (grub_gui_box_t self, int modify_layout, } static void -box_paint (void *vself) +box_paint (void *vself, const grub_video_rect_t *region) { grub_gui_box_t self = vself; struct component_node *cur; @@ -176,7 +176,7 @@ box_paint (void *vself) for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) { grub_gui_component_t comp = cur->component; - comp->ops->paint (comp); + comp->ops->paint (comp, region); } grub_gui_restore_viewport (&vpsave); } diff --git a/gfxmenu/gui_canvas.c b/gfxmenu/gui_canvas.c index a2cd77df6..d155364d7 100644 --- a/gfxmenu/gui_canvas.c +++ b/gfxmenu/gui_canvas.c @@ -79,7 +79,7 @@ canvas_is_instance (void *vself __attribute__((unused)), const char *type) } static void -canvas_paint (void *vself) +canvas_paint (void *vself, const grub_video_rect_t *region) { grub_gui_canvas_t self = vself; struct component_node *cur; @@ -106,7 +106,8 @@ canvas_paint (void *vself) } /* Paint the child. */ - comp->ops->paint (comp); + if (grub_video_have_common_points (region, &r)) + comp->ops->paint (comp, region); } grub_gui_restore_viewport (&vpsave); } diff --git a/gfxmenu/gui_circular_progress.c b/gfxmenu/gui_circular_progress.c index cd95c51f9..f3c8bc3af 100644 --- a/gfxmenu/gui_circular_progress.c +++ b/gfxmenu/gui_circular_progress.c @@ -112,12 +112,16 @@ check_pixmaps (circular_progress_t self) } static void -circprog_paint (void *vself) +circprog_paint (void *vself, const grub_video_rect_t *region) { circular_progress_t self = vself; if (! self->visible) return; + + if (!grub_video_have_common_points (region, &self->bounds)) + return; + if (! check_pixmaps (self)) return; diff --git a/gfxmenu/gui_image.c b/gfxmenu/gui_image.c index 1c58a535b..eb2ff1ee0 100644 --- a/gfxmenu/gui_image.c +++ b/gfxmenu/gui_image.c @@ -67,12 +67,16 @@ image_is_instance (void *vself __attribute__((unused)), const char *type) } static void -image_paint (void *vself) +image_paint (void *vself, const grub_video_rect_t *region) { grub_gui_image_t self = vself; + grub_video_rect_t vpsave; + if (! self->bitmap) return; - grub_video_rect_t vpsave; + if (!grub_video_have_common_points (region, &self->bounds)) + return; + grub_gui_set_viewport (&self->bounds, &vpsave); grub_video_blit_bitmap (self->bitmap, GRUB_VIDEO_BLIT_BLEND, 0, 0, 0, 0, diff --git a/gfxmenu/gui_label.c b/gfxmenu/gui_label.c index eb2a495ff..30474f52f 100644 --- a/gfxmenu/gui_label.c +++ b/gfxmenu/gui_label.c @@ -77,13 +77,16 @@ label_is_instance (void *vself __attribute__((unused)), const char *type) } static void -label_paint (void *vself) +label_paint (void *vself, const grub_video_rect_t *region) { grub_gui_label_t self = vself; if (! self->visible) return; + if (!grub_video_have_common_points (region, &self->bounds)) + return; + /* Calculate the starting x coordinate. */ int left_x; if (self->align == align_left) diff --git a/gfxmenu/gui_list.c b/gfxmenu/gui_list.c index aa9655b45..bf6d94657 100644 --- a/gfxmenu/gui_list.c +++ b/gfxmenu/gui_list.c @@ -311,16 +311,18 @@ draw_menu (list_impl_t self) } static void -list_paint (void *vself) +list_paint (void *vself, const grub_video_rect_t *region) { list_impl_t self = vself; + grub_video_rect_t vpsave; if (! self->visible) return; + if (!grub_video_have_common_points (region, &self->bounds)) + return; check_boxes (self); - grub_video_rect_t vpsave; grub_gui_set_viewport (&self->bounds, &vpsave); draw_menu (self); grub_gui_restore_viewport (&vpsave); diff --git a/gfxmenu/gui_progress_bar.c b/gfxmenu/gui_progress_bar.c index 440d4b2fc..498711169 100644 --- a/gfxmenu/gui_progress_bar.c +++ b/gfxmenu/gui_progress_bar.c @@ -171,11 +171,13 @@ draw_text (grub_gui_progress_bar_t self) } static void -progress_bar_paint (void *vself) +progress_bar_paint (void *vself, const grub_video_rect_t *region) { grub_gui_progress_bar_t self = vself; if (! self->visible) return; + if (!grub_video_have_common_points (region, &self->bounds)) + return; grub_video_rect_t vpsave; grub_gui_set_viewport (&self->bounds, &vpsave); diff --git a/gfxmenu/view.c b/gfxmenu/view.c index e807d3838..1c512fee1 100644 --- a/gfxmenu/view.c +++ b/gfxmenu/view.c @@ -55,6 +55,8 @@ grub_gfxmenu_view_t grub_gfxmenu_view_new (const char *theme_path, grub_gfxmenu_model_t model) { grub_gfxmenu_view_t view; + grub_err_t err; + struct grub_video_mode_info mode_info; view = grub_malloc (sizeof (*view)); if (! view) @@ -67,6 +69,18 @@ grub_gfxmenu_view_new (const char *theme_path, grub_gfxmenu_model_t model) (unsigned *) &view->screen.width, (unsigned *) &view->screen.height); + err = grub_video_get_info (&mode_info); + if (err) + { + grub_free (view); + return 0; + } + else + view->double_repaint = (mode_info.mode_type + & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED) + && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); + + /* Clear the screen; there may be garbage left over in video memory, and loading the menu style (particularly the background) can take a while. */ grub_video_fill_rect (grub_video_map_rgb (0, 0, 0), @@ -97,6 +111,15 @@ grub_gfxmenu_view_new (const char *theme_path, grub_gfxmenu_model_t model) view->title_text = grub_strdup ("GRUB Boot Menu"); view->progress_message_text = 0; view->theme_path = 0; + view->last_seconds_remaining = -2; + + /* Set the timeout bar's frame. */ + view->progress_message_frame.width = view->screen.width * 4 / 5; + view->progress_message_frame.height = 50; + view->progress_message_frame.x = view->screen.x + + (view->screen.width - view->progress_message_frame.width) / 2; + view->progress_message_frame.y = view->screen.y + + view->screen.height - 90 - 20 - view->progress_message_frame.height; if (grub_gfxmenu_view_load_theme (view, theme_path) != 0) { @@ -141,21 +164,23 @@ set_progress_message (grub_gfxmenu_view_t view, const char *message) } static void -draw_background (grub_gfxmenu_view_t view) +redraw_background (grub_gfxmenu_view_t view, + const grub_video_rect_t *bounds) { if (view->desktop_image) { struct grub_video_bitmap *img = view->desktop_image; grub_video_blit_bitmap (img, GRUB_VIDEO_BLIT_REPLACE, - view->screen.x, view->screen.y, 0, 0, - grub_video_bitmap_get_width (img), - grub_video_bitmap_get_height (img)); + bounds->x, bounds->y, + bounds->x - view->screen.x, + bounds->y - view->screen.y, + bounds->width, bounds->height); } else { grub_video_fill_rect (grub_gui_map_color (view->desktop_color), - view->screen.x, view->screen.y, - view->screen.width, view->screen.height); + bounds->x, bounds->y, + bounds->width, bounds->height); } } @@ -191,6 +216,7 @@ update_timeout_visit (grub_gui_component_t component, { struct progress_value_data *pv; pv = (struct progress_value_data *) userdata; + component->ops->set_property (component, "visible", pv->visible); component->ops->set_property (component, "start", pv->start); component->ops->set_property (component, "end", pv->end); @@ -198,16 +224,43 @@ update_timeout_visit (grub_gui_component_t component, component->ops->set_property (component, "text", pv->text); } -static void -update_timeout (grub_gfxmenu_view_t view) + +static inline void +update_timeout (grub_gfxmenu_view_t view, int is_init) { char startbuf[20]; char valuebuf[20]; char msgbuf[120]; - int timeout = grub_gfxmenu_model_get_timeout_ms (view->model); - int remaining = grub_gfxmenu_model_get_timeout_remaining_ms (view->model); + int timeout; + int remaining; struct progress_value_data pv; + int seconds_remaining_rounded_up; + + auto void redraw_timeout_visit (grub_gui_component_t component, + void *userdata __attribute__ ((unused))); + + auto void redraw_timeout_visit (grub_gui_component_t component, + void *userdata __attribute__ ((unused))) + { + grub_video_rect_t bounds; + component->ops->get_bounds (component, &bounds); + grub_gfxmenu_view_redraw (view, &bounds); + } + + timeout = grub_gfxmenu_model_get_timeout_ms (view->model); + if (timeout > 0) + { + remaining = grub_gfxmenu_model_get_timeout_remaining_ms (view->model); + seconds_remaining_rounded_up = (remaining + 999) / 1000; + } + else + seconds_remaining_rounded_up = -1; + + if (view->last_seconds_remaining == seconds_remaining_rounded_up && !is_init) + return; + + view->last_seconds_remaining = seconds_remaining_rounded_up; pv.visible = timeout > 0 ? "true" : "false"; grub_sprintf (startbuf, "%d", -timeout); @@ -216,7 +269,6 @@ update_timeout (grub_gfxmenu_view_t view) grub_sprintf (valuebuf, "%d", remaining > 0 ? -remaining : 0); pv.value = valuebuf; - int seconds_remaining_rounded_up = (remaining + 999) / 1000; grub_sprintf (msgbuf, "The highlighted entry will be booted automatically in %d s.", seconds_remaining_rounded_up); @@ -224,6 +276,21 @@ update_timeout (grub_gfxmenu_view_t view) grub_gui_find_by_id ((grub_gui_component_t) view->canvas, TIMEOUT_COMPONENT_ID, update_timeout_visit, &pv); + if (!is_init) + { + grub_gui_find_by_id ((grub_gui_component_t) view->canvas, + TIMEOUT_COMPONENT_ID, redraw_timeout_visit, &pv); + grub_video_swap_buffers (); + if (view->double_repaint) + grub_gui_find_by_id ((grub_gui_component_t) view->canvas, + TIMEOUT_COMPONENT_ID, redraw_timeout_visit, &pv); + } +} + +void +grub_gfxmenu_redraw_timeout (grub_gfxmenu_view_t view) +{ + update_timeout (view, 0); } static void @@ -252,19 +319,13 @@ static void draw_message (grub_gfxmenu_view_t view) { char *text = view->progress_message_text; + grub_video_rect_t f = view->progress_message_frame; if (! text) return; grub_font_t font = view->message_font; grub_video_color_t color = grub_gui_map_color (view->message_color); - /* Set the timeout bar's frame. */ - grub_video_rect_t f; - f.width = view->screen.width * 4 / 5; - f.height = 50; - f.x = view->screen.x + (view->screen.width - f.width) / 2; - f.y = view->screen.y + view->screen.height - 90 - 20 - f.height; - /* Border. */ grub_video_fill_rect (color, f.x-1, f.y-1, f.width+2, f.height+2); @@ -280,19 +341,62 @@ draw_message (grub_gfxmenu_view_t view) grub_font_draw_string (text, font, color, x, y); } +void +grub_gfxmenu_view_redraw (grub_gfxmenu_view_t view, + const grub_video_rect_t *region) +{ + grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + + redraw_background (view, region); + if (view->canvas) + view->canvas->ops->component.paint (view->canvas, region); + draw_title (view); + if (grub_video_have_common_points (&view->progress_message_frame, region)) + draw_message (view); +} void grub_gfxmenu_view_draw (grub_gfxmenu_view_t view) { - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); - update_timeout (view); + update_timeout (view, 1); update_menu_components (view); - draw_background (view); - if (view->canvas) - view->canvas->ops->component.paint (view->canvas); - draw_title (view); - draw_message (view); + grub_gfxmenu_view_redraw (view, &view->screen); + grub_video_swap_buffers (); + if (view->double_repaint) + grub_gfxmenu_view_redraw (view, &view->screen); +} + +static void +redraw_menu_visit (grub_gui_component_t component, + void *userdata) +{ + grub_gfxmenu_view_t view; + view = userdata; + if (component->ops->is_instance (component, "list")) + { + grub_gui_list_t list; + grub_video_rect_t bounds; + + list = (grub_gui_list_t) component; + component->ops->get_bounds (component, &bounds); + grub_gfxmenu_view_redraw (view, &bounds); + } +} + +void +grub_gfxmenu_redraw_menu (grub_gfxmenu_view_t view) +{ + update_menu_components (view); + + grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas, + redraw_menu_visit, view); + grub_video_swap_buffers (); + if (view->double_repaint) + { + grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas, + redraw_menu_visit, view); + } } static grub_err_t @@ -316,7 +420,7 @@ static int term_initialized; static grub_term_output_t term_original; static void -draw_terminal_box (void) +draw_terminal_box (grub_gfxmenu_view_t view) { grub_gfxmenu_box_t term_box; int termx; @@ -335,6 +439,11 @@ draw_terminal_box (void) term_box->draw (term_box, termx - term_box->get_left_pad (term_box), termy - term_box->get_top_pad (term_box)); + grub_video_swap_buffers (); + if (view->double_repaint) + term_box->draw (term_box, + termx - term_box->get_left_pad (term_box), + termy - term_box->get_top_pad (term_box)); } static void @@ -342,9 +451,6 @@ init_terminal (grub_gfxmenu_view_t view) { int termx; int termy; - struct grub_video_mode_info mode_info; - grub_err_t err; - int double_repaint; term_original = grub_term_get_current_output (); @@ -354,34 +460,20 @@ init_terminal (grub_gfxmenu_view_t view) termx = view->screen.x + view->screen.width * (10 - 7) / 10 / 2; termy = view->screen.y + view->screen.height * (10 - 7) / 10 / 2; - err = grub_video_get_info (&mode_info); - if (err) - { - grub_errno = GRUB_ERR_NONE; - double_repaint = 1; - } - else - double_repaint = (mode_info.mode_type - & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED) - && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); - /* Note: currently there is no API for changing the gfxterm font on the fly, so whatever font the initially loaded theme specifies will be permanent. */ grub_gfxterm_init_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY, termx, termy, term_target_width, term_target_height, - double_repaint, view->terminal_font_name, 3); + view->double_repaint, view->terminal_font_name, 3); if (grub_errno != GRUB_ERR_NONE) return; term_initialized = 1; - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); - grub_gfxmenu_view_draw (view); - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); - term_view = view; grub_term_set_current_output (grub_gfxterm_get_term ()); + grub_refresh (); } static void destroy_terminal (void) @@ -405,8 +497,10 @@ notify_booting (grub_menu_entry_t entry, void *userdata) grub_sprintf (s, "Booting '%s'", entry->title); set_progress_message (view, s); grub_free (s); - grub_gfxmenu_view_draw (view); + grub_gfxmenu_view_redraw (view, &view->progress_message_frame); grub_video_swap_buffers (); + if (view->double_repaint) + grub_gfxmenu_view_redraw (view, &view->progress_message_frame); } static void @@ -421,8 +515,10 @@ notify_fallback (grub_menu_entry_t entry, void *userdata) grub_sprintf (s, "Falling back to '%s'", entry->title); set_progress_message (view, s); grub_free (s); - grub_gfxmenu_view_draw (view); + grub_gfxmenu_view_redraw (view, &view->progress_message_frame); grub_video_swap_buffers (); + if (view->double_repaint) + grub_gfxmenu_view_redraw (view, &view->progress_message_frame); } static void @@ -442,6 +538,8 @@ int grub_gfxmenu_view_execute_with_fallback (grub_gfxmenu_view_t view, grub_menu_entry_t entry) { + draw_terminal_box (view); + grub_menu_execute_with_fallback (grub_gfxmenu_model_get_menu (view->model), entry, &execute_callback, (void *) view); @@ -453,7 +551,6 @@ grub_gfxmenu_view_execute_with_fallback (grub_gfxmenu_view_t view, "Unable to automatically boot. " "Press SPACE to continue."); grub_gfxmenu_view_draw (view); - grub_video_swap_buffers (); while (GRUB_TERM_ASCII_CHAR(grub_getkey ()) != ' ') { /* Wait for SPACE to be pressed. */ @@ -461,6 +558,11 @@ grub_gfxmenu_view_execute_with_fallback (grub_gfxmenu_view_t view, set_progress_message (view, 0); /* Clear the message. */ + grub_gfxmenu_view_redraw (view, &view->progress_message_frame); + grub_video_swap_buffers (); + if (view->double_repaint) + grub_gfxmenu_view_redraw (view, &view->progress_message_frame); + return 1; /* Ok. */ } @@ -468,14 +570,7 @@ int grub_gfxmenu_view_execute_entry (grub_gfxmenu_view_t view, grub_menu_entry_t entry) { - /* Currently we switch back to text mode by restoring - the original terminal before executing the menu entry. - It is hard to make it work when executing a menu entry - that switches video modes -- it using gfxterm in a - window, the repaint callback seems to crash GRUB. */ - /* TODO: Determine if this works when 'gfxterm' was set as - the current terminal before invoking the gfxmenu. */ - destroy_terminal (); + draw_terminal_box (view); grub_menu_execute_entry (entry); if (grub_errno != GRUB_ERR_NONE) @@ -484,13 +579,14 @@ grub_gfxmenu_view_execute_entry (grub_gfxmenu_view_t view, if (set_graphics_mode () != GRUB_ERR_NONE) return 0; /* Failure. */ - init_terminal (view); + grub_gfxmenu_view_draw (view); return 1; /* Ok. */ } void -grub_gfxmenu_view_run_terminal (grub_gfxmenu_view_t view __attribute__((unused))) +grub_gfxmenu_view_run_terminal (grub_gfxmenu_view_t view) { - draw_terminal_box (); + draw_terminal_box (view); grub_cmdline_run (1); + grub_gfxmenu_view_draw (view); } diff --git a/include/grub/gfxmenu_view.h b/include/grub/gfxmenu_view.h index 1144382f2..c86334400 100644 --- a/include/grub/gfxmenu_view.h +++ b/include/grub/gfxmenu_view.h @@ -54,7 +54,15 @@ int grub_gfxmenu_view_execute_entry (grub_gfxmenu_view_t view, void grub_gfxmenu_view_run_terminal (grub_gfxmenu_view_t view); +void +grub_gfxmenu_redraw_menu (grub_gfxmenu_view_t view); +void +grub_gfxmenu_redraw_timeout (grub_gfxmenu_view_t view); + +void +grub_gfxmenu_view_redraw (grub_gfxmenu_view_t view, + const grub_video_rect_t *region); /* Implementation details -- this should not be used outside of the view itself. */ @@ -86,6 +94,12 @@ struct grub_gfxmenu_view grub_gui_container_t canvas; grub_gfxmenu_model_t model; + + int last_seconds_remaining; + + int double_repaint; + + grub_video_rect_t progress_message_frame; }; #endif /* ! GRUB_GFXMENU_VIEW_HEADER */ diff --git a/include/grub/gui.h b/include/grub/gui.h index 5b785dbb5..385c0962b 100644 --- a/include/grub/gui.h +++ b/include/grub/gui.h @@ -50,13 +50,14 @@ struct grub_gui_component_ops void (*destroy) (void *self); const char * (*get_id) (void *self); int (*is_instance) (void *self, const char *type); - void (*paint) (void *self); + void (*paint) (void *self, const grub_video_rect_t *bounds); void (*set_parent) (void *self, grub_gui_container_t parent); grub_gui_container_t (*get_parent) (void *self); void (*set_bounds) (void *self, const grub_video_rect_t *bounds); void (*get_bounds) (void *self, grub_video_rect_t *bounds); void (*get_preferred_size) (void *self, int *width, int *height); grub_err_t (*set_property) (void *self, const char *name, const char *value); + void (*repaint) (void *self, int second_pass); }; struct grub_gui_container_ops @@ -162,4 +163,17 @@ grub_gui_map_color (grub_gui_color_t c) return grub_video_map_rgba (c.red, c.green, c.blue, c.alpha); } +static inline int +grub_video_have_common_points (const grub_video_rect_t *a, + const grub_video_rect_t *b) +{ + if (!((a->x <= b->x && b->x <= a->x + a->width) + || (b->x <= a->x && a->x <= b->x + b->width))) + return 0; + if (!((a->y <= b->y && b->y <= a->y + a->height) + || (b->y <= a->y && a->y <= b->y + b->height))) + return 0; + return 1; +} + #endif /* ! GRUB_GUI_H */ From f788bf3cd4a3ae22d25d305f42652651ccc962f5 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 26 Nov 2009 23:54:26 +0000 Subject: [PATCH 029/237] Add (unused) mode_mask parameter (implicitly documented in ChangeLog.videomask) --- video/efi_fb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video/efi_fb.c b/video/efi_fb.c index 2faff12f9..a4a9950b1 100644 --- a/video/efi_fb.c +++ b/video/efi_fb.c @@ -197,7 +197,7 @@ grub_video_efi_fini (void) static grub_err_t grub_video_efi_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 2fac00e6687eb0b55e7102c2d6c64a389084bc77 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 27 Nov 2009 10:20:24 +0100 Subject: [PATCH 030/237] Fixed a warning --- gfxmenu/view.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gfxmenu/view.c b/gfxmenu/view.c index 1c512fee1..7d9bb1cd0 100644 --- a/gfxmenu/view.c +++ b/gfxmenu/view.c @@ -255,7 +255,10 @@ update_timeout (grub_gfxmenu_view_t view, int is_init) seconds_remaining_rounded_up = (remaining + 999) / 1000; } else - seconds_remaining_rounded_up = -1; + { + seconds_remaining_rounded_up = -1; + remaining = -1; + } if (view->last_seconds_remaining == seconds_remaining_rounded_up && !is_init) return; From af20edb21d83d413e9721948f71e8ca2035e7d1b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 30 Nov 2009 12:51:20 +0100 Subject: [PATCH 031/237] 2009-11-30 Vladimir Serbinenko Agglomerate scrolling in gfxterm. * term/gfxterm.c (grub_virtual_screen): New member 'total_screen'. (grub_virtual_screen_setup): Initialise 'total_screen'. (write_char): Split to ... (paint_char): ... this ... (write_char): ... and this. (paint_char): Handle delayed scrolling. (draw_cursor): Likewise. (scroll_up): Split to ... (real_scroll): ... this ... (scroll_up): ... and this. (real_scroll): Handle multi-line scroll and draw below-the-bottom characters. (grub_gfxterm_refresh): Call real_scroll. --- term/gfxterm.c | 157 ++++++++++++++++++++++++++++++------------------- 1 file changed, 98 insertions(+), 59 deletions(-) diff --git a/term/gfxterm.c b/term/gfxterm.c index 5330c4ac4..be0487830 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -102,6 +102,8 @@ struct grub_virtual_screen /* Text buffer for virtual screen. Contains (columns * rows) number of entries. */ struct grub_colored_char *text_buffer; + + int total_scroll; }; struct grub_gfxterm_window @@ -225,6 +227,7 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y, virtual_screen.cursor_x = 0; virtual_screen.cursor_y = 0; virtual_screen.cursor_state = 1; + virtual_screen.total_scroll = 0; /* Calculate size of text buffer. */ virtual_screen.columns = virtual_screen.width / virtual_screen.normal_char_width; @@ -586,8 +589,8 @@ dirty_region_redraw (void) redraw_screen_rect (x, y, width, height); } -static void -write_char (void) +static inline void +paint_char (unsigned cx, unsigned cy) { struct grub_colored_char *p; struct grub_font_glyph *glyph; @@ -599,10 +602,12 @@ write_char (void) unsigned int height; unsigned int width; + if (cy + virtual_screen.total_scroll >= virtual_screen.rows) + return; + /* Find out active character. */ p = (virtual_screen.text_buffer - + virtual_screen.cursor_x - + (virtual_screen.cursor_y * virtual_screen.columns)); + + cx + (cy * virtual_screen.columns)); p -= p->index; @@ -616,8 +621,8 @@ write_char (void) color = p->fg_color; bgcolor = p->bg_color; - x = virtual_screen.cursor_x * virtual_screen.normal_char_width; - y = virtual_screen.cursor_y * virtual_screen.normal_char_height; + x = cx * virtual_screen.normal_char_width; + y = (cy + virtual_screen.total_scroll) * virtual_screen.normal_char_height; /* Render glyph to text layer. */ grub_video_set_active_render_target (text_layer); @@ -630,64 +635,58 @@ write_char (void) width, height); } -static void +static inline void +write_char (void) +{ + paint_char (virtual_screen.cursor_x, virtual_screen.cursor_y); +} + +static inline void draw_cursor (int show) { + unsigned int x; + unsigned int y; + unsigned int width; + unsigned int height; + grub_video_color_t color; + write_char (); - if (show) - { - unsigned int x; - unsigned int y; - unsigned int width; - unsigned int height; - grub_video_color_t color; + if (!show) + return; - /* Determine cursor properties and position on text layer. */ - x = virtual_screen.cursor_x * virtual_screen.normal_char_width; - width = virtual_screen.normal_char_width; - color = virtual_screen.fg_color; - y = (virtual_screen.cursor_y * virtual_screen.normal_char_height - + grub_font_get_ascent (virtual_screen.font)); - height = 2; + if (virtual_screen.cursor_y + virtual_screen.total_scroll + >= virtual_screen.rows) + return; - /* Render cursor to text layer. */ - grub_video_set_active_render_target (text_layer); - grub_video_fill_rect (color, x, y, width, height); - grub_video_set_active_render_target (render_target); - - /* Mark cursor to be redrawn. */ - dirty_region_add (virtual_screen.offset_x + x, - virtual_screen.offset_y + y, - width, height); - } + /* Determine cursor properties and position on text layer. */ + x = virtual_screen.cursor_x * virtual_screen.normal_char_width; + width = virtual_screen.normal_char_width; + color = virtual_screen.fg_color; + y = ((virtual_screen.cursor_y + virtual_screen.total_scroll) + * virtual_screen.normal_char_height + + grub_font_get_ascent (virtual_screen.font)); + height = 2; + + /* Render cursor to text layer. */ + grub_video_set_active_render_target (text_layer); + grub_video_fill_rect (color, x, y, width, height); + grub_video_set_active_render_target (render_target); + + /* Mark cursor to be redrawn. */ + dirty_region_add (virtual_screen.offset_x + x, + virtual_screen.offset_y + y, + width, height); } static void -scroll_up (void) +real_scroll (void) { - unsigned int i; + unsigned int i, j, was_scroll; grub_video_color_t color; - /* If we don't have background bitmap, remove cursor. */ - if (!bitmap) - { - /* Remove cursor. */ - draw_cursor (0); - } - - /* Scroll text buffer with one line to up. */ - grub_memmove (virtual_screen.text_buffer, - virtual_screen.text_buffer + virtual_screen.columns, - sizeof (*virtual_screen.text_buffer) - * virtual_screen.columns - * (virtual_screen.rows - 1)); - - /* Clear last line in text buffer. */ - for (i = virtual_screen.columns * (virtual_screen.rows - 1); - i < virtual_screen.columns * virtual_screen.rows; - i++) - clear_char (&(virtual_screen.text_buffer[i])); + if (!virtual_screen.total_scroll) + return; /* If we have bitmap, re-draw screen, otherwise scroll physical screen too. */ if (bitmap) @@ -695,7 +694,8 @@ scroll_up (void) /* Scroll physical screen. */ grub_video_set_active_render_target (text_layer); color = virtual_screen.bg_color; - grub_video_scroll (color, 0, -virtual_screen.normal_char_height); + grub_video_scroll (color, 0, -virtual_screen.normal_char_height + * virtual_screen.total_scroll); /* Mark virtual screen to be redrawn. */ dirty_region_add_virtualscreen (); @@ -704,6 +704,9 @@ scroll_up (void) { grub_video_rect_t saved_view; + /* Remove cursor. */ + draw_cursor (0); + grub_video_set_active_render_target (render_target); /* Save viewport and set it to our window. */ grub_video_get_viewport ((unsigned *) &saved_view.x, @@ -723,13 +726,15 @@ scroll_up (void) virtual_screen.offset_x, virtual_screen.offset_y, virtual_screen.width, - virtual_screen.normal_char_height); + virtual_screen.normal_char_height + * virtual_screen.total_scroll); grub_video_set_active_render_target (render_target); dirty_region_redraw (); /* Scroll physical screen. */ - grub_video_scroll (color, 0, -virtual_screen.normal_char_height); + grub_video_scroll (color, 0, -virtual_screen.normal_char_height + * virtual_screen.total_scroll); if (i) grub_video_swap_buffers (); @@ -739,22 +744,54 @@ scroll_up (void) /* Scroll physical screen. */ grub_video_set_active_render_target (text_layer); color = virtual_screen.bg_color; - grub_video_scroll (color, 0, -virtual_screen.normal_char_height); + grub_video_scroll (color, 0, -virtual_screen.normal_char_height + * virtual_screen.total_scroll); /* Restore saved viewport. */ grub_video_set_viewport (saved_view.x, saved_view.y, saved_view.width, saved_view.height); grub_video_set_active_render_target (render_target); - /* Draw cursor if visible. */ - if (virtual_screen.cursor_state) - draw_cursor (1); } + /* Draw cursor if visible. */ + if (virtual_screen.cursor_state) + draw_cursor (1); + + was_scroll = virtual_screen.total_scroll; + virtual_screen.total_scroll = 0; + + /* Draw shadow part. */ + for (i = virtual_screen.rows - was_scroll; + i < virtual_screen.rows; i++) + for (j = 0; j < virtual_screen.columns; j++) + paint_char (j, i); + if (repaint_callback) repaint_callback (window.x, window.y, window.width, window.height); } +static void +scroll_up (void) +{ + unsigned int i; + + /* Scroll text buffer with one line to up. */ + grub_memmove (virtual_screen.text_buffer, + virtual_screen.text_buffer + virtual_screen.columns, + sizeof (*virtual_screen.text_buffer) + * virtual_screen.columns + * (virtual_screen.rows - 1)); + + /* Clear last line in text buffer. */ + for (i = virtual_screen.columns * (virtual_screen.rows - 1); + i < virtual_screen.columns * virtual_screen.rows; + i++) + clear_char (&(virtual_screen.text_buffer[i])); + + virtual_screen.total_scroll++; +} + static void grub_gfxterm_putchar (grub_uint32_t c) { @@ -1023,6 +1060,8 @@ grub_gfxterm_setcursor (int on) static void grub_gfxterm_refresh (void) { + real_scroll (); + /* Redraw only changed regions. */ dirty_region_redraw (); From e59e3e59caa3d3f7dbe54812f7b97964f03aa3aa Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 30 Nov 2009 12:52:39 +0100 Subject: [PATCH 032/237] Changelog --- ChangeLog.gfxtermscroll | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ChangeLog.gfxtermscroll diff --git a/ChangeLog.gfxtermscroll b/ChangeLog.gfxtermscroll new file mode 100644 index 000000000..b0733116f --- /dev/null +++ b/ChangeLog.gfxtermscroll @@ -0,0 +1,18 @@ +2009-11-30 Vladimir Serbinenko + + Agglomerate scrolling in gfxterm. + + * term/gfxterm.c (grub_virtual_screen): New member 'total_screen'. + (grub_virtual_screen_setup): Initialise 'total_screen'. + (write_char): Split to ... + (paint_char): ... this ... + (write_char): ... and this. + (paint_char): Handle delayed scrolling. + (draw_cursor): Likewise. + (scroll_up): Split to ... + (real_scroll): ... this ... + (scroll_up): ... and this. + (real_scroll): Handle multi-line scroll and draw below-the-bottom + characters. + (grub_gfxterm_refresh): Call real_scroll. + From f505738643d0c580026f63d28777eb5bef8ff4da Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 2 Dec 2009 14:42:28 +0100 Subject: [PATCH 033/237] Fix warning --- gfxmenu/gui_string_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gfxmenu/gui_string_util.c b/gfxmenu/gui_string_util.c index 31b2f0aca..8ea7c497b 100644 --- a/gfxmenu/gui_string_util.c +++ b/gfxmenu/gui_string_util.c @@ -206,7 +206,7 @@ grub_get_dirname (const char *file_path) } static __inline int -isxdigit (char c) +my_isxdigit (char c) { return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') @@ -261,7 +261,7 @@ grub_gui_parse_color (const char *s, grub_gui_color_t *color) /* Count the hexits to determine the format. */ int hexits = 0; const char *end = s; - while (isxdigit (*end)) + while (my_isxdigit (*end)) { end++; hexits++; From 17d1956f5c5bab387f544bdffa0c9041ae8d80c6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 2 Dec 2009 21:03:41 +0100 Subject: [PATCH 034/237] Fix cursor drawing and whole screen scrolling --- term/gfxterm.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/term/gfxterm.c b/term/gfxterm.c index be0487830..eb2c47c3d 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -754,19 +754,22 @@ real_scroll (void) } - /* Draw cursor if visible. */ - if (virtual_screen.cursor_state) - draw_cursor (1); - was_scroll = virtual_screen.total_scroll; virtual_screen.total_scroll = 0; + if (was_scroll > virtual_screen.rows) + was_scroll = virtual_screen.rows; + /* Draw shadow part. */ for (i = virtual_screen.rows - was_scroll; i < virtual_screen.rows; i++) for (j = 0; j < virtual_screen.columns; j++) paint_char (j, i); + /* Draw cursor if visible. */ + if (virtual_screen.cursor_state) + draw_cursor (1); + if (repaint_callback) repaint_callback (window.x, window.y, window.width, window.height); } From 3d79d70fe4d78302b6c0a116278e490193154dc6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 20 Dec 2009 01:51:38 +0100 Subject: [PATCH 035/237] Don't use UNUSED --- gfxmenu/gfxmenu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gfxmenu/gfxmenu.c b/gfxmenu/gfxmenu.c index ab1c8befb..62ee34234 100644 --- a/gfxmenu/gfxmenu.c +++ b/gfxmenu/gfxmenu.c @@ -201,8 +201,9 @@ show_menu (grub_menu_t menu, int nested) } static grub_err_t -grub_cmd_gfxmenu (grub_command_t cmd UNUSED, - int argc UNUSED, char **args UNUSED) +grub_cmd_gfxmenu (grub_command_t cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) { grub_menu_t menu = grub_env_get_data_slot ("menu"); if (! menu) From 9b1209ba15cc0cddaf965f98777eb6cbd1213129 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 26 Dec 2009 02:37:01 +0100 Subject: [PATCH 036/237] Cache loaded theme --- gfxmenu/gfxmenu.c | 63 +++++++++++++++++++++++++++----- gfxmenu/view.c | 71 ++++++++----------------------------- include/grub/gfxmenu_view.h | 3 +- 3 files changed, 70 insertions(+), 67 deletions(-) diff --git a/gfxmenu/gfxmenu.c b/gfxmenu/gfxmenu.c index 0d807914b..f39cdbbfe 100644 --- a/gfxmenu/gfxmenu.c +++ b/gfxmenu/gfxmenu.c @@ -37,21 +37,39 @@ #include #include -void -grub_gfxmenu_viewer_fini (void *data) -{ - grub_gfxmenu_view_t view = data; +grub_gfxmenu_view_t cached_view; - grub_gfxmenu_view_destroy (view); +static grub_err_t +set_graphics_mode (void) +{ + const char *modestr = grub_env_get ("gfxmode"); + if (!modestr || !modestr[0]) + modestr = "auto"; + return grub_video_set_mode (modestr, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); +} + +/* FIXME: conflicts with gfxterm. */ +static grub_err_t +set_text_mode (void) +{ + return grub_video_restore (); +} + +void +grub_gfxmenu_viewer_fini (void *data __attribute__ ((unused))) +{ + set_text_mode (); } /* FIXME: 't' and 'c'. */ grub_err_t grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) { - grub_gfxmenu_view_t view; + grub_gfxmenu_view_t view = NULL; const char *theme_path; struct grub_menu_viewer *instance; + grub_err_t err; + struct grub_video_mode_info mode_info; theme_path = grub_env_get ("theme"); if (! theme_path) @@ -61,15 +79,41 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) if (!instance) return grub_errno; - /* Create the view. */ - view = grub_gfxmenu_view_new (theme_path, menu, entry, nested); + set_graphics_mode (); + err = grub_video_get_info (&mode_info); + if (err) + { + set_text_mode (); + return 0; + } - if (! view) + if (!cached_view || grub_strcmp (cached_view->theme_path, theme_path) != 0 + || cached_view->screen.width != (int) mode_info.width + || cached_view->screen.height != (int) mode_info.height) + { + grub_free (cached_view); + /* Create the view. */ + cached_view = grub_gfxmenu_view_new (theme_path, mode_info.width, + mode_info.height); + } + + if (! cached_view) { grub_free (instance); + set_text_mode (); return grub_errno; } + view = cached_view; + + view->double_repaint = (mode_info.mode_type + & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED) + && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); + view->selected = entry; + view->menu = menu; + view->nested = nested; + view->first_timeout = -1; + grub_gfxmenu_view_draw (view); instance->data = view; @@ -90,5 +134,6 @@ GRUB_MOD_INIT (gfxmenu) GRUB_MOD_FINI (gfxmenu) { + grub_gfxmenu_view_destroy (cached_view); grub_gfxmenu_try_hook = NULL; } diff --git a/gfxmenu/view.c b/gfxmenu/view.c index 882469447..8c460ff88 100644 --- a/gfxmenu/view.c +++ b/gfxmenu/view.c @@ -45,62 +45,31 @@ static grub_gfxmenu_view_t term_view; #endif -static grub_err_t set_graphics_mode (void); -static grub_err_t set_text_mode (void); - /* Create a new view object, loading the theme specified by THEME_PATH and associating MODEL with the view. */ grub_gfxmenu_view_t -grub_gfxmenu_view_new (const char *theme_path, grub_menu_t menu, int entry, - int nested) +grub_gfxmenu_view_new (const char *theme_path, + int width, int height) { grub_gfxmenu_view_t view; - grub_err_t err; - struct grub_video_mode_info mode_info; + grub_font_t default_font; + grub_gui_color_t default_fg_color; + grub_gui_color_t default_bg_color; view = grub_malloc (sizeof (*view)); if (! view) return 0; - set_graphics_mode (); - grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); - grub_video_get_viewport ((unsigned *) &view->screen.x, - (unsigned *) &view->screen.y, - (unsigned *) &view->screen.width, - (unsigned *) &view->screen.height); - - err = grub_video_get_info (&mode_info); - if (err) - { - grub_free (view); - return 0; - } - else - view->double_repaint = (mode_info.mode_type - & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED) - && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); - - - /* Clear the screen; there may be garbage left over in video memory, and - loading the menu style (particularly the background) can take a while. */ - grub_video_fill_rect (grub_video_map_rgb (0, 0, 0), - view->screen.x, view->screen.y, - view->screen.width, view->screen.height); - grub_video_swap_buffers (); - - grub_font_t default_font; - grub_gui_color_t default_fg_color; - grub_gui_color_t default_bg_color; + view->screen.x = 0; + view->screen.y = 0; + view->screen.width = width; + view->screen.height = height; default_font = grub_font_get ("Helvetica 12"); default_fg_color = grub_gui_color_rgb (0, 0, 0); default_bg_color = grub_gui_color_rgb (255, 255, 255); view->canvas = 0; - view->selected = entry; - view->menu = menu; - view->nested = nested; - view->first_timeout = -1; view->title_font = default_font; view->message_font = default_font; @@ -151,7 +120,6 @@ grub_gfxmenu_view_destroy (grub_gfxmenu_view_t view) view->canvas->ops->component.destroy (view->canvas); grub_free (view); - set_text_mode (); #if 0 destroy_terminal (); #endif @@ -376,6 +344,12 @@ grub_gfxmenu_view_redraw (grub_gfxmenu_view_t view, void grub_gfxmenu_view_draw (grub_gfxmenu_view_t view) { + /* Clear the screen; there may be garbage left over in video memory. */ + grub_video_fill_rect (grub_video_map_rgb (0, 0, 0), + view->screen.x, view->screen.y, + view->screen.width, view->screen.height); + grub_video_swap_buffers (); + update_menu_components (view); grub_gfxmenu_view_redraw (view, &view->screen); @@ -426,21 +400,6 @@ grub_gfxmenu_set_chosen_entry (int entry, void *data) } -static grub_err_t -set_graphics_mode (void) -{ - const char *modestr = grub_env_get ("gfxmode"); - if (!modestr || !modestr[0]) - modestr = "auto"; - return grub_video_set_mode (modestr, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); -} - -static grub_err_t -set_text_mode (void) -{ - return grub_video_restore (); -} - /* FIXME */ #if 0 static int term_target_width; diff --git a/include/grub/gfxmenu_view.h b/include/grub/gfxmenu_view.h index 92cedc6a7..1b83cc5a3 100644 --- a/include/grub/gfxmenu_view.h +++ b/include/grub/gfxmenu_view.h @@ -31,8 +31,7 @@ typedef struct grub_gfxmenu_view *grub_gfxmenu_view_t; grub_gfxmenu_view_t grub_gfxmenu_view_new (const char *theme_path, - grub_menu_t menu, int entry, - int nested); + int width, int height); void grub_gfxmenu_view_destroy (grub_gfxmenu_view_t view); From d3ee2d201e3a241ee1f39e9a2a2e3e6580579186 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 26 Dec 2009 16:41:54 +0100 Subject: [PATCH 037/237] Various fixes to make gfxmenu work smoothly in multioutput environment --- gfxmenu/gfxmenu.c | 43 +++++----- gfxmenu/view.c | 109 ++++++++++---------------- include/grub/gfxmenu_view.h | 8 -- include/grub/gfxterm.h | 18 +++-- include/grub/menu.h | 4 - term/gfxterm.c | 152 ++++++++++++++++-------------------- 6 files changed, 137 insertions(+), 197 deletions(-) diff --git a/gfxmenu/gfxmenu.c b/gfxmenu/gfxmenu.c index f39cdbbfe..b093ec49e 100644 --- a/gfxmenu/gfxmenu.c +++ b/gfxmenu/gfxmenu.c @@ -39,26 +39,9 @@ grub_gfxmenu_view_t cached_view; -static grub_err_t -set_graphics_mode (void) -{ - const char *modestr = grub_env_get ("gfxmode"); - if (!modestr || !modestr[0]) - modestr = "auto"; - return grub_video_set_mode (modestr, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); -} - -/* FIXME: conflicts with gfxterm. */ -static grub_err_t -set_text_mode (void) -{ - return grub_video_restore (); -} - void grub_gfxmenu_viewer_fini (void *data __attribute__ ((unused))) { - set_text_mode (); } /* FIXME: 't' and 'c'. */ @@ -73,18 +56,23 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) theme_path = grub_env_get ("theme"); if (! theme_path) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "no theme specified"); + { + grub_gfxterm_fullscreen (); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "no theme specified"); + } instance = grub_zalloc (sizeof (*instance)); if (!instance) - return grub_errno; + { + grub_gfxterm_fullscreen (); + return grub_errno; + } - set_graphics_mode (); err = grub_video_get_info (&mode_info); if (err) { - set_text_mode (); - return 0; + grub_gfxterm_fullscreen (); + return err; } if (!cached_view || grub_strcmp (cached_view->theme_path, theme_path) != 0 @@ -100,7 +88,7 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) if (! cached_view) { grub_free (instance); - set_text_mode (); + grub_gfxterm_fullscreen (); return grub_errno; } @@ -129,6 +117,15 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) GRUB_MOD_INIT (gfxmenu) { + struct grub_term_output *term; + + FOR_ACTIVE_TERM_OUTPUTS(term) + if (grub_gfxmenu_try_hook && grub_strcmp (term->name, "gfxterm") == 0) + { + grub_gfxterm_fullscreen (); + break; + } + grub_gfxmenu_try_hook = grub_gfxmenu_try; } diff --git a/gfxmenu/view.c b/gfxmenu/view.c index 8c460ff88..a7ca14530 100644 --- a/gfxmenu/view.c +++ b/gfxmenu/view.c @@ -41,9 +41,10 @@ status changes. */ #define TIMEOUT_COMPONENT_ID "__timeout__" -#if 0 +static void +init_terminal (grub_gfxmenu_view_t view); +static grub_video_rect_t term_rect; static grub_gfxmenu_view_t term_view; -#endif /* Create a new view object, loading the theme specified by THEME_PATH and associating MODEL with the view. */ @@ -98,10 +99,6 @@ grub_gfxmenu_view_new (const char *theme_path, return 0; } -#if 0 - init_terminal (view); -#endif - return view; } @@ -119,26 +116,8 @@ grub_gfxmenu_view_destroy (grub_gfxmenu_view_t view) if (view->canvas) view->canvas->ops->component.destroy (view->canvas); grub_free (view); - -#if 0 - destroy_terminal (); -#endif } -#if 0 -/* Sets MESSAGE as the progress message for the view. - MESSAGE can be 0, in which case no message is displayed. */ -static void -set_progress_message (grub_gfxmenu_view_t view, const char *message) -{ - grub_free (view->progress_message_text); - if (message) - view->progress_message_text = grub_strdup (message); - else - view->progress_message_text = 0; -} -#endif - static void redraw_background (grub_gfxmenu_view_t view, const grub_video_rect_t *bounds) @@ -331,6 +310,9 @@ void grub_gfxmenu_view_redraw (grub_gfxmenu_view_t view, const grub_video_rect_t *region) { + if (grub_video_have_common_points (&term_rect, region)) + grub_gfxterm_schedule_repaint (); + grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); redraw_background (view, region); @@ -344,11 +326,17 @@ grub_gfxmenu_view_redraw (grub_gfxmenu_view_t view, void grub_gfxmenu_view_draw (grub_gfxmenu_view_t view) { + init_terminal (view); + /* Clear the screen; there may be garbage left over in video memory. */ grub_video_fill_rect (grub_video_map_rgb (0, 0, 0), view->screen.x, view->screen.y, view->screen.width, view->screen.height); grub_video_swap_buffers (); + if (view->double_repaint) + grub_video_fill_rect (grub_video_map_rgb (0, 0, 0), + view->screen.x, view->screen.y, + view->screen.width, view->screen.height); update_menu_components (view); @@ -399,77 +387,60 @@ grub_gfxmenu_set_chosen_entry (int entry, void *data) grub_gfxmenu_redraw_menu (view); } - -/* FIXME */ -#if 0 -static int term_target_width; -static int term_target_height; -static int term_initialized; -static grub_term_output_t term_original; - static void -draw_terminal_box (grub_gfxmenu_view_t view) +grub_gfxmenu_draw_terminal_box (void) { grub_gfxmenu_box_t term_box; - int termx; - int termy; term_box = term_view->terminal_box; if (!term_box) return; - - termx = term_view->screen.x + term_view->screen.width * (10 - 7) / 10 / 2; - termy = term_view->screen.y + term_view->screen.height * (10 - 7) / 10 / 2; - term_box->set_content_size (term_box, term_target_width, - term_target_height); + term_box->set_content_size (term_box, term_rect.width, + term_rect.height); term_box->draw (term_box, - termx - term_box->get_left_pad (term_box), - termy - term_box->get_top_pad (term_box)); + term_rect.x - term_box->get_left_pad (term_box), + term_rect.y - term_box->get_top_pad (term_box)); grub_video_swap_buffers (); - if (view->double_repaint) + if (term_view->double_repaint) term_box->draw (term_box, - termx - term_box->get_left_pad (term_box), - termy - term_box->get_top_pad (term_box)); + term_rect.x - term_box->get_left_pad (term_box), + term_rect.y - term_box->get_top_pad (term_box)); } static void init_terminal (grub_gfxmenu_view_t view) { - int termx; - int termy; + term_rect.width = view->screen.width * 7 / 10; + term_rect.height = view->screen.height * 7 / 10; - term_original = grub_term_get_current_output (); + term_rect.x = view->screen.x + view->screen.width * (10 - 7) / 10 / 2; + term_rect.y = view->screen.y + view->screen.height * (10 - 7) / 10 / 2; - term_target_width = view->screen.width * 7 / 10; - term_target_height = view->screen.height * 7 / 10; - - termx = view->screen.x + view->screen.width * (10 - 7) / 10 / 2; - termy = view->screen.y + view->screen.height * (10 - 7) / 10 / 2; + term_view = view; /* Note: currently there is no API for changing the gfxterm font on the fly, so whatever font the initially loaded theme specifies will be permanent. */ - grub_gfxterm_init_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY, termx, termy, - term_target_width, term_target_height, - view->double_repaint, view->terminal_font_name, 3); - if (grub_errno != GRUB_ERR_NONE) - return; - term_initialized = 1; - - term_view = view; - - grub_term_set_current_output (grub_gfxterm_get_term ()); - grub_refresh (); + grub_gfxterm_set_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY, term_rect.x, + term_rect.y, + term_rect.width, term_rect.height, + view->double_repaint, view->terminal_font_name, 3); + grub_gfxterm_decorator_hook = grub_gfxmenu_draw_terminal_box; } -static void destroy_terminal (void) +#if 0 +/* Sets MESSAGE as the progress message for the view. + MESSAGE can be 0, in which case no message is displayed. */ +static void +set_progress_message (grub_gfxmenu_view_t view, const char *message) { - if (term_initialized) - grub_gfxterm_destroy_window (); - if (term_original) - grub_term_set_current_output (term_original); + grub_free (view->progress_message_text); + if (message) + view->progress_message_text = grub_strdup (message); + else + view->progress_message_text = 0; } static void diff --git a/include/grub/gfxmenu_view.h b/include/grub/gfxmenu_view.h index 1b83cc5a3..7cbfa89d3 100644 --- a/include/grub/gfxmenu_view.h +++ b/include/grub/gfxmenu_view.h @@ -45,14 +45,6 @@ grub_err_t grub_gui_recreate_box (grub_gfxmenu_box_t *boxptr, void grub_gfxmenu_view_draw (grub_gfxmenu_view_t view); -int grub_gfxmenu_view_execute_with_fallback (grub_gfxmenu_view_t view, - grub_menu_entry_t entry); - -int grub_gfxmenu_view_execute_entry (grub_gfxmenu_view_t view, - grub_menu_entry_t entry); - -void grub_gfxmenu_view_run_terminal (grub_gfxmenu_view_t view); - void grub_gfxmenu_redraw_menu (grub_gfxmenu_view_t view); diff --git a/include/grub/gfxterm.h b/include/grub/gfxterm.h index e607bd5e1..fe3da7409 100644 --- a/include/grub/gfxterm.h +++ b/include/grub/gfxterm.h @@ -25,18 +25,20 @@ #include grub_err_t -grub_gfxterm_init_window (struct grub_video_render_target *target, - int x, int y, int width, int height, - int double_repaint, - const char *font_name, int border_width); - -void grub_gfxterm_destroy_window (void); - -const struct grub_term_output *grub_gfxterm_get_term (void); +grub_gfxterm_set_window (struct grub_video_render_target *target, + int x, int y, int width, int height, + int double_repaint, + const char *font_name, int border_width); typedef void (*grub_gfxterm_repaint_callback_t)(int x, int y, int width, int height); void grub_gfxterm_set_repaint_callback (grub_gfxterm_repaint_callback_t func); +void grub_gfxterm_schedule_repaint (void); + +grub_err_t grub_gfxterm_fullscreen (void); + +extern void (*grub_gfxterm_decorator_hook) (void); + #endif /* ! GRUB_GFXTERM_HEADER */ diff --git a/include/grub/menu.h b/include/grub/menu.h index 20a1fc47f..78f461b92 100644 --- a/include/grub/menu.h +++ b/include/grub/menu.h @@ -83,10 +83,6 @@ typedef struct grub_menu_execute_callback } *grub_menu_execute_callback_t; -extern grub_err_t (*grub_gfxmenu_try_hook) (int entry, grub_menu_t menu, - int nested); - - grub_menu_entry_t grub_menu_get_entry (grub_menu_t menu, int no); int grub_menu_get_timeout (void); void grub_menu_set_timeout (int timeout); diff --git a/term/gfxterm.c b/term/gfxterm.c index eb2c47c3d..8ef7d848b 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -115,20 +115,16 @@ struct grub_gfxterm_window int double_repaint; }; -static int refcount; static struct grub_video_render_target *render_target; +void (*grub_gfxterm_decorator_hook) (void) = NULL; static struct grub_gfxterm_window window; static struct grub_virtual_screen virtual_screen; static grub_gfxterm_repaint_callback_t repaint_callback; - -static grub_err_t init_window (struct grub_video_render_target *target, - int x, int y, int width, int height, - int double_repaint, - const char *font_name, int border_width); +static int repaint_schedulded = 0; +static int repaint_was_schedulded = 0; static void destroy_window (void); - static struct grub_video_render_target *text_layer; static unsigned int bitmap_width; @@ -271,10 +267,17 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y, return grub_errno; } -static grub_err_t -init_window (struct grub_video_render_target *target, - int x, int y, int width, int height, int double_repaint, - const char *font_name, int border_width) +void +grub_gfxterm_schedule_repaint (void) +{ + repaint_schedulded = 1; +} + +grub_err_t +grub_gfxterm_set_window (struct grub_video_render_target *target, + int x, int y, int width, int height, + int double_repaint, + const char *font_name, int border_width) { /* Clean up any prior instance. */ destroy_window (); @@ -299,45 +302,55 @@ init_window (struct grub_video_render_target *target, window.height = height; window.double_repaint = double_repaint; - /* Mark whole window as dirty. */ dirty_region_reset (); - dirty_region_add (0, 0, width, height); + grub_gfxterm_schedule_repaint (); return grub_errno; } grub_err_t -grub_gfxterm_init_window (struct grub_video_render_target *target, - int x, int y, int width, int height, - int double_repaint, - const char *font_name, int border_width) -{ - if (refcount++ == 0) - init_window (target, x, y, width, height, double_repaint, - font_name, border_width); - return grub_errno; -} - -static grub_err_t -grub_gfxterm_init (void) +grub_gfxterm_fullscreen (void) { const char *font_name; - const char *modevar; struct grub_video_mode_info mode_info; - char *tmp; - grub_err_t err; grub_video_color_t color; + grub_err_t err; - /* If gfxterm has already been initialized by calling the init_window - function, then leave it alone when it is set as the current terminal. */ - if (refcount++ != 0) - return GRUB_ERR_NONE; + err = grub_video_get_info (&mode_info); + /* Figure out what mode we ended up. */ + if (err) + return err; + + grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + + /* Make sure screen is black. */ + color = grub_video_map_rgb (0, 0, 0); + grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height); + bitmap = 0; /* Select the font to use. */ font_name = grub_env_get ("gfxterm_font"); if (! font_name) font_name = ""; /* Allow fallback to any font. */ + grub_gfxterm_decorator_hook = NULL; + + return grub_gfxterm_set_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY, + 0, 0, mode_info.width, mode_info.height, + mode_info.mode_type + & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED + && !(mode_info.mode_type + & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP), + font_name, DEFAULT_BORDER_WIDTH); +} + +static grub_err_t +grub_gfxterm_init (void) +{ + char *tmp; + grub_err_t err; + const char *modevar; + /* Parse gfxmode environment variable if set. */ modevar = grub_env_get ("gfxmode"); if (! modevar || *modevar == 0) @@ -358,35 +371,11 @@ grub_gfxterm_init (void) if (err) return err; - err = grub_video_get_info (&mode_info); - /* Figure out what mode we ended up. */ + err = grub_gfxterm_fullscreen (); if (err) - return err; + grub_video_restore (); - /* Make sure screen is black. */ - color = grub_video_map_rgb (0, 0, 0); - grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height); - bitmap = 0; - - /* Select the font to use. */ - font_name = grub_env_get ("gfxterm_font"); - if (! font_name) - font_name = ""; /* Allow fallback to any font. */ - - /* Leave borders for virtual screen. */ - if (init_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY, - 0, 0, mode_info.width, mode_info.height, - mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED - && !(mode_info.mode_type - & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP), - font_name, - DEFAULT_BORDER_WIDTH) != GRUB_ERR_NONE) - { - grub_video_restore (); - return grub_errno; - } - - return grub_errno; + return err; } static void @@ -402,26 +391,15 @@ destroy_window (void) grub_virtual_screen_free (); } -void -grub_gfxterm_destroy_window (void) -{ - if (--refcount == 0) - destroy_window (); -} - static grub_err_t grub_gfxterm_fini (void) { - /* Don't destroy an explicitly initialized terminal instance when it is - unset as the current terminal. */ - if (--refcount == 0) - { - destroy_window (); - grub_video_restore (); - } + destroy_window (); + grub_video_restore (); /* Clear error state. */ - return (grub_errno = GRUB_ERR_NONE); + grub_errno = GRUB_ERR_NONE; + return GRUB_ERR_NONE; } static void @@ -521,6 +499,7 @@ dirty_region_reset (void) dirty_region.top_left_y = -1; dirty_region.bottom_right_x = -1; dirty_region.bottom_right_y = -1; + repaint_was_schedulded = 0; } static int @@ -540,6 +519,16 @@ dirty_region_add (int x, int y, unsigned int width, unsigned int height) if ((width == 0) || (height == 0)) return; + if (repaint_schedulded) + { + x = virtual_screen.offset_x; + y = virtual_screen.offset_y; + width = virtual_screen.width; + height = virtual_screen.height; + repaint_schedulded = 0; + repaint_was_schedulded = 1; + } + if (dirty_region_is_empty ()) { dirty_region.top_left_x = x; @@ -586,6 +575,9 @@ dirty_region_redraw (void) width = dirty_region.bottom_right_x - x + 1; height = dirty_region.bottom_right_y - y + 1; + if (repaint_was_schedulded && grub_gfxterm_decorator_hook) + grub_gfxterm_decorator_hook (); + redraw_screen_rect (x, y, width, height); } @@ -1109,7 +1101,6 @@ grub_gfxterm_background_image_cmd (grub_extcmd_t cmd __attribute__ ((unused)), bitmap = 0; /* Mark whole screen as dirty. */ - dirty_region_reset (); dirty_region_add (0, 0, window.width, window.height); } @@ -1152,7 +1143,6 @@ grub_gfxterm_background_image_cmd (grub_extcmd_t cmd __attribute__ ((unused)), bitmap_height = grub_video_bitmap_get_height (bitmap); /* Mark whole screen as dirty. */ - dirty_region_reset (); dirty_region_add (0, 0, window.width, window.height); } } @@ -1182,18 +1172,10 @@ static struct grub_term_output grub_video_term = .next = 0 }; -const struct grub_term_output * -grub_gfxterm_get_term (void) -{ - return &grub_video_term; -} - static grub_extcmd_t background_image_cmd_handle; GRUB_MOD_INIT(term_gfxterm) { - refcount = 0; - grub_term_register_output ("gfxterm", &grub_video_term); background_image_cmd_handle = grub_register_extcmd ("background_image", From 4cc972be91c947f12a9edcd10946ae1119494fe7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 26 Dec 2009 16:58:01 +0100 Subject: [PATCH 038/237] Clarify FIXME comments. --- gfxmenu/gfxmenu.c | 2 +- gfxmenu/view.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gfxmenu/gfxmenu.c b/gfxmenu/gfxmenu.c index b093ec49e..1fe6e7297 100644 --- a/gfxmenu/gfxmenu.c +++ b/gfxmenu/gfxmenu.c @@ -44,7 +44,7 @@ grub_gfxmenu_viewer_fini (void *data __attribute__ ((unused))) { } -/* FIXME: 't' and 'c'. */ +/* FIXME: Previously 't' changed to text menu is it necessary? */ grub_err_t grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) { diff --git a/gfxmenu/view.c b/gfxmenu/view.c index a7ca14530..c32211261 100644 --- a/gfxmenu/view.c +++ b/gfxmenu/view.c @@ -430,6 +430,9 @@ init_terminal (grub_gfxmenu_view_t view) grub_gfxterm_decorator_hook = grub_gfxmenu_draw_terminal_box; } +/* FIXME: previously notifications were displayed in special case. + Is it necessary? + */ #if 0 /* Sets MESSAGE as the progress message for the view. MESSAGE can be 0, in which case no message is displayed. */ From a2b4c09b1c48c5e3b8958291a06c2ee651b5a57d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 27 Dec 2009 22:24:46 +0100 Subject: [PATCH 039/237] Don't destroy NULL view --- gfxmenu/view.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gfxmenu/view.c b/gfxmenu/view.c index 7d9bb1cd0..e2348b6ef 100644 --- a/gfxmenu/view.c +++ b/gfxmenu/view.c @@ -136,6 +136,8 @@ grub_gfxmenu_view_new (const char *theme_path, grub_gfxmenu_model_t model) void grub_gfxmenu_view_destroy (grub_gfxmenu_view_t view) { + if (!view) + return; grub_video_bitmap_destroy (view->desktop_image); if (view->terminal_box) view->terminal_box->destroy (view->terminal_box); From 9a17588459f2bc876c7b3f4c9d86b0489ca1bc5b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Dec 2009 17:31:02 +0100 Subject: [PATCH 040/237] Initial support for scalable gfxmenu --- gfxmenu/gui_box.c | 232 +++++++++++++++++++------------- gfxmenu/gui_canvas.c | 120 ++++++++--------- gfxmenu/gui_circular_progress.c | 52 +------ gfxmenu/gui_image.c | 38 +----- gfxmenu/gui_label.c | 36 +---- gfxmenu/gui_list.c | 64 +++------ gfxmenu/gui_progress_bar.c | 48 +------ gfxmenu/gui_string_util.c | 38 ------ gfxmenu/theme_loader.c | 104 ++++++++------ gfxmenu/view.c | 4 +- include/grub/gui.h | 59 +++++++- include/grub/gui_string_util.h | 2 - include/grub/video.h | 8 +- 13 files changed, 368 insertions(+), 437 deletions(-) diff --git a/gfxmenu/gui_box.c b/gfxmenu/gui_box.c index 4fe131f98..45028e5b1 100644 --- a/gfxmenu/gui_box.c +++ b/gfxmenu/gui_box.c @@ -32,17 +32,16 @@ struct component_node typedef struct grub_gui_box *grub_gui_box_t; typedef void (*layout_func_t) (grub_gui_box_t self, int modify_layout, - int *width, int *height); + unsigned *minimal_width, + unsigned *minimal_height); struct grub_gui_box { - struct grub_gui_container_ops *container; + struct grub_gui_container container; grub_gui_container_t parent; grub_video_rect_t bounds; char *id; - int preferred_width; - int preferred_height; /* Doubly linked list of components with dummy head & tail nodes. */ struct component_node chead; @@ -87,82 +86,158 @@ box_is_instance (void *vself __attribute__((unused)), const char *type) static void layout_horizontally (grub_gui_box_t self, int modify_layout, - int *width, int *height) + unsigned *min_width, unsigned *min_height) { /* Start at the left (chead) and set the x coordinates as we go right. */ /* All components have their width set to the box's width. */ struct component_node *cur; - int x = 0; - if (height) - *height = 0; + unsigned w = 0, mwfrac = 0, h = 0, x = 0; + grub_fixed_unsigned_t wfrac = 0; + int bogus_frac = 0; + for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) { grub_gui_component_t c = cur->component; + unsigned mw = 0, mh = 0; + + if (c->ops->get_minimal_size) + c->ops->get_minimal_size (c, &mw, &mh); + + if (!c->ishfrac && c->h > h) + h = c->h; + if (mh > h) + h = mh; + if (!c->iswfrac) + w += mw > c->w ? mw : c->w; + if (c->iswfrac) + { + wfrac += c->wfrac; + mwfrac += mw; + } + } + if (wfrac > GRUB_FIXED_1 || (w > 0 && wfrac == GRUB_FIXED_1)) + bogus_frac = 1; + + if (min_width) + { + if (wfrac < GRUB_FIXED_1) + *min_width = grub_fixed_ufu_divide (w, GRUB_FIXED_1 - wfrac); + else + *min_width = w; + if (*min_width < w + mwfrac) + *min_width = w + mwfrac; + } + if (min_height) + *min_height = h; + + if (!modify_layout) + return; + + for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) + { grub_video_rect_t r; + grub_gui_component_t c = cur->component; + unsigned mw = 0, mh = 0; - c->ops->get_preferred_size (c, &r.width, &r.height); + r.x = x; + r.y = 0; + r.width = 32; + r.height = h; - /* Check and possibly update the maximum width, if non-null. */ - if (height && r.height > *height) - *height = r.height; + if (c->ops->get_minimal_size) + c->ops->get_minimal_size (c, &mw, &mh); - /* Set the component's bounds, if the flag is set. */ - if (modify_layout) - { - r.x = x; - r.y = 0; - /* Width comes from the component's preferred size. */ - r.height = self->bounds.height; - c->ops->set_bounds (c, &r); - } + if (!c->iswfrac) + r.width = c->w; + if (c->iswfrac && !bogus_frac) + r.width = grub_fixed_ufu_multiply (self->bounds.width, c->wfrac); + + if (r.width < mw) + r.width = mw; + + c->ops->set_bounds (c, &r); x += r.width; } - - /* Return the sum of the children's preferred widths. */ - if (width) - *width = x; } static void layout_vertically (grub_gui_box_t self, int modify_layout, - int *width, int *height) + unsigned *min_width, unsigned *min_height) { - /* Start at the top (chead) and set the y coordinates as we go down. */ - /* All components have their width set to the vbox's width. */ + /* Start at the top (chead) and set the y coordinates as we go rdown. */ + /* All components have their height set to the box's height. */ struct component_node *cur; - int y = 0; - if (width) - *width = 0; + unsigned h = 0, mhfrac = 0, w = 0, y = 0; + grub_fixed_unsigned_t hfrac = 0; + int bogus_frac = 0; + for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) { grub_gui_component_t c = cur->component; + unsigned mw = 0, mh = 0; + + if (c->ops->get_minimal_size) + c->ops->get_minimal_size (c, &mw, &mh); + + if (!c->iswfrac && c->w > w) + w = c->w; + if (mw > w) + w = mw; + if (!c->ishfrac) + h += mh > c->h ? mh : c->h; + if (c->ishfrac) + { + hfrac += c->hfrac; + mhfrac += mh; + } + } + if (hfrac > GRUB_FIXED_1 || (h > 0 && hfrac == GRUB_FIXED_1)) + bogus_frac = 1; + + if (min_height) + { + if (hfrac < GRUB_FIXED_1) + *min_height = grub_fixed_ufu_divide (h, GRUB_FIXED_1 - hfrac); + else + *min_height = h; + if (*min_height < h + mhfrac) + *min_height = h + mhfrac; + } + if (min_width) + *min_width = w; + + if (!modify_layout) + return; + + for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) + { grub_video_rect_t r; + grub_gui_component_t c = cur->component; + unsigned mw = 0, mh = 0; - c->ops->get_preferred_size (c, &r.width, &r.height); + r.x = 0; + r.y = y; + r.width = w; + r.height = 32; - /* Check and possibly update the maximum width, if non-null. */ - if (width && r.width > *width) - *width = r.width; + if (c->ops->get_minimal_size) + c->ops->get_minimal_size (c, &mw, &mh); - /* Set the component's bounds, if the flag is set. */ - if (modify_layout) - { - r.x = 0; - r.y = y; - r.width = self->bounds.width; - /* Height comes from the component's preferred size. */ - c->ops->set_bounds (c, &r); - } + if (!c->ishfrac) + r.height = c->h; + if (c->ishfrac) + r.height = grub_fixed_ufu_multiply (self->bounds.height, c->hfrac); + + if (r.height < mh) + r.height = mh; + + c->ops->set_bounds (c, &r); y += r.height; } - - /* Return the sum of the children's preferred heights. */ - if (height) - *height = y; } static void @@ -213,16 +288,10 @@ box_get_bounds (void *vself, grub_video_rect_t *bounds) /* The box's preferred size is based on the preferred sizes of its children. */ static void -box_get_preferred_size (void *vself, int *width, int *height) +box_get_minimal_size (void *vself, unsigned *width, unsigned *height) { grub_gui_box_t self = vself; self->layout_func (self, 0, width, height); /* Just calculate the size. */ - - /* Allow preferred dimensions to override the computed dimensions. */ - if (self->preferred_width >= 0) - *width = self->preferred_width; - if (self->preferred_height >= 0) - *height = self->preferred_height; } static grub_err_t @@ -241,15 +310,6 @@ box_set_property (void *vself, const char *name, const char *value) else self->id = 0; } - else if (grub_strcmp (name, "preferred_size") == 0) - { - int w; - int h; - if (grub_gui_parse_2_tuple (value, &w, &h) != GRUB_ERR_NONE) - return grub_errno; - self->preferred_width = w; - self->preferred_height = h; - } return grub_errno; } @@ -303,21 +363,22 @@ box_iterate_children (void *vself, cb (cur->component, userdata); } +static struct grub_gui_component_ops box_comp_ops = + { + .destroy = box_destroy, + .get_id = box_get_id, + .is_instance = box_is_instance, + .paint = box_paint, + .set_parent = box_set_parent, + .get_parent = box_get_parent, + .set_bounds = box_set_bounds, + .get_bounds = box_get_bounds, + .get_minimal_size = box_get_minimal_size, + .set_property = box_set_property + }; + static struct grub_gui_container_ops box_ops = { - .component = - { - .destroy = box_destroy, - .get_id = box_get_id, - .is_instance = box_is_instance, - .paint = box_paint, - .set_parent = box_set_parent, - .get_parent = box_get_parent, - .set_bounds = box_set_bounds, - .get_bounds = box_get_bounds, - .get_preferred_size = box_get_preferred_size, - .set_property = box_set_property - }, .add = box_add, .remove = box_remove, .iterate_children = box_iterate_children @@ -329,24 +390,13 @@ static grub_gui_box_t box_new (layout_func_t layout_func) { grub_gui_box_t box; - box = grub_malloc (sizeof (*box)); + box = grub_zalloc (sizeof (*box)); if (! box) return 0; - box->container = &box_ops; - box->parent = 0; - box->bounds.x = 0; - box->bounds.y = 0; - box->bounds.width = 0; - box->bounds.height = 0; - box->id = 0; - box->preferred_width = -1; - box->preferred_height = -1; - box->chead.component = 0; - box->chead.prev = 0; + box->container.ops = &box_ops; + box->container.component.ops = &box_comp_ops; box->chead.next = &box->ctail; - box->ctail.component = 0; box->ctail.prev = &box->chead; - box->ctail.next = 0; box->layout_func = layout_func; return box; } diff --git a/gfxmenu/gui_canvas.c b/gfxmenu/gui_canvas.c index d155364d7..8b55b2a73 100644 --- a/gfxmenu/gui_canvas.c +++ b/gfxmenu/gui_canvas.c @@ -32,13 +32,11 @@ struct component_node struct grub_gui_canvas { - struct grub_gui_container_ops *container; + struct grub_gui_container container; grub_gui_container_t parent; grub_video_rect_t bounds; char *id; - int preferred_width; - int preferred_height; /* Component list (dummy head node). */ struct component_node components; }; @@ -88,22 +86,52 @@ canvas_paint (void *vself, const grub_video_rect_t *region) grub_gui_set_viewport (&self->bounds, &vpsave); for (cur = self->components.next; cur; cur = cur->next) { - int pw; - int ph; grub_video_rect_t r; grub_gui_component_t comp; comp = cur->component; - /* Give the child its preferred size. */ - comp->ops->get_preferred_size (comp, &pw, &ph); - comp->ops->get_bounds (comp, &r); - if (r.width != pw || r.height != ph) - { - r.width = pw; - r.height = ph; - comp->ops->set_bounds (comp, &r); - } + r.x = 0; + r.y = 0; + r.width = 32; + r.height = 32; + + if (!comp->iswfrac && comp->w) + r.width = comp->w; + + if (!comp->ishfrac && comp->h) + r.height = comp->h; + + if (!comp->isxfrac && comp->x) + r.x = comp->x; + + if (!comp->isyfrac && comp->y) + r.y = comp->y; + + if (comp->ishfrac && comp->hfrac) + r.height = grub_fixed_ufu_multiply (self->bounds.height, comp->hfrac); + + if (comp->iswfrac && comp->wfrac) + r.width = grub_fixed_ufu_multiply (self->bounds.width, comp->wfrac); + + if (comp->isxfrac && comp->xfrac) + r.x = grub_fixed_ufu_multiply (self->bounds.width, comp->xfrac); + + if (comp->isyfrac && comp->yfrac) + r.y = grub_fixed_ufu_multiply (self->bounds.height, comp->yfrac); + + if (comp->ops->get_minimal_size) + { + unsigned mw; + unsigned mh; + comp->ops->get_minimal_size (comp, &mw, &mh); + if (r.width < mw) + r.width = mw; + if (r.height < mh) + r.height = mh; + } + + comp->ops->set_bounds (comp, &r); /* Paint the child. */ if (grub_video_have_common_points (region, &r)) @@ -140,20 +168,6 @@ canvas_get_bounds (void *vself, grub_video_rect_t *bounds) *bounds = self->bounds; } -static void -canvas_get_preferred_size (void *vself, int *width, int *height) -{ - grub_gui_canvas_t self = vself; - *width = 0; - *height = 0; - - /* Allow preferred dimensions to override the empty dimensions. */ - if (self->preferred_width >= 0) - *width = self->preferred_width; - if (self->preferred_height >= 0) - *height = self->preferred_height; -} - static grub_err_t canvas_set_property (void *vself, const char *name, const char *value) { @@ -170,15 +184,6 @@ canvas_set_property (void *vself, const char *name, const char *value) else self->id = 0; } - else if (grub_strcmp (name, "preferred_size") == 0) - { - int w; - int h; - if (grub_gui_parse_2_tuple (value, &w, &h) != GRUB_ERR_NONE) - return grub_errno; - self->preferred_width = w; - self->preferred_height = h; - } return grub_errno; } @@ -227,21 +232,21 @@ canvas_iterate_children (void *vself, cb (cur->component, userdata); } +static struct grub_gui_component_ops canvas_comp_ops = +{ + .destroy = canvas_destroy, + .get_id = canvas_get_id, + .is_instance = canvas_is_instance, + .paint = canvas_paint, + .set_parent = canvas_set_parent, + .get_parent = canvas_get_parent, + .set_bounds = canvas_set_bounds, + .get_bounds = canvas_get_bounds, + .set_property = canvas_set_property +}; + static struct grub_gui_container_ops canvas_ops = { - .component = - { - .destroy = canvas_destroy, - .get_id = canvas_get_id, - .is_instance = canvas_is_instance, - .paint = canvas_paint, - .set_parent = canvas_set_parent, - .get_parent = canvas_get_parent, - .set_bounds = canvas_set_bounds, - .get_bounds = canvas_get_bounds, - .get_preferred_size = canvas_get_preferred_size, - .set_property = canvas_set_property - }, .add = canvas_add, .remove = canvas_remove, .iterate_children = canvas_iterate_children @@ -251,19 +256,10 @@ grub_gui_container_t grub_gui_canvas_new (void) { grub_gui_canvas_t canvas; - canvas = grub_malloc (sizeof (*canvas)); + canvas = grub_zalloc (sizeof (*canvas)); if (! canvas) return 0; - canvas->container = &canvas_ops; - canvas->parent = 0; - canvas->bounds.x = 0; - canvas->bounds.y = 0; - canvas->bounds.width = 0; - canvas->bounds.height = 0; - canvas->id = 0; - canvas->preferred_width = -1; - canvas->preferred_height = -1; - canvas->components.component = 0; - canvas->components.next = 0; + canvas->container.ops = &canvas_ops; + canvas->container.component.ops = &canvas_comp_ops; return (grub_gui_container_t) canvas; } diff --git a/gfxmenu/gui_circular_progress.c b/gfxmenu/gui_circular_progress.c index f3c8bc3af..e57d1c236 100644 --- a/gfxmenu/gui_circular_progress.c +++ b/gfxmenu/gui_circular_progress.c @@ -28,13 +28,11 @@ struct grub_gui_circular_progress { - struct grub_gui_component_ops *circprog_ops; + struct grub_gui_component comp; grub_gui_container_t parent; grub_video_rect_t bounds; char *id; - int preferred_width; - int preferred_height; int visible; int start; int end; @@ -209,21 +207,6 @@ circprog_get_bounds (void *vself, grub_video_rect_t *bounds) *bounds = self->bounds; } -static void -circprog_get_preferred_size (void *vself, int *width, int *height) -{ - circular_progress_t self = vself; - - *width = 0; - *height = 0; - - /* Allow preferred dimensions to override the circprog dimensions. */ - if (self->preferred_width >= 0) - *width = self->preferred_width; - if (self->preferred_height >= 0) - *height = self->preferred_height; -} - static grub_err_t circprog_set_property (void *vself, const char *name, const char *value) { @@ -270,15 +253,6 @@ circprog_set_property (void *vself, const char *name, const char *value) grub_free (self->theme_dir); self->theme_dir = value ? grub_strdup (value) : 0; } - else if (grub_strcmp (name, "preferred_size") == 0) - { - int w; - int h; - if (grub_gui_parse_2_tuple (value, &w, &h) != GRUB_ERR_NONE) - return grub_errno; - self->preferred_width = w; - self->preferred_height = h; - } else if (grub_strcmp (name, "visible") == 0) { self->visible = grub_strcmp (value, "false") != 0; @@ -304,7 +278,6 @@ static struct grub_gui_component_ops circprog_ops = .get_parent = circprog_get_parent, .set_bounds = circprog_set_bounds, .get_bounds = circprog_get_bounds, - .get_preferred_size = circprog_get_preferred_size, .set_property = circprog_set_property }; @@ -312,32 +285,13 @@ grub_gui_component_t grub_gui_circular_progress_new (void) { circular_progress_t self; - self = grub_malloc (sizeof (*self)); + self = grub_zalloc (sizeof (*self)); if (! self) return 0; - self->circprog_ops = &circprog_ops; - self->parent = 0; - self->bounds.x = 0; - self->bounds.y = 0; - self->bounds.width = 0; - self->bounds.height = 0; - self->id = 0; - self->preferred_width = -1; - self->preferred_height = -1; + self->comp.ops = &circprog_ops; self->visible = 1; - self->start = 0; - self->end = 0; - self->value = 0; self->num_ticks = 64; self->start_angle = -64; - self->ticks_disappear = 0; - - self->theme_dir = 0; - self->need_to_load_pixmaps = 0; - self->center_file = 0; - self->tick_file = 0; - self->center_bitmap = 0; - self->tick_bitmap = 0; return (grub_gui_component_t) self; } diff --git a/gfxmenu/gui_image.c b/gfxmenu/gui_image.c index eb2ff1ee0..ef8bcbe9a 100644 --- a/gfxmenu/gui_image.c +++ b/gfxmenu/gui_image.c @@ -26,13 +26,11 @@ struct grub_gui_image { - struct grub_gui_component_ops *image; + struct grub_gui_component component; grub_gui_container_t parent; grub_video_rect_t bounds; char *id; - int preferred_width; - int preferred_height; struct grub_video_bitmap *raw_bitmap; struct grub_video_bitmap *bitmap; }; @@ -172,8 +170,9 @@ image_get_bounds (void *vself, grub_video_rect_t *bounds) *bounds = self->bounds; } +/* FIXME: inform rendering system it's not forced minimum. */ static void -image_get_preferred_size (void *vself, int *width, int *height) +image_get_minimal_size (void *vself, unsigned *width, unsigned *height) { grub_gui_image_t self = vself; @@ -187,12 +186,6 @@ image_get_preferred_size (void *vself, int *width, int *height) *width = 0; *height = 0; } - - /* Allow preferred dimensions to override the image dimensions. */ - if (self->preferred_width >= 0) - *width = self->preferred_width; - if (self->preferred_height >= 0) - *height = self->preferred_height; } static grub_err_t @@ -217,15 +210,6 @@ image_set_property (void *vself, const char *name, const char *value) grub_gui_image_t self = vself; if (grub_strcmp (name, "file") == 0) return load_image (self, value); - else if (grub_strcmp (name, "preferred_size") == 0) - { - int w; - int h; - if (grub_gui_parse_2_tuple (value, &w, &h) != GRUB_ERR_NONE) - return grub_errno; - self->preferred_width = w; - self->preferred_height = h; - } else if (grub_strcmp (name, "id") == 0) { grub_free (self->id); @@ -247,7 +231,7 @@ static struct grub_gui_component_ops image_ops = .get_parent = image_get_parent, .set_bounds = image_set_bounds, .get_bounds = image_get_bounds, - .get_preferred_size = image_get_preferred_size, + .get_minimal_size = image_get_minimal_size, .set_property = image_set_property }; @@ -255,20 +239,10 @@ grub_gui_component_t grub_gui_image_new (void) { grub_gui_image_t image; - image = grub_malloc (sizeof (*image)); + image = grub_zalloc (sizeof (*image)); if (! image) return 0; - image->image = &image_ops; - image->parent = 0; - image->bounds.x = 0; - image->bounds.y = 0; - image->bounds.width = 0; - image->bounds.height = 0; - image->id = 0; - image->preferred_width = -1; - image->preferred_height = -1; - image->raw_bitmap = 0; - image->bitmap = 0; + image->component.ops = &image_ops; return (grub_gui_component_t) image; } diff --git a/gfxmenu/gui_label.c b/gfxmenu/gui_label.c index 30474f52f..b2835ea1a 100644 --- a/gfxmenu/gui_label.c +++ b/gfxmenu/gui_label.c @@ -39,13 +39,11 @@ enum align_mode { struct grub_gui_label { - struct grub_gui_component_ops *label; + struct grub_gui_component comp; grub_gui_container_t parent; grub_video_rect_t bounds; char *id; - int preferred_width; - int preferred_height; int visible; char *text; grub_font_t font; @@ -140,18 +138,12 @@ label_get_bounds (void *vself, grub_video_rect_t *bounds) } static void -label_get_preferred_size (void *vself, int *width, int *height) +label_get_minimal_size (void *vself, unsigned *width, unsigned *height) { grub_gui_label_t self = vself; *width = grub_font_get_string_width (self->font, self->text); *height = (grub_font_get_ascent (self->font) + grub_font_get_descent (self->font)); - - /* Allow preferred dimensions to override the computed dimensions. */ - if (self->preferred_width >= 0) - *width = self->preferred_width; - if (self->preferred_height >= 0) - *height = self->preferred_height; } static grub_err_t @@ -189,16 +181,6 @@ label_set_property (void *vself, const char *name, const char *value) { self->visible = grub_strcmp (value, "false") != 0; } - else if (grub_strcmp (name, "preferred_size") == 0) - { - int w; - int h; - if (grub_gui_parse_2_tuple (value, &w, &h) == GRUB_ERR_NONE) - { - self->preferred_width = w; - self->preferred_height = h; - } - } else if (grub_strcmp (name, "id") == 0) { grub_free (self->id); @@ -220,7 +202,7 @@ static struct grub_gui_component_ops label_ops = .get_parent = label_get_parent, .set_bounds = label_set_bounds, .get_bounds = label_get_bounds, - .get_preferred_size = label_get_preferred_size, + .get_minimal_size = label_get_minimal_size, .set_property = label_set_property }; @@ -228,18 +210,10 @@ grub_gui_component_t grub_gui_label_new (void) { grub_gui_label_t label; - label = grub_malloc (sizeof (*label)); + label = grub_zalloc (sizeof (*label)); if (! label) return 0; - label->label = &label_ops; - label->parent = 0; - label->bounds.x = 0; - label->bounds.y = 0; - label->bounds.width = 0; - label->bounds.height = 0; - label->id = 0; - label->preferred_width = -1; - label->preferred_height = -1; + label->comp.ops = &label_ops; label->visible = 1; label->text = grub_strdup (""); label->font = grub_font_get ("Helvetica 10"); diff --git a/gfxmenu/gui_list.c b/gfxmenu/gui_list.c index bf6d94657..c55cfd85c 100644 --- a/gfxmenu/gui_list.c +++ b/gfxmenu/gui_list.c @@ -26,13 +26,11 @@ struct grub_gui_list_impl { - struct grub_gui_list_ops *list_ops; + struct grub_gui_list list; grub_gui_container_t parent; grub_video_rect_t bounds; char *id; - int preferred_width; - int preferred_height; int visible; int icon_width; @@ -357,7 +355,7 @@ list_get_bounds (void *vself, grub_video_rect_t *bounds) } static void -list_get_preferred_size (void *vself, int *width, int *height) +list_get_minimal_size (void *vself, unsigned *width, unsigned *height) { list_impl_t self = vself; @@ -387,12 +385,6 @@ list_get_preferred_size (void *vself, int *width, int *height) *width = 0; *height = 0; } - - /* Allow preferred dimensions to override the computed dimensions. */ - if (self->preferred_width >= 0) - *width = self->preferred_width; - if (self->preferred_height >= 0) - *height = self->preferred_height; } static grub_err_t @@ -507,15 +499,6 @@ list_set_property (void *vself, const char *name, const char *value) grub_free (self->theme_dir); self->theme_dir = value ? grub_strdup (value) : 0; } - else if (grub_strcmp (name, "preferred_size") == 0) - { - int w; - int h; - if (grub_gui_parse_2_tuple (value, &w, &h) != GRUB_ERR_NONE) - return grub_errno; - self->preferred_width = w; - self->preferred_height = h; - } else if (grub_strcmp (name, "id") == 0) { grub_free (self->id); @@ -538,21 +521,22 @@ list_set_view_info (void *vself, self->menu = menu; } +static struct grub_gui_component_ops list_comp_ops = + { + .destroy = list_destroy, + .get_id = list_get_id, + .is_instance = list_is_instance, + .paint = list_paint, + .set_parent = list_set_parent, + .get_parent = list_get_parent, + .set_bounds = list_set_bounds, + .get_bounds = list_get_bounds, + .get_minimal_size = list_get_minimal_size, + .set_property = list_set_property + }; + static struct grub_gui_list_ops list_ops = { - .component_ops = - { - .destroy = list_destroy, - .get_id = list_get_id, - .is_instance = list_is_instance, - .paint = list_paint, - .set_parent = list_set_parent, - .get_parent = list_get_parent, - .set_bounds = list_set_bounds, - .get_bounds = list_get_bounds, - .get_preferred_size = list_get_preferred_size, - .set_property = list_set_property - }, .set_view_info = list_set_view_info }; @@ -564,19 +548,13 @@ grub_gui_list_new (void) grub_gui_color_t default_fg_color; grub_gui_color_t default_bg_color; - self = grub_malloc (sizeof (*self)); + self = grub_zalloc (sizeof (*self)); if (! self) return 0; - self->list_ops = &list_ops; - self->parent = 0; - self->bounds.x = 0; - self->bounds.y = 0; - self->bounds.width = 0; - self->bounds.height = 0; - self->id = 0; - self->preferred_width = -1; - self->preferred_height = -1; + self->list.ops = &list_ops; + self->list.component.ops = &list_comp_ops; + self->visible = 1; default_font = grub_font_get ("Helvetica 12"); @@ -617,7 +595,7 @@ grub_gui_list_new (void) self->icon_manager = grub_gfxmenu_icon_manager_new (); if (! self->icon_manager) { - self->list_ops->component_ops.destroy (self); + self->list.component.ops->destroy (self); return 0; } grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager, diff --git a/gfxmenu/gui_progress_bar.c b/gfxmenu/gui_progress_bar.c index 498711169..9af93cff5 100644 --- a/gfxmenu/gui_progress_bar.c +++ b/gfxmenu/gui_progress_bar.c @@ -27,13 +27,11 @@ struct grub_gui_progress_bar { - struct grub_gui_component_ops *progress_bar; + struct grub_gui_component component; grub_gui_container_t parent; grub_video_rect_t bounds; char *id; - int preferred_width; - int preferred_height; int visible; int start; int end; @@ -221,18 +219,11 @@ progress_bar_get_bounds (void *vself, grub_video_rect_t *bounds) } static void -progress_bar_get_preferred_size (void *vself, int *width, int *height) +progress_bar_get_minimal_size (void *vself __attribute__ ((unused)), + unsigned *width, unsigned *height) { - grub_gui_progress_bar_t self = vself; - *width = 200; *height = 28; - - /* Allow preferred dimensions to override the progress_bar dimensions. */ - if (self->preferred_width >= 0) - *width = self->preferred_width; - if (self->preferred_height >= 0) - *height = self->preferred_height; } static grub_err_t @@ -296,15 +287,6 @@ progress_bar_set_property (void *vself, const char *name, const char *value) grub_free (self->theme_dir); self->theme_dir = value ? grub_strdup (value) : 0; } - else if (grub_strcmp (name, "preferred_size") == 0) - { - int w; - int h; - if (grub_gui_parse_2_tuple (value, &w, &h) != GRUB_ERR_NONE) - return grub_errno; - self->preferred_width = w; - self->preferred_height = h; - } else if (grub_strcmp (name, "visible") == 0) { self->visible = grub_strcmp (value, "false") != 0; @@ -334,7 +316,7 @@ static struct grub_gui_component_ops progress_bar_ops = .get_parent = progress_bar_get_parent, .set_bounds = progress_bar_set_bounds, .get_bounds = progress_bar_get_bounds, - .get_preferred_size = progress_bar_get_preferred_size, + .get_minimal_size = progress_bar_get_minimal_size, .set_property = progress_bar_set_property }; @@ -342,22 +324,11 @@ grub_gui_component_t grub_gui_progress_bar_new (void) { grub_gui_progress_bar_t self; - self = grub_malloc (sizeof (*self)); + self = grub_zalloc (sizeof (*self)); if (! self) return 0; - self->progress_bar = &progress_bar_ops; - self->parent = 0; - self->bounds.x = 0; - self->bounds.y = 0; - self->bounds.width = 0; - self->bounds.height = 0; - self->id = 0; - self->preferred_width = -1; - self->preferred_height = -1; + self->component.ops = &progress_bar_ops; self->visible = 1; - self->start = 0; - self->end = 0; - self->value = 0; self->show_text = 1; self->text = grub_strdup (""); self->font = grub_font_get ("Helvetica 10"); @@ -369,12 +340,5 @@ grub_gui_progress_bar_new (void) self->bg_color = gray; self->fg_color = lightgray; - self->theme_dir = 0; - self->need_to_recreate_pixmaps = 0; - self->bar_pattern = 0; - self->highlight_pattern = 0; - self->bar_box = 0; - self->highlight_box = 0; - return (grub_gui_component_t) self; } diff --git a/gfxmenu/gui_string_util.c b/gfxmenu/gui_string_util.c index 8ea7c497b..8c51e396a 100644 --- a/gfxmenu/gui_string_util.c +++ b/gfxmenu/gui_string_util.c @@ -325,41 +325,3 @@ grub_gui_parse_color (const char *s, grub_gui_color_t *color) *color = c; return grub_errno; } - -/* Parse a value in the form "(x, y)", storing the first element (x) into - *PX and the second element (y) into *PY. - Returns GRUB_ERR_NONE if successfully parsed. */ -grub_err_t -grub_gui_parse_2_tuple (const char *s, int *px, int *py) -{ - int x; - int y; - - while (*s && grub_isspace (*s)) - s++; - if (*s != '(') - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "missing `(' in 2-tuple `%s'", s); - - /* Skip the opening parentheses. */ - s++; - if (*s == 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "unexpected end of 2-tuple after `(' in `%s'", s); - - /* Parse the first element. */ - x = grub_strtol (s, 0, 10); - if ((s = grub_strchr (s, ',')) == 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "missing comma in 2-tuple `%s'", s); - - /* Skip the element separator (the comma). */ - s++; - /* Parse the second element. */ - y = grub_strtol (s, 0, 10); - - *px = x; - *py = y; - - return grub_errno; -} diff --git a/gfxmenu/theme_loader.c b/gfxmenu/theme_loader.c index 3512c7bf1..29bc1d2a6 100644 --- a/gfxmenu/theme_loader.c +++ b/gfxmenu/theme_loader.c @@ -510,35 +510,73 @@ read_object (struct parsebuf *p, grub_gui_container_t parent) } /* Handle the property value. */ - if (grub_strcmp (property, "position") == 0) + if (grub_strcmp (property, "left") == 0) { - /* Special case for position value. */ - int x; - int y; - - if (grub_gui_parse_2_tuple (value, &x, &y) == GRUB_ERR_NONE) - { - grub_video_rect_t r; - component->ops->get_bounds (component, &r); - r.x = x; - r.y = y; - component->ops->set_bounds (component, &r); - } + unsigned num; + char *ptr; + num = grub_strtoul (value, &ptr, 0); + if (*ptr == '%') + { + component->isxfrac = 1; + component->xfrac + = grub_fixed_fuf_divide (grub_unsigned_to_fixed (num), 100); + } + else + { + component->isxfrac = 0; + component->x = num; + } } - else if (grub_strcmp (property, "size") == 0) + else if (grub_strcmp (property, "top") == 0) { - /* Special case for size value. */ - int w; - int h; - - if (grub_gui_parse_2_tuple (value, &w, &h) == GRUB_ERR_NONE) - { - grub_video_rect_t r; - component->ops->get_bounds (component, &r); - r.width = w; - r.height = h; - component->ops->set_bounds (component, &r); - } + unsigned num; + char *ptr; + num = grub_strtoul (value, &ptr, 0); + if (*ptr == '%') + { + component->isyfrac = 1; + component->yfrac + = grub_fixed_fuf_divide (grub_unsigned_to_fixed (num), 100); + } + else + { + component->isyfrac = 0; + component->y = num; + } + } + else if (grub_strcmp (property, "width") == 0) + { + unsigned num; + char *ptr; + num = grub_strtoul (value, &ptr, 0); + if (*ptr == '%') + { + component->iswfrac = 1; + component->wfrac + = grub_fixed_fuf_divide (grub_unsigned_to_fixed (num), 100); + } + else + { + component->iswfrac = 0; + component->w = num; + } + } + else if (grub_strcmp (property, "height") == 0) + { + unsigned num; + char *ptr; + num = grub_strtoul (value, &ptr, 0); + if (*ptr == '%') + { + component->ishfrac = 1; + component->hfrac + = grub_fixed_fuf_divide (grub_unsigned_to_fixed (num), 100); + } + else + { + component->ishfrac = 0; + component->h = num; + } } else { @@ -552,16 +590,6 @@ read_object (struct parsebuf *p, grub_gui_container_t parent) goto cleanup; } - /* Set the object's size to its preferred size unless the user has - explicitly specified the size. */ - component->ops->get_bounds (component, &bounds); - if (bounds.width == -1 || bounds.height == -1) - { - component->ops->get_preferred_size (component, - &bounds.width, &bounds.height); - component->ops->set_bounds (component, &bounds); - } - cleanup: grub_free (name); return grub_errno; @@ -665,7 +693,7 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path) } if (view->canvas) - view->canvas->ops->component.destroy (view->canvas); + view->canvas->component.ops->destroy (view->canvas); view->canvas = grub_gui_canvas_new (); ((grub_gui_component_t) view->canvas) @@ -708,7 +736,7 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path) fail: if (view->canvas) { - view->canvas->ops->component.destroy (view->canvas); + view->canvas->component.ops->destroy (view->canvas); view->canvas = 0; } diff --git a/gfxmenu/view.c b/gfxmenu/view.c index e2348b6ef..414541dda 100644 --- a/gfxmenu/view.c +++ b/gfxmenu/view.c @@ -146,7 +146,7 @@ grub_gfxmenu_view_destroy (grub_gfxmenu_view_t view) grub_free (view->progress_message_text); grub_free (view->theme_path); if (view->canvas) - view->canvas->ops->component.destroy (view->canvas); + view->canvas->component.ops->destroy (view->canvas); grub_free (view); set_text_mode (); @@ -354,7 +354,7 @@ grub_gfxmenu_view_redraw (grub_gfxmenu_view_t view, redraw_background (view, region); if (view->canvas) - view->canvas->ops->component.paint (view->canvas, region); + view->canvas->component.ops->paint (view->canvas, region); draw_title (view); if (grub_video_have_common_points (&view->progress_message_frame, region)) draw_message (view); diff --git a/include/grub/gui.h b/include/grub/gui.h index 385c0962b..873d29e76 100644 --- a/include/grub/gui.h +++ b/include/grub/gui.h @@ -55,14 +55,13 @@ struct grub_gui_component_ops grub_gui_container_t (*get_parent) (void *self); void (*set_bounds) (void *self, const grub_video_rect_t *bounds); void (*get_bounds) (void *self, grub_video_rect_t *bounds); - void (*get_preferred_size) (void *self, int *width, int *height); + void (*get_minimal_size) (void *self, unsigned *width, unsigned *height); grub_err_t (*set_property) (void *self, const char *name, const char *value); void (*repaint) (void *self, int second_pass); }; struct grub_gui_container_ops { - struct grub_gui_component_ops component; void (*add) (void *self, grub_gui_component_t comp); void (*remove) (void *self, grub_gui_component_t comp); void (*iterate_children) (void *self, @@ -71,24 +70,78 @@ struct grub_gui_container_ops struct grub_gui_list_ops { - struct grub_gui_component_ops component_ops; void (*set_view_info) (void *self, const char *theme_path, grub_gfxmenu_model_t menu); }; +typedef grub_uint32_t grub_fixed_unsigned_t; +#define GRUB_FIXED_1 0x10000 + +static inline unsigned +grub_fixed_ufu_divide (grub_uint32_t a, grub_fixed_unsigned_t b) +{ + return (a << 16) / b; +} + +static inline grub_fixed_unsigned_t +grub_fixed_fuf_divide (grub_fixed_unsigned_t a, grub_uint32_t b) +{ + return a / b; +} + +static inline unsigned +grub_fixed_ufu_multiply (grub_uint32_t a, grub_fixed_unsigned_t b) +{ + return (a * b) >> 16; +} + +static inline unsigned +grub_fixed_to_unsigned (grub_fixed_unsigned_t in) +{ + return in >> 16; +} + +static inline grub_fixed_unsigned_t +grub_unsigned_to_fixed (unsigned in) +{ + return in << 16; +} + struct grub_gui_component { struct grub_gui_component_ops *ops; + int isxfrac:1; + int isyfrac:1; + int iswfrac:1; + int ishfrac:1; + union { + unsigned x; + grub_fixed_unsigned_t xfrac; + }; + union { + unsigned y; + grub_fixed_unsigned_t yfrac; + }; + union { + unsigned w; + grub_fixed_unsigned_t wfrac; + }; + union { + unsigned h; + grub_fixed_unsigned_t hfrac; + }; }; struct grub_gui_container { + struct grub_gui_component component; struct grub_gui_container_ops *ops; }; struct grub_gui_list { + struct grub_gui_component component; struct grub_gui_list_ops *ops; }; diff --git a/include/grub/gui_string_util.h b/include/grub/gui_string_util.h index 7b5fbb3ea..1baa2eede 100644 --- a/include/grub/gui_string_util.h +++ b/include/grub/gui_string_util.h @@ -34,6 +34,4 @@ int grub_gui_get_named_color (const char *name, grub_gui_color_t *color); grub_err_t grub_gui_parse_color (const char *s, grub_gui_color_t *color); -grub_err_t grub_gui_parse_2_tuple (const char *s, int *px, int *py); - #endif /* GRUB_GUI_STRING_UTIL_HEADER */ diff --git a/include/grub/video.h b/include/grub/video.h index 833df04c8..868e87871 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -160,10 +160,10 @@ struct grub_video_mode_info /* A 2D rectangle type. */ struct grub_video_rect { - int x; - int y; - int width; - int height; + unsigned x; + unsigned y; + unsigned width; + unsigned height; }; typedef struct grub_video_rect grub_video_rect_t; From 7a68c375f36455f16d5aeae14d9055bb164537aa Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Dec 2009 17:57:20 +0100 Subject: [PATCH 041/237] Fix warnings --- gfxmenu/gfxmenu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gfxmenu/gfxmenu.c b/gfxmenu/gfxmenu.c index 1fe6e7297..1db96a80f 100644 --- a/gfxmenu/gfxmenu.c +++ b/gfxmenu/gfxmenu.c @@ -39,13 +39,13 @@ grub_gfxmenu_view_t cached_view; -void +static void grub_gfxmenu_viewer_fini (void *data __attribute__ ((unused))) { } /* FIXME: Previously 't' changed to text menu is it necessary? */ -grub_err_t +static grub_err_t grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) { grub_gfxmenu_view_t view = NULL; @@ -76,8 +76,8 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) } if (!cached_view || grub_strcmp (cached_view->theme_path, theme_path) != 0 - || cached_view->screen.width != (int) mode_info.width - || cached_view->screen.height != (int) mode_info.height) + || cached_view->screen.width != mode_info.width + || cached_view->screen.height != mode_info.height) { grub_free (cached_view); /* Create the view. */ From f8882fe8f92af456ebd629038d931276bdb0a1ff Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Dec 2009 22:50:38 +0100 Subject: [PATCH 042/237] Fix mismerge --- normal/menu.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/normal/menu.c b/normal/menu.c index 850350edd..17730eff3 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -232,9 +232,6 @@ menu_fini (void) viewers = NULL; } -/* FIXME: allow text menu in parallel with gfxmenu. */ -grub_err_t (*grub_gfxmenu_try_hook) (int entry, grub_menu_t menu, - int nested) = NULL; static void menu_init (int entry, grub_menu_t menu, int nested) { From b9da1700808ea5d8492aaf7c9daa0dcc048e5271 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jan 2010 19:38:11 +0100 Subject: [PATCH 043/237] Preliminary support for mixed percent and linear declarations --- gfxmenu/gui_box.c | 50 ++++++++----------- gfxmenu/gui_canvas.c | 66 +++++++++++++------------ gfxmenu/theme_loader.c | 108 +++++++++++++++-------------------------- include/grub/gui.h | 58 +++++++++------------- 4 files changed, 117 insertions(+), 165 deletions(-) diff --git a/gfxmenu/gui_box.c b/gfxmenu/gui_box.c index 45028e5b1..38b15f96d 100644 --- a/gfxmenu/gui_box.c +++ b/gfxmenu/gui_box.c @@ -93,7 +93,7 @@ layout_horizontally (grub_gui_box_t self, int modify_layout, struct component_node *cur; unsigned w = 0, mwfrac = 0, h = 0, x = 0; - grub_fixed_unsigned_t wfrac = 0; + grub_fixed_signed_t wfrac = 0; int bogus_frac = 0; for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) @@ -104,17 +104,14 @@ layout_horizontally (grub_gui_box_t self, int modify_layout, if (c->ops->get_minimal_size) c->ops->get_minimal_size (c, &mw, &mh); - if (!c->ishfrac && c->h > h) + if (c->h > (signed) h) h = c->h; if (mh > h) h = mh; - if (!c->iswfrac) - w += mw > c->w ? mw : c->w; - if (c->iswfrac) - { - wfrac += c->wfrac; - mwfrac += mw; - } + wfrac += c->wfrac; + w += c->w; + if (mw - c->w > 0) + mwfrac += mw - c->w; } if (wfrac > GRUB_FIXED_1 || (w > 0 && wfrac == GRUB_FIXED_1)) bogus_frac = 1; @@ -122,7 +119,7 @@ layout_horizontally (grub_gui_box_t self, int modify_layout, if (min_width) { if (wfrac < GRUB_FIXED_1) - *min_width = grub_fixed_ufu_divide (w, GRUB_FIXED_1 - wfrac); + *min_width = grub_fixed_sfs_divide (w, GRUB_FIXED_1 - wfrac); else *min_width = w; if (*min_width < w + mwfrac) @@ -142,16 +139,14 @@ layout_horizontally (grub_gui_box_t self, int modify_layout, r.x = x; r.y = 0; - r.width = 32; r.height = h; if (c->ops->get_minimal_size) c->ops->get_minimal_size (c, &mw, &mh); - if (!c->iswfrac) - r.width = c->w; - if (c->iswfrac && !bogus_frac) - r.width = grub_fixed_ufu_multiply (self->bounds.width, c->wfrac); + r.width = c->w; + if (!bogus_frac) + r.width += grub_fixed_sfs_multiply (self->bounds.width, c->wfrac); if (r.width < mw) r.width = mw; @@ -171,7 +166,7 @@ layout_vertically (grub_gui_box_t self, int modify_layout, struct component_node *cur; unsigned h = 0, mhfrac = 0, w = 0, y = 0; - grub_fixed_unsigned_t hfrac = 0; + grub_fixed_signed_t hfrac = 0; int bogus_frac = 0; for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) @@ -182,17 +177,14 @@ layout_vertically (grub_gui_box_t self, int modify_layout, if (c->ops->get_minimal_size) c->ops->get_minimal_size (c, &mw, &mh); - if (!c->iswfrac && c->w > w) + if (c->w > (signed) w) w = c->w; if (mw > w) w = mw; - if (!c->ishfrac) - h += mh > c->h ? mh : c->h; - if (c->ishfrac) - { - hfrac += c->hfrac; - mhfrac += mh; - } + hfrac += c->hfrac; + h += c->h; + if (mh - c->h > 0) + mhfrac += mh - c->h; } if (hfrac > GRUB_FIXED_1 || (h > 0 && hfrac == GRUB_FIXED_1)) bogus_frac = 1; @@ -200,7 +192,7 @@ layout_vertically (grub_gui_box_t self, int modify_layout, if (min_height) { if (hfrac < GRUB_FIXED_1) - *min_height = grub_fixed_ufu_divide (h, GRUB_FIXED_1 - hfrac); + *min_height = grub_fixed_sfs_divide (h, GRUB_FIXED_1 - hfrac); else *min_height = h; if (*min_height < h + mhfrac) @@ -221,15 +213,13 @@ layout_vertically (grub_gui_box_t self, int modify_layout, r.x = 0; r.y = y; r.width = w; - r.height = 32; if (c->ops->get_minimal_size) c->ops->get_minimal_size (c, &mw, &mh); - if (!c->ishfrac) - r.height = c->h; - if (c->ishfrac) - r.height = grub_fixed_ufu_multiply (self->bounds.height, c->hfrac); + r.height = c->h; + if (!bogus_frac) + r.height += grub_fixed_sfs_multiply (self->bounds.height, c->hfrac); if (r.height < mh) r.height = mh; diff --git a/gfxmenu/gui_canvas.c b/gfxmenu/gui_canvas.c index 8b55b2a73..b3919c2d3 100644 --- a/gfxmenu/gui_canvas.c +++ b/gfxmenu/gui_canvas.c @@ -88,49 +88,51 @@ canvas_paint (void *vself, const grub_video_rect_t *region) { grub_video_rect_t r; grub_gui_component_t comp; + signed x, y, w, h; comp = cur->component; - r.x = 0; - r.y = 0; - r.width = 32; - r.height = 32; - - if (!comp->iswfrac && comp->w) - r.width = comp->w; - - if (!comp->ishfrac && comp->h) - r.height = comp->h; - - if (!comp->isxfrac && comp->x) - r.x = comp->x; - - if (!comp->isyfrac && comp->y) - r.y = comp->y; - - if (comp->ishfrac && comp->hfrac) - r.height = grub_fixed_ufu_multiply (self->bounds.height, comp->hfrac); - - if (comp->iswfrac && comp->wfrac) - r.width = grub_fixed_ufu_multiply (self->bounds.width, comp->wfrac); - - if (comp->isxfrac && comp->xfrac) - r.x = grub_fixed_ufu_multiply (self->bounds.width, comp->xfrac); - - if (comp->isyfrac && comp->yfrac) - r.y = grub_fixed_ufu_multiply (self->bounds.height, comp->yfrac); + w = grub_fixed_sfs_multiply (self->bounds.width, comp->wfrac) + comp->w; + h = grub_fixed_sfs_multiply (self->bounds.height, comp->hfrac) + comp->h; + x = grub_fixed_sfs_multiply (self->bounds.width, comp->xfrac) + comp->x; + y = grub_fixed_sfs_multiply (self->bounds.height, comp->yfrac) + comp->y; if (comp->ops->get_minimal_size) { unsigned mw; unsigned mh; comp->ops->get_minimal_size (comp, &mw, &mh); - if (r.width < mw) - r.width = mw; - if (r.height < mh) - r.height = mh; + if (w < (signed) mw) + w = mw; + if (h < (signed) mh) + h = mh; } + /* Sanity checks. */ + if (w <= 0) + w = 32; + if (h <= 0) + h = 32; + + if (x >= (signed) self->bounds.width) + x = self->bounds.width - 32; + if (y >= (signed) self->bounds.height) + y = self->bounds.height - 32; + + if (x < 0) + x = 0; + if (y < 0) + y = 0; + + if (x + w >= (signed) self->bounds.width) + w = self->bounds.width - x; + if (y + h >= (signed) self->bounds.height) + h = self->bounds.height - y; + + r.x = x; + r.y = y; + r.width = w; + r.height = h; comp->ops->set_bounds (comp, &r); /* Paint the child. */ diff --git a/gfxmenu/theme_loader.c b/gfxmenu/theme_loader.c index 29bc1d2a6..09637d6b4 100644 --- a/gfxmenu/theme_loader.c +++ b/gfxmenu/theme_loader.c @@ -361,6 +361,40 @@ read_expression (struct parsebuf *p) return grub_new_substring (p->buf, start, end); } +static grub_err_t +parse_proportional_spec (char *value, signed *abs, grub_fixed_signed_t *prop) +{ + signed num; + char *ptr; + int sig = 0; + *abs = 0; + *prop = 0; + ptr = value; + while (*ptr) + { + sig = 0; + + while (*ptr == '-' || *ptr == '+') + { + if (*ptr == '-') + sig = !sig; + ptr++; + } + + num = grub_strtoul (ptr, &ptr, 0); + if (grub_errno) + return grub_errno; + if (sig) + num = -num; + if (*ptr == '%') + *prop += grub_fixed_fsf_divide (grub_signed_to_fixed (num), 100); + else + *abs += num; + } + return GRUB_ERR_NONE; +} + + /* Read a GUI object specification from the theme file. Any components created will be added to the GUI container PARENT. */ static grub_err_t @@ -511,78 +545,16 @@ read_object (struct parsebuf *p, grub_gui_container_t parent) /* Handle the property value. */ if (grub_strcmp (property, "left") == 0) - { - unsigned num; - char *ptr; - num = grub_strtoul (value, &ptr, 0); - if (*ptr == '%') - { - component->isxfrac = 1; - component->xfrac - = grub_fixed_fuf_divide (grub_unsigned_to_fixed (num), 100); - } - else - { - component->isxfrac = 0; - component->x = num; - } - } + parse_proportional_spec (value, &component->x, &component->xfrac); else if (grub_strcmp (property, "top") == 0) - { - unsigned num; - char *ptr; - num = grub_strtoul (value, &ptr, 0); - if (*ptr == '%') - { - component->isyfrac = 1; - component->yfrac - = grub_fixed_fuf_divide (grub_unsigned_to_fixed (num), 100); - } - else - { - component->isyfrac = 0; - component->y = num; - } - } + parse_proportional_spec (value, &component->y, &component->yfrac); else if (grub_strcmp (property, "width") == 0) - { - unsigned num; - char *ptr; - num = grub_strtoul (value, &ptr, 0); - if (*ptr == '%') - { - component->iswfrac = 1; - component->wfrac - = grub_fixed_fuf_divide (grub_unsigned_to_fixed (num), 100); - } - else - { - component->iswfrac = 0; - component->w = num; - } - } + parse_proportional_spec (value, &component->w, &component->wfrac); else if (grub_strcmp (property, "height") == 0) - { - unsigned num; - char *ptr; - num = grub_strtoul (value, &ptr, 0); - if (*ptr == '%') - { - component->ishfrac = 1; - component->hfrac - = grub_fixed_fuf_divide (grub_unsigned_to_fixed (num), 100); - } - else - { - component->ishfrac = 0; - component->h = num; - } - } + parse_proportional_spec (value, &component->h, &component->hfrac); else - { - /* General property handling. */ - component->ops->set_property (component, property, value); - } + /* General property handling. */ + component->ops->set_property (component, property, value); grub_free (value); grub_free (property); diff --git a/include/grub/gui.h b/include/grub/gui.h index 873d29e76..7c4774838 100644 --- a/include/grub/gui.h +++ b/include/grub/gui.h @@ -75,62 +75,50 @@ struct grub_gui_list_ops grub_gfxmenu_model_t menu); }; -typedef grub_uint32_t grub_fixed_unsigned_t; +typedef signed grub_fixed_signed_t; #define GRUB_FIXED_1 0x10000 -static inline unsigned -grub_fixed_ufu_divide (grub_uint32_t a, grub_fixed_unsigned_t b) +static inline signed +grub_fixed_sfs_divide (signed a, grub_fixed_signed_t b) { - return (a << 16) / b; + return (a * GRUB_FIXED_1) / b; } -static inline grub_fixed_unsigned_t -grub_fixed_fuf_divide (grub_fixed_unsigned_t a, grub_uint32_t b) +static inline grub_fixed_signed_t +grub_fixed_fsf_divide (grub_fixed_signed_t a, signed b) { return a / b; } -static inline unsigned -grub_fixed_ufu_multiply (grub_uint32_t a, grub_fixed_unsigned_t b) +static inline signed +grub_fixed_sfs_multiply (signed a, grub_fixed_signed_t b) { - return (a * b) >> 16; + return (a * b) / GRUB_FIXED_1; } -static inline unsigned -grub_fixed_to_unsigned (grub_fixed_unsigned_t in) +static inline signed +grub_fixed_to_signed (grub_fixed_signed_t in) { - return in >> 16; + return in / GRUB_FIXED_1; } -static inline grub_fixed_unsigned_t -grub_unsigned_to_fixed (unsigned in) +static inline grub_fixed_signed_t +grub_signed_to_fixed (signed in) { - return in << 16; + return in * GRUB_FIXED_1; } struct grub_gui_component { struct grub_gui_component_ops *ops; - int isxfrac:1; - int isyfrac:1; - int iswfrac:1; - int ishfrac:1; - union { - unsigned x; - grub_fixed_unsigned_t xfrac; - }; - union { - unsigned y; - grub_fixed_unsigned_t yfrac; - }; - union { - unsigned w; - grub_fixed_unsigned_t wfrac; - }; - union { - unsigned h; - grub_fixed_unsigned_t hfrac; - }; + signed x; + grub_fixed_signed_t xfrac; + signed y; + grub_fixed_signed_t yfrac; + signed w; + grub_fixed_signed_t wfrac; + signed h; + grub_fixed_signed_t hfrac; }; struct grub_gui_container From 6812d2e72d05e88645c8daabf72c3848170a5b91 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jan 2010 21:06:27 +0100 Subject: [PATCH 044/237] Fix non-skipping of percent sign --- gfxmenu/theme_loader.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gfxmenu/theme_loader.c b/gfxmenu/theme_loader.c index 09637d6b4..3854c6c53 100644 --- a/gfxmenu/theme_loader.c +++ b/gfxmenu/theme_loader.c @@ -387,7 +387,10 @@ parse_proportional_spec (char *value, signed *abs, grub_fixed_signed_t *prop) if (sig) num = -num; if (*ptr == '%') - *prop += grub_fixed_fsf_divide (grub_signed_to_fixed (num), 100); + { + *prop += grub_fixed_fsf_divide (grub_signed_to_fixed (num), 100); + ptr++; + } else *abs += num; } From be42af388421dcb922fb8b55388f2b852df4d275 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jan 2010 21:07:06 +0100 Subject: [PATCH 045/237] Compute list size automatically --- gfxmenu/gui_list.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/gfxmenu/gui_list.c b/gfxmenu/gui_list.c index c55cfd85c..b4886a2cc 100644 --- a/gfxmenu/gui_list.c +++ b/gfxmenu/gui_list.c @@ -53,8 +53,6 @@ struct grub_gui_list_impl grub_gfxmenu_box_t scrollbar_thumb; int scrollbar_width; - int min_items_shown; - int max_items_shown; int first_shown_index; int need_to_recreate_boxes; @@ -91,12 +89,16 @@ list_destroy (void *vself) static int get_num_shown_items (list_impl_t self) { - int n = grub_gfxmenu_model_get_num_entries (self->menu); - if (self->min_items_shown != -1 && n < self->min_items_shown) - n = self->min_items_shown; - if (self->max_items_shown != -1 && n > self->max_items_shown) - n = self->max_items_shown; - return n; + int boxpad = self->item_padding; + int item_vspace = self->item_spacing; + int item_height = self->item_height; + + grub_gfxmenu_box_t box = self->menu_box; + int box_top_pad = box->get_top_pad (box); + int box_bottom_pad = box->get_bottom_pad (box); + + return (self->bounds.height + item_vspace - 2 * boxpad + - box_top_pad - box_bottom_pad) / (item_height + item_vspace); } static int @@ -364,15 +366,22 @@ list_get_minimal_size (void *vself, unsigned *width, unsigned *height) int boxpad = self->item_padding; int item_vspace = self->item_spacing; int item_height = self->item_height; - int num_items = get_num_shown_items (self); + int num_items = 3; grub_gfxmenu_box_t box = self->menu_box; int box_left_pad = box->get_left_pad (box); int box_top_pad = box->get_top_pad (box); int box_right_pad = box->get_right_pad (box); int box_bottom_pad = box->get_bottom_pad (box); + unsigned width_s; + + *width = grub_font_get_string_width (self->item_font, "Typical OS"); + width_s = grub_font_get_string_width (self->selected_item_font, + "Typical OS"); + if (*width < width_s) + *width = width_s; - *width = 400 + 2 * boxpad + box_left_pad + box_right_pad; + *width += 2 * boxpad + box_left_pad + box_right_pad; /* Set the menu box height to fit the items. */ *height = (item_height * num_items @@ -485,14 +494,6 @@ list_set_property (void *vself, const char *name, const char *value) { self->draw_scrollbar = grub_strcmp (value, "false") != 0; } - else if (grub_strcmp (name, "min_items_shown") == 0) - { - self->min_items_shown = grub_strtol (value, 0, 10); - } - else if (grub_strcmp (name, "max_items_shown") == 0) - { - self->max_items_shown = grub_strtol (value, 0, 10); - } else if (grub_strcmp (name, "theme_dir") == 0) { self->need_to_recreate_boxes = 1; @@ -581,8 +582,6 @@ grub_gui_list_new (void) self->scrollbar_thumb_pattern = 0; self->scrollbar_width = 16; - self->min_items_shown = -1; - self->max_items_shown = -1; self->first_shown_index = 0; self->need_to_recreate_boxes = 0; From eb1c959440899c2bfd7dbc514b5ec11b17a2a283 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jan 2010 21:24:33 +0100 Subject: [PATCH 046/237] grub-mkconfig support for themes --- util/grub-mkconfig.in | 1 + util/grub.d/00_header.in | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index 49e52b313..7e667fb3e 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -220,6 +220,7 @@ export GRUB_DEFAULT \ GRUB_DISABLE_LINUX_UUID \ GRUB_DISABLE_LINUX_RECOVERY \ GRUB_GFXMODE \ + GRUB_THEME \ GRUB_DISABLE_OS_PROBER if test "x${grub_cfg}" != "x"; then diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 0adfe6b76..da394783a 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -93,6 +93,15 @@ if loadfont `make_system_path_relative_to_its_root ${GRUB_FONT_PATH}` ; then # understand terminal_output terminal gfxterm fi +EOF +if [ x$GRUB_THEME != x ] && [ -f $GRUB_THEME ] \ + && is_path_readable_by_grub $GRUB_THEME; then + echo "Found theme: $GRUB_THEME" >&2 + prepare_grub_to_access_device `${grub_probe} --target=device $GRUB_THEME` + echo "insmod gfxmenu" + echo "set theme=(\$root)/`make_system_path_relative_to_its_root $GRUB_THEME`" +fi + cat << EOF fi EOF ;; From b9d28aa05fdd761074189b0acb1f3fd666f3894e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jan 2010 23:22:02 +0100 Subject: [PATCH 047/237] Fix missing viewport in gui_list --- gfxmenu/gui_list.c | 82 +++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/gfxmenu/gui_list.c b/gfxmenu/gui_list.c index b4886a2cc..fd0f11635 100644 --- a/gfxmenu/gui_list.c +++ b/gfxmenu/gui_list.c @@ -209,7 +209,8 @@ draw_scrollbar (list_impl_t self, /* Draw the list of items. */ static void -draw_menu (list_impl_t self) +draw_menu (list_impl_t self, int width, int drawing_scrollbar, + int num_shown_items) { if (! self->menu_box || ! self->selected_item_box) return; @@ -222,38 +223,19 @@ draw_menu (list_impl_t self) int descent = grub_font_get_descent (self->item_font); int item_height = self->item_height; - int total_num_items = grub_gfxmenu_model_get_num_entries (self->menu); - int num_shown_items = get_num_shown_items (self); - grub_gfxmenu_box_t box = self->menu_box; - int width = self->bounds.width; - int height = self->bounds.height; - - int box_left_pad = box->get_left_pad (box); - int box_top_pad = box->get_top_pad (box); - int box_right_pad = box->get_right_pad (box); - int box_bottom_pad = box->get_bottom_pad (box); - - box->set_content_size (box, - width - box_left_pad - box_right_pad, - height - box_top_pad - box_bottom_pad); - - box->draw (box, 0, 0); - make_selected_item_visible (self); - int drawing_scrollbar = (self->draw_scrollbar - && (num_shown_items < total_num_items) - && check_scrollbar (self)); - int scrollbar_h_space = drawing_scrollbar ? self->scrollbar_width : 0; - int item_top = box_top_pad + boxpad; - int item_left = box_left_pad + boxpad; + grub_gfxmenu_box_t selbox = self->selected_item_box; + int sel_leftpad = selbox->get_left_pad (selbox); + int item_top = boxpad; + int item_left = boxpad + sel_leftpad; int menu_index; int visible_index; for (visible_index = 0, menu_index = self->first_shown_index; - visible_index < num_shown_items && menu_index < total_num_items; + visible_index < num_shown_items && menu_index < self->menu->size; visible_index++, menu_index++) { int is_selected = @@ -261,12 +243,9 @@ draw_menu (list_impl_t self) if (is_selected) { - grub_gfxmenu_box_t selbox = self->selected_item_box; - int sel_leftpad = selbox->get_left_pad (selbox); int sel_toppad = selbox->get_top_pad (selbox); selbox->set_content_size (selbox, (width - 2 * boxpad - - box_left_pad - box_right_pad - scrollbar_h_space), item_height); selbox->draw (selbox, @@ -300,14 +279,6 @@ draw_menu (list_impl_t self) item_top += item_height + item_vspace; } - - if (drawing_scrollbar) - draw_scrollbar (self, - self->first_shown_index, num_shown_items, - 0, total_num_items, - width - box_right_pad + self->scrollbar_width, - box_top_pad + boxpad, - height - box_top_pad - box_bottom_pad); } static void @@ -323,8 +294,45 @@ list_paint (void *vself, const grub_video_rect_t *region) check_boxes (self); + if (! self->menu_box || ! self->selected_item_box) + return; + grub_gui_set_viewport (&self->bounds, &vpsave); - draw_menu (self); + { + grub_gfxmenu_box_t box = self->menu_box; + int box_left_pad = box->get_left_pad (box); + int box_top_pad = box->get_top_pad (box); + int box_right_pad = box->get_right_pad (box); + int box_bottom_pad = box->get_bottom_pad (box); + grub_video_rect_t vpsave2, content_rect; + int num_shown_items = get_num_shown_items (self); + int drawing_scrollbar = (self->draw_scrollbar + && (num_shown_items < self->menu->size) + && check_scrollbar (self)); + + content_rect.x = box_left_pad; + content_rect.y = box_top_pad; + content_rect.width = self->bounds.width - box_left_pad - box_right_pad; + content_rect.height = self->bounds.height - box_top_pad - box_bottom_pad; + + box->set_content_size (box, content_rect.width, content_rect.height); + + box->draw (box, 0, 0); + + grub_gui_set_viewport (&content_rect, &vpsave2); + draw_menu (self, content_rect.width, drawing_scrollbar, num_shown_items); + grub_gui_restore_viewport (&vpsave2); + + if (drawing_scrollbar) + draw_scrollbar (self, + self->first_shown_index, num_shown_items, + 0, self->menu->size, + content_rect.width - box_right_pad + + self->scrollbar_width, + box_top_pad + self->item_padding, + content_rect.height - box_top_pad - box_bottom_pad); + } + grub_gui_restore_viewport (&vpsave); } From ea51afb099a6a88288f6b4f0800b16e0ca76d9dc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jan 2010 23:49:40 +0100 Subject: [PATCH 048/237] Use pixmapbar only when images available --- gfxmenu/gui_progress_bar.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gfxmenu/gui_progress_bar.c b/gfxmenu/gui_progress_bar.c index 9af93cff5..95be91e2a 100644 --- a/gfxmenu/gui_progress_bar.c +++ b/gfxmenu/gui_progress_bar.c @@ -46,6 +46,7 @@ struct grub_gui_progress_bar char *theme_dir; int need_to_recreate_pixmaps; + int pixmapbar_available; char *bar_pattern; char *highlight_pattern; grub_gfxmenu_box_t bar_box; @@ -77,6 +78,8 @@ progress_bar_is_instance (void *vself __attribute__((unused)), const char *type) static int check_pixmaps (grub_gui_progress_bar_t self) { + if (!self->pixmapbar_available) + return 0; if (self->need_to_recreate_pixmaps) { grub_gui_recreate_box (&self->bar_box, @@ -137,6 +140,7 @@ draw_pixmap_bar (grub_gui_progress_bar_t self) int bar_v_pad = bar_t_pad + bar_b_pad; int tracklen = w - bar_h_pad; int trackheight = h - bar_v_pad; + bar->set_content_size (bar, tracklen, trackheight); int barwidth = (tracklen @@ -172,12 +176,16 @@ static void progress_bar_paint (void *vself, const grub_video_rect_t *region) { grub_gui_progress_bar_t self = vself; + grub_video_rect_t vpsave; + if (! self->visible) return; if (!grub_video_have_common_points (region, &self->bounds)) return; - grub_video_rect_t vpsave; + if (self->end == self->start) + return; + grub_gui_set_viewport (&self->bounds, &vpsave); if (check_pixmaps (self)) @@ -272,12 +280,14 @@ progress_bar_set_property (void *vself, const char *name, const char *value) else if (grub_strcmp (name, "bar_style") == 0) { self->need_to_recreate_pixmaps = 1; + self->pixmapbar_available = 1; grub_free (self->bar_pattern); self->bar_pattern = value ? grub_strdup (value) : 0; } else if (grub_strcmp (name, "highlight_style") == 0) { self->need_to_recreate_pixmaps = 1; + self->pixmapbar_available = 1; grub_free (self->highlight_pattern); self->highlight_pattern = value ? grub_strdup (value) : 0; } From 4d253049d5139b34e35154e74850d3c68e4d0b8b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jan 2010 01:42:21 +0100 Subject: [PATCH 049/237] Fix non-clearing of timeout. Template support for timeout text. --- gfxmenu/gui_circular_progress.c | 39 +++++++------- gfxmenu/gui_progress_bar.c | 96 +++++++++++++++++++++------------ gfxmenu/view.c | 44 ++++++--------- include/grub/gui.h | 11 ++++ normal/menu.c | 2 + 5 files changed, 110 insertions(+), 82 deletions(-) diff --git a/gfxmenu/gui_circular_progress.c b/gfxmenu/gui_circular_progress.c index 7634c368d..9a859ee2e 100644 --- a/gfxmenu/gui_circular_progress.c +++ b/gfxmenu/gui_circular_progress.c @@ -28,7 +28,7 @@ struct grub_gui_circular_progress { - struct grub_gui_component comp; + struct grub_gui_progress progress; grub_gui_container_t parent; grub_video_rect_t bounds; @@ -215,19 +215,7 @@ static grub_err_t circprog_set_property (void *vself, const char *name, const char *value) { circular_progress_t self = vself; - if (grub_strcmp (name, "value") == 0) - { - self->value = grub_strtol (value, 0, 10); - } - else if (grub_strcmp (name, "start") == 0) - { - self->start = grub_strtol (value, 0, 10); - } - else if (grub_strcmp (name, "end") == 0) - { - self->end = grub_strtol (value, 0, 10); - } - else if (grub_strcmp (name, "num_ticks") == 0) + if (grub_strcmp (name, "num_ticks") == 0) { self->num_ticks = grub_strtol (value, 0, 10); } @@ -257,10 +245,6 @@ circprog_set_property (void *vself, const char *name, const char *value) grub_free (self->theme_dir); self->theme_dir = value ? grub_strdup (value) : 0; } - else if (grub_strcmp (name, "visible") == 0) - { - self->visible = grub_strcmp (value, "false") != 0; - } else if (grub_strcmp (name, "id") == 0) { grub_free (self->id); @@ -272,6 +256,17 @@ circprog_set_property (void *vself, const char *name, const char *value) return grub_errno; } +static void +circprog_set_state (void *vself, int visible, int start, + int current, int end) +{ + circular_progress_t self = vself; + self->visible = visible; + self->start = start; + self->value = current; + self->end = end; +} + static struct grub_gui_component_ops circprog_ops = { .destroy = circprog_destroy, @@ -285,6 +280,11 @@ static struct grub_gui_component_ops circprog_ops = .set_property = circprog_set_property }; +static struct grub_gui_progress_ops circprog_prog_ops = + { + .set_state = circprog_set_state + }; + grub_gui_component_t grub_gui_circular_progress_new (void) { @@ -292,7 +292,8 @@ grub_gui_circular_progress_new (void) self = grub_zalloc (sizeof (*self)); if (! self) return 0; - self->comp.ops = &circprog_ops; + self->progress.ops = &circprog_prog_ops; + self->progress.component.ops = &circprog_ops; self->visible = 1; self->num_ticks = 64; self->start_angle = -64; diff --git a/gfxmenu/gui_progress_bar.c b/gfxmenu/gui_progress_bar.c index d982924cb..6a7f43962 100644 --- a/gfxmenu/gui_progress_bar.c +++ b/gfxmenu/gui_progress_bar.c @@ -24,10 +24,11 @@ #include #include #include +#include struct grub_gui_progress_bar { - struct grub_gui_component component; + struct grub_gui_progress progress; grub_gui_container_t parent; grub_video_rect_t bounds; @@ -37,7 +38,7 @@ struct grub_gui_progress_bar int end; int value; int show_text; - char *text; + char *template; grub_font_t font; grub_gui_color_t text_color; grub_gui_color_t border_color; @@ -156,14 +157,20 @@ draw_pixmap_bar (grub_gui_progress_bar_t self) static void draw_text (grub_gui_progress_bar_t self) { - const char *text = self->text; - if (text && self->show_text) + if (self->template) { grub_font_t font = self->font; grub_video_color_t text_color = grub_gui_map_color (self->text_color); int width = self->bounds.width; int height = self->bounds.height; - + char *text = grub_asprintf (self->template, + self->value > 0 ? self->value : -self->value); + if (!text) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + return; + } /* Center the text. */ int text_width = grub_font_get_string_width (font, text); int x = (width - text_width) / 2; @@ -228,35 +235,60 @@ progress_bar_get_bounds (void *vself, grub_video_rect_t *bounds) } static void -progress_bar_get_minimal_size (void *vself __attribute__ ((unused)), +progress_bar_get_minimal_size (void *vself, unsigned *width, unsigned *height) { + unsigned text_width = 0, text_height = 0; + grub_gui_progress_bar_t self = vself; + + if (self->template) + { + text_width = grub_font_get_string_width (self->font, self->template); + text_width += grub_font_get_string_width (self->font, "XXXXXXXXXX"); + text_height = grub_font_get_descent (self->font) + + grub_font_get_ascent (self->font); + } *width = 200; + if (*width < text_width) + *width = text_width; *height = 28; + if (*height < text_height) + *height = text_height; +} + +static void +progress_bar_set_state (void *vself, int visible, int start, + int current, int end) +{ + grub_gui_progress_bar_t self = vself; + self->visible = visible; + self->start = start; + self->value = current; + self->end = end; } static grub_err_t progress_bar_set_property (void *vself, const char *name, const char *value) { grub_gui_progress_bar_t self = vself; - if (grub_strcmp (name, "value") == 0) + if (grub_strcmp (name, "text") == 0) { - self->value = grub_strtol (value, 0, 10); - } - else if (grub_strcmp (name, "start") == 0) - { - self->start = grub_strtol (value, 0, 10); - } - else if (grub_strcmp (name, "end") == 0) - { - self->end = grub_strtol (value, 0, 10); - } - else if (grub_strcmp (name, "text") == 0) - { - grub_free (self->text); - if (! value) - value = ""; - self->text = grub_strdup (value); + grub_free (self->template); + if (grub_strcmp (value, "@TIMEOUT_NOTIFICATION_LONG@") == 0) + value + = _("The highlighted entry will be executed automatically in %ds."); + else if (grub_strcmp (value, "@TIMEOUT_NOTIFICATION_MIDDLE@") == 0) + /* TRANSLATORS: 's' stands for seconds. + It's a standalone timeout notification. + Please use the short form in your language. */ + value = _("%ds remaining."); + else if (grub_strcmp (value, "@TIMEOUT_NOTIFICATION_SHORT@") == 0) + /* TRANSLATORS: 's' stands for seconds. + It's a standalone timeout notification. + Please use the shortest form available in you language. */ + value = _("%ds"); + + self->template = grub_strdup (value); } else if (grub_strcmp (name, "font") == 0) { @@ -298,14 +330,6 @@ progress_bar_set_property (void *vself, const char *name, const char *value) grub_free (self->theme_dir); self->theme_dir = value ? grub_strdup (value) : 0; } - else if (grub_strcmp (name, "visible") == 0) - { - self->visible = grub_strcmp (value, "false") != 0; - } - else if (grub_strcmp (name, "show_text") == 0) - { - self->show_text = grub_strcmp (value, "false") != 0; - } else if (grub_strcmp (name, "id") == 0) { grub_free (self->id); @@ -331,6 +355,11 @@ static struct grub_gui_component_ops progress_bar_ops = .set_property = progress_bar_set_property }; +static struct grub_gui_progress_ops progress_bar_pb_ops = + { + .set_state = progress_bar_set_state + }; + grub_gui_component_t grub_gui_progress_bar_new (void) { @@ -338,10 +367,9 @@ grub_gui_progress_bar_new (void) self = grub_zalloc (sizeof (*self)); if (! self) return 0; - self->component.ops = &progress_bar_ops; + self->progress.ops = &progress_bar_pb_ops; + self->progress.component.ops = &progress_bar_ops; self->visible = 1; - self->show_text = 1; - self->text = grub_strdup (""); self->font = grub_font_get ("Helvetica 10"); grub_gui_color_t black = { .red = 0, .green = 0, .blue = 0, .alpha = 255 }; grub_gui_color_t gray = { .red = 128, .green = 128, .blue = 128, .alpha = 255 }; diff --git a/gfxmenu/view.c b/gfxmenu/view.c index 5008b105b..611c01e1b 100644 --- a/gfxmenu/view.c +++ b/gfxmenu/view.c @@ -160,11 +160,10 @@ draw_title (grub_gfxmenu_view_t view) struct progress_value_data { - const char *visible; - const char *start; - const char *end; - const char *value; - const char *text; + int visible; + int start; + int end; + int value; }; static void @@ -174,19 +173,14 @@ update_timeout_visit (grub_gui_component_t component, struct progress_value_data *pv; pv = (struct progress_value_data *) userdata; - component->ops->set_property (component, "visible", pv->visible); - component->ops->set_property (component, "start", pv->start); - component->ops->set_property (component, "end", pv->end); - component->ops->set_property (component, "value", pv->value); - component->ops->set_property (component, "text", pv->text); + ((struct grub_gui_progress *) component)->ops + ->set_state ((struct grub_gui_progress *) component, + pv->visible, pv->start, pv->value, pv->end); } void grub_gfxmenu_print_timeout (int timeout, void *data) { - char valuebuf[sizeof ("-XXXXXXXXXXX")]; - char startbuf[sizeof ("-XXXXXXXXXXX")]; - char msgbuf[120]; struct grub_gfxmenu_view *view = data; struct progress_value_data pv; @@ -205,17 +199,10 @@ grub_gfxmenu_print_timeout (int timeout, void *data) if (view->first_timeout == -1) view->first_timeout = timeout; - pv.visible = "true"; - grub_sprintf (startbuf, "%d", -(view->first_timeout + 1)); - pv.start = startbuf; - pv.end = "0"; - grub_sprintf (valuebuf, "%d", -timeout); - pv.value = valuebuf; - - grub_sprintf (msgbuf, - "The highlighted entry will be booted automatically in %d s.", - timeout); - pv.text = msgbuf; + pv.visible = 1; + pv.start = -(view->first_timeout + 1); + pv.end = 0; + pv.value = -timeout; grub_gui_find_by_id ((grub_gui_component_t) view->canvas, TIMEOUT_COMPONENT_ID, update_timeout_visit, &pv); @@ -244,11 +231,10 @@ grub_gfxmenu_clear_timeout (void *data) grub_gfxmenu_view_redraw (view, &bounds); } - pv.visible = "false"; - pv.start = "1"; - pv.end = "0"; - pv.value = "0"; - pv.text = ""; + pv.visible = 0; + pv.start = 1; + pv.end = 0; + pv.value = 0; grub_gui_find_by_id ((grub_gui_component_t) view->canvas, TIMEOUT_COMPONENT_ID, update_timeout_visit, &pv); diff --git a/include/grub/gui.h b/include/grub/gui.h index 6f8f44805..7bd71acd3 100644 --- a/include/grub/gui.h +++ b/include/grub/gui.h @@ -74,6 +74,11 @@ struct grub_gui_list_ops grub_gfxmenu_view_t view); }; +struct grub_gui_progress_ops +{ + void (*set_state) (void *self, int visible, int start, int current, int end); +}; + typedef signed grub_fixed_signed_t; #define GRUB_FIXED_1 0x10000 @@ -120,6 +125,12 @@ struct grub_gui_component grub_fixed_signed_t hfrac; }; +struct grub_gui_progress +{ + struct grub_gui_component component; + struct grub_gui_progress_ops *ops; +}; + struct grub_gui_container { struct grub_gui_component component; diff --git a/normal/menu.c b/normal/menu.c index 17730eff3..bbd1049e4 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -362,6 +362,8 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) if (timeout > 0) menu_print_timeout (timeout); + else + clear_timeout (); while (1) { From 2ab45155287b5a6088fab6b65a95069f83904ce9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jan 2010 10:50:50 +0100 Subject: [PATCH 050/237] Push error before calling grub_gfxterm_fullscreen --- gfxmenu/gfxmenu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gfxmenu/gfxmenu.c b/gfxmenu/gfxmenu.c index 1db96a80f..a2e765156 100644 --- a/gfxmenu/gfxmenu.c +++ b/gfxmenu/gfxmenu.c @@ -57,21 +57,27 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) theme_path = grub_env_get ("theme"); if (! theme_path) { + grub_error_push (); grub_gfxterm_fullscreen (); + grub_error_pop (); return grub_error (GRUB_ERR_FILE_NOT_FOUND, "no theme specified"); } instance = grub_zalloc (sizeof (*instance)); if (!instance) { + grub_error_push (); grub_gfxterm_fullscreen (); + grub_error_pop (); return grub_errno; } err = grub_video_get_info (&mode_info); if (err) { + grub_error_push (); grub_gfxterm_fullscreen (); + grub_error_pop (); return err; } @@ -88,7 +94,9 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) if (! cached_view) { grub_free (instance); + grub_error_push (); grub_gfxterm_fullscreen (); + grub_error_pop (); return grub_errno; } From cd622720c84608c9ab561f41a689ed58e3804bb4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jan 2010 10:51:23 +0100 Subject: [PATCH 051/237] Clear both buffers on gfxterm init --- term/gfxterm.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/term/gfxterm.c b/term/gfxterm.c index 0abe0f07d..26e94e474 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -315,6 +315,7 @@ grub_gfxterm_fullscreen (void) struct grub_video_mode_info mode_info; grub_video_color_t color; grub_err_t err; + int double_redraw; err = grub_video_get_info (&mode_info); /* Figure out what mode we ended up. */ @@ -323,9 +324,17 @@ grub_gfxterm_fullscreen (void) grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + double_redraw = mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED + && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); + /* Make sure screen is black. */ color = grub_video_map_rgb (0, 0, 0); grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height); + if (double_redraw) + { + grub_video_swap_buffers (); + grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height); + } bitmap = 0; /* Select the font to use. */ @@ -337,10 +346,7 @@ grub_gfxterm_fullscreen (void) return grub_gfxterm_set_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY, 0, 0, mode_info.width, mode_info.height, - mode_info.mode_type - & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED - && !(mode_info.mode_type - & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP), + double_redraw, font_name, DEFAULT_BORDER_WIDTH); } From 34d2c9a10faf2abb7d4dc1562b272f692008a878 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jan 2010 22:19:28 +0100 Subject: [PATCH 052/237] Fix compilation error --- gfxmenu/gui_progress_bar.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gfxmenu/gui_progress_bar.c b/gfxmenu/gui_progress_bar.c index 6a7f43962..550b5d43c 100644 --- a/gfxmenu/gui_progress_bar.c +++ b/gfxmenu/gui_progress_bar.c @@ -163,14 +163,15 @@ draw_text (grub_gui_progress_bar_t self) grub_video_color_t text_color = grub_gui_map_color (self->text_color); int width = self->bounds.width; int height = self->bounds.height; - char *text = grub_asprintf (self->template, - self->value > 0 ? self->value : -self->value); + char *text = grub_malloc (grub_strlen (self->template) + 10); if (!text) { grub_print_error (); grub_errno = GRUB_ERR_NONE; return; } + grub_sprintf (text, self->template, + self->value > 0 ? self->value : -self->value); /* Center the text. */ int text_width = grub_font_get_string_width (font, text); int x = (width - text_width) / 2; From c1b952d3d9a79ad03ded72d8abc58c0190f8a065 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 7 Jan 2010 18:20:11 +0000 Subject: [PATCH 053/237] 2010-01-07 Robert Millan * util/grub.d/10_hurd.in: Add --class information to menuentries. * util/grub.d/10_kfreebsd.in: Likewise. * util/grub.d/10_linux.in: Likewise. --- ChangeLog.mkconfig | 5 +++++ util/grub.d/10_hurd.in | 7 +++++-- util/grub.d/10_kfreebsd.in | 16 ++++++++++++---- util/grub.d/10_linux.in | 7 +++++-- 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 ChangeLog.mkconfig diff --git a/ChangeLog.mkconfig b/ChangeLog.mkconfig new file mode 100644 index 000000000..665c938c7 --- /dev/null +++ b/ChangeLog.mkconfig @@ -0,0 +1,5 @@ +2010-01-07 Robert Millan + + * util/grub.d/10_hurd.in: Add --class information to menuentries. + * util/grub.d/10_kfreebsd.in: Likewise. + * util/grub.d/10_linux.in: Likewise. diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in index c1871e07a..b56c585ee 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -1,7 +1,7 @@ #! /bin/sh -e # grub-mkconfig helper script. -# Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. +# Copyright (C) 2006,2007,2008,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 @@ -21,10 +21,13 @@ exec_prefix=@exec_prefix@ libdir=@libdir@ . ${libdir}/grub/grub-mkconfig_lib +CLASS="--class gnu --class os" + if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then OS=GNU else OS="${GRUB_DISTRIBUTOR} GNU/Hurd" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]') ${CLASS}" fi at_least_one=false @@ -69,7 +72,7 @@ if ${all_of_them} && test -e /lib/ld.so.1 ; then : ; else fi cat << EOF -menuentry "${OS}" { +menuentry "${OS}" ${CLASS} { EOF prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" cat << EOF diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index 026f1d7ac..7eb26072c 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -1,7 +1,7 @@ #! /bin/sh -e # grub-mkconfig helper script. -# 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 @@ -26,9 +26,17 @@ libdir=@libdir@ export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR=@LOCALEDIR@ +CLASS="--class os" + case "${GRUB_DISTRIBUTOR}" in - Debian) OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD" ;; - *) OS="FreeBSD" ;; + Debian) + OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]') --class gnu-kfreebsd --class gnu ${CLASS}" + ;; + *) + OS="FreeBSD" + CLASS="--class freebsd --class bsd ${CLASS}" + ;; esac kfreebsd_entry () @@ -38,7 +46,7 @@ kfreebsd_entry () recovery="$3" # not used yet args="$4" # not used yet title="$(gettext "%s, with kFreeBSD %s")" - printf "menuentry \"${title}\" {" ${os} ${version} + printf "menuentry \"${title}\" ${CLASS} {" ${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/")" diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index dc9696ec8..74d880641 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -1,7 +1,7 @@ #! /bin/sh -e # grub-mkconfig helper script. -# 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 @@ -26,10 +26,13 @@ libdir=@libdir@ export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR=@LOCALEDIR@ +CLASS="--class gnu-linux --class gnu --class os" + if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then OS=GNU/Linux else OS="${GRUB_DISTRIBUTOR} GNU/Linux" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]') ${CLASS}" fi # loop-AES arranges things so that /dev/loop/X can be our root device, but @@ -58,7 +61,7 @@ linux_entry () else title="$(gettext "%s, with Linux %s")" fi - printf "menuentry \"${title}\" {" ${os} ${version} + printf "menuentry \"${title}\" ${CLASS} {" ${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/")" From b5c72e3b0f2f09274cc67cbc335f1e3ca73f289e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Jan 2010 19:15:49 +0100 Subject: [PATCH 054/237] Fix list scrollbar position miscalculation --- gfxmenu/gui_list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gfxmenu/gui_list.c b/gfxmenu/gui_list.c index ccf360ad3..8377bf4bb 100644 --- a/gfxmenu/gui_list.c +++ b/gfxmenu/gui_list.c @@ -327,7 +327,7 @@ list_paint (void *vself, const grub_video_rect_t *region) draw_scrollbar (self, self->first_shown_index, num_shown_items, 0, self->view->menu->size, - content_rect.width - box_right_pad + self->bounds.width - box_right_pad + self->scrollbar_width, box_top_pad + self->item_padding, content_rect.height - box_top_pad - box_bottom_pad); From 2810a4ef1c2462f44da08a66b9337793a2b3fdd5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 9 Jan 2010 11:48:38 +0100 Subject: [PATCH 055/237] Fix scrollbar height --- gfxmenu/gui_list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gfxmenu/gui_list.c b/gfxmenu/gui_list.c index 8377bf4bb..a78339385 100644 --- a/gfxmenu/gui_list.c +++ b/gfxmenu/gui_list.c @@ -330,7 +330,7 @@ list_paint (void *vself, const grub_video_rect_t *region) self->bounds.width - box_right_pad + self->scrollbar_width, box_top_pad + self->item_padding, - content_rect.height - box_top_pad - box_bottom_pad); + self->bounds.height - box_top_pad - box_bottom_pad); } grub_gui_restore_viewport (&vpsave); From 3b6f7ab75d3c4aa8bc59d56b71284ece7c809b5f Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 11 Jan 2010 19:19:24 +0100 Subject: [PATCH 056/237] Add missing menuviewer initialization. --- util/grub.d/00_header.in | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index da394783a..306bef3c3 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -1,7 +1,7 @@ #! /bin/sh -e # grub-mkconfig helper script. -# 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 @@ -98,8 +98,11 @@ if [ x$GRUB_THEME != x ] && [ -f $GRUB_THEME ] \ && is_path_readable_by_grub $GRUB_THEME; then echo "Found theme: $GRUB_THEME" >&2 prepare_grub_to_access_device `${grub_probe} --target=device $GRUB_THEME` - echo "insmod gfxmenu" - echo "set theme=(\$root)/`make_system_path_relative_to_its_root $GRUB_THEME`" + cat << EOF +insmod gfxmenu +set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME` +set menuviewer=gfxmenu +EOF fi cat << EOF fi From 6419c43e4f767cd5f3dcf4258c45bd3edcb60efa Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Wed, 20 Jan 2010 13:56:45 +0000 Subject: [PATCH 057/237] Fix indentation in util/grub.d/00_header.in output --- util/grub.d/00_header.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 306bef3c3..7cee825d2 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -97,11 +97,11 @@ EOF if [ x$GRUB_THEME != x ] && [ -f $GRUB_THEME ] \ && is_path_readable_by_grub $GRUB_THEME; then echo "Found theme: $GRUB_THEME" >&2 - prepare_grub_to_access_device `${grub_probe} --target=device $GRUB_THEME` + prepare_grub_to_access_device `${grub_probe} --target=device $GRUB_THEME` | sed -e "s/^/ /" cat << EOF -insmod gfxmenu -set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME` -set menuviewer=gfxmenu + insmod gfxmenu + set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME` + set menuviewer=gfxmenu EOF fi cat << EOF From 566863ca1973b0cb39d469e46a384e59bcc437b4 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Fri, 22 Jan 2010 17:12:40 +0000 Subject: [PATCH 058/237] 2010-01-22 Robert Millan Use generic grub_reboot() for i386-efi. * kern/efi/efi.c [__i386__] (grub_reboot): Remove. * kern/i386/efi/startup.S: Include `"../realmode.S"'. * kern/i386/realmode.S: Include `'. --- ChangeLog | 8 ++++++++ kern/efi/efi.c | 5 ++++- kern/i386/efi/startup.S | 4 +++- kern/i386/realmode.S | 3 ++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5eef8a821..e559f218e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-01-22 Robert Millan + + Use generic grub_reboot() for i386-efi. + + * kern/efi/efi.c [__i386__] (grub_reboot): Remove. + * kern/i386/efi/startup.S: Include `"../realmode.S"'. + * kern/i386/realmode.S: Include `'. + 2010-01-22 Vladimir Serbinenko * kern/ieee1275/init.c (grub_machine_set_prefix): Don't check for diff --git a/kern/efi/efi.c b/kern/efi/efi.c index c6ce04c5e..d8b225535 100644 --- a/kern/efi/efi.c +++ b/kern/efi/efi.c @@ -1,7 +1,7 @@ /* efi.c - generic EFI support */ /* * 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 @@ -162,6 +162,8 @@ grub_exit (void) for (;;) ; } +/* On i386, a firmware-independant grub_reboot() is provided by realmode.S. */ +#ifndef __i386__ void grub_reboot (void) { @@ -169,6 +171,7 @@ grub_reboot (void) efi_call_4 (grub_efi_system_table->runtime_services->reset_system, GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL); } +#endif void grub_halt (void) diff --git a/kern/i386/efi/startup.S b/kern/i386/efi/startup.S index b88628010..5b464ab83 100644 --- a/kern/i386/efi/startup.S +++ b/kern/i386/efi/startup.S @@ -1,7 +1,7 @@ /* startup.S - bootstrap GRUB itself */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,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 @@ -62,3 +62,5 @@ codestart: movl %eax, EXT_C(grub_efi_system_table) call EXT_C(grub_main) ret + +#include "../realmode.S" diff --git a/kern/i386/realmode.S b/kern/i386/realmode.S index a74eb1217..578c8d2a8 100644 --- a/kern/i386/realmode.S +++ b/kern/i386/realmode.S @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,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 @@ -16,6 +16,7 @@ * along with GRUB. If not, see . */ +#include /* * Note: These functions defined in this file may be called from C. From 454fcd1c9bd5229c2fccabb1e34cbf0b1693ba92 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Jan 2010 20:40:21 +0100 Subject: [PATCH 059/237] 2010-01-22 Vladimir Serbinenko * configure.ac: Check for _restgpr_14_x. * include/grub/powerpc/libgcc.h [HAVE__RESTGPR_14_X]: Add _restgpr_*_x and _savegpr_* prototypes. --- ChangeLog | 6 ++++++ configure.ac | 2 +- include/grub/powerpc/libgcc.h | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e559f218e..a44d1f66e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-22 Vladimir Serbinenko + + * configure.ac: Check for _restgpr_14_x. + * include/grub/powerpc/libgcc.h [HAVE__RESTGPR_14_X]: Add _restgpr_*_x + and _savegpr_* prototypes. + 2010-01-22 Robert Millan Use generic grub_reboot() for i386-efi. diff --git a/configure.ac b/configure.ac index b1435de44..f621b5648 100644 --- a/configure.ac +++ b/configure.ac @@ -439,7 +439,7 @@ AC_SUBST(TARGET_CPPFLAGS) AC_SUBST(TARGET_LDFLAGS) # Check for libgcc symbols (must be performed before we add -nostdlib to LDFLAGS) -AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2) +AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x) # Set them to their new values for the tests below. CC="$TARGET_CC" diff --git a/include/grub/powerpc/libgcc.h b/include/grub/powerpc/libgcc.h index 452ad4366..6be122308 100644 --- a/include/grub/powerpc/libgcc.h +++ b/include/grub/powerpc/libgcc.h @@ -33,3 +33,42 @@ void EXPORT_FUNC (__trampoline_setup) (void); #ifdef HAVE___UCMPDI2 void EXPORT_FUNC (__ucmpdi2) (void); #endif + +#ifdef HAVE__RESTGPR_14_X +void EXPORT_FUNC (_restgpr_14_x) (void); +void EXPORT_FUNC (_restgpr_15_x) (void); +void EXPORT_FUNC (_restgpr_16_x) (void); +void EXPORT_FUNC (_restgpr_17_x) (void); +void EXPORT_FUNC (_restgpr_18_x) (void); +void EXPORT_FUNC (_restgpr_19_x) (void); +void EXPORT_FUNC (_restgpr_20_x) (void); +void EXPORT_FUNC (_restgpr_21_x) (void); +void EXPORT_FUNC (_restgpr_22_x) (void); +void EXPORT_FUNC (_restgpr_23_x) (void); +void EXPORT_FUNC (_restgpr_24_x) (void); +void EXPORT_FUNC (_restgpr_25_x) (void); +void EXPORT_FUNC (_restgpr_26_x) (void); +void EXPORT_FUNC (_restgpr_27_x) (void); +void EXPORT_FUNC (_restgpr_28_x) (void); +void EXPORT_FUNC (_restgpr_29_x) (void); +void EXPORT_FUNC (_restgpr_30_x) (void); +void EXPORT_FUNC (_restgpr_31_x) (void); +void EXPORT_FUNC (_savegpr_14) (void); +void EXPORT_FUNC (_savegpr_15) (void); +void EXPORT_FUNC (_savegpr_16) (void); +void EXPORT_FUNC (_savegpr_17) (void); +void EXPORT_FUNC (_savegpr_18) (void); +void EXPORT_FUNC (_savegpr_19) (void); +void EXPORT_FUNC (_savegpr_20) (void); +void EXPORT_FUNC (_savegpr_21) (void); +void EXPORT_FUNC (_savegpr_22) (void); +void EXPORT_FUNC (_savegpr_23) (void); +void EXPORT_FUNC (_savegpr_24) (void); +void EXPORT_FUNC (_savegpr_25) (void); +void EXPORT_FUNC (_savegpr_26) (void); +void EXPORT_FUNC (_savegpr_27) (void); +void EXPORT_FUNC (_savegpr_28) (void); +void EXPORT_FUNC (_savegpr_29) (void); +void EXPORT_FUNC (_savegpr_30) (void); +void EXPORT_FUNC (_savegpr_31) (void); +#endif From 4b358c0a56edfcd90e52a1fb6334408ffa6909fa Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Jan 2010 20:42:02 +0100 Subject: [PATCH 060/237] 2010-01-22 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_setcolorstate): Allocate on stack since heap may be unavailable at that point. (grub_ofconsole_gotoxy): Likewise. --- ChangeLog | 6 ++++++ term/ieee1275/ofconsole.c | 16 ++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index a44d1f66e..d700466fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-22 Vladimir Serbinenko + + * term/ieee1275/ofconsole.c (grub_ofconsole_setcolorstate): Allocate on + stack since heap may be unavailable at that point. + (grub_ofconsole_gotoxy): Likewise. + 2010-01-22 Vladimir Serbinenko * configure.ac: Check for _restgpr_14_x. diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index 3799e2e27..51dca7a53 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -109,7 +109,7 @@ grub_ofconsole_getcharwidth (grub_uint32_t c __attribute__((unused))) static void grub_ofconsole_setcolorstate (grub_term_color_state state) { - char *setcol; + char setcol[256]; int fg; int bg; @@ -128,10 +128,8 @@ grub_ofconsole_setcolorstate (grub_term_color_state state) return; } - setcol = grub_xasprintf ("\e[3%dm\e[4%dm", fg, bg); - if (setcol) - grub_ofconsole_writeesc (setcol); - grub_free (setcol); + grub_snprintf (setcol, sizeof (setcol), "\e[3%dm\e[4%dm", fg, bg); + grub_ofconsole_writeesc (setcol); } static void @@ -288,14 +286,12 @@ grub_ofconsole_gotoxy (grub_uint8_t x, grub_uint8_t y) { if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_ANSI)) { - char *s; + char s[256]; grub_curr_x = x; grub_curr_y = y; - s = grub_xasprintf ("\e[%d;%dH", y + 1, x + 1); - if (s) - grub_ofconsole_writeesc (s); - grub_free (s); + grub_snprintf (s, sizeof (s), "\e[%d;%dH", y + 1, x + 1); + grub_ofconsole_writeesc (s); } else { From f4c499f86f3ea8e3e3cedbc70ca53e15c480725d Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Sat, 23 Jan 2010 19:46:28 +0530 Subject: [PATCH 061/237] replaced magic numbers with macros --- script/execute.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/script/execute.c b/script/execute.c index c956960da..d42918f50 100644 --- a/script/execute.c +++ b/script/execute.c @@ -35,6 +35,9 @@ grub_script_execute_cmd (struct grub_script_cmd *cmd) return cmd->exec (cmd); } +#define ARG_ALLOCATION_UNIT (32 * sizeof (char)) +#define ARGV_ALLOCATION_UNIT (8 * sizeof (void*)) + /* Expand arguments in ARGLIST into multiple arguments. */ char ** grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *count) @@ -56,7 +59,7 @@ grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *c if (oom) return; - p = grub_realloc (argv, ALIGN_UP (sizeof(char*) * (argc + 1), 32)); + p = grub_realloc (argv, ALIGN_UP (sizeof(char*) * (argc + 1), ARGV_ALLOCATION_UNIT)); if (!p) oom = 1; else @@ -78,7 +81,7 @@ grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *c len = nchar ?: grub_strlen (str); old = argv[argc - 1] ? grub_strlen (argv[argc - 1]) : 0; - p = grub_realloc (argv[argc - 1], ALIGN_UP(old + len + 1, 32)); + p = grub_realloc (argv[argc - 1], ALIGN_UP(old + len + 1, ARG_ALLOCATION_UNIT)); if (p) { From fc9e58104a1a99e0bc2956a77b365820d035fb39 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Sat, 23 Jan 2010 22:38:10 +0530 Subject: [PATCH 062/237] fix underquoted AC_DEFUN parameters --- ChangeLog | 4 ++++ acinclude.m4 | 32 ++++++++++++++++---------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index d700466fa..9bb6b1c01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-23 BVK Chaitanya + + * acinclude.m4: Quote underquoted AC_DEFUN parameters. + 2010-01-22 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_setcolorstate): Allocate on diff --git a/acinclude.m4 b/acinclude.m4 index 36a3b3e08..692404e20 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -14,7 +14,7 @@ $2 dnl Check whether target compiler is working -AC_DEFUN(grub_PROG_TARGET_CC, +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([[ @@ -36,7 +36,7 @@ dnl grub_ASM_USCORE checks if C symbols get an underscore after dnl compiling to assembler. dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by dnl Erich Boleyn and modified by Yoshinori K. Okuji. -AC_DEFUN(grub_ASM_USCORE, +AC_DEFUN([grub_ASM_USCORE], [AC_REQUIRE([AC_PROG_CC]) AC_MSG_CHECKING([if C symbols get an underscore after compilation]) AC_CACHE_VAL(grub_cv_asm_uscore, @@ -75,7 +75,7 @@ AC_MSG_RESULT([$grub_cv_asm_uscore]) dnl Some versions of `objcopy -O binary' vary their output depending dnl on the link address. -AC_DEFUN(grub_PROG_OBJCOPY_ABSOLUTE, +AC_DEFUN([grub_PROG_OBJCOPY_ABSOLUTE], [AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses]) AC_CACHE_VAL(grub_cv_prog_objcopy_absolute, [cat > conftest.c <<\EOF @@ -119,7 +119,7 @@ fi dnl Supply --build-id=none to ld if building modules. dnl This suppresses warnings from ld on some systems -AC_DEFUN(grub_PROG_LD_BUILD_ID_NONE, +AC_DEFUN([grub_PROG_LD_BUILD_ID_NONE], [AC_MSG_CHECKING([whether linker accepts --build-id=none]) AC_CACHE_VAL(grub_cv_prog_ld_build_id_none, [save_LDFLAGS="$LDFLAGS" @@ -150,7 +150,7 @@ dnl dnl We only support the newer versions, because the old versions cause dnl major pain, by requiring manual assembly to get 16-bit instructions into dnl asm files. -AC_DEFUN(grub_I386_ASM_ADDR32, +AC_DEFUN([grub_I386_ASM_ADDR32], [AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT]) AC_MSG_CHECKING([for .code16 addr32 assembler support]) @@ -178,7 +178,7 @@ AC_MSG_RESULT([$grub_cv_i386_asm_addr32])]) dnl check if our compiler is apple cc dnl because it requires numerous workarounds -AC_DEFUN(grub_apple_cc, +AC_DEFUN([grub_apple_cc], [AC_REQUIRE([AC_PROG_CC]) AC_MSG_CHECKING([whether our compiler is apple cc]) AC_CACHE_VAL(grub_cv_apple_cc, @@ -193,7 +193,7 @@ AC_MSG_RESULT([$grub_cv_apple_cc])]) dnl check if our target compiler is apple cc dnl because it requires numerous workarounds -AC_DEFUN(grub_apple_target_cc, +AC_DEFUN([grub_apple_target_cc], [AC_REQUIRE([AC_PROG_CC]) AC_MSG_CHECKING([whether our target compiler is apple cc]) AC_CACHE_VAL(grub_cv_apple_target_cc, @@ -210,7 +210,7 @@ AC_MSG_RESULT([$grub_cv_apple_target_cc])]) dnl Later versions of GAS requires that addr32 and data32 prefixes dnl appear in the same lines as the instructions they modify, while dnl earlier versions requires that they appear in separate lines. -AC_DEFUN(grub_I386_ASM_PREFIX_REQUIREMENT, +AC_DEFUN([grub_I386_ASM_PREFIX_REQUIREMENT], [AC_REQUIRE([AC_PROG_CC]) AC_MSG_CHECKING(dnl [whether addr32 must be in the same line as the instruction]) @@ -246,7 +246,7 @@ AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])]) dnl Older versions of GAS require that absolute indirect calls/jumps are dnl not prefixed with `*', while later versions warn if not prefixed. -AC_DEFUN(grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK, +AC_DEFUN([grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK], [AC_REQUIRE([AC_PROG_CC]) AC_MSG_CHECKING(dnl [whether an absolute indirect call/jump must not be prefixed with an asterisk]) @@ -276,7 +276,7 @@ AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])]) dnl Check what symbol is defined as a bss start symbol. dnl Written by Michael Hohmoth and Yoshinori K. Okuji. -AC_DEFUN(grub_CHECK_BSS_START_SYMBOL, +AC_DEFUN([grub_CHECK_BSS_START_SYMBOL], [AC_REQUIRE([AC_PROG_CC]) AC_MSG_CHECKING([if __bss_start is defined by the compiler]) AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol, @@ -320,7 +320,7 @@ fi dnl Check what symbol is defined as an end symbol. dnl Written by Yoshinori K. Okuji. -AC_DEFUN(grub_CHECK_END_SYMBOL, +AC_DEFUN([grub_CHECK_END_SYMBOL], [AC_REQUIRE([AC_PROG_CC]) AC_MSG_CHECKING([if end is defined by the compiler]) AC_CACHE_VAL(grub_cv_check_end_symbol, @@ -352,7 +352,7 @@ fi ]) dnl Check if the C compiler generates calls to `__enable_execute_stack()'. -AC_DEFUN(grub_CHECK_ENABLE_EXECUTE_STACK,[ +AC_DEFUN([grub_CHECK_ENABLE_EXECUTE_STACK],[ AC_MSG_CHECKING([whether `$CC' generates calls to `__enable_execute_stack()']) AC_LANG_CONFTEST([[ void f (int (*p) (void)); @@ -379,7 +379,7 @@ rm -f conftest* dnl Check if the C compiler supports `-fstack-protector'. -AC_DEFUN(grub_CHECK_STACK_PROTECTOR,[ +AC_DEFUN([grub_CHECK_STACK_PROTECTOR],[ [# Smashing stack protector. ssp_possible=yes] AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector']) @@ -398,7 +398,7 @@ else ]) dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin). -AC_DEFUN(grub_CHECK_STACK_ARG_PROBE,[ +AC_DEFUN([grub_CHECK_STACK_ARG_PROBE],[ [# Smashing stack arg probe. sap_possible=yes] AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe']) @@ -414,7 +414,7 @@ else ]) dnl Check if ln can handle directories properly (mingw). -AC_DEFUN(grub_CHECK_LINK_DIR,[ +AC_DEFUN([grub_CHECK_LINK_DIR],[ AC_MSG_CHECKING([whether ln can handle directories properly]) [mkdir testdir 2>/dev/null case $srcdir in @@ -432,7 +432,7 @@ rm -rf testdir] ]) dnl Check if the C compiler supports `-fPIE'. -AC_DEFUN(grub_CHECK_PIE,[ +AC_DEFUN([grub_CHECK_PIE],[ [# Position independent executable. pie_possible=yes] AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default]) From 69be5b74be62f112d9e4afc10c1ede8c42cb502c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Jan 2010 22:56:08 +0100 Subject: [PATCH 063/237] 2010-01-23 Vladimir Serbinenko * configure.ac: Check for libgcc symbols with -nostdlib. --- ChangeLog | 4 ++++ configure.ac | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9bb6b1c01..cec7af8a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-23 Vladimir Serbinenko + + * configure.ac: Check for libgcc symbols with -nostdlib. + 2010-01-23 BVK Chaitanya * acinclude.m4: Quote underquoted AC_DEFUN parameters. diff --git a/configure.ac b/configure.ac index f621b5648..012aef96e 100644 --- a/configure.ac +++ b/configure.ac @@ -438,18 +438,25 @@ AC_SUBST(TARGET_ASFLAGS) AC_SUBST(TARGET_CPPFLAGS) AC_SUBST(TARGET_LDFLAGS) -# Check for libgcc symbols (must be performed before we add -nostdlib to LDFLAGS) -AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x) - # Set them to their new values for the tests below. CC="$TARGET_CC" +if test "x$TARGET_APPLE_CC" = x1 ; then +CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error" +else +CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100 -Wl,--defsym,abort=main -Wno-error" +fi +CPPFLAGS="$TARGET_CPPFLAGS" +LDFLAGS="$TARGET_LDFLAGS" +LIBS=-lgcc + +# Check for libgcc symbols +AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x) + if test "x$TARGET_APPLE_CC" = x1 ; then CFLAGS="$TARGET_CFLAGS -nostdlib" else CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100" fi -CPPFLAGS="$TARGET_CPPFLAGS" -LDFLAGS="$TARGET_LDFLAGS" # Defined in aclocal.m4. grub_PROG_TARGET_CC From c273d4cea97158122d3eb9baad6497efac8e9126 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 24 Jan 2010 14:30:10 +0100 Subject: [PATCH 064/237] 2010-01-24 Samuel Thibault * util/grub.d/10_hurd.in: Add a recovery mode. --- ChangeLog | 4 ++++ util/grub.d/10_hurd.in | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ChangeLog b/ChangeLog index cec7af8a5..ee582693f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-24 Samuel Thibault + + * util/grub.d/10_hurd.in: Add a recovery mode. + 2010-01-23 Vladimir Serbinenko * configure.ac: Check for libgcc symbols with -nostdlib. diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in index 65a9a70b1..8c9060932 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -89,3 +89,25 @@ cat << EOF module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)' } EOF + +cat << EOF +menuentry "${OS} (recovery mode)" { +EOF +prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" +cat << EOF + echo $(gettext "Loading GNU Mach ...") + multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} -s +EOF +save_default_entry | sed -e "s/^/\t/" +prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" +cat << EOF + echo $(gettext "Loading the Hurd ...") + module /hurd/${hurd_fs}.static ${hurd_fs} \\ + --multiboot-command-line='\${kernel-command-line}' \\ + --host-priv-port='\${host-port}' \\ + --device-master-port='\${device-port}' \\ + --exec-server-task='\${exec-task}' -T typed '\${root}' \\ + '\$(task-create)' '\$(task-resume)' + module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)' +} +EOF From 67951a534f282c5463cb0274f4ec14d38a91eff7 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 24 Jan 2010 21:04:29 +0000 Subject: [PATCH 065/237] 2010-01-24 Robert Millan * loader/mips/linux.c (grub_cmd_linux, grub_cmd_initrd): Don't capitalize error strings. --- ChangeLog | 5 +++++ loader/mips/linux.c | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index ee582693f..7367d9679 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-24 Robert Millan + + * loader/mips/linux.c (grub_cmd_linux, grub_cmd_initrd): Don't + capitalize error strings. + 2010-01-24 Samuel Thibault * util/grub.d/10_hurd.in: Add a recovery mode. diff --git a/loader/mips/linux.c b/loader/mips/linux.c index 51060c4fb..64497f466 100644 --- a/loader/mips/linux.c +++ b/loader/mips/linux.c @@ -196,7 +196,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), { grub_elf_close (elf); return grub_error (GRUB_ERR_UNKNOWN_OS, - "This ELF file is not of the right type\n"); + "this ELF file is not of the right type\n"); } /* Release the previously used memory. */ @@ -236,7 +236,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (grub_elf_is_elf64 (elf)) err = grub_linux_load64 (elf, &extra, size); else - err = grub_error (GRUB_ERR_BAD_FILE_TYPE, "Unknown ELF class"); + err = grub_error (GRUB_ERR_BAD_FILE_TYPE, "unknown ELF class"); grub_elf_close (elf); @@ -325,13 +325,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), grub_size_t overhead; if (argc == 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "No initrd specified"); + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no initrd specified"); if (!loaded) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "You need to load Linux first."); + return grub_error (GRUB_ERR_BAD_ARGUMENT, "you need to load Linux first."); if (initrd_loaded) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Only one initrd can be loaded."); + return grub_error (GRUB_ERR_BAD_ARGUMENT, "only one initrd can be loaded."); file = grub_file_open (argv[0]); if (! file) @@ -353,7 +353,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, playground + linux_size + overhead, size) != size) { - grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file"); + grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); grub_file_close (file); return grub_errno; From ea4a7e35ebb262325dc194832530ae9bc4f30184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Sutre?= Date: Mon, 25 Jan 2010 10:06:55 +0100 Subject: [PATCH 066/237] =?UTF-8?q?2010-01-25=20=20Gr=C3=A9goire=20Sutre?= =?UTF-8?q?=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * configure.ac: Check for `limits.h'. * util/misc.c: Include `' (for PATH_MAX). --- ChangeLog | 5 +++++ configure.ac | 2 +- util/misc.c | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7367d9679..ab11ad50f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-25 Grégoire Sutre + + * configure.ac: Check for `limits.h'. + * util/misc.c: Include `' (for PATH_MAX). + 2010-01-24 Robert Millan * loader/mips/linux.c (grub_cmd_linux, grub_cmd_initrd): Don't diff --git a/configure.ac b/configure.ac index 012aef96e..be498be8b 100644 --- a/configure.ac +++ b/configure.ac @@ -221,7 +221,7 @@ AC_HEADER_MAJOR AC_HEADER_DIRENT AC_CHECK_FUNCS(memmove sbrk strdup lstat getuid getgid) AC_CHECK_HEADERS(sys/mkdev.h sys/sysmacros.h malloc.h termios.h sys/types.h) -AC_CHECK_HEADERS(unistd.h string.h strings.h sys/stat.h sys/fcntl.h) +AC_CHECK_HEADERS(unistd.h string.h strings.h sys/stat.h sys/fcntl.h limits.h) # # Check for target programs. diff --git a/util/misc.c b/util/misc.c index 8f66e4350..371e7cc14 100644 --- a/util/misc.c +++ b/util/misc.c @@ -30,6 +30,9 @@ #include #include #include +#ifdef HAVE_LIMITS_H +#include +#endif #include #include From 37effddaf3687c8099669b38d9d2fbaa79076bac Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Mon, 25 Jan 2010 22:01:14 +0530 Subject: [PATCH 067/237] make parenthesis as valid word characters --- ChangeLog.lexer-rewrite | 5 +++++ script/parser.y | 2 -- script/yylex.l | 4 +--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ChangeLog.lexer-rewrite b/ChangeLog.lexer-rewrite index 56c637976..9b2ab9e2f 100644 --- a/ChangeLog.lexer-rewrite +++ b/ChangeLog.lexer-rewrite @@ -1,3 +1,8 @@ +2010-01-25 BVK Chaitanya + + * script/yylex.l: Accept parenthesis as part of word. + * script/parser.y: Remove GRUB_PARSER_TOKEN_{LPAR,RPAR} tokens. + 2010-01-10 BVK Chaitanya * conf/any-emu.rmk: Build rule updates. diff --git a/script/parser.y b/script/parser.y index b8d981866..baf1fd9b5 100644 --- a/script/parser.y +++ b/script/parser.y @@ -45,8 +45,6 @@ %token GRUB_PARSER_TOKEN_PIPE "|" %token GRUB_PARSER_TOKEN_AMP "&" %token GRUB_PARSER_TOKEN_SEMI ";" -%token GRUB_PARSER_TOKEN_LPAR "(" -%token GRUB_PARSER_TOKEN_RPAR ")" %token GRUB_PARSER_TOKEN_LBR "{" %token GRUB_PARSER_TOKEN_RBR "}" %token GRUB_PARSER_TOKEN_NOT "!" diff --git a/script/yylex.l b/script/yylex.l index 7cef8496b..db276ef61 100644 --- a/script/yylex.l +++ b/script/yylex.l @@ -128,7 +128,7 @@ typedef grub_size_t yy_size_t; BLANK [ \t] COMMENT ^[ \t]*#.*$ -CHAR [^|&$;()<> \t\n\'\"\\] +CHAR [^|&$;<> \t\n\'\"\\] DIGITS [[:digit:]]+ NAME [[:alpha:]_][[:alnum:][:digit:]_]* @@ -157,8 +157,6 @@ WORD ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE})+ "|" { RECORD; return GRUB_PARSER_TOKEN_PIPE; } "&" { RECORD; return GRUB_PARSER_TOKEN_AMP; } ";" { RECORD; return GRUB_PARSER_TOKEN_SEMI; } -"(" { RECORD; return GRUB_PARSER_TOKEN_LPAR; } -")" { RECORD; return GRUB_PARSER_TOKEN_RPAR; } "<" { RECORD; return GRUB_PARSER_TOKEN_LT; } ">" { RECORD; return GRUB_PARSER_TOKEN_GT; } From 847effd8bf38e04839db3b673f7827f4bd781de0 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 25 Jan 2010 17:04:22 +0000 Subject: [PATCH 068/237] 2010-01-25 Colin Watson * util/hostdisk.c (open_device): Add trailing newline to debug message. --- ChangeLog | 5 +++++ util/hostdisk.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ab11ad50f..12b7ccb31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-25 Colin Watson + + * util/hostdisk.c (open_device): Add trailing newline to debug + message. + 2010-01-25 Grégoire Sutre * configure.ac: Check for `limits.h'. diff --git a/util/hostdisk.c b/util/hostdisk.c index 603445801..a594f75ec 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -340,7 +340,7 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) is_partition = linux_find_partition (dev, disk->partition->start); /* Open the partition. */ - grub_dprintf ("hostdisk", "opening the device `%s' in open_device()", dev); + grub_dprintf ("hostdisk", "opening the device `%s' in open_device()\n", dev); fd = open (dev, flags); if (fd < 0) { From 42e0cba3af386ae4e5df2e82c759d833bae1ae47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Sutre?= Date: Tue, 26 Jan 2010 01:57:56 +0100 Subject: [PATCH 069/237] Reset LIBS after check for libgcc symbols in configure.ac. --- ChangeLog | 4 ++++ configure.ac | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 12b7ccb31..e66e2d403 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-26 Vladimir Serbinenko + + * configure.ac: Reset LIBS after check for libgcc symbols. + 2010-01-25 Colin Watson * util/hostdisk.c (open_device): Add trailing newline to debug diff --git a/configure.ac b/configure.ac index be498be8b..e6751e5cf 100644 --- a/configure.ac +++ b/configure.ac @@ -457,6 +457,7 @@ CFLAGS="$TARGET_CFLAGS -nostdlib" else CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100" fi +LIBS="" # Defined in aclocal.m4. grub_PROG_TARGET_CC From 59cad637aec20e1a5122c6a0a7f30ed48b5b4b2a Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Tue, 26 Jan 2010 16:45:16 +0100 Subject: [PATCH 070/237] Update my email address --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e66e2d403..aabc66370 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23847,7 +23847,7 @@ * genmk.rb (PModule#rule): Make sure to get only symbol names from the output of nm. - Reported by Robert Millan . + Reported by Robert Millan . 2003-09-25 Yoshinori K. Okuji From 3973a59a3476cb9201f70446e03b6e5301b3c3bf Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Tue, 26 Jan 2010 16:39:37 +0000 Subject: [PATCH 071/237] 2010-01-26 Robert Millan * include/grub/i386/pc/boot.h (GRUB_BOOT_MACHINE_PXE_DL): New macro. * boot/i386/pc/pxeboot.S: Include `'. (_start): Macroify `0x7F'. * kern/i386/pc/init.c: Include `'. (make_install_device): Use "(pxe)" as fallback prefix when booting via PXE. --- ChangeLog | 11 +++++++++++ boot/i386/pc/pxeboot.S | 6 ++++-- include/grub/i386/pc/boot.h | 2 ++ kern/i386/pc/init.c | 37 ++++++++++++++++++++++--------------- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index aabc66370..293e40a40 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-01-26 Robert Millan + + * include/grub/i386/pc/boot.h (GRUB_BOOT_MACHINE_PXE_DL): New macro. + + * boot/i386/pc/pxeboot.S: Include `'. + (_start): Macroify `0x7F'. + + * kern/i386/pc/init.c: Include `'. + (make_install_device): Use "(pxe)" as fallback prefix when booting + via PXE. + 2010-01-26 Vladimir Serbinenko * configure.ac: Reset LIBS after check for libgcc symbols. diff --git a/boot/i386/pc/pxeboot.S b/boot/i386/pc/pxeboot.S index 28c90e29b..446bfc781 100644 --- a/boot/i386/pc/pxeboot.S +++ b/boot/i386/pc/pxeboot.S @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2000,2005,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2000,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 @@ -16,6 +16,8 @@ * along with GRUB. If not, see . */ +#include + .file "pxeboot.S" .text @@ -28,7 +30,7 @@ _start: start: /* Use drive number 0x7F for PXE */ - movb $0x7F, %dl + movb $GRUB_BOOT_MACHINE_PXE_DL, %dl /* Jump to the real world */ ljmp $0, $0x8200 diff --git a/include/grub/i386/pc/boot.h b/include/grub/i386/pc/boot.h index 508b10742..e88c62b71 100644 --- a/include/grub/i386/pc/boot.h +++ b/include/grub/i386/pc/boot.h @@ -66,6 +66,8 @@ /* The size of a block list used in the kernel startup code. */ #define GRUB_BOOT_MACHINE_LIST_SIZE 12 +#define GRUB_BOOT_MACHINE_PXE_DL 0x7f + #ifndef ASM_FILE /* This is the blocklist used in the diskboot image. */ diff --git a/kern/i386/pc/init.c b/kern/i386/pc/init.c index e45ad3971..1707049fe 100644 --- a/kern/i386/pc/init.c +++ b/kern/i386/pc/init.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2002,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 @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -62,22 +63,28 @@ make_install_device (void) { /* No hardcoded root partition - make it from the boot drive and the partition number encoded at the install time. */ - grub_snprintf (dev, sizeof (dev), - "(%cd%u", (grub_boot_drive & 0x80) ? 'h' : 'f', - grub_boot_drive & 0x7f); - ptr += grub_strlen (ptr); + if (grub_boot_drive == GRUB_BOOT_MACHINE_PXE_DL) + { + grub_strcpy (dev, "(pxe"); + ptr += sizeof ("(pxe") - 1; + } + else + { + grub_snprintf (dev, sizeof (dev), + "(%cd%u", (grub_boot_drive & 0x80) ? 'h' : 'f', + grub_boot_drive & 0x7f); + ptr += grub_strlen (ptr); - if (grub_install_dos_part >= 0) - grub_snprintf (ptr, sizeof (dev) - (ptr - dev), - ",%u", grub_install_dos_part + 1); + if (grub_install_dos_part >= 0) + grub_snprintf (ptr, sizeof (dev) - (ptr - dev), + ",%u", grub_install_dos_part + 1); + ptr += grub_strlen (ptr); - ptr += grub_strlen (ptr); - - if (grub_install_bsd_part >= 0) - grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ",%c", - grub_install_bsd_part + 'a'); - - ptr += grub_strlen (ptr); + if (grub_install_bsd_part >= 0) + grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ",%c", + grub_install_bsd_part + 'a'); + ptr += grub_strlen (ptr); + } grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ")%s", grub_prefix); grub_strcpy (grub_prefix, dev); From 94e7e712819fa4a320b013fb850341679a9fa71d Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Tue, 26 Jan 2010 18:12:49 +0000 Subject: [PATCH 072/237] 2010-01-26 Robert Millan * util/bin2h.c (usage): Make --help actually explain what `grub-bin2h' does. --- ChangeLog | 5 +++++ util/bin2h.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 293e40a40..097d6b217 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-26 Robert Millan + + * util/bin2h.c (usage): Make --help actually explain what `grub-bin2h' + does. + 2010-01-26 Robert Millan * include/grub/i386/pc/boot.h (GRUB_BOOT_MACHINE_PXE_DL): New macro. diff --git a/util/bin2h.c b/util/bin2h.c index 5ce47f086..3a0723ea3 100644 --- a/util/bin2h.c +++ b/util/bin2h.c @@ -41,6 +41,8 @@ usage (int status) printf ("\ Usage: %s [OPTIONS] SYMBOL-NAME\n\ \n\ +Convert a binary file to a C header.\n\ +\n\ -h, --help display this message and exit\n\ -V, --version print version information and exit\n\ \n\ From de0b7a4ed1e72ea5e66027d80c6a708418980b70 Mon Sep 17 00:00:00 2001 From: carles Date: Tue, 26 Jan 2010 20:16:08 +0000 Subject: [PATCH 073/237] 2010-01-25 Carles Pina i Estany * font/font.c: Include `grub/fontformat.h. Remove font file format constants. (grub_font_load): Use the new macros. * include/grub/fontformat.h: New file. * util/grub-mkfont.c: Include `grub/fontformat.c'. (write_font_pf2): Use the new macros. --- ChangeLog | 9 +++++++ font/font.c | 51 +++++++++++++++++++++------------------ include/grub/fontformat.h | 38 +++++++++++++++++++++++++++++ util/grub-mkfont.c | 38 +++++++++++++++++++---------- 4 files changed, 99 insertions(+), 37 deletions(-) create mode 100644 include/grub/fontformat.h diff --git a/ChangeLog b/ChangeLog index 097d6b217..a0628fd7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-01-25 Carles Pina i Estany + + * font/font.c: Include `grub/fontformat.h. + Remove font file format constants. + (grub_font_load): Use the new macros. + * include/grub/fontformat.h: New file. + * util/grub-mkfont.c: Include `grub/fontformat.c'. + (write_font_pf2): Use the new macros. + 2010-01-26 Robert Millan * util/bin2h.c (usage): Make --help actually explain what `grub-bin2h' diff --git a/font/font.c b/font/font.c index 587e418cc..639f4d720 100644 --- a/font/font.c +++ b/font/font.c @@ -26,6 +26,7 @@ #include #include #include +#include #ifdef USE_ASCII_FAILBACK #include "ascii.h" @@ -89,19 +90,6 @@ struct font_file_section int eof; }; -/* Font file format constants. */ -static const char pff2_magic[4] = { 'P', 'F', 'F', '2' }; -static const char section_names_file[4] = { 'F', 'I', 'L', 'E' }; -static const char section_names_font_name[4] = { 'N', 'A', 'M', 'E' }; -static const char section_names_point_size[4] = { 'P', 'T', 'S', 'Z' }; -static const char section_names_weight[4] = { 'W', 'E', 'I', 'G' }; -static const char section_names_max_char_width[4] = { 'M', 'A', 'X', 'W' }; -static const char section_names_max_char_height[4] = { 'M', 'A', 'X', 'H' }; -static const char section_names_ascent[4] = { 'A', 'S', 'C', 'E' }; -static const char section_names_descent[4] = { 'D', 'E', 'S', 'C' }; -static const char section_names_char_index[4] = { 'C', 'H', 'I', 'X' }; -static const char section_names_data[4] = { 'D', 'A', 'T', 'A' }; - /* Replace unknown glyphs with a rounded question mark. */ static grub_uint8_t unknown_glyph_bitmap[] = { @@ -460,7 +448,8 @@ grub_font_load (const char *filename) #if FONT_DEBUG >= 3 grub_printf("opened FILE section\n"); #endif - if (grub_memcmp (section.name, section_names_file, 4) != 0) + if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FILE, + sizeof(FONT_FORMAT_SECTION_NAMES_FILE) - 1) != 0) { grub_error (GRUB_ERR_BAD_FONT, "font file format error: 1st section must be FILE"); @@ -489,7 +478,7 @@ grub_font_load (const char *filename) grub_printf("read magic ok\n"); #endif - if (grub_memcmp (magic, pff2_magic, 4) != 0) + if (grub_memcmp (magic, FONT_FORMAT_PFF2_MAGIC, 4) != 0) { grub_error (GRUB_ERR_BAD_FONT, "invalid font magic %x %x %x %x", magic[0], magic[1], magic[2], magic[3]); @@ -529,18 +518,22 @@ grub_font_load (const char *filename) section.name[2], section.name[3]); #endif - if (grub_memcmp (section.name, section_names_font_name, 4) == 0) + if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FONT_NAME, + sizeof(FONT_FORMAT_SECTION_NAMES_FONT_NAME) - 1) == 0) { font->name = read_section_as_string (§ion); if (!font->name) goto fail; } - else if (grub_memcmp (section.name, section_names_point_size, 4) == 0) + else if (grub_memcmp (section.name, + FONT_FORMAT_SECTION_NAMES_POINT_SIZE, + sizeof(FONT_FORMAT_SECTION_NAMES_POINT_SIZE) - 1) == 0) { if (read_section_as_short (§ion, &font->point_size) != 0) goto fail; } - else if (grub_memcmp (section.name, section_names_weight, 4) == 0) + else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_WEIGHT, + sizeof(FONT_FORMAT_SECTION_NAMES_WEIGHT) - 1) == 0) { char *wt; wt = read_section_as_string (§ion); @@ -553,32 +546,42 @@ grub_font_load (const char *filename) font->weight = FONT_WEIGHT_BOLD; grub_free (wt); } - else if (grub_memcmp (section.name, section_names_max_char_width, 4) == 0) + else if (grub_memcmp (section.name, + FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH, + sizeof(FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH) - 1) == 0) { if (read_section_as_short (§ion, &font->max_char_width) != 0) goto fail; } - else if (grub_memcmp (section.name, section_names_max_char_height, 4) == 0) + else if (grub_memcmp (section.name, + FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT, + sizeof(FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT) - 1) == 0) { if (read_section_as_short (§ion, &font->max_char_height) != 0) goto fail; } - else if (grub_memcmp (section.name, section_names_ascent, 4) == 0) + else if (grub_memcmp (section.name, + FONT_FORMAT_SECTION_NAMES_ASCENT, + sizeof(FONT_FORMAT_SECTION_NAMES_ASCENT) - 1) == 0) { if (read_section_as_short (§ion, &font->ascent) != 0) goto fail; } - else if (grub_memcmp (section.name, section_names_descent, 4) == 0) + else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_DESCENT, + sizeof(FONT_FORMAT_SECTION_NAMES_DESCENT) - 1) == 0) { if (read_section_as_short (§ion, &font->descent) != 0) goto fail; } - else if (grub_memcmp (section.name, section_names_char_index, 4) == 0) + else if (grub_memcmp (section.name, + FONT_FORMAT_SECTION_NAMES_CHAR_INDEX, + sizeof(FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) - 1) == 0) { if (load_font_index (file, section.length, font) != 0) goto fail; } - else if (grub_memcmp (section.name, section_names_data, 4) == 0) + else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_DATA, + sizeof(FONT_FORMAT_SECTION_NAMES_DATA) - 1) == 0) { /* When the DATA section marker is reached, we stop reading. */ break; diff --git a/include/grub/fontformat.h b/include/grub/fontformat.h new file mode 100644 index 000000000..b5060588c --- /dev/null +++ b/include/grub/fontformat.h @@ -0,0 +1,38 @@ +/* + * 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_FONT_FORMAT_HEADER +#define GRUB_FONT_FORMAT_HEADER 1 + +/* FONT_FORMAT_PFF2_MAGIC use only 4 relevants bytes and the \0. */ +#define FONT_FORMAT_PFF2_MAGIC "PFF2" +#define FONT_FORMAT_SECTION_NAMES_FILE "FILE" +#define FONT_FORMAT_SECTION_NAMES_FONT_NAME "NAME" +#define FONT_FORMAT_SECTION_NAMES_POINT_SIZE "PTSZ" +#define FONT_FORMAT_SECTION_NAMES_WEIGHT "WEIG" +#define FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH "MAXW" +#define FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT "MAXH" +#define FONT_FORMAT_SECTION_NAMES_ASCENT "ASCE" +#define FONT_FORMAT_SECTION_NAMES_DESCENT "DESC" +#define FONT_FORMAT_SECTION_NAMES_CHAR_INDEX "CHIX" +#define FONT_FORMAT_SECTION_NAMES_DATA "DATA" +#define FONT_FORMAT_SECTION_NAMES_FAMILY "FAMI" +#define FONT_FORMAT_SECTION_NAMES_SLAN "SLAN" + +#endif /* ! GRUB_FONT_FORMAT_HEADER */ + diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index 38906a70e..51e2e494c 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -392,9 +393,10 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file) offset = 0; leng = grub_cpu_to_be32 (4); - grub_util_write_image ("FILE", 4, file); + grub_util_write_image (FONT_FORMAT_SECTION_NAMES_FILE, + sizeof(FONT_FORMAT_SECTION_NAMES_FILE) - 1, file); grub_util_write_image ((char *) &leng, 4, file); - grub_util_write_image ("PFF2", 4, file); + grub_util_write_image (FONT_FORMAT_PFF2_MAGIC, 4, file); offset += 12; if (! font_info->name) @@ -416,20 +418,25 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file) font_name = xasprintf ("%s %s %d", font_info->name, &style_name[1], font_info->size); - write_string_section ("NAME", font_name, &offset, file); - write_string_section ("FAMI", font_info->name, &offset, file); - write_string_section ("WEIG", + write_string_section (FONT_FORMAT_SECTION_NAMES_FONT_NAME, + font_name, &offset, file); + write_string_section (FONT_FORMAT_SECTION_NAMES_FAMILY, + font_info->name, &offset, file); + write_string_section (FONT_FORMAT_SECTION_NAMES_WEIGHT, (font_info->style & FT_STYLE_FLAG_BOLD) ? "bold" : "normal", &offset, file); - write_string_section ("SLAN", + write_string_section (FONT_FORMAT_SECTION_NAMES_SLAN, (font_info->style & FT_STYLE_FLAG_ITALIC) ? "italic" : "normal", &offset, file); - write_be16_section ("PTSZ", font_info->size, &offset, file); - write_be16_section ("MAXW", font_info->max_width, &offset, file); - write_be16_section ("MAXH", font_info->max_height, &offset, file); + write_be16_section (FONT_FORMAT_SECTION_NAMES_POINT_SIZE, + font_info->size, &offset, file); + write_be16_section (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH, + font_info->max_width, &offset, file); + write_be16_section (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT, + font_info->max_height, &offset, file); if (! font_info->desc) { @@ -447,8 +454,10 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file) font_info->asce = font_info->max_y; } - write_be16_section ("ASCE", font_info->asce, &offset, file); - write_be16_section ("DESC", font_info->desc, &offset, file); + write_be16_section (FONT_FORMAT_SECTION_NAMES_ASCENT, + font_info->asce, &offset, file); + write_be16_section (FONT_FORMAT_SECTION_NAMES_DESCENT, + font_info->desc, &offset, file); if (font_verbosity > 0) { @@ -479,7 +488,9 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file) printf ("Number of glyph: %d\n", num); leng = grub_cpu_to_be32 (num * 9); - grub_util_write_image ("CHIX", 4, file); + grub_util_write_image (FONT_FORMAT_SECTION_NAMES_CHAR_INDEX, + sizeof(FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) - 1, + file); grub_util_write_image ((char *) &leng, 4, file); offset += 8 + num * 9 + 8; @@ -495,7 +506,8 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file) } leng = 0xffffffff; - grub_util_write_image ("DATA", 4, file); + grub_util_write_image (FONT_FORMAT_SECTION_NAMES_DATA, + sizeof(FONT_FORMAT_SECTION_NAMES_DATA) - 1, file); grub_util_write_image ((char *) &leng, 4, file); for (cur = font_info->glyph; cur; cur = cur->next) From b510928c3857245d4415cab78b87279ce6bcfbd3 Mon Sep 17 00:00:00 2001 From: carles Date: Tue, 26 Jan 2010 21:23:59 +0000 Subject: [PATCH 074/237] 2010-01-26 Carles Pina i Estany * util/bin2h.c (usage): Fix warning (space after backslash). --- ChangeLog | 4 ++++ util/bin2h.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a0628fd7d..ca129a3be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-26 Carles Pina i Estany + + * util/bin2h.c (usage): Fix warning (space after backslash). + 2010-01-25 Carles Pina i Estany * font/font.c: Include `grub/fontformat.h. diff --git a/util/bin2h.c b/util/bin2h.c index 3a0723ea3..e81ede8c6 100644 --- a/util/bin2h.c +++ b/util/bin2h.c @@ -42,7 +42,7 @@ usage (int status) Usage: %s [OPTIONS] SYMBOL-NAME\n\ \n\ Convert a binary file to a C header.\n\ -\n\ +\n\ -h, --help display this message and exit\n\ -V, --version print version information and exit\n\ \n\ From aa2f9dd26d5dac1f64a5a08417c4638f47e7f564 Mon Sep 17 00:00:00 2001 From: carles Date: Tue, 26 Jan 2010 23:07:37 +0000 Subject: [PATCH 075/237] Correct ChangeLog entry date. --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ca129a3be..b54d3bcbc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,7 +2,7 @@ * util/bin2h.c (usage): Fix warning (space after backslash). -2010-01-25 Carles Pina i Estany +2010-01-26 Carles Pina i Estany * font/font.c: Include `grub/fontformat.h. Remove font file format constants. From 254e2ce59664771f59f8698b1dd62429caccbda0 Mon Sep 17 00:00:00 2001 From: carles Date: Wed, 27 Jan 2010 00:19:46 +0000 Subject: [PATCH 076/237] 2010-01-27 Carles Pina i Estany * util/lvm.c: New macro LVM_DEV_MAPPER_STRING. (grub_util_lvm_isvolume): Use LVM_DEV_MAPPER_STRING. --- ChangeLog | 5 +++++ util/lvm.c | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index b54d3bcbc..e3988f150 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-27 Carles Pina i Estany + + * util/lvm.c: New macro LVM_DEV_MAPPER_STRING. + (grub_util_lvm_isvolume): Use LVM_DEV_MAPPER_STRING. + 2010-01-26 Carles Pina i Estany * util/bin2h.c (usage): Fix warning (space after backslash). diff --git a/util/lvm.c b/util/lvm.c index 8a8ed1e4c..0a0916344 100644 --- a/util/lvm.c +++ b/util/lvm.c @@ -26,6 +26,8 @@ #include #include +#define LVM_DEV_MAPPER_STRING "/dev/mapper/" + int grub_util_lvm_isvolume (char *name) { @@ -33,10 +35,10 @@ grub_util_lvm_isvolume (char *name) struct stat st; int err; - devname = xmalloc (strlen (name) + 13); + devname = xmalloc (strlen (name) + sizeof (LVM_DEV_MAPPER_STRING)); - strcpy (devname, "/dev/mapper/"); - strcpy (devname+12, name); + strcpy (devname, LVM_DEV_MAPPER_STRING); + strcpy (devname + sizeof(LVM_DEV_MAPPER_STRING) - 1, name); err = stat (devname, &st); free (devname); From af75a9f19a81c2c5fada0c44779a491fae388e96 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Wed, 27 Jan 2010 01:49:11 +0000 Subject: [PATCH 077/237] 2010-01-27 Robert Millan * util/grub-fstest.c (fstest): Rewrite allocation, fixing a few memleak conditions. --- ChangeLog | 5 +++++ util/grub-fstest.c | 37 ++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index e3988f150..c4930acb8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-27 Robert Millan + + * util/grub-fstest.c (fstest): Rewrite allocation, fixing a few + memleak conditions. + 2010-01-27 Carles Pina i Estany * util/lvm.c: New macro LVM_DEV_MAPPER_STRING. diff --git a/util/grub-fstest.c b/util/grub-fstest.c index bf30286a4..c03c43451 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -280,27 +280,29 @@ fstest (char **images, int num_disks, int cmd, int n, char **args) { char *host_file; char *loop_name; - char *argv[3] = { "-p" }; + char *argv[3]; int i; + argv[0] = "-p"; + for (i = 0; i < num_disks; i++) { loop_name = grub_xasprintf ("loop%d", i); - host_file = grub_xasprintf ("(host)%s", images[i]); + if (!loop_name) + grub_util_error (grub_errmsg); - if (!loop_name || !host_file) - { - grub_free (loop_name); - grub_free (host_file); - grub_util_error (grub_errmsg); - return; - } + host_file = grub_xasprintf ("(host)%s", images[i]); + if (!host_file) + grub_util_error (grub_errmsg); argv[1] = loop_name; argv[2] = host_file; if (execute_command ("loopback", 3, argv)) grub_util_error ("loopback command fails"); + + grub_free (loop_name); + grub_free (host_file); } grub_lvm_fini (); @@ -336,19 +338,16 @@ fstest (char **images, int num_disks, int cmd, int n, char **args) for (i = 0; i < num_disks; i++) { - grub_free (loop_name); loop_name = grub_xasprintf ("loop%d", i); if (!loop_name) - { - grub_free (host_file); - grub_util_error (grub_errmsg); - return; - } - execute_command ("loopback", 2, argv); - } + grub_util_error (grub_errmsg); - grub_free (loop_name); - grub_free (host_file); + argv[1] = loop_name; + + execute_command ("loopback", 2, argv); + + grub_free (loop_name); + } } static struct option options[] = { From c294d9d8123c85abaebbc48a169e88f0cff08c39 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Wed, 27 Jan 2010 03:11:20 +0000 Subject: [PATCH 078/237] 2010-01-27 Robert Millan Remove unused parameter. * fs/iso9660.c (struct grub_iso9660_data): Remove `length' parameter. (grub_iso9660_open): Remove initialization of `data->length'. --- ChangeLog | 7 +++++++ fs/iso9660.c | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c4930acb8..6c79d2b30 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-01-27 Robert Millan + + Remove unused parameter. + + * fs/iso9660.c (struct grub_iso9660_data): Remove `length' parameter. + (grub_iso9660_open): Remove initialization of `data->length'. + 2010-01-27 Robert Millan * util/grub-fstest.c (fstest): Rewrite allocation, fixing a few diff --git a/fs/iso9660.c b/fs/iso9660.c index a8a310f50..cadfbba2b 100644 --- a/fs/iso9660.c +++ b/fs/iso9660.c @@ -136,7 +136,6 @@ struct grub_iso9660_data struct grub_iso9660_primary_voldesc voldesc; grub_disk_t disk; unsigned int first_sector; - unsigned int length; int rockridge; int susp_skip; int joliet; @@ -744,7 +743,6 @@ grub_iso9660_open (struct grub_file *file, const char *name) goto fail; data->first_sector = foundnode->blk; - data->length = foundnode->size; file->data = data; file->size = foundnode->size; From 67667b9ced0abf5d0931c551d29a6faab2e1623e Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Wed, 27 Jan 2010 03:15:03 +0000 Subject: [PATCH 079/237] 2010-01-27 Robert Millan * kern/disk.c (grub_disk_read): Fix bug that would cause infinite loop when using read hooks on files whose size isn't sector-aligned. --- ChangeLog | 5 +++++ kern/disk.c | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6c79d2b30..e0ee80d22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-27 Robert Millan + + * kern/disk.c (grub_disk_read): Fix bug that would cause infinite + loop when using read hooks on files whose size isn't sector-aligned. + 2010-01-27 Robert Millan Remove unused parameter. diff --git a/kern/disk.c b/kern/disk.c index 544896f2f..075838d1e 100644 --- a/kern/disk.c +++ b/kern/disk.c @@ -464,12 +464,14 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, if (disk->read_hook) while (size) { + grub_size_t to_read = (size > GRUB_DISK_SECTOR_SIZE) ? GRUB_DISK_SECTOR_SIZE : size; (disk->read_hook) (sector, real_offset, - ((size > GRUB_DISK_SECTOR_SIZE) - ? GRUB_DISK_SECTOR_SIZE - : size)); + to_read); + if (grub_errno != GRUB_ERR_NONE) + goto finish; + sector++; - size -= GRUB_DISK_SECTOR_SIZE - real_offset; + size -= to_read - real_offset; real_offset = 0; } From 27dea7eda42de98a181a799ee52cd74f1cb201bd Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Wed, 27 Jan 2010 03:18:14 +0000 Subject: [PATCH 080/237] 2010-01-27 Robert Millan * util/hostfs.c: Include `'. (grub_hostfs_read): Handle errors from fseeko() and fread(). --- ChangeLog | 5 +++++ util/hostfs.c | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index e0ee80d22..60ce328bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-27 Robert Millan + + * util/hostfs.c: Include `'. + (grub_hostfs_read): Handle errors from fseeko() and fread(). + 2010-01-27 Robert Millan * kern/disk.c (grub_disk_read): Fix bug that would cause infinite diff --git a/util/hostfs.c b/util/hostfs.c index df930b42e..501ad4664 100644 --- a/util/hostfs.c +++ b/util/hostfs.c @@ -1,7 +1,7 @@ /* hostfs.c - Dummy filesystem to provide access to the hosts filesystem */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 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 @@ -26,6 +26,7 @@ #include #include +#include /* dirent.d_type is a BSD extension, not part of POSIX */ @@ -118,10 +119,17 @@ grub_hostfs_read (grub_file_t file, char *buf, grub_size_t len) FILE *f; f = (FILE *) file->data; - fseeko (f, file->offset, SEEK_SET); - int s = fread (buf, 1, len, f); + if (fseeko (f, file->offset, SEEK_SET) != 0) + { + grub_error (GRUB_ERR_OUT_OF_RANGE, "fseeko: %s", strerror (errno)); + return -1; + } - return s; + unsigned int s = fread (buf, 1, len, f); + if (s != len) + grub_error (GRUB_ERR_FILE_READ_ERROR, "fread: %s", strerror (errno)); + + return (signed) s; } static grub_err_t From e709ebe2ef8fc4b64fcf092744a3edd6bba2c9eb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 27 Jan 2010 16:29:21 +0100 Subject: [PATCH 081/237] 2010-01-27 Vladimir Serbinenko * commands/hashsum.c (hash_file): Avoid possible stack overflow by having a 4KiB and not 32KiB buffer size. --- ChangeLog | 5 +++++ commands/hashsum.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 60ce328bf..aceb55009 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-27 Vladimir Serbinenko + + * commands/hashsum.c (hash_file): Avoid possible stack overflow by + having a 4KiB and not 32KiB buffer size. + 2010-01-27 Robert Millan * util/hostfs.c: Include `'. diff --git a/commands/hashsum.c b/commands/hashsum.c index a4e71b844..951479fa7 100644 --- a/commands/hashsum.c +++ b/commands/hashsum.c @@ -57,7 +57,7 @@ static grub_err_t hash_file (grub_file_t file, const gcry_md_spec_t *hash, void *result) { grub_uint8_t context[hash->contextsize]; - char *readbuf[4096]; + grub_uint8_t readbuf[4096]; grub_memset (context, 0, sizeof (context)); hash->init (context); From 989e1f934b0d612ea9e06d0af61ad0f5586cb2e4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 27 Jan 2010 17:30:03 +0100 Subject: [PATCH 082/237] 2010-01-27 Vladimir Serbinenko * kern/disk.c (grub_disk_read): Fix offset computation when reading last sectors. --- ChangeLog | 5 +++++ kern/disk.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index aceb55009..ba4a7d7e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-27 Vladimir Serbinenko + + * kern/disk.c (grub_disk_read): Fix offset computation when reading + last sectors. + 2010-01-27 Vladimir Serbinenko * commands/hashsum.c (hash_file): Avoid possible stack overflow by diff --git a/kern/disk.c b/kern/disk.c index 075838d1e..a01373072 100644 --- a/kern/disk.c +++ b/kern/disk.c @@ -441,7 +441,7 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, grub_errno = GRUB_ERR_NONE; - num = ((size + GRUB_DISK_SECTOR_SIZE - 1) + num = ((size + real_offset + pos + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); p = grub_realloc (tmp_buf, num << GRUB_DISK_SECTOR_BITS); @@ -458,7 +458,7 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, goto finish; } - grub_memcpy (buf, tmp_buf + real_offset, size); + grub_memcpy (buf, tmp_buf + pos + real_offset, size); /* Call the read hook, if any. */ if (disk->read_hook) From 63533ab09361a8a623ec95cecdc20cc098fbca51 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 27 Jan 2010 17:47:36 +0100 Subject: [PATCH 083/237] 2010-01-27 Vladimir Serbinenko * normal/cmdline.c (grub_cmdline_get): Fix completion in the middle of the line. --- ChangeLog | 5 +++++ normal/cmdline.c | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ba4a7d7e3..a7f995e29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-27 Vladimir Serbinenko + + * normal/cmdline.c (grub_cmdline_get): Fix completion in the middle + of the line. + 2010-01-27 Vladimir Serbinenko * kern/disk.c (grub_disk_read): Fix offset computation when reading diff --git a/normal/cmdline.c b/normal/cmdline.c index bcffffeab..997965fca 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -419,10 +419,13 @@ grub_cmdline_get (const char *prompt) int restore; char *insertu8; char *bufu8; + grub_uint32_t c; + c = buf[lpos]; buf[lpos] = '\0'; bufu8 = grub_ucs4_to_utf8_alloc (buf, lpos); + buf[lpos] = c; if (!bufu8) { grub_print_error (); @@ -462,8 +465,19 @@ grub_cmdline_get (const char *prompt) insertlen, 0); if (t > 0) { - insert[t] = 0; - cl_insert (insert); + if (insert[t-1] == ' ' && buf[lpos] == ' ') + { + insert[t-1] = 0; + if (t != 1) + cl_insert (insert); + lpos++; + cl_set_pos_all (); + } + else + { + insert[t] = 0; + cl_insert (insert); + } } grub_free (insertu8); From 2e1cb9bbbf3e5d6ee800037b26f9ae9707787d68 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 28 Jan 2010 12:49:40 +0000 Subject: [PATCH 084/237] 2010-01-28 Colin Watson * util/grub.d/10_linux.in: This script does not use any of the contents of gettext.sh, only the external command `gettext', so stop sourcing it. (Moreover, gettext.sh isn't necessarily installed in the same prefix as GRUB.) * util/grub.d/10_kfreebsd.in: Likewise. --- ChangeLog | 8 ++++++++ util/grub.d/10_kfreebsd.in | 1 - util/grub.d/10_linux.in | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a7f995e29..59e46f124 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-01-28 Colin Watson + + * util/grub.d/10_linux.in: This script does not use any of the + contents of gettext.sh, only the external command `gettext', so stop + sourcing it. (Moreover, gettext.sh isn't necessarily installed in + the same prefix as GRUB.) + * util/grub.d/10_kfreebsd.in: Likewise. + 2010-01-27 Vladimir Serbinenko * normal/cmdline.c (grub_cmdline_get): Fix completion in the middle diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index b84b90a33..62d2fe321 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -22,7 +22,6 @@ bindir=@bindir@ libdir=@libdir@ . ${libdir}/grub/grub-mkconfig_lib -. ${bindir}/gettext.sh export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR=@localedir@ diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 90a6e83e7..b1c75a25b 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -22,7 +22,6 @@ bindir=@bindir@ libdir=@libdir@ . ${libdir}/grub/grub-mkconfig_lib -. ${bindir}/gettext.sh export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR=@localedir@ From ec1444e6dffc8bf907439f1e0bd97c1fb53f78f0 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 28 Jan 2010 15:27:41 +0000 Subject: [PATCH 085/237] 2010-01-28 Robert Millan * Makefile.in (check): Exit with fail status when one of the tests fails. * tests/example_functional_test.c (example_test): Fix reversed assert. * tests/example_unit_test.c (example_test): Likewise. --- ChangeLog | 7 +++++++ Makefile.in | 10 ++++------ tests/example_functional_test.c | 2 +- tests/example_unit_test.c | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 59e46f124..d40f765a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-01-28 Robert Millan + + * Makefile.in (check): Exit with fail status when one of the tests + fails. + * tests/example_functional_test.c (example_test): Fix reversed assert. + * tests/example_unit_test.c (example_test): Likewise. + 2010-01-28 Colin Watson * util/grub.d/10_linux.in: This script does not use any of the diff --git a/Makefile.in b/Makefile.in index d0bbe3b25..aa03002f4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -473,23 +473,21 @@ distcheck: dist check: all $(UNIT_TESTS) $(FUNCTIONAL_TESTS) $(SCRIPTED_TESTS) @list="$(UNIT_TESTS)"; \ + set -e; \ for file in $$list; do \ $(builddir)/$$file; \ done @list="$(FUNCTIONAL_TESTS)"; \ + set -e; \ for file in $$list; do \ mod=`basename $$file .mod`; \ echo "insmod functional_test; insmod $$mod; functional_test" \ | $(builddir)/grub-shell; \ done @list="$(SCRIPTED_TESTS)"; \ + set -e; \ for file in $$list; do \ - echo "$$file:"; \ - if $(builddir)/$$file; then \ - echo "$$file: PASS"; \ - else \ - echo "$$file: FAIL"; \ - fi; \ + $(builddir)/$$file; \ done .SUFFIX: diff --git a/tests/example_functional_test.c b/tests/example_functional_test.c index f43c0f1ce..6802d2d53 100644 --- a/tests/example_functional_test.c +++ b/tests/example_functional_test.c @@ -28,7 +28,7 @@ example_test (void) /* 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); + grub_test_assert (2 != 3, "2 matches %d", 3); } /* Register example_test method as a functional test. */ diff --git a/tests/example_unit_test.c b/tests/example_unit_test.c index 4999f1412..d721a9d0a 100644 --- a/tests/example_unit_test.c +++ b/tests/example_unit_test.c @@ -31,7 +31,7 @@ example_test (void) /* 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); + grub_test_assert (2 != 3, "2 matches %d", 3); } /* Register example_test method as a unit test. */ From 275d6f6bd44f85d2b91a53cfe0622c26034fae8a Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Thu, 28 Jan 2010 21:43:28 +0530 Subject: [PATCH 086/237] fix grub-script-check --- include/grub/script_sh.h | 2 +- util/grub-script-check.c | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h index 0bd14abcd..f6177b02a 100644 --- a/include/grub/script_sh.h +++ b/include/grub/script_sh.h @@ -112,7 +112,7 @@ struct grub_script_cmd_menuentry struct grub_script_arglist *arglist; /* The sourcecode the entry will be generated from. */ - char *sourcecode; + const char *sourcecode; /* Options. XXX: Not used yet. */ int options; diff --git a/util/grub-script-check.c b/util/grub-script-check.c index 3bfd6a425..5bc5df1c1 100644 --- a/util/grub-script-check.c +++ b/util/grub-script-check.c @@ -82,16 +82,8 @@ grub_script_execute_cmdif (struct grub_script_cmd *cmd __attribute__ ((unused))) } grub_err_t -grub_script_execute_menuentry (struct grub_script_cmd *cmd) +grub_script_execute_menuentry (struct grub_script_cmd *cmd __attribute__ ((unused))) { - 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; } @@ -146,6 +138,7 @@ main (int argc, char *argv[]) auto grub_err_t get_config_line (char **line, int cont); grub_err_t get_config_line (char **line, int cont __attribute__ ((unused))) { + int i; char *cmdline = 0; size_t len = 0; ssize_t read; @@ -164,6 +157,17 @@ main (int argc, char *argv[]) if (verbose) grub_printf("%s", cmdline); + for (i = 0; cmdline[i] != '\0'; i++) + { + /* Replace tabs and carriage returns with spaces. */ + if (cmdline[i] == '\t' || cmdline[i] == '\r') + cmdline[i] = ' '; + + /* Replace '\n' with '\0'. */ + if (cmdline[i] == '\n') + cmdline[i] = '\0'; + } + *line = grub_strdup (cmdline); free (cmdline); From f45d2663b08b4df452e054261cbf229d9c4779a5 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Thu, 28 Jan 2010 21:46:59 +0530 Subject: [PATCH 087/237] add changelog --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index a7f995e29..c000b38d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-28 BVK Chaitanya + + * include/grub/script_sh.h (sourcecode): Add const qualifier. + * util/grub-script-check.c (getline): Fix empty lines case. + 2010-01-27 Vladimir Serbinenko * normal/cmdline.c (grub_cmdline_get): Fix completion in the middle From bf7fcba2d7665e01c6bd6f5c2fd9da4ce69d9674 Mon Sep 17 00:00:00 2001 From: Christian Schmitt Date: Thu, 28 Jan 2010 23:10:37 +0100 Subject: [PATCH 088/237] 2010-01-28 Christian Schmitt * util/ieee1275/grub-install.in: Fix nvsetenv arguments. --- ChangeLog | 4 ++++ util/ieee1275/grub-install.in | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4e30a39a8..f0d881599 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-28 Christian Schmitt + + * util/ieee1275/grub-install.in: Fix nvsetenv arguments. + 2010-01-28 BVK Chaitanya * include/grub/script_sh.h (sourcecode): Add const qualifier. diff --git a/util/ieee1275/grub-install.in b/util/ieee1275/grub-install.in index 9a26b0dca..97c485d55 100644 --- a/util/ieee1275/grub-install.in +++ b/util/ieee1275/grub-install.in @@ -46,8 +46,8 @@ install_device= debug=no update_nvram=yes -ofpathname=/usr/sbin/ofpathname -nvsetenv=/sbin/nvsetenv +ofpathname=`which ofpathname` +nvsetenv=`which nvsetenv` # Usage: usage # Print the usage. @@ -216,11 +216,11 @@ if test $update_nvram = yes; then } # Point boot-device at the new grub install - boot_device="boot-device $ofpath:$partno,\\grub" - "$nvsetenv" "$boot_device" || { + boot_device="$ofpath:$partno,\\grub" + "$nvsetenv" boot-device "$boot_device" || { echo "$nvsetenv failed." echo "You will have to set boot-device manually. At the Open Firmware prompt, type:" - echo " setenv $boot_device" + echo " setenv boot-device $boot_device" exit 1 } fi From 61e89d9db65c78389111b5e5e8696145a3eb1b82 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 31 Jan 2010 01:26:11 +0100 Subject: [PATCH 089/237] 2010-01-31 Vladimir Serbinenko * font/font.c (find_glyph): Check that bmp_idx is available before using it. (grub_font_get_string_width): Never call grub_font_get_glyph_internal with (font == NULL). --- ChangeLog | 7 +++++++ font/font.c | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index f0d881599..eced79d59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-01-31 Vladimir Serbinenko + + * font/font.c (find_glyph): Check that bmp_idx is available before + using it. + (grub_font_get_string_width): Never call grub_font_get_glyph_internal + with (font == NULL). + 2010-01-28 Christian Schmitt * util/ieee1275/grub-install.in: Fix nvsetenv arguments. diff --git a/font/font.c b/font/font.c index 639f4d720..16f2ed35b 100644 --- a/font/font.c +++ b/font/font.c @@ -668,7 +668,7 @@ find_glyph (const grub_font_t font, grub_uint32_t code) table = font->char_index; /* Use BMP index if possible. */ - if (code < 0x10000) + if (code < 0x10000 && font->bmp_idx) { if (font->bmp_idx[code] == 0xffff) return 0; @@ -942,8 +942,9 @@ grub_font_get_string_width (grub_font_t font, const char *str) struct grub_font_glyph * grub_font_get_glyph (grub_font_t font, grub_uint32_t code) { - struct grub_font_glyph *glyph; - glyph = grub_font_get_glyph_internal (font, code); + struct grub_font_glyph *glyph = 0; + if (font) + glyph = grub_font_get_glyph_internal (font, code); if (glyph == 0) { glyph = ascii_glyph_lookup (code); From fbab7b0794256f5b44c5f9769ea272e55cb6bcc1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 31 Jan 2010 01:57:17 +0100 Subject: [PATCH 090/237] Framebuffer on PowerPC-based macs --- conf/powerpc-ieee1275.rmk | 5 + include/grub/ieee1275/ieee1275.h | 4 + kern/ieee1275/openfw.c | 23 ++- video/ieee1275.c | 298 +++++++++++++++++++++++++++++++ 4 files changed, 327 insertions(+), 3 deletions(-) create mode 100644 video/ieee1275.c diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index 23bd2d620..8622293ab 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -70,6 +70,11 @@ boot_mod_SOURCES = commands/boot.c lib/i386/pc/biosnum.c boot_mod_CFLAGS = $(COMMON_CFLAGS) boot_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += ieee1275_fb.mod +ieee1275_fb_mod_SOURCES = video/ieee1275.c +ieee1275_fb_mod_CFLAGS = $(COMMON_CFLAGS) +ieee1275_fb_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For linux.mod. linux_mod_SOURCES = loader/powerpc/ieee1275/linux.c linux_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index 8b31e32e2..2aad199da 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -176,4 +176,8 @@ int EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size); char *EXPORT_FUNC(grub_ieee1275_encode_devname) (const char *path); char *EXPORT_FUNC(grub_ieee1275_get_filename) (const char *path); +int EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook) + (struct grub_ieee1275_devalias * + alias)); + #endif /* ! GRUB_IEEE1275_HEADER */ diff --git a/kern/ieee1275/openfw.c b/kern/ieee1275/openfw.c index 5f0aad119..684680231 100644 --- a/kern/ieee1275/openfw.c +++ b/kern/ieee1275/openfw.c @@ -72,7 +72,7 @@ grub_children_iterate (char *devpath, if (grub_ieee1275_get_property (child, "device_type", childtype, IEEE1275_MAX_PROP_LEN, &actual)) - continue; + childtype[0] = 0; if (grub_ieee1275_package_to_path (child, childpath, IEEE1275_MAX_PATH_LEN, &actual)) @@ -82,7 +82,10 @@ grub_children_iterate (char *devpath, IEEE1275_MAX_PROP_LEN, &actual)) continue; - fullname = grub_xasprintf ("%s/%s", devpath, childname); + if (devpath[0] == '/' && devpath[1] == 0) + fullname = grub_xasprintf ("/%s", childname); + else + fullname = grub_xasprintf ("%s/%s", devpath, childname); if (!fullname) { grub_free (childname); @@ -99,7 +102,7 @@ grub_children_iterate (char *devpath, if (ret) break; } - while (grub_ieee1275_peer (child, &child)); + while (grub_ieee1275_peer (child, &child) != -1); grub_free (childname); grub_free (childpath); @@ -108,6 +111,20 @@ grub_children_iterate (char *devpath, return ret; } +int +grub_ieee1275_devices_iterate (int (*hook) (struct grub_ieee1275_devalias *alias)) +{ + auto int it_through (struct grub_ieee1275_devalias *alias); + int it_through (struct grub_ieee1275_devalias *alias) + { + if (hook (alias)) + return 1; + return grub_children_iterate (alias->name, it_through); + } + + return grub_children_iterate ("/", it_through); +} + /* Iterate through all device aliases. This function can be used to find a device of a specific type. */ int diff --git a/video/ieee1275.c b/video/ieee1275.c new file mode 100644 index 000000000..a9fc16a0f --- /dev/null +++ b/video/ieee1275.c @@ -0,0 +1,298 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 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 . + */ + +#define grub_video_render_target grub_video_fbrender_target + +#include +#include +#include +#include +#include +#include +#include +#include + +/* Only 8-bit indexed color is supported for now. */ + +static unsigned old_width, old_height; +static int restore_needed; +static char *display; + +static struct +{ + struct grub_video_mode_info mode_info; + struct grub_video_render_target *render_target; + grub_uint8_t *ptr; +} framebuffer; + +static grub_err_t +grub_video_ieee1275_set_palette (unsigned int start, unsigned int count, + struct grub_video_palette_data *palette_data); + +static void +set_video_mode (unsigned width __attribute__ ((unused)), + unsigned height __attribute__ ((unused))) +{ + /* TODO */ +} + +static void +find_display (void) +{ + auto int hook (struct grub_ieee1275_devalias *alias); + int hook (struct grub_ieee1275_devalias *alias) + { + if (grub_strcmp (alias->type, "display") == 0) + { + grub_dprintf ("video", "Found display %s\n", alias->name); + display = grub_strdup (alias->name); + return 1; + } + return 0; + } + + grub_ieee1275_devices_iterate (hook); +} + +static grub_err_t +grub_video_ieee1275_init (void) +{ + grub_memset (&framebuffer, 0, sizeof(framebuffer)); + return grub_video_fb_init (); +} + +static grub_err_t +grub_video_ieee1275_fini (void) +{ + if (restore_needed) + { + set_video_mode (old_width, old_height); + restore_needed = 0; + } + return grub_video_fb_fini (); +} + +static grub_err_t +grub_video_ieee1275_fill_mode_info (grub_ieee1275_phandle_t dev, + struct grub_video_mode_info *out) +{ + grub_uint32_t tmp; + + grub_memset (out, 0, sizeof (*out)); + + if (grub_ieee1275_get_integer_property (dev, "width", &tmp, + sizeof (tmp), 0)) + return grub_error (GRUB_ERR_IO, "Couldn't retrieve display width."); + out->width = tmp; + + if (grub_ieee1275_get_integer_property (dev, "height", &tmp, + sizeof (tmp), 0)) + return grub_error (GRUB_ERR_IO, "Couldn't retrieve display height."); + out->height = tmp; + + if (grub_ieee1275_get_integer_property (dev, "linebytes", &tmp, + sizeof (tmp), 0)) + return grub_error (GRUB_ERR_IO, "Couldn't retrieve display pitch."); + out->pitch = tmp; + + out->mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR; + out->bpp = 8; + out->bytes_per_pixel = 1; + out->number_of_colors = 256; + + out->blit_format = grub_video_get_blit_format (out); + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_video_ieee1275_setup (unsigned int width, unsigned int height, + unsigned int mode_type __attribute__ ((unused)), + unsigned int mode_mask __attribute__ ((unused))) +{ + grub_uint32_t current_width, current_height, address; + grub_err_t err; + grub_ieee1275_phandle_t dev; + + if (!display) + return grub_error (GRUB_ERR_IO, "Couldn't find display device."); + + if (grub_ieee1275_finddevice (display, &dev)) + return grub_error (GRUB_ERR_IO, "Couldn't open display device."); + + if (grub_ieee1275_get_integer_property (dev, "width", ¤t_width, + sizeof (current_width), 0)) + return grub_error (GRUB_ERR_IO, "Couldn't retrieve display width."); + + if (grub_ieee1275_get_integer_property (dev, "height", ¤t_height, + sizeof (current_width), 0)) + return grub_error (GRUB_ERR_IO, "Couldn't retrieve display height."); + + if ((width == current_width && height == current_height) + || (width == 0 && height == 0)) + { + grub_dprintf ("video", "IEEE1275: keeping current mode %dx%d\n", + current_width, current_height); + } + else + { + grub_dprintf ("video", "IEEE1275: Setting mode %dx%d\n", width, height); + /* TODO. */ + } + + err = grub_video_ieee1275_fill_mode_info (dev, &framebuffer.mode_info); + if (err) + { + grub_dprintf ("video", "IEEE1275: couldn't fill mode info\n"); + return err; + } + + if (grub_ieee1275_get_integer_property (dev, "address", &address, + sizeof (address), 0)) + return grub_error (GRUB_ERR_IO, "Couldn't retrieve display address."); + + framebuffer.ptr = (void *) address; + + grub_video_ieee1275_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS, + grub_video_fbstd_colors); + + grub_dprintf ("video", "IEEE1275: initialising FB @ %p %dx%dx%d\n", + framebuffer.ptr, framebuffer.mode_info.width, + framebuffer.mode_info.height, framebuffer.mode_info.bpp); + + err = grub_video_fb_create_render_target_from_pointer + (&framebuffer.render_target, &framebuffer.mode_info, framebuffer.ptr); + + if (err) + { + grub_dprintf ("video", "IEEE1275: Couldn't create FB target\n"); + return err; + } + + err = grub_video_fb_set_active_render_target (framebuffer.render_target); + + if (err) + { + grub_dprintf ("video", "IEEE1275: Couldn't set FB target\n"); + return err; + } + + err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS, + grub_video_fbstd_colors); + + if (err) + grub_dprintf ("video", "IEEE1275: Couldn't set palette\n"); + else + grub_dprintf ("video", "IEEE1275: Success\n"); + + return err; +} + +static grub_err_t +grub_video_ieee1275_swap_buffers (void) +{ + /* TODO: Implement buffer swapping. */ + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_video_ieee1275_set_active_render_target (struct grub_video_render_target *target) +{ + if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY) + target = framebuffer.render_target; + + return grub_video_fb_set_active_render_target (target); +} + +static grub_err_t +grub_video_ieee1275_get_info_and_fini (struct grub_video_mode_info *mode_info, + void **framebuf) +{ + grub_memcpy (mode_info, &(framebuffer.mode_info), sizeof (*mode_info)); + *framebuf = (char *) framebuffer.ptr; + + grub_video_fb_fini (); + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_video_ieee1275_set_palette (unsigned int start, unsigned int count, + struct grub_video_palette_data *palette_data) +{ + grub_err_t err; + struct grub_video_palette_data fb_palette_data[256]; + + err = grub_video_fb_set_palette (start, count, palette_data); + if (err) + return err; + + grub_video_fb_get_palette (0, 256, fb_palette_data); + + /* TODO. */ + + return GRUB_ERR_NONE; +} + +static struct grub_video_adapter grub_video_ieee1275_adapter = + { + .name = "IEEE1275 video driver", + + .init = grub_video_ieee1275_init, + .fini = grub_video_ieee1275_fini, + .setup = grub_video_ieee1275_setup, + .get_info = grub_video_fb_get_info, + .get_info_and_fini = grub_video_ieee1275_get_info_and_fini, + .set_palette = grub_video_ieee1275_set_palette, + .get_palette = grub_video_fb_get_palette, + .set_viewport = grub_video_fb_set_viewport, + .get_viewport = grub_video_fb_get_viewport, + .map_color = grub_video_fb_map_color, + .map_rgb = grub_video_fb_map_rgb, + .map_rgba = grub_video_fb_map_rgba, + .unmap_color = grub_video_fb_unmap_color, + .fill_rect = grub_video_fb_fill_rect, + .blit_bitmap = grub_video_fb_blit_bitmap, + .blit_render_target = grub_video_fb_blit_render_target, + .scroll = grub_video_fb_scroll, + .swap_buffers = grub_video_ieee1275_swap_buffers, + .create_render_target = grub_video_fb_create_render_target, + .delete_render_target = grub_video_fb_delete_render_target, + .set_active_render_target = grub_video_ieee1275_set_active_render_target, + .get_active_render_target = grub_video_fb_get_active_render_target, + + .next = 0 + }; + +GRUB_MOD_INIT(ieee1275_fb) +{ + find_display (); + if (display) + grub_video_register (&grub_video_ieee1275_adapter); +} + +GRUB_MOD_FINI(ieee1275_fb) +{ + if (restore_needed) + { + set_video_mode (old_width, old_height); + restore_needed = 0; + } + if (display) + grub_video_unregister (&grub_video_ieee1275_adapter); + grub_free (display); +} From 3b205d4ddf7c61363f9868dba14e8b95c22c95b4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 31 Jan 2010 11:11:03 +0100 Subject: [PATCH 091/237] 2010-01-31 Vladimir Serbinenko * disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Fix off-by-one error. --- ChangeLog | 4 ++++ disk/ieee1275/ofdisk.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index eced79d59..4598e1b74 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-31 Vladimir Serbinenko + + * disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Fix off-by-one error. + 2010-01-31 Vladimir Serbinenko * font/font.c (find_glyph): Check that bmp_idx is available before diff --git a/disk/ieee1275/ofdisk.c b/disk/ieee1275/ofdisk.c index c8c4d1a4e..051ece0b9 100644 --- a/disk/ieee1275/ofdisk.c +++ b/disk/ieee1275/ofdisk.c @@ -118,7 +118,7 @@ grub_ofdisk_iterate (int (*hook) (const char *name)) static char * compute_dev_path (const char *name) { - char *devpath = grub_malloc (grub_strlen (name) + 2); + char *devpath = grub_malloc (grub_strlen (name) + 3); char *p, c; if (!devpath) From 996649b073c98b4f13d2908cf887f4bd52d2ce5f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 3 Feb 2010 00:43:55 +0100 Subject: [PATCH 092/237] 2010-02-03 Vladimir Serbinenko * disk/i386/pc/biosdisk.c (grub_biosdisk_read): Handle non-2048 aligned CDROM reads. (grub_biosdisk_write): Refuse to write to CDROM. --- ChangeLog | 6 ++++++ disk/i386/pc/biosdisk.c | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4598e1b74..83d0c58a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-02-03 Vladimir Serbinenko + + * disk/i386/pc/biosdisk.c (grub_biosdisk_read): Handle non-2048 aligned + CDROM reads. + (grub_biosdisk_write): Refuse to write to CDROM. + 2010-01-31 Vladimir Serbinenko * disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Fix off-by-one error. diff --git a/disk/i386/pc/biosdisk.c b/disk/i386/pc/biosdisk.c index 682474b1a..94d0e3708 100644 --- a/disk/i386/pc/biosdisk.c +++ b/disk/i386/pc/biosdisk.c @@ -307,8 +307,17 @@ grub_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector, while (size) { grub_size_t len; + grub_size_t cdoff = 0; len = get_safe_sectors (sector, data->sectors); + + if (data->flags & GRUB_BIOSDISK_FLAG_CDROM) + { + cdoff = (sector & 3) << GRUB_DISK_SECTOR_BITS; + len = ALIGN_UP (sector + len, 4) - (sector & ~3); + sector &= ~3; + } + if (len > size) len = size; @@ -316,7 +325,7 @@ grub_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector, GRUB_MEMORY_MACHINE_SCRATCH_SEG)) return grub_errno; - grub_memcpy (buf, (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, + grub_memcpy (buf, (void *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + cdoff), len << GRUB_DISK_SECTOR_BITS); buf += len << GRUB_DISK_SECTOR_BITS; sector += len; @@ -332,6 +341,9 @@ grub_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector, { struct grub_biosdisk_data *data = disk->data; + if (data->flags & GRUB_BIOSDISK_FLAG_CDROM) + return grub_error (GRUB_ERR_IO, "can't write to CDROM"); + while (size) { grub_size_t len; From 399f6e4d9cf9c1a3aedf2a113f81680e03395c08 Mon Sep 17 00:00:00 2001 From: Torsten Landschoff Date: Wed, 3 Feb 2010 00:46:55 +0100 Subject: [PATCH 093/237] 2010-02-03 Torsten Landschoff * kern/disk.c (grub_disk_read): Fix offset computation when reading last sectors. --- ChangeLog | 5 +++++ kern/disk.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 83d0c58a8..d7ae963dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-03 Torsten Landschoff + + * kern/disk.c (grub_disk_read): Fix offset computation when reading + last sectors. + 2010-02-03 Vladimir Serbinenko * disk/i386/pc/biosdisk.c (grub_biosdisk_read): Handle non-2048 aligned diff --git a/kern/disk.c b/kern/disk.c index a01373072..5c30e1727 100644 --- a/kern/disk.c +++ b/kern/disk.c @@ -441,7 +441,7 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, grub_errno = GRUB_ERR_NONE; - num = ((size + real_offset + pos + GRUB_DISK_SECTOR_SIZE - 1) + num = ((size + real_offset + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); p = grub_realloc (tmp_buf, num << GRUB_DISK_SECTOR_BITS); @@ -458,7 +458,7 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, goto finish; } - grub_memcpy (buf, tmp_buf + pos + real_offset, size); + grub_memcpy (buf, tmp_buf + real_offset, size); /* Call the read hook, if any. */ if (disk->read_hook) From 2b4068e99251e7e6e123b8440375b6f64fe73291 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 3 Feb 2010 00:49:35 +0100 Subject: [PATCH 094/237] 2010-02-03 Vladimir Serbinenko * util/hostdisk.c (open_device): Don't use partition device when reading before the partition. (grub_util_biosdisk_read): Don't read from partition and before the partition in single operation. (grub_util_biosdisk_write): Don't write to partition and before the partition in single operation. --- ChangeLog | 9 +++++++++ util/hostdisk.c | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d7ae963dd..54a51afc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-02-03 Vladimir Serbinenko + + * util/hostdisk.c (open_device): Don't use partition device when reading + before the partition. + (grub_util_biosdisk_read): Don't read from partition and before the + partition in single operation. + (grub_util_biosdisk_write): Don't write to partition and before the + partition in single operation. + 2010-02-03 Torsten Landschoff * kern/disk.c (grub_disk_read): Fix offset computation when reading diff --git a/util/hostdisk.c b/util/hostdisk.c index a594f75ec..5c56b7579 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -336,7 +336,8 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) char dev[PATH_MAX]; strcpy (dev, map[disk->id].device); - if (disk->partition && strncmp (map[disk->id].device, "/dev/", 5) == 0) + if (disk->partition && sector >= disk->partition->start + && strncmp (map[disk->id].device, "/dev/", 5) == 0) is_partition = linux_find_partition (dev, disk->partition->start); /* Open the partition. */ @@ -490,6 +491,23 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector, { int fd; + /* Split pre-partition and partition reads. */ + if (disk->partition && sector < disk->partition->start + && sector + size > disk->partition->start) + { + grub_err_t err; + err = grub_util_biosdisk_read (disk, sector, + disk->partition->start - sector, + buf); + if (err) + return err; + + return grub_util_biosdisk_read (disk, disk->partition->start, + size - (disk->partition->start - sector), + buf + ((disk->partition->start - sector) + << GRUB_DISK_SECTOR_BITS)); + } + fd = open_device (disk, sector, O_RDONLY); if (fd < 0) return grub_errno; @@ -527,6 +545,23 @@ grub_util_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector, { int fd; + /* Split pre-partition and partition writes. */ + if (disk->partition && sector < disk->partition->start + && sector + size > disk->partition->start) + { + grub_err_t err; + err = grub_util_biosdisk_write (disk, sector, + disk->partition->start - sector, + buf); + if (err) + return err; + + return grub_util_biosdisk_write (disk, disk->partition->start, + size - (disk->partition->start - sector), + buf + ((disk->partition->start - sector) + << GRUB_DISK_SECTOR_BITS)); + } + fd = open_device (disk, sector, O_WRONLY); if (fd < 0) return grub_errno; From 98f5714739f9978b4e2c16941ba0b75a9b9bb826 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 3 Feb 2010 01:34:55 +0100 Subject: [PATCH 095/237] Fix mips compilation --- conf/mips-yeeloong.rmk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/mips-yeeloong.rmk b/conf/mips-yeeloong.rmk index 964f29384..eb0dc9676 100644 --- a/conf/mips-yeeloong.rmk +++ b/conf/mips-yeeloong.rmk @@ -21,7 +21,7 @@ kernel_img_SOURCES = kern/$(target_cpu)/startup.S \ font/font_cmd.c font/font.c io/bufio.c \ video/video.c video/fb/video_fb.c video/fb/fbblit.c \ video/fb/fbfill.c video/fb/fbutil.c video/bitmap.c \ - video/sm712.c bus/pci.c bus/bonito.c \ + video/bitmap_scale.c video/sm712.c bus/pci.c bus/bonito.c \ term/gfxterm.c commands/extcmd.c lib/arg.c \ symlist.c kernel_img_CFLAGS = $(COMMON_CFLAGS) -DUSE_ASCII_FAILBACK From 58b78c121d96defe92ea8e60fe6b730cbd0f496d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 5 Feb 2010 23:04:09 +0100 Subject: [PATCH 096/237] error on unsupported resolution --- video/ieee1275.c | 1 + 1 file changed, 1 insertion(+) diff --git a/video/ieee1275.c b/video/ieee1275.c index a9fc16a0f..21b65bd32 100644 --- a/video/ieee1275.c +++ b/video/ieee1275.c @@ -152,6 +152,7 @@ grub_video_ieee1275_setup (unsigned int width, unsigned int height, { grub_dprintf ("video", "IEEE1275: Setting mode %dx%d\n", width, height); /* TODO. */ + return grub_error (GRUB_ERR_IO, "can't set mode %dx%d", width, height); } err = grub_video_ieee1275_fill_mode_info (dev, &framebuffer.mode_info); From 4f8528fc2b30a7ef05f7896f54cec961ce49276b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Feb 2010 00:30:25 +0100 Subject: [PATCH 097/237] 2010-02-06 Vladimir Serbinenko * kern/ieee1275/openfw.c (grub_devalias_iterate): Stop iterating on error. --- ChangeLog | 5 +++++ kern/ieee1275/openfw.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 54a51afc0..d92d92117 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-06 Vladimir Serbinenko + + * kern/ieee1275/openfw.c (grub_devalias_iterate): Stop iterating on + error. + 2010-02-03 Vladimir Serbinenko * util/hostdisk.c (open_device): Don't use partition device when reading diff --git a/kern/ieee1275/openfw.c b/kern/ieee1275/openfw.c index 5f0aad119..39432c584 100644 --- a/kern/ieee1275/openfw.c +++ b/kern/ieee1275/openfw.c @@ -135,7 +135,7 @@ grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias)) /* Find the first property. */ aliasname[0] = '\0'; - while (grub_ieee1275_next_property (aliases, aliasname, aliasname)) + while (grub_ieee1275_next_property (aliases, aliasname, aliasname) > 0) { grub_ieee1275_phandle_t dev; grub_ssize_t pathlen; From 5562834e18004d4639dc6bcf1b9a20d925d9869c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Feb 2010 00:32:07 +0100 Subject: [PATCH 098/237] 2010-02-06 Vladimir Serbinenko * kern/ieee1275/openfw.c (grub_ieee1275_encode_devname): Support whole disk devices. --- ChangeLog | 5 +++++ kern/ieee1275/openfw.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d92d92117..e2a8f7575 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-06 Vladimir Serbinenko + + * kern/ieee1275/openfw.c (grub_ieee1275_encode_devname): Support whole + disk devices. + 2010-02-06 Vladimir Serbinenko * kern/ieee1275/openfw.c (grub_devalias_iterate): Stop iterating on diff --git a/kern/ieee1275/openfw.c b/kern/ieee1275/openfw.c index 39432c584..dd9a9138f 100644 --- a/kern/ieee1275/openfw.c +++ b/kern/ieee1275/openfw.c @@ -374,7 +374,7 @@ grub_ieee1275_encode_devname (const char *path) char *partition = grub_ieee1275_parse_args (path, GRUB_PARSE_PARTITION); char *encoding; - if (partition) + if (partition && partition[0]) { unsigned int partno = grub_strtoul (partition, 0, 0); From 3746a6bc3191c93a41216d03f8436c838dba6d99 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Feb 2010 15:25:59 +0100 Subject: [PATCH 099/237] 2010-02-06 Vladimir Serbinenko * fs/i386/pc/pxe.c (grub_pxefs_dir): Return with failure on non-pxe disk. (grub_pxefs_open): Likewise. --- ChangeLog | 6 ++++++ fs/i386/pc/pxe.c | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 117933d07..eed0f93bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-02-06 Vladimir Serbinenko + + * fs/i386/pc/pxe.c (grub_pxefs_dir): Return with failure on + non-pxe disk. + (grub_pxefs_open): Likewise. + 2010-02-06 Colin D Bennett * conf/common.rmk (pkglib_MODULES): Add gfxmenu.mod. diff --git a/fs/i386/pc/pxe.c b/fs/i386/pc/pxe.c index 8bfe17594..92529883e 100644 --- a/fs/i386/pc/pxe.c +++ b/fs/i386/pc/pxe.c @@ -173,12 +173,15 @@ static struct grub_disk_dev grub_pxe_dev = }; static grub_err_t -grub_pxefs_dir (grub_device_t device __attribute__ ((unused)), +grub_pxefs_dir (grub_device_t device, const char *path __attribute__ ((unused)), int (*hook) (const char *filename, const struct grub_dirhook_info *info) __attribute__ ((unused))) { + if (device->disk->dev->id != GRUB_DISK_DEVICE_PXE_ID) + return grub_error (GRUB_ERR_IO, "not a pxe disk"); + return GRUB_ERR_NONE; } @@ -194,6 +197,9 @@ grub_pxefs_open (struct grub_file *file, const char *name) struct grub_pxe_disk_data *disk_data = file->device->disk->data; grub_file_t file_int, bufio; + if (file->device->disk->dev->id != GRUB_DISK_DEVICE_PXE_ID) + return grub_error (GRUB_ERR_IO, "not a pxe disk"); + if (curr_file != 0) { grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &c.c2); From 911df80c54af99b2e83a6ab1e51e813f7a9f81f0 Mon Sep 17 00:00:00 2001 From: Yves Blusseau Date: Sat, 6 Feb 2010 15:37:23 +0100 Subject: [PATCH 100/237] 2010-02-06 Yves Blusseau * conf/common.rmk (grub_script_check_SOURCES): add missing dependencies. (grub_mkpasswd_pbkdf2_SOURCES): Likewise. --- ChangeLog | 5 +++++ conf/common.rmk | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index eed0f93bc..ba2561819 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-06 Yves Blusseau + + * conf/common.rmk (grub_script_check_SOURCES): add missing dependencies. + (grub_mkpasswd_pbkdf2_SOURCES): Likewise. + 2010-02-06 Vladimir Serbinenko * fs/i386/pc/pxe.c (grub_pxefs_dir): Return with failure on diff --git a/conf/common.rmk b/conf/common.rmk index 13ca431ba..6cce36395 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -94,7 +94,8 @@ grub_bin2h_SOURCES = gnulib/progname.c util/bin2h.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 \ +grub_script_check_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.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 @@ -759,7 +760,7 @@ password_pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS) password_pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS) bin_UTILITIES += grub-mkpasswd-pbkdf2 -grub_mkpasswd_pbkdf2_SOURCES = gnulib/progname.c util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c +grub_mkpasswd_pbkdf2_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c grub_mkpasswd_pbkdf2_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap -DGRUB_MKPASSWD=1 include $(srcdir)/conf/gcry.mk From 89494cb55c887e7b3150dbcfed50fd360521a67b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Feb 2010 15:51:22 +0100 Subject: [PATCH 101/237] 2010-02-06 Vladimir Serbinenko * disk/ieee1275/ofdisk.c (grub_ofdisk_read): Correct error handling. --- ChangeLog | 4 ++++ disk/ieee1275/ofdisk.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ba2561819..72d5bd899 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,10 @@ * conf/common.rmk (grub_script_check_SOURCES): add missing dependencies. (grub_mkpasswd_pbkdf2_SOURCES): Likewise. +2010-02-06 Vladimir Serbinenko + + * disk/ieee1275/ofdisk.c (grub_ofdisk_read): Correct error handling. + 2010-02-06 Vladimir Serbinenko * fs/i386/pc/pxe.c (grub_pxefs_dir): Return with failure on diff --git a/disk/ieee1275/ofdisk.c b/disk/ieee1275/ofdisk.c index 051ece0b9..238cff33d 100644 --- a/disk/ieee1275/ofdisk.c +++ b/disk/ieee1275/ofdisk.c @@ -248,7 +248,7 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector, (long long) sector); grub_ieee1275_read ((grub_ieee1275_ihandle_t) (unsigned long) disk->data, buf, size * 512UL, &actual); - if (actual != actual) + if (actual != (grub_ssize_t) (size * 512UL)) return grub_error (GRUB_ERR_READ_ERROR, "read error on block: %llu", (long long) sector); From 7b5d0fe4440c8a061ab9a9cb3089b546cb9f88f6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Feb 2010 15:53:39 +0100 Subject: [PATCH 102/237] Increase heap limit --- kern/ieee1275/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kern/ieee1275/init.c b/kern/ieee1275/init.c index f3a4f4d81..75f261a71 100644 --- a/kern/ieee1275/init.c +++ b/kern/ieee1275/init.c @@ -38,11 +38,11 @@ #define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024) /* The maximum heap size we're going to claim */ -#define HEAP_MAX_SIZE (unsigned long) (4 * 1024 * 1024) +#define HEAP_MAX_SIZE (unsigned long) (32 * 1024 * 1024) /* If possible, we will avoid claiming heap above this address, because it seems to cause relocation problems with OSes that link at 4 MiB */ -#define HEAP_MAX_ADDR (unsigned long) (4 * 1024 * 1024) +#define HEAP_MAX_ADDR (unsigned long) (32 * 1024 * 1024) extern char _start[]; extern char _end[]; From 09706ce58a85af4ba3b9306c02ebf8f560f857a0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Feb 2010 16:00:29 +0100 Subject: [PATCH 103/237] Fixed ChangeLog --- ChangeLog | 14 ++++++++++---- ChangeLog.gfxmenu | 0 ChangeLog.mkconfig | 5 ----- 3 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 ChangeLog.gfxmenu delete mode 100644 ChangeLog.mkconfig diff --git a/ChangeLog b/ChangeLog index 72d5bd899..c0c15024e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,18 +1,24 @@ +2010-02-06 Vladimir Serbinenko + + * disk/ieee1275/ofdisk.c (grub_ofdisk_read): Correct error handling. + 2010-02-06 Yves Blusseau * conf/common.rmk (grub_script_check_SOURCES): add missing dependencies. (grub_mkpasswd_pbkdf2_SOURCES): Likewise. -2010-02-06 Vladimir Serbinenko - - * disk/ieee1275/ofdisk.c (grub_ofdisk_read): Correct error handling. - 2010-02-06 Vladimir Serbinenko * fs/i386/pc/pxe.c (grub_pxefs_dir): Return with failure on non-pxe disk. (grub_pxefs_open): Likewise. +2010-02-06 Robert Millan + + * util/grub.d/10_hurd.in: Add --class information to menuentries. + * util/grub.d/10_kfreebsd.in: Likewise. + * util/grub.d/10_linux.in: Likewise. + 2010-02-06 Colin D Bennett * conf/common.rmk (pkglib_MODULES): Add gfxmenu.mod. diff --git a/ChangeLog.gfxmenu b/ChangeLog.gfxmenu deleted file mode 100644 index e69de29bb..000000000 diff --git a/ChangeLog.mkconfig b/ChangeLog.mkconfig deleted file mode 100644 index 665c938c7..000000000 --- a/ChangeLog.mkconfig +++ /dev/null @@ -1,5 +0,0 @@ -2010-01-07 Robert Millan - - * util/grub.d/10_hurd.in: Add --class information to menuentries. - * util/grub.d/10_kfreebsd.in: Likewise. - * util/grub.d/10_linux.in: Likewise. From e0a3000a5cab9e6d306e8af82301f9b0f1087940 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Feb 2010 16:00:56 +0100 Subject: [PATCH 104/237] ChangeLog --- ChangeLog.ofwfb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 ChangeLog.ofwfb diff --git a/ChangeLog.ofwfb b/ChangeLog.ofwfb new file mode 100644 index 000000000..49063b54d --- /dev/null +++ b/ChangeLog.ofwfb @@ -0,0 +1,16 @@ +2010-02-06 Vladimir Serbinenko + + * conf/powerpc-ieee1275.rmk (pkglib_MODULES): Add ieee1275_fb.mod. + (ieee1275_fb_mod_SOURCES): New variable. + (ieee1275_fb_mod_CFLAGS): Likewise. + (ieee1275_fb_mod_LDFLAGS): Likewise. + * include/grub/ieee1275/ieee1275.h (grub_ieee1275_devices_iterate): + New proto. + * kern/ieee1275/init.c (HEAP_MAX_SIZE): Increased. + (HEAP_MAX_ADDR): Likewise. + * kern/ieee1275/openfw.c (grub_children_iterate): Don't skip empty + type. + Correct stop condition. + (grub_ieee1275_devices_iterate): New function. + * video/ieee1275.c: New file. + From 51906b8c8a774ce75737fec2396472e0827f9186 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Feb 2010 16:32:45 +0100 Subject: [PATCH 105/237] 2010-02-06 Vladimir Serbinenko * loader/i386/pc/xnu.c (grub_xnu_set_video): Add const qualifier to modevar. Return grub_errno on allocation error. --- ChangeLog | 6 ++++++ loader/i386/pc/xnu.c | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c0c15024e..6da224094 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-02-06 Vladimir Serbinenko + + * loader/i386/pc/xnu.c (grub_xnu_set_video): Add const qualifier to + modevar. + Return grub_errno on allocation error. + 2010-02-06 Vladimir Serbinenko * disk/ieee1275/ofdisk.c (grub_ofdisk_read): Correct error handling. diff --git a/loader/i386/pc/xnu.c b/loader/i386/pc/xnu.c index 57937946b..39a595d9b 100644 --- a/loader/i386/pc/xnu.c +++ b/loader/i386/pc/xnu.c @@ -35,7 +35,8 @@ grub_xnu_set_video (struct grub_xnu_boot_params *params) { struct grub_video_mode_info mode_info; int ret; - char *tmp, *modevar; + char *tmp; + const char *modevar; void *framebuffer; grub_err_t err; struct grub_video_bitmap *bitmap = NULL; @@ -51,8 +52,7 @@ grub_xnu_set_video (struct grub_xnu_boot_params *params) { tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar); if (! tmp) - return grub_error (GRUB_ERR_OUT_OF_MEMORY, - "couldn't allocate temporary storag"); + return grub_errno; err = grub_video_set_mode (tmp, GRUB_VIDEO_MODE_TYPE_PURE_TEXT | GRUB_VIDEO_MODE_TYPE_DEPTH_MASK, From 468d69fec23203f110f1ae3610c123c58e929d4f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Feb 2010 20:49:57 +0100 Subject: [PATCH 106/237] 2010-02-06 Vladimir Serbinenko * fs/fat.c (grub_fat_iterate_dir): Free unibuf at exit. --- ChangeLog | 4 ++++ fs/fat.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6da224094..b9dfd7e73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-06 Vladimir Serbinenko + + * fs/fat.c (grub_fat_iterate_dir): Free unibuf at exit. + 2010-02-06 Vladimir Serbinenko * loader/i386/pc/xnu.c (grub_xnu_set_video): Add const qualifier to diff --git a/fs/fat.c b/fs/fat.c index d008dc10d..89050943c 100644 --- a/fs/fat.c +++ b/fs/fat.c @@ -592,6 +592,7 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data, } grub_free (filename); + grub_free (unibuf); return grub_errno; } From 6846cec5f76a14d2ca98f87e909d23e170e2da62 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Feb 2010 20:52:11 +0100 Subject: [PATCH 107/237] 2010-02-06 Vladimir Serbinenko * commands/ls.c (grub_ls_list_files): Free pathname on exit. --- ChangeLog | 4 ++++ commands/ls.c | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9dfd7e73..e60191a7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-06 Vladimir Serbinenko + + * commands/ls.c (grub_ls_list_files): Free pathname on exit. + 2010-02-06 Vladimir Serbinenko * fs/fat.c (grub_fat_iterate_dir): Free unibuf at exit. diff --git a/commands/ls.c b/commands/ls.c index 8a8319ac8..eb1049617 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -87,14 +87,13 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) int print_files_long (const char *filename, const struct grub_dirhook_info *info) { - char *pathname; - if ((! all) && (filename[0] == '.')) return 0; if (! info->dir) { grub_file_t file; + char *pathname; if (dirname[grub_strlen (dirname) - 1] == '/') pathname = grub_xasprintf ("%s%s", dirname, filename); @@ -110,6 +109,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) if (! file) { grub_errno = 0; + grub_free (pathname); return 0; } @@ -144,6 +144,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) } grub_file_close (file); + grub_free (pathname); } else grub_printf ("%-12s", "DIR"); From f51a90d0cff937298dcd754282235fb70f210663 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Feb 2010 20:59:56 +0100 Subject: [PATCH 108/237] 2010-02-06 Vladimir Serbinenko * partmap/sun.c (sun_partition_map_iterate): Restructure flow to fix buggy hook call and memory leak. --- ChangeLog | 5 ++++ partmap/sun.c | 64 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index e60191a7d..8de063bf2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-06 Vladimir Serbinenko + + * partmap/sun.c (sun_partition_map_iterate): Restructure flow to fix + buggy hook call and memory leak. + 2010-02-06 Vladimir Serbinenko * commands/ls.c (grub_ls_list_files): Free pathname on exit. diff --git a/partmap/sun.c b/partmap/sun.c index 42cf0d598..df9adb0c0 100644 --- a/partmap/sun.c +++ b/partmap/sun.c @@ -91,6 +91,7 @@ sun_partition_map_iterate (grub_disk_t disk, struct grub_disk raw; struct grub_sun_block block; int partnum; + grub_err_t err; raw = *disk; raw.partition = 0; @@ -100,36 +101,47 @@ sun_partition_map_iterate (grub_disk_t disk, return grub_errno; p->partmap = &grub_sun_partition_map; - if (grub_disk_read (&raw, 0, 0, sizeof (struct grub_sun_block), - &block) == GRUB_ERR_NONE) + err = grub_disk_read (&raw, 0, 0, sizeof (struct grub_sun_block), + &block); + if (err) { - if (GRUB_PARTMAP_SUN_MAGIC != grub_be_to_cpu16 (block.magic)) - grub_error (GRUB_ERR_BAD_PART_TABLE, "not a sun partition table"); + grub_free (p); + return err; + } - if (! grub_sun_is_valid (&block)) - grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum"); + if (GRUB_PARTMAP_SUN_MAGIC != grub_be_to_cpu16 (block.magic)) + { + grub_free (p); + return grub_error (GRUB_ERR_BAD_PART_TABLE, + "not a sun partition table"); + } - /* Maybe another error value would be better, because partition - table _is_ recognized but invalid. */ - for (partnum = 0; partnum < GRUB_PARTMAP_SUN_MAX_PARTS; partnum++) + if (! grub_sun_is_valid (&block)) + { + grub_free (p); + return grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum"); + } + + /* Maybe another error value would be better, because partition + table _is_ recognized but invalid. */ + for (partnum = 0; partnum < GRUB_PARTMAP_SUN_MAX_PARTS; partnum++) + { + struct grub_sun_partition_descriptor *desc; + + if (block.infos[partnum].id == 0 + || block.infos[partnum].id == GRUB_PARTMAP_SUN_WHOLE_DISK_ID) + continue; + + desc = &block.partitions[partnum]; + p->start = ((grub_uint64_t) grub_be_to_cpu32 (desc->start_cylinder) + * grub_be_to_cpu16 (block.ntrks) + * grub_be_to_cpu16 (block.nsect)); + p->len = grub_be_to_cpu32 (desc->num_sectors); + p->index = partnum; + if (p->len) { - struct grub_sun_partition_descriptor *desc; - - if (block.infos[partnum].id == 0 - || block.infos[partnum].id == GRUB_PARTMAP_SUN_WHOLE_DISK_ID) - continue; - - desc = &block.partitions[partnum]; - p->start = ((grub_uint64_t) grub_be_to_cpu32 (desc->start_cylinder) - * grub_be_to_cpu16 (block.ntrks) - * grub_be_to_cpu16 (block.nsect)); - p->len = grub_be_to_cpu32 (desc->num_sectors); - p->index = partnum; - if (p->len) - { - if (hook (disk, p)) - partnum = GRUB_PARTMAP_SUN_MAX_PARTS; - } + if (hook (disk, p)) + partnum = GRUB_PARTMAP_SUN_MAX_PARTS; } } From b6c0d9c2019996754e8a04b53a328c43c85f5c73 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Feb 2010 23:39:14 +0100 Subject: [PATCH 109/237] 2010-02-06 Vladimir Serbinenko * kern/misc.c (grub_utf8_to_ucs4): Don't eat valid characters preceeded by non-valid ones. * kern/term.c (grub_putchar): Likewise. --- ChangeLog | 6 ++++++ kern/misc.c | 4 ++++ kern/term.c | 9 +++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8de063bf2..e71065338 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-02-06 Vladimir Serbinenko + + * kern/misc.c (grub_utf8_to_ucs4): Don't eat valid characters preceeded + by non-valid ones. + * kern/term.c (grub_putchar): Likewise. + 2010-02-06 Vladimir Serbinenko * partmap/sun.c (sun_partition_map_iterate): Restructure flow to fix diff --git a/kern/misc.c b/kern/misc.c index 309267786..f45991d96 100644 --- a/kern/misc.c +++ b/kern/misc.c @@ -971,6 +971,10 @@ grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize, { /* invalid */ code = '?'; + /* Character c may be valid, don't eat it. */ + src--; + if (srcsize != (grub_size_t)-1) + srcsize++; count = 0; } else diff --git a/kern/term.c b/kern/term.c index b381d9336..6e3a2b454 100644 --- a/kern/term.c +++ b/kern/term.c @@ -57,16 +57,17 @@ grub_putchar (int c) { static grub_size_t size = 0; static grub_uint8_t buf[6]; + grub_uint8_t *rest; grub_uint32_t code; - grub_size_t ret; buf[size++] = c; - ret = grub_utf8_to_ucs4 (&code, 1, buf, size, 0); - if (ret != 0) + while (grub_utf8_to_ucs4 (&code, 1, buf, size, (const grub_uint8_t **) &rest) + != 0) { struct grub_term_output *term; - size = 0; + size -= rest - buf; + grub_memmove (buf, rest, size); FOR_ACTIVE_TERM_OUTPUTS(term) grub_putcode (code, term); if (code == '\n' && grub_newline_hook) From 007d0695e2f4a60f2a1919f002c6fda589f1750b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 00:36:18 +0100 Subject: [PATCH 110/237] 2010-02-07 Vladimir Serbinenko * include/grub/i18n.h (grub_gettext_dummy): Removed. * kern/misc.c (grub_gettext_dummy): Make static. --- ChangeLog | 5 +++++ include/grub/i18n.h | 1 - kern/misc.c | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e71065338..b6b74e8a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-07 Vladimir Serbinenko + + * include/grub/i18n.h (grub_gettext_dummy): Removed. + * kern/misc.c (grub_gettext_dummy): Make static. + 2010-02-06 Vladimir Serbinenko * kern/misc.c (grub_utf8_to_ucs4): Don't eat valid characters preceeded diff --git a/include/grub/i18n.h b/include/grub/i18n.h index 4d4a0b7bd..0cba54765 100644 --- a/include/grub/i18n.h +++ b/include/grub/i18n.h @@ -22,7 +22,6 @@ #include #include -const char *EXPORT_FUNC(grub_gettext_dummy) (const char *s); extern const char *(*EXPORT_VAR(grub_gettext)) (const char *s); /* NLS can be disabled through the configure --disable-nls option. */ diff --git a/kern/misc.c b/kern/misc.c index f45991d96..4772e22b0 100644 --- a/kern/misc.c +++ b/kern/misc.c @@ -35,7 +35,7 @@ grub_iswordseparator (int c) } /* grub_gettext_dummy is not translating anything. */ -const char * +static const char * grub_gettext_dummy (const char *s) { return s; From a4bced7752d6be5c367c46f1322c93b642f3e4f1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 00:40:17 +0100 Subject: [PATCH 111/237] 2010-02-07 Vladimir Serbinenko * include/grub/dl.h (grub_dl_register_symbol): Don't export. --- ChangeLog | 4 ++++ include/grub/dl.h | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b6b74e8a3..1f1b1c2e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-07 Vladimir Serbinenko + + * include/grub/dl.h (grub_dl_register_symbol): Don't export. + 2010-02-07 Vladimir Serbinenko * include/grub/i18n.h (grub_gettext_dummy): Removed. diff --git a/include/grub/dl.h b/include/grub/dl.h index 9340b6ce4..ac0ecd336 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -110,8 +110,8 @@ int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod); #endif void EXPORT_FUNC(grub_dl_iterate) (int (*hook) (grub_dl_t mod)); grub_dl_t EXPORT_FUNC(grub_dl_get) (const char *name); -grub_err_t EXPORT_FUNC(grub_dl_register_symbol) (const char *name, void *addr, - grub_dl_t mod); +grub_err_t grub_dl_register_symbol (const char *name, void *addr, + grub_dl_t mod); grub_err_t grub_arch_dl_check_header (void *ehdr); grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr); From 74b45184e47b791abac5324241aa887ce74310ab Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 00:46:09 +0100 Subject: [PATCH 112/237] 2010-02-07 Vladimir Serbinenko * include/grub/err.h (grub_err_printf): Don't export. --- ChangeLog | 4 ++++ include/grub/err.h | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f1b1c2e2..22c14424e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-07 Vladimir Serbinenko + + * include/grub/err.h (grub_err_printf): Don't export. + 2010-02-07 Vladimir Serbinenko * include/grub/dl.h (grub_dl_register_symbol): Don't export. diff --git a/include/grub/err.h b/include/grub/err.h index 7a5ce1ae0..e44705389 100644 --- a/include/grub/err.h +++ b/include/grub/err.h @@ -66,7 +66,7 @@ void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn)); void EXPORT_FUNC(grub_error_push) (void); int EXPORT_FUNC(grub_error_pop) (void); void EXPORT_FUNC(grub_print_error) (void); -int EXPORT_FUNC(grub_err_printf) (const char *fmt, ...) -__attribute__ ((format (printf, 1, 2))); +int grub_err_printf (const char *fmt, ...) + __attribute__ ((format (printf, 1, 2))); #endif /* ! GRUB_ERR_HEADER */ From 8f891adc6f193b70915635418c2b73b5450b1546 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 00:52:31 +0100 Subject: [PATCH 113/237] 2010-02-07 Vladimir Serbinenko * include/grub/cache.h (grub_arch_sync_caches) [i386 || x86_64]: Inline. * kern/i386/coreboot/init.c (grub_arch_sync_caches): Remove. * kern/i386/efi/init.c (grub_arch_sync_caches): Likewise. * kern/i386/ieee1275/init.c (grub_arch_sync_caches): Likewise. * kern/i386/pc/init.c (grub_arch_sync_caches): Likewise. * util/misc.c (grub_arch_sync_caches) [i386 || x86_64]: Likewise. --- ChangeLog | 9 +++++++++ include/grub/cache.h | 8 ++++++++ kern/i386/coreboot/init.c | 6 ------ kern/i386/efi/init.c | 6 ------ kern/i386/ieee1275/init.c | 6 ------ kern/i386/pc/init.c | 6 ------ util/misc.c | 2 ++ 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22c14424e..c91b4a042 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-02-07 Vladimir Serbinenko + + * include/grub/cache.h (grub_arch_sync_caches) [i386 || x86_64]: Inline. + * kern/i386/coreboot/init.c (grub_arch_sync_caches): Remove. + * kern/i386/efi/init.c (grub_arch_sync_caches): Likewise. + * kern/i386/ieee1275/init.c (grub_arch_sync_caches): Likewise. + * kern/i386/pc/init.c (grub_arch_sync_caches): Likewise. + * util/misc.c (grub_arch_sync_caches) [i386 || x86_64]: Likewise. + 2010-02-07 Vladimir Serbinenko * include/grub/err.h (grub_err_printf): Don't export. diff --git a/include/grub/cache.h b/include/grub/cache.h index 745af43c3..27e44f0a2 100644 --- a/include/grub/cache.h +++ b/include/grub/cache.h @@ -23,6 +23,14 @@ #include #include +#if defined (__i386__) || defined (__x86_64__) +static inline void +grub_arch_sync_caches (void *address __attribute__ ((unused)), + grub_size_t len __attribute__ ((unused))) +{ +} +#else void EXPORT_FUNC(grub_arch_sync_caches) (void *address, grub_size_t len); +#endif #endif /* ! GRUB_CACHE_HEADER */ diff --git a/kern/i386/coreboot/init.c b/kern/i386/coreboot/init.c index 550a2a60a..5f80f28c1 100644 --- a/kern/i386/coreboot/init.c +++ b/kern/i386/coreboot/init.c @@ -67,12 +67,6 @@ grub_exit (void) grub_cpu_idle (); } -void -grub_arch_sync_caches (void *address __attribute__ ((unused)), - grub_size_t len __attribute__ ((unused))) -{ -} - void grub_machine_init (void) { diff --git a/kern/i386/efi/init.c b/kern/i386/efi/init.c index e1950d758..f73f828c6 100644 --- a/kern/i386/efi/init.c +++ b/kern/i386/efi/init.c @@ -45,9 +45,3 @@ grub_machine_set_prefix (void) { grub_efi_set_prefix (); } - -void -grub_arch_sync_caches (void *address __attribute__ ((unused)), - grub_size_t len __attribute__ ((unused))) -{ -} diff --git a/kern/i386/ieee1275/init.c b/kern/i386/ieee1275/init.c index 7658ee1a7..9fb98739b 100644 --- a/kern/i386/ieee1275/init.c +++ b/kern/i386/ieee1275/init.c @@ -26,9 +26,3 @@ void grub_stop_floppy (void) { } - -void -grub_arch_sync_caches (void *address __attribute__ ((unused)), - grub_size_t len __attribute__ ((unused))) -{ -} diff --git a/kern/i386/pc/init.c b/kern/i386/pc/init.c index 1707049fe..fa646df19 100644 --- a/kern/i386/pc/init.c +++ b/kern/i386/pc/init.c @@ -47,12 +47,6 @@ static int num_regions; grub_addr_t grub_os_area_addr; grub_size_t grub_os_area_size; -void -grub_arch_sync_caches (void *address __attribute__ ((unused)), - grub_size_t len __attribute__ ((unused))) -{ -} - static char * make_install_device (void) { diff --git a/util/misc.c b/util/misc.c index 371e7cc14..4e8eec323 100644 --- a/util/misc.c +++ b/util/misc.c @@ -371,11 +371,13 @@ grub_millisleep (grub_uint32_t ms) #endif +#if !(defined (__i386__) || defined (__x86_64__)) void grub_arch_sync_caches (void *address __attribute__ ((unused)), grub_size_t len __attribute__ ((unused))) { } +#endif #ifndef HAVE_VASPRINTF From 6b2ad14b7aeb2c168859889c2aa54da5a24f8cbb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 01:33:37 +0100 Subject: [PATCH 114/237] 2010-02-07 Vladimir Serbinenko * fs/reiserfs.c (grub_reiserfs_read): Use #if 0 instead of commenting code out. --- ChangeLog | 5 +++++ fs/reiserfs.c | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c91b4a042..771ba8e04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-07 Vladimir Serbinenko + + * fs/reiserfs.c (grub_reiserfs_read): Use #if 0 instead of commenting + code out. + 2010-02-07 Vladimir Serbinenko * include/grub/cache.h (grub_arch_sync_caches) [i386 || x86_64]: Inline. diff --git a/fs/reiserfs.c b/fs/reiserfs.c index 444bf3120..c3db52f60 100644 --- a/fs/reiserfs.c +++ b/fs/reiserfs.c @@ -1189,7 +1189,8 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len) (unsigned long long) (current_position - initial_position), (unsigned long) len); return current_position - initial_position; -/* + +#if 0 switch (found.type) { case GRUB_REISERFS_DIRECT: @@ -1232,7 +1233,8 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len) goto fail; } - return read_length;*/ + return read_length; +#endif fail: grub_free (indirect_block_ptr); From 74e31b5ca20e3cf62d2233e4efcc82dd5ab3df05 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 01:41:23 +0100 Subject: [PATCH 115/237] 2010-02-07 Vladimir Serbinenko * loader/i386/linux.c (grub_linux_setup_video): Handle error appropriately. --- ChangeLog | 5 +++++ loader/i386/linux.c | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 771ba8e04..46c96bdb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-07 Vladimir Serbinenko + + * loader/i386/linux.c (grub_linux_setup_video): Handle error + appropriately. + 2010-02-07 Vladimir Serbinenko * fs/reiserfs.c (grub_reiserfs_read): Use #if 0 instead of commenting diff --git a/loader/i386/linux.c b/loader/i386/linux.c index 831d8b25a..630aec6f4 100644 --- a/loader/i386/linux.c +++ b/loader/i386/linux.c @@ -394,12 +394,15 @@ grub_linux_setup_video (struct linux_kernel_params *params) { struct grub_video_mode_info mode_info; void *framebuffer; - int ret; + grub_err_t err; - ret = grub_video_get_info_and_fini (&mode_info, &framebuffer); + err = grub_video_get_info_and_fini (&mode_info, &framebuffer); - if (ret) - return 1; + if (err) + { + grub_errno = GRUB_ERR_NONE; + return 1; + } params->lfb_width = mode_info.width; params->lfb_height = mode_info.height; From 909301af11e312a64fba7929bbb53f48b9460615 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 02:07:35 +0100 Subject: [PATCH 116/237] First try at generating grub-emu from modules --- Makefile.in | 2 +- commands/sleep.c | 1 - conf/any-emu.rmk | 113 ++++++++++++++++++++----------------------- configure.ac | 1 + disk/loopback.c | 4 +- font/font_cmd.c | 4 +- genemuinit.sh | 68 ++++++++++++++++++++++++++ genemuinitheader.sh | 48 ++++++++++++++++++ include/grub/i18n.h | 8 +-- partmap/acorn.c | 4 +- partmap/amiga.c | 4 +- partmap/apple.c | 4 +- partmap/gpt.c | 4 +- partmap/msdos.c | 4 +- partmap/sun.c | 4 +- parttool/msdospart.c | 4 +- term/gfxterm.c | 12 ++--- util/grub-emu.c | 6 +-- video/bitmap.c | 4 +- video/readers/jpeg.c | 4 +- video/readers/png.c | 4 +- video/readers/tga.c | 4 +- video/video.c | 4 +- 23 files changed, 209 insertions(+), 106 deletions(-) create mode 100644 genemuinit.sh create mode 100644 genemuinitheader.sh diff --git a/Makefile.in b/Makefile.in index 46b380cd5..faf13a134 100644 --- a/Makefile.in +++ b/Makefile.in @@ -84,7 +84,7 @@ TARGET_ASFLAGS = @TARGET_ASFLAGS@ TARGET_MODULE_FORMAT = @TARGET_MODULE_FORMAT@ TARGET_APPLE_CC = @TARGET_APPLE_CC@ OBJCONV = @OBJCONV@ -TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -nostdinc -isystem $(shell $(TARGET_CC) -print-file-name=include) -I$(srcdir)/include -I$(builddir) -I$(builddir)/include \ +TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I$(srcdir)/include -I$(builddir) -I$(builddir)/include \ -Wall -W TARGET_LDFLAGS = @TARGET_LDFLAGS@ TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@ diff --git a/commands/sleep.c b/commands/sleep.c index 9207b60a7..cb208c96f 100644 --- a/commands/sleep.c +++ b/commands/sleep.c @@ -22,7 +22,6 @@ #include #include #include -#include #include static const struct grub_arg_option options[] = diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index fb97de0a0..310076345 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -1,94 +1,85 @@ # -*- makefile -*- +COMMON_LDFLAGS += -nostdlib +COMMON_CFLAGS += -DGRUB_UTIL=1 + # Used by various components. These rules need to precede them. script/lexer.c_DEPENDENCIES = grub_script.tab.h -sbin_UTILITIES += grub-emu +#sbin_UTILITIES += grub-emu util/grub-emu.c_DEPENDENCIES = grub_emu_init.h -grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ - commands/configfile.c commands/echo.c commands/help.c \ - commands/handler.c commands/ls.c commands/test.c \ - commands/search.c commands/blocklist.c commands/hexdump.c \ - lib/hexdump.c commands/halt.c commands/reboot.c \ - lib/envblk.c commands/loadenv.c \ - commands/gptsync.c commands/probe.c commands/xnu_uuid.c \ - commands/password.c commands/keystatus.c \ - disk/host.c disk/loopback.c disk/scsi.c \ - fs/fshelp.c \ - \ - io/gzio.c \ - kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \ +pkglib_MODULES += main.mod +main_mod_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \ kern/err.c kern/list.c kern/handler.c \ - kern/command.c kern/corecmd.c commands/extcmd.c kern/file.c \ + kern/command.c kern/corecmd.c kern/file.c \ kern/fs.c commands/boot.c kern/main.c kern/misc.c kern/parser.c \ kern/partition.c kern/reader.c kern/term.c \ kern/rescue_reader.c kern/rescue_parser.c \ - lib/arg.c normal/cmdline.c normal/datetime.c normal/misc.c \ - normal/handler.c normal/auth.c normal/autofs.c \ - normal/completion.c normal/main.c normal/color.c \ - normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ - normal/menu_text.c \ - script/main.c script/execute.c script/function.c \ - script/lexer.c script/script.c grub_script.tab.c \ - partmap/amiga.c partmap/apple.c partmap/msdos.c partmap/sun.c \ - partmap/acorn.c partmap/gpt.c \ \ - fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c \ - fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c \ - fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \ - fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/afs_be.c \ - fs/befs.c fs/befs_be.c fs/tar.c \ - \ - util/console.c util/hostfs.c util/grub-emu.c util/misc.c \ + util/console.c util/grub-emu.c util/misc.c \ util/hostdisk.c util/getroot.c \ \ - disk/raid.c disk/raid5_recover.c disk/raid6_recover.c \ - disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c \ - commands/parttool.c parttool/msdospart.c \ grub_emu_init.c gnulib/progname.c +main_mod_CFLAGS = $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 +main_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For hostfs.mod. +pkglib_MODULES += hostfs.mod +hostfs_mod_SOURCES = util/hostfs.c +hostfs_mod_CFLAGS = $(COMMON_CFLAGS) +hostfs_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For host.mod. +pkglib_MODULES += host.mod +host_mod_SOURCES = disk/host.c +host_mod_CFLAGS = $(COMMON_CFLAGS) +host_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For reboot.mod. +pkglib_MODULES += reboot.mod +reboot_mod_SOURCES = commands/reboot.c +reboot_mod_CFLAGS = $(COMMON_CFLAGS) +reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For halt.mod. +pkglib_MODULES += halt.mod +halt_mod_SOURCES = commands/halt.c +halt_mod_CFLAGS = $(COMMON_CFLAGS) +halt_mod_LDFLAGS = $(COMMON_LDFLAGS) ifeq ($(target_cpu), i386) -grub_emu_SOURCES += commands/i386/cpuid.c +pkglib_MODULES += cpuid.mod +cpuid_mod_SOURCES = commands/i386/cpuid.c +cpuid_mod_CFLAGS = $(COMMON_CFLAGS) +cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS) endif grub_emu_LDFLAGS = $(LIBCURSES) ifeq ($(enable_grub_emu_usb), yes) -grub_emu_SOURCES += disk/usbms.c util/usb.c bus/usb/usb.c \ +pkglib_MODULES += usb.mod +usb_mod_SOURCES = disk/usbms.c util/usb.c bus/usb/usb.c \ commands/usbtest.c -grub_emu_LDFLAGS += $(LIBCURSES) $(LIBUSB) +cpuid_mod_CFLAGS = $(COMMON_CFLAGS) +usb_mod_LDFLAGS = $(COMMON_LDFLAGS) $(LIBUSB) endif ifeq ($(enable_grub_emu_pci), yes) -grub_emu_SOURCES += util/pci.c commands/lspci.c -grub_emu_LDFLAGS += $(LIBPCIACCESS) +pkglib_MODULES += pci.mod +pci_mod_SOURCES = util/pci.c commands/lspci.c +pci_mod_LDFLAGS = $(LIBPCIACCESS) endif -grub_emu_init.lst: geninit.sh $(filter-out grub_emu_init.c,$(grub_emu_SOURCES)) - rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@ -DISTCLEANFILES += grub_emu_init.lst -grub_emu_init.h: grub_emu_init.lst $(filter-out grub_emu_init.c,$(grub_emu_SOURCES)) geninitheader.sh - rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@ +grub_emu_init.h: genemuinitheader.sh + rm -f $@; echo $(pkglib_MODULES) |sh $(srcdir)/genemuinitheader.sh > $@ DISTCLEANFILES += grub_emu_init.h -grub_emu_init.c: grub_emu_init.lst $(filter-out grub_emu_init.c,$(grub_emu_SOURCES)) geninit.sh grub_emu_init.h - rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@ +grub_emu_init.c: genemuinit.sh + rm -f $@; echo $(pkglib_MODULES) |sed 's,elf.mod,,;s,extcmd.mod,,;s,main.mod,,;s,gzio.mod,,;s,fshelp.mod,,;s,bufio.mod,,;s,setjmp.mod,,;'|sh $(srcdir)/genemuinit.sh > $@ DISTCLEANFILES += grub_emu_init.c +include $(srcdir)/conf/common.mk - - -# FIXME: this could be shared with common.rmk - -# For grub-mkfont. -ifeq ($(enable_grub_mkfont), yes) -bin_UTILITIES += grub-mkfont -grub_mkfont_SOURCES = gnulib/progname.c util/grub-mkfont.c util/misc.c -grub_mkfont_CFLAGS = $(freetype_cflags) -grub_mkfont_LDFLAGS = $(freetype_libs) -endif - -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 +grub-emu: $(pkglib_MODULES) + $(CC) -o $@ $(pkglib_MODULES) $(grub_emu_LDFLAGS) $(LDFLAGS) $(grub_emu_SOURCES) diff --git a/configure.ac b/configure.ac index 6560d3e31..098e4524e 100644 --- a/configure.ac +++ b/configure.ac @@ -74,6 +74,7 @@ fi if test -z "$target_alias"; then case "$target_cpu"-"$platform" in x86_64-efi) ;; + x86_64-emu) ;; x86_64-*) target_cpu=i386 ;; powerpc64-ieee1275) target_cpu=powerpc ;; esac diff --git a/disk/loopback.c b/disk/loopback.c index 29805182e..a8bc25d8c 100644 --- a/disk/loopback.c +++ b/disk/loopback.c @@ -241,7 +241,7 @@ static struct grub_disk_dev grub_loopback_dev = static grub_extcmd_t cmd; -GRUB_MOD_INIT(loop) +GRUB_MOD_INIT(loopback) { cmd = grub_register_extcmd ("loopback", grub_cmd_loopback, GRUB_COMMAND_FLAG_BOTH, @@ -250,7 +250,7 @@ GRUB_MOD_INIT(loop) grub_disk_dev_register (&grub_loopback_dev); } -GRUB_MOD_FINI(loop) +GRUB_MOD_FINI(loopback) { grub_unregister_extcmd (cmd); grub_disk_dev_unregister (&grub_loopback_dev); diff --git a/font/font_cmd.c b/font/font_cmd.c index 0402b8d77..b3eeb4dca 100644 --- a/font/font_cmd.c +++ b/font/font_cmd.c @@ -56,7 +56,7 @@ lsfonts_command (grub_command_t cmd __attribute__ ((unused)), static grub_command_t cmd_loadfont, cmd_lsfonts; -GRUB_MOD_INIT(font_manager) +GRUB_MOD_INIT(font) { grub_font_loader_init (); @@ -69,7 +69,7 @@ GRUB_MOD_INIT(font_manager) 0, "List the loaded fonts."); } -GRUB_MOD_FINI(font_manager) +GRUB_MOD_FINI(font) { /* TODO: Determine way to free allocated resources. Warning: possible pointer references could be in use. */ diff --git a/genemuinit.sh b/genemuinit.sh new file mode 100644 index 000000000..e40a683af --- /dev/null +++ b/genemuinit.sh @@ -0,0 +1,68 @@ +#! /bin/sh +# +# Copyright (C) 2002,2005,2007 Free Software Foundation, Inc. +# +# This gensymlist.sh is free software; the author +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +lst="$1" +shift + +cat <. + */ + +#include "grub_emu_init.h" + +EOF + +cat <. + */ + +EOF + +cat < # include -# define _(str) gettext(str) -#else +//# define _(str) gettext(str) +//#else # define _(str) grub_gettext(str) const char *EXPORT_FUNC(grub_gettext_dummy) (const char *s); extern const char *(*EXPORT_VAR(grub_gettext)) (const char *s); -#endif + //#endif #define N_(str) str diff --git a/partmap/acorn.c b/partmap/acorn.c index e005975c0..ed8738755 100644 --- a/partmap/acorn.c +++ b/partmap/acorn.c @@ -195,12 +195,12 @@ static struct grub_partition_map grub_acorn_partition_map = .get_name = acorn_partition_map_get_name }; -GRUB_MOD_INIT(acorn_partition_map) +GRUB_MOD_INIT(part_acorn) { grub_partition_map_register (&grub_acorn_partition_map); } -GRUB_MOD_FINI(acorn_partition_map) +GRUB_MOD_FINI(part_acorn) { grub_partition_map_unregister (&grub_acorn_partition_map); } diff --git a/partmap/amiga.c b/partmap/amiga.c index dce9f4f1f..f769d4048 100644 --- a/partmap/amiga.c +++ b/partmap/amiga.c @@ -204,12 +204,12 @@ static struct grub_partition_map grub_amiga_partition_map = .get_name = amiga_partition_map_get_name }; -GRUB_MOD_INIT(amiga_partition_map) +GRUB_MOD_INIT(part_amiga) { grub_partition_map_register (&grub_amiga_partition_map); } -GRUB_MOD_FINI(amiga_partition_map) +GRUB_MOD_FINI(part_amiga) { grub_partition_map_unregister (&grub_amiga_partition_map); } diff --git a/partmap/apple.c b/partmap/apple.c index 4dea55a32..6208ebcea 100644 --- a/partmap/apple.c +++ b/partmap/apple.c @@ -247,12 +247,12 @@ static struct grub_partition_map grub_apple_partition_map = .get_name = apple_partition_map_get_name }; -GRUB_MOD_INIT(apple_partition_map) +GRUB_MOD_INIT(part_apple) { grub_partition_map_register (&grub_apple_partition_map); } -GRUB_MOD_FINI(apple_partition_map) +GRUB_MOD_FINI(part_apple) { grub_partition_map_unregister (&grub_apple_partition_map); } diff --git a/partmap/gpt.c b/partmap/gpt.c index 4a4957437..46f3f0a37 100644 --- a/partmap/gpt.c +++ b/partmap/gpt.c @@ -182,12 +182,12 @@ static struct grub_partition_map grub_gpt_partition_map = .get_name = gpt_partition_map_get_name }; -GRUB_MOD_INIT(gpt_partition_map) +GRUB_MOD_INIT(part_gpt) { grub_partition_map_register (&grub_gpt_partition_map); } -GRUB_MOD_FINI(gpt_partition_map) +GRUB_MOD_FINI(part_gpt) { grub_partition_map_unregister (&grub_gpt_partition_map); } diff --git a/partmap/msdos.c b/partmap/msdos.c index 6ba7fb927..bae7ced9b 100644 --- a/partmap/msdos.c +++ b/partmap/msdos.c @@ -327,12 +327,12 @@ static struct grub_partition_map grub_msdos_partition_map = .get_name = pc_partition_map_get_name }; -GRUB_MOD_INIT(pc_partition_map) +GRUB_MOD_INIT(part_msdos) { grub_partition_map_register (&grub_msdos_partition_map); } -GRUB_MOD_FINI(pc_partition_map) +GRUB_MOD_FINI(part_msdos) { grub_partition_map_unregister (&grub_msdos_partition_map); } diff --git a/partmap/sun.c b/partmap/sun.c index e816ec17a..39cd29969 100644 --- a/partmap/sun.c +++ b/partmap/sun.c @@ -202,12 +202,12 @@ static struct grub_partition_map grub_sun_partition_map = .get_name = sun_partition_map_get_name }; -GRUB_MOD_INIT(sun_partition_map) +GRUB_MOD_INIT(part_sun) { grub_partition_map_register (&grub_sun_partition_map); } -GRUB_MOD_FINI(sun_partition_map) +GRUB_MOD_FINI(part_sun) { grub_partition_map_unregister (&grub_sun_partition_map); } diff --git a/parttool/msdospart.c b/parttool/msdospart.c index dbb25bc52..6ce48a977 100644 --- a/parttool/msdospart.c +++ b/parttool/msdospart.c @@ -138,7 +138,7 @@ static grub_err_t grub_pcpart_type (const grub_device_t dev, return GRUB_ERR_NONE; } -GRUB_MOD_INIT (pcpart) +GRUB_MOD_INIT (msdospart) { activate_table_handle = grub_parttool_register ("part_msdos", grub_pcpart_boot, @@ -148,7 +148,7 @@ GRUB_MOD_INIT (pcpart) grub_pcpart_typeargs); } -GRUB_MOD_FINI(pcpart) +GRUB_MOD_FINI(msdospart) { grub_parttool_unregister (activate_table_handle); grub_parttool_unregister (type_table_handle); diff --git a/term/gfxterm.c b/term/gfxterm.c index f161499e6..5c94a6b9a 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -251,7 +251,7 @@ static int NESTED_FUNC_ATTR video_hook (grub_video_adapter_t p __attribute__ ((u } static grub_err_t -grub_gfxterm_init (void) +grub_gfxterm_term_init (void) { char *font_name; char *modevar; @@ -312,7 +312,7 @@ grub_gfxterm_init (void) } static grub_err_t -grub_gfxterm_fini (void) +grub_gfxterm_term_fini (void) { if (bitmap) { @@ -932,8 +932,8 @@ grub_gfxterm_background_image_cmd (grub_command_t cmd __attribute__ ((unused)), static struct grub_term_output grub_video_term = { .name = "gfxterm", - .init = grub_gfxterm_init, - .fini = grub_gfxterm_fini, + .init = grub_gfxterm_term_init, + .fini = grub_gfxterm_term_fini, .putchar = grub_gfxterm_putchar, .getcharwidth = grub_gfxterm_getcharwidth, .getwh = grub_virtual_screen_getwh, @@ -951,7 +951,7 @@ static struct grub_term_output grub_video_term = static grub_command_t cmd; -GRUB_MOD_INIT(term_gfxterm) +GRUB_MOD_INIT(gfxterm) { grub_term_register_output ("gfxterm", &grub_video_term); cmd = grub_register_command ("background_image", @@ -959,7 +959,7 @@ GRUB_MOD_INIT(term_gfxterm) 0, "Load background image for active terminal"); } -GRUB_MOD_FINI(term_gfxterm) +GRUB_MOD_FINI(gfxterm) { grub_unregister_command (cmd); grub_term_unregister_output (&grub_video_term); diff --git a/util/grub-emu.c b/util/grub-emu.c index e65c8585e..b3117ab53 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -51,7 +51,7 @@ static char *prefix = NULL; grub_addr_t grub_arch_modules_addr (void) { - return NULL; + return 0; } grub_err_t @@ -106,10 +106,6 @@ grub_machine_fini (void) grub_console_fini (); } -void -read_command_list (void) -{ -} static struct option options[] = diff --git a/video/bitmap.c b/video/bitmap.c index 7b135a5dc..02ded85c6 100644 --- a/video/bitmap.c +++ b/video/bitmap.c @@ -243,11 +243,11 @@ void *grub_video_bitmap_get_data (struct grub_video_bitmap *bitmap) } /* Initialize bitmap module. */ -GRUB_MOD_INIT(video_bitmap) +GRUB_MOD_INIT(bitmap) { } /* Finalize bitmap module. */ -GRUB_MOD_FINI(video_bitmap) +GRUB_MOD_FINI(bitmap) { } diff --git a/video/readers/jpeg.c b/video/readers/jpeg.c index 460a52872..8b7398c39 100644 --- a/video/readers/jpeg.c +++ b/video/readers/jpeg.c @@ -725,7 +725,7 @@ static struct grub_video_bitmap_reader jpeg_reader = { .next = 0 }; -GRUB_MOD_INIT (video_reader_jpeg) +GRUB_MOD_INIT (jpeg) { grub_video_bitmap_reader_register (&jpg_reader); grub_video_bitmap_reader_register (&jpeg_reader); @@ -736,7 +736,7 @@ GRUB_MOD_INIT (video_reader_jpeg) #endif } -GRUB_MOD_FINI (video_reader_jpeg) +GRUB_MOD_FINI (jpeg) { #if defined(JPEG_DEBUG) grub_unregister_command ("jpegtest"); diff --git a/video/readers/png.c b/video/readers/png.c index c2008aeb2..7acce2145 100644 --- a/video/readers/png.c +++ b/video/readers/png.c @@ -890,7 +890,7 @@ static struct grub_video_bitmap_reader png_reader = { .next = 0 }; -GRUB_MOD_INIT (video_reader_png) +GRUB_MOD_INIT (png) { grub_video_bitmap_reader_register (&png_reader); #if defined(PNG_DEBUG) @@ -900,7 +900,7 @@ GRUB_MOD_INIT (video_reader_png) #endif } -GRUB_MOD_FINI (video_reader_png) +GRUB_MOD_FINI (png) { #if defined(PNG_DEBUG) grub_unregister_command ("pngtest"); diff --git a/video/readers/tga.c b/video/readers/tga.c index d0ca2770f..5f0a7f890 100644 --- a/video/readers/tga.c +++ b/video/readers/tga.c @@ -476,7 +476,7 @@ static struct grub_video_bitmap_reader tga_reader = { .next = 0 }; -GRUB_MOD_INIT(video_reader_tga) +GRUB_MOD_INIT(tga) { grub_video_bitmap_reader_register (&tga_reader); #if defined(TGA_DEBUG) @@ -485,7 +485,7 @@ GRUB_MOD_INIT(video_reader_tga) #endif } -GRUB_MOD_FINI(video_reader_tga) +GRUB_MOD_FINI(tga) { #if defined(TGA_DEBUG) grub_unregister_command ("tgatest"); diff --git a/video/video.c b/video/video.c index c1d66bdd0..5dcca7c7e 100644 --- a/video/video.c +++ b/video/video.c @@ -713,11 +713,11 @@ grub_video_set_mode (const char *modestring, } /* Initialize Video API module. */ -GRUB_MOD_INIT(video_video) +GRUB_MOD_INIT(video) { } /* Finalize Video API module. */ -GRUB_MOD_FINI(video_video) +GRUB_MOD_FINI(video) { } From 98e6959dead1c97d77e3b6dc8dc25cf1bd6cd173 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 02:37:48 +0100 Subject: [PATCH 117/237] 2010-02-07 Vladimir Serbinenko Fix warnings in grub-emu when compiling with maximum warning options. * util/grub-emu.c (ENABLE_RELOCATABLE): New definition. (grub_arch_modules_addr): Return 0 and not NULL. * util/misc.c (ENABLE_RELOCATABLE): New definition. (xstrdup): USe newstr instead of dup. --- ChangeLog | 9 +++++++++ util/grub-emu.c | 3 ++- util/misc.c | 9 +++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 46c96bdb2..33b0ea3bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-02-07 Vladimir Serbinenko + + Fix warnings in grub-emu when compiling with maximum warning options. + + * util/grub-emu.c (ENABLE_RELOCATABLE): New definition. + (grub_arch_modules_addr): Return 0 and not NULL. + * util/misc.c (ENABLE_RELOCATABLE): New definition. + (xstrdup): USe newstr instead of dup. + 2010-02-07 Vladimir Serbinenko * loader/i386/linux.c (grub_linux_setup_video): Handle error diff --git a/util/grub-emu.c b/util/grub-emu.c index 21fc6fa09..554556ae8 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -40,6 +40,7 @@ #include +#define ENABLE_RELOCATABLE 0 #include "progname.h" /* Used for going back to the main function. */ @@ -51,7 +52,7 @@ static char *prefix = NULL; grub_addr_t grub_arch_modules_addr (void) { - return NULL; + return 0; } grub_err_t diff --git a/util/misc.c b/util/misc.c index 4e8eec323..8c79e8d9b 100644 --- a/util/misc.c +++ b/util/misc.c @@ -43,6 +43,7 @@ #include #include +#define ENABLE_RELOCATABLE 0 #include "progname.h" /* Include malloc.h, only if memalign is available. It is known that @@ -142,13 +143,13 @@ char * xstrdup (const char *str) { size_t len; - char *dup; + char *newstr; len = strlen (str); - dup = (char *) xmalloc (len + 1); - memcpy (dup, str, len + 1); + newstr = (char *) xmalloc (len + 1); + memcpy (newstr, str, len + 1); - return dup; + return newstr; } char * From f88d801b1733c5decb09cfcce3ead23455894fc7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 02:44:47 +0100 Subject: [PATCH 118/237] 2010-02-07 Vladimir Serbinenko Fix warnings in grub-emu when compiling with maximum warning options. * util/hostdisk.c (grub_util_biosdisk_get_grub_dev): Rename one instance of disk to dsk to avoid shadowing. --- ChangeLog | 2 ++ util/hostdisk.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 33b0ea3bd..4de8073ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ (grub_arch_modules_addr): Return 0 and not NULL. * util/misc.c (ENABLE_RELOCATABLE): New definition. (xstrdup): USe newstr instead of dup. + * util/hostdisk.c (grub_util_biosdisk_get_grub_dev): Rename one instance + of disk to dsk to avoid shadowing. 2010-02-07 Vladimir Serbinenko diff --git a/util/hostdisk.c b/util/hostdisk.c index 5c56b7579..9a3f30ce0 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -981,10 +981,10 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev) struct hd_geometry hdg; int dos_part = -1; int bsd_part = -1; - auto int find_partition (grub_disk_t disk, + auto int find_partition (grub_disk_t dsk, const grub_partition_t partition); - int find_partition (grub_disk_t disk __attribute__ ((unused)), + int find_partition (grub_disk_t dsk __attribute__ ((unused)), const grub_partition_t partition) { struct grub_msdos_partition *pcdata = NULL; From 74e4934e1c8147e622a843a7ca7a3b7c98a0783e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 02:47:18 +0100 Subject: [PATCH 119/237] 2010-02-07 Vladimir Serbinenko * util/hostdisk.c (grub_util_biosdisk_get_grub_dev): Rename one instance of disk to dsk to avoid shadowing. (find_free_slot): Fix prototype. * util/getroot.c (grub_util_is_dmraid): Make static. * include/grub/time.h (grub_get_rtc) [GRUB_MACHINE_EMU || GRUB_UTIL]: Add missing prototype. * util/sdl.c (grub_video_sdl_set_viewport): Remove. --- ChangeLog | 7 ++++++- include/grub/time.h | 2 ++ util/getroot.c | 3 ++- util/hostdisk.c | 2 +- util/sdl.c | 26 -------------------------- 5 files changed, 11 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4de8073ee..ec3318c5b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,9 +5,14 @@ * util/grub-emu.c (ENABLE_RELOCATABLE): New definition. (grub_arch_modules_addr): Return 0 and not NULL. * util/misc.c (ENABLE_RELOCATABLE): New definition. - (xstrdup): USe newstr instead of dup. + (xstrdup): Use newstr instead of dup. * util/hostdisk.c (grub_util_biosdisk_get_grub_dev): Rename one instance of disk to dsk to avoid shadowing. + (find_free_slot): Fix prototype. + * util/getroot.c (grub_util_is_dmraid): Make static. + * include/grub/time.h (grub_get_rtc) [GRUB_MACHINE_EMU || GRUB_UTIL]: + Add missing prototype. + * util/sdl.c (grub_video_sdl_set_viewport): Remove. 2010-02-07 Vladimir Serbinenko diff --git a/include/grub/time.h b/include/grub/time.h index 5aafdc9ed..ae2617edb 100644 --- a/include/grub/time.h +++ b/include/grub/time.h @@ -25,6 +25,8 @@ #if defined (GRUB_MACHINE_EMU) || defined (GRUB_UTIL) #define GRUB_TICKS_PER_SECOND 100000 +/* Return the real time in ticks. */ +grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void); #else #include #endif diff --git a/util/getroot.c b/util/getroot.c index 6357c8a26..82393635c 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -460,7 +460,8 @@ grub_guess_root_device (const char *dir) return os_dev; } -int + +static int grub_util_is_dmraid (const char *os_dev) { if (! strncmp (os_dev, "/dev/mapper/nvidia_", 19)) diff --git a/util/hostdisk.c b/util/hostdisk.c index 9a3f30ce0..98d3d53ae 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -137,7 +137,7 @@ find_grub_drive (const char *name) } static int -find_free_slot () +find_free_slot (void) { unsigned int i; diff --git a/util/sdl.c b/util/sdl.c index a5a310518..d261db6b0 100644 --- a/util/sdl.c +++ b/util/sdl.c @@ -179,32 +179,6 @@ grub_video_sdl_set_palette (unsigned int start, unsigned int count, return grub_video_fb_set_palette (start, count, palette_data); } -grub_err_t -grub_video_sdl_set_viewport (unsigned int x, unsigned int y, - unsigned int width, unsigned int height) -{ - /* Make sure viewport is withing screen dimensions. If viewport was set - to be out of the region, mark its size as zero. */ - if (x > (unsigned) window->w) - { - x = 0; - width = 0; - } - - if (y > (unsigned) window->h) - { - y = 0; - height = 0; - } - - if (x + width > (unsigned) window->w) - width = window->w - x; - - if (y + height > (unsigned) window->h) - height = window->h - y; - return grub_video_fb_set_viewport (x, y, width, height); -} - static grub_err_t grub_video_sdl_swap_buffers (void) { From dcb3f497be11f052e794385fed50b1d8367c5fb0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 03:29:59 +0100 Subject: [PATCH 120/237] Rename main.mod to kernel.img --- conf/any-emu.rmk | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 2fc8daf45..ebcc9087c 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -8,8 +8,9 @@ script/lexer.c_DEPENDENCIES = grub_script.tab.h #sbin_UTILITIES += grub-emu util/grub-emu.c_DEPENDENCIES = grub_emu_init.h -pkglib_MODULES += main.mod -main_mod_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \ +kernel_img_RELOCATABLE = yes +pkglib_PROGRAMS = kernel.img +kernel_img_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \ kern/err.c kern/list.c kern/handler.c \ kern/command.c kern/corecmd.c kern/file.c \ kern/fs.c commands/boot.c kern/main.c kern/misc.c kern/parser.c \ @@ -20,8 +21,8 @@ main_mod_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \ util/hostdisk.c util/getroot.c \ \ grub_emu_init.c gnulib/progname.c -main_mod_CFLAGS = $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 -main_mod_LDFLAGS = $(COMMON_LDFLAGS) +kernel_img_CFLAGS = $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) # For hostfs.mod. pkglib_MODULES += hostfs.mod @@ -85,11 +86,11 @@ grub_emu_init.h: genemuinitheader.sh DISTCLEANFILES += grub_emu_init.h grub_emu_init.c: genemuinit.sh - rm -f $@; echo $(pkglib_MODULES) |sed 's,elf.mod,,;s,extcmd.mod,,;s,main.mod,,;s,gzio.mod,,;s,fshelp.mod,,;s,bufio.mod,,;s,setjmp.mod,,;s,crypto.mod,,;s,pbkdf2.mod,,;s,trig.mod,,;s,bitmap_scale.mod,,;s,charset.mod,,;'|sh $(srcdir)/genemuinit.sh > $@ + rm -f $@; echo $(pkglib_MODULES) |sed 's,elf.mod,,;s,extcmd.mod,,;s,gzio.mod,,;s,fshelp.mod,,;s,bufio.mod,,;s,setjmp.mod,,;s,crypto.mod,,;s,pbkdf2.mod,,;s,trig.mod,,;s,bitmap_scale.mod,,;s,charset.mod,,;'|sh $(srcdir)/genemuinit.sh > $@ DISTCLEANFILES += grub_emu_init.c include $(srcdir)/conf/common.mk -grub-emu: $(pkglib_MODULES) - $(CC) -o $@ $(pkglib_MODULES) $(grub_emu_LDFLAGS) $(LDFLAGS) +grub-emu: $(pkglib_MODULES) $(pkglib_PROGRAMS) + $(CC) -o $@ $(pkglib_MODULES) $(pkglib_PROGRAMS) $(grub_emu_LDFLAGS) $(LDFLAGS) From c5160d75c4efaa62f8d57f180c6d544b44096ca1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 03:43:07 +0100 Subject: [PATCH 121/237] Don't strip on any-emu --- conf/any-emu.rmk | 1 + genmk.rb | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index ebcc9087c..983dc2c1f 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -23,6 +23,7 @@ kernel_img_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \ grub_emu_init.c gnulib/progname.c kernel_img_CFLAGS = $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 kernel_img_LDFLAGS = $(COMMON_LDFLAGS) +TARGET_NO_STRIP = yes # For hostfs.mod. pkglib_MODULES += hostfs.mod diff --git a/genmk.rb b/genmk.rb index df03e1dfe..65bcb3ddd 100644 --- a/genmk.rb +++ b/genmk.rb @@ -148,7 +148,7 @@ ifneq ($(TARGET_APPLE_CC),1) -rm -f $@ $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ #{pre_obj} #{mod_obj} if test ! -z \"$(TARGET_OBJ2ELF)\"; then ./$(TARGET_OBJ2ELF) $@ || (rm -f $@; exit 1); fi - $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -K _grub_mod_init -K _grub_mod_fini -R .note -R .comment $@ + if test x$(TARGET_NO_STRIP) != xyes ; then $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -K _grub_mod_init -K _grub_mod_fini -R .note -R .comment $@; fi else #{@name}: #{pre_obj} #{mod_obj} $(TARGET_OBJ2ELF) -rm -f $@ @@ -330,11 +330,11 @@ MOSTLYCLEANFILES += #{deps_str} ifeq ($(#{prefix}_RELOCATABLE),yes) #{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str} $(TARGET_CC) -Wl,-r,-d -o $@ #{objs_str} $(TARGET_LDFLAGS) $(#{prefix}_LDFLAGS) - $(STRIP) --strip-unneeded -K start -R .note -R .comment $@ + if test x$(TARGET_NO_STRIP) != xyes ; then $(STRIP) --strip-unneeded -K start -R .note -R .comment $@; fi else #{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str} $(TARGET_CC) -o $@ #{objs_str} $(TARGET_LDFLAGS) $(#{prefix}_LDFLAGS) - $(STRIP) -R .rel.dyn -R .reginfo -R .note -R .comment $@ + if test x$(TARGET_NO_STRIP) != xyes ; then $(STRIP) -R .rel.dyn -R .reginfo -R .note -R .comment $@; fi endif " + objs.collect_with_index do |obj, i| From ebe841ad55b15f9920675b567c02bb6661e5bd18 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 03:48:38 +0100 Subject: [PATCH 122/237] Don't try to generate moddep.lst on any-emu.rmk --- conf/any-emu.rmk | 1 + genmk.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 983dc2c1f..7ed5fa74b 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -24,6 +24,7 @@ kernel_img_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \ kernel_img_CFLAGS = $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 kernel_img_LDFLAGS = $(COMMON_LDFLAGS) TARGET_NO_STRIP = yes +TARGET_NO_DYNAMIC_MODULES = yes # For hostfs.mod. pkglib_MODULES += hostfs.mod diff --git a/genmk.rb b/genmk.rb index 65bcb3ddd..7df15043a 100644 --- a/genmk.rb +++ b/genmk.rb @@ -143,6 +143,13 @@ mostlyclean-module-#{@name}.#{@rule_count}: MOSTLYCLEAN_MODULE_TARGETS += mostlyclean-module-#{@name}.#{@rule_count} UNDSYMFILES += #{undsym} +ifeq ($(TARGET_NO_DYNAMIC_MODULES), yes) +#{@name}: #{pre_obj} $(TARGET_OBJ2ELF) + -rm -f $@ + $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ #{pre_obj} + if test ! -z \"$(TARGET_OBJ2ELF)\"; then ./$(TARGET_OBJ2ELF) $@ || (rm -f $@; exit 1); fi + if test x$(TARGET_NO_STRIP) != xyes ; then $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -K _grub_mod_init -K _grub_mod_fini -R .note -R .comment $@; fi +else ifneq ($(TARGET_APPLE_CC),1) #{@name}: #{pre_obj} #{mod_obj} $(TARGET_OBJ2ELF) -rm -f $@ @@ -157,6 +164,7 @@ else $(OBJCONV) -f$(TARGET_MODULE_FORMAT) -nr:_grub_mod_init:grub_mod_init -nr:_grub_mod_fini:grub_mod_fini -wd1106 -nu -nd $@.bin $@ -rm -f $@.bin endif +endif #{pre_obj}: $(#{prefix}_DEPENDENCIES) #{objs_str} -rm -f $@ From 285505d3fc59db1fc760e1d459809c7d282ac309 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 03:58:14 +0100 Subject: [PATCH 123/237] Eliminate blacklist of modules w/o init --- conf/any-emu.rmk | 6 +++--- genemuinit.sh | 10 +++++++--- genemuinitheader.sh | 10 +++++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 7ed5fa74b..3e92cbe73 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -84,11 +84,11 @@ endif grub_emu_init.h: genemuinitheader.sh - rm -f $@; echo $(pkglib_MODULES) |sh $(srcdir)/genemuinitheader.sh > $@ + rm -f $@; echo $(pkglib_MODULES) | sh $(srcdir)/genemuinitheader.sh $(NM) > $@ DISTCLEANFILES += grub_emu_init.h -grub_emu_init.c: genemuinit.sh - rm -f $@; echo $(pkglib_MODULES) |sed 's,elf.mod,,;s,extcmd.mod,,;s,gzio.mod,,;s,fshelp.mod,,;s,bufio.mod,,;s,setjmp.mod,,;s,crypto.mod,,;s,pbkdf2.mod,,;s,trig.mod,,;s,bitmap_scale.mod,,;s,charset.mod,,;'|sh $(srcdir)/genemuinit.sh > $@ +grub_emu_init.c: genemuinit.sh $(pkglib_MODULES) + rm -f $@; echo $(pkglib_MODULES) | sh $(srcdir)/genemuinit.sh $(NM) > $@ DISTCLEANFILES += grub_emu_init.c include $(srcdir)/conf/common.mk diff --git a/genemuinit.sh b/genemuinit.sh index e40a683af..45c15ecb9 100644 --- a/genemuinit.sh +++ b/genemuinit.sh @@ -11,7 +11,7 @@ # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. -lst="$1" +nm="$1" shift cat < /dev/null; then + echo "grub_${line}_init ();" | sed 's,\.mod,,g;' + fi done cat < /dev/null; then + echo "grub_${line}_fini ();" | sed 's,\.mod,,g;' + fi done cat < /dev/null; then + echo "void grub_${line}_init (void);" | sed 's,\.mod,,g;' + fi + if ${nm} --defined-only -P -p ${line} | grep grub_mod_fini > /dev/null; then + echo "void grub_${line}_fini (void);" | sed 's,\.mod,,g;' + fi done From 1eebb21608647883706de5fe9022652eed5a7e01 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 04:01:22 +0100 Subject: [PATCH 124/237] Add missing dependency --- conf/any-emu.rmk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 3e92cbe73..542cd9bd1 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -83,7 +83,7 @@ grub_emu_LDFLAGS += $(LIBPCIACCESS) endif -grub_emu_init.h: genemuinitheader.sh +grub_emu_init.h: genemuinitheader.sh $(pkglib_MODULES) rm -f $@; echo $(pkglib_MODULES) | sh $(srcdir)/genemuinitheader.sh $(NM) > $@ DISTCLEANFILES += grub_emu_init.h From 2083672af13f98a2efcd467b1a818eff5669b942 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 04:23:44 +0100 Subject: [PATCH 125/237] Remove -DGRUB_UTIL when compiling grub-emu --- commands/parttool.c | 2 +- conf/any-emu.rmk | 4 +-- efiemu/main.c | 4 +-- efiemu/mm.c | 4 +-- include/grub/dl.h | 9 +++-- include/grub/mm.h | 2 +- include/grub/multiboot2.h | 70 --------------------------------------- include/grub/normal.h | 33 ------------------ include/grub/partition.h | 14 -------- include/grub/pci.h | 2 +- kern/dl.c | 2 +- loader/xnu.c | 6 ++-- util/grub-emu.c | 2 -- util/misc.c | 4 +++ 14 files changed, 24 insertions(+), 134 deletions(-) delete mode 100644 include/grub/multiboot2.h diff --git a/commands/parttool.c b/commands/parttool.c index 5ad6133ca..0850c5e1d 100644 --- a/commands/parttool.c +++ b/commands/parttool.c @@ -175,7 +175,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), } /* Load modules. */ -#ifndef GRUB_UTIL +#if GRUB_NO_MODULES { const char *prefix; prefix = grub_env_get ("prefix"); diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 542cd9bd1..0f717c59c 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -1,7 +1,7 @@ # -*- makefile -*- COMMON_LDFLAGS += -nostdlib -COMMON_CFLAGS += -DGRUB_UTIL=1 +COMMON_CFLAGS += # Used by various components. These rules need to precede them. script/lexer.c_DEPENDENCIES = grub_script.tab.h @@ -21,7 +21,7 @@ kernel_img_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \ util/hostdisk.c util/getroot.c \ \ grub_emu_init.c gnulib/progname.c -kernel_img_CFLAGS = $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 +kernel_img_CFLAGS = $(CPPFLAGS) $(CFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) TARGET_NO_STRIP = yes TARGET_NO_DYNAMIC_MODULES = yes diff --git a/efiemu/main.c b/efiemu/main.c index 9480bfc4d..8a8a508fa 100644 --- a/efiemu/main.c +++ b/efiemu/main.c @@ -265,7 +265,7 @@ grub_efiemu_autocore (void) grub_free (filename); if (err) return err; -#ifndef GRUB_UTIL +#ifndef GRUB_MACHINE_EMU err = grub_machine_efiemu_init_tables (); if (err) return err; @@ -313,7 +313,7 @@ grub_cmd_efiemu_load (grub_command_t cmd __attribute__ ((unused)), err = grub_efiemu_load_file (args[0]); if (err) return err; -#ifndef GRUB_UTIL +#ifndef GRUB_MACHINE_EMU err = grub_machine_efiemu_init_tables (); if (err) return err; diff --git a/efiemu/mm.c b/efiemu/mm.c index 6099a14ee..4b293606f 100644 --- a/efiemu/mm.c +++ b/efiemu/mm.c @@ -281,7 +281,7 @@ grub_efiemu_mmap_init (void) // the place for memory used by efiemu itself mmap_reserved_size = GRUB_EFI_MAX_MEMORY_TYPE + 1; -#ifndef GRUB_UTIL +#ifndef GRUB_MACHINE_EMU grub_machine_mmap_iterate (bounds_hook); #endif @@ -394,7 +394,7 @@ grub_efiemu_mmap_fill (void) } } -#ifndef GRUB_UTIL +#ifndef GRUB_MACHINE_EMU grub_machine_mmap_iterate (fill_hook); #endif diff --git a/include/grub/dl.h b/include/grub/dl.h index ac0ecd336..17e03f400 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -91,7 +91,12 @@ grub_dl_t grub_dl_load_core (void *addr, grub_size_t size); int EXPORT_FUNC(grub_dl_unload) (grub_dl_t mod); void grub_dl_unload_unneeded (void); void grub_dl_unload_all (void); -#ifdef GRUB_UTIL +#if defined (GRUB_MACHINE_EMU) || defined (GRUB_UTIL) +#define GRUB_NO_MODULES 1 +#else +#define GRUB_NO_MODULES 0 +#endif +#if GRUB_NO_MODULES static inline int grub_dl_ref (grub_dl_t mod) { @@ -116,7 +121,7 @@ grub_err_t grub_dl_register_symbol (const char *name, void *addr, grub_err_t grub_arch_dl_check_header (void *ehdr); grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr); -#if defined (_mips) && ! defined (GRUB_UTIL) +#if defined (_mips) && ! defined (GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) #define GRUB_LINKER_HAVE_INIT 1 void grub_arch_dl_init_linker (void); #endif diff --git a/include/grub/mm.h b/include/grub/mm.h index 4caf80511..4f443ee25 100644 --- a/include/grub/mm.h +++ b/include/grub/mm.h @@ -36,7 +36,7 @@ void *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size); void *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size); /* For debugging. */ -#if defined(MM_DEBUG) && !defined(GRUB_UTIL) +#if defined(MM_DEBUG) && !defined(GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) /* Set this variable to 1 when you want to trace all memory function calls. */ extern int EXPORT_VAR(grub_mm_debug); diff --git a/include/grub/multiboot2.h b/include/grub/multiboot2.h deleted file mode 100644 index af10cdc21..000000000 --- a/include/grub/multiboot2.h +++ /dev/null @@ -1,70 +0,0 @@ -/* multiboot2.h - multiboot2 header file with grub definitions. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2007 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_MULTIBOOT2_HEADER -#define GRUB_MULTIBOOT2_HEADER 1 - -#include -#include -#include - -#ifndef GRUB_UTIL -typedef grub_uint32_t uint32_t; -typedef grub_uint64_t uint64_t; -#define __WORDSIZE GRUB_TARGET_WORDSIZE -#endif - -struct multiboot2_tag_header; - -grub_err_t -grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len); - -grub_err_t -grub_mb2_tags_arch_create (void); - -void -grub_mb2_arch_boot (grub_addr_t entry, void *tags); - -void -grub_mb2_arch_unload (struct multiboot2_tag_header *tags); - -grub_err_t -grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, grub_addr_t *addr, int *do_load); - -grub_err_t -grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, grub_addr_t *addr, int *do_load); - -grub_err_t -grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr); - -grub_err_t -grub_mb2_arch_module_free (grub_addr_t addr, grub_size_t size); - -void -grub_multiboot2 (int argc, char *argv[]); - -void -grub_module2 (int argc, char *argv[]); - -#define for_each_tag(tag, tags) \ - for (tag = tags; \ - tag && tag->key != MULTIBOOT2_TAG_END; \ - tag = (struct multiboot2_tag_header *)((char *)tag + tag->len)) - -#endif /* ! GRUB_MULTIBOOT2_HEADER */ diff --git a/include/grub/normal.h b/include/grub/normal.h index e804fde77..fad1a41ba 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -110,37 +110,4 @@ void read_terminal_list (void); void grub_set_more (int onoff); -#ifdef GRUB_UTIL -void grub_normal_init (void); -void grub_normal_fini (void); -void grub_hello_init (void); -void grub_hello_fini (void); -void grub_ls_init (void); -void grub_ls_fini (void); -void grub_cat_init (void); -void grub_cat_fini (void); -void grub_boot_init (void); -void grub_boot_fini (void); -void grub_cmp_init (void); -void grub_cmp_fini (void); -void grub_terminal_init (void); -void grub_terminal_fini (void); -void grub_loop_init (void); -void grub_loop_fini (void); -void grub_help_init (void); -void grub_help_fini (void); -void grub_halt_init (void); -void grub_halt_fini (void); -void grub_reboot_init (void); -void grub_reboot_fini (void); -void grub_configfile_init (void); -void grub_configfile_fini (void); -void grub_search_init (void); -void grub_search_fini (void); -void grub_test_init (void); -void grub_test_fini (void); -void grub_blocklist_init (void); -void grub_blocklist_fini (void); -#endif - #endif /* ! GRUB_NORMAL_HEADER */ diff --git a/include/grub/partition.h b/include/grub/partition.h index d35658cdd..faa89cea6 100644 --- a/include/grub/partition.h +++ b/include/grub/partition.h @@ -83,20 +83,6 @@ void EXPORT_FUNC(grub_partition_map_register) (grub_partition_map_t partmap); void EXPORT_FUNC(grub_partition_map_unregister) (grub_partition_map_t partmap); -#ifdef GRUB_UTIL -void grub_msdos_partition_map_init (void); -void grub_msdos_partition_map_fini (void); -void grub_amiga_partition_map_init (void); -void grub_amiga_partition_map_fini (void); -void grub_apple_partition_map_init (void); -void grub_apple_partition_map_fini (void); -void grub_sun_partition_map_init (void); -void grub_sun_partition_map_fini (void); -void grub_gpt_partition_map_init (void); -void grub_gpt_partition_map_fini (void); -void grub_apple_partition_map_init (void); -void grub_apple_partition_map_fini (void); -#endif static inline grub_disk_addr_t grub_partition_get_start (const grub_partition_t p) diff --git a/include/grub/pci.h b/include/grub/pci.h index 1f3ac7fc7..89bd1034a 100644 --- a/include/grub/pci.h +++ b/include/grub/pci.h @@ -68,7 +68,7 @@ typedef grub_uint32_t grub_pci_id_t; -#ifdef GRUB_UTIL +#ifdef GRUB_MACHINE_EMU #include #else typedef grub_uint32_t grub_pci_address_t; diff --git a/kern/dl.c b/kern/dl.c index 4735a004a..278d5b568 100644 --- a/kern/dl.c +++ b/kern/dl.c @@ -469,7 +469,7 @@ grub_dl_resolve_dependencies (grub_dl_t mod, Elf_Ehdr *e) return GRUB_ERR_NONE; } -#ifndef GRUB_UTIL +#if !GRUB_NO_MODULES int grub_dl_ref (grub_dl_t mod) { diff --git a/loader/xnu.c b/loader/xnu.c index cf9fa740b..8f1d0c641 100644 --- a/loader/xnu.c +++ b/loader/xnu.c @@ -1390,7 +1390,7 @@ grub_cmd_xnu_splash (grub_extcmd_t cmd, } -#ifndef GRUB_UTIL +#ifndef GRUB_MACHINE_EMU static grub_err_t grub_cmd_xnu_resume (grub_command_t cmd __attribute__ ((unused)), int argc, char *args[]) @@ -1444,7 +1444,7 @@ GRUB_MOD_INIT(xnu) N_("Load a splash image for XNU."), xnu_splash_cmd_options); -#ifndef GRUB_UTIL +#ifndef GRUB_MACHINE_EMU cmd_resume = grub_register_command ("xnu_resume", grub_cmd_xnu_resume, 0, N_("Load XNU hibernate image.")); #endif @@ -1456,7 +1456,7 @@ GRUB_MOD_INIT(xnu) GRUB_MOD_FINI(xnu) { -#ifndef GRUB_UTIL +#ifndef GRUB_MACHINE_EMU grub_unregister_command (cmd_resume); #endif grub_unregister_command (cmd_mkext); diff --git a/util/grub-emu.c b/util/grub-emu.c index f64e66c5f..08ae19836 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -157,8 +157,6 @@ main (int argc, char *argv[]) set_program_name (argv[0]); - grub_util_init_nls (); - while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1) switch (opt) { diff --git a/util/misc.c b/util/misc.c index 8c79e8d9b..7381c8fdd 100644 --- a/util/misc.c +++ b/util/misc.c @@ -104,6 +104,7 @@ grub_util_error (const char *fmt, ...) exit (1); } +#ifdef GRUB_UTIL int grub_err_printf (const char *fmt, ...) { @@ -116,6 +117,7 @@ grub_err_printf (const char *fmt, ...) return ret; } +#endif void * xmalloc (size_t size) @@ -598,6 +600,7 @@ make_system_path_relative_to_its_root (const char *path) return buf3; } +#ifdef GRUB_UTIL void grub_util_init_nls (void) { @@ -607,3 +610,4 @@ grub_util_init_nls (void) textdomain (PACKAGE); #endif /* ENABLE_NLS */ } +#endif From 19987ffa0249acd32cb76eff5e4aeef33f3a1076 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 04:45:54 +0100 Subject: [PATCH 126/237] Remove the need for explicit make grub-emu --- Makefile.in | 11 +++++++---- conf/any-emu.rmk | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile.in b/Makefile.in index 853eea9db..e69c18b40 100644 --- a/Makefile.in +++ b/Makefile.in @@ -178,7 +178,10 @@ endif ### General targets. CLEANFILES += $(pkglib_DATA) $(pkgdata_DATA) po/*.mo -pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst +pkglib_DATA += command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst +ifneq ($(platform), emu) +pkglib_DATA += moddep.lst +endif moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep.awk cat $(DEFSYMFILES) /dev/null \ | $(AWK) -f $(srcdir)/genmoddep.awk $(UNDSYMFILES) > $@ \ @@ -278,7 +281,7 @@ build_env.mk: Makefile ) > $@ pkglib_BUILDDIR += config.h grub_script.tab.h -all-local: $(PROGRAMS) $(PKGLIB) $(PKGDATA) $(SCRIPTS) $(INFOS) $(MKFILES) $(foreach lang, $(LINGUAS), po/$(lang).mo) +all-local: $(PROGRAMS) $(GRUB_EMU) $(PKGLIB) $(PKGDATA) $(SCRIPTS) $(INFOS) $(MKFILES) $(foreach lang, $(LINGUAS), po/$(lang).mo) install: install-local @@ -299,7 +302,7 @@ install-local: all $(INSTALL_DATA) $$dir$$file $(DESTDIR)$(pkgdatadir)/$$dest; \ done $(SHELL) $(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)/man1 - @list='$(bin_UTILITIES)'; for file in $$list; do \ + @list='$(bin_UTILITIES) $(GRUB_EMU)'; for file in $$list; do \ if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \ dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \ $(INSTALL_PROGRAM) $$dir$$file $(DESTDIR)$(bindir)/$$dest; \ @@ -375,7 +378,7 @@ uninstall: dest="`echo $$file | sed 's,.*/,,'`"; \ rm -f $(DESTDIR)$(pkgdatadir)/$$dest; \ done - @list='$(bin_UTILITIES) $(bin_SCRIPTS)'; for file in $$list; do \ + @list='$(bin_UTILITIES) $(bin_SCRIPTS) $(GRUB_EMU)'; for file in $$list; do \ dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \ rm -f $(DESTDIR)$(bindir)/$$dest; \ rm -f $(DESTDIR)$(mandir)/man1/$$dest.1; \ diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 0f717c59c..7e9e34920 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -82,6 +82,7 @@ pci_mod_LDFLAGS = $(COMMON_LDFLAGS) grub_emu_LDFLAGS += $(LIBPCIACCESS) endif +include $(srcdir)/conf/common.mk grub_emu_init.h: genemuinitheader.sh $(pkglib_MODULES) rm -f $@; echo $(pkglib_MODULES) | sh $(srcdir)/genemuinitheader.sh $(NM) > $@ @@ -91,8 +92,8 @@ grub_emu_init.c: genemuinit.sh $(pkglib_MODULES) rm -f $@; echo $(pkglib_MODULES) | sh $(srcdir)/genemuinit.sh $(NM) > $@ DISTCLEANFILES += grub_emu_init.c -include $(srcdir)/conf/common.mk - +CLEANFILES += grub-emu grub-emu: $(pkglib_MODULES) $(pkglib_PROGRAMS) $(CC) -o $@ $(pkglib_MODULES) $(pkglib_PROGRAMS) $(grub_emu_LDFLAGS) $(LDFLAGS) +GRUB_EMU=grub-emu From ceb294b7eef0d0bd14376e9f2bfb32f909975771 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 04:47:46 +0100 Subject: [PATCH 127/237] Don't create useless .lst --- Makefile.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile.in b/Makefile.in index e69c18b40..820bfa946 100644 --- a/Makefile.in +++ b/Makefile.in @@ -178,9 +178,8 @@ endif ### General targets. CLEANFILES += $(pkglib_DATA) $(pkgdata_DATA) po/*.mo -pkglib_DATA += command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst ifneq ($(platform), emu) -pkglib_DATA += moddep.lst +pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst endif moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep.awk cat $(DEFSYMFILES) /dev/null \ From c3e6233987018f036f54c92f0e303db57a364529 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 04:50:30 +0100 Subject: [PATCH 128/237] REmove the need for disable-werror --- conf/any-emu.rmk | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 7e9e34920..77092454b 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -20,12 +20,18 @@ kernel_img_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \ util/console.c util/grub-emu.c util/misc.c \ util/hostdisk.c util/getroot.c \ \ - grub_emu_init.c gnulib/progname.c + grub_emu_init.c kernel_img_CFLAGS = $(CPPFLAGS) $(CFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) TARGET_NO_STRIP = yes TARGET_NO_DYNAMIC_MODULES = yes +# progname.c always has warnings. Compile it separately. +pkglib_MODULES += progname.mod +progname_mod_SOURCES = gnulib/progname.c +progname_mod_CFLAGS = $(COMMON_CFLAGS) -Wno-error +progname_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For hostfs.mod. pkglib_MODULES += hostfs.mod hostfs_mod_SOURCES = util/hostfs.c From b255e9cfb3939bd36f039e269d30e718ac00d62d Mon Sep 17 00:00:00 2001 From: Yves Blusseau Date: Sun, 7 Feb 2010 16:02:51 +0100 Subject: [PATCH 129/237] 2010-02-07 Yves Blusseau * gnulib/getdelim.c: add missing header (type ssize_t must be defined). --- ChangeLog | 4 ++++ gnulib/getdelim.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index ec3318c5b..540639220 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-07 Yves Blusseau + + * gnulib/getdelim.c: add missing header (type ssize_t must be defined). + 2010-02-07 Vladimir Serbinenko Fix warnings in grub-emu when compiling with maximum warning options. diff --git a/gnulib/getdelim.c b/gnulib/getdelim.c index 12f2167c9..85818b565 100644 --- a/gnulib/getdelim.c +++ b/gnulib/getdelim.c @@ -27,6 +27,7 @@ #include #include #include +#include #ifndef SSIZE_MAX # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) From ac307b2ae4e58d2854281bf4a00527b778a4dd2b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 16:47:50 +0100 Subject: [PATCH 130/237] Cleanup --- Makefile.in | 6 ++++-- conf/any-emu.rmk | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile.in b/Makefile.in index 820bfa946..7af2df1f0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -89,8 +89,10 @@ TARGET_ASFLAGS = @TARGET_ASFLAGS@ TARGET_MODULE_FORMAT = @TARGET_MODULE_FORMAT@ TARGET_APPLE_CC = @TARGET_APPLE_CC@ OBJCONV = @OBJCONV@ -TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I$(srcdir)/include -I$(builddir) -I$(builddir)/include \ - -Wall -W +TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I$(srcdir)/include -I$(builddir) -I$(builddir)/include -Wall -W +ifneq ($(platform), emu) +TARGET_CPPFLAGS += -nostdinc -isystem $(shell $(TARGET_CC) -print-file-name=include) +endif TARGET_LDFLAGS = @TARGET_LDFLAGS@ TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@ TARGET_IMG_LDFLAGS = @TARGET_IMG_LDFLAGS@ diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 77092454b..529174bc3 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -6,7 +6,6 @@ COMMON_CFLAGS += # Used by various components. These rules need to precede them. script/lexer.c_DEPENDENCIES = grub_script.tab.h -#sbin_UTILITIES += grub-emu util/grub-emu.c_DEPENDENCIES = grub_emu_init.h kernel_img_RELOCATABLE = yes pkglib_PROGRAMS = kernel.img From 62853e73e5b455f2208d3ba410736a4bd0b407d9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 16:48:11 +0100 Subject: [PATCH 131/237] ChangeLog --- ChangeLog.emu-mod | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ChangeLog.emu-mod diff --git a/ChangeLog.emu-mod b/ChangeLog.emu-mod new file mode 100644 index 000000000..7ebdecdd8 --- /dev/null +++ b/ChangeLog.emu-mod @@ -0,0 +1,57 @@ +2010-02-07 Vladimir Serbinenko + + Compile parts of grub-emu as modules. + + * Makefile.in (TARGET_CPPFLAGS) [emu]: Remove -nostdinc -isystem. + (pkglib_DATA) [emu]: Remove moddep.lst command.lst fs.lst + partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst. + (all-local): Add $(GRUB_EMU). + (install-local): Install $(GRUB_EMU). + (uninstall): Uninstall $(GRUB_EMU). + * commands/parttool.c: Replace GRUB_UTIL with GRUB_NO_MODULES. + * kern/dl.c: Likewise. + * commands/sleep.c: Not include machine/time.h. + * conf/any-emu.rmk (COMMON_LDFLAGS): New variable. + (COMMON_CFLAGS): Likewise. + (sbin_UTILITIES): Remove grub-emu. + (grub_emu_SOURCES): Removed. + (kernel_img_RELOCATABLE): New variable. + (pkglib_PROGRAMS): Add kernel.img. + (kernel_img_SOURCES): New variable + (kernel_img_CFLAGS): Likewise. + (kernel_img_LDFLAGS): Likewise. + (TARGET_NO_STRIP): Likewise. + (TARGET_NO_DYNAMIC_MODULES): Likewise. + (pkglib_MODULES): Add progname.mod, hostfs.mod, host.mod, reboot.mod, + halt.mod, cpuid.mod, usb.mod, sdl.mod and pci.mod. + (grub-emu): New target. + (GRUB_EMU): New variable. + * configure.ac: Whitelist -emu as possible x86_64 architecture. + * efiemu/main.c: Replace GRUB_UTIL with GRUB_MACHINE_EMU. + * loader/xnu.c: Likewise. + * include/grub/pci.h: Likewise. + * genemuinit.sh: New file. + * genemuinitheader.sh: Likewise. + * genmk.rb: Don't strip if TARGET_NO_STRIP is yes. + Support TARGET_NO_DYNAMIC_MODULES. + * include/grub/dl.h (GRUB_NO_MODULES): New variable. + * commands/search.c: Fix GRUB_MOD_INIT and GRUB_MOD_FINI arguments. + * disk/loopback.c: Likewise. + * font/font_cmd.c: Likewise. + * partmap/acorn.c: Likewise. + * partmap/amiga.c: Likewise. + * partmap/apple.c: Likewise. + * partmap/gpt.c: Likewise. + * partmap/msdos.c: Likewise. + * partmap/sun.c: Likewise. + * parttool/msdospart.c: Likewise. + * term/gfxterm.c: Likewise. + * video/bitmap.c: Likewise. + * video/readers/jpeg.c: Likewise. + * video/readers/png.c: Likewise. + * video/readers/tga.c: Likewise. + * video/video.c: Likewise. + * util/grub-emu.c (read_command_list): Removed. + (main): Don't call util_init_nls. + * util/misc.c (grub_err_printf) [!GRUB_UTIL]: Removed. + (grub_util_init_nls) [!GRUB_UTIL]: Likewise. From 6e14234c874224e88345492373c77eee34d00e18 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 16:51:16 +0100 Subject: [PATCH 132/237] 2010-02-07 Vladimir Serbinenko * include/grub/multiboot2.h: Remove leftover file. --- ChangeLog | 6 +++- include/grub/multiboot2.h | 70 --------------------------------------- 2 files changed, 5 insertions(+), 71 deletions(-) delete mode 100644 include/grub/multiboot2.h diff --git a/ChangeLog b/ChangeLog index 540639220..7e9e18348 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ +2010-02-07 Vladimir Serbinenko + + * include/grub/multiboot2.h: Remove leftover file. + 2010-02-07 Yves Blusseau - * gnulib/getdelim.c: add missing header (type ssize_t must be defined). + * gnulib/getdelim.c: add missing header (type ssize_t must be defined). 2010-02-07 Vladimir Serbinenko diff --git a/include/grub/multiboot2.h b/include/grub/multiboot2.h deleted file mode 100644 index af10cdc21..000000000 --- a/include/grub/multiboot2.h +++ /dev/null @@ -1,70 +0,0 @@ -/* multiboot2.h - multiboot2 header file with grub definitions. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2007 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_MULTIBOOT2_HEADER -#define GRUB_MULTIBOOT2_HEADER 1 - -#include -#include -#include - -#ifndef GRUB_UTIL -typedef grub_uint32_t uint32_t; -typedef grub_uint64_t uint64_t; -#define __WORDSIZE GRUB_TARGET_WORDSIZE -#endif - -struct multiboot2_tag_header; - -grub_err_t -grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len); - -grub_err_t -grub_mb2_tags_arch_create (void); - -void -grub_mb2_arch_boot (grub_addr_t entry, void *tags); - -void -grub_mb2_arch_unload (struct multiboot2_tag_header *tags); - -grub_err_t -grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, grub_addr_t *addr, int *do_load); - -grub_err_t -grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, grub_addr_t *addr, int *do_load); - -grub_err_t -grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr); - -grub_err_t -grub_mb2_arch_module_free (grub_addr_t addr, grub_size_t size); - -void -grub_multiboot2 (int argc, char *argv[]); - -void -grub_module2 (int argc, char *argv[]); - -#define for_each_tag(tag, tags) \ - for (tag = tags; \ - tag && tag->key != MULTIBOOT2_TAG_END; \ - tag = (struct multiboot2_tag_header *)((char *)tag + tag->len)) - -#endif /* ! GRUB_MULTIBOOT2_HEADER */ From e28e32ae51c75a64333deffbd78f1cda9c376fc8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 16:52:47 +0100 Subject: [PATCH 133/237] 2010-02-07 Vladimir Serbinenko * include/grub/normal.h [GRUB_UTIL]: Remove leftover declarations. * include/grub/partition.h [GRUB_UTIL]: Likewise. --- ChangeLog | 2 ++ include/grub/normal.h | 33 --------------------------------- include/grub/partition.h | 14 -------------- 3 files changed, 2 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7e9e18348..dede0af2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ 2010-02-07 Vladimir Serbinenko * include/grub/multiboot2.h: Remove leftover file. + * include/grub/normal.h [GRUB_UTIL]: Remove leftover declarations. + * include/grub/partition.h [GRUB_UTIL]: Likewise. 2010-02-07 Yves Blusseau diff --git a/include/grub/normal.h b/include/grub/normal.h index e804fde77..fad1a41ba 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -110,37 +110,4 @@ void read_terminal_list (void); void grub_set_more (int onoff); -#ifdef GRUB_UTIL -void grub_normal_init (void); -void grub_normal_fini (void); -void grub_hello_init (void); -void grub_hello_fini (void); -void grub_ls_init (void); -void grub_ls_fini (void); -void grub_cat_init (void); -void grub_cat_fini (void); -void grub_boot_init (void); -void grub_boot_fini (void); -void grub_cmp_init (void); -void grub_cmp_fini (void); -void grub_terminal_init (void); -void grub_terminal_fini (void); -void grub_loop_init (void); -void grub_loop_fini (void); -void grub_help_init (void); -void grub_help_fini (void); -void grub_halt_init (void); -void grub_halt_fini (void); -void grub_reboot_init (void); -void grub_reboot_fini (void); -void grub_configfile_init (void); -void grub_configfile_fini (void); -void grub_search_init (void); -void grub_search_fini (void); -void grub_test_init (void); -void grub_test_fini (void); -void grub_blocklist_init (void); -void grub_blocklist_fini (void); -#endif - #endif /* ! GRUB_NORMAL_HEADER */ diff --git a/include/grub/partition.h b/include/grub/partition.h index d35658cdd..faa89cea6 100644 --- a/include/grub/partition.h +++ b/include/grub/partition.h @@ -83,20 +83,6 @@ void EXPORT_FUNC(grub_partition_map_register) (grub_partition_map_t partmap); void EXPORT_FUNC(grub_partition_map_unregister) (grub_partition_map_t partmap); -#ifdef GRUB_UTIL -void grub_msdos_partition_map_init (void); -void grub_msdos_partition_map_fini (void); -void grub_amiga_partition_map_init (void); -void grub_amiga_partition_map_fini (void); -void grub_apple_partition_map_init (void); -void grub_apple_partition_map_fini (void); -void grub_sun_partition_map_init (void); -void grub_sun_partition_map_fini (void); -void grub_gpt_partition_map_init (void); -void grub_gpt_partition_map_fini (void); -void grub_apple_partition_map_init (void); -void grub_apple_partition_map_fini (void); -#endif static inline grub_disk_addr_t grub_partition_get_start (const grub_partition_t p) From a1a8d38a5862ec296e5940be1f38af8804118f09 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 17:30:16 +0100 Subject: [PATCH 134/237] Use nostdinc --- conf/any-emu.rmk | 25 ++++--------------------- util/grub-emu.c | 9 +++++++++ util/hostdisk.c | 6 +++--- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 529174bc3..d3d2c2f2f 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -1,7 +1,7 @@ # -*- makefile -*- COMMON_LDFLAGS += -nostdlib -COMMON_CFLAGS += +COMMON_CFLAGS += -nostdinc -isystem $(shell $(TARGET_CC) -print-file-name=include) # Used by various components. These rules need to precede them. script/lexer.c_DEPENDENCIES = grub_script.tab.h @@ -19,30 +19,12 @@ kernel_img_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \ util/console.c util/grub-emu.c util/misc.c \ util/hostdisk.c util/getroot.c \ \ - grub_emu_init.c -kernel_img_CFLAGS = $(CPPFLAGS) $(CFLAGS) + grub_emu_init.c gnulib/progname.c util/hostfs.c disk/host.c +kernel_img_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-undef -I$(srcdir)/gnulib kernel_img_LDFLAGS = $(COMMON_LDFLAGS) TARGET_NO_STRIP = yes TARGET_NO_DYNAMIC_MODULES = yes -# progname.c always has warnings. Compile it separately. -pkglib_MODULES += progname.mod -progname_mod_SOURCES = gnulib/progname.c -progname_mod_CFLAGS = $(COMMON_CFLAGS) -Wno-error -progname_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For hostfs.mod. -pkglib_MODULES += hostfs.mod -hostfs_mod_SOURCES = util/hostfs.c -hostfs_mod_CFLAGS = $(COMMON_CFLAGS) -hostfs_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For host.mod. -pkglib_MODULES += host.mod -host_mod_SOURCES = disk/host.c -host_mod_CFLAGS = $(COMMON_CFLAGS) -host_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For reboot.mod. pkglib_MODULES += reboot.mod reboot_mod_SOURCES = commands/reboot.c @@ -76,6 +58,7 @@ endif ifeq ($(enable_grub_emu_sdl), yes) pkglib_MODULES += sdl.mod sdl_mod_SOURCES = util/sdl.c +sdl_mod_CFLAGS = sdl_mod_LDFLAGS = $(COMMON_LDFLAGS) grub_emu_LDFLAGS += $(LIBSDL) endif diff --git a/util/grub-emu.c b/util/grub-emu.c index 08ae19836..7d4544509 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -146,6 +146,11 @@ usage (int status) } +void grub_hostfs_init (void); +void grub_hostfs_fini (void); +void grub_host_init (void); +void grub_host_fini (void); + int main (int argc, char *argv[]) { @@ -204,6 +209,8 @@ main (int argc, char *argv[]) signal (SIGINT, SIG_IGN); grub_console_init (); + grub_host_init (); + grub_hostfs_init (); /* XXX: This is a bit unportable. */ grub_util_biosdisk_init (dev_map); @@ -236,6 +243,8 @@ main (int argc, char *argv[]) grub_main (); grub_fini_all (); + grub_hostfs_fini (); + grub_host_fini (); grub_machine_fini (); diff --git a/util/hostdisk.c b/util/hostdisk.c index 98d3d53ae..be5d05afc 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -168,7 +168,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) drive = find_grub_drive (name); if (drive < 0) - return grub_error (GRUB_ERR_BAD_DEVICE, + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no mapping exists for `%s'", name); disk->has_partitions = 1; @@ -198,7 +198,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) fd = open (map[drive].device, O_RDONLY); if (fd == -1) - return grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s' while attempting to get disk size", map[drive].device); + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot open `%s' while attempting to get disk size", map[drive].device); # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode)) @@ -244,7 +244,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) # warning "No special routine to get the size of a block device is implemented for your OS. This is not possibly fatal." #endif if (stat (map[drive].device, &st) < 0) - return grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive].device); + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot stat `%s'", map[drive].device); disk->total_sectors = st.st_size >> GRUB_DISK_SECTOR_BITS; From b4674703a12144315b2d725c40bc490645727712 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 17:39:52 +0100 Subject: [PATCH 135/237] Add fno-builtin --- conf/any-emu.rmk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index d3d2c2f2f..a4ee9b755 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -1,7 +1,7 @@ # -*- makefile -*- COMMON_LDFLAGS += -nostdlib -COMMON_CFLAGS += -nostdinc -isystem $(shell $(TARGET_CC) -print-file-name=include) +COMMON_CFLAGS += -nostdinc -isystem $(shell $(TARGET_CC) -print-file-name=include) -fno-builtin # Used by various components. These rules need to precede them. script/lexer.c_DEPENDENCIES = grub_script.tab.h From c98d2a13c20f4e5bd75b500d7cbbd739c4b71a61 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 7 Feb 2010 10:27:03 -0800 Subject: [PATCH 136/237] 2010-02-07 Colin Watson * NEWS: Update. --- ChangeLog | 4 ++++ NEWS | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/ChangeLog b/ChangeLog index dede0af2e..37081a9e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-07 Colin Watson + + * NEWS: Update. + 2010-02-07 Vladimir Serbinenko * include/grub/multiboot2.h: Remove leftover file. diff --git a/NEWS b/NEWS index cc725fd3b..828eea081 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,20 @@ New in 1.98: +* Graphical menu support. + +* MIPS support. + +* Saved default menu entry support, with new utilities `grub-reboot' and + `grub-set-default'. + +* Unit testing framework. + +* Support for multiple terminals. + +* Encrypted password support, with a new utility `grub-mkpasswd-pbkdf2'. + +* `grub-mkfloppy' removed; use `grub-mkrescue' to create floppy images. + * Add grub-probe support for GNU/Hurd. * Add support for gettext. From 473df63dc0fa943ab4b3bdbbabc224dd63a1a45d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 19:57:55 +0100 Subject: [PATCH 137/237] 2010-02-07 Vladimir Serbinenko * genkernsyms.sh.in: Use TARGET_CC. --- ChangeLog | 4 ++++ genkernsyms.sh.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 37081a9e4..f7b2ce8bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-07 Vladimir Serbinenko + + * genkernsyms.sh.in: Use TARGET_CC. + 2010-02-07 Colin Watson * NEWS: Update. diff --git a/genkernsyms.sh.in b/genkernsyms.sh.in index b2f3f7af9..c5c63b2d5 100644 --- a/genkernsyms.sh.in +++ b/genkernsyms.sh.in @@ -14,7 +14,7 @@ ### The configure script will replace these variables. : ${srcdir=@srcdir@} -: ${CC=@CC@} +: ${CC=@TARGET_CC@} u= grep "^#define HAVE_ASM_USCORE" config.h >/dev/null 2>&1 && u="_" From 56e33364c54611d68cce355bdf1c191c3d69b157 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 19:59:19 +0100 Subject: [PATCH 138/237] Fix yeeloong compilation --- kern/mips/yeeloong/init.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kern/mips/yeeloong/init.c b/kern/mips/yeeloong/init.c index 14e8a39a2..d48a7341a 100644 --- a/kern/mips/yeeloong/init.c +++ b/kern/mips/yeeloong/init.c @@ -29,10 +29,10 @@ #include extern void grub_video_sm712_init (void); -extern void grub_video_video_init (void); -extern void grub_video_bitmap_init (void); -extern void grub_font_manager_init (void); -extern void grub_term_gfxterm_init (void); +extern void grub_video_init (void); +extern void grub_bitmap_init (void); +extern void grub_font_init (void); +extern void grub_gfxterm_init (void); extern void grub_at_keyboard_init (void); /* FIXME: use interrupt to count high. */ @@ -98,10 +98,10 @@ grub_machine_init (void) /* Initialize output terminal (can't be done earlier, as gfxterm relies on a working heap. */ grub_video_sm712_init (); - grub_video_video_init (); - grub_video_bitmap_init (); - grub_font_manager_init (); - grub_term_gfxterm_init (); + grub_video_init (); + grub_bitmap_init (); + grub_font_init (); + grub_gfxterm_init (); grub_at_keyboard_init (); } From 62509f04348a468b9db6894ae15e9dc14bbff484 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 22:49:45 +0100 Subject: [PATCH 139/237] 2010-02-07 Vladimir Serbinenko * kern/ieee1275/openfw.c (grub_halt): Try executing "poweroff". --- ChangeLog | 4 ++++ kern/ieee1275/openfw.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f7b2ce8bf..ff8f3d41c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-07 Vladimir Serbinenko + + * kern/ieee1275/openfw.c (grub_halt): Try executing "poweroff". + 2010-02-07 Vladimir Serbinenko * genkernsyms.sh.in: Use TARGET_CC. diff --git a/kern/ieee1275/openfw.c b/kern/ieee1275/openfw.c index dd9a9138f..e5f565c4c 100644 --- a/kern/ieee1275/openfw.c +++ b/kern/ieee1275/openfw.c @@ -405,8 +405,9 @@ grub_reboot (void) void grub_halt (void) { - /* Not standardized. We try both known commands. */ + /* Not standardized. We try three known commands. */ grub_ieee1275_interpret ("shut-down", 0); grub_ieee1275_interpret ("power-off", 0); + grub_ieee1275_interpret ("poweroff", 0); } From f84dc56090d055077b4c9bc222e665b20bf22094 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 22:56:25 +0100 Subject: [PATCH 140/237] Initial implementation of ofwclock --- ChangeLog.ofwclock | 15 ++++ conf/powerpc-ieee1275.rmk | 17 +++++ conf/sparc64-ieee1275.rmk | 17 +++++ lib/ieee1275/datetime.c | 142 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+) create mode 100644 ChangeLog.ofwclock create mode 100644 lib/ieee1275/datetime.c diff --git a/ChangeLog.ofwclock b/ChangeLog.ofwclock new file mode 100644 index 000000000..1cdd99cd4 --- /dev/null +++ b/ChangeLog.ofwclock @@ -0,0 +1,15 @@ +2010-02-07 Vladimir Serbinenko + + * conf/powerpc-ieee1275.rmk (pkglib_MODULES): Add datetime.mod, + date.mod, datehook.mod. + (datetime_mod_SOURCES): New variable. + (datetime_mod_CFLAGS): Likewise. + (datetime_mod_LDFLAGS): Likewise. + (date_mod_SOURCES): Likewise. + (date_mod_CFLAGS): Likewise. + (date_mod_LDFLAGS): Likewise. + (datehook_mod_SOURCES): Likewise. + (datehook_mod_CFLAGS): Likewise. + (datehook_mod_LDFLAGS): Likewise. + * conf/sparc64-ieee1275.rmk: Likewise. + * lib/ieee1275/datetime.c: New file. diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index 8622293ab..73e56e66f 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -105,4 +105,21 @@ lsmmap_mod_SOURCES = commands/lsmmap.c lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += datetime.mod date.mod datehook.mod + +# For datetime.mod +datetime_mod_SOURCES = lib/ieee1275/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For datehook.mod +datehook_mod_SOURCES = hook/datehook.c +datehook_mod_CFLAGS = $(COMMON_CFLAGS) +datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index befc7dce5..6210826e2 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -133,4 +133,21 @@ lsmmap_mod_SOURCES = commands/lsmmap.c lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += datetime.mod date.mod datehook.mod + +# For datetime.mod +datetime_mod_SOURCES = lib/ieee1275/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For datehook.mod +datehook_mod_SOURCES = hook/datehook.c +datehook_mod_CFLAGS = $(COMMON_CFLAGS) +datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk diff --git a/lib/ieee1275/datetime.c b/lib/ieee1275/datetime.c new file mode 100644 index 000000000..aaf17b0fa --- /dev/null +++ b/lib/ieee1275/datetime.c @@ -0,0 +1,142 @@ +/* kern/cmos_datetime.c - CMOS datetime function. + * + * 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 . + */ + +#include +#include +#include + +static char *rtc = 0; + +static void +find_rtc (void) +{ + auto int hook (struct grub_ieee1275_devalias *alias); + int hook (struct grub_ieee1275_devalias *alias) + { + if (grub_strcmp (alias->type, "rtc") == 0) + { + grub_dprintf ("datetime", "Found RTC %s\n", alias->name); + rtc = grub_strdup (alias->name); + return 1; + } + return 0; + } + + grub_ieee1275_devices_iterate (hook); +} + +grub_err_t +grub_get_datetime (struct grub_datetime *datetime) +{ + struct get_time_args + { + struct grub_ieee1275_common_hdr common; + grub_ieee1275_cell_t method; + grub_ieee1275_cell_t device; + grub_ieee1275_cell_t catch_result; + grub_ieee1275_cell_t year; + grub_ieee1275_cell_t month; + grub_ieee1275_cell_t day; + grub_ieee1275_cell_t hour; + grub_ieee1275_cell_t minute; + grub_ieee1275_cell_t second; + } + args; + int status; + grub_ieee1275_ihandle_t ihandle; + + if (!rtc) + find_rtc (); + if (!rtc) + return grub_error (GRUB_ERR_IO, "no RTC found"); + + status = grub_ieee1275_open (rtc, &ihandle); + if (status == -1) + return grub_error (GRUB_ERR_IO, "couldn't open RTC"); + + INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 7); + args.device = (grub_ieee1275_cell_t) ihandle; + args.method = (grub_ieee1275_cell_t) "get-time"; + + status = IEEE1275_CALL_ENTRY_FN (&args); + + grub_ieee1275_close (ihandle); + + if (status == -1) + return grub_error (GRUB_ERR_IO, "get-time failed"); + + datetime->year = args.year; + datetime->month = args.month; + datetime->day = args.day; + datetime->hour = args.hour; + datetime->minute = args.minute; + datetime->second = args.second; + + return GRUB_ERR_NONE; +} + +grub_err_t +grub_set_datetime (struct grub_datetime *datetime) +{ + struct get_time_args + { + struct grub_ieee1275_common_hdr common; + grub_ieee1275_cell_t method; + grub_ieee1275_cell_t device; + grub_ieee1275_cell_t year; + grub_ieee1275_cell_t month; + grub_ieee1275_cell_t day; + grub_ieee1275_cell_t hour; + grub_ieee1275_cell_t minute; + grub_ieee1275_cell_t second; + grub_ieee1275_cell_t catch_result; + } + args; + int status; + grub_ieee1275_ihandle_t ihandle; + + if (!rtc) + find_rtc (); + if (!rtc) + return grub_error (GRUB_ERR_IO, "no RTC found"); + + status = grub_ieee1275_open (rtc, &ihandle); + if (status == -1) + return grub_error (GRUB_ERR_IO, "couldn't open RTC"); + + INIT_IEEE1275_COMMON (&args.common, "call-method", 8, 1); + args.device = (grub_ieee1275_cell_t) ihandle; + args.method = (grub_ieee1275_cell_t) "set-time"; + + args.year = datetime->year; + args.month = datetime->month; + args.day = datetime->day; + args.hour = datetime->hour; + args.minute = datetime->minute; + args.second = datetime->second; + + status = IEEE1275_CALL_ENTRY_FN (&args); + + grub_ieee1275_close (ihandle); + + if (status == -1) + return grub_error (GRUB_ERR_IO, "set-time failed"); + + return GRUB_ERR_NONE; +} From ec0be08d40bf33e612f152d0d58324cce4800afe Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 23:49:49 +0100 Subject: [PATCH 141/237] Clean building system --- commands/lsmmap.c | 4 ++ conf/any-emu.rmk | 10 +-- conf/common.rmk | 36 +++++++++++ conf/i386-coreboot.rmk | 108 +------------------------------ conf/i386-efi.rmk | 35 +--------- conf/i386-ieee1275.rmk | 54 ++-------------- conf/i386-pc.rmk | 63 ++---------------- conf/i386-qemu.rmk | 108 ++++++++++++++++++++++++++++++- conf/i386.rmk | 25 +++++++ conf/mips-yeeloong.rmk | 13 ---- conf/mips.rmk | 20 ------ conf/powerpc-ieee1275.rmk | 44 ++----------- conf/sparc64-ieee1275.rmk | 47 +++----------- conf/x86_64-efi.rmk | 35 +--------- disk/memdisk.c | 1 - hook/datehook.c | 4 +- include/grub/datetime.h | 7 ++ include/grub/i386/efi/serial.h | 1 + include/grub/x86_64/efi/serial.h | 1 + util/time.c | 46 +++++++++++++ video/ieee1275.c | 5 +- 21 files changed, 261 insertions(+), 406 deletions(-) create mode 100644 include/grub/i386/efi/serial.h create mode 100644 include/grub/x86_64/efi/serial.h create mode 100644 util/time.c diff --git a/commands/lsmmap.c b/commands/lsmmap.c index d5eef1ce9..2755df9c4 100644 --- a/commands/lsmmap.c +++ b/commands/lsmmap.c @@ -16,7 +16,9 @@ * along with GRUB. If not, see . */ +#ifndef GRUB_MACHINE_EMU #include +#endif #include #include #include @@ -34,7 +36,9 @@ grub_cmd_lsmmap (grub_command_t cmd __attribute__ ((unused)), (long long) addr, (long long) size, type); return 0; } +#ifndef GRUB_MACHINE_EMU grub_machine_mmap_iterate (hook); +#endif return 0; } diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index a4ee9b755..ee5ab3cd4 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -12,12 +12,12 @@ pkglib_PROGRAMS = kernel.img kernel_img_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \ kern/err.c kern/list.c kern/handler.c \ kern/command.c kern/corecmd.c kern/file.c \ - kern/fs.c commands/boot.c kern/main.c kern/misc.c kern/parser.c \ + kern/fs.c kern/main.c kern/misc.c kern/parser.c \ kern/partition.c kern/term.c \ kern/rescue_reader.c kern/rescue_parser.c \ \ util/console.c util/grub-emu.c util/misc.c \ - util/hostdisk.c util/getroot.c \ + util/hostdisk.c util/getroot.c util/time.c \ \ grub_emu_init.c gnulib/progname.c util/hostfs.c disk/host.c kernel_img_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-undef -I$(srcdir)/gnulib @@ -25,12 +25,6 @@ kernel_img_LDFLAGS = $(COMMON_LDFLAGS) TARGET_NO_STRIP = yes TARGET_NO_DYNAMIC_MODULES = yes -# For reboot.mod. -pkglib_MODULES += reboot.mod -reboot_mod_SOURCES = commands/reboot.c -reboot_mod_CFLAGS = $(COMMON_CFLAGS) -reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For halt.mod. pkglib_MODULES += halt.mod halt_mod_SOURCES = commands/halt.c diff --git a/conf/common.rmk b/conf/common.rmk index 6cce36395..f3c85d971 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -759,6 +759,42 @@ password_pbkdf2_mod_SOURCES = commands/password_pbkdf2.c password_pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS) password_pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For memdisk.mod. +pkglib_MODULES += memdisk.mod +memdisk_mod_SOURCES = disk/memdisk.c +memdisk_mod_CFLAGS = $(COMMON_CFLAGS) +memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For reboot.mod. +pkglib_MODULES += reboot.mod +reboot_mod_SOURCES = commands/reboot.c +reboot_mod_CFLAGS = $(COMMON_CFLAGS) +reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +pkglib_MODULES += date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For datehook.mod +pkglib_MODULES += datehook.mod +datehook_mod_SOURCES = hook/datehook.c +datehook_mod_CFLAGS = $(COMMON_CFLAGS) +datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For lsmmap.mod +pkglib_MODULES += lsmmap.mod +lsmmap_mod_SOURCES = commands/lsmmap.c +lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) +lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For boot.mod. +pkglib_MODULES += boot.mod +boot_mod_SOURCES = commands/boot.c lib/i386/pc/biosnum.c +boot_mod_CFLAGS = $(COMMON_CFLAGS) +boot_mod_LDFLAGS = $(COMMON_LDFLAGS) + bin_UTILITIES += grub-mkpasswd-pbkdf2 grub_mkpasswd_pbkdf2_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c grub_mkpasswd_pbkdf2_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap -DGRUB_MKPASSWD=1 diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index 9563c0b2b..85407b47e 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -11,8 +11,6 @@ script/lexer.c_DEPENDENCIES = grub_script.tab.h GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200 -ifeq ($(platform), coreboot) - pkglib_PROGRAMS += kernel.img kernel_img_SOURCES = kern/i386/coreboot/startup.S \ kern/i386/misc.S \ @@ -41,55 +39,6 @@ kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,$(GRUB_KERNEL_MACHINE_LINK_ADDR),-Bstatic -endif - -ifeq ($(platform), qemu) - -GRUB_BOOT_MACHINE_LINK_ADDR = 0xffe00 - -pkglib_IMAGES += boot.img -boot_img_SOURCES = boot/i386/qemu/boot.S -boot_img_ASFLAGS = $(COMMON_ASFLAGS) -DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR) -boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_BOOT_MACHINE_LINK_ADDR) -boot_img_FORMAT = binary - -bin_UTILITIES += grub-mkimage -grub_mkimage_SOURCES = util/grub-mkrawimage.c util/misc.c \ - util/resolve.c gnulib/progname.c -grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR) -util/grub-mkrawimage.c_DEPENDENCIES = Makefile - - -pkglib_IMAGES += kernel.img -kernel_img_SOURCES = kern/i386/qemu/startup.S \ - kern/i386/misc.S \ - kern/i386/coreboot/init.c \ - kern/i386/qemu/mmap.c \ - kern/i386/halt.c \ - kern/main.c kern/device.c \ - kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ - kern/misc.c kern/mm.c kern/term.c \ - kern/rescue_parser.c kern/rescue_reader.c \ - kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ - kern/$(target_cpu)/dl.c kern/parser.c kern/partition.c \ - kern/i386/tsc.c kern/i386/pit.c \ - kern/generic/rtc_get_time_ms.c \ - kern/generic/millisleep.c \ - kern/env.c \ - term/i386/pc/vga_text.c term/i386/vga_common.c \ - symlist.c -kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ - env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ - machine/boot.h machine/console.h machine/init.h \ - machine/memory.h machine/loader.h list.h handler.h command.h i18n.h \ - env_private.h -kernel_img_CFLAGS = $(COMMON_CFLAGS) -DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR) -kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR) -kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) -kernel_img_FORMAT = binary -endif - MOSTLYCLEANFILES += symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst @@ -106,17 +55,7 @@ bin_SCRIPTS += grub-mkrescue grub_mkrescue_SOURCES = util/grub-mkrescue.in # Modules. -pkglib_MODULES = linux.mod \ - aout.mod play.mod serial.mod \ - memdisk.mod pci.mod lspci.mod reboot.mod \ - halt.mod datetime.mod date.mod datehook.mod \ - lsmmap.mod mmap.mod - -# For boot.mod. -pkglib_MODULES += boot.mod -boot_mod_SOURCES = commands/boot.c -boot_mod_CFLAGS = $(COMMON_CFLAGS) -boot_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES = linux.mod aout.mod halt.mod datetime.mod mmap.mod # For mmap.mod. mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c @@ -129,21 +68,11 @@ linux_mod_SOURCES = loader/i386/linux.c linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For reboot.mod. -reboot_mod_SOURCES = commands/reboot.c -reboot_mod_CFLAGS = $(COMMON_CFLAGS) -reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For halt.mod. halt_mod_SOURCES = commands/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For serial.mod. -serial_mod_SOURCES = term/serial.c -serial_mod_CFLAGS = $(COMMON_CFLAGS) -serial_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For aout.mod. aout_mod_SOURCES = loader/aout.c aout_mod_CFLAGS = $(COMMON_CFLAGS) @@ -156,45 +85,10 @@ bsd_mod_CFLAGS = $(COMMON_CFLAGS) bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) bsd_mod_ASFLAGS = $(COMMON_ASFLAGS) -# For play.mod. -play_mod_SOURCES = commands/i386/pc/play.c -play_mod_CFLAGS = $(COMMON_CFLAGS) -play_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For memdisk.mod. -memdisk_mod_SOURCES = disk/memdisk.c -memdisk_mod_CFLAGS = $(COMMON_CFLAGS) -memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For pci.mod -pci_mod_SOURCES = bus/pci.c -pci_mod_CFLAGS = $(COMMON_CFLAGS) -pci_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For lspci.mod -lspci_mod_SOURCES = commands/lspci.c -lspci_mod_CFLAGS = $(COMMON_CFLAGS) -lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For datetime.mod datetime_mod_SOURCES = lib/cmos_datetime.c datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For date.mod -date_mod_SOURCES = commands/date.c -date_mod_CFLAGS = $(COMMON_CFLAGS) -date_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For datehook.mod -datehook_mod_SOURCES = hook/datehook.c -datehook_mod_CFLAGS = $(COMMON_CFLAGS) -datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For lsmmap.mod -lsmmap_mod_SOURCES = commands/lsmmap.c -lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) -lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - include $(srcdir)/conf/i386.mk include $(srcdir)/conf/common.mk diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index c03abb429..345350406 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -32,8 +32,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_PROGRAMS = kernel.img pkglib_MODULES = chain.mod appleldr.mod \ - linux.mod halt.mod reboot.mod pci.mod lspci.mod \ - datetime.mod date.mod datehook.mod loadbios.mod \ + linux.mod halt.mod \ + datetime.mod loadbios.mod \ fixvideo.mod mmap.mod acpi.mod # For kernel.img. @@ -68,12 +68,6 @@ symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist. kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) -# For boot.mod. -pkglib_MODULES += boot.mod -boot_mod_SOURCES = commands/boot.c -boot_mod_CFLAGS = $(COMMON_CFLAGS) -boot_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For acpi.mod. acpi_mod_SOURCES = commands/acpi.c commands/efi/acpi.c acpi_mod_CFLAGS = $(COMMON_CFLAGS) @@ -105,36 +99,11 @@ halt_mod_SOURCES = commands/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For reboot.mod. -reboot_mod_SOURCES = commands/reboot.c -reboot_mod_CFLAGS = $(COMMON_CFLAGS) -reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For pci.mod -pci_mod_SOURCES = bus/pci.c -pci_mod_CFLAGS = $(COMMON_CFLAGS) -pci_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For lspci.mod -lspci_mod_SOURCES = commands/lspci.c -lspci_mod_CFLAGS = $(COMMON_CFLAGS) -lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For datetime.mod datetime_mod_SOURCES = lib/efi/datetime.c datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For date.mod -date_mod_SOURCES = commands/date.c -date_mod_CFLAGS = $(COMMON_CFLAGS) -date_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For datehook.mod -datehook_mod_SOURCES = hook/datehook.c -datehook_mod_CFLAGS = $(COMMON_CFLAGS) -datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For loadbios.mod loadbios_mod_SOURCES = commands/efi/loadbios.c loadbios_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index e19f6e9a1..6e5fd3055 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -54,16 +54,10 @@ sbin_SCRIPTS = grub-install grub_install_SOURCES = util/ieee1275/grub-install.in # Modules. -pkglib_MODULES = halt.mod reboot.mod suspend.mod \ - aout.mod serial.mod linux.mod \ - nand.mod memdisk.mod pci.mod lspci.mod datetime.mod \ - date.mod datehook.mod lsmmap.mod mmap.mod - -# For boot.mod. -pkglib_MODULES += boot.mod -boot_mod_SOURCES = commands/boot.c -boot_mod_CFLAGS = $(COMMON_CFLAGS) -boot_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES = halt.mod suspend.mod \ + aout.mod linux.mod \ + nand.mod datetime.mod \ + mmap.mod # For mmap.mod. mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c @@ -81,21 +75,11 @@ suspend_mod_SOURCES = commands/ieee1275/suspend.c suspend_mod_CFLAGS = $(COMMON_CFLAGS) suspend_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For reboot.mod -reboot_mod_SOURCES = commands/reboot.c -reboot_mod_CFLAGS = $(COMMON_CFLAGS) -reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For halt.mod halt_mod_SOURCES = commands/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For serial.mod. -serial_mod_SOURCES = term/serial.c -serial_mod_CFLAGS = $(COMMON_CFLAGS) -serial_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For linux.mod. linux_mod_SOURCES = loader/i386/ieee1275/linux.c linux_mod_CFLAGS = $(COMMON_CFLAGS) @@ -106,40 +90,10 @@ nand_mod_SOURCES = disk/ieee1275/nand.c nand_mod_CFLAGS = $(COMMON_CFLAGS) nand_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For memdisk.mod. -memdisk_mod_SOURCES = disk/memdisk.c -memdisk_mod_CFLAGS = $(COMMON_CFLAGS) -memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For pci.mod -pci_mod_SOURCES = bus/pci.c -pci_mod_CFLAGS = $(COMMON_CFLAGS) -pci_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For lspci.mod -lspci_mod_SOURCES = commands/lspci.c -lspci_mod_CFLAGS = $(COMMON_CFLAGS) -lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For datetime.mod datetime_mod_SOURCES = lib/cmos_datetime.c datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For date.mod -date_mod_SOURCES = commands/date.c -date_mod_CFLAGS = $(COMMON_CFLAGS) -date_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For datehook.mod -datehook_mod_SOURCES = hook/datehook.c -datehook_mod_CFLAGS = $(COMMON_CFLAGS) -datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For lsmmap.mod -lsmmap_mod_SOURCES = commands/lsmmap.c -lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) -lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - include $(srcdir)/conf/i386.mk include $(srcdir)/conf/common.mk diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 580bfea0a..b30863812 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -107,7 +107,7 @@ grub_setup_SOURCES = gnulib/progname.c \ partmap/msdos.c partmap/gpt.c \ \ disk/raid.c disk/mdraid_linux.c disk/lvm.c \ - util/raid.c util/lvm.c \ + util/raid.c util/lvm.c \ grub_setup_init.c sbin_SCRIPTS += grub-install @@ -117,20 +117,14 @@ bin_SCRIPTS += grub-mkrescue grub_mkrescue_SOURCES = util/grub-mkrescue.in pkglib_MODULES = biosdisk.mod chain.mod \ - reboot.mod halt.mod \ - vbe.mod vbetest.mod vbeinfo.mod play.mod serial.mod \ - vga.mod memdisk.mod pci.mod lspci.mod \ - aout.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \ - datehook.mod lsmmap.mod ata_pthru.mod hdparm.mod \ + halt.mod \ + vbe.mod vbetest.mod vbeinfo.mod \ + vga.mod \ + aout.mod bsd.mod pxe.mod pxecmd.mod datetime.mod \ + ata_pthru.mod hdparm.mod \ usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod \ efiemu.mod mmap.mod acpi.mod drivemap.mod -# For boot.mod. -pkglib_MODULES += boot.mod -boot_mod_SOURCES = commands/boot.c lib/i386/pc/biosnum.c -boot_mod_CFLAGS = $(COMMON_CFLAGS) -boot_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For drivemap.mod. drivemap_mod_SOURCES = commands/i386/pc/drivemap.c \ commands/i386/pc/drivemap_int13h.S @@ -187,21 +181,11 @@ xnu_mod_CFLAGS = $(COMMON_CFLAGS) xnu_mod_LDFLAGS = $(COMMON_LDFLAGS) xnu_mod_ASFLAGS = $(COMMON_ASFLAGS) -# For reboot.mod. -reboot_mod_SOURCES = commands/reboot.c -reboot_mod_CFLAGS = $(COMMON_CFLAGS) -reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For halt.mod. halt_mod_SOURCES = commands/i386/pc/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For serial.mod. -serial_mod_SOURCES = term/serial.c -serial_mod_CFLAGS = $(COMMON_CFLAGS) -serial_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For vbe.mod. vbe_mod_SOURCES = video/i386/pc/vbe.c vbe_mod_CFLAGS = $(COMMON_CFLAGS) @@ -217,31 +201,11 @@ vbetest_mod_SOURCES = commands/i386/pc/vbetest.c vbetest_mod_CFLAGS = $(COMMON_CFLAGS) vbetest_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For play.mod. -play_mod_SOURCES = commands/i386/pc/play.c -play_mod_CFLAGS = $(COMMON_CFLAGS) -play_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For vga.mod. vga_mod_SOURCES = term/i386/pc/vga.c vga_mod_CFLAGS = $(COMMON_CFLAGS) vga_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For memdisk.mod. -memdisk_mod_SOURCES = disk/memdisk.c -memdisk_mod_CFLAGS = $(COMMON_CFLAGS) -memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For pci.mod -pci_mod_SOURCES = bus/pci.c -pci_mod_CFLAGS = $(COMMON_CFLAGS) -pci_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For lspci.mod -lspci_mod_SOURCES = commands/lspci.c -lspci_mod_CFLAGS = $(COMMON_CFLAGS) -lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For aout.mod aout_mod_SOURCES = loader/aout.c aout_mod_CFLAGS = $(COMMON_CFLAGS) @@ -298,21 +262,6 @@ datetime_mod_SOURCES = lib/cmos_datetime.c datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For date.mod -date_mod_SOURCES = commands/date.c -date_mod_CFLAGS = $(COMMON_CFLAGS) -date_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For datehook.mod -datehook_mod_SOURCES = hook/datehook.c -datehook_mod_CFLAGS = $(COMMON_CFLAGS) -datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For lsmmap.mod -lsmmap_mod_SOURCES = commands/lsmmap.c -lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) -lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For ata_pthru.mod. ata_pthru_mod_SOURCES = disk/ata_pthru.c ata_pthru_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/i386-qemu.rmk b/conf/i386-qemu.rmk index 573a5d0f3..17e4f1129 100644 --- a/conf/i386-qemu.rmk +++ b/conf/i386-qemu.rmk @@ -1,2 +1,108 @@ # -*- makefile -*- -include $(srcdir)/conf/i386-coreboot.mk + +COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 +COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 +COMMON_LDFLAGS = -m32 -nostdlib + +# Used by various components. These rules need to precede them. +script/lexer.c_DEPENDENCIES = grub_script.tab.h + +# Images. + +GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200 +GRUB_BOOT_MACHINE_LINK_ADDR = 0xffe00 + +pkglib_IMAGES += boot.img +boot_img_SOURCES = boot/i386/qemu/boot.S +boot_img_ASFLAGS = $(COMMON_ASFLAGS) -DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR) +boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_BOOT_MACHINE_LINK_ADDR) +boot_img_FORMAT = binary + +bin_UTILITIES += grub-mkimage +grub_mkimage_SOURCES = util/grub-mkrawimage.c util/misc.c \ + util/resolve.c gnulib/progname.c +grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR) +util/grub-mkrawimage.c_DEPENDENCIES = Makefile + +pkglib_IMAGES += kernel.img +kernel_img_SOURCES = kern/i386/qemu/startup.S \ + kern/i386/misc.S \ + kern/i386/coreboot/init.c \ + kern/i386/qemu/mmap.c \ + kern/i386/halt.c \ + kern/main.c kern/device.c \ + kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ + kern/misc.c kern/mm.c kern/term.c \ + kern/rescue_parser.c kern/rescue_reader.c \ + kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ + kern/$(target_cpu)/dl.c kern/parser.c kern/partition.c \ + kern/i386/tsc.c kern/i386/pit.c \ + kern/generic/rtc_get_time_ms.c \ + kern/generic/millisleep.c \ + kern/env.c \ + term/i386/pc/vga_text.c term/i386/vga_common.c \ + symlist.c +kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ + env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ + partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ + machine/boot.h machine/console.h machine/init.h \ + machine/memory.h machine/loader.h list.h handler.h command.h i18n.h \ + env_private.h +kernel_img_CFLAGS = $(COMMON_CFLAGS) -DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR) +kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) +kernel_img_FORMAT = binary + +MOSTLYCLEANFILES += symlist.c kernel_syms.lst +DEFSYMFILES += kernel_syms.lst + +symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh + /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) + +kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh + /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) + +sbin_SCRIPTS += grub-install +grub_install_SOURCES = util/grub-install.in + +bin_SCRIPTS += grub-mkrescue +grub_mkrescue_SOURCES = util/grub-mkrescue.in + +# Modules. +pkglib_MODULES = linux.mod aout.mod halt.mod datetime.mod mmap.mod + +# For mmap.mod. +mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c +mmap_mod_CFLAGS = $(COMMON_CFLAGS) +mmap_mod_LDFLAGS = $(COMMON_LDFLAGS) +mmap_mod_ASFLAGS = $(COMMON_ASFLAGS) + +# For linux.mod. +linux_mod_SOURCES = loader/i386/linux.c +linux_mod_CFLAGS = $(COMMON_CFLAGS) +linux_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For halt.mod. +halt_mod_SOURCES = commands/halt.c +halt_mod_CFLAGS = $(COMMON_CFLAGS) +halt_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For aout.mod. +aout_mod_SOURCES = loader/aout.c +aout_mod_CFLAGS = $(COMMON_CFLAGS) +aout_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For bsd.mod +pkglib_MODULES += bsd.mod +bsd_mod_SOURCES = loader/i386/bsd.c loader/i386/bsd32.c loader/i386/bsd64.c loader/i386/bsd_helper.S loader/i386/bsd_trampoline.S +bsd_mod_CFLAGS = $(COMMON_CFLAGS) +bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) +bsd_mod_ASFLAGS = $(COMMON_ASFLAGS) + +# For datetime.mod +datetime_mod_SOURCES = lib/cmos_datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +include $(srcdir)/conf/i386.mk +include $(srcdir)/conf/common.mk diff --git a/conf/i386.rmk b/conf/i386.rmk index d240858fe..86b6fd795 100644 --- a/conf/i386.rmk +++ b/conf/i386.rmk @@ -47,3 +47,28 @@ multiboot2_mod_SOURCES = loader/i386/multiboot.c \ multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) + +# For serial.mod. +pkglib_MODULES += serial.mod +serial_mod_SOURCES = term/serial.c +serial_mod_CFLAGS = $(COMMON_CFLAGS) +serial_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For pci.mod +pkglib_MODULES += pci.mod +pci_mod_SOURCES = bus/pci.c +pci_mod_CFLAGS = $(COMMON_CFLAGS) +pci_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For lspci.mod +pkglib_MODULES += lspci.mod +lspci_mod_SOURCES = commands/lspci.c +lspci_mod_CFLAGS = $(COMMON_CFLAGS) +lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For play.mod. +pkglib_MODULES += play.mod +play_mod_SOURCES = commands/i386/pc/play.c +play_mod_CFLAGS = $(COMMON_CFLAGS) +play_mod_LDFLAGS = $(COMMON_LDFLAGS) + diff --git a/conf/mips-yeeloong.rmk b/conf/mips-yeeloong.rmk index eb0dc9676..d5e1d1c5d 100644 --- a/conf/mips-yeeloong.rmk +++ b/conf/mips-yeeloong.rmk @@ -61,19 +61,6 @@ datetime_mod_SOURCES = lib/cmos_datetime.c datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For date.mod -pkglib_MODULES += date.mod -date_mod_SOURCES = commands/date.c -date_mod_CFLAGS = $(COMMON_CFLAGS) -date_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For datehook.mod -pkglib_MODULES += datehook.mod -datehook_mod_SOURCES = hook/datehook.c -datehook_mod_CFLAGS = $(COMMON_CFLAGS) -datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) - - sbin_SCRIPTS += grub-install grub_install_SOURCES = util/grub-install.in diff --git a/conf/mips.rmk b/conf/mips.rmk index 1ef4fc395..e04b0adf2 100644 --- a/conf/mips.rmk +++ b/conf/mips.rmk @@ -40,26 +40,6 @@ grub_mkimage_SOURCES = gnulib/progname.c util/grub-mkrawimage.c util/misc.c \ grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(LINK_BASE) util/grub-mkrawimage.c_DEPENDENCIES = Makefile -# Modules. -pkglib_MODULES = memdisk.mod \ - lsmmap.mod - -# For boot.mod. -pkglib_MODULES += boot.mod -boot_mod_SOURCES = commands/boot.c lib/i386/pc/biosnum.c -boot_mod_CFLAGS = $(COMMON_CFLAGS) -boot_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For memdisk.mod. -memdisk_mod_SOURCES = disk/memdisk.c -memdisk_mod_CFLAGS = $(COMMON_CFLAGS) -memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For lsmmap.mod -lsmmap_mod_SOURCES = commands/lsmmap.c -lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) -lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For serial.mod. pkglib_MODULES += serial.mod serial_mod_SOURCES = term/serial.c diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index 73e56e66f..a22c38ec1 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -57,69 +57,33 @@ grub_install_SOURCES = util/ieee1275/grub-install.in grub_mkrescue_SOURCES = util/powerpc/ieee1275/grub-mkrescue.in # Modules. -pkglib_MODULES = halt.mod \ - linux.mod \ - reboot.mod \ - suspend.mod \ - memdisk.mod \ - lsmmap.mod - -# For boot.mod. -pkglib_MODULES += boot.mod -boot_mod_SOURCES = commands/boot.c lib/i386/pc/biosnum.c -boot_mod_CFLAGS = $(COMMON_CFLAGS) -boot_mod_LDFLAGS = $(COMMON_LDFLAGS) - pkglib_MODULES += ieee1275_fb.mod ieee1275_fb_mod_SOURCES = video/ieee1275.c ieee1275_fb_mod_CFLAGS = $(COMMON_CFLAGS) ieee1275_fb_mod_LDFLAGS = $(COMMON_LDFLAGS) # For linux.mod. +pkglib_MODULES += linux.mod linux_mod_SOURCES = loader/powerpc/ieee1275/linux.c linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_LDFLAGS = $(COMMON_LDFLAGS) # For suspend.mod +pkglib_MODULES += suspend.mod suspend_mod_SOURCES = commands/ieee1275/suspend.c suspend_mod_CFLAGS = $(COMMON_CFLAGS) suspend_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For reboot.mod -reboot_mod_SOURCES = commands/reboot.c -reboot_mod_CFLAGS = $(COMMON_CFLAGS) -reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For halt.mod +pkglib_MODULES += halt.mod halt_mod_SOURCES = commands/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For memdisk.mod. -memdisk_mod_SOURCES = disk/memdisk.c -memdisk_mod_CFLAGS = $(COMMON_CFLAGS) -memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For lsmmap.mod -lsmmap_mod_SOURCES = commands/lsmmap.c -lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) -lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - -pkglib_MODULES += datetime.mod date.mod datehook.mod - # For datetime.mod +pkglib_MODULES += datetime.mod datetime_mod_SOURCES = lib/ieee1275/datetime.c datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For date.mod -date_mod_SOURCES = commands/date.c -date_mod_CFLAGS = $(COMMON_CFLAGS) -date_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For datehook.mod -datehook_mod_SOURCES = hook/datehook.c -datehook_mod_CFLAGS = $(COMMON_CFLAGS) -datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) - include $(srcdir)/conf/common.mk diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index 6210826e2..69ed325b2 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -82,7 +82,7 @@ grub_setup_SOURCES = util/sparc64/ieee1275/grub-setup.c util/hostdisk.c \ partmap/sun.c partmap/acorn.c \ \ disk/raid.c disk/mdraid_linux.c disk/lvm.c \ - util/raid.c util/lvm.c gnulib/progname.c \ + util/raid.c util/lvm.c gnulib/progname.c \ grub_setup_init.c # For grub-ofpathname. @@ -96,58 +96,27 @@ sbin_SCRIPTS = grub-install grub_install_SOURCES = util/grub-install.in # Modules. -pkglib_MODULES = halt.mod \ - linux.mod \ - reboot.mod \ - memdisk.mod \ - lsmmap.mod - -# For boot.mod. -pkglib_MODULES += boot.mod -boot_mod_SOURCES = commands/boot.c lib/i386/pc/biosnum.c -boot_mod_CFLAGS = $(COMMON_CFLAGS) -boot_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += ieee1275_fb.mod +ieee1275_fb_mod_SOURCES = video/ieee1275.c +ieee1275_fb_mod_CFLAGS = $(COMMON_CFLAGS) +ieee1275_fb_mod_LDFLAGS = $(COMMON_LDFLAGS) # For linux.mod. +pkglib_MODULES += linux.mod linux_mod_SOURCES = loader/sparc64/ieee1275/linux.c linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For reboot.mod. -reboot_mod_SOURCES = commands/reboot.c -reboot_mod_CFLAGS = $(COMMON_CFLAGS) -reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For halt.mod. +pkglib_MODULES += halt.mod halt_mod_SOURCES = commands/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For memdisk.mod. -memdisk_mod_SOURCES = disk/memdisk.c -memdisk_mod_CFLAGS = $(COMMON_CFLAGS) -memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For lsmmap.mod -lsmmap_mod_SOURCES = commands/lsmmap.c -lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) -lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - -pkglib_MODULES += datetime.mod date.mod datehook.mod - # For datetime.mod +pkglib_MODULES += datetime.mod datetime_mod_SOURCES = lib/ieee1275/datetime.c datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For date.mod -date_mod_SOURCES = commands/date.c -date_mod_CFLAGS = $(COMMON_CFLAGS) -date_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For datehook.mod -datehook_mod_SOURCES = hook/datehook.c -datehook_mod_CFLAGS = $(COMMON_CFLAGS) -datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) - include $(srcdir)/conf/common.mk diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index d5c3c24cb..4116894f4 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -31,8 +31,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_PROGRAMS = kernel.img pkglib_MODULES = chain.mod appleldr.mod \ - halt.mod reboot.mod linux.mod pci.mod lspci.mod \ - datetime.mod date.mod datehook.mod loadbios.mod \ + halt.mod linux.mod \ + datetime.mod loadbios.mod \ fixvideo.mod mmap.mod acpi.mod # For kernel.img. @@ -67,12 +67,6 @@ symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist. kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) -# For boot.mod. -pkglib_MODULES += boot.mod -boot_mod_SOURCES = commands/boot.c lib/i386/pc/biosnum.c -boot_mod_CFLAGS = $(COMMON_CFLAGS) -boot_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For acpi.mod. acpi_mod_SOURCES = commands/acpi.c commands/efi/acpi.c acpi_mod_CFLAGS = $(COMMON_CFLAGS) @@ -105,36 +99,11 @@ halt_mod_SOURCES = commands/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For reboot.mod. -reboot_mod_SOURCES = commands/reboot.c -reboot_mod_CFLAGS = $(COMMON_CFLAGS) -reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For pci.mod -pci_mod_SOURCES = bus/pci.c -pci_mod_CFLAGS = $(COMMON_CFLAGS) -pci_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For lspci.mod -lspci_mod_SOURCES = commands/lspci.c -lspci_mod_CFLAGS = $(COMMON_CFLAGS) -lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For datetime.mod datetime_mod_SOURCES = lib/efi/datetime.c datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For date.mod -date_mod_SOURCES = commands/date.c -date_mod_CFLAGS = $(COMMON_CFLAGS) -date_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For datehook.mod -datehook_mod_SOURCES = hook/datehook.c -datehook_mod_CFLAGS = $(COMMON_CFLAGS) -datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For loadbios.mod loadbios_mod_SOURCES = commands/efi/loadbios.c loadbios_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/disk/memdisk.c b/disk/memdisk.c index 4a0470837..2e8885020 100644 --- a/disk/memdisk.c +++ b/disk/memdisk.c @@ -23,7 +23,6 @@ #include #include #include -#include static char *memdisk_addr; static grub_off_t memdisk_size = 0; diff --git a/hook/datehook.c b/hook/datehook.c index 4876e1198..9b5b54bf3 100644 --- a/hook/datehook.c +++ b/hook/datehook.c @@ -84,7 +84,7 @@ grub_read_hook_datetime (struct grub_env_var *var, return buf; } -GRUB_MOD_INIT(datetime) +GRUB_MOD_INIT(datehook) { int i; @@ -93,7 +93,7 @@ GRUB_MOD_INIT(datetime) grub_read_hook_datetime, 0); } -GRUB_MOD_FINI(datetime) +GRUB_MOD_FINI(datehook) { int i; diff --git a/include/grub/datetime.h b/include/grub/datetime.h index 2dbba55e2..e721e89af 100644 --- a/include/grub/datetime.h +++ b/include/grub/datetime.h @@ -33,10 +33,17 @@ struct grub_datetime }; /* Return date and time. */ +#ifdef GRUB_MACHINE_EMU +grub_err_t EXPORT_FUNC(grub_get_datetime) (struct grub_datetime *datetime); + +/* Set date and time. */ +grub_err_t EXPORT_FUNC(grub_set_datetime) (struct grub_datetime *datetime); +#else grub_err_t grub_get_datetime (struct grub_datetime *datetime); /* Set date and time. */ grub_err_t grub_set_datetime (struct grub_datetime *datetime); +#endif int grub_get_weekday (struct grub_datetime *datetime); char *grub_get_weekday_name (struct grub_datetime *datetime); diff --git a/include/grub/i386/efi/serial.h b/include/grub/i386/efi/serial.h new file mode 100644 index 000000000..2d8563414 --- /dev/null +++ b/include/grub/i386/efi/serial.h @@ -0,0 +1 @@ +#include diff --git a/include/grub/x86_64/efi/serial.h b/include/grub/x86_64/efi/serial.h new file mode 100644 index 000000000..2d8563414 --- /dev/null +++ b/include/grub/x86_64/efi/serial.h @@ -0,0 +1 @@ +#include diff --git a/util/time.c b/util/time.c new file mode 100644 index 000000000..5da8092a9 --- /dev/null +++ b/util/time.c @@ -0,0 +1,46 @@ +/* + * 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 + +grub_err_t +grub_get_datetime (struct grub_datetime *datetime) +{ + struct tm *mytm; + time_t mytime; + + mytime = time (&mytime); + mytm = gmtime (&mytime); + + datetime->year = mytm->tm_year + 1900; + datetime->month = mytm->tm_mon + 1; + datetime->day = mytm->tm_mday; + datetime->hour = mytm->tm_hour; + datetime->minute = mytm->tm_min; + datetime->second = mytm->tm_sec; + + return GRUB_ERR_NONE; +} + +grub_err_t +grub_set_datetime (struct grub_datetime *datetime __attribute__ ((unused))) +{ + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "no clock setting routine available"); +} diff --git a/video/ieee1275.c b/video/ieee1275.c index 21b65bd32..0cf47a1a8 100644 --- a/video/ieee1275.c +++ b/video/ieee1275.c @@ -124,7 +124,8 @@ grub_video_ieee1275_setup (unsigned int width, unsigned int height, unsigned int mode_type __attribute__ ((unused)), unsigned int mode_mask __attribute__ ((unused))) { - grub_uint32_t current_width, current_height, address; + grub_uint32_t current_width, current_height; + grub_addr_t address; grub_err_t err; grub_ieee1275_phandle_t dev; @@ -162,7 +163,7 @@ grub_video_ieee1275_setup (unsigned int width, unsigned int height, return err; } - if (grub_ieee1275_get_integer_property (dev, "address", &address, + if (grub_ieee1275_get_integer_property (dev, "address", (void *) &address, sizeof (address), 0)) return grub_error (GRUB_ERR_IO, "Couldn't retrieve display address."); From 660960d6972a1ea59f2fb23fbadd2529b5a72620 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 9 Feb 2010 14:09:08 +0100 Subject: [PATCH 142/237] 2010-02-09 Vladimir Serbinenko * configure.ac: Check for ft2build.h. --- ChangeLog | 4 ++++ configure.ac | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index ff8f3d41c..793018ca9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-09 Vladimir Serbinenko + + * configure.ac: Check for ft2build.h. + 2010-02-07 Vladimir Serbinenko * kern/ieee1275/openfw.c (grub_halt): Try executing "poweroff". diff --git a/configure.ac b/configure.ac index b4323e24f..48702afd6 100644 --- a/configure.ac +++ b/configure.ac @@ -679,6 +679,16 @@ if test x"$grub_mkfont_excuse" = x ; then freetype_cflags=`freetype-config --cflags` freetype_libs=`freetype-config --libs` fi + +if test x"$grub_mkfont_excuse" = x ; then + # Check for freetype libraries. + SAVED_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $freetype_cflags" + AC_CHECK_HEADERS([ft2build.h], [], + [grub_mkfont_excuse=["need freetype2 headers"]]) + CFLAGS="$SAVED_CFLAGS" +fi + if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then AC_MSG_ERROR([grub-mkfont was explicitly requested but can't be compiled]) fi From a3df209041d587f7dd50958bd1f8b20fae42a68f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 9 Feb 2010 21:16:17 +0100 Subject: [PATCH 143/237] Fix libusb compilation --- conf/any-emu.rmk | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index a4ee9b755..2ded20e2e 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -47,11 +47,29 @@ endif grub_emu_LDFLAGS = $(LIBCURSES) ifeq ($(enable_grub_emu_usb), yes) +pkglib_MODULES += libusb.mod +libusb_mod_SOURCES = util/usb.c +libusb_mod_CFLAGS = +libusb_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For usb.mod pkglib_MODULES += usb.mod -usb_mod_SOURCES = disk/usbms.c util/usb.c bus/usb/usb.c \ - commands/usbtest.c +usb_mod_SOURCES = bus/usb/usb.c usb_mod_CFLAGS = $(COMMON_CFLAGS) usb_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For usbtest.mod +pkglib_MODULES += usbtest.mod +usbtest_mod_SOURCES = commands/usbtest.c +usbtest_mod_CFLAGS = $(COMMON_CFLAGS) +usbtest_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For usbms.mod +pkglib_MODULES += usbms.mod +usbms_mod_SOURCES = disk/usbms.c +usbms_mod_CFLAGS = $(COMMON_CFLAGS) +usbms_mod_LDFLAGS = $(COMMON_LDFLAGS) + grub_emu_LDFLAGS += $(LIBUSB) endif From 38c95667d6e4e16aa273be18b5d405972352a23f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 10 Feb 2010 00:05:19 +0100 Subject: [PATCH 144/237] Unify efi rmk --- conf/i386-efi.rmk | 130 +---------------------------------------- conf/x86-efi.rmk | 138 ++++++++++++++++++++++++++++++++++++++++++++ conf/x86_64-efi.rmk | 130 +---------------------------------------- 3 files changed, 140 insertions(+), 258 deletions(-) create mode 100644 conf/x86-efi.rmk diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index 345350406..b6e6821f4 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -4,132 +4,4 @@ COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 COMMON_CFLAGS = -fno-builtin -m32 COMMON_LDFLAGS = -melf_i386 -nostdlib -# Used by various components. These rules need to precede them. -script/lexer.c_DEPENDENCIES = grub_script.tab.h - -# Utilities. -bin_UTILITIES = grub-mkimage - -# For grub-mkimage. -grub_mkimage_SOURCES = gnulib/progname.c util/i386/efi/grub-mkimage.c \ - util/misc.c util/resolve.c -util/i386/efi/grub-mkimage.c_DEPENDENCIES = Makefile - -# For grub-setup. -#grub_setup_SOURCES = util/i386/pc/grub-setup.c util/hostdisk.c \ -# util/misc.c util/getroot.c kern/device.c kern/disk.c \ -# kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c \ -# fs/sfs.c kern/parser.c kern/partition.c partmap/msdos.c \ -# fs/ufs.c fs/ufs2.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c \ -# kern/fs.c kern/env.c fs/fshelp.c - -# Scripts. -sbin_SCRIPTS = grub-install - -# For grub-install. -grub_install_SOURCES = util/i386/efi/grub-install.in - -# Modules. -pkglib_PROGRAMS = kernel.img -pkglib_MODULES = chain.mod appleldr.mod \ - linux.mod halt.mod \ - datetime.mod loadbios.mod \ - fixvideo.mod mmap.mod acpi.mod - -# For kernel.img. -kernel_img_RELOCATABLE = yes -kernel_img_SOURCES = kern/i386/efi/startup.S kern/main.c kern/device.c \ - kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ - kern/misc.c kern/mm.c kern/term.c \ - kern/rescue_parser.c kern/rescue_reader.c \ - kern/$(target_cpu)/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \ - kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \ - term/efi/console.c disk/efi/efidisk.c \ - kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ - kern/i386/tsc.c kern/i386/pit.c \ - kern/generic/rtc_get_time_ms.c \ - kern/generic/millisleep.c -kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ - env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ - efi/efi.h efi/time.h efi/disk.h i386/pit.h list.h handler.h command.h \ - i18n.h env_private.h -kernel_img_CFLAGS = $(COMMON_CFLAGS) -kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -kernel_img_LDFLAGS = $(COMMON_LDFLAGS) - -MOSTLYCLEANFILES += symlist.c -MOSTLYCLEANFILES += symlist.c kernel_syms.lst -DEFSYMFILES += kernel_syms.lst - -symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh - /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - -kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh - /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - -# For acpi.mod. -acpi_mod_SOURCES = commands/acpi.c commands/efi/acpi.c -acpi_mod_CFLAGS = $(COMMON_CFLAGS) -acpi_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 -mmap_mod_CFLAGS = $(COMMON_CFLAGS) -mmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For chain.mod. -chain_mod_SOURCES = loader/efi/chainloader.c -chain_mod_CFLAGS = $(COMMON_CFLAGS) -chain_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For appleldr.mod. -appleldr_mod_SOURCES = loader/efi/appleloader.c -appleldr_mod_CFLAGS = $(COMMON_CFLAGS) -appleldr_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For linux.mod. -linux_mod_SOURCES = loader/i386/efi/linux.c -linux_mod_CFLAGS = $(COMMON_CFLAGS) -linux_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For halt.mod. -halt_mod_SOURCES = commands/halt.c -halt_mod_CFLAGS = $(COMMON_CFLAGS) -halt_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For datetime.mod -datetime_mod_SOURCES = lib/efi/datetime.c -datetime_mod_CFLAGS = $(COMMON_CFLAGS) -datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For loadbios.mod -loadbios_mod_SOURCES = commands/efi/loadbios.c -loadbios_mod_CFLAGS = $(COMMON_CFLAGS) -loadbios_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For fixvideo.mod -fixvideo_mod_SOURCES = commands/efi/fixvideo.c -fixvideo_mod_CFLAGS = $(COMMON_CFLAGS) -fixvideo_mod_LDFLAGS = $(COMMON_LDFLAGS) - -pkglib_MODULES += efi_uga.mod -efi_uga_mod_SOURCES = video/efi_uga.c -efi_uga_mod_CFLAGS = $(COMMON_CFLAGS) -efi_uga_mod_LDFLAGS = $(COMMON_LDFLAGS) - -pkglib_MODULES += efi_gop.mod -efi_gop_mod_SOURCES = video/efi_gop.c -efi_gop_mod_CFLAGS = $(COMMON_CFLAGS) -efi_gop_mod_LDFLAGS = $(COMMON_LDFLAGS) - -pkglib_MODULES += xnu.mod -xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c loader/i386/efi/xnu.c \ - loader/macho32.c loader/macho64.c loader/macho.c loader/xnu.c -xnu_mod_CFLAGS = $(COMMON_CFLAGS) -xnu_mod_LDFLAGS = $(COMMON_LDFLAGS) -xnu_mod_ASFLAGS = $(COMMON_ASFLAGS) - -include $(srcdir)/conf/i386.mk -include $(srcdir)/conf/common.mk +include $(srcdir)/conf/x86-efi.mk \ No newline at end of file diff --git a/conf/x86-efi.rmk b/conf/x86-efi.rmk new file mode 100644 index 000000000..b115d174b --- /dev/null +++ b/conf/x86-efi.rmk @@ -0,0 +1,138 @@ +# -*- makefile -*- + +# Used by various components. These rules need to precede them. +script/lexer.c_DEPENDENCIES = grub_script.tab.h + +# Utilities. +bin_UTILITIES = grub-mkimage + +# For grub-mkimage. +grub_mkimage_SOURCES = gnulib/progname.c util/i386/efi/grub-mkimage.c \ + util/misc.c util/resolve.c +util/i386/efi/grub-mkimage.c_DEPENDENCIES = Makefile + +# For grub-setup. +#grub_setup_SOURCES = util/i386/pc/grub-setup.c util/hostdisk.c \ +# util/misc.c util/getroot.c kern/device.c kern/disk.c \ +# kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c \ +# fs/sfs.c kern/parser.c kern/partition.c partmap/msdos.c \ +# fs/ufs.c fs/ufs2.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c \ +# kern/fs.c kern/env.c fs/fshelp.c + +# Scripts. +sbin_SCRIPTS = grub-install + +# For grub-install. +grub_install_SOURCES = util/i386/efi/grub-install.in + +# Modules. +pkglib_PROGRAMS = kernel.img +pkglib_MODULES = chain.mod appleldr.mod \ + linux.mod halt.mod \ + datetime.mod loadbios.mod \ + fixvideo.mod mmap.mod acpi.mod + +# For kernel.img. +kernel_img_RELOCATABLE = yes +kernel_img_SOURCES = kern/$(target_cpu)/efi/startup.S kern/main.c kern/device.c \ + kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ + kern/misc.c kern/mm.c kern/term.c \ + kern/rescue_parser.c kern/rescue_reader.c \ + kern/$(target_cpu)/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \ + kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \ + term/efi/console.c disk/efi/efidisk.c \ + kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ + kern/i386/tsc.c kern/i386/pit.c \ + kern/generic/rtc_get_time_ms.c \ + kern/generic/millisleep.c +ifeq ($(target_cpu),x86_64) +kernel_img_SOURCES += kern/x86_64/efi/callwrap.S +endif +kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ + env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ + partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ + efi/efi.h efi/time.h efi/disk.h i386/pit.h list.h handler.h command.h \ + i18n.h env_private.h +kernel_img_CFLAGS = $(COMMON_CFLAGS) +kernel_img_ASFLAGS = $(COMMON_ASFLAGS) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) + +MOSTLYCLEANFILES += symlist.c +MOSTLYCLEANFILES += symlist.c kernel_syms.lst +DEFSYMFILES += kernel_syms.lst + +symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh + /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) + +kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh + /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) + +# For acpi.mod. +acpi_mod_SOURCES = commands/acpi.c commands/efi/acpi.c +acpi_mod_CFLAGS = $(COMMON_CFLAGS) +acpi_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 +mmap_mod_CFLAGS = $(COMMON_CFLAGS) +mmap_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For chain.mod. +chain_mod_SOURCES = loader/efi/chainloader.c +chain_mod_CFLAGS = $(COMMON_CFLAGS) +chain_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For appleldr.mod. +appleldr_mod_SOURCES = loader/efi/appleloader.c +appleldr_mod_CFLAGS = $(COMMON_CFLAGS) +appleldr_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For linux.mod. +linux_mod_SOURCES = loader/i386/efi/linux.c +ifeq ($(target_cpu), x86_64) +linux_mod_SOURCES += loader/i386/linux_trampoline.S +endif +linux_mod_CFLAGS = $(COMMON_CFLAGS) +linux_mod_ASFLAGS = $(COMMON_ASFLAGS) +linux_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For halt.mod. +halt_mod_SOURCES = commands/halt.c +halt_mod_CFLAGS = $(COMMON_CFLAGS) +halt_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For datetime.mod +datetime_mod_SOURCES = lib/efi/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For loadbios.mod +loadbios_mod_SOURCES = commands/efi/loadbios.c +loadbios_mod_CFLAGS = $(COMMON_CFLAGS) +loadbios_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For fixvideo.mod +fixvideo_mod_SOURCES = commands/efi/fixvideo.c +fixvideo_mod_CFLAGS = $(COMMON_CFLAGS) +fixvideo_mod_LDFLAGS = $(COMMON_LDFLAGS) + +pkglib_MODULES += efi_uga.mod +efi_uga_mod_SOURCES = video/efi_uga.c +efi_uga_mod_CFLAGS = $(COMMON_CFLAGS) +efi_uga_mod_LDFLAGS = $(COMMON_LDFLAGS) + +pkglib_MODULES += efi_gop.mod +efi_gop_mod_SOURCES = video/efi_gop.c +efi_gop_mod_CFLAGS = $(COMMON_CFLAGS) +efi_gop_mod_LDFLAGS = $(COMMON_LDFLAGS) + +pkglib_MODULES += xnu.mod +xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c loader/i386/efi/xnu.c \ + loader/macho32.c loader/macho64.c loader/macho.c loader/xnu.c +xnu_mod_CFLAGS = $(COMMON_CFLAGS) +xnu_mod_LDFLAGS = $(COMMON_LDFLAGS) +xnu_mod_ASFLAGS = $(COMMON_ASFLAGS) + +include $(srcdir)/conf/i386.mk +include $(srcdir)/conf/common.mk diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index 4116894f4..816cce34e 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -4,132 +4,4 @@ COMMON_ASFLAGS = -nostdinc -fno-builtin -m64 COMMON_CFLAGS = -fno-builtin -m64 COMMON_LDFLAGS = -melf_x86_64 -nostdlib -# Used by various components. These rules need to precede them. -script/lexer.c_DEPENDENCIES = grub_script.tab.h - -# Utilities. -bin_UTILITIES = grub-mkimage - -# For grub-mkimage. -grub_mkimage_SOURCES = gnulib/progname.c util/i386/efi/grub-mkimage.c \ - util/misc.c util/resolve.c - -# For grub-setup. -#grub_setup_SOURCES = util/i386/pc/grub-setup.c util/hostdisk.c \ -# util/misc.c util/getroot.c kern/device.c kern/disk.c \ -# kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c \ -# fs/sfs.c kern/parser.c kern/partition.c partmap/msdos.c \ -# fs/ufs.c fs/ufs2.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c \ -# kern/fs.c kern/env.c fs/fshelp.c - -# Scripts. -sbin_SCRIPTS = grub-install - -# For grub-install. -grub_install_SOURCES = util/i386/efi/grub-install.in - -# Modules. -pkglib_PROGRAMS = kernel.img -pkglib_MODULES = chain.mod appleldr.mod \ - halt.mod linux.mod \ - datetime.mod loadbios.mod \ - fixvideo.mod mmap.mod acpi.mod - -# For kernel.img. -kernel_img_RELOCATABLE = yes -kernel_img_SOURCES = kern/x86_64/efi/startup.S kern/x86_64/efi/callwrap.S \ - kern/main.c kern/device.c \ - kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ - kern/misc.c kern/mm.c kern/term.c \ - kern/rescue_parser.c kern/rescue_reader.c \ - kern/$(target_cpu)/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \ - kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \ - kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ - kern/i386/tsc.c kern/i386/pit.c \ - kern/generic/millisleep.c kern/generic/rtc_get_time_ms.c \ - term/efi/console.c disk/efi/efidisk.c -kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ - env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ - efi/efi.h efi/time.h efi/disk.h machine/loader.h i386/pit.h list.h \ - handler.h command.h i18n.h env_private.h -kernel_img_CFLAGS = $(COMMON_CFLAGS) -kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -kernel_img_LDFLAGS = $(COMMON_LDFLAGS) - -MOSTLYCLEANFILES += symlist.c -MOSTLYCLEANFILES += symlist.c kernel_syms.lst -DEFSYMFILES += kernel_syms.lst - -symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh - /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - -kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh - /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - -# For acpi.mod. -acpi_mod_SOURCES = commands/acpi.c commands/efi/acpi.c -acpi_mod_CFLAGS = $(COMMON_CFLAGS) -acpi_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 -mmap_mod_CFLAGS = $(COMMON_CFLAGS) -mmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For chain.mod. -chain_mod_SOURCES = loader/efi/chainloader.c -chain_mod_CFLAGS = $(COMMON_CFLAGS) -chain_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For appleldr.mod. -appleldr_mod_SOURCES = loader/efi/appleloader.c -appleldr_mod_CFLAGS = $(COMMON_CFLAGS) -appleldr_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For linux.mod. -linux_mod_SOURCES = loader/i386/efi/linux.c loader/i386/linux_trampoline.S -linux_mod_CFLAGS = $(COMMON_CFLAGS) -linux_mod_ASFLAGS = $(COMMON_ASFLAGS) -linux_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For halt.mod. -halt_mod_SOURCES = commands/halt.c -halt_mod_CFLAGS = $(COMMON_CFLAGS) -halt_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For datetime.mod -datetime_mod_SOURCES = lib/efi/datetime.c -datetime_mod_CFLAGS = $(COMMON_CFLAGS) -datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For loadbios.mod -loadbios_mod_SOURCES = commands/efi/loadbios.c -loadbios_mod_CFLAGS = $(COMMON_CFLAGS) -loadbios_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For fixvideo.mod -fixvideo_mod_SOURCES = commands/efi/fixvideo.c -fixvideo_mod_CFLAGS = $(COMMON_CFLAGS) -fixvideo_mod_LDFLAGS = $(COMMON_LDFLAGS) - -pkglib_MODULES += efi_uga.mod -efi_uga_mod_SOURCES = video/efi_uga.c -efi_uga_mod_CFLAGS = $(COMMON_CFLAGS) -efi_uga_mod_LDFLAGS = $(COMMON_LDFLAGS) - -pkglib_MODULES += efi_gop.mod -efi_gop_mod_SOURCES = video/efi_gop.c -efi_gop_mod_CFLAGS = $(COMMON_CFLAGS) -efi_gop_mod_LDFLAGS = $(COMMON_LDFLAGS) - -pkglib_MODULES += xnu.mod -xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c loader/i386/efi/xnu.c \ - loader/macho32.c loader/macho64.c loader/macho.c loader/xnu.c -xnu_mod_CFLAGS = $(COMMON_CFLAGS) -xnu_mod_LDFLAGS = $(COMMON_LDFLAGS) -xnu_mod_ASFLAGS = $(COMMON_ASFLAGS) - -include $(srcdir)/conf/i386.mk -include $(srcdir)/conf/common.mk +include $(srcdir)/conf/x86-efi.mk From ed4e9b07a4a3bcf2c89079e450f80bc9db5a5de7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 10 Feb 2010 00:16:28 +0100 Subject: [PATCH 145/237] unify symlist.c --- conf/common.rmk | 9 +++++++++ conf/i386-coreboot.rmk | 9 --------- conf/i386-ieee1275.rmk | 9 --------- conf/i386-pc.rmk | 9 --------- conf/i386-qemu.rmk | 9 --------- conf/mips.rmk | 10 ---------- conf/powerpc-ieee1275.rmk | 9 --------- conf/sparc64-ieee1275.rmk | 9 --------- conf/x86-efi.rmk | 10 ---------- 9 files changed, 9 insertions(+), 74 deletions(-) diff --git a/conf/common.rmk b/conf/common.rmk index f3c85d971..4133e7c97 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -100,6 +100,15 @@ grub_script_check_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.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 +MOSTLYCLEANFILES += symlist.c kernel_syms.lst +DEFSYMFILES += kernel_syms.lst + +symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh + /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) + +kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh + /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) + # 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 diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index 85407b47e..dbcba7f6b 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -39,15 +39,6 @@ kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,$(GRUB_KERNEL_MACHINE_LINK_ADDR),-Bstatic -MOSTLYCLEANFILES += symlist.c kernel_syms.lst -DEFSYMFILES += kernel_syms.lst - -symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh - /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - -kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh - /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - sbin_SCRIPTS += grub-install grub_install_SOURCES = util/grub-install.in diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index 6e5fd3055..ebcde000c 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -38,15 +38,6 @@ kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x10000,-Bstatic -MOSTLYCLEANFILES += symlist.c kernel_syms.lst -DEFSYMFILES += kernel_syms.lst - -symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh - /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - -kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh - /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - # Scripts. sbin_SCRIPTS = grub-install diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index b30863812..535c91109 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -71,15 +71,6 @@ kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) kernel_img_FORMAT = binary -MOSTLYCLEANFILES += symlist.c kernel_syms.lst -DEFSYMFILES += kernel_syms.lst - -symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh - /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - -kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh - /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - # Utilities. bin_UTILITIES = grub-mkimage sbin_UTILITIES = grub-setup diff --git a/conf/i386-qemu.rmk b/conf/i386-qemu.rmk index 17e4f1129..af150932f 100644 --- a/conf/i386-qemu.rmk +++ b/conf/i386-qemu.rmk @@ -53,15 +53,6 @@ kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KE kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) kernel_img_FORMAT = binary -MOSTLYCLEANFILES += symlist.c kernel_syms.lst -DEFSYMFILES += kernel_syms.lst - -symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh - /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - -kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh - /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - sbin_SCRIPTS += grub-install grub_install_SOURCES = util/grub-install.in diff --git a/conf/mips.rmk b/conf/mips.rmk index e04b0adf2..32d945734 100644 --- a/conf/mips.rmk +++ b/conf/mips.rmk @@ -9,10 +9,6 @@ COMMON_LDFLAGS += -nostdlib script/lexer.c_DEPENDENCIES = grub_script.tab.h # Images. - -MOSTLYCLEANFILES += symlist.c kernel_syms.lst -DEFSYMFILES += kernel_syms.lst - kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h reader.h \ symbol.h term.h time.h types.h loader.h partition.h \ @@ -23,12 +19,6 @@ ifeq ($(platform), yeeloong) kernel_img_HEADERS += pci.h endif -symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh - /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - -kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh - /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - # Scripts. sbin_SCRIPTS = bin_SCRIPTS = diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index a22c38ec1..d5d6d3bd2 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -10,21 +10,12 @@ script/lexer.c_DEPENDENCIES = grub_script.tab.h # Images. -MOSTLYCLEANFILES += symlist.c kernel_syms.lst -DEFSYMFILES += kernel_syms.lst - kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h reader.h \ symbol.h term.h time.h types.h powerpc/libgcc.h loader.h partition.h \ msdos_partition.h ieee1275/ieee1275.h machine/kernel.h handler.h list.h \ command.h i18n.h env_private.h -symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh - /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - -kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh - /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - # Programs pkglib_PROGRAMS = kernel.img diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index 69ed325b2..2668f1060 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -23,9 +23,6 @@ diskboot_img_ASFLAGS = $(COMMON_ASFLAGS) diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,0x4200 diskboot_img_FORMAT = binary -MOSTLYCLEANFILES += symlist.c kernel_syms.lst -DEFSYMFILES += kernel_syms.lst - kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ @@ -51,12 +48,6 @@ kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,0x200000,-Bstatic,-melf64_sparc -static-libgcc -lgcc kernel_img_FORMAT = binary -symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh - /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - -kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh - /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - # Utilities. bin_UTILITIES = grub-mkimage sbin_UTILITIES = grub-setup grub-ofpathname diff --git a/conf/x86-efi.rmk b/conf/x86-efi.rmk index b115d174b..58918e145 100644 --- a/conf/x86-efi.rmk +++ b/conf/x86-efi.rmk @@ -57,16 +57,6 @@ kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -MOSTLYCLEANFILES += symlist.c -MOSTLYCLEANFILES += symlist.c kernel_syms.lst -DEFSYMFILES += kernel_syms.lst - -symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh - /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - -kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh - /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) - # For acpi.mod. acpi_mod_SOURCES = commands/acpi.c commands/efi/acpi.c acpi_mod_CFLAGS = $(COMMON_CFLAGS) From efca454179d415fea918ee6f3d565cd5d9bb3af8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 10 Feb 2010 01:05:40 +0100 Subject: [PATCH 146/237] Merge kernel_img_HEADERS --- conf/common.rmk | 6 ++++++ conf/i386-coreboot.rmk | 6 ------ conf/i386-ieee1275.rmk | 6 +----- conf/i386-pc.rmk | 9 ++------- conf/i386-qemu.rmk | 6 ------ conf/mips-yeeloong.rmk | 1 + conf/mips.rmk | 10 +--------- conf/powerpc-ieee1275.rmk | 6 +----- conf/sparc64-ieee1275.rmk | 7 +------ conf/x86-efi.rmk | 6 +----- gensymlist.sh.in | 1 + 11 files changed, 15 insertions(+), 49 deletions(-) diff --git a/conf/common.rmk b/conf/common.rmk index 4133e7c97..b97de8e22 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -103,6 +103,12 @@ grub_script_check_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c MOSTLYCLEANFILES += symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst +kernel_img_HEADERS += boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ + env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ + partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ + machine/memory.h machine/loader.h machine/kernel.h \ + list.h handler.h command.h i18n.h env_private.h + symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index dbcba7f6b..44b80761e 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -29,12 +29,6 @@ kernel_img_SOURCES = kern/i386/coreboot/startup.S \ kern/env.c \ term/i386/pc/vga_text.c term/i386/vga_common.c \ symlist.c -kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ - env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ - machine/boot.h machine/console.h machine/init.h \ - machine/memory.h machine/loader.h list.h handler.h command.h i18n.h \ - env_private.h kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,$(GRUB_KERNEL_MACHINE_LINK_ADDR),-Bstatic diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index ebcde000c..d23ba4c0e 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -29,11 +29,7 @@ kernel_img_SOURCES = kern/i386/ieee1275/startup.S \ term/ieee1275/ofconsole.c \ disk/ieee1275/ofdisk.c \ symlist.c -kernel_img_HEADERS = cache.h device.h disk.h dl.h elf.h elfload.h \ - env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ - ieee1275/ieee1275.h machine/kernel.h machine/loader.h machine/memory.h \ - list.h handler.h command.h i18n.h env_private.h +kernel_img_HEADERS += ieee1275/ieee1275.h kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x10000,-Bstatic diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 535c91109..b620c43af 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -59,13 +59,8 @@ kernel_img_SOURCES = kern/i386/pc/startup.S \ kern/env.c \ term/i386/pc/console.c term/i386/vga_common.c \ symlist.c -kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ - env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ - machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \ - machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \ - machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h \ - i18n.h env_private.h +kernel_img_HEADERS += machine/biosdisk.h machine/vga.h machine/vbe.h \ + machine/pxe.h i386/pit.h machine/init.h kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) diff --git a/conf/i386-qemu.rmk b/conf/i386-qemu.rmk index af150932f..355870c89 100644 --- a/conf/i386-qemu.rmk +++ b/conf/i386-qemu.rmk @@ -42,12 +42,6 @@ kernel_img_SOURCES = kern/i386/qemu/startup.S \ kern/env.c \ term/i386/pc/vga_text.c term/i386/vga_common.c \ symlist.c -kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ - env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ - machine/boot.h machine/console.h machine/init.h \ - machine/memory.h machine/loader.h list.h handler.h command.h i18n.h \ - env_private.h kernel_img_CFLAGS = $(COMMON_CFLAGS) -DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) diff --git a/conf/mips-yeeloong.rmk b/conf/mips-yeeloong.rmk index d5e1d1c5d..8b6c0426a 100644 --- a/conf/mips-yeeloong.rmk +++ b/conf/mips-yeeloong.rmk @@ -24,6 +24,7 @@ kernel_img_SOURCES = kern/$(target_cpu)/startup.S \ video/bitmap_scale.c video/sm712.c bus/pci.c bus/bonito.c \ term/gfxterm.c commands/extcmd.c lib/arg.c \ symlist.c +kernel_img_HEADERS += pci.h kernel_img_CFLAGS = $(COMMON_CFLAGS) -DUSE_ASCII_FAILBACK kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \ diff --git a/conf/mips.rmk b/conf/mips.rmk index 32d945734..6948d8d66 100644 --- a/conf/mips.rmk +++ b/conf/mips.rmk @@ -9,15 +9,7 @@ COMMON_LDFLAGS += -nostdlib script/lexer.c_DEPENDENCIES = grub_script.tab.h # Images. -kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ - env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h reader.h \ - symbol.h term.h time.h types.h loader.h partition.h \ - msdos_partition.h machine/kernel.h handler.h list.h \ - command.h machine/memory.h cpu/libgcc.h cpu/cache.h i18n.h env_private.h - -ifeq ($(platform), yeeloong) -kernel_img_HEADERS += pci.h -endif +kernel_img_HEADERS += cpu/libgcc.h cpu/cache.h # Scripts. sbin_SCRIPTS = diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index d5d6d3bd2..59cde4efe 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -10,11 +10,7 @@ script/lexer.c_DEPENDENCIES = grub_script.tab.h # Images. -kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ - env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h reader.h \ - symbol.h term.h time.h types.h powerpc/libgcc.h loader.h partition.h \ - msdos_partition.h ieee1275/ieee1275.h machine/kernel.h handler.h list.h \ - command.h i18n.h env_private.h +kernel_img_HEADERS += cpu/libgcc.h ieee1275/ieee1275.h # Programs pkglib_PROGRAMS = kernel.img diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index 2668f1060..dbca42e58 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -23,12 +23,7 @@ diskboot_img_ASFLAGS = $(COMMON_ASFLAGS) diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,0x4200 diskboot_img_FORMAT = binary -kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ - env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ - list.h handler.h command.h i18n.h \ - sparc64/libgcc.h ieee1275/ieee1275.h machine/kernel.h \ - sparc64/ieee1275/ieee1275.h env_private.h +kernel_img_HEADERS += cpu/libgcc.h ieee1275/ieee1275.h cpu/ieee1275/ieee1275.h kernel_img_SOURCES = kern/sparc64/ieee1275/crt0.S kern/ieee1275/cmain.c \ kern/ieee1275/ieee1275.c kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/err.c kern/file.c kern/fs.c \ diff --git a/conf/x86-efi.rmk b/conf/x86-efi.rmk index 58918e145..94f305506 100644 --- a/conf/x86-efi.rmk +++ b/conf/x86-efi.rmk @@ -48,11 +48,7 @@ kernel_img_SOURCES = kern/$(target_cpu)/efi/startup.S kern/main.c kern/device.c ifeq ($(target_cpu),x86_64) kernel_img_SOURCES += kern/x86_64/efi/callwrap.S endif -kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ - env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ - efi/efi.h efi/time.h efi/disk.h i386/pit.h list.h handler.h command.h \ - i18n.h env_private.h +kernel_img_HEADERS += efi/efi.h efi/time.h efi/disk.h i386/pit.h kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/gensymlist.sh.in b/gensymlist.sh.in index 27fc5e61a..087d0072f 100644 --- a/gensymlist.sh.in +++ b/gensymlist.sh.in @@ -37,6 +37,7 @@ cat <. */ +#include EOF for i in $*; do From 428b0b2edd213d8c966a8afb0a91154dac514dc6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 10 Feb 2010 01:09:23 +0100 Subject: [PATCH 147/237] Unify lexer.c_DEPENDENCIES --- conf/any-emu.rmk | 3 --- conf/common.rmk | 3 +++ conf/i386-coreboot.rmk | 3 --- conf/i386-ieee1275.rmk | 3 --- conf/i386-pc.rmk | 3 --- conf/i386-qemu.rmk | 3 --- conf/mips.rmk | 3 --- conf/powerpc-ieee1275.rmk | 3 --- conf/sparc64-ieee1275.rmk | 3 --- conf/x86-efi.rmk | 3 --- 10 files changed, 3 insertions(+), 27 deletions(-) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index ee5ab3cd4..95f44844c 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -3,9 +3,6 @@ COMMON_LDFLAGS += -nostdlib COMMON_CFLAGS += -nostdinc -isystem $(shell $(TARGET_CC) -print-file-name=include) -fno-builtin -# Used by various components. These rules need to precede them. -script/lexer.c_DEPENDENCIES = grub_script.tab.h - util/grub-emu.c_DEPENDENCIES = grub_emu_init.h kernel_img_RELOCATABLE = yes pkglib_PROGRAMS = kernel.img diff --git a/conf/common.rmk b/conf/common.rmk index b97de8e22..55a430572 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -1,5 +1,8 @@ # -*- makefile -*- +# Used by various components. These rules need to precede them. +script/lexer.c_DEPENDENCIES = grub_script.tab.h + sbin_UTILITIES += grub-mkdevicemap grub_mkdevicemap_SOURCES = gnulib/progname.c util/grub-mkdevicemap.c \ util/deviceiter.c \ diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index 44b80761e..048356a53 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -4,9 +4,6 @@ COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 COMMON_LDFLAGS = -m32 -nostdlib -# Used by various components. These rules need to precede them. -script/lexer.c_DEPENDENCIES = grub_script.tab.h - # Images. GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200 diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index d23ba4c0e..c65e2f7de 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -4,9 +4,6 @@ COMMON_ASFLAGS = -m32 -nostdinc -fno-builtin COMMON_CFLAGS = -ffreestanding -mrtd -mregparm=3 COMMON_LDFLAGS = -nostdlib -# Used by various components. These rules need to precede them. -script/lexer.c_DEPENDENCIES = grub_script.tab.h - # Images. pkglib_PROGRAMS = kernel.img diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index b620c43af..57904b265 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -6,9 +6,6 @@ COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 COMMON_LDFLAGS = -m32 -nostdlib -# Used by various components. These rules need to precede them. -script/lexer.c_DEPENDENCIES = grub_script.tab.h - # Images. pkglib_IMAGES = boot.img cdboot.img diskboot.img kernel.img lnxboot.img \ pxeboot.img diff --git a/conf/i386-qemu.rmk b/conf/i386-qemu.rmk index 355870c89..c7209f348 100644 --- a/conf/i386-qemu.rmk +++ b/conf/i386-qemu.rmk @@ -4,9 +4,6 @@ COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 COMMON_LDFLAGS = -m32 -nostdlib -# Used by various components. These rules need to precede them. -script/lexer.c_DEPENDENCIES = grub_script.tab.h - # Images. GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200 diff --git a/conf/mips.rmk b/conf/mips.rmk index 6948d8d66..84eed8805 100644 --- a/conf/mips.rmk +++ b/conf/mips.rmk @@ -5,9 +5,6 @@ COMMON_ASFLAGS += -nostdinc COMMON_CFLAGS += -ffreestanding -mexplicit-relocs -mflush-func=grub_cpu_flush_cache COMMON_LDFLAGS += -nostdlib -# Used by various components. These rules need to precede them. -script/lexer.c_DEPENDENCIES = grub_script.tab.h - # Images. kernel_img_HEADERS += cpu/libgcc.h cpu/cache.h diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index 59cde4efe..ce54ca494 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -5,9 +5,6 @@ COMMON_ASFLAGS = -nostdinc -D__ASSEMBLY__ COMMON_CFLAGS = -ffreestanding COMMON_LDFLAGS += -nostdlib -# Used by various components. These rules need to precede them. -script/lexer.c_DEPENDENCIES = grub_script.tab.h - # Images. kernel_img_HEADERS += cpu/libgcc.h ieee1275/ieee1275.h diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index dbca42e58..ffa8c1e7c 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -5,9 +5,6 @@ COMMON_ASFLAGS = -nostdinc -m64 COMMON_CFLAGS = -ffreestanding -m64 -mno-app-regs COMMON_LDFLAGS = -melf64_sparc -nostdlib -mno-relax -# Used by various components. These rules need to precede them. -script/lexer.c_DEPENDENCIES = grub_script.tab.h - # Images. pkglib_IMAGES = boot.img diskboot.img kernel.img diff --git a/conf/x86-efi.rmk b/conf/x86-efi.rmk index 94f305506..b27855aa4 100644 --- a/conf/x86-efi.rmk +++ b/conf/x86-efi.rmk @@ -1,8 +1,5 @@ # -*- makefile -*- -# Used by various components. These rules need to precede them. -script/lexer.c_DEPENDENCIES = grub_script.tab.h - # Utilities. bin_UTILITIES = grub-mkimage From c395ad834ea17c3bf75cf84ae09a57806b43f718 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 10 Feb 2010 01:10:09 +0100 Subject: [PATCH 148/237] Remove leftover __ASSEMBLY__ --- conf/powerpc-ieee1275.rmk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index ce54ca494..e7668fc5d 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -1,7 +1,7 @@ # -*- makefile -*- -COMMON_ASFLAGS = -nostdinc -D__ASSEMBLY__ +COMMON_ASFLAGS = -nostdinc COMMON_CFLAGS = -ffreestanding COMMON_LDFLAGS += -nostdlib From 5c2ee77128083e2b53ec0fd4f4916322c13c0399 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 10 Feb 2010 01:39:23 +0100 Subject: [PATCH 149/237] Share common compilation flags --- Makefile.in | 8 ++++---- conf/any-emu.rmk | 1 - conf/i386-coreboot.rmk | 4 +--- conf/i386-efi.rmk | 4 +--- conf/i386-ieee1275.rmk | 4 +--- conf/i386-pc.rmk | 4 +--- conf/i386-qemu.rmk | 4 +--- conf/mips.rmk | 4 +--- conf/powerpc-ieee1275.rmk | 4 ---- conf/sparc64-ieee1275.rmk | 7 +++---- conf/x86_64-efi.rmk | 4 +--- configure.ac | 2 ++ 12 files changed, 16 insertions(+), 34 deletions(-) diff --git a/Makefile.in b/Makefile.in index 7af2df1f0..c4059e58e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -84,8 +84,8 @@ LDFLAGS = @LDFLAGS@ $(LIBS) CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/gnulib -I$(srcdir)/include -Wall -W \ -DGRUB_LIBDIR=\"$(pkglibdir)\" -DLOCALEDIR=\"$(localedir)\" TARGET_CC = @TARGET_CC@ -TARGET_CFLAGS = @TARGET_CFLAGS@ -TARGET_ASFLAGS = @TARGET_ASFLAGS@ +TARGET_CFLAGS = -ffreestanding @TARGET_CFLAGS@ +TARGET_ASFLAGS = -nostdinc -fno-builtin @TARGET_ASFLAGS@ TARGET_MODULE_FORMAT = @TARGET_MODULE_FORMAT@ TARGET_APPLE_CC = @TARGET_APPLE_CC@ OBJCONV = @OBJCONV@ @@ -93,9 +93,9 @@ TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I$(srcdir)/include -I$(builddir) -I$(buildd ifneq ($(platform), emu) TARGET_CPPFLAGS += -nostdinc -isystem $(shell $(TARGET_CC) -print-file-name=include) endif -TARGET_LDFLAGS = @TARGET_LDFLAGS@ +TARGET_LDFLAGS = -nostdlib @TARGET_LDFLAGS@ TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@ -TARGET_IMG_LDFLAGS = @TARGET_IMG_LDFLAGS@ +TARGET_IMG_LDFLAGS = -nostdlib @TARGET_IMG_LDFLAGS@ TARGET_IMG_CFLAGS = @TARGET_IMG_CFLAGS@ TARGET_OBJ2ELF = @TARGET_OBJ2ELF@ EXEEXT = @EXEEXT@ diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 95f44844c..c06e7758a 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -1,6 +1,5 @@ # -*- makefile -*- -COMMON_LDFLAGS += -nostdlib COMMON_CFLAGS += -nostdinc -isystem $(shell $(TARGET_CC) -print-file-name=include) -fno-builtin util/grub-emu.c_DEPENDENCIES = grub_emu_init.h diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index 048356a53..3cef9313f 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -1,8 +1,6 @@ # -*- makefile -*- -COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 -COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 -COMMON_LDFLAGS = -m32 -nostdlib +COMMON_CFLAGS = -mrtd -mregparm=3 # Images. diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index b6e6821f4..a92cff224 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -1,7 +1,5 @@ # -*- makefile -*- -COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 -COMMON_CFLAGS = -fno-builtin -m32 -COMMON_LDFLAGS = -melf_i386 -nostdlib +COMMON_LDFLAGS = -melf_i386 include $(srcdir)/conf/x86-efi.mk \ No newline at end of file diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index c65e2f7de..d4a459b3e 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -1,8 +1,6 @@ # -*- makefile -*- -COMMON_ASFLAGS = -m32 -nostdinc -fno-builtin -COMMON_CFLAGS = -ffreestanding -mrtd -mregparm=3 -COMMON_LDFLAGS = -nostdlib +COMMON_CFLAGS = -mrtd -mregparm=3 # Images. pkglib_PROGRAMS = kernel.img diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 57904b265..19c996543 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -2,9 +2,7 @@ GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200 -COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 -COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 -COMMON_LDFLAGS = -m32 -nostdlib +COMMON_CFLAGS = -mrtd -mregparm=3 # Images. pkglib_IMAGES = boot.img cdboot.img diskboot.img kernel.img lnxboot.img \ diff --git a/conf/i386-qemu.rmk b/conf/i386-qemu.rmk index c7209f348..97273e1ce 100644 --- a/conf/i386-qemu.rmk +++ b/conf/i386-qemu.rmk @@ -1,8 +1,6 @@ # -*- makefile -*- -COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 -COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 -COMMON_LDFLAGS = -m32 -nostdlib +COMMON_CFLAGS = -mrtd -mregparm=3 # Images. diff --git a/conf/mips.rmk b/conf/mips.rmk index 84eed8805..b43edbf69 100644 --- a/conf/mips.rmk +++ b/conf/mips.rmk @@ -1,9 +1,7 @@ # -*- makefile -*- -COMMON_ASFLAGS += -nostdinc -COMMON_CFLAGS += -ffreestanding -mexplicit-relocs -mflush-func=grub_cpu_flush_cache -COMMON_LDFLAGS += -nostdlib +COMMON_CFLAGS += -mexplicit-relocs -mflush-func=grub_cpu_flush_cache # Images. kernel_img_HEADERS += cpu/libgcc.h cpu/cache.h diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index e7668fc5d..86f6ddcb3 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -1,10 +1,6 @@ # -*- makefile -*- -COMMON_ASFLAGS = -nostdinc -COMMON_CFLAGS = -ffreestanding -COMMON_LDFLAGS += -nostdlib - # Images. kernel_img_HEADERS += cpu/libgcc.h ieee1275/ieee1275.h diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index ffa8c1e7c..507a05ab9 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -1,9 +1,8 @@ # -*- makefile -*- -COMMON_ASFLAGS = -nostdinc -m64 -COMMON_CFLAGS = -ffreestanding -m64 -mno-app-regs -COMMON_LDFLAGS = -melf64_sparc -nostdlib -mno-relax +COMMON_CFLAGS = -mno-app-regs +COMMON_LDFLAGS = -melf64_sparc -mno-relax # Images. pkglib_IMAGES = boot.img diskboot.img kernel.img @@ -37,7 +36,7 @@ kernel_img_SOURCES = kern/sparc64/ieee1275/crt0.S kern/ieee1275/cmain.c \ symlist.c kern/$(target_cpu)/cache.S kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,0x200000,-Bstatic,-melf64_sparc -static-libgcc -lgcc +kernel_img_LDFLAGS = -Wl,-N,-Ttext,0x200000,-Bstatic,-melf64_sparc -static-libgcc -lgcc kernel_img_FORMAT = binary # Utilities. diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index 816cce34e..200621280 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -1,7 +1,5 @@ # -*- makefile -*- -COMMON_ASFLAGS = -nostdinc -fno-builtin -m64 -COMMON_CFLAGS = -fno-builtin -m64 -COMMON_LDFLAGS = -melf_x86_64 -nostdlib +COMMON_LDFLAGS = -melf_x86_64 include $(srcdir)/conf/x86-efi.mk diff --git a/configure.ac b/configure.ac index f3fcd8c48..462fca225 100644 --- a/configure.ac +++ b/configure.ac @@ -353,6 +353,7 @@ AC_MSG_RESULT([$TARGET_OBJ2ELF]) if test "x$target_m32" = x1; then # Force 32-bit mode. TARGET_CFLAGS="$TARGET_CFLAGS -m32" + TARGET_ASFLAGS="$TARGET_CFLAGS -m32" TARGET_LDFLAGS="$TARGET_LDFLAGS -m32" TARGET_MODULE_FORMAT="elf32" fi @@ -360,6 +361,7 @@ fi if test "x$target_m64" = x1; then # Force 64-bit mode. TARGET_CFLAGS="$TARGET_CFLAGS -m64" + TARGET_ASFLAGS="$TARGET_ASFLAGS -m64" TARGET_LDFLAGS="$TARGET_LDFLAGS -m64" TARGET_MODULE_FORMAT="elf64" fi From 9a31b3a79763b6080327741a8f86618016c5ddbf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 10 Feb 2010 01:49:47 +0100 Subject: [PATCH 150/237] Fix yeeloong compilation --- conf/mips-yeeloong.rmk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/mips-yeeloong.rmk b/conf/mips-yeeloong.rmk index 8b6c0426a..0d57a2884 100644 --- a/conf/mips-yeeloong.rmk +++ b/conf/mips-yeeloong.rmk @@ -3,6 +3,8 @@ LINK_BASE = 0x80200000 target_machine=yeeloong COMMON_CFLAGS += -march=mips3 COMMON_ASFLAGS += -march=mips3 + +kernel_img_HEADERS += pci.h include $(srcdir)/conf/mips.mk pkglib_IMAGES = kernel.img @@ -24,7 +26,6 @@ kernel_img_SOURCES = kern/$(target_cpu)/startup.S \ video/bitmap_scale.c video/sm712.c bus/pci.c bus/bonito.c \ term/gfxterm.c commands/extcmd.c lib/arg.c \ symlist.c -kernel_img_HEADERS += pci.h kernel_img_CFLAGS = $(COMMON_CFLAGS) -DUSE_ASCII_FAILBACK kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \ @@ -64,4 +65,3 @@ datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) sbin_SCRIPTS += grub-install grub_install_SOURCES = util/grub-install.in - From 52d45a32d3d51ddd8d62c42ab374c15b0f13ac98 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 10 Feb 2010 01:50:40 +0100 Subject: [PATCH 151/237] Add missing tailing newline --- conf/i386-efi.rmk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index a92cff224..e826cb333 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -2,4 +2,4 @@ COMMON_LDFLAGS = -melf_i386 -include $(srcdir)/conf/x86-efi.mk \ No newline at end of file +include $(srcdir)/conf/x86-efi.mk From 67443b0d684a8485cdf8706b01ceac6b67180793 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 10 Feb 2010 01:51:02 +0100 Subject: [PATCH 152/237] Remove useless efi grub-setup --- conf/x86-efi.rmk | 8 -------- 1 file changed, 8 deletions(-) diff --git a/conf/x86-efi.rmk b/conf/x86-efi.rmk index b27855aa4..5cb472168 100644 --- a/conf/x86-efi.rmk +++ b/conf/x86-efi.rmk @@ -8,14 +8,6 @@ grub_mkimage_SOURCES = gnulib/progname.c util/i386/efi/grub-mkimage.c \ util/misc.c util/resolve.c util/i386/efi/grub-mkimage.c_DEPENDENCIES = Makefile -# For grub-setup. -#grub_setup_SOURCES = util/i386/pc/grub-setup.c util/hostdisk.c \ -# util/misc.c util/getroot.c kern/device.c kern/disk.c \ -# kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c \ -# fs/sfs.c kern/parser.c kern/partition.c partmap/msdos.c \ -# fs/ufs.c fs/ufs2.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c \ -# kern/fs.c kern/env.c fs/fshelp.c - # Scripts. sbin_SCRIPTS = grub-install From dd01d3970f99a644f03baa09cbd8e85618d2545d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 10 Feb 2010 18:09:44 +0100 Subject: [PATCH 153/237] 2010-02-10 Vladimir Serbinenko * script/execute.c (grub_script_execute_cmdline): Use grub_print_error to show messages instead of discarding them. Process errors after executing command and not before. Keep old method too as precaution. --- ChangeLog | 7 +++++++ script/execute.c | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 793018ca9..b3e77335b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-02-10 Vladimir Serbinenko + + * script/execute.c (grub_script_execute_cmdline): Use grub_print_error + to show messages instead of discarding them. + Process errors after executing command and not before. Keep old method + too as precaution. + 2010-02-09 Vladimir Serbinenko * configure.ac: Check for ft2build.h. diff --git a/script/execute.c b/script/execute.c index ee7e099bc..a0773c191 100644 --- a/script/execute.c +++ b/script/execute.c @@ -100,8 +100,8 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) grubcmd = grub_command_find (cmdname); if (! grubcmd) { - /* Ignore errors. */ - grub_errno = GRUB_ERR_NONE; + /* Shouldn't happen but precaution is good. */ + grub_print_error (); /* It's not a GRUB command, try all functions. */ func = grub_script_function_find (cmdname); @@ -156,6 +156,11 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) grub_free (args[i]); grub_free (args); + if (grub_errno == GRUB_ERR_TEST_FAILURE) + grub_errno = GRUB_ERR_NONE; + + grub_print_error (); + grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret); grub_env_set ("?", errnobuf); From 65a533e78a4e79b59f24b792bc7dd80c9d1afefb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 10 Feb 2010 19:53:13 +0100 Subject: [PATCH 154/237] 2010-02-10 Vladimir Serbinenko Support GRUB_GFXPAYLOAD_LINUX. * util/grub-mkconfig.in: Export GRUB_GFXPAYLOAD_LINUX. * util/grub.d/10_linux.in (linux_entry): Handle GRUB_GFXPAYLOAD_LINUX. --- ChangeLog | 7 +++++++ util/grub-mkconfig.in | 1 + util/grub.d/10_linux.in | 10 ++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b3e77335b..b4eb12a54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-02-10 Vladimir Serbinenko + + Support GRUB_GFXPAYLOAD_LINUX. + + * util/grub-mkconfig.in: Export GRUB_GFXPAYLOAD_LINUX. + * util/grub.d/10_linux.in (linux_entry): Handle GRUB_GFXPAYLOAD_LINUX. + 2010-02-10 Vladimir Serbinenko * script/execute.c (grub_script_execute_cmdline): Use grub_print_error diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index 7e667fb3e..1363f479a 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -221,6 +221,7 @@ export GRUB_DEFAULT \ GRUB_DISABLE_LINUX_RECOVERY \ GRUB_GFXMODE \ GRUB_THEME \ + GRUB_GFXPAYLOAD_LINUX \ GRUB_DISABLE_OS_PROBER if test "x${grub_cfg}" != "x"; then diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 8d5379fd6..046874ef0 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -65,9 +65,15 @@ linux_entry () # Use ELILO's generic "efifb" when it's known to be available. # FIXME: We need an interface to select vesafb in case efifb can't be used. - if grep -qx "CONFIG_FB_EFI=y" /boot/config-${version} 2> /dev/null ; then - cat << EOF + if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then + if grep -qx "CONFIG_FB_EFI=y" /boot/config-${version} 2> /dev/null ; then + cat << EOF set gfxpayload=keep +EOF + fi + else + cat << EOF + set gfxpayload=$GRUB_GFXPAYLOAD_LINUX EOF fi From 7cae4377a2cccea05d6b40a69cd8ac0ad4af4702 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 10 Feb 2010 20:27:12 +0100 Subject: [PATCH 155/237] 2010-02-10 Vladimir Serbinenko Pass SIMPLE framebuffer size in bytes and not 64K blocks. * loader/i386/efi/linux.c (grub_linux_setup_video): Don't divide by 64K. * loader/i386/linux.c (grub_linux_setup_video): Likewise. (grub_linux_boot): Divide by 64K when on VESA. --- ChangeLog | 8 ++++++++ loader/i386/efi/linux.c | 2 +- loader/i386/linux.c | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b4eb12a54..70353ec0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-02-10 Vladimir Serbinenko + + Pass SIMPLE framebuffer size in bytes and not 64K blocks. + + * loader/i386/efi/linux.c (grub_linux_setup_video): Don't divide by 64K. + * loader/i386/linux.c (grub_linux_setup_video): Likewise. + (grub_linux_boot): Divide by 64K when on VESA. + 2010-02-10 Vladimir Serbinenko Support GRUB_GFXPAYLOAD_LINUX. diff --git a/loader/i386/efi/linux.c b/loader/i386/efi/linux.c index ebaf89743..a6db22e22 100644 --- a/loader/i386/efi/linux.c +++ b/loader/i386/efi/linux.c @@ -576,7 +576,7 @@ grub_linux_setup_video (struct linux_kernel_params *params) params->lfb_line_len = line_len; params->lfb_base = fb_base; - params->lfb_size = (line_len * params->lfb_height + 65535) >> 16; + params->lfb_size = ALIGN_UP (line_len * params->lfb_height, 65536); params->red_mask_size = 8; params->red_field_pos = 16; diff --git a/loader/i386/linux.c b/loader/i386/linux.c index 630aec6f4..d3d935182 100644 --- a/loader/i386/linux.c +++ b/loader/i386/linux.c @@ -410,7 +410,7 @@ grub_linux_setup_video (struct linux_kernel_params *params) params->lfb_line_len = mode_info.pitch; params->lfb_base = (grub_size_t) framebuffer; - params->lfb_size = (params->lfb_line_len * params->lfb_height + 65535) >> 16; + params->lfb_size = ALIGN_UP (params->lfb_line_len * params->lfb_height, 65536); params->red_mask_size = mode_info.red_mask_size; params->red_field_pos = mode_info.red_field_pos; @@ -543,6 +543,8 @@ grub_linux_boot (void) /* Use generic framebuffer unless VESA is known to be supported. */ if (params->have_vga != GRUB_VIDEO_LINUX_TYPE_VESA) params->have_vga = GRUB_VIDEO_LINUX_TYPE_SIMPLE; + else + params->lfb_size >>= 16; } else { From a929c8cd1efbd4322ca6118d25fb4b0c63c77564 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Thu, 11 Feb 2010 18:49:57 +0530 Subject: [PATCH 156/237] fix off-by-one error in menuentry cmd --- ChangeLog.lexer-rewrite | 5 +++++ script/lexer.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog.lexer-rewrite b/ChangeLog.lexer-rewrite index 9b2ab9e2f..24d009d14 100644 --- a/ChangeLog.lexer-rewrite +++ b/ChangeLog.lexer-rewrite @@ -1,3 +1,8 @@ +2010-02-10 BVK Chaitanya + + * script/lexer.c (grub_script_lexer_record_stop): Fix off-by-one + bug. + 2010-01-25 BVK Chaitanya * script/yylex.l: Accept parenthesis as part of word. diff --git a/script/lexer.c b/script/lexer.c index caefdb7a7..42a570348 100644 --- a/script/lexer.c +++ b/script/lexer.c @@ -76,7 +76,7 @@ grub_script_lexer_record_stop (struct grub_parser_param *parser) while (*end && grub_isspace (*end)) end--; if (*end == '}') end--; while (*end && grub_isspace (*end)) end--; - *end = '\0'; + end[1] = '\0'; return start; } From 6bea3f8983a193bb26933556e12d5544d3aac75b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 12 Feb 2010 20:08:56 +0100 Subject: [PATCH 157/237] merge sparc grub-mkimage into grub-mkrawimage --- conf/sparc64-ieee1275.rmk | 2 +- configure.ac | 9 +- include/grub/sparc64/ieee1275/kernel.h | 2 + util/grub-mkrawimage.c | 26 ++- util/sparc64/ieee1275/grub-mkimage.c | 300 ------------------------- 5 files changed, 35 insertions(+), 304 deletions(-) delete mode 100644 util/sparc64/ieee1275/grub-mkimage.c diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index befc7dce5..6a91b40ee 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -62,7 +62,7 @@ bin_UTILITIES = grub-mkimage sbin_UTILITIES = grub-setup grub-ofpathname # For grub-mkimage. -grub_mkimage_SOURCES = util/sparc64/ieee1275/grub-mkimage.c util/misc.c \ +grub_mkimage_SOURCES = util/grub-mkrawimage.c util/misc.c \ util/resolve.c gnulib/progname.c # For grub-setup. diff --git a/configure.ac b/configure.ac index 48702afd6..b5db67b7a 100644 --- a/configure.ac +++ b/configure.ac @@ -138,9 +138,14 @@ case "$platform" in qemu) machine_CFLAGS="-DGRUB_MACHINE_QEMU=1" ;; pc) machine_CFLAGS="-DGRUB_MACHINE_PCBIOS=1" ;; emu) machine_CFLAGS="-DGRUB_MACHINE_EMU=1" ;; - yeeloong) machine_CFLAGS="-DGRUB_MACHINE_MIPS_YEELOONG=1 -DGRUB_MACHINE_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; - qemu-mips) machine_CFLAGS="-DGRUB_MACHINE_MIPS_QEMU_MIPS=1 -DGRUB_MACHINE_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; + yeeloong) machine_CFLAGS="-DGRUB_MACHINE_MIPS_YEELOONG=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; + qemu-mips) machine_CFLAGS="-DGRUB_MACHINE_MIPS_QEMU_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; esac +case "$target_cpu" in + mips) machine_CFLAGS="$machine_CFLAGS -DGRUB_MACHINE_MIPS=1" ;; + sparc64) machine_CFLAGS="$machine_CFLAGS -DGRUB_MACHINE_SPARC64=1" ;; +esac + CFLAGS="$CFLAGS $machine_CFLAGS" TARGET_ASFLAGS="$TARGET_ASFLAGS $machine_CFLAGS" TARGET_CFLAGS="$TARGET_CFLAGS $machine_CFLAGS" diff --git a/include/grub/sparc64/ieee1275/kernel.h b/include/grub/sparc64/ieee1275/kernel.h index e63e1f616..8eb1671a8 100644 --- a/include/grub/sparc64/ieee1275/kernel.h +++ b/include/grub/sparc64/ieee1275/kernel.h @@ -39,6 +39,8 @@ /* End of the data section. */ #define GRUB_KERNEL_MACHINE_DATA_END 0x114 +#define GRUB_KERNEL_MACHINE_RAW_SIZE 0 + #ifndef ASM_FILE #include diff --git a/util/grub-mkrawimage.c b/util/grub-mkrawimage.c index 2316479e9..e17446f78 100644 --- a/util/grub-mkrawimage.c +++ b/util/grub-mkrawimage.c @@ -142,7 +142,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], } for (p = path_list; p; p = p->next) - total_module_size += (grub_util_get_image_size (p->name) + total_module_size += (ALIGN_UP (grub_util_get_image_size (p->name), 4) + sizeof (struct grub_module_header)); grub_util_info ("the total module size is 0x%x", total_module_size); @@ -295,6 +295,30 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], core_img = rom_img; core_size = rom_size; + free (boot_img); + free (boot_path); + } +#elif defined (GRUB_MACHINE_SPARC64) + { + unsigned int num; + char *boot_path, *boot_img; + size_t boot_size; + + num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); + num <<= GRUB_DISK_SECTOR_BITS; + + boot_path = grub_util_get_path (dir, "diskboot.img"); + boot_size = grub_util_get_image_size (boot_path); + if (boot_size != GRUB_DISK_SECTOR_SIZE) + grub_util_error ("diskboot.img is not one sector size"); + + boot_img = grub_util_read_image (boot_path); + + *((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE + - GRUB_BOOT_MACHINE_LIST_SIZE + 8)) + = grub_host_to_target32 (num); + + grub_util_write_image (boot_img, boot_size, out); free (boot_img); free (boot_path); } diff --git a/util/sparc64/ieee1275/grub-mkimage.c b/util/sparc64/ieee1275/grub-mkimage.c deleted file mode 100644 index 6907b8d8a..000000000 --- a/util/sparc64/ieee1275/grub-mkimage.c +++ /dev/null @@ -1,300 +0,0 @@ -/* grub-mkimage.c - make a bootable image */ -/* - * GRUB -- GRand Unified Bootloader - * 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 - * 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 -#include -#include - -#include -#include -#include -#include - -#define _GNU_SOURCE 1 -#include - -#include "progname.h" - -static void -compress_kernel (char *kernel_img, size_t kernel_size, - char **core_img, size_t *core_size) -{ - /* No compression support yet. */ - grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size); - *core_img = xmalloc (kernel_size); - memcpy (*core_img, kernel_img, kernel_size); - *core_size = kernel_size; -} - -static void -generate_image (const char *dir, const char *prefix, FILE *out, char *mods[], char *memdisk_path) -{ - size_t kernel_size, total_module_size, memdisk_size, core_size, boot_size, offset; - char *kernel_path, *kernel_img, *core_img, *boot_path, *boot_img; - struct grub_util_path_list *path_list, *p; - struct grub_module_info *modinfo; - grub_addr_t module_addr; - unsigned int num; - - path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods); - - kernel_path = grub_util_get_path (dir, "kernel.img"); - kernel_size = grub_util_get_image_size (kernel_path); - - total_module_size = sizeof (struct grub_module_info); - for (p = path_list; p; p = p->next) - total_module_size += (grub_util_get_image_size (p->name) - + sizeof (struct grub_module_header)); - - memdisk_size = 0; - if (memdisk_path) - { - memdisk_size = ALIGN_UP(grub_util_get_image_size (memdisk_path), 512); - grub_util_info ("the size of memory disk is 0x%x", memdisk_size); - total_module_size += memdisk_size + sizeof (struct grub_module_header); - } - - grub_util_info ("the total module size is 0x%x", total_module_size); - - kernel_img = xmalloc (kernel_size + total_module_size); - grub_util_load_image (kernel_path, kernel_img); - - if ((GRUB_KERNEL_MACHINE_PREFIX + strlen (prefix) + 1) - > GRUB_KERNEL_MACHINE_DATA_END) - grub_util_error ("prefix too long"); - strcpy (kernel_img + GRUB_KERNEL_MACHINE_PREFIX, prefix); - - /* Fill in the grub_module_info structure. */ - modinfo = (struct grub_module_info *) (kernel_img + kernel_size); - modinfo->magic = GRUB_MODULE_MAGIC; - modinfo->offset = sizeof (struct grub_module_info); - modinfo->size = total_module_size; - - offset = kernel_size + sizeof (struct grub_module_info); - for (p = path_list; p; p = p->next) - { - struct grub_module_header *header; - size_t mod_size; - - mod_size = grub_util_get_image_size (p->name); - - header = (struct grub_module_header *) (kernel_img + offset); - header->type = OBJ_TYPE_ELF; - header->size = grub_host_to_target32 (mod_size + sizeof (*header)); - offset += sizeof (*header); - - grub_util_load_image (p->name, kernel_img + offset); - offset += mod_size; - } - - if (memdisk_path) - { - struct grub_module_header *header; - - header = (struct grub_module_header *) (kernel_img + offset); - header->type = OBJ_TYPE_MEMDISK; - header->size = grub_host_to_target32 (memdisk_size + sizeof (*header)); - offset += sizeof (*header); - - grub_util_load_image (memdisk_path, kernel_img + offset); - offset += memdisk_size; - } - - compress_kernel (kernel_img, kernel_size + total_module_size, - &core_img, &core_size); - - grub_util_info ("the core size is 0x%x", core_size); - - num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); - num <<= GRUB_DISK_SECTOR_BITS; - - boot_path = grub_util_get_path (dir, "diskboot.img"); - boot_size = grub_util_get_image_size (boot_path); - if (boot_size != GRUB_DISK_SECTOR_SIZE) - grub_util_error ("diskboot.img is not one sector size"); - - boot_img = grub_util_read_image (boot_path); - - /* sparc is a big endian architecture. */ - *((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE - - GRUB_BOOT_MACHINE_LIST_SIZE + 8)) - = grub_cpu_to_be32 (num); - - grub_util_write_image (boot_img, boot_size, out); - free (boot_img); - free (boot_path); - - module_addr = (path_list - ? (GRUB_BOOT_MACHINE_IMAGE_ADDRESS + kernel_size) - : 0); - - grub_util_info ("the first module address is 0x%x", module_addr); - - *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE)) - = grub_cpu_to_be32 (total_module_size); - *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE)) - = grub_cpu_to_be32 (kernel_size); - - /* No compression support yet. */ - *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE)) - = grub_cpu_to_be32 (0); - - grub_util_write_image (core_img, core_size, out); - free (kernel_img); - free (core_img); - free (kernel_path); - - while (path_list) - { - struct grub_util_path_list *next = path_list->next; - free ((void *) path_list->name); - free (path_list); - path_list = next; - } -} - -static struct option options[] = - { - {"directory", required_argument, 0, 'd'}, - {"prefix", required_argument, 0, 'p'}, - {"memdisk", required_argument, 0, 'm'}, - {"output", required_argument, 0, 'o'}, - {"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 [OPTION]... [MODULES]\n\ -\n\ -Make a bootable image of GRUB.\n\ -\n\ - -d, --directory=DIR use images and modules under DIR [default=%s]\n\ - -p, --prefix=DIR set grub_prefix directory [default=%s]\n\ - -m, --memdisk=FILE embed FILE as a memdisk image\n\ - -o, --output=FILE output a generated image to FILE [default=stdout]\n\ - -h, --help display this message and exit\n\ - -V, --version print version information and exit\n\ - -v, --verbose print verbose messages\n\ -\n\ -Report bugs to <%s>.\n\ -", program_name, GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); - - exit (status); -} - -int -main (int argc, char *argv[]) -{ - char *output = NULL; - char *dir = NULL; - char *prefix = NULL; - char *memdisk = NULL; - FILE *fp = stdout; - - set_program_name (argv[0]); - - grub_util_init_nls (); - - while (1) - { - int c = getopt_long (argc, argv, "d:p:m:o:hVv", options, 0); - - if (c == -1) - break; - else - switch (c) - { - case 'o': - if (output) - free (output); - output = xstrdup (optarg); - break; - - case 'd': - if (dir) - free (dir); - dir = xstrdup (optarg); - break; - - case 'm': - if (memdisk) - free (memdisk); - memdisk = xstrdup (optarg); - - if (prefix) - free (prefix); - prefix = xstrdup ("(memdisk)/boot/grub"); - break; - - case 'h': - usage (0); - break; - - case 'p': - if (prefix) - free (prefix); - prefix = xstrdup (optarg); - break; - - case 'V': - printf ("grub-mkimage (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION); - return 0; - - case 'v': - verbosity++; - break; - - default: - usage (1); - break; - } - } - - if (output) - { - fp = fopen (output, "wb"); - if (! fp) - grub_util_error ("cannot open %s", output); - } - - generate_image (dir ? : GRUB_LIBDIR, - prefix ? : DEFAULT_DIRECTORY, fp, - argv + optind, memdisk); - - fclose (fp); - - if (dir) - free (dir); - - return 0; -} From 82da2062d83a2ce5a7c7657c910a051cc47ba809 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 15:25:37 +0100 Subject: [PATCH 158/237] 2010-02-13 Vladimir Serbinenko * util/grub-mkrawimage.c (generate_image): Add forgotten ALIGN_UP. --- ChangeLog | 4 ++++ util/grub-mkrawimage.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 70353ec0c..ddbccd1be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-13 Vladimir Serbinenko + + * util/grub-mkrawimage.c (generate_image): Add forgotten ALIGN_UP. + 2010-02-10 Vladimir Serbinenko Pass SIMPLE framebuffer size in bytes and not 64K blocks. diff --git a/util/grub-mkrawimage.c b/util/grub-mkrawimage.c index 2316479e9..5e8948c27 100644 --- a/util/grub-mkrawimage.c +++ b/util/grub-mkrawimage.c @@ -142,7 +142,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], } for (p = path_list; p; p = p->next) - total_module_size += (grub_util_get_image_size (p->name) + total_module_size += (ALIGN_UP (grub_util_get_image_size (p->name), 4) + sizeof (struct grub_module_header)); grub_util_info ("the total module size is 0x%x", total_module_size); From b274d734f3c82897f7a6337b0a2d055f29421e20 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 15:40:13 +0100 Subject: [PATCH 159/237] 2010-02-13 Vladimir Serbinenko Properly create cross-endian images. * include/grub/types.h (grub_host_to_target_addr): New macro * util/grub-mkrawimage.c (generate_image): Add missing host_to_target. --- ChangeLog | 7 +++++++ include/grub/types.h | 6 ++++++ util/grub-mkrawimage.c | 14 +++++++------- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index ddbccd1be..0d84d9340 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-02-13 Vladimir Serbinenko + + Properly create cross-endian images. + + * include/grub/types.h (grub_host_to_target_addr): New macro + * util/grub-mkrawimage.c (generate_image): Add missing host_to_target. + 2010-02-13 Vladimir Serbinenko * util/grub-mkrawimage.c (generate_image): Add forgotten ALIGN_UP. diff --git a/include/grub/types.h b/include/grub/types.h index 93174b424..9eaafd0c1 100644 --- a/include/grub/types.h +++ b/include/grub/types.h @@ -223,4 +223,10 @@ static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t x) # endif #endif /* ! WORDS_BIGENDIAN */ +#if GRUB_TARGET_SIZEOF_VOID_P == 8 +# define grub_host_to_target_addr(x) grub_host_to_target64(x) +#else +# define grub_host_to_target_addr(x) grub_host_to_target32(x) +#endif + #endif /* ! GRUB_TYPES_HEADER */ diff --git a/util/grub-mkrawimage.c b/util/grub-mkrawimage.c index 5e8948c27..023854c0c 100644 --- a/util/grub-mkrawimage.c +++ b/util/grub-mkrawimage.c @@ -157,9 +157,9 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], /* Fill in the grub_module_info structure. */ modinfo = (struct grub_module_info *) (kernel_img + kernel_size); memset (modinfo, 0, sizeof (struct grub_module_info)); - modinfo->magic = GRUB_MODULE_MAGIC; - modinfo->offset = sizeof (struct grub_module_info); - modinfo->size = total_module_size; + modinfo->magic = grub_host_to_target32 (GRUB_MODULE_MAGIC); + modinfo->offset = grub_host_to_target_addr (sizeof (struct grub_module_info)); + modinfo->size = grub_host_to_target_addr (total_module_size); offset = kernel_size + sizeof (struct grub_module_info); for (p = path_list; p; p = p->next) @@ -172,7 +172,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], header = (struct grub_module_header *) (kernel_img + offset); memset (header, 0, sizeof (struct grub_module_header)); - header->type = OBJ_TYPE_ELF; + header->type = grub_host_to_target32 (OBJ_TYPE_ELF); header->size = grub_host_to_target32 (mod_size + sizeof (*header)); offset += sizeof (*header); memset (kernel_img + offset + orig_size, 0, mod_size - orig_size); @@ -187,7 +187,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], header = (struct grub_module_header *) (kernel_img + offset); memset (header, 0, sizeof (struct grub_module_header)); - header->type = OBJ_TYPE_MEMDISK; + header->type = grub_host_to_target32 (OBJ_TYPE_MEMDISK); header->size = grub_host_to_target32 (memdisk_size + sizeof (*header)); offset += sizeof (*header); @@ -201,7 +201,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], header = (struct grub_module_header *) (kernel_img + offset); memset (header, 0, sizeof (struct grub_module_header)); - header->type = OBJ_TYPE_FONT; + header->type = grub_host_to_target32 (OBJ_TYPE_FONT); header->size = grub_host_to_target32 (font_size + sizeof (*header)); offset += sizeof (*header); @@ -215,7 +215,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], header = (struct grub_module_header *) (kernel_img + offset); memset (header, 0, sizeof (struct grub_module_header)); - header->type = OBJ_TYPE_CONFIG; + header->type = grub_host_to_target32 (OBJ_TYPE_CONFIG); header->size = grub_host_to_target32 (config_size + sizeof (*header)); offset += sizeof (*header); From da278c4d348bbc0ce2c3e812282c6f82c234b08d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 15:54:27 +0100 Subject: [PATCH 160/237] 2010-02-13 Vladimir Serbinenko Properly align 64-bit targets. * util/grub-mkrawimage.c (ALIGN_ADDR): New macro. (generate_image): Use ALIGN_ADDR. --- ChangeLog | 7 +++++++ util/grub-mkrawimage.c | 12 +++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0d84d9340..9591c45a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-02-13 Vladimir Serbinenko + + Properly align 64-bit targets. + + * util/grub-mkrawimage.c (ALIGN_ADDR): New macro. + (generate_image): Use ALIGN_ADDR. + 2010-02-13 Vladimir Serbinenko Properly create cross-endian images. diff --git a/util/grub-mkrawimage.c b/util/grub-mkrawimage.c index 023854c0c..4ed29744f 100644 --- a/util/grub-mkrawimage.c +++ b/util/grub-mkrawimage.c @@ -41,6 +41,8 @@ #include "progname.h" +#define ALIGN_ADDR(x) (ALIGN_UP((x), GRUB_TARGET_SIZEOF_VOID_P)) + #ifdef ENABLE_LZMA #include @@ -129,20 +131,20 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], if (font_path) { - font_size = ALIGN_UP(grub_util_get_image_size (font_path), 4); + font_size = ALIGN_ADDR (grub_util_get_image_size (font_path)); total_module_size += font_size + sizeof (struct grub_module_header); } if (config_path) { config_size_pure = grub_util_get_image_size (config_path) + 1; - config_size = ALIGN_UP(config_size_pure, 4); + config_size = ALIGN_ADDR (config_size_pure); grub_util_info ("the size of config file is 0x%x", config_size); total_module_size += config_size + sizeof (struct grub_module_header); } for (p = path_list; p; p = p->next) - total_module_size += (ALIGN_UP (grub_util_get_image_size (p->name), 4) + total_module_size += (ALIGN_ADDR (grub_util_get_image_size (p->name)) + sizeof (struct grub_module_header)); grub_util_info ("the total module size is 0x%x", total_module_size); @@ -168,7 +170,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], size_t mod_size, orig_size; orig_size = grub_util_get_image_size (p->name); - mod_size = ALIGN_UP(orig_size, 4); + mod_size = ALIGN_ADDR (orig_size); header = (struct grub_module_header *) (kernel_img + offset); memset (header, 0, sizeof (struct grub_module_header)); @@ -339,7 +341,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], Elf32_Phdr *phdr; grub_uint32_t target_addr; - program_size = ALIGN_UP (core_size, 4); + program_size = ALIGN_ADDR (core_size); elf_img = xmalloc (program_size + sizeof (*ehdr) + sizeof (*phdr)); memset (elf_img, 0, program_size + sizeof (*ehdr) + sizeof (*phdr)); From bdca260795fdc2b58a7ca83d46a9ce97aedbd7e4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 15:57:42 +0100 Subject: [PATCH 161/237] 2010-02-13 Vladimir Serbinenko * util/grub-mkrawimage.c (main): Call set_program_name. --- ChangeLog | 4 ++++ util/grub-mkrawimage.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9591c45a9..760ac720c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-13 Vladimir Serbinenko + + * util/grub-mkrawimage.c (main): Call set_program_name. + 2010-02-13 Vladimir Serbinenko Properly align 64-bit targets. diff --git a/util/grub-mkrawimage.c b/util/grub-mkrawimage.c index 4ed29744f..83bb51c02 100644 --- a/util/grub-mkrawimage.c +++ b/util/grub-mkrawimage.c @@ -476,6 +476,8 @@ main (int argc, char *argv[]) grub_platform_image_format_t format = GRUB_PLATFORM_IMAGE_DEFAULT; #endif + set_program_name (argv[0]); + grub_util_init_nls (); while (1) From ca62070b698ab3acc91eb1594b77d404dd1c1546 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 16:13:28 +0100 Subject: [PATCH 162/237] 2010-02-13 Vladimir Serbinenko Fix over-4GiB seek on sparc64. * include/grub/ieee1275/ieee1275.h (grub_ieee1275_seek): Replace pos_i and pos_lo with pos. All users updated. * include/grub/powerpc/ieee1275/ieee1275.h (GRUB_IEEE1275_CELL_SIZEOF): New constant. * include/grub/sparc64/ieee1275/ieee1275.h (GRUB_IEEE1275_CELL_SIZEOF): Likewise. * kern/ieee1275/ieee1275.c (grub_ieee1275_seek): Split pos into pos_hi and pos_lo. --- ChangeLog | 13 +++++++++++++ disk/ieee1275/ofdisk.c | 2 +- include/grub/ieee1275/ieee1275.h | 2 +- include/grub/powerpc/ieee1275/ieee1275.h | 1 + include/grub/sparc64/ieee1275/ieee1275.h | 1 + kern/ieee1275/ieee1275.c | 15 +++++++++++---- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 760ac720c..6f1820d5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-02-13 Vladimir Serbinenko + + Fix over-4GiB seek on sparc64. + + * include/grub/ieee1275/ieee1275.h (grub_ieee1275_seek): + Replace pos_i and pos_lo with pos. All users updated. + * include/grub/powerpc/ieee1275/ieee1275.h (GRUB_IEEE1275_CELL_SIZEOF): + New constant. + * include/grub/sparc64/ieee1275/ieee1275.h (GRUB_IEEE1275_CELL_SIZEOF): + Likewise. + * kern/ieee1275/ieee1275.c (grub_ieee1275_seek): Split pos into pos_hi + and pos_lo. + 2010-02-13 Vladimir Serbinenko * util/grub-mkrawimage.c (main): Call set_program_name. diff --git a/disk/ieee1275/ofdisk.c b/disk/ieee1275/ofdisk.c index 238cff33d..0adedf33f 100644 --- a/disk/ieee1275/ofdisk.c +++ b/disk/ieee1275/ofdisk.c @@ -241,7 +241,7 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector, pos = sector * 512UL; grub_ieee1275_seek ((grub_ieee1275_ihandle_t) (unsigned long) disk->data, - (int) (pos >> 32), (int) pos & 0xFFFFFFFFUL, &status); + pos, &status); if (status < 0) return grub_error (GRUB_ERR_READ_ERROR, "seek error, can't seek block %llu", diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index 8b31e32e2..a852a7b61 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -138,7 +138,7 @@ int EXPORT_FUNC(grub_ieee1275_read) (grub_ieee1275_ihandle_t ihandle, void *buffer, grub_size_t len, grub_ssize_t *actualp); int EXPORT_FUNC(grub_ieee1275_seek) (grub_ieee1275_ihandle_t ihandle, - int pos_hi, int pos_lo, + grub_disk_addr_t pos, grub_ssize_t *result); int EXPORT_FUNC(grub_ieee1275_peer) (grub_ieee1275_phandle_t node, grub_ieee1275_phandle_t *result); diff --git a/include/grub/powerpc/ieee1275/ieee1275.h b/include/grub/powerpc/ieee1275/ieee1275.h index 7e93055c9..3c7683fad 100644 --- a/include/grub/powerpc/ieee1275/ieee1275.h +++ b/include/grub/powerpc/ieee1275/ieee1275.h @@ -22,6 +22,7 @@ #include +#define GRUB_IEEE1275_CELL_SIZEOF 4 typedef grub_uint32_t grub_ieee1275_cell_t; #endif /* ! GRUB_IEEE1275_MACHINE_HEADER */ diff --git a/include/grub/sparc64/ieee1275/ieee1275.h b/include/grub/sparc64/ieee1275/ieee1275.h index b25e98a6d..1619510fb 100644 --- a/include/grub/sparc64/ieee1275/ieee1275.h +++ b/include/grub/sparc64/ieee1275/ieee1275.h @@ -22,6 +22,7 @@ #include +#define GRUB_IEEE1275_CELL_SIZEOF 8 typedef grub_uint64_t grub_ieee1275_cell_t; /* Encoding of 'mode' argument to grub_ieee1275_map_physical() */ diff --git a/kern/ieee1275/ieee1275.c b/kern/ieee1275/ieee1275.c index 8a5773c23..9e2919172 100644 --- a/kern/ieee1275/ieee1275.c +++ b/kern/ieee1275/ieee1275.c @@ -284,8 +284,8 @@ grub_ieee1275_read (grub_ieee1275_ihandle_t ihandle, void *buffer, } int -grub_ieee1275_seek (grub_ieee1275_ihandle_t ihandle, int pos_hi, - int pos_lo, grub_ssize_t *result) +grub_ieee1275_seek (grub_ieee1275_ihandle_t ihandle, grub_disk_addr_t pos, + grub_ssize_t *result) { struct write_args { @@ -299,8 +299,15 @@ grub_ieee1275_seek (grub_ieee1275_ihandle_t ihandle, int pos_hi, INIT_IEEE1275_COMMON (&args.common, "seek", 3, 1); args.ihandle = ihandle; - args.pos_hi = (grub_ieee1275_cell_t) pos_hi; - args.pos_lo = (grub_ieee1275_cell_t) pos_lo; + /* To prevent stupid gcc warning. */ +#if GRUB_IEEE1275_CELL_SIZEOF >= 8 + args.pos_hi = 0; + args.pos_lo = pos; +#else + args.pos_hi = (grub_ieee1275_cell_t) (pos >> (8 * GRUB_IEEE1275_CELL_SIZEOF)); + args.pos_lo = (grub_ieee1275_cell_t) + (pos & ((1ULL << (8 * GRUB_IEEE1275_CELL_SIZEOF)) - 1)); +#endif if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; From e0128bbdc4243cb676156cca5c1a31f216d562f6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 16:16:40 +0100 Subject: [PATCH 163/237] 2010-02-13 Vladimir Serbinenko * disk/ieee1275/ofdisk.c (grub_ofdisk_read): Remove excessively verbose dprintf. --- ChangeLog | 5 +++++ disk/ieee1275/ofdisk.c | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6f1820d5e..6690f7f81 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-13 Vladimir Serbinenko + + * disk/ieee1275/ofdisk.c (grub_ofdisk_read): Remove excessively + verbose dprintf. + 2010-02-13 Vladimir Serbinenko Fix over-4GiB seek on sparc64. diff --git a/disk/ieee1275/ofdisk.c b/disk/ieee1275/ofdisk.c index 0adedf33f..05c0dd04d 100644 --- a/disk/ieee1275/ofdisk.c +++ b/disk/ieee1275/ofdisk.c @@ -234,10 +234,6 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector, grub_ssize_t status, actual; unsigned long long pos; - grub_dprintf ("disk", - "Reading handle %p: sector 0x%llx, size 0x%lx, buf %p.\n", - (void *) disk->data, (long long) sector, (long) size, buf); - pos = sector * 512UL; grub_ieee1275_seek ((grub_ieee1275_ihandle_t) (unsigned long) disk->data, From 17cec782c4463f8c92d130eca1f0e2439803c1e2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 16:23:20 +0100 Subject: [PATCH 164/237] 2010-02-13 Vladimir Serbinenko * kern/sparc64/ieee1275/crt0.S (codestart): Move modules backwards. --- ChangeLog | 4 ++++ kern/sparc64/ieee1275/crt0.S | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6690f7f81..47da5ccf2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-13 Vladimir Serbinenko + + * kern/sparc64/ieee1275/crt0.S (codestart): Move modules backwards. + 2010-02-13 Vladimir Serbinenko * disk/ieee1275/ofdisk.c (grub_ofdisk_read): Remove excessively diff --git a/kern/sparc64/ieee1275/crt0.S b/kern/sparc64/ieee1275/crt0.S index 4e67cbc19..3749f3005 100644 --- a/kern/sparc64/ieee1275/crt0.S +++ b/kern/sparc64/ieee1275/crt0.S @@ -53,12 +53,16 @@ codestart: or %o3, %lo(_end), %o3 sethi %hi(grub_total_module_size), %o4 lduw [%o4 + %lo(grub_total_module_size)], %o4 + add %o2, %o4, %o2 + add %o3, %o4, %o3 + sub %o2, 4, %o2 + sub %o3, 4, %o3 1: lduw [%o2], %o5 stw %o5, [%o3] subcc %o4, 4, %o4 - add %o2, 4, %o2 + sub %o2, 4, %o2 bne,pt %icc, 1b - add %o3, 4, %o3 + sub %o3, 4, %o3 /* Now it's safe to clear out the BSS. */ sethi %hi(__bss_start), %o2 From a49217cff7157395f3770f84fd5b1f01d107cce3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 16:26:50 +0100 Subject: [PATCH 165/237] aout image support --- boot/sparc64/ieee1275/diskboot.S | 2 +- conf/sparc64-ieee1275.rmk | 2 +- include/grub/aout.h | 5 + include/grub/kernel.h | 2 + include/grub/sparc64/ieee1275/kernel.h | 13 +++ kern/main.c | 19 ++++ kern/mips/yeeloong/init.c | 28 +----- kern/sparc64/ieee1275/crt0.S | 2 +- kern/sparc64/ieee1275/init.c | 2 +- util/grub-mkrawimage.c | 128 +++++++++++++++---------- 10 files changed, 122 insertions(+), 81 deletions(-) diff --git a/boot/sparc64/ieee1275/diskboot.S b/boot/sparc64/ieee1275/diskboot.S index 68ed0eee0..5016bf9e0 100644 --- a/boot/sparc64/ieee1275/diskboot.S +++ b/boot/sparc64/ieee1275/diskboot.S @@ -129,7 +129,7 @@ bootit: mov NOTIFICATION_DONE_LEN, %o3 sethi %hi(GRUB_BOOT_MACHINE_IMAGE_ADDRESS), %o2 jmpl %o2 + %lo(GRUB_BOOT_MACHINE_IMAGE_ADDRESS), %o7 - mov CIF_REG, %o0 + mov CIF_REG, %o4 1: ba,a 1b lastlist: diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index 6a91b40ee..4b51a5c3e 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -48,7 +48,7 @@ kernel_img_SOURCES = kern/sparc64/ieee1275/crt0.S kern/ieee1275/cmain.c \ symlist.c kern/$(target_cpu)/cache.S kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,0x200000,-Bstatic,-melf64_sparc -static-libgcc -lgcc +kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,0x4400,-Bstatic,-melf64_sparc -static-libgcc -lgcc kernel_img_FORMAT = binary symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh diff --git a/include/grub/aout.h b/include/grub/aout.h index 04e85f8b0..f962a97b3 100644 --- a/include/grub/aout.h +++ b/include/grub/aout.h @@ -102,6 +102,7 @@ union grub_aout_header #define AOUT_MID_I386 134 /* i386 BSD binary */ #define AOUT_MID_SPARC 138 /* sparc */ #define AOUT_MID_HP200 200 /* hp200 (68010) BSD binary */ +#define AOUT_MID_SUN 0x103 #define AOUT_MID_HP300 300 /* hp300 (68020+68881) BSD binary */ #define AOUT_MID_HPUX 0x20C /* hp200/300 HP-UX binary */ #define AOUT_MID_HPUX800 0x20B /* hp800 HP-UX binary */ @@ -114,10 +115,14 @@ union grub_aout_header #define AOUT_GETMID(header) ((header).a_midmag >> 16) & 0x03ff) #define AOUT_GETFLAG(header) ((header).a_midmag >> 26) & 0x3f) +#ifndef GRUB_UTIL + int EXPORT_FUNC(grub_aout_get_type) (union grub_aout_header *header); grub_err_t EXPORT_FUNC(grub_aout_load) (grub_file_t file, int offset, grub_addr_t load_addr, int load_size, grub_addr_t bss_end_addr); +#endif + #endif /* ! GRUB_AOUT_HEADER */ diff --git a/include/grub/kernel.h b/include/grub/kernel.h index 9586a90b9..bf52ffcb4 100644 --- a/include/grub/kernel.h +++ b/include/grub/kernel.h @@ -59,6 +59,8 @@ extern grub_addr_t grub_arch_modules_addr (void); extern void EXPORT_FUNC(grub_module_iterate) (int (*hook) (struct grub_module_header *)); +grub_addr_t grub_modules_get_end (void); + /* The start point of the C code. */ void grub_main (void); diff --git a/include/grub/sparc64/ieee1275/kernel.h b/include/grub/sparc64/ieee1275/kernel.h index 8eb1671a8..78e039bc5 100644 --- a/include/grub/sparc64/ieee1275/kernel.h +++ b/include/grub/sparc64/ieee1275/kernel.h @@ -41,8 +41,21 @@ #define GRUB_KERNEL_MACHINE_RAW_SIZE 0 +#define GRUB_PLATFORM_IMAGE_FORMATS "raw, aout" +#define GRUB_PLATFORM_IMAGE_DEFAULT_FORMAT "raw" + +#define GRUB_PLATFORM_IMAGE_DEFAULT GRUB_PLATFORM_IMAGE_RAW + #ifndef ASM_FILE +typedef enum { + GRUB_PLATFORM_IMAGE_RAW, + GRUB_PLATFORM_IMAGE_AOUT +} + grub_platform_image_format_t; +#define GRUB_PLATFORM_IMAGE_RAW GRUB_PLATFORM_IMAGE_RAW +#define GRUB_PLATFORM_IMAGE_AOUT GRUB_PLATFORM_IMAGE_AOUT + #include #include diff --git a/kern/main.c b/kern/main.c index 456105378..54235821d 100644 --- a/kern/main.c +++ b/kern/main.c @@ -53,6 +53,25 @@ grub_module_iterate (int (*hook) (struct grub_module_header *header)) } } +/* This is actualy platform-independant but used only on yeeloong and sparc. */ +#if defined (GRUB_MACHINE_MIPS_YEELOONG) || defined (GRUB_MACHINE_SPARC64) +grub_addr_t +grub_modules_get_end (void) +{ + struct grub_module_info *modinfo; + grub_addr_t modbase; + + modbase = grub_arch_modules_addr (); + modinfo = (struct grub_module_info *) modbase; + + /* Check if there are any modules. */ + if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC) + return modbase; + + return modbase + modinfo->size; +} +#endif + /* Load all modules in core. */ static void grub_load_modules (void) diff --git a/kern/mips/yeeloong/init.c b/kern/mips/yeeloong/init.c index 14e8a39a2..d148d08dc 100644 --- a/kern/mips/yeeloong/init.c +++ b/kern/mips/yeeloong/init.c @@ -63,35 +63,13 @@ grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, return GRUB_ERR_NONE; } - -static void * -get_modules_end (void) -{ - struct grub_module_info *modinfo; - struct grub_module_header *header; - grub_addr_t modbase; - - modbase = grub_arch_modules_addr (); - modinfo = (struct grub_module_info *) modbase; - - /* Check if there are any modules. */ - if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC) - return modinfo; - - for (header = (struct grub_module_header *) (modbase + modinfo->offset); - header < (struct grub_module_header *) (modbase + modinfo->size); - header = (struct grub_module_header *) ((char *) header + header->size)); - - return header; -} - void grub_machine_init (void) { - void *modend; - modend = get_modules_end (); + grub_addr_t modend; + modend = grub_modules_get_end (); grub_mm_init_region (modend, (grub_arch_memsize << 20) - - (((grub_addr_t) modend) - GRUB_ARCH_LOWMEMVSTART)); + - (modend - GRUB_ARCH_LOWMEMVSTART)); /* FIXME: use upper memory as well. */ grub_install_get_time_ms (grub_rtc_get_time_ms); diff --git a/kern/sparc64/ieee1275/crt0.S b/kern/sparc64/ieee1275/crt0.S index 4e67cbc19..1dc65dc64 100644 --- a/kern/sparc64/ieee1275/crt0.S +++ b/kern/sparc64/ieee1275/crt0.S @@ -24,7 +24,7 @@ .globl _start _start: ba codestart - nop + mov %o4, %o0 . = EXT_C(_start) + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE diff --git a/kern/sparc64/ieee1275/init.c b/kern/sparc64/ieee1275/init.c index 115328f40..5827be658 100644 --- a/kern/sparc64/ieee1275/init.c +++ b/kern/sparc64/ieee1275/init.c @@ -104,7 +104,7 @@ grub_machine_set_prefix (void) static void grub_heap_init (void) { - grub_mm_init_region ((void *)(long)0x4000UL, 0x200000 - 0x4000); + grub_mm_init_region ((void *) grub_modules_get_end (), 0x200000); } static void diff --git a/util/grub-mkrawimage.c b/util/grub-mkrawimage.c index e17446f78..26ccd7d94 100644 --- a/util/grub-mkrawimage.c +++ b/util/grub-mkrawimage.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -230,6 +231,36 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], grub_util_info ("the core size is 0x%x", core_size); +#ifdef GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE + *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE)) + = grub_host_to_target32 (total_module_size); +#endif + *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE)) + = grub_host_to_target32 (kernel_size); +#ifdef GRUB_KERNEL_MACHINE_COMPRESSED_SIZE + *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE)) + = grub_host_to_target32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE); +#endif + +#if defined(GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) && defined(GRUB_KERNEL_MACHINE_INSTALL_BSD_PART) + /* If we included a drive in our prefix, let GRUB know it doesn't have to + prepend the drive told by BIOS. */ + if (prefix[0] == '(') + { + *((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART)) + = grub_host_to_target32 (-2); + *((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)) + = grub_host_to_target32 (-2); + } +#endif + +#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)"), + GRUB_KERNEL_MACHINE_LINK_ADDR + core_size, + GRUB_MEMORY_MACHINE_UPPER); +#endif + #if defined(GRUB_MACHINE_PCBIOS) { unsigned num; @@ -299,62 +330,50 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], free (boot_path); } #elif defined (GRUB_MACHINE_SPARC64) - { - unsigned int num; - char *boot_path, *boot_img; - size_t boot_size; - - num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); - num <<= GRUB_DISK_SECTOR_BITS; - - boot_path = grub_util_get_path (dir, "diskboot.img"); - boot_size = grub_util_get_image_size (boot_path); - if (boot_size != GRUB_DISK_SECTOR_SIZE) - grub_util_error ("diskboot.img is not one sector size"); - - boot_img = grub_util_read_image (boot_path); - - *((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE - - GRUB_BOOT_MACHINE_LIST_SIZE + 8)) - = grub_host_to_target32 (num); - - grub_util_write_image (boot_img, boot_size, out); - free (boot_img); - free (boot_path); - } -#endif - -#ifdef GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE - *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE)) - = grub_host_to_target32 (total_module_size); -#endif - *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE)) - = grub_host_to_target32 (kernel_size); -#ifdef GRUB_KERNEL_MACHINE_COMPRESSED_SIZE - *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE)) - = grub_host_to_target32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE); -#endif - -#if defined(GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) && defined(GRUB_KERNEL_MACHINE_INSTALL_BSD_PART) - /* If we included a drive in our prefix, let GRUB know it doesn't have to - prepend the drive told by BIOS. */ - if (prefix[0] == '(') + if (format == GRUB_PLATFORM_IMAGE_AOUT) { - *((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART)) - = grub_host_to_target32 (-2); - *((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)) - = grub_host_to_target32 (-2); + void *aout_img; + size_t aout_size; + struct grub_aout32_header *aout_head; + + aout_size = core_size + sizeof (*aout_head); + aout_img = xmalloc (aout_size); + aout_head = aout_img; + aout_head->a_midmag = grub_host_to_target32 ((AOUT_MID_SUN << 16) + | AOUT32_OMAGIC); + aout_head->a_text = grub_host_to_target32 (core_size); + aout_head->a_entry = grub_host_to_target32 (0x4400); + memcpy (aout_img + sizeof (*aout_head), core_img, core_size); + + free (core_img); + core_img = aout_img; + core_size = aout_size; } -#endif + else + { + unsigned int num; + char *boot_path, *boot_img; + size_t boot_size; -#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)"), - GRUB_KERNEL_MACHINE_LINK_ADDR + core_size, - GRUB_MEMORY_MACHINE_UPPER); -#endif + num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); + num <<= GRUB_DISK_SECTOR_BITS; -#if defined(GRUB_MACHINE_MIPS) + boot_path = grub_util_get_path (dir, "diskboot.img"); + boot_size = grub_util_get_image_size (boot_path); + if (boot_size != GRUB_DISK_SECTOR_SIZE) + grub_util_error ("diskboot.img is not one sector size"); + + boot_img = grub_util_read_image (boot_path); + + *((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE + - GRUB_BOOT_MACHINE_LIST_SIZE + 8)) + = grub_host_to_target32 (num); + + grub_util_write_image (boot_img, boot_size, out); + free (boot_img); + free (boot_path); + } +#elif defined(GRUB_MACHINE_MIPS) if (format == GRUB_PLATFORM_IMAGE_ELF) { char *elf_img; @@ -527,6 +546,11 @@ main (int argc, char *argv[]) if (strcmp (optarg, "elf") == 0) format = GRUB_PLATFORM_IMAGE_ELF; else +#endif +#ifdef GRUB_PLATFORM_IMAGE_AOUT + if (strcmp (optarg, "aout") == 0) + format = GRUB_PLATFORM_IMAGE_AOUT; + else #endif usage (1); break; From 8c6052cea547d2d6960d22b19b75a75870cb98bc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 16:30:22 +0100 Subject: [PATCH 166/237] 2010-02-13 Vladimir Serbinenko * loader/sparc64/ieee1275/linux.c (alloc_phys): Correct bounds checking. --- ChangeLog | 4 ++++ loader/sparc64/ieee1275/linux.c | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47da5ccf2..c9f64df01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-13 Vladimir Serbinenko + + * loader/sparc64/ieee1275/linux.c (alloc_phys): Correct bounds checking. + 2010-02-13 Vladimir Serbinenko * kern/sparc64/ieee1275/crt0.S (codestart): Move modules backwards. diff --git a/loader/sparc64/ieee1275/linux.c b/loader/sparc64/ieee1275/linux.c index 42bae6bb8..51d82ddcc 100644 --- a/loader/sparc64/ieee1275/linux.c +++ b/loader/sparc64/ieee1275/linux.c @@ -193,20 +193,20 @@ alloc_phys (grub_addr_t size) return 0; addr = align_addr (addr, FOUR_MB); - if (addr >= end) + if (addr + size >= end) return 0; if (addr >= grub_phys_start && addr < grub_phys_end) { addr = align_addr (grub_phys_end, FOUR_MB); - if (addr >= end) + if (addr + size >= end) return 0; } if ((addr + size) >= grub_phys_start && (addr + size) < grub_phys_end) { addr = align_addr (grub_phys_end, FOUR_MB); - if (addr >= end) + if (addr + size >= end) return 0; } @@ -217,14 +217,14 @@ alloc_phys (grub_addr_t size) if (addr >= linux_paddr && addr < linux_end) { addr = linux_end; - if (addr >= end) + if (addr + size >= end) return 0; } if ((addr + size) >= linux_paddr && (addr + size) < linux_end) { addr = linux_end; - if (addr >= end) + if (addr + size >= end) return 0; } } From 2c0fcc366632cbbf9bf14a6ded41088a0a72f4df Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 16:32:24 +0100 Subject: [PATCH 167/237] 2010-02-13 Vladimir Serbinenko * loader/sparc64/ieee1275/linux.c (align_addr): Remove. (alloc_phys): Use ALIGN_UP instead of align_addr. --- ChangeLog | 5 +++++ loader/sparc64/ieee1275/linux.c | 14 ++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index c9f64df01..01067182f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-13 Vladimir Serbinenko + + * loader/sparc64/ieee1275/linux.c (align_addr): Remove. + (alloc_phys): Use ALIGN_UP instead of align_addr. + 2010-02-13 Vladimir Serbinenko * loader/sparc64/ieee1275/linux.c (alloc_phys): Correct bounds checking. diff --git a/loader/sparc64/ieee1275/linux.c b/loader/sparc64/ieee1275/linux.c index 51d82ddcc..65f334ab3 100644 --- a/loader/sparc64/ieee1275/linux.c +++ b/loader/sparc64/ieee1275/linux.c @@ -173,12 +173,6 @@ grub_linux_unload (void) #define FOUR_MB (4 * 1024 * 1024) -static grub_addr_t -align_addr(grub_addr_t val, grub_addr_t align) -{ - return (val + (align - 1)) & ~(align - 1); -} - static grub_addr_t alloc_phys (grub_addr_t size) { @@ -192,27 +186,27 @@ alloc_phys (grub_addr_t size) if (type != 1) return 0; - addr = align_addr (addr, FOUR_MB); + addr = ALIGN_UP (addr, FOUR_MB); if (addr + size >= end) return 0; if (addr >= grub_phys_start && addr < grub_phys_end) { - addr = align_addr (grub_phys_end, FOUR_MB); + addr = ALIGN_UP (grub_phys_end, FOUR_MB); if (addr + size >= end) return 0; } if ((addr + size) >= grub_phys_start && (addr + size) < grub_phys_end) { - addr = align_addr (grub_phys_end, FOUR_MB); + addr = ALIGN_UP (grub_phys_end, FOUR_MB); if (addr + size >= end) return 0; } if (loaded) { - grub_addr_t linux_end = align_addr (linux_paddr + linux_size, FOUR_MB); + grub_addr_t linux_end = ALIGN_UP (linux_paddr + linux_size, FOUR_MB); if (addr >= linux_paddr && addr < linux_end) { From 69e137e819725cd86617aa3de826c4b19f390f5a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 16:40:29 +0100 Subject: [PATCH 168/237] 2010-02-13 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Macroify constants. --- ChangeLog | 5 +++++ term/ieee1275/ofconsole.c | 18 +++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 01067182f..ff5621a56 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-13 Vladimir Serbinenko + + * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Macroify + constants. + 2010-02-13 Vladimir Serbinenko * loader/sparc64/ieee1275/linux.c (align_addr): Remove. diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index 51dca7a53..6073e25d2 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -165,7 +165,7 @@ grub_ofconsole_readkey (int *key) return 1; } - if (c != 91) + if (c != '[') return 0; grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); @@ -174,21 +174,21 @@ grub_ofconsole_readkey (int *key) switch (c) { - case 65: + case 'A': /* Up: Ctrl-p. */ - c = 16; + c = GRUB_TERM_UP; break; - case 66: + case 'B': /* Down: Ctrl-n. */ - c = 14; + c = GRUB_TERM_DOWN; break; - case 67: + case 'C': /* Right: Ctrl-f. */ - c = 6; + c = GRUB_TERM_RIGHT; break; - case 68: + case 'D': /* Left: Ctrl-b. */ - c = 2; + c = GRUB_TERM_LEFT; break; } } From 5b59a4e367fc4510e0ae4f4181c0c71841233783 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 16:44:34 +0100 Subject: [PATCH 169/237] 2010-02-13 Vladimir Serbinenko * disk/ieee1275/ofdisk.c (grub_ofdisk_open): Check device type before opening and not after. --- ChangeLog | 5 +++++ disk/ieee1275/ofdisk.c | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff5621a56..eb937f97e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-13 Vladimir Serbinenko + + * disk/ieee1275/ofdisk.c (grub_ofdisk_open): Check device type before + opening and not after. + 2010-02-13 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Macroify diff --git a/disk/ieee1275/ofdisk.c b/disk/ieee1275/ofdisk.c index 05c0dd04d..e5a4a67fa 100644 --- a/disk/ieee1275/ofdisk.c +++ b/disk/ieee1275/ofdisk.c @@ -172,16 +172,6 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) grub_dprintf ("disk", "Opening `%s'.\n", op->devpath); - grub_ieee1275_open (op->devpath, &dev_ihandle); - if (! dev_ihandle) - { - grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); - goto fail; - } - - grub_dprintf ("disk", "Opened `%s' as handle %p.\n", op->devpath, - (void *) (unsigned long) dev_ihandle); - if (grub_ieee1275_finddevice (op->devpath, &dev)) { grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read device properties"); @@ -201,6 +191,16 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) goto fail; } + grub_ieee1275_open (op->devpath, &dev_ihandle); + if (! dev_ihandle) + { + grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); + goto fail; + } + + grub_dprintf ("disk", "Opened `%s' as handle %p.\n", op->devpath, + (void *) (unsigned long) dev_ihandle); + /* XXX: There is no property to read the number of blocks. There should be a property `#blocks', but it is not there. Perhaps it is possible to use seek for this. */ From 904935c3effb50738589b6d52d7219e6534a8a0f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 16:48:22 +0100 Subject: [PATCH 170/237] 2010-02-13 Vladimir Serbinenko Merge grub_ieee1275_map_physical into grub_map and rename to grub_ieee1275_map * include/grub/ieee1275/ieee1275.h (grub_ieee1275_map): New proto. * include/grub/sparc64/ieee1275/ieee1275.h (grub_ieee1275_map_physical): Remove. * kern/ieee1275/openfw.c (grub_map): Rename to ... (grub_ieee1275_map): ... this. All users updated. Add phys_lo when necessary. * kern/sparc64/ieee1275/ieee1275.c (grub_ieee1275_map_physical): Remove. --- ChangeLog | 13 ++++++++++ include/grub/ieee1275/ieee1275.h | 4 +++ include/grub/sparc64/ieee1275/ieee1275.h | 4 --- kern/ieee1275/openfw.c | 27 ++++++++++++++----- kern/sparc64/ieee1275/ieee1275.c | 33 ------------------------ loader/sparc64/ieee1275/linux.c | 6 ++--- 6 files changed, 40 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index eb937f97e..bd8165647 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-02-13 Vladimir Serbinenko + + Merge grub_ieee1275_map_physical into grub_map and rename to + grub_ieee1275_map + + * include/grub/ieee1275/ieee1275.h (grub_ieee1275_map): New proto. + * include/grub/sparc64/ieee1275/ieee1275.h (grub_ieee1275_map_physical): + Remove. + * kern/ieee1275/openfw.c (grub_map): Rename to ... + (grub_ieee1275_map): ... this. All users updated. Add phys_lo when + necessary. + * kern/sparc64/ieee1275/ieee1275.c (grub_ieee1275_map_physical): Remove. + 2010-02-13 Vladimir Serbinenko * disk/ieee1275/ofdisk.c (grub_ofdisk_open): Check device type before diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index a852a7b61..62e8f3812 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -173,6 +173,10 @@ grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate) (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); int EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size); +int +EXPORT_FUNC(grub_ieee1275_map) (grub_addr_t phys, grub_addr_t virt, + grub_size_t size, grub_uint32_t mode); + char *EXPORT_FUNC(grub_ieee1275_encode_devname) (const char *path); char *EXPORT_FUNC(grub_ieee1275_get_filename) (const char *path); diff --git a/include/grub/sparc64/ieee1275/ieee1275.h b/include/grub/sparc64/ieee1275/ieee1275.h index 1619510fb..527c46ae7 100644 --- a/include/grub/sparc64/ieee1275/ieee1275.h +++ b/include/grub/sparc64/ieee1275/ieee1275.h @@ -37,10 +37,6 @@ typedef grub_uint64_t grub_ieee1275_cell_t; #define IEEE1275_MAP_DEFAULT (IEEE1275_MAP_WRITE | IEEE1275_MAP_READ | \ IEEE1275_MAP_EXEC | IEEE1275_MAP_CACHED) -extern int EXPORT_FUNC(grub_ieee1275_map_physical) (grub_addr_t paddr, - grub_addr_t vaddr, - grub_size_t size, - grub_uint32_t mode); extern int EXPORT_FUNC(grub_ieee1275_claim_vaddr) (grub_addr_t vaddr, grub_size_t size); extern int EXPORT_FUNC(grub_ieee1275_alloc_physmem) (grub_addr_t *paddr, diff --git a/kern/ieee1275/openfw.c b/kern/ieee1275/openfw.c index e5f565c4c..13fccbf9a 100644 --- a/kern/ieee1275/openfw.c +++ b/kern/ieee1275/openfw.c @@ -199,9 +199,9 @@ nextprop: } /* Call the "map" method of /chosen/mmu. */ -static int -grub_map (grub_addr_t phys, grub_addr_t virt, grub_uint32_t size, - grub_uint8_t mode) +int +grub_ieee1275_map (grub_addr_t phys, grub_addr_t virt, grub_size_t size, + grub_uint32_t mode) { struct map_args { struct grub_ieee1275_common_hdr common; @@ -210,17 +210,30 @@ grub_map (grub_addr_t phys, grub_addr_t virt, grub_uint32_t size, grub_ieee1275_cell_t mode; grub_ieee1275_cell_t size; grub_ieee1275_cell_t virt; - grub_ieee1275_cell_t phys; +#ifdef GRUB_MACHINE_SPARC64 + grub_ieee1275_cell_t phys_high; +#endif + grub_ieee1275_cell_t phys_low; grub_ieee1275_cell_t catch_result; } args; - INIT_IEEE1275_COMMON (&args.common, "call-method", 6, 1); + INIT_IEEE1275_COMMON (&args.common, "call-method", +#ifdef GRUB_MACHINE_SPARC64 + 7, +#else + 6, +#endif + 1); args.method = (grub_ieee1275_cell_t) "map"; args.ihandle = grub_ieee1275_mmu; - args.phys = phys; +#ifdef GRUB_MACHINE_SPARC64 + args.phys_high = 0; +#endif + args.phys_low = phys; args.virt = virt; args.size = size; args.mode = mode; /* Format is WIMG0PP. */ + args.catch_result = (grub_ieee1275_cell_t) -1; if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; @@ -235,7 +248,7 @@ grub_claimmap (grub_addr_t addr, grub_size_t size) return -1; if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_REAL_MODE) - && grub_map (addr, addr, size, 0x00)) + && grub_ieee1275_map (addr, addr, size, 0x00)) { grub_printf ("map failed: address 0x%llx, size 0x%llx\n", (long long) addr, (long long) size); diff --git a/kern/sparc64/ieee1275/ieee1275.c b/kern/sparc64/ieee1275/ieee1275.c index 438a171ca..53be692c3 100644 --- a/kern/sparc64/ieee1275/ieee1275.c +++ b/kern/sparc64/ieee1275/ieee1275.c @@ -21,39 +21,6 @@ /* Sun specific ieee1275 interfaces used by GRUB. */ -int -grub_ieee1275_map_physical (grub_addr_t paddr, grub_addr_t vaddr, - grub_size_t size, grub_uint32_t mode) -{ - struct map_physical_args - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t ihandle; - grub_ieee1275_cell_t mode; - grub_ieee1275_cell_t size; - grub_ieee1275_cell_t virt; - grub_ieee1275_cell_t phys_high; - grub_ieee1275_cell_t phys_low; - grub_ieee1275_cell_t catch_result; - } - args; - - INIT_IEEE1275_COMMON (&args.common, "call-method", 7, 1); - args.method = (grub_ieee1275_cell_t) "map"; - args.ihandle = grub_ieee1275_mmu; - args.mode = mode; - args.size = size; - args.virt = vaddr; - args.phys_high = 0; - args.phys_low = paddr; - args.catch_result = (grub_ieee1275_cell_t) -1; - - if (IEEE1275_CALL_ENTRY_FN (&args) == -1) - return -1; - return args.catch_result; -} - int grub_ieee1275_claim_vaddr (grub_addr_t vaddr, grub_size_t size) { diff --git a/loader/sparc64/ieee1275/linux.c b/loader/sparc64/ieee1275/linux.c index 65f334ab3..24a6849a6 100644 --- a/loader/sparc64/ieee1275/linux.c +++ b/loader/sparc64/ieee1275/linux.c @@ -252,8 +252,8 @@ grub_linux_load64 (grub_elf_t elf) if (paddr == (grub_addr_t) -1) return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't allocate physical memory"); - ret = grub_ieee1275_map_physical (paddr, linux_addr - off, - linux_size + off, IEEE1275_MAP_DEFAULT); + ret = grub_ieee1275_map (paddr, linux_addr - off, + linux_size + off, IEEE1275_MAP_DEFAULT); if (ret) return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't map physical memory"); @@ -403,7 +403,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), "couldn't allocate physical memory"); goto fail; } - ret = grub_ieee1275_map_physical (paddr, addr, size, IEEE1275_MAP_DEFAULT); + ret = grub_ieee1275_map (paddr, addr, size, IEEE1275_MAP_DEFAULT); if (ret) { grub_error (GRUB_ERR_OUT_OF_MEMORY, From 10f6389453e746a5235e5db6c70b4b55dc0355a6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Feb 2010 18:48:33 +0100 Subject: [PATCH 171/237] Fix raw image addresses --- boot/sparc64/ieee1275/boot.S | 2 +- boot/sparc64/ieee1275/diskboot.S | 2 +- include/grub/sparc64/ieee1275/boot.h | 5 +++-- util/grub-mkrawimage.c | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/boot/sparc64/ieee1275/boot.S b/boot/sparc64/ieee1275/boot.S index 74f4ee014..167406017 100644 --- a/boot/sparc64/ieee1275/boot.S +++ b/boot/sparc64/ieee1275/boot.S @@ -118,7 +118,7 @@ prom_call: boot_continue: mov %o7, PIC_REG /* PIC base */ - sethi %hi(SCRATCH_PAD), %l1 /* OF argument slots */ + sethi %hi(SCRATCH_PAD_BOOT), %l1 /* OF argument slots */ /* Find the /chosen node so we can fetch the stdout handle, * and thus perform console output. diff --git a/boot/sparc64/ieee1275/diskboot.S b/boot/sparc64/ieee1275/diskboot.S index 5016bf9e0..a4d4b5bf9 100644 --- a/boot/sparc64/ieee1275/diskboot.S +++ b/boot/sparc64/ieee1275/diskboot.S @@ -81,7 +81,7 @@ prom_call: after_info_block: - sethi %hi(SCRATCH_PAD), %l1 /* OF argument slots */ + sethi %hi(SCRATCH_PAD_DISKBOOT), %l1 /* OF argument slots */ GET_ABS(notification_string, %o2) call console_write diff --git a/include/grub/sparc64/ieee1275/boot.h b/include/grub/sparc64/ieee1275/boot.h index 95f311ce5..e1c1aa675 100644 --- a/include/grub/sparc64/ieee1275/boot.h +++ b/include/grub/sparc64/ieee1275/boot.h @@ -25,7 +25,8 @@ #define BOOTDEV_REG %l6 #define PIC_REG %l7 -#define SCRATCH_PAD 0x10000 +#define SCRATCH_PAD_BOOT 0x5000 +#define SCRATCH_PAD_DISKBOOT 0x4000 #define GET_ABS(symbol, reg) \ add PIC_REG, (symbol - pic_base), reg @@ -51,7 +52,7 @@ #define GRUB_BOOT_MACHINE_LIST_SIZE 12 -#define GRUB_BOOT_MACHINE_IMAGE_ADDRESS 0x200000 +#define GRUB_BOOT_MACHINE_IMAGE_ADDRESS 0x4400 #define GRUB_BOOT_MACHINE_KERNEL_ADDR 0x4200 diff --git a/util/grub-mkrawimage.c b/util/grub-mkrawimage.c index d0be7149c..933c46963 100644 --- a/util/grub-mkrawimage.c +++ b/util/grub-mkrawimage.c @@ -344,7 +344,8 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], aout_head->a_midmag = grub_host_to_target32 ((AOUT_MID_SUN << 16) | AOUT32_OMAGIC); aout_head->a_text = grub_host_to_target32 (core_size); - aout_head->a_entry = grub_host_to_target32 (0x4400); + aout_head->a_entry + = grub_host_to_target32 (GRUB_BOOT_MACHINE_IMAGE_ADDRESS); memcpy (aout_img + sizeof (*aout_head), core_img, core_size); free (core_img); From 8c717950104035bb2d9f70bb8f31cdcaee4fb8bb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Feb 2010 02:10:46 +0100 Subject: [PATCH 172/237] 2010-02-13 Vladimir Serbinenko * io/gzio.c (grub_gzio_open): Use grub_zalloc. --- ChangeLog | 4 ++++ io/gzio.c | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd8165647..2084735e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-13 Vladimir Serbinenko + + * io/gzio.c (grub_gzio_open): Use grub_zalloc. + 2010-02-13 Vladimir Serbinenko Merge grub_ieee1275_map_physical into grub_map and rename to diff --git a/io/gzio.c b/io/gzio.c index 39f6d7b13..9bf609105 100644 --- a/io/gzio.c +++ b/io/gzio.c @@ -1121,14 +1121,13 @@ grub_gzio_open (grub_file_t io, int transparent) if (! file) return 0; - gzio = grub_malloc (sizeof (*gzio)); + gzio = grub_zalloc (sizeof (*gzio)); if (! gzio) { grub_free (file); return 0; } - grub_memset (gzio, 0, sizeof (*gzio)); gzio->file = io; file->device = io->device; From 095f5f82f7c68f8bfabf1b35c1204626fa4dddf6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Feb 2010 13:18:33 +0100 Subject: [PATCH 173/237] 2010-02-14 Vladimir Serbinenko * fs/i386/pc/pxe.c (GRUB_MOD_INIT): Fix typo. Reported by: Pavel Pisa. --- ChangeLog | 5 +++++ fs/i386/pc/pxe.c | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2084735e0..1dfaca669 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-14 Vladimir Serbinenko + + * fs/i386/pc/pxe.c (GRUB_MOD_INIT): Fix typo. + Reported by: Pavel Pisa. + 2010-02-13 Vladimir Serbinenko * io/gzio.c (grub_gzio_open): Use grub_zalloc. diff --git a/fs/i386/pc/pxe.c b/fs/i386/pc/pxe.c index 92529883e..82d8ee583 100644 --- a/fs/i386/pc/pxe.c +++ b/fs/i386/pc/pxe.c @@ -568,21 +568,21 @@ GRUB_MOD_INIT(pxe) buf = grub_xasprintf ("%d", grub_pxe_blksize); if (buf) - grub_env_set ("net_pxe_blksize", buf); + grub_env_set ("pxe_blksize", buf); grub_free (buf); set_ip_env ("pxe_default_server", grub_pxe_default_server_ip); set_ip_env ("pxe_default_gateway", grub_pxe_default_gateway_ip); set_ip_env ("net_pxe_ip", grub_pxe_your_ip); - grub_register_variable_hook ("net_pxe_default_server", 0, + grub_register_variable_hook ("pxe_default_server", 0, grub_env_write_pxe_default_server); - grub_register_variable_hook ("net_pxe_default_gateway", 0, + grub_register_variable_hook ("pxe_default_gateway", 0, grub_env_write_pxe_default_gateway); /* XXX: Is it possible to change IP in PXE? */ grub_register_variable_hook ("net_pxe_ip", 0, grub_env_write_readonly); - grub_register_variable_hook ("net_pxe_blksize", 0, + grub_register_variable_hook ("pxe_blksize", 0, grub_env_write_pxe_blocksize); grub_disk_dev_register (&grub_pxe_dev); grub_fs_register (&grub_pxefs_fs); From 320dd174b5efd6dd7fde6636180f0547aaaae889 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Feb 2010 14:32:21 +0100 Subject: [PATCH 174/237] Increase stack size on sparc --- include/grub/sparc64/ieee1275/ieee1275.h | 2 ++ include/grub/sparc64/ieee1275/kernel.h | 1 + kern/sparc64/ieee1275/crt0.S | 16 +++++++++++++--- kern/sparc64/ieee1275/init.c | 6 +++++- loader/sparc64/ieee1275/linux.c | 17 +++++++++++------ 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/include/grub/sparc64/ieee1275/ieee1275.h b/include/grub/sparc64/ieee1275/ieee1275.h index 527c46ae7..32c77f80f 100644 --- a/include/grub/sparc64/ieee1275/ieee1275.h +++ b/include/grub/sparc64/ieee1275/ieee1275.h @@ -43,4 +43,6 @@ extern int EXPORT_FUNC(grub_ieee1275_alloc_physmem) (grub_addr_t *paddr, grub_size_t size, grub_uint32_t align); +extern grub_addr_t EXPORT_VAR (grub_ieee1275_original_stack); + #endif /* ! GRUB_IEEE1275_MACHINE_HEADER */ diff --git a/include/grub/sparc64/ieee1275/kernel.h b/include/grub/sparc64/ieee1275/kernel.h index 78e039bc5..a16fb88e7 100644 --- a/include/grub/sparc64/ieee1275/kernel.h +++ b/include/grub/sparc64/ieee1275/kernel.h @@ -40,6 +40,7 @@ #define GRUB_KERNEL_MACHINE_DATA_END 0x114 #define GRUB_KERNEL_MACHINE_RAW_SIZE 0 +#define GRUB_KERNEL_MACHINE_STACK_SIZE 0x40000 #define GRUB_PLATFORM_IMAGE_FORMATS "raw, aout" #define GRUB_PLATFORM_IMAGE_DEFAULT_FORMAT "raw" diff --git a/kern/sparc64/ieee1275/crt0.S b/kern/sparc64/ieee1275/crt0.S index f1ff6b466..d5a172296 100644 --- a/kern/sparc64/ieee1275/crt0.S +++ b/kern/sparc64/ieee1275/crt0.S @@ -53,8 +53,17 @@ codestart: or %o3, %lo(_end), %o3 sethi %hi(grub_total_module_size), %o4 lduw [%o4 + %lo(grub_total_module_size)], %o4 + add %o2, %o4, %o2 add %o3, %o4, %o3 + + /* Save ieee1275 stack for future use by booter. */ + mov %o6, %o1 + /* Our future stack. */ + sethi %hi(GRUB_KERNEL_MACHINE_STACK_SIZE - 2047), %o5 + or %o5, %lo(GRUB_KERNEL_MACHINE_STACK_SIZE - 2047), %o5 + add %o3, %o5, %o6 + sub %o2, 4, %o2 sub %o3, 4, %o3 1: lduw [%o2], %o5 @@ -62,7 +71,7 @@ codestart: subcc %o4, 4, %o4 sub %o2, 4, %o2 bne,pt %icc, 1b - sub %o3, 4, %o3 + sub %o3, 4, %o3 /* Now it's safe to clear out the BSS. */ sethi %hi(__bss_start), %o2 @@ -74,8 +83,9 @@ codestart: cmp %o2, %o3 blt,pt %xcc, 1b nop + sethi %hi(grub_ieee1275_original_stack), %o2 + stx %o1, [%o2 + %lo(grub_ieee1275_original_stack)] sethi %hi(grub_ieee1275_entry_fn), %o2 - stx %o0, [%o2 + %lo(grub_ieee1275_entry_fn)] call grub_main - nop + stx %o0, [%o2 + %lo(grub_ieee1275_entry_fn)] 1: ba,a 1b diff --git a/kern/sparc64/ieee1275/init.c b/kern/sparc64/ieee1275/init.c index 5827be658..a995217bc 100644 --- a/kern/sparc64/ieee1275/init.c +++ b/kern/sparc64/ieee1275/init.c @@ -23,12 +23,15 @@ #include #include #include +#include #include #include #include #include #include +grub_addr_t grub_ieee1275_original_stack; + void grub_exit (void) { @@ -104,7 +107,8 @@ grub_machine_set_prefix (void) static void grub_heap_init (void) { - grub_mm_init_region ((void *) grub_modules_get_end (), 0x200000); + grub_mm_init_region ((void *) (grub_modules_get_end () + + GRUB_KERNEL_MACHINE_STACK_SIZE), 0x200000); } static void diff --git a/loader/sparc64/ieee1275/linux.c b/loader/sparc64/ieee1275/linux.c index 24a6849a6..f55b4fa2a 100644 --- a/loader/sparc64/ieee1275/linux.c +++ b/loader/sparc64/ieee1275/linux.c @@ -58,9 +58,6 @@ static grub_size_t linux_size; static char *linux_args; -typedef void (*kernel_entry_t) (unsigned long, unsigned long, - unsigned long, unsigned long, int (void *)); - struct linux_bootstr_info { int len, valid; char buf[]; @@ -92,7 +89,6 @@ static grub_err_t grub_linux_boot (void) { struct linux_bootstr_info *bp; - kernel_entry_t linuxmain; struct linux_hdrs *hp; grub_addr_t addr; @@ -141,8 +137,17 @@ grub_linux_boot (void) grub_dprintf ("loader", "Jumping to Linux...\n"); /* Boot the kernel. */ - linuxmain = (kernel_entry_t) linux_addr; - linuxmain (0, 0, 0, 0, grub_ieee1275_entry_fn); + asm volatile ("sethi %hi(grub_ieee1275_entry_fn), %o1\n" + "ldx [%o1 + %lo(grub_ieee1275_entry_fn)], %o4\n" + "sethi %hi(grub_ieee1275_original_stack), %o1\n" + "ldx [%o1 + %lo(grub_ieee1275_original_stack)], %o6\n" + "sethi %hi(linux_addr), %o1\n" + "ldx [%o1 + %lo(linux_addr)], %o5\n" + "mov %g0, %o0\n" + "mov %g0, %o2\n" + "mov %g0, %o3\n" + "jmp %o5\n" + "mov %g0, %o1\n"); return GRUB_ERR_NONE; } From bc028f2f86ad3fa97afc0262fe414190717a988f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Feb 2010 14:46:19 +0100 Subject: [PATCH 175/237] 2010-02-14 Vladimir Serbinenko Prevent unknown commands from stopping menuentry execution. * script/execute.c (grub_script_execute_cmdline): Print error after unknown command. --- ChangeLog | 7 +++++++ script/execute.c | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1dfaca669..7c8e0a988 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-02-14 Vladimir Serbinenko + + Prevent unknown commands from stopping menuentry execution. + + * script/execute.c (grub_script_execute_cmdline): Print error after + unknown command. + 2010-02-14 Vladimir Serbinenko * fs/i386/pc/pxe.c (GRUB_MOD_INIT): Fix typo. diff --git a/script/execute.c b/script/execute.c index a0773c191..6e914aeeb 100644 --- a/script/execute.c +++ b/script/execute.c @@ -100,8 +100,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) grubcmd = grub_command_find (cmdname); if (! grubcmd) { - /* Shouldn't happen but precaution is good. */ - grub_print_error (); + grub_errno = GRUB_ERR_NONE; /* It's not a GRUB command, try all functions. */ func = grub_script_function_find (cmdname); @@ -126,6 +125,8 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno); grub_env_set ("?", errnobuf); + grub_print_error (); + return 0; } } From d27859b2eccc98d3c5e0ce50d4dfd58b253e6df0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Feb 2010 14:47:50 +0100 Subject: [PATCH 176/237] 2010-02-14 Vladimir Serbinenko * util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Enclose set root in single quotes to prevent \, from being unescaped. --- ChangeLog | 5 +++++ util/grub-mkconfig_lib.in | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7c8e0a988..403394560 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-14 Vladimir Serbinenko + + * util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Enclose + set root in single quotes to prevent \, from being unescaped. + 2010-02-14 Vladimir Serbinenko Prevent unknown commands from stopping menuentry execution. diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index fc24c7b70..45354041a 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -120,7 +120,7 @@ prepare_grub_to_access_device () # If there's a filesystem UUID that GRUB is capable of identifying, use it; # otherwise set root as per value in device.map. - echo "set root=`${grub_probe} --device ${device} --target=drive`" + echo "set root='`${grub_probe} --device ${device} --target=drive`'" if fs_uuid="`${grub_probe} --device ${device} --target=fs_uuid 2> /dev/null`" ; then echo "search --no-floppy --fs-uuid --set ${fs_uuid}" fi From e29f95dc538733358ed22678a75198c3281bc696 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Feb 2010 14:51:06 +0100 Subject: [PATCH 177/237] 2010-02-14 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_putchar): Don't output non-ASCII characters. --- ChangeLog | 5 +++++ term/ieee1275/ofconsole.c | 47 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 403394560..a75dd8636 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-14 Vladimir Serbinenko + + * term/ieee1275/ofconsole.c (grub_ofconsole_putchar): Don't output + non-ASCII characters. + 2010-02-14 Vladimir Serbinenko * util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Enclose diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index 6073e25d2..86b150a33 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -77,7 +77,52 @@ grub_ofconsole_writeesc (const char *str) static void grub_ofconsole_putchar (grub_uint32_t c) { - char chr = c; + char chr; + + if (c > 0x7F) + { + /* Better than nothing. */ + switch (c) + { + case GRUB_TERM_DISP_LEFT: + c = '<'; + break; + + case GRUB_TERM_DISP_UP: + c = '^'; + break; + + case GRUB_TERM_DISP_RIGHT: + c = '>'; + break; + + case GRUB_TERM_DISP_DOWN: + c = 'v'; + break; + + case GRUB_TERM_DISP_HLINE: + c = '-'; + break; + + case GRUB_TERM_DISP_VLINE: + c = '|'; + break; + + case GRUB_TERM_DISP_UL: + case GRUB_TERM_DISP_UR: + case GRUB_TERM_DISP_LL: + case GRUB_TERM_DISP_LR: + c = '+'; + break; + + default: + c = '?'; + break; + } + } + + chr = c; + if (c == '\n') { grub_curr_y++; From a08769434f565d7ef0ad1cffb5050e4894ff115e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Feb 2010 14:52:10 +0100 Subject: [PATCH 178/237] 2010-02-14 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Wait for possible escape sequence after \e. --- ChangeLog | 5 +++++ term/ieee1275/ofconsole.c | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index a75dd8636..8d654ce88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-14 Vladimir Serbinenko + + * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Wait for possible + escape sequence after \e. + 2010-02-14 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_putchar): Don't output diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index 86b150a33..82108022a 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -203,7 +204,14 @@ grub_ofconsole_readkey (int *key) if (actual > 0 && c == '\e') { + grub_uint64_t start; grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); + + /* On 9600 we have to wait up to 12 milliseconds. */ + start = grub_get_time_ms (); + while (actual <= 0 && grub_get_time_ms () - start < 12) + grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); + if (actual <= 0) { *key = '\e'; @@ -214,6 +222,10 @@ grub_ofconsole_readkey (int *key) return 0; grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); + /* On 9600 we have to wait up to 12 milliseconds. */ + start = grub_get_time_ms (); + while (actual <= 0 && grub_get_time_ms () - start < 12) + grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); if (actual <= 0) return 0; From 04459e70a353d59a83b10e0135e6e0b27e104b48 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 14 Feb 2010 17:07:34 +0100 Subject: [PATCH 179/237] 2010-02-07 Samuel Thibault * commands/i386/pc/play.c (BASE_TEMPO): Set to 60 * GRUB_TICKS_PER_SECOND instead of 120. --- ChangeLog | 5 +++++ commands/i386/pc/play.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 8d654ce88..03388c7f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-07 Samuel Thibault + + * commands/i386/pc/play.c (BASE_TEMPO): Set to 60 * + GRUB_TICKS_PER_SECOND instead of 120. + 2010-02-14 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Wait for possible diff --git a/commands/i386/pc/play.c b/commands/i386/pc/play.c index 1151dddf4..04bf8625d 100644 --- a/commands/i386/pc/play.c +++ b/commands/i386/pc/play.c @@ -29,7 +29,7 @@ #include #include -#define BASE_TEMPO 120 +#define BASE_TEMPO (60 * GRUB_TICKS_PER_SECOND) /* The speaker port. */ #define SPEAKER 0x61 From 14da0fb7e81cc5f46903201563f8d3302d25a88c Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 14 Feb 2010 17:25:52 +0100 Subject: [PATCH 180/237] 2010-02-14 Samuel Thibault * commands/i386/pc/play.c (T_REST, T_FINE, struct note, beep_on): Use grub_uint16_t instead of short. (grub_cmd_play): Use grub_uint32_t instead of int, convert data from disk from little endian to cpu endianness. --- ChangeLog | 7 +++++++ commands/i386/pc/play.c | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 03388c7f3..950a26f3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-02-14 Samuel Thibault + + * commands/i386/pc/play.c (T_REST, T_FINE, struct note, beep_on): Use + grub_uint16_t instead of short. + (grub_cmd_play): Use grub_uint32_t instead of int, convert data from + disk from little endian to cpu endianness. + 2010-02-07 Samuel Thibault * commands/i386/pc/play.c (BASE_TEMPO): Set to 60 * diff --git a/commands/i386/pc/play.c b/commands/i386/pc/play.c index 04bf8625d..84819b551 100644 --- a/commands/i386/pc/play.c +++ b/commands/i386/pc/play.c @@ -101,13 +101,13 @@ #define PIT_CTRL_COUNT_BINARY 0x00 /* 16-bit binary counter. */ #define PIT_CTRL_COUNT_BCD 0x01 /* 4-decade BCD counter. */ -#define T_REST ((short) 0) -#define T_FINE ((short) -1) +#define T_REST ((grub_uint16_t) 0) +#define T_FINE ((grub_uint16_t) -1) struct note { - short pitch; - short duration; + grub_uint16_t pitch; + grub_uint16_t duration; }; static void @@ -120,7 +120,7 @@ beep_off (void) } static void -beep_on (short pitch) +beep_on (grub_uint16_t pitch) { unsigned char status; unsigned int counter; @@ -149,7 +149,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), { grub_file_t file; struct note buf; - int tempo; + grub_uint32_t tempo; unsigned int to; if (argc != 1) @@ -166,12 +166,18 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), "file doesn't even contains a full tempo record"); } + tempo = grub_le_to_cpu32(tempo); + grub_dprintf ("play","tempo = %d\n", tempo); while (grub_file_read (file, &buf, - sizeof (struct note)) == sizeof (struct note) - && buf.pitch != T_FINE && grub_checkkey () < 0) + sizeof (struct note)) == sizeof (struct note)) { + buf.pitch = grub_le_to_cpu16(buf.pitch); + buf.duration = grub_le_to_cpu16(buf.duration); + + if (buf.pitch == T_FINE || grub_checkkey () >= 0) + break; grub_dprintf ("play", "pitch = %d, duration = %d\n", buf.pitch, buf.duration); From 37c8483b9756d3ea161d0f7a123c4bd57e1cddaf Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 14 Feb 2010 18:14:16 +0100 Subject: [PATCH 181/237] 2010-02-14 Samuel Thibault * commands/i386/pc/play.c (grub_cmd_play): If grub_file_open fails, parse arguments as inline tempo and notes. Move code for playing notes to... (play): ... new function. --- ChangeLog | 7 +++ commands/i386/pc/play.c | 125 +++++++++++++++++++++++++++------------- 2 files changed, 92 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 950a26f3d..60a1f5db3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-02-14 Samuel Thibault + + * commands/i386/pc/play.c (grub_cmd_play): If grub_file_open fails, + parse arguments as inline tempo and notes. Move code for playing notes + to... + (play): ... new function. + 2010-02-14 Samuel Thibault * commands/i386/pc/play.c (T_REST, T_FINE, struct note, beep_on): Use diff --git a/commands/i386/pc/play.c b/commands/i386/pc/play.c index 84819b551..1bca3d763 100644 --- a/commands/i386/pc/play.c +++ b/commands/i386/pc/play.c @@ -143,66 +143,111 @@ beep_on (grub_uint16_t pitch) grub_outb (status | SPEAKER_TMR2 | SPEAKER_DATA, SPEAKER); } +/* Returns whether playing should continue. */ +static int +play (unsigned tempo, struct note *note) +{ + unsigned int to; + + if (note->pitch == T_FINE || grub_checkkey () >= 0) + return 1; + + grub_dprintf ("play", "pitch = %d, duration = %d\n", note->pitch, + note->duration); + + switch (note->pitch) + { + case T_REST: + beep_off (); + break; + + default: + beep_on (note->pitch); + break; + } + + to = grub_get_rtc () + BASE_TEMPO * note->duration / tempo; + while (((unsigned int) grub_get_rtc () <= to) && (grub_checkkey () < 0)) + ; + + return 0; +} + static grub_err_t grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { grub_file_t file; - struct note buf; - grub_uint32_t tempo; - unsigned int to; - if (argc != 1) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required"); + if (argc < 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name or tempo and notes required"); file = grub_file_open (args[0]); - if (! file) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); - - if (grub_file_read (file, &tempo, sizeof(tempo)) != sizeof(tempo)) + if (file) { - grub_file_close (file); - return grub_error (GRUB_ERR_FILE_READ_ERROR, - "file doesn't even contains a full tempo record"); - } + struct note buf; + grub_uint32_t tempo; - tempo = grub_le_to_cpu32(tempo); - - grub_dprintf ("play","tempo = %d\n", tempo); - - while (grub_file_read (file, &buf, - sizeof (struct note)) == sizeof (struct note)) - { - buf.pitch = grub_le_to_cpu16(buf.pitch); - buf.duration = grub_le_to_cpu16(buf.duration); - - if (buf.pitch == T_FINE || grub_checkkey () >= 0) - break; - - grub_dprintf ("play", "pitch = %d, duration = %d\n", buf.pitch, - buf.duration); - - switch (buf.pitch) + if (grub_file_read (file, &tempo, sizeof (tempo)) != sizeof (tempo)) { - case T_REST: - beep_off (); - break; + grub_file_close (file); + return grub_error (GRUB_ERR_FILE_READ_ERROR, + "file doesn't even contains a full tempo record"); + } - default: - beep_on (buf.pitch); + tempo = grub_le_to_cpu32 (tempo); + grub_dprintf ("play","tempo = %d\n", tempo); + + while (grub_file_read (file, &buf, + sizeof (struct note)) == sizeof (struct note)) + { + buf.pitch = grub_le_to_cpu16 (buf.pitch); + buf.duration = grub_le_to_cpu16 (buf.duration); + + if (play (tempo, &buf)) break; } - to = grub_get_rtc () + BASE_TEMPO * buf.duration / tempo; - while (((unsigned int) grub_get_rtc () <= to) && (grub_checkkey () < 0)) - ; + grub_file_close (file); + } + else + { + char *end; + unsigned tempo; + struct note note; + int i; + tempo = grub_strtoul (args[0], &end, 0); + + if (*end) + /* Was not a number either, assume it was supposed to be a file name. */ + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + + grub_dprintf ("play","tempo = %d\n", tempo); + + for (i = 1; i + 1 < argc; i += 2) + { + note.pitch = grub_strtoul (args[i], &end, 0); + if (*end) + { + grub_error (GRUB_ERR_BAD_NUMBER, "bogus pitch number"); + break; + } + + note.duration = grub_strtoul (args[i + 1], &end, 0); + if (*end) + { + grub_error (GRUB_ERR_BAD_NUMBER, "bogus duration number"); + break; + } + + if (play (tempo, ¬e)) + break; + } } beep_off (); - grub_file_close (file); - while (grub_checkkey () > 0) grub_getkey (); From 6fa7cfce657a2862ffd65d581b77443e77bf70b5 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 14 Feb 2010 18:36:26 +0100 Subject: [PATCH 182/237] 2010-02-14 Samuel Thibault * commands/i386/pc/play.c (GRUB_MOD_INIT(play)): Fix help. * docs/grub.texi (Command-line and menu entry commands): Document play command. --- ChangeLog | 6 ++++++ commands/i386/pc/play.c | 3 ++- docs/grub.texi | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 60a1f5db3..74f4380f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-02-14 Samuel Thibault + + * commands/i386/pc/play.c (GRUB_MOD_INIT(play)): Fix help. + * docs/grub.texi (Command-line and menu entry commands): Document play + command. + 2010-02-14 Samuel Thibault * commands/i386/pc/play.c (grub_cmd_play): If grub_file_open fails, diff --git a/commands/i386/pc/play.c b/commands/i386/pc/play.c index 1bca3d763..44d98a1f0 100644 --- a/commands/i386/pc/play.c +++ b/commands/i386/pc/play.c @@ -259,7 +259,8 @@ static grub_command_t cmd; GRUB_MOD_INIT(play) { cmd = grub_register_command ("play", grub_cmd_play, - N_("FILE"), N_("Play a tune.")); + N_("FILE | TEMPO [PITCH1 DURATION1] [PITCH2 DURATION2] ... "), + N_("Play a tune.")); } GRUB_MOD_FINI(play) diff --git a/docs/grub.texi b/docs/grub.texi index 4fa44462e..f8a9bc414 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1126,6 +1126,7 @@ you forget a command, you can run the command @command{help} * insmod:: Insert a module * keystatus:: Check key modifier status * ls:: List devices or files +* play:: Play a tune * reboot:: Reboot your computer * set:: Set an environment variable * unset:: Unset an environment variable @@ -1364,6 +1365,24 @@ name syntax}), then list the contents of that directory. @end deffn +@node play +@subsection play + +@deffn Command play file | tempo [pitch1 duration1] [pitch2 duration2] ... +Plays a tune + +If the argument is a file name (@pxref{File name syntax}), play the tune +recorded in it. The file format is first the tempo as an unsigned 32bit +little-endian number, then pairs of unsigned 16bit little-endian numbers for +pitch and duration pairs. + +If the arguments are a series of numbers, play the inline tune. + +The tempo is the base for all note durations. 60 gives a 1-second base, 120 +gives a half-second base, etc. Pitches are Hz. +@end deffn + + @node reboot @subsection reboot From a3334e79e8dbba33491e6cdee540f20bc7eebd80 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Feb 2010 20:03:19 +0100 Subject: [PATCH 183/237] Revert gratuituos change of alias.name --- kern/ieee1275/openfw.c | 18 ++---------------- video/ieee1275.c | 4 ++-- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/kern/ieee1275/openfw.c b/kern/ieee1275/openfw.c index 92ab2f683..ee8520359 100644 --- a/kern/ieee1275/openfw.c +++ b/kern/ieee1275/openfw.c @@ -68,7 +68,6 @@ grub_children_iterate (char *devpath, { struct grub_ieee1275_devalias alias; grub_ssize_t actual; - char *fullname; if (grub_ieee1275_get_property (child, "device_type", childtype, IEEE1275_MAX_PROP_LEN, &actual)) @@ -82,23 +81,10 @@ grub_children_iterate (char *devpath, IEEE1275_MAX_PROP_LEN, &actual)) continue; - if (devpath[0] == '/' && devpath[1] == 0) - fullname = grub_xasprintf ("/%s", childname); - else - fullname = grub_xasprintf ("%s/%s", devpath, childname); - if (!fullname) - { - grub_free (childname); - grub_free (childpath); - grub_free (childtype); - return 0; - } - alias.type = childtype; alias.path = childpath; - alias.name = fullname; + alias.name = childname; ret = hook (&alias); - grub_free (fullname); if (ret) break; } @@ -119,7 +105,7 @@ grub_ieee1275_devices_iterate (int (*hook) (struct grub_ieee1275_devalias *alias { if (hook (alias)) return 1; - return grub_children_iterate (alias->name, it_through); + return grub_children_iterate (alias->path, it_through); } return grub_children_iterate ("/", it_through); diff --git a/video/ieee1275.c b/video/ieee1275.c index 21b65bd32..3f0b93fb8 100644 --- a/video/ieee1275.c +++ b/video/ieee1275.c @@ -59,8 +59,8 @@ find_display (void) { if (grub_strcmp (alias->type, "display") == 0) { - grub_dprintf ("video", "Found display %s\n", alias->name); - display = grub_strdup (alias->name); + grub_dprintf ("video", "Found display %s\n", alias->path); + display = grub_strdup (alias->path); return 1; } return 0; From 8886d76d245b68d63c11a98038ba2000b83c0919 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Feb 2010 20:04:26 +0100 Subject: [PATCH 184/237] Rename get_time_args to set_time_args --- lib/ieee1275/datetime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ieee1275/datetime.c b/lib/ieee1275/datetime.c index aaf17b0fa..ef37724ed 100644 --- a/lib/ieee1275/datetime.c +++ b/lib/ieee1275/datetime.c @@ -94,7 +94,7 @@ grub_get_datetime (struct grub_datetime *datetime) grub_err_t grub_set_datetime (struct grub_datetime *datetime) { - struct get_time_args + struct set_time_args { struct grub_ieee1275_common_hdr common; grub_ieee1275_cell_t method; From 07096a4f27bdc9f66e239b2e938a8634b55d00eb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Feb 2010 20:05:09 +0100 Subject: [PATCH 185/237] Use alias->path --- lib/ieee1275/datetime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ieee1275/datetime.c b/lib/ieee1275/datetime.c index ef37724ed..7e6f8d1f1 100644 --- a/lib/ieee1275/datetime.c +++ b/lib/ieee1275/datetime.c @@ -31,8 +31,8 @@ find_rtc (void) { if (grub_strcmp (alias->type, "rtc") == 0) { - grub_dprintf ("datetime", "Found RTC %s\n", alias->name); - rtc = grub_strdup (alias->name); + grub_dprintf ("datetime", "Found RTC %s\n", alias->path); + rtc = grub_strdup (alias->path); return 1; } return 0; From 0dd1e0dd38107f60c8281ea9b9eb912bbf575aff Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 15 Feb 2010 18:59:40 +0100 Subject: [PATCH 186/237] 2010-02-15 Vladimir Serbinenko * gensymlist.sh.in: Use TARGET_CC instead of CC. --- ChangeLog | 4 ++++ gensymlist.sh.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 74f4380f6..a080c450c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-15 Vladimir Serbinenko + + * gensymlist.sh.in: Use TARGET_CC instead of CC. + 2010-02-14 Samuel Thibault * commands/i386/pc/play.c (GRUB_MOD_INIT(play)): Fix help. diff --git a/gensymlist.sh.in b/gensymlist.sh.in index 27fc5e61a..7cd3b48e3 100644 --- a/gensymlist.sh.in +++ b/gensymlist.sh.in @@ -14,7 +14,7 @@ ### The configure script will replace these variables. : ${srcdir=@srcdir@} -: ${CC=@CC@} +: ${CC=@TARGET_CC@} cat < Date: Mon, 15 Feb 2010 19:01:38 +0100 Subject: [PATCH 187/237] 2010-02-15 Vladimir Serbinenko * term/serial.c (serial_get_divisor) [GRUB_MACHINE_MIPS_YEELOONG]: Double divisor. (serial_hw_init) [GRUB_MACHINE_MIPS_YEELOONG]: Don't enable advanced features. (GRUB_MOD_INIT) [GRUB_MACHINE_MIPS_YEELOONG]: Default to 115200. --- ChangeLog | 8 ++++++++ term/serial.c | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ChangeLog b/ChangeLog index a080c450c..c2948b20b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-02-15 Vladimir Serbinenko + + * term/serial.c (serial_get_divisor) [GRUB_MACHINE_MIPS_YEELOONG]: + Double divisor. + (serial_hw_init) [GRUB_MACHINE_MIPS_YEELOONG]: Don't enable advanced + features. + (GRUB_MOD_INIT) [GRUB_MACHINE_MIPS_YEELOONG]: Default to 115200. + 2010-02-15 Vladimir Serbinenko * gensymlist.sh.in: Use TARGET_CC instead of CC. diff --git a/term/serial.c b/term/serial.c index 62cd11fee..05497ce40 100644 --- a/term/serial.c +++ b/term/serial.c @@ -232,7 +232,12 @@ serial_get_divisor (unsigned int speed) /* Set the baud rate. */ for (i = 0; i < sizeof (divisor_tab) / sizeof (divisor_tab[0]); i++) if (divisor_tab[i].speed == speed) + /* UART in Yeeloong runs twice the usual rate. */ +#ifdef GRUB_MACHINE_MIPS_YEELOONG + return 2 * divisor_tab[i].div; +#else return divisor_tab[i].div; +#endif return 0; } @@ -292,11 +297,14 @@ serial_hw_init (void) | serial_settings.stop_bits); grub_outb (status, serial_settings.port + UART_LCR); + /* In Yeeloong serial port has only 3 wires. */ +#ifndef GRUB_MACHINE_MIPS_YEELOONG /* Enable the FIFO. */ grub_outb (UART_ENABLE_FIFO, serial_settings.port + UART_FCR); /* Turn on DTR, RTS, and OUT2. */ grub_outb (UART_ENABLE_MODEM, serial_settings.port + UART_MCR); +#endif /* Drain the input buffer. */ while (grub_serial_checkkey () != -1) @@ -613,7 +621,11 @@ GRUB_MOD_INIT(serial) /* Set default settings. */ serial_settings.port = serial_hw_get_port (0); +#ifdef GRUB_MACHINE_MIPS_YEELOONG + serial_settings.divisor = serial_get_divisor (115200); +#else serial_settings.divisor = serial_get_divisor (9600); +#endif serial_settings.word_len = UART_8BITS_WORD; serial_settings.parity = UART_NO_PARITY; serial_settings.stop_bits = UART_1_STOP_BIT; From 13b6d963eaf38d6029b5c3a2f696a573a55a97b3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 15 Feb 2010 19:03:07 +0100 Subject: [PATCH 188/237] Fix yeeloong compilation --- kern/mips/yeeloong/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kern/mips/yeeloong/init.c b/kern/mips/yeeloong/init.c index d148d08dc..1a29a9af6 100644 --- a/kern/mips/yeeloong/init.c +++ b/kern/mips/yeeloong/init.c @@ -68,7 +68,7 @@ grub_machine_init (void) { grub_addr_t modend; modend = grub_modules_get_end (); - grub_mm_init_region (modend, (grub_arch_memsize << 20) + grub_mm_init_region ((void *) modend, (grub_arch_memsize << 20) - (modend - GRUB_ARCH_LOWMEMVSTART)); /* FIXME: use upper memory as well. */ grub_install_get_time_ms (grub_rtc_get_time_ms); From 2793c71ea948b5849723f578984950e546a805ca Mon Sep 17 00:00:00 2001 From: Georgy Buranov Date: Tue, 16 Feb 2010 13:13:02 +0100 Subject: [PATCH 189/237] 2010-02-16 Georgy Buranov * disk/efi/efidisk.c (grub_efidisk_get_device_name): Fix a typo. --- ChangeLog | 4 ++++ disk/efi/efidisk.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c2948b20b..d6925f0dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-16 Georgy Buranov + + * disk/efi/efidisk.c (grub_efidisk_get_device_name): Fix a typo. + 2010-02-15 Vladimir Serbinenko * term/serial.c (serial_get_divisor) [GRUB_MACHINE_MIPS_YEELOONG]: diff --git a/disk/efi/efidisk.c b/disk/efi/efidisk.c index 58300a0d2..f9c6f3153 100644 --- a/disk/efi/efidisk.c +++ b/disk/efi/efidisk.c @@ -825,7 +825,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) if (! disk) return 1; - if (disk->id == GRUB_DISK_DEVICE_EFIDISK_ID) + if (disk->dev->id == GRUB_DISK_DEVICE_EFIDISK_ID) { struct grub_efidisk_data *d; From d9f31a41ca6acb44a0f4d0ee78e0d464e3167fef Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 16 Feb 2010 13:23:08 +0100 Subject: [PATCH 190/237] 2010-02-16 Vladimir Serbinenko Remove any reference to non-free fonts. * commands/videotest.c (grub_cmd_videotest): Use unifont by default. * docs/gfxmenu-theme-example.txt: Removed. It's both outdated and uses non-free components. * font/font.c (grub_font_get_name): Remove example name. * gfxmenu/gui_label.c (grub_gui_label_new): Use unifont by default. * gfxmenu/gui_list.c (grub_gui_list_new): Likewise. * gfxmenu/gui_progress_bar.c (grub_gui_progress_bar_new): Likewise. * gfxmenu/view.c (grub_gfxmenu_view_new): Likewise. --- ChangeLog | 13 ++++ commands/videotest.c | 11 +-- docs/gfxmenu-theme-example.txt | 128 --------------------------------- font/font.c | 2 +- gfxmenu/gui_label.c | 2 +- gfxmenu/gui_list.c | 2 +- gfxmenu/gui_progress_bar.c | 2 +- gfxmenu/view.c | 2 +- 8 files changed, 21 insertions(+), 141 deletions(-) delete mode 100644 docs/gfxmenu-theme-example.txt diff --git a/ChangeLog b/ChangeLog index d6925f0dd..1817ad732 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-02-16 Vladimir Serbinenko + + Remove any reference to non-free fonts. + + * commands/videotest.c (grub_cmd_videotest): Use unifont by default. + * docs/gfxmenu-theme-example.txt: Removed. It's both outdated and + uses non-free components. + * font/font.c (grub_font_get_name): Remove example name. + * gfxmenu/gui_label.c (grub_gui_label_new): Use unifont by default. + * gfxmenu/gui_list.c (grub_gui_list_new): Likewise. + * gfxmenu/gui_progress_bar.c (grub_gui_progress_bar_new): Likewise. + * gfxmenu/view.c (grub_gfxmenu_view_new): Likewise. + 2010-02-16 Georgy Buranov * disk/efi/efidisk.c (grub_efidisk_get_device_name): Fix a typo. diff --git a/commands/videotest.c b/commands/videotest.c index 1730a2031..390811a71 100644 --- a/commands/videotest.c +++ b/commands/videotest.c @@ -69,9 +69,9 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)), color = grub_video_map_rgb (0, 255, 255); grub_video_fill_rect (color, 100, 100, 100, 100); - sansbig = grub_font_get ("Helvetica Bold 24"); - sans = grub_font_get ("Helvetica Bold 14"); - sanssmall = grub_font_get ("Helvetica 8"); + sansbig = grub_font_get ("Unknown Regular 16"); + sans = grub_font_get ("Unknown Regular 16"); + sanssmall = grub_font_get ("Unknown Regular 16"); fixed = grub_font_get ("Fixed 20"); if (! sansbig || ! sans || ! sanssmall || ! fixed) return grub_error (GRUB_ERR_BAD_FONT, "no font loaded"); @@ -126,11 +126,6 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)), grub_font_draw_string (str, fixed, color, 16, texty); texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed); - /* Some character don't exist in the Helvetica font, so the font engine - will fall back to using glyphs from another font that does contain them. - TODO The font engine should be smart about selecting a replacement font - and prioritize fonts with similar sizes. */ - texty += grub_font_get_ascent(sansbig); grub_font_draw_string (str, sansbig, color, 16, texty); texty += grub_font_get_descent (sansbig) + grub_font_get_leading (sansbig); diff --git a/docs/gfxmenu-theme-example.txt b/docs/gfxmenu-theme-example.txt deleted file mode 100644 index 4363dc8df..000000000 --- a/docs/gfxmenu-theme-example.txt +++ /dev/null @@ -1,128 +0,0 @@ -# GRUB gfxmenu theme "winter". -# Uses background image from: -# http://www.cyberpunkcafe.com/e107_plugins/autogallery/autogallery.php?show=1.Open%20Source%20Wallpaper -# "without-leaves.png" was called "Without Leafs in Winter.png" - -lua-script: "winter.lua" -title-text: "" -title-font: "Helvetica Bold 18" -status-font: "Helvetica 8" -terminal-font: "Fixed 9" -title-color: "40, 40, 40" -status-color: "#FFF" -status-bg-color: "0, 166, 183, 128" -desktop-image: "without-leaves.png" -desktop-color: "0, 154, 183" -terminal-box: "terminal_*.png" - -+ boot_menu { - position = (120, 60) - preferred_size = (400, -1) - item_font = "Helvetica Bold 14" - selected_item_font = "Helvetica Bold 14" - item_color = "0, 0, 0" - selected_item_color = "203, 251, 255" - menu_pixmap_style = "menu_*.png" - selected_item_pixmap_style = "select_*.png" - icon_width = 44 - icon_height = 44 - item_height = 32 - item_padding = 0 - item_icon_space = 3 - item_spacing = 11 -} - -# You can add text at arbitrary locations on the screen. -# The specification within the "+label {...}" block is free-form, -# so you can use as much or as little white space as you like. - -+ label { - position = (170, 50) - font = "smoothansi 13" - color = "0,0,128" - text = "This is the Winter theme ... brought to you by GRUB!" -} - -# Show the text alignment supported by labels. -+ vbox { - position = (220, 347) - preferred_size = (200, -1) # A preferred size of -1 means automatic. - + label { text="Text alignment demo" align="center" font="aqui 11" } - + label { text="Left" align="left" font="cure 11" } - + label { text="Center" align="center" font="cure 11" } - + label { text="Right" align="right" font="cure 11" } -} - -+ vbox { - position = (580, 10) - + label { text="GNU" font="gelly 11" color="0, 0, 0" } - + label { text="GRUB" font="aqui 11" color="0, 0, 0" } - + label { text="boot loader" font="cure 11" color="0, 0, 0" } -} - -+ hbox { - position = (80, 10) - + label { text="GNU" font="gelly 11" color="0, 0, 0" } - + label { text="GRUB" font="aqui 11" color="0, 0, 0" } - + label { text="boot loader" font="cure 11" color="0, 0, 0" } -} - -# Demonstration of a compound layout: boxes within boxes. -+ hbox -{ - position = (480, 3) - - + vbox - { - # Note: We can't just use 'size' to set the image's size, - # since the vbox will resize the component according to its - # preferred size, which for images is the native image size. - - + image { file="/boot/grub/themes/icons/ubuntu.png" - preferred_size = (20, 20) } - + image { file="/boot/grub/themes/icons/gentoo.png" - preferred_size = (20, 20) } - } - - + vbox - { - + label { text="GRand" font="cure 11" color=#99F } - + label { text="Unified" font="cure 11" color=#BBF } - + label { text="Bootloader" font="cure 11" color=#DDF } - } -} - -# By defining a 'progress_bar' type component with an ID of '__timeout__', -# the progress bar will be used to display the time remaining before an -# the default entry is automatically booted. -+ progress_bar -{ - id = "__timeout__" - position = (80, 393) - preferred_size = (500, 24) - font = "cure 11" - text_color = #000 - fg_color = #CCF - bg_color = #66B - border_color = #006 - show_text = false -} - -# Although the progress_bar component is normally used to indicate the -# time remaining, it's also possible to create other components with an ID -# of '__timeout__'. All components with and ID of 'timeout_bar' will have -# the following properties set based on the timeout value: -# text, value, start, end, visible. -# In this case, we have set 'show_text=false' on the progress bar, and use -# the following label's 'text' property to display the message. -+ label -{ - id = "__timeout__" - position = (80, 420) - preferred_size = (500, 24) - font = "lime 11" - color = #117 - align = "center" -} - - diff --git a/font/font.c b/font/font.c index 16f2ed35b..1b3dc6387 100644 --- a/font/font.c +++ b/font/font.c @@ -862,7 +862,7 @@ grub_font_get (const char *font_name) return &null_font; } -/* Get the full name of the font. For instance, "Helvetica Bold 12". */ +/* Get the full name of the font. */ const char * grub_font_get_name (grub_font_t font) { diff --git a/gfxmenu/gui_label.c b/gfxmenu/gui_label.c index b2835ea1a..a9dd575ac 100644 --- a/gfxmenu/gui_label.c +++ b/gfxmenu/gui_label.c @@ -216,7 +216,7 @@ grub_gui_label_new (void) label->comp.ops = &label_ops; label->visible = 1; label->text = grub_strdup (""); - label->font = grub_font_get ("Helvetica 10"); + label->font = grub_font_get ("Unknown Regular 16"); label->color.red = 0; label->color.green = 0; label->color.blue = 0; diff --git a/gfxmenu/gui_list.c b/gfxmenu/gui_list.c index a78339385..0d771413f 100644 --- a/gfxmenu/gui_list.c +++ b/gfxmenu/gui_list.c @@ -566,7 +566,7 @@ grub_gui_list_new (void) self->visible = 1; - default_font = grub_font_get ("Helvetica 12"); + default_font = grub_font_get ("Unknown Regular 16"); default_fg_color = grub_gui_color_rgb (0, 0, 0); default_bg_color = grub_gui_color_rgb (255, 255, 255); diff --git a/gfxmenu/gui_progress_bar.c b/gfxmenu/gui_progress_bar.c index 4fda61d49..d786aae31 100644 --- a/gfxmenu/gui_progress_bar.c +++ b/gfxmenu/gui_progress_bar.c @@ -371,7 +371,7 @@ grub_gui_progress_bar_new (void) self->progress.ops = &progress_bar_pb_ops; self->progress.component.ops = &progress_bar_ops; self->visible = 1; - self->font = grub_font_get ("Helvetica 10"); + self->font = grub_font_get ("Unknown Regular 16"); grub_gui_color_t black = { .red = 0, .green = 0, .blue = 0, .alpha = 255 }; grub_gui_color_t gray = { .red = 128, .green = 128, .blue = 128, .alpha = 255 }; grub_gui_color_t lightgray = { .red = 200, .green = 200, .blue = 200, .alpha = 255 }; diff --git a/gfxmenu/view.c b/gfxmenu/view.c index 611c01e1b..bf637a96d 100644 --- a/gfxmenu/view.c +++ b/gfxmenu/view.c @@ -66,7 +66,7 @@ grub_gfxmenu_view_new (const char *theme_path, view->screen.width = width; view->screen.height = height; - default_font = grub_font_get ("Helvetica 12"); + default_font = grub_font_get ("Unknown Regular 16"); default_fg_color = grub_gui_color_rgb (0, 0, 0); default_bg_color = grub_gui_color_rgb (255, 255, 255); From 0a39de87d9371ce8d1a844a6f52bdc81ae257420 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 18 Feb 2010 08:56:31 +0100 Subject: [PATCH 191/237] 2010-02-14 Samuel Thibault * util/grub-mkconfig.in: Export GRUB_INIT_TUNE. * util/grub.d/00_header.in: Handle GRUB_INIT_TUNE. --- ChangeLog | 5 +++++ util/grub-mkconfig.in | 3 ++- util/grub.d/00_header.in | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1817ad732..38bb39ac9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-14 Samuel Thibault + + * util/grub-mkconfig.in: Export GRUB_INIT_TUNE. + * util/grub.d/00_header.in: Handle GRUB_INIT_TUNE. + 2010-02-16 Vladimir Serbinenko Remove any reference to non-free fonts. diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index 1363f479a..fb1dd4544 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -222,7 +222,8 @@ export GRUB_DEFAULT \ GRUB_GFXMODE \ GRUB_THEME \ GRUB_GFXPAYLOAD_LINUX \ - GRUB_DISABLE_OS_PROBER + GRUB_DISABLE_OS_PROBER \ + GRUB_INIT_TUNE if test "x${grub_cfg}" != "x"; then rm -f ${grub_cfg}.new diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index a7b051daf..c86f7b867 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -158,3 +158,11 @@ else set timeout=${GRUB_TIMEOUT} EOF fi + +# Play an initial tune +if [ "x${GRUB_INIT_TUNE}" != "x" ] ; then + cat << EOF +insmod play +play ${GRUB_INIT_TUNE} +EOF +fi From 42b1d186858987e2672ac0c483fe47d864193f87 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 20 Feb 2010 11:15:51 +0100 Subject: [PATCH 192/237] 2010-02-20 Vladimir Serbinenko * video/fb/video_fb.c (grub_video_fb_scroll): Fix a pixel size bug. Reported by: Michael Suchanek. --- ChangeLog | 7 ++++++- video/fb/video_fb.c | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 38bb39ac9..ca8e3c3fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ -2010-02-14 Samuel Thibault +2010-02-20 Vladimir Serbinenko + + * video/fb/video_fb.c (grub_video_fb_scroll): Fix a pixel size bug. + Reported by: Michael Suchanek. + +2010-02-18 Samuel Thibault * util/grub-mkconfig.in: Export GRUB_INIT_TUNE. * util/grub.d/00_header.in: Handle GRUB_INIT_TUNE. diff --git a/video/fb/video_fb.c b/video/fb/video_fb.c index 65652c3cf..9c5577bb9 100644 --- a/video/fb/video_fb.c +++ b/video/fb/video_fb.c @@ -1006,11 +1006,13 @@ grub_video_fb_scroll (grub_video_color_t color, int dx, int dy) { \ /* 3b. Move data downwards. */ \ dst = (void *) grub_video_fb_get_video_ptr (&target, \ - dst_x + width - 1, \ + dst_x + width, \ dst_y + height - 1); \ src = (void *) grub_video_fb_get_video_ptr (&target, \ - src_x + width - 1, \ + src_x + width, \ src_y + height - 1); \ + dst--; \ + src--; \ for (j = 0; j < height; j++) \ { \ for (i = 0; i < linelen; i++) \ From d1484a422ec7d94394e17277584a28730f92ff4e Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Sat, 20 Feb 2010 11:23:13 +0100 Subject: [PATCH 193/237] 2010-02-20 Manoel Rebelo Abranches * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Add delete and backspace keys. --- ChangeLog | 5 ++ term/ieee1275/ofconsole.c | 119 ++++++++++++++++++++++++-------------- 2 files changed, 79 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca8e3c3fd..95dcd51a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-20 Manoel Rebelo Abranches + + * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Add delete and + backspace keys. + 2010-02-20 Vladimir Serbinenko * video/fb/video_fb.c (grub_video_fb_scroll): Fix a pixel size bug. diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index 82108022a..a4ffdcd23 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -202,53 +202,82 @@ grub_ofconsole_readkey (int *key) grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); - if (actual > 0 && c == '\e') - { - grub_uint64_t start; - grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); - - /* On 9600 we have to wait up to 12 milliseconds. */ - start = grub_get_time_ms (); - while (actual <= 0 && grub_get_time_ms () - start < 12) - grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); - - if (actual <= 0) + if (actual > 0) + switch(c) + { + case 0x7f: + /* Backspace: Ctrl-h. */ + c = '\b'; + break; + case '\e': { - *key = '\e'; - return 1; + grub_uint64_t start; + grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); + + /* On 9600 we have to wait up to 12 milliseconds. */ + start = grub_get_time_ms (); + while (actual <= 0 && grub_get_time_ms () - start < 12) + grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); + + if (actual <= 0) + { + *key = '\e'; + return 1; + } + + if (c != '[') + return 0; + + grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); + + /* On 9600 we have to wait up to 12 milliseconds. */ + start = grub_get_time_ms (); + while (actual <= 0 && grub_get_time_ms () - start < 12) + grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); + if (actual <= 0) + return 0; + + switch (c) + { + case 'A': + /* Up: Ctrl-p. */ + c = GRUB_TERM_UP; + break; + case 'B': + /* Down: Ctrl-n. */ + c = GRUB_TERM_DOWN; + break; + case 'C': + /* Right: Ctrl-f. */ + c = GRUB_TERM_RIGHT; + break; + case 'D': + /* Left: Ctrl-b. */ + c = GRUB_TERM_LEFT; + break; + case '3': + { + grub_uint64_t start; + grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); + /* On 9600 we have to wait up to 12 milliseconds. */ + start = grub_get_time_ms (); + while (actual <= 0 && grub_get_time_ms () - start < 12) + grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); + + if (actual <= 0) + return 0; + + /* Delete: Ctrl-d. */ + if (c == '~') + c = GRUB_TERM_DC; + else + return 0; + break; + } + break; + } } - - if (c != '[') - return 0; - - grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); - /* On 9600 we have to wait up to 12 milliseconds. */ - start = grub_get_time_ms (); - while (actual <= 0 && grub_get_time_ms () - start < 12) - grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); - if (actual <= 0) - return 0; - - switch (c) - { - case 'A': - /* Up: Ctrl-p. */ - c = GRUB_TERM_UP; - break; - case 'B': - /* Down: Ctrl-n. */ - c = GRUB_TERM_DOWN; - break; - case 'C': - /* Right: Ctrl-f. */ - c = GRUB_TERM_RIGHT; - break; - case 'D': - /* Left: Ctrl-b. */ - c = GRUB_TERM_LEFT; - break; - } - } + } *key = c; return actual > 0; From 7dd05b96dcda4ad27b3d3a4d3025d1e9a3bce1e6 Mon Sep 17 00:00:00 2001 From: carles Date: Sat, 20 Feb 2010 23:31:35 +0000 Subject: [PATCH 194/237] 2010-02-20 Carles Pina i Estany * util/grub-mkrawimage.c (usage): Change string formatting to improve gettext. --- ChangeLog | 5 +++++ util/grub-mkrawimage.c | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 95dcd51a7..fbfe0ef6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-20 Carles Pina i Estany + + * util/grub-mkrawimage.c (usage): Change string formatting to + improve gettext. + 2010-02-20 Manoel Rebelo Abranches * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Add delete and diff --git a/util/grub-mkrawimage.c b/util/grub-mkrawimage.c index 83bb51c02..dd84f2d81 100644 --- a/util/grub-mkrawimage.c +++ b/util/grub-mkrawimage.c @@ -446,10 +446,8 @@ Make a bootable image of GRUB.\n\ -o, --output=FILE output a generated image to FILE [default=stdout]\n" #ifdef GRUB_PLATFORM_IMAGE_DEFAULT "\ - -O, --format=FORMAT generate an image in format [default=" - GRUB_PLATFORM_IMAGE_DEFAULT_FORMAT "]\n \ - available formats: " - GRUB_PLATFORM_IMAGE_FORMATS "\n" + -O, --format=FORMAT generate an image in format [default=%s]\n\ + available formats: %s\n" #endif "\ -h, --help display this message and exit\n\ @@ -457,7 +455,12 @@ Make a bootable image of GRUB.\n\ -v, --verbose print verbose messages\n\ \n\ Report bugs to <%s>.\n\ -"), program_name, GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); +"), +program_name, GRUB_LIBDIR, DEFAULT_DIRECTORY, +#ifdef GRUB_PLATFORM_IMAGE_DEFAULT + GRUB_PLATFORM_IMAGE_DEFAULT_FORMAT, GRUB_PLATFORM_IMAGE_FORMATS, +#endif +PACKAGE_BUGREPORT); exit (status); } From 618307dd08e2a1e710ed2d3122b1ae6146c0850f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 22 Feb 2010 09:18:59 +0100 Subject: [PATCH 195/237] 2010-02-20 Vladimir Serbinenko * fs/iso9660.c (grub_iso9660_iterate_dir): Strip version from joliet filename. Reported by: Georgy Buranov --- ChangeLog | 6 ++++++ fs/iso9660.c | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fbfe0ef6a..509870f95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-02-20 Vladimir Serbinenko + + * fs/iso9660.c (grub_iso9660_iterate_dir): Strip version from joliet + filename. + Reported by: Georgy Buranov + 2010-02-20 Carles Pina i Estany * util/grub-mkrawimage.c (usage): Change string formatting to diff --git a/fs/iso9660.c b/fs/iso9660.c index cadfbba2b..6dc465f25 100644 --- a/fs/iso9660.c +++ b/fs/iso9660.c @@ -629,12 +629,16 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, if (dir->data->joliet) { - char *oldname; + char *oldname, *semicolon; oldname = filename; filename = grub_iso9660_convert_string ((grub_uint16_t *) oldname, dirent.namelen >> 1); + semicolon = grub_strrchr (filename, ';'); + if (semicolon) + *semicolon = '\0'; + if (filename_alloc) grub_free (oldname); From 33dfc52f44114ec268eba26e18bcb19668b729d8 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 22 Feb 2010 12:42:13 +0000 Subject: [PATCH 196/237] 2010-02-10 Colin King 2010-02-10 Colin Watson Shrink the pre-partition-table part of boot.img by eight bytes. * boot/i386/pc/boot.S (ERR): New macro. (chs_mode): Use ERR. (geometry_error): Likewise. (hd_probe_error): Remove. This is only used once, so we wrwite it inline instead. (read_error): Instead of printing read_error_string, just set up %si and fall through to ... (error_message): ... this new function, also used by ERR. --- ChangeLog.trim-boot-img | 13 +++++++++++++ boot/i386/pc/boot.S | 18 ++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 ChangeLog.trim-boot-img diff --git a/ChangeLog.trim-boot-img b/ChangeLog.trim-boot-img new file mode 100644 index 000000000..26408af25 --- /dev/null +++ b/ChangeLog.trim-boot-img @@ -0,0 +1,13 @@ +2010-02-10 Colin King +2010-02-10 Colin Watson + + Shrink the pre-partition-table part of boot.img by eight bytes. + + * boot/i386/pc/boot.S (ERR): New macro. + (chs_mode): Use ERR. + (geometry_error): Likewise. + (hd_probe_error): Remove. This is only used once, so we wrwite + it inline instead. + (read_error): Instead of printing read_error_string, just set up + %si and fall through to ... + (error_message): ... this new function, also used by ERR. diff --git a/boot/i386/pc/boot.S b/boot/i386/pc/boot.S index 257f9044e..4afc57349 100644 --- a/boot/i386/pc/boot.S +++ b/boot/i386/pc/boot.S @@ -27,6 +27,7 @@ /* Print message string */ #define MSG(x) movw $x, %si; call LOCAL(message) +#define ERR(x) movw $x, %si; jmp LOCAL(error_message) .file "boot.S" @@ -233,7 +234,7 @@ LOCAL(chs_mode): jz LOCAL(floppy_probe) /* Nope, we definitely have a hard disk, and we're screwed. */ - jmp LOCAL(hd_probe_error) + ERR(hd_probe_error_string) LOCAL(final_init): /* set the mode to zero */ @@ -360,22 +361,15 @@ LOCAL(copy_buffer): * BIOS Geometry translation error (past the end of the disk geometry!). */ LOCAL(geometry_error): - MSG(geometry_error_string) - jmp LOCAL(general_error) - -/* - * Disk probe failure. - */ -LOCAL(hd_probe_error): - MSG(hd_probe_error_string) - jmp LOCAL(general_error) + ERR(geometry_error_string) /* * Read error on the disk. */ LOCAL(read_error): - MSG(read_error_string) - + movw $read_error_string, %si +LOCAL(error_message): + call LOCAL(message) LOCAL(general_error): MSG(general_error_string) From 2b8fa975d4fc8b4759b947b1dc7559ce8e95ff0a Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 24 Feb 2010 10:02:16 +0000 Subject: [PATCH 197/237] 2010-02-24 Joey Korkames * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Remove duplicate declaration of `start'. --- ChangeLog | 5 +++++ term/ieee1275/ofconsole.c | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 509870f95..fb5c42dce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-24 Joey Korkames + + * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Remove + duplicate declaration of `start'. + 2010-02-20 Vladimir Serbinenko * fs/iso9660.c (grub_iso9660_iterate_dir): Strip version from joliet diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index a4ffdcd23..c0f895a15 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -257,7 +257,6 @@ grub_ofconsole_readkey (int *key) break; case '3': { - grub_uint64_t start; grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); /* On 9600 we have to wait up to 12 milliseconds. */ start = grub_get_time_ms (); From f17d332e493775a5ef3ef3e9140d7cf3b9337816 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 24 Feb 2010 11:29:11 +0100 Subject: [PATCH 198/237] Remove trailing spaces in kern/device.c --- kern/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kern/device.c b/kern/device.c index 5cfd190f3..cd019fdaf 100644 --- a/kern/device.c +++ b/kern/device.c @@ -152,7 +152,7 @@ grub_device_iterate (int (*hook) (const char *name)) grub_free (partition_name); grub_free (p); return 1; - } + } grub_free (partition_name); p->next = ents; From 607ffde2caa0d6f9734e519b17040fe4bcaf8995 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 24 Feb 2010 15:21:36 +0100 Subject: [PATCH 199/237] 2010-02-24 Vladimir Serbinenko * loader/i386/multiboot_mbi.c (grub_multiboot_set_bootdev): Fix a memory leak. Reported by: Seth Goldberg. --- ChangeLog | 6 ++++++ loader/i386/multiboot_mbi.c | 1 + 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index fb5c42dce..35ecc7073 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-02-24 Vladimir Serbinenko + + * loader/i386/multiboot_mbi.c (grub_multiboot_set_bootdev): Fix a + memory leak. + Reported by: Seth Goldberg. + 2010-02-24 Joey Korkames * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Remove diff --git a/loader/i386/multiboot_mbi.c b/loader/i386/multiboot_mbi.c index a154d1b23..3f937c446 100644 --- a/loader/i386/multiboot_mbi.c +++ b/loader/i386/multiboot_mbi.c @@ -463,6 +463,7 @@ grub_multiboot_set_bootdev (void) if ((p[0] >= 'a') && (p[0] <= 'z')) part = p[0] - 'a'; } + grub_free (p); } if (dev) grub_device_close (dev); From 4a8a763c7b03814e70ba26b09c2e0c1108b9164a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 24 Feb 2010 15:24:21 +0100 Subject: [PATCH 200/237] 2010-02-24 Vladimir Serbinenko * normal/crypto.c (read_crypto_list): Fix a memory leak. * normal/term.c (read_terminal_list): Likewise. * normal/main.c (grub_normal_init_page): Likewise. (grub_normal_read_line_real): Likewise. --- ChangeLog | 7 +++++++ normal/crypto.c | 1 + normal/main.c | 4 ++++ normal/term.c | 1 + 4 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index 35ecc7073..24981a5fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-02-24 Vladimir Serbinenko + + * normal/crypto.c (read_crypto_list): Fix a memory leak. + * normal/term.c (read_terminal_list): Likewise. + * normal/main.c (grub_normal_init_page): Likewise. + (grub_normal_read_line_real): Likewise. + 2010-02-24 Vladimir Serbinenko * loader/i386/multiboot_mbi.c (grub_multiboot_set_bootdev): Fix a diff --git a/normal/crypto.c b/normal/crypto.c index 932f26f97..95899fbd5 100644 --- a/normal/crypto.c +++ b/normal/crypto.c @@ -88,6 +88,7 @@ read_crypto_list (void) } file = grub_file_open (filename); + grub_free (filename); if (!file) { grub_errno = GRUB_ERR_NONE; diff --git a/normal/main.c b/normal/main.c index 9f8c12773..2306427fc 100644 --- a/normal/main.c +++ b/normal/main.c @@ -418,6 +418,7 @@ grub_normal_init_page (struct grub_term_output *term) msg_len = grub_utf8_to_ucs4_alloc (msg_formatted, &unicode_msg, &last_position); + grub_free (msg_formatted); if (msg_len < 0) { @@ -582,10 +583,13 @@ grub_normal_read_line_real (char **line, int cont, int nested) if (cont || nested) { grub_free (*line); + grub_free (prompt); *line = 0; return grub_errno; } } + + grub_free (prompt); return 0; } diff --git a/normal/term.c b/normal/term.c index 42201fbb3..e31d403ee 100644 --- a/normal/term.c +++ b/normal/term.c @@ -175,6 +175,7 @@ read_terminal_list (void) } file = grub_file_open (filename); + grub_free (filename); if (!file) { grub_errno = GRUB_ERR_NONE; From a0ca21c2d2ccf7cb6985507b0cef6e676234fd67 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 25 Feb 2010 13:30:50 +0000 Subject: [PATCH 201/237] 2010-02-25 Jordan Uggla * util/grub-mkconfig.in (GRUB_SAVEDEFAULT): Export new variable. * util/grub-mkconfig_lib.in (save_default_entry): Only save a new default entry if GRUB_SAVEDEFAULT=true. This allows using GRUB_DEFAULT=saved on its own to let grub-reboot work, without saving a new default on every boot. --- ChangeLog | 8 ++++++++ util/grub-mkconfig.in | 3 ++- util/grub-mkconfig_lib.in | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 24981a5fc..b8f6ba35d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-02-25 Jordan Uggla + + * util/grub-mkconfig.in (GRUB_SAVEDEFAULT): Export new variable. + * util/grub-mkconfig_lib.in (save_default_entry): Only save a new + default entry if GRUB_SAVEDEFAULT=true. This allows using + GRUB_DEFAULT=saved on its own to let grub-reboot work, without + saving a new default on every boot. + 2010-02-24 Vladimir Serbinenko * normal/crypto.c (read_crypto_list): Fix a memory leak. diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index fb1dd4544..daa110be7 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -223,7 +223,8 @@ export GRUB_DEFAULT \ GRUB_THEME \ GRUB_GFXPAYLOAD_LINUX \ GRUB_DISABLE_OS_PROBER \ - GRUB_INIT_TUNE + GRUB_INIT_TUNE \ + GRUB_SAVEDEFAULT if test "x${grub_cfg}" != "x"; then rm -f ${grub_cfg}.new diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 45354041a..bcd6baffb 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -96,7 +96,7 @@ convert_system_path_to_grub_path () save_default_entry () { - if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then + if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then cat << EOF savedefault EOF From c140a1803787036762faec8f76d931b11f66148a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 25 Feb 2010 15:10:18 +0100 Subject: [PATCH 202/237] 2010-02-25 Vladimir Serbinenko Don't compile video modules on yeeloong since video subsystem is part of kernel. * conf/common.rmk (pkglib_MODULES) [yeeloong]: Remove video.mod, video_fb.mod, bitmap.mod, font.mod, gfxterm.mod and bufio.mod * conf/mips-yeeloong.rmk (kernel_img_HEADERS): Add bitmap.h, video.h, gfxterm.h, font.h, bitmap_scale.h and bufio.h. * conf/mips.rmk (kernel_img_HEADERS): Add values instead of overwriting. * include/grub/bitmap.h: Add EXPORT_FUNC and EXPORT_VAR. * include/grub/bitmap_scale.h: Likewise. * include/grub/bufio.h: Likewise. * include/grub/font.h: Likewise. * include/grub/gfxterm.h: Likewise. * include/grub/video.h: Likewise. * include/grub/vbe.h: Don't include video_fb.h. * video/i386/pc/vbe.c: Include video_fb.h. * commands/i386/pc/vbetest.c: Include video.h. --- ChangeLog | 20 +++++++++ commands/i386/pc/vbetest.c | 1 + conf/common.rmk | 68 +++++++++++++++++----------- conf/mips-yeeloong.rmk | 3 ++ conf/mips.rmk | 2 +- include/grub/bitmap.h | 26 +++++------ include/grub/bitmap_scale.h | 11 ++--- include/grub/bufio.h | 4 +- include/grub/font.h | 40 +++++++++-------- include/grub/gfxterm.h | 14 +++--- include/grub/i386/pc/vbe.h | 2 - include/grub/video.h | 88 +++++++++++++++++++++---------------- video/i386/pc/vbe.c | 1 + 13 files changed, 168 insertions(+), 112 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8f6ba35d..233e1fc2d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2010-02-25 Vladimir Serbinenko + + Don't compile video modules on yeeloong since video subsystem is part + of kernel. + + * conf/common.rmk (pkglib_MODULES) [yeeloong]: Remove video.mod, + video_fb.mod, bitmap.mod, font.mod, gfxterm.mod and bufio.mod + * conf/mips-yeeloong.rmk (kernel_img_HEADERS): Add bitmap.h, + video.h, gfxterm.h, font.h, bitmap_scale.h and bufio.h. + * conf/mips.rmk (kernel_img_HEADERS): Add values instead of overwriting. + * include/grub/bitmap.h: Add EXPORT_FUNC and EXPORT_VAR. + * include/grub/bitmap_scale.h: Likewise. + * include/grub/bufio.h: Likewise. + * include/grub/font.h: Likewise. + * include/grub/gfxterm.h: Likewise. + * include/grub/video.h: Likewise. + * include/grub/vbe.h: Don't include video_fb.h. + * video/i386/pc/vbe.c: Include video_fb.h. + * commands/i386/pc/vbetest.c: Include video.h. + 2010-02-25 Jordan Uggla * util/grub-mkconfig.in (GRUB_SAVEDEFAULT): Export new variable. diff --git a/commands/i386/pc/vbetest.c b/commands/i386/pc/vbetest.c index d97323087..d2921c09d 100644 --- a/commands/i386/pc/vbetest.c +++ b/commands/i386/pc/vbetest.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include diff --git a/conf/common.rmk b/conf/common.rmk index 6cce36395..7effa8af3 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -621,26 +621,28 @@ sh_mod_SOURCES = script/main.c script/script.c script/execute.c \ sh_mod_CFLAGS = $(COMMON_CFLAGS) sh_mod_LDFLAGS = $(COMMON_LDFLAGS) +ifneq (, $(FONT_SOURCE)) +font/font.c_DEPENDENCIES = ascii.h +endif + # Common Video Subsystem specific modules. -pkglib_MODULES += video.mod videotest.mod bitmap.mod tga.mod jpeg.mod \ - png.mod gfxterm.mod video_fb.mod +# On Yeeloong it's part of kernel +ifneq ($(platform), yeeloong) # For video.mod. +pkglib_MODULES += video.mod video_mod_SOURCES = video/video.c video_mod_CFLAGS = $(COMMON_CFLAGS) video_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += video_fb.mod video_fb_mod_SOURCES = video/fb/video_fb.c video/fb/fbblit.c \ video/fb/fbfill.c video/fb/fbutil.c video_fb_mod_CFLAGS = $(COMMON_CFLAGS) video_fb_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For videotest.mod. -videotest_mod_SOURCES = commands/videotest.c -videotest_mod_CFLAGS = $(COMMON_CFLAGS) -videotest_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For bitmap.mod +pkglib_MODULES += bitmap.mod bitmap_mod_SOURCES = video/bitmap.c bitmap_mod_CFLAGS = $(COMMON_CFLAGS) bitmap_mod_LDFLAGS = $(COMMON_LDFLAGS) @@ -651,36 +653,46 @@ bitmap_scale_mod_SOURCES = video/bitmap_scale.c bitmap_scale_mod_CFLAGS = $(COMMON_CFLAGS) bitmap_scale_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For tga.mod -tga_mod_SOURCES = video/readers/tga.c -tga_mod_CFLAGS = $(COMMON_CFLAGS) -tga_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For jpeg.mod. -jpeg_mod_SOURCES = video/readers/jpeg.c -jpeg_mod_CFLAGS = $(COMMON_CFLAGS) -jpeg_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For png.mod. -png_mod_SOURCES = video/readers/png.c -png_mod_CFLAGS = $(COMMON_CFLAGS) -png_mod_LDFLAGS = $(COMMON_LDFLAGS) - pkglib_MODULES += font.mod -ifneq (, $(FONT_SOURCE)) -font/font.c_DEPENDENCIES = ascii.h -endif font_mod_SOURCES = font/font_cmd.c font/font.c font_mod_CFLAGS = $(COMMON_CFLAGS) font_mod_LDFLAGS = $(COMMON_LDFLAGS) # For gfxterm.mod. +pkglib_MODULES += gfxterm.mod gfxterm_mod_SOURCES = term/gfxterm.c gfxterm_mod_CFLAGS = $(COMMON_CFLAGS) gfxterm_mod_LDFLAGS = $(COMMON_LDFLAGS) +endif + +# For videotest.mod. +pkglib_MODULES += videotest.mod +videotest_mod_SOURCES = commands/videotest.c +videotest_mod_CFLAGS = $(COMMON_CFLAGS) +videotest_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For tga.mod +pkglib_MODULES += tga.mod +tga_mod_SOURCES = video/readers/tga.c +tga_mod_CFLAGS = $(COMMON_CFLAGS) +tga_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For jpeg.mod. +pkglib_MODULES += jpeg.mod +jpeg_mod_SOURCES = video/readers/jpeg.c +jpeg_mod_CFLAGS = $(COMMON_CFLAGS) +jpeg_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For png.mod. +pkglib_MODULES += png.mod +png_mod_SOURCES = video/readers/png.c +png_mod_CFLAGS = $(COMMON_CFLAGS) +png_mod_LDFLAGS = $(COMMON_LDFLAGS) + + # Misc. -pkglib_MODULES += gzio.mod bufio.mod elf.mod +pkglib_MODULES += gzio.mod elf.mod # For elf.mod. elf_mod_SOURCES = kern/elf.c @@ -692,10 +704,14 @@ gzio_mod_SOURCES = io/gzio.c gzio_mod_CFLAGS = $(COMMON_CFLAGS) gzio_mod_LDFLAGS = $(COMMON_LDFLAGS) +# On Yeeloong it's part of kernel +ifneq ($(platform), yeeloong) # For bufio.mod. +pkglib_MODULES += bufio.mod bufio_mod_SOURCES = io/bufio.c bufio_mod_CFLAGS = $(COMMON_CFLAGS) bufio_mod_LDFLAGS = $(COMMON_LDFLAGS) +endif # For gettext.mod. pkglib_MODULES += gettext.mod diff --git a/conf/mips-yeeloong.rmk b/conf/mips-yeeloong.rmk index eb0dc9676..0d9a4c1bb 100644 --- a/conf/mips-yeeloong.rmk +++ b/conf/mips-yeeloong.rmk @@ -3,6 +3,9 @@ LINK_BASE = 0x80200000 target_machine=yeeloong COMMON_CFLAGS += -march=mips3 COMMON_ASFLAGS += -march=mips3 + +kernel_img_HEADERS += bitmap.h video.h gfxterm.h font.h bitmap_scale.h bufio.h + include $(srcdir)/conf/mips.mk pkglib_IMAGES = kernel.img diff --git a/conf/mips.rmk b/conf/mips.rmk index 1ef4fc395..c7c80a26d 100644 --- a/conf/mips.rmk +++ b/conf/mips.rmk @@ -13,7 +13,7 @@ script/lexer.c_DEPENDENCIES = grub_script.tab.h MOSTLYCLEANFILES += symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst -kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ +kernel_img_HEADERS += boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h reader.h \ symbol.h term.h time.h types.h loader.h partition.h \ msdos_partition.h machine/kernel.h handler.h list.h \ diff --git a/include/grub/bitmap.h b/include/grub/bitmap.h index 42c439d69..6e300391a 100644 --- a/include/grub/bitmap.h +++ b/include/grub/bitmap.h @@ -47,24 +47,24 @@ struct grub_video_bitmap_reader }; typedef struct grub_video_bitmap_reader *grub_video_bitmap_reader_t; -void grub_video_bitmap_reader_register (grub_video_bitmap_reader_t reader); -void grub_video_bitmap_reader_unregister (grub_video_bitmap_reader_t reader); +void EXPORT_FUNC (grub_video_bitmap_reader_register) (grub_video_bitmap_reader_t reader); +void EXPORT_FUNC (grub_video_bitmap_reader_unregister) (grub_video_bitmap_reader_t reader); -grub_err_t grub_video_bitmap_create (struct grub_video_bitmap **bitmap, - unsigned int width, unsigned int height, - enum grub_video_blit_format blit_format); +grub_err_t EXPORT_FUNC (grub_video_bitmap_create) (struct grub_video_bitmap **bitmap, + unsigned int width, unsigned int height, + enum grub_video_blit_format blit_format); -grub_err_t grub_video_bitmap_destroy (struct grub_video_bitmap *bitmap); +grub_err_t EXPORT_FUNC (grub_video_bitmap_destroy) (struct grub_video_bitmap *bitmap); -grub_err_t grub_video_bitmap_load (struct grub_video_bitmap **bitmap, - const char *filename); +grub_err_t EXPORT_FUNC (grub_video_bitmap_load) (struct grub_video_bitmap **bitmap, + const char *filename); -unsigned int grub_video_bitmap_get_width (struct grub_video_bitmap *bitmap); -unsigned int grub_video_bitmap_get_height (struct grub_video_bitmap *bitmap); +unsigned int EXPORT_FUNC (grub_video_bitmap_get_width) (struct grub_video_bitmap *bitmap); +unsigned int EXPORT_FUNC (grub_video_bitmap_get_height) (struct grub_video_bitmap *bitmap); -void grub_video_bitmap_get_mode_info (struct grub_video_bitmap *bitmap, - struct grub_video_mode_info *mode_info); +void EXPORT_FUNC (grub_video_bitmap_get_mode_info) (struct grub_video_bitmap *bitmap, + struct grub_video_mode_info *mode_info); -void *grub_video_bitmap_get_data (struct grub_video_bitmap *bitmap); +void *EXPORT_FUNC (grub_video_bitmap_get_data) (struct grub_video_bitmap *bitmap); #endif /* ! GRUB_BITMAP_HEADER */ diff --git a/include/grub/bitmap_scale.h b/include/grub/bitmap_scale.h index 7ea9d7914..dce9fbbf2 100644 --- a/include/grub/bitmap_scale.h +++ b/include/grub/bitmap_scale.h @@ -39,10 +39,11 @@ enum grub_video_bitmap_scale_method }; grub_err_t -grub_video_bitmap_create_scaled (struct grub_video_bitmap **dst, - int dst_width, int dst_height, - struct grub_video_bitmap *src, - enum - grub_video_bitmap_scale_method scale_method); +EXPORT_FUNC (grub_video_bitmap_create_scaled) (struct grub_video_bitmap **dst, + int dst_width, int dst_height, + struct grub_video_bitmap *src, + enum + grub_video_bitmap_scale_method + scale_method); #endif /* ! GRUB_BITMAP_SCALE_HEADER */ diff --git a/include/grub/bufio.h b/include/grub/bufio.h index 9a2294c26..acdd0c882 100644 --- a/include/grub/bufio.h +++ b/include/grub/bufio.h @@ -22,7 +22,7 @@ #include -grub_file_t grub_bufio_open (grub_file_t io, int size); -grub_file_t grub_buffile_open (const char *name, int size); +grub_file_t EXPORT_FUNC (grub_bufio_open) (grub_file_t io, int size); +grub_file_t EXPORT_FUNC (grub_buffile_open) (const char *name, int size); #endif /* ! GRUB_BUFIO_H */ diff --git a/include/grub/font.h b/include/grub/font.h index 1816e3570..7c5c17403 100644 --- a/include/grub/font.h +++ b/include/grub/font.h @@ -81,36 +81,38 @@ int grub_font_load (const char *filename); "Family Name Bold Italic 14", where Bold and Italic are optional. If no font matches the name specified, the most recently loaded font is returned as a fallback. */ -grub_font_t grub_font_get (const char *font_name); +grub_font_t EXPORT_FUNC (grub_font_get) (const char *font_name); -const char *grub_font_get_name (grub_font_t font); +const char *EXPORT_FUNC (grub_font_get_name) (grub_font_t font); -int grub_font_get_max_char_width (grub_font_t font); +int EXPORT_FUNC (grub_font_get_max_char_width) (grub_font_t font); -int grub_font_get_max_char_height (grub_font_t font); +int EXPORT_FUNC (grub_font_get_max_char_height) (grub_font_t font); -int grub_font_get_ascent (grub_font_t font); +int EXPORT_FUNC (grub_font_get_ascent) (grub_font_t font); -int grub_font_get_descent (grub_font_t font); +int EXPORT_FUNC (grub_font_get_descent) (grub_font_t font); -int grub_font_get_leading (grub_font_t font); +int EXPORT_FUNC (grub_font_get_leading) (grub_font_t font); -int grub_font_get_height (grub_font_t font); +int EXPORT_FUNC (grub_font_get_height) (grub_font_t font); -int grub_font_get_string_width (grub_font_t font, const char *str); +int EXPORT_FUNC (grub_font_get_string_width) (grub_font_t font, + const char *str); -struct grub_font_glyph *grub_font_get_glyph (grub_font_t font, - grub_uint32_t code); +struct grub_font_glyph *EXPORT_FUNC (grub_font_get_glyph) (grub_font_t font, + grub_uint32_t code); -struct grub_font_glyph *grub_font_get_glyph_with_fallback (grub_font_t font, - grub_uint32_t code); +struct grub_font_glyph *EXPORT_FUNC (grub_font_get_glyph_with_fallback) (grub_font_t font, + grub_uint32_t code); -grub_err_t grub_font_draw_glyph (struct grub_font_glyph *glyph, - grub_video_color_t color, - int left_x, int baseline_y); +grub_err_t EXPORT_FUNC (grub_font_draw_glyph) (struct grub_font_glyph *glyph, + grub_video_color_t color, + int left_x, int baseline_y); -grub_err_t grub_font_draw_string (const char *str, grub_font_t font, - grub_video_color_t color, - int left_x, int baseline_y); +grub_err_t EXPORT_FUNC (grub_font_draw_string) (const char *str, + grub_font_t font, + grub_video_color_t color, + int left_x, int baseline_y); #endif /* ! GRUB_FONT_HEADER */ diff --git a/include/grub/gfxterm.h b/include/grub/gfxterm.h index fe3da7409..295354baf 100644 --- a/include/grub/gfxterm.h +++ b/include/grub/gfxterm.h @@ -25,20 +25,20 @@ #include grub_err_t -grub_gfxterm_set_window (struct grub_video_render_target *target, - int x, int y, int width, int height, - int double_repaint, - const char *font_name, int border_width); +EXPORT_FUNC (grub_gfxterm_set_window) (struct grub_video_render_target *target, + int x, int y, int width, int height, + int double_repaint, + const char *font_name, int border_width); typedef void (*grub_gfxterm_repaint_callback_t)(int x, int y, int width, int height); void grub_gfxterm_set_repaint_callback (grub_gfxterm_repaint_callback_t func); -void grub_gfxterm_schedule_repaint (void); +void EXPORT_FUNC (grub_gfxterm_schedule_repaint) (void); -grub_err_t grub_gfxterm_fullscreen (void); +grub_err_t EXPORT_FUNC (grub_gfxterm_fullscreen) (void); -extern void (*grub_gfxterm_decorator_hook) (void); +extern void (*EXPORT_VAR (grub_gfxterm_decorator_hook)) (void); #endif /* ! GRUB_GFXTERM_HEADER */ diff --git a/include/grub/i386/pc/vbe.h b/include/grub/i386/pc/vbe.h index 9c4c4dd3d..abf246fa1 100644 --- a/include/grub/i386/pc/vbe.h +++ b/include/grub/i386/pc/vbe.h @@ -19,8 +19,6 @@ #ifndef GRUB_VBE_MACHINE_HEADER #define GRUB_VBE_MACHINE_HEADER 1 -#include - /* Default video mode to be used. */ #define GRUB_VBE_DEFAULT_VIDEO_MODE 0x101 diff --git a/include/grub/video.h b/include/grub/video.h index fa459aebd..57f2b37f2 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -259,13 +259,13 @@ struct grub_video_adapter }; typedef struct grub_video_adapter *grub_video_adapter_t; -void grub_video_register (grub_video_adapter_t adapter); +void EXPORT_FUNC (grub_video_register) (grub_video_adapter_t adapter); void grub_video_unregister (grub_video_adapter_t adapter); void grub_video_iterate (int (*hook) (grub_video_adapter_t adapter)); -grub_err_t grub_video_restore (void); +grub_err_t EXPORT_FUNC (grub_video_restore) (void); -grub_err_t grub_video_get_info (struct grub_video_mode_info *mode_info); +grub_err_t EXPORT_FUNC (grub_video_get_info) (struct grub_video_mode_info *mode_info); /* Framebuffer address may change as a part of normal operation (e.g. double buffering). That's why you need to stop video subsystem to be @@ -283,57 +283,71 @@ grub_err_t grub_video_set_palette (unsigned int start, unsigned int count, grub_err_t grub_video_get_palette (unsigned int start, unsigned int count, struct grub_video_palette_data *palette_data); -grub_err_t grub_video_set_viewport (unsigned int x, unsigned int y, - unsigned int width, unsigned int height); +grub_err_t EXPORT_FUNC (grub_video_set_viewport) (unsigned int x, + unsigned int y, + unsigned int width, + unsigned int height); -grub_err_t grub_video_get_viewport (unsigned int *x, unsigned int *y, - unsigned int *width, unsigned int *height); +grub_err_t EXPORT_FUNC (grub_video_get_viewport) (unsigned int *x, + unsigned int *y, + unsigned int *width, + unsigned int *height); -grub_video_color_t grub_video_map_color (grub_uint32_t color_name); +grub_video_color_t EXPORT_FUNC (grub_video_map_color) (grub_uint32_t color_name); -grub_video_color_t grub_video_map_rgb (grub_uint8_t red, grub_uint8_t green, - grub_uint8_t blue); +grub_video_color_t EXPORT_FUNC (grub_video_map_rgb) (grub_uint8_t red, + grub_uint8_t green, + grub_uint8_t blue); -grub_video_color_t grub_video_map_rgba (grub_uint8_t red, grub_uint8_t green, - grub_uint8_t blue, grub_uint8_t alpha); +grub_video_color_t EXPORT_FUNC (grub_video_map_rgba) (grub_uint8_t red, + grub_uint8_t green, + grub_uint8_t blue, + grub_uint8_t alpha); -grub_err_t grub_video_unmap_color (grub_video_color_t color, - grub_uint8_t *red, grub_uint8_t *green, - grub_uint8_t *blue, grub_uint8_t *alpha); +grub_err_t EXPORT_FUNC (grub_video_unmap_color) (grub_video_color_t color, + grub_uint8_t *red, + grub_uint8_t *green, + grub_uint8_t *blue, + grub_uint8_t *alpha); -grub_err_t grub_video_fill_rect (grub_video_color_t color, int x, int y, - unsigned int width, unsigned int height); +grub_err_t EXPORT_FUNC (grub_video_fill_rect) (grub_video_color_t color, + int x, int y, + unsigned int width, + unsigned int height); -grub_err_t grub_video_blit_bitmap (struct grub_video_bitmap *bitmap, - enum grub_video_blit_operators oper, - int x, int y, int offset_x, int offset_y, - unsigned int width, unsigned int height); +grub_err_t EXPORT_FUNC (grub_video_blit_bitmap) (struct grub_video_bitmap *bitmap, + enum grub_video_blit_operators oper, + int x, int y, + int offset_x, int offset_y, + unsigned int width, + unsigned int height); -grub_err_t grub_video_blit_render_target (struct grub_video_render_target *source, - enum grub_video_blit_operators oper, - int x, int y, - int offset_x, int offset_y, - unsigned int width, - unsigned int height); +grub_err_t EXPORT_FUNC (grub_video_blit_render_target) (struct grub_video_render_target *source, + enum grub_video_blit_operators oper, + int x, int y, + int offset_x, + int offset_y, + unsigned int width, + unsigned int height); grub_err_t grub_video_scroll (grub_video_color_t color, int dx, int dy); -grub_err_t grub_video_swap_buffers (void); +grub_err_t EXPORT_FUNC (grub_video_swap_buffers) (void); -grub_err_t grub_video_create_render_target (struct grub_video_render_target **result, - unsigned int width, - unsigned int height, - unsigned int mode_type); +grub_err_t EXPORT_FUNC (grub_video_create_render_target) (struct grub_video_render_target **result, + unsigned int width, + unsigned int height, + unsigned int mode_type); -grub_err_t grub_video_delete_render_target (struct grub_video_render_target *target); +grub_err_t EXPORT_FUNC (grub_video_delete_render_target) (struct grub_video_render_target *target); -grub_err_t grub_video_set_active_render_target (struct grub_video_render_target *target); +grub_err_t EXPORT_FUNC (grub_video_set_active_render_target) (struct grub_video_render_target *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, - unsigned int modemask, - unsigned int modevalue); +grub_err_t EXPORT_FUNC (grub_video_set_mode) (const char *modestring, + unsigned int modemask, + unsigned int modevalue); static inline int grub_video_check_mode_flag (unsigned int flags, unsigned int mask, diff --git a/video/i386/pc/vbe.c b/video/i386/pc/vbe.c index 0107cc297..72b8f1831 100644 --- a/video/i386/pc/vbe.c +++ b/video/i386/pc/vbe.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include From 72b286313ab2c1e94f115b04bda5c17f99150484 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 26 Feb 2010 14:32:24 +0100 Subject: [PATCH 203/237] 2010-02-26 Vladimir Serbinenko * util/grub.d/10_linux.in (linux_entry): Don't default to gfxpayload=keep if Linux doesn't support video handover. --- ChangeLog | 5 +++++ util/grub.d/10_linux.in | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 233e1fc2d..e7617dc1d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-26 Vladimir Serbinenko + + * util/grub.d/10_linux.in (linux_entry): Don't default to + gfxpayload=keep if Linux doesn't support video handover. + 2010-02-25 Vladimir Serbinenko Don't compile video modules on yeeloong since video subsystem is part diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 046874ef0..2c60bc681 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -66,7 +66,8 @@ linux_entry () # Use ELILO's generic "efifb" when it's known to be available. # FIXME: We need an interface to select vesafb in case efifb can't be used. if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then - if grep -qx "CONFIG_FB_EFI=y" /boot/config-${version} 2> /dev/null ; then + if grep -qx "CONFIG_FB_EFI=y" /boot/config-${version} 2> /dev/null \ + && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" /boot/config-${version} 2> /dev/null; then cat << EOF set gfxpayload=keep EOF From 5519963bf6ae5804f98b4828b6c9687f9f31a9cf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 1 Mar 2010 19:07:48 +0100 Subject: [PATCH 204/237] 2010-03-01 Vladimir Serbinenko * configure.ac: Update version to 1.98. --- ChangeLog | 4 ++++ configure.ac | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e7617dc1d..3812610d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-01 Vladimir Serbinenko + + * configure.ac: Update version to 1.98. + 2010-02-26 Vladimir Serbinenko * util/grub.d/10_linux.in (linux_entry): Don't default to diff --git a/configure.ac b/configure.ac index 48702afd6..ac3f0d196 100644 --- a/configure.ac +++ b/configure.ac @@ -31,7 +31,7 @@ dnl (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for the target dnl type. -AC_INIT([GRUB],[1.97],[bug-grub@gnu.org]) +AC_INIT([GRUB],[1.98],[bug-grub@gnu.org]) AM_INIT_AUTOMAKE() AC_PREREQ(2.60) AC_CONFIG_SRCDIR([include/grub/dl.h]) From 5382b1e4a899b713f3fd50a123e7bfb380e3beef Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 1 Mar 2010 20:24:34 +0100 Subject: [PATCH 205/237] 2010-03-01 Vladimir Serbinenko * commands/cat.c (grub_cmd_cat): Propagate grub_gzfile_open error. --- ChangeLog | 4 ++++ commands/cat.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3812610d7..2010872b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-01 Vladimir Serbinenko + + * commands/cat.c (grub_cmd_cat): Propagate grub_gzfile_open error. + 2010-03-01 Vladimir Serbinenko * configure.ac: Update version to 1.98. diff --git a/commands/cat.c b/commands/cat.c index 844034777..3bdafc4c6 100644 --- a/commands/cat.c +++ b/commands/cat.c @@ -41,7 +41,7 @@ grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)), file = grub_gzfile_open (args[0], 1); if (! file) - return 0; + return grub_errno; while ((size = grub_file_read (file, buf, sizeof (buf))) > 0 && key != GRUB_TERM_ESC) From c6f2fe52f185525c64980321449e07637ade222f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 1 Mar 2010 20:58:45 +0100 Subject: [PATCH 206/237] 2010-03-01 Vladimir Serbinenko Wait for user entry basing on presence of output rather than on errors. * include/grub/normal.h (grub_normal_get_line_counter): New proto. (grub_install_newline_hook): Likewise. * normal/main.c (GRUB_MOD_INIT): Call grub_install_newline_hook. * normal/menu.c (show_menu): Check line_counter to determine presence of output. * normal/term.c (grub_normal_line_counter): New variable. (grub_normal_get_line_counter): New function. (grub_install_newline_hook): Likewise. --- ChangeLog | 13 +++++++++++++ include/grub/normal.h | 3 +++ normal/main.c | 1 + normal/menu.c | 12 ++++++------ normal/term.c | 16 +++++++++++++++- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2010872b1..5ba6dd4eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-03-01 Vladimir Serbinenko + + Wait for user entry basing on presence of output rather than on errors. + + * include/grub/normal.h (grub_normal_get_line_counter): New proto. + (grub_install_newline_hook): Likewise. + * normal/main.c (GRUB_MOD_INIT): Call grub_install_newline_hook. + * normal/menu.c (show_menu): Check line_counter to determine presence + of output. + * normal/term.c (grub_normal_line_counter): New variable. + (grub_normal_get_line_counter): New function. + (grub_install_newline_hook): Likewise. + 2010-03-01 Vladimir Serbinenko * commands/cat.c (grub_cmd_cat): Propagate grub_gzfile_open error. diff --git a/include/grub/normal.h b/include/grub/normal.h index fad1a41ba..fe45ddf71 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -110,4 +110,7 @@ void read_terminal_list (void); void grub_set_more (int onoff); +int grub_normal_get_line_counter (void); +void grub_install_newline_hook (void); + #endif /* ! GRUB_NORMAL_HEADER */ diff --git a/normal/main.c b/normal/main.c index 2306427fc..5a5467485 100644 --- a/normal/main.c +++ b/normal/main.c @@ -654,6 +654,7 @@ GRUB_MOD_INIT(normal) grub_set_history (GRUB_DEFAULT_HISTORY_SIZE); + grub_install_newline_hook (); grub_register_variable_hook ("pager", 0, grub_env_write_pager); /* Register a command "normal" for the rescue mode. */ diff --git a/normal/menu.c b/normal/menu.c index c47e83bc2..07951dacc 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -559,14 +559,14 @@ show_menu (grub_menu_t menu, int nested) } else { + int lines_before = grub_normal_get_line_counter (); grub_errno = GRUB_ERR_NONE; grub_menu_execute_entry (e); - if (grub_errno != GRUB_ERR_NONE) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - grub_wait_after_message (); - } + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + + if (lines_before != grub_normal_get_line_counter ()) + grub_wait_after_message (); } } diff --git a/normal/term.c b/normal/term.c index e31d403ee..7bedd6799 100644 --- a/normal/term.c +++ b/normal/term.c @@ -30,6 +30,14 @@ static unsigned grub_more_lines; /* If the more pager is active. */ static int grub_more; +static int grub_normal_line_counter = 0; + +int +grub_normal_get_line_counter (void) +{ + return grub_normal_line_counter; +} + static void process_newline (void) { @@ -41,6 +49,8 @@ process_newline (void) height = grub_term_height (cur); grub_more_lines++; + grub_normal_line_counter++; + if (grub_more && grub_more_lines >= height - 1) { char key; @@ -76,6 +86,11 @@ grub_set_more (int onoff) grub_more--; grub_more_lines = 0; +} + +void +grub_install_newline_hook (void) +{ grub_newline_hook = process_newline; } @@ -150,7 +165,6 @@ grub_terminal_autoload_free (void) grub_term_output_autoload = NULL; } - /* Read the file terminal.lst for auto-loading. */ void read_terminal_list (void) From c4d0b332c54e34b6a40fcda05183943ee192f24c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 1 Mar 2010 21:00:02 +0100 Subject: [PATCH 207/237] 2010-03-01 Vladimir Serbinenko * fs/ext2.c (grub_ext2_read_block): Fix an integer overflow. --- ChangeLog | 4 ++++ fs/ext2.c | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5ba6dd4eb..90bbce0e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-01 Vladimir Serbinenko + + * fs/ext2.c (grub_ext2_read_block): Fix an integer overflow. + 2010-03-01 Vladimir Serbinenko Wait for user entry basing on presence of output rather than on errors. diff --git a/fs/ext2.c b/fs/ext2.c index ac36b329b..f2fec828a 100644 --- a/fs/ext2.c +++ b/fs/ext2.c @@ -436,7 +436,8 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) grub_uint32_t indir[blksz / 4]; if (grub_disk_read (data->disk, - grub_le_to_cpu32 (inode->blocks.indir_block) + ((grub_disk_addr_t) + grub_le_to_cpu32 (inode->blocks.indir_block)) << log2_blksz, 0, blksz, indir)) return grub_errno; @@ -452,13 +453,15 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) grub_uint32_t indir[blksz / 4]; if (grub_disk_read (data->disk, - grub_le_to_cpu32 (inode->blocks.double_indir_block) + ((grub_disk_addr_t) + grub_le_to_cpu32 (inode->blocks.double_indir_block)) << log2_blksz, 0, blksz, indir)) return grub_errno; if (grub_disk_read (data->disk, - grub_le_to_cpu32 (indir[rblock / perblock]) + ((grub_disk_addr_t) + grub_le_to_cpu32 (indir[rblock / perblock])) << log2_blksz, 0, blksz, indir)) return grub_errno; From 22d7b6137a3b362b6230af23dc1009f4ed87a208 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 3 Mar 2010 10:44:12 +0000 Subject: [PATCH 208/237] 2010-03-03 Colin Watson * util/hostdisk.c (struct grub_util_biosdisk_data): New structure. (grub_util_biosdisk_open): Initialise disk->data. (struct linux_partition_cache): New structure. (linux_find_partition): Cache partition start positions; these are expensive to compute on every read and write. (open_device): Cache open file descriptor in disk->data, so that we don't have to reopen it and flush the buffer cache for consecutive operations on the same device. (grub_util_biosdisk_close): New function. (grub_util_biosdisk_dev): Set `close' member. * conf/common.rmk (grub_probe_SOURCES): Add kern/list.c. * conf/i386-efi.rmk (grub_setup_SOURCES): Likewise. * conf/i386-pc.rmk (grub_setup_SOURCES): Likewise. * conf/sparc64-ieee1275.rmk (grub_setup_SOURCES): Likewise. * conf/x86_64-efi.rmk (grub_setup_SOURCES): Likewise. --- ChangeLog.hostdisk-speedup | 18 +++++++ conf/common.rmk | 2 +- conf/i386-efi.rmk | 2 +- conf/i386-pc.rmk | 3 +- conf/sparc64-ieee1275.rmk | 3 +- conf/x86_64-efi.rmk | 2 +- util/hostdisk.c | 104 ++++++++++++++++++++++++++++++++----- 7 files changed, 116 insertions(+), 18 deletions(-) create mode 100644 ChangeLog.hostdisk-speedup diff --git a/ChangeLog.hostdisk-speedup b/ChangeLog.hostdisk-speedup new file mode 100644 index 000000000..ef48978a4 --- /dev/null +++ b/ChangeLog.hostdisk-speedup @@ -0,0 +1,18 @@ +2010-03-03 Colin Watson + + * util/hostdisk.c (struct grub_util_biosdisk_data): New structure. + (grub_util_biosdisk_open): Initialise disk->data. + (struct linux_partition_cache): New structure. + (linux_find_partition): Cache partition start positions; these are + expensive to compute on every read and write. + (open_device): Cache open file descriptor in disk->data, so that we + don't have to reopen it and flush the buffer cache for consecutive + operations on the same device. + (grub_util_biosdisk_close): New function. + (grub_util_biosdisk_dev): Set `close' member. + + * conf/common.rmk (grub_probe_SOURCES): Add kern/list.c. + * conf/i386-efi.rmk (grub_setup_SOURCES): Likewise. + * conf/i386-pc.rmk (grub_setup_SOURCES): Likewise. + * conf/sparc64-ieee1275.rmk (grub_setup_SOURCES): Likewise. + * conf/x86_64-efi.rmk (grub_setup_SOURCES): Likewise. diff --git a/conf/common.rmk b/conf/common.rmk index 7effa8af3..8f63e2db8 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -24,7 +24,7 @@ util/grub-probe.c_DEPENDENCIES = grub_probe_init.h grub_probe_SOURCES = gnulib/progname.c util/grub-probe.c \ util/hostdisk.c util/misc.c util/getroot.c \ kern/device.c kern/disk.c kern/err.c kern/misc.c \ - kern/parser.c kern/partition.c kern/file.c \ + kern/parser.c kern/partition.c kern/file.c kern/list.c \ \ fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c \ fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c \ diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index c03abb429..8f159e9c0 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -21,7 +21,7 @@ util/i386/efi/grub-mkimage.c_DEPENDENCIES = Makefile # kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c \ # fs/sfs.c kern/parser.c kern/partition.c partmap/msdos.c \ # fs/ufs.c fs/ufs2.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c \ -# kern/fs.c kern/env.c fs/fshelp.c +# kern/fs.c kern/env.c kern/list.c fs/fshelp.c # Scripts. sbin_SCRIPTS = grub-install diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 580bfea0a..610f4791b 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -96,7 +96,8 @@ grub_setup_SOURCES = gnulib/progname.c \ util/i386/pc/grub-setup.c util/hostdisk.c \ util/misc.c util/getroot.c kern/device.c kern/disk.c \ kern/err.c kern/misc.c kern/parser.c kern/partition.c \ - kern/file.c kern/fs.c kern/env.c fs/fshelp.c \ + kern/file.c kern/fs.c kern/env.c kern/list.c \ + fs/fshelp.c \ \ fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \ fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c \ diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index befc7dce5..e8bdccb2d 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -70,7 +70,8 @@ util/sparc64/ieee1275/grub-setup.c_DEPENDENCIES = grub_setup_init.h grub_setup_SOURCES = util/sparc64/ieee1275/grub-setup.c util/hostdisk.c \ util/misc.c util/getroot.c kern/device.c kern/disk.c \ kern/err.c kern/misc.c kern/parser.c kern/partition.c \ - kern/file.c kern/fs.c kern/env.c fs/fshelp.c \ + kern/file.c kern/fs.c kern/env.c kern/list.c \ + fs/fshelp.c \ \ fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \ fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c \ diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index d5c3c24cb..e17777e0a 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -20,7 +20,7 @@ grub_mkimage_SOURCES = gnulib/progname.c util/i386/efi/grub-mkimage.c \ # kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c \ # fs/sfs.c kern/parser.c kern/partition.c partmap/msdos.c \ # fs/ufs.c fs/ufs2.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c \ -# kern/fs.c kern/env.c fs/fshelp.c +# kern/fs.c kern/env.c kern/list.c fs/fshelp.c # Scripts. sbin_SCRIPTS = grub-install diff --git a/util/hostdisk.c b/util/hostdisk.c index 98d3d53ae..9ece36885 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -103,6 +104,12 @@ struct char *device; } map[256]; +struct grub_util_biosdisk_data +{ + char *dev; + int fd; +}; + #ifdef __linux__ /* Check if we have devfs support. */ static int @@ -165,6 +172,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) { int drive; struct stat st; + struct grub_util_biosdisk_data *data; drive = find_grub_drive (name); if (drive < 0) @@ -173,6 +181,9 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) disk->has_partitions = 1; disk->id = drive; + disk->data = data = xmalloc (sizeof (struct grub_util_biosdisk_data)); + data->dev = NULL; + data->fd = -1; /* Get the size. */ #if defined(__MINGW32__) @@ -254,6 +265,17 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) } #ifdef __linux__ +/* Cache of partition start sectors for each disk. */ +struct linux_partition_cache +{ + struct linux_partition_cache *next; + char *dev; + unsigned long start; + int partno; +}; + +struct linux_partition_cache *linux_partition_cache_list; + static int linux_find_partition (char *dev, unsigned long sector) { @@ -262,6 +284,7 @@ linux_find_partition (char *dev, unsigned long sector) char *p; int i; char real_dev[PATH_MAX]; + struct linux_partition_cache *cache; strcpy(real_dev, dev); @@ -281,6 +304,16 @@ linux_find_partition (char *dev, unsigned long sector) format = "%d"; } + for (cache = linux_partition_cache_list; cache; cache = cache->next) + { + if (strcmp (cache->dev, dev) == 0 && cache->start == sector) + { + sprintf (p, format, cache->partno); + strcpy (dev, real_dev); + return 1; + } + } + for (i = 1; i < 10000; i++) { int fd; @@ -301,6 +334,15 @@ linux_find_partition (char *dev, unsigned long sector) if (hdg.start == sector) { + struct linux_partition_cache *new_cache_item; + + new_cache_item = xmalloc (sizeof *new_cache_item); + new_cache_item->dev = xstrdup (dev); + new_cache_item->start = hdg.start; + new_cache_item->partno = i; + grub_list_push (GRUB_AS_LIST_P (&linux_partition_cache_list), + GRUB_AS_LIST (new_cache_item)); + strcpy (dev, real_dev); return 1; } @@ -314,6 +356,7 @@ static int open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) { int fd; + struct grub_util_biosdisk_data *data = disk->data; #ifdef O_LARGEFILE flags |= O_LARGEFILE; @@ -340,18 +383,30 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) && strncmp (map[disk->id].device, "/dev/", 5) == 0) is_partition = linux_find_partition (dev, disk->partition->start); - /* Open the partition. */ - grub_dprintf ("hostdisk", "opening the device `%s' in open_device()\n", dev); - fd = open (dev, flags); - if (fd < 0) + if (data->dev && strcmp (data->dev, dev) == 0) { - grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", dev); - return -1; + grub_dprintf ("hostdisk", "reusing open device `%s'\n", dev); + fd = data->fd; } + else + { + /* Open the partition. */ + grub_dprintf ("hostdisk", "opening the device `%s' in open_device()\n", dev); + fd = open (dev, flags); + if (fd < 0) + { + grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", dev); + return -1; + } - /* Flush the buffer cache to the physical disk. - XXX: This also empties the buffer cache. */ - ioctl (fd, BLKFLSBUF, 0); + /* Flush the buffer cache to the physical disk. + XXX: This also empties the buffer cache. */ + ioctl (fd, BLKFLSBUF, 0); + + free (data->dev); + data->dev = xstrdup (dev); + data->fd = fd; + } if (is_partition) sector -= disk->partition->start; @@ -375,7 +430,21 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) } #endif - fd = open (map[disk->id].device, flags); + if (data->dev && strcmp (data->dev, map[disk->id].device) == 0) + { + grub_dprintf ("hostdisk", "reusing open device `%s'\n", data->dev); + fd = data->fd; + } + else + { + fd = open (map[disk->id].device, flags); + if (fd >= 0) + { + free (data->dev); + data->dev = xstrdup (map[disk->id].device); + data->fd = fd; + } + } #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) if (! (sysctl_oldflags & 0x10) @@ -535,7 +604,6 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector, != (ssize_t) (size << GRUB_DISK_SECTOR_BITS)) grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id].device); - close (fd); return grub_errno; } @@ -570,17 +638,27 @@ grub_util_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector, != (ssize_t) (size << GRUB_DISK_SECTOR_BITS)) grub_error (GRUB_ERR_WRITE_ERROR, "cannot write to `%s'", map[disk->id].device); - close (fd); return grub_errno; } +static void +grub_util_biosdisk_close (struct grub_disk *disk) +{ + struct grub_util_biosdisk_data *data = disk->data; + + free (data->dev); + if (data->fd != -1) + close (data->fd); + free (data); +} + static struct grub_disk_dev grub_util_biosdisk_dev = { .name = "biosdisk", .id = GRUB_DISK_DEVICE_BIOSDISK_ID, .iterate = grub_util_biosdisk_iterate, .open = grub_util_biosdisk_open, - .close = 0, + .close = grub_util_biosdisk_close, .read = grub_util_biosdisk_read, .write = grub_util_biosdisk_write, .next = 0 From c6293875f961046e9d961db56fbf6082a5d955cc Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 3 Mar 2010 20:03:50 +0000 Subject: [PATCH 209/237] reopen device when the requested access mode changes --- util/hostdisk.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/util/hostdisk.c b/util/hostdisk.c index 9ece36885..b8f3129f0 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -107,6 +107,7 @@ struct struct grub_util_biosdisk_data { char *dev; + int access_mode; int fd; }; @@ -183,6 +184,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) disk->id = drive; disk->data = data = xmalloc (sizeof (struct grub_util_biosdisk_data)); data->dev = NULL; + data->access_mode = 0; data->fd = -1; /* Get the size. */ @@ -383,13 +385,18 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) && strncmp (map[disk->id].device, "/dev/", 5) == 0) is_partition = linux_find_partition (dev, disk->partition->start); - if (data->dev && strcmp (data->dev, dev) == 0) + if (data->dev && strcmp (data->dev, dev) == 0 && + data->access_mode == (flags & O_ACCMODE)) { grub_dprintf ("hostdisk", "reusing open device `%s'\n", dev); fd = data->fd; } else { + free (data->dev); + if (data->fd != -1) + close (data->fd); + /* Open the partition. */ grub_dprintf ("hostdisk", "opening the device `%s' in open_device()\n", dev); fd = open (dev, flags); @@ -403,8 +410,8 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) XXX: This also empties the buffer cache. */ ioctl (fd, BLKFLSBUF, 0); - free (data->dev); data->dev = xstrdup (dev); + data->access_mode = (flags & O_ACCMODE); data->fd = fd; } @@ -430,18 +437,23 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) } #endif - if (data->dev && strcmp (data->dev, map[disk->id].device) == 0) + if (data->dev && strcmp (data->dev, map[disk->id].device) == 0 && + data->access_mode == (flags & O_ACCMODE)) { grub_dprintf ("hostdisk", "reusing open device `%s'\n", data->dev); fd = data->fd; } else { + free (data->dev); + if (data->fd != -1) + close (data->fd); + fd = open (map[disk->id].device, flags); if (fd >= 0) { - free (data->dev); data->dev = xstrdup (map[disk->id].device); + data->access_mode = (flags & O_ACCMODE); data->fd = fd; } } From 08dcd91370183936b9a58882991564afc674a9b7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 4 Mar 2010 15:12:34 +0100 Subject: [PATCH 210/237] 2010-03-04 Vladimir Serbinenko * util/i386/efi/grub-install.in: Copy gettext files. --- ChangeLog | 4 ++++ util/i386/efi/grub-install.in | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/ChangeLog b/ChangeLog index 90bbce0e2..6eb0d5377 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-04 Vladimir Serbinenko + + * util/i386/efi/grub-install.in: Copy gettext files. + 2010-03-01 Vladimir Serbinenko * fs/ext2.c (grub_ext2_read_block): Fix an integer overflow. diff --git a/util/i386/efi/grub-install.in b/util/i386/efi/grub-install.in index caa7be7e4..6a8573e81 100644 --- a/util/i386/efi/grub-install.in +++ b/util/i386/efi/grub-install.in @@ -180,6 +180,14 @@ for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do cp -f $file ${grubdir} || exit 1 done +# Copy gettext files +mkdir -p ${grubdir}/locale/ +for file in ${grubdir}/locale/*.mo ${pkglibdir}/locale/*.mo; do + if test -f "$file"; then + cp -f "$file" ${grubdir}/locale/ + fi +done + if ! test -f ${grubdir}/grubenv; then $grub_editenv ${grubdir}/grubenv create fi From a8efbf649e9fbacf850cee6c80f8b6aea9b691a5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 4 Mar 2010 15:41:32 +0100 Subject: [PATCH 211/237] 2010-03-04 Vladimir Serbinenko * genmk.rb: Remove terminal*.lst in make clean. --- ChangeLog | 4 ++++ genmk.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6eb0d5377..e3b704c76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-04 Vladimir Serbinenko + + * genmk.rb: Remove terminal*.lst in make clean. + 2010-03-04 Vladimir Serbinenko * util/i386/efi/grub-install.in: Copy gettext files. diff --git a/genmk.rb b/genmk.rb index df03e1dfe..efea16412 100644 --- a/genmk.rb +++ b/genmk.rb @@ -201,7 +201,7 @@ endif -include #{dep} clean-module-#{extra_target}.#{@rule_count}: - rm -f #{command} #{fs} #{partmap} #{handler} #{parttool} #{video} + rm -f #{command} #{fs} #{partmap} #{handler} #{parttool} #{video} #{terminal} CLEAN_MODULE_TARGETS += clean-module-#{extra_target}.#{@rule_count} From c0ee0385c9bc3a84aaa5de95aacefaff47dd07d6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 4 Mar 2010 15:50:57 +0100 Subject: [PATCH 212/237] 2010-03-04 Vladimir Serbinenko * Makefile.in (CLEANFILES) [FONT_SOURCE && grub_mkfont]: Add ascii.bitmaps. --- ChangeLog | 5 +++++ Makefile.in | 1 + 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index e3b704c76..413622c32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-03-04 Vladimir Serbinenko + + * Makefile.in (CLEANFILES) [FONT_SOURCE && grub_mkfont]: Add + ascii.bitmaps. + 2010-03-04 Vladimir Serbinenko * genmk.rb: Remove terminal*.lst in make clean. diff --git a/Makefile.in b/Makefile.in index 539cde397..5a4ef459f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -239,6 +239,7 @@ else ifeq ($(enable_grub_mkfont),yes) pkgdata_DATA += unicode.pf2 ascii.pf2 ascii.h +CLEANFILES += ascii.bitmaps # Arrows and lines are needed to draw the menu, so we always include them UNICODE_ARROWS=0x2190-0x2193 From b4b7be98dbfa11240c59ba06df51e4baf68253da Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 4 Mar 2010 16:08:46 +0100 Subject: [PATCH 213/237] 2010-03-04 Vladimir Serbinenko * Makefile.in (DISTCLEANFILES): Add stamp-h1. --- ChangeLog | 4 ++++ Makefile.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 413622c32..255d3422c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-04 Vladimir Serbinenko + + * Makefile.in (DISTCLEANFILES): Add stamp-h1. + 2010-03-04 Vladimir Serbinenko * Makefile.in (CLEANFILES) [FONT_SOURCE && grub_mkfont]: Add diff --git a/Makefile.in b/Makefile.in index 5a4ef459f..4144dfb5a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -147,7 +147,7 @@ INFOS = $(info_INFOS) CLEANFILES = MOSTLYCLEANFILES = DISTCLEANFILES = config.status config.cache config.log config.h \ - Makefile stamp-h include/grub/cpu include/grub/machine \ + Makefile stamp-h stamp-h1 include/grub/cpu include/grub/machine \ gensymlist.sh genkernsyms.sh build_env.mk \ docs/grub.info docs/version.texi docs/stamp-vti From f209b5b2305bdbed24bf9eb215e9625b7ea878be Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 4 Mar 2010 16:13:35 +0100 Subject: [PATCH 214/237] 2010-03-04 Vladimir Serbinenko * normal/crypto.c (read_crypto_list): Fix a typo. Reported by: Seth Goldberg. --- ChangeLog | 7 +++++++ normal/crypto.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 255d3422c..9246179f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ +2010-03-04 Vladimir Serbinenko + + * normal/crypto.c (read_crypto_list): Fix a typo. + Reported by: Seth Goldberg. + 2010-03-04 Vladimir Serbinenko * Makefile.in (DISTCLEANFILES): Add stamp-h1. + Reported by: Seth Goldberg. 2010-03-04 Vladimir Serbinenko @@ -10,6 +16,7 @@ 2010-03-04 Vladimir Serbinenko * genmk.rb: Remove terminal*.lst in make clean. + Reported by: Seth Goldberg. 2010-03-04 Vladimir Serbinenko diff --git a/normal/crypto.c b/normal/crypto.c index 95899fbd5..f051e2c4c 100644 --- a/normal/crypto.c +++ b/normal/crypto.c @@ -95,7 +95,7 @@ read_crypto_list (void) return; } - /* Override previous commands.lst. */ + /* Override previous crypto.lst. */ grub_crypto_spec_free (); for (;; grub_free (buf)) From 4760f97911b1c2ba2e98efc3e467381d8dc94af0 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Thu, 4 Mar 2010 16:25:26 +0100 Subject: [PATCH 215/237] 2010-03-04 Christian Franke * util/grub-pe2elf.c: Add missing include "progname.h". --- ChangeLog | 4 ++++ util/grub-pe2elf.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9246179f4..634193596 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-04 Christian Franke + + * util/grub-pe2elf.c: Add missing include "progname.h". + 2010-03-04 Vladimir Serbinenko * normal/crypto.c (read_crypto_list): Fix a typo. diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c index 488ad9b23..f370bbfa8 100644 --- a/util/grub-pe2elf.c +++ b/util/grub-pe2elf.c @@ -29,6 +29,8 @@ #include #include +#include "progname.h" + static struct option options[] = { {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, From fc8345da984282291928da32f02f4317e7808a45 Mon Sep 17 00:00:00 2001 From: Jordan Uggla Date: Thu, 4 Mar 2010 16:28:57 +0100 Subject: [PATCH 216/237] 2010-03-04 Jordan Uggla * INSTALL: Add gettext as a dependency and add qemu to a new section "Prerequisites for make-check". --- ChangeLog | 5 +++++ INSTALL | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 634193596..d3d939985 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-03-04 Jordan Uggla + + * INSTALL: Add gettext as a dependency and add qemu to a new section + "Prerequisites for make-check". + 2010-03-04 Christian Franke * util/grub-pe2elf.c: Add missing include "progname.h". diff --git a/INSTALL b/INSTALL index cfade2026..0dd408bcc 100644 --- a/INSTALL +++ b/INSTALL @@ -14,6 +14,7 @@ configuring the GRUB. * GCC 4.1.3 or later * GNU Make * GNU Bison 2.3 or later +* GNU gettext 0.17 or later * GNU binutils 2.9.1.0.23 or later * Other standard GNU/Unix tools @@ -25,6 +26,10 @@ need the following. * Autoconf 2.60 or later * Automake 1.10.1 or later +Prerequisites for make-check: + +* qemu, specifically the binary 'qemu-system-i386' + Configuring the GRUB ==================== From b54d93ac1ba60ddee1a697e2f0b16d848385752f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 4 Mar 2010 17:03:43 +0100 Subject: [PATCH 217/237] 2010-03-04 Vladimir Serbinenko Disable linux.mod on qemu-mips since it's not functional and leads to compilation failure. * conf/mips.rmk (pkglib_MODULES): Remove linux.mod. * conf/mips-yeeloong.rmk (pkglib_MODULES): Add linux.mod. * conf/mips.rmk (linux_mod_SOURCES): Move from here ... * conf/mips-yeeloong.rmk (linux_mod_SOURCES): ... here * conf/mips.rmk (linux_mod_CFLAGS): Move from here ... * conf/mips-yeeloong.rmk (linux_mod_CFLAGS): ... here * conf/mips.rmk (linux_mod_ASFLAGS): Move from here ... * conf/mips-yeeloong.rmk (linux_mod_ASFLAGS): ... here * conf/mips.rmk (linux_mod_LDFLAGS): Move from here ... * conf/mips-yeeloong.rmk (linux_mod_LDFLAGS): ... here Reported by: BVK Chaitanya --- ChangeLog | 17 +++++++++++++++++ conf/mips-yeeloong.rmk | 5 +++++ conf/mips.rmk | 6 ------ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3d939985..039a80a59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2010-03-04 Vladimir Serbinenko + + Disable linux.mod on qemu-mips since it's not functional and leads + to compilation failure. + + * conf/mips.rmk (pkglib_MODULES): Remove linux.mod. + * conf/mips-yeeloong.rmk (pkglib_MODULES): Add linux.mod. + * conf/mips.rmk (linux_mod_SOURCES): Move from here ... + * conf/mips-yeeloong.rmk (linux_mod_SOURCES): ... here + * conf/mips.rmk (linux_mod_CFLAGS): Move from here ... + * conf/mips-yeeloong.rmk (linux_mod_CFLAGS): ... here + * conf/mips.rmk (linux_mod_ASFLAGS): Move from here ... + * conf/mips-yeeloong.rmk (linux_mod_ASFLAGS): ... here + * conf/mips.rmk (linux_mod_LDFLAGS): Move from here ... + * conf/mips-yeeloong.rmk (linux_mod_LDFLAGS): ... here + Reported by: BVK Chaitanya + 2010-03-04 Jordan Uggla * INSTALL: Add gettext as a dependency and add qemu to a new section diff --git a/conf/mips-yeeloong.rmk b/conf/mips-yeeloong.rmk index 0d9a4c1bb..9977f7881 100644 --- a/conf/mips-yeeloong.rmk +++ b/conf/mips-yeeloong.rmk @@ -76,6 +76,11 @@ datehook_mod_SOURCES = hook/datehook.c datehook_mod_CFLAGS = $(COMMON_CFLAGS) datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += linux.mod +linux_mod_SOURCES = loader/$(target_cpu)/linux.c +linux_mod_CFLAGS = $(COMMON_CFLAGS) +linux_mod_ASFLAGS = $(COMMON_ASFLAGS) +linux_mod_LDFLAGS = $(COMMON_LDFLAGS) sbin_SCRIPTS += grub-install grub_install_SOURCES = util/grub-install.in diff --git a/conf/mips.rmk b/conf/mips.rmk index c7c80a26d..536d35cac 100644 --- a/conf/mips.rmk +++ b/conf/mips.rmk @@ -73,10 +73,4 @@ relocator_mod_CFLAGS = $(COMMON_CFLAGS) relocator_mod_ASFLAGS = $(COMMON_ASFLAGS) relocator_mod_LDFLAGS = $(COMMON_LDFLAGS) -pkglib_MODULES += linux.mod -linux_mod_SOURCES = loader/$(target_cpu)/linux.c -linux_mod_CFLAGS = $(COMMON_CFLAGS) -linux_mod_ASFLAGS = $(COMMON_ASFLAGS) -linux_mod_LDFLAGS = $(COMMON_LDFLAGS) - include $(srcdir)/conf/common.mk From 41168ea49c613eec088ffb3dae7e301a86bce8b0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 4 Mar 2010 21:30:58 +0100 Subject: [PATCH 218/237] 2010-03-04 Vladimir Serbinenko * normal/autofs.c (autoload_fs_module): Handle errors. --- ChangeLog | 4 ++++ normal/autofs.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 039a80a59..f72f71783 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-04 Vladimir Serbinenko + + * normal/autofs.c (autoload_fs_module): Handle errors. + 2010-03-04 Vladimir Serbinenko Disable linux.mod on qemu-mips since it's not functional and leads diff --git a/normal/autofs.c b/normal/autofs.c index 57e43fdf4..11b3fc1be 100644 --- a/normal/autofs.c +++ b/normal/autofs.c @@ -38,6 +38,9 @@ autoload_fs_module (void) if (! grub_dl_get (p->name) && grub_dl_load (p->name)) return 1; + if (grub_errno) + grub_print_error (); + fs_module_list = p->next; grub_free (p->name); grub_free (p); From d07803630846b2afda23b926bb28b0523fed8adc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 4 Mar 2010 21:32:11 +0100 Subject: [PATCH 219/237] 2010-03-04 Vladimir Serbinenko * kern/main.c (grub_load_modules): Handle errors from init functions of embeded modules. --- ChangeLog | 5 +++++ kern/main.c | 3 +++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index f72f71783..f3a6a12f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-03-04 Vladimir Serbinenko + + * kern/main.c (grub_load_modules): Handle errors from init functions of + embeded modules. + 2010-03-04 Vladimir Serbinenko * normal/autofs.c (autoload_fs_module): Handle errors. diff --git a/kern/main.c b/kern/main.c index 456105378..e7566fab9 100644 --- a/kern/main.c +++ b/kern/main.c @@ -68,6 +68,9 @@ grub_load_modules (void) (header->size - sizeof (struct grub_module_header)))) grub_fatal ("%s", grub_errmsg); + if (grub_errno) + grub_print_error (); + return 0; } From fcee14ed5fad3455597ac9672c48368b9e324b79 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 4 Mar 2010 21:35:36 +0100 Subject: [PATCH 220/237] 2010-03-04 Vladimir Serbinenko * NEWS: mention multiboot on EFI. --- ChangeLog | 4 ++++ NEWS | 2 ++ 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index f3a6a12f5..bb3637911 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-04 Vladimir Serbinenko + + * NEWS: mention multiboot on EFI. + 2010-03-04 Vladimir Serbinenko * kern/main.c (grub_load_modules): Handle errors from init functions of diff --git a/NEWS b/NEWS index 828eea081..66ac67904 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ New in 1.98: +* Multiboot on EFI support. + * Graphical menu support. * MIPS support. From c7ef54aab162ffa2b8aeb27dd9885686f4c08432 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 4 Mar 2010 22:33:49 +0100 Subject: [PATCH 221/237] 2010-03-04 Vladimir Serbinenko * configure.ac: Alias amd64 to x86_64. --- ChangeLog | 4 ++++ configure.ac | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index bb3637911..e5f1186a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-04 Vladimir Serbinenko + + * configure.ac: Alias amd64 to x86_64. + 2010-03-04 Vladimir Serbinenko * NEWS: mention multiboot on EFI. diff --git a/configure.ac b/configure.ac index ac3f0d196..1f7d6125c 100644 --- a/configure.ac +++ b/configure.ac @@ -51,6 +51,7 @@ fi case "$target_cpu" in i[[3456]]86) target_cpu=i386 ;; + amd64) target_cpu=x86_64 ;; sparc) target_cpu=sparc64 ;; mipsel|mips64el) target_cpu=mips; From d116e0d8d1a8ac94ee8564e565f002f215452e0d Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 4 Mar 2010 23:16:34 +0100 Subject: [PATCH 222/237] 2010-03-04 Robert Millan Support relative image path in theme file. * gfxmenu/gui_image.c (grub_gui_image): New member theme_dir. (image_set_property): Handle theme_dir and relative path. --- ChangeLog | 7 +++++++ gfxmenu/gui_image.c | 25 +++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e5f1186a9..ae4a19108 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-03-04 Robert Millan + + Support relative image path in theme file. + + * gfxmenu/gui_image.c (grub_gui_image): New member theme_dir. + (image_set_property): Handle theme_dir and relative path. + 2010-03-04 Vladimir Serbinenko * configure.ac: Alias amd64 to x86_64. diff --git a/gfxmenu/gui_image.c b/gfxmenu/gui_image.c index ef8bcbe9a..3988f4ba8 100644 --- a/gfxmenu/gui_image.c +++ b/gfxmenu/gui_image.c @@ -31,6 +31,7 @@ struct grub_gui_image grub_gui_container_t parent; grub_video_rect_t bounds; char *id; + char *theme_dir; struct grub_video_bitmap *raw_bitmap; struct grub_video_bitmap *bitmap; }; @@ -208,8 +209,28 @@ static grub_err_t image_set_property (void *vself, const char *name, const char *value) { grub_gui_image_t self = vself; - if (grub_strcmp (name, "file") == 0) - return load_image (self, value); + if (grub_strcmp (name, "theme_dir") == 0) + { + grub_free (self->theme_dir); + self->theme_dir = grub_strdup (value); + } + else if (grub_strcmp (name, "file") == 0) + { + char *absvalue; + grub_err_t err; + + /* Resolve to an absolute path. */ + if (! self->theme_dir) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unspecified theme_dir"); + absvalue = grub_resolve_relative_path (self->theme_dir, value); + if (! absvalue) + return grub_errno; + + err = load_image (self, absvalue); + grub_free (absvalue); + + return err; + } else if (grub_strcmp (name, "id") == 0) { grub_free (self->id); From 3ab4bd77dd3cf74bbe9e304a0c43835cfc4be314 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 5 Mar 2010 15:29:28 +0100 Subject: [PATCH 223/237] 2010-03-04 Vladimir Serbinenko * disk/scsi.c (grub_scsi_iterate): Fix a memory leak. --- ChangeLog | 4 ++++ disk/scsi.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ae4a19108..db2c8855e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-04 Vladimir Serbinenko + + * disk/scsi.c (grub_scsi_iterate): Fix a memory leak. + 2010-03-04 Robert Millan Support relative image path in theme file. diff --git a/disk/scsi.c b/disk/scsi.c index 6f3233b29..eba237287 100644 --- a/disk/scsi.c +++ b/disk/scsi.c @@ -208,12 +208,14 @@ grub_scsi_iterate (int (*hook) (const char *name)) for (i = 0; i < luns; i++) { char *sname; + int ret; sname = grub_xasprintf ("%s%c", name, 'a' + i); if (!sname) return 1; - if (hook (sname)) - return 1; + ret = hook (sname); grub_free (sname); + if (ret) + return 1; } return 0; } From 48a5a769a2b7df4544a3883f4c57aaff72031db2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 5 Mar 2010 15:30:44 +0100 Subject: [PATCH 224/237] 2010-03-04 Vladimir Serbinenko * gettext/gettext.c (grub_gettext_init_ext): Fix a memory leak. --- ChangeLog | 4 ++++ gettext/gettext.c | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index db2c8855e..df53d39ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-04 Vladimir Serbinenko + + * gettext/gettext.c (grub_gettext_init_ext): Fix a memory leak. + 2010-03-04 Vladimir Serbinenko * disk/scsi.c (grub_scsi_iterate): Fix a memory leak. diff --git a/gettext/gettext.c b/gettext/gettext.c index 9a1756be7..0aa8decbd 100644 --- a/gettext/gettext.c +++ b/gettext/gettext.c @@ -279,13 +279,6 @@ grub_gettext_init_ext (const char *lang) /* mo_file e.g.: /boot/grub/locale/ca.mo */ - mo_file = - grub_malloc (grub_strlen (locale_dir) + grub_strlen ("/") + - grub_strlen (lang) + grub_strlen (".mo") + 1); - - /* Warning: if changing some paths in the below line, change the grub_malloc - contents below. */ - mo_file = grub_xasprintf ("%s/%s.mo", locale_dir, lang); if (!mo_file) return; From 60b03859e891684f20c287197f9016231bafbd60 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 5 Mar 2010 15:38:04 +0100 Subject: [PATCH 225/237] 2010-03-05 Vladimir Serbinenko * util/import_gcry.py: Add autogenerated files to MAINTAINER_CLEANFILES. --- ChangeLog | 4 ++++ util/import_gcry.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index df53d39ad..fa2f1ff05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-05 Vladimir Serbinenko + + * util/import_gcry.py: Add autogenerated files to MAINTAINER_CLEANFILES. + 2010-03-04 Vladimir Serbinenko * gettext/gettext.c (grub_gettext_init_ext): Fix a memory leak. diff --git a/util/import_gcry.py b/util/import_gcry.py index d71924d53..b9c3edcde 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -62,6 +62,7 @@ mdblocksizes = {"_gcry_digest_spec_crc32" : 64, "_gcry_digest_spec_whirlpool" : 64} cryptolist = open (os.path.join (cipher_dir_out, "crypto.lst"), "w") +conf.write ("MAINTAINER_CLEANFILES += $(srcdir)/conf/gcry.rmk $(srcdir)/lib/libgcrypt-grub/cipher/ChangeLog $(srcdir)/lib/libgcrypt-grub/cipher/cipher.h $(srcdir)/lib/libgcrypt-grub/cipher/crypto.lst $(srcdir)/lib/libgcrypt-grub/cipher/g10lib.h $(srcdir)/lib/libgcrypt-grub/cipher/memory.h $(srcdir)/lib/libgcrypt-grub/cipher/types.h\n"); # rijndael is the only cipher using aliases. So no need for mangling, just # hardcode it @@ -87,6 +88,7 @@ for cipher_file in cipher_files: continue nch = False if re.match (".*\.[ch]$", cipher_file): + conf.write ("MAINTAINER_CLEANFILES += $(srcdir)/lib/libgcrypt-grub/cipher/" + cipher_file + "\n"); isc = re.match (".*\.c$", cipher_file) f = open (infile, "r") fw = open (outfile, "w") From 8f9a632b96321457a61c03ddff1faf2a373d52bc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Mar 2010 17:22:04 +0100 Subject: [PATCH 226/237] 2010-03-05 Vladimir Serbinenko Fix FreeBSD compilation. * Makefile.in (TARGET_CPPFLAGS): Remove -nostdinc -isystem. * configure.ac: Add -nostdinc -isystem to TARGET_CPPFLAGS if it works. --- ChangeLog | 7 +++++++ Makefile.in | 2 +- configure.ac | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fa2f1ff05..c9356b222 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-03-05 Vladimir Serbinenko + + Fix FreeBSD compilation. + + * Makefile.in (TARGET_CPPFLAGS): Remove -nostdinc -isystem. + * configure.ac: Add -nostdinc -isystem to TARGET_CPPFLAGS if it works. + 2010-03-05 Vladimir Serbinenko * util/import_gcry.py: Add autogenerated files to MAINTAINER_CLEANFILES. diff --git a/Makefile.in b/Makefile.in index 4144dfb5a..47584cdde 100644 --- a/Makefile.in +++ b/Makefile.in @@ -89,7 +89,7 @@ TARGET_ASFLAGS = @TARGET_ASFLAGS@ TARGET_MODULE_FORMAT = @TARGET_MODULE_FORMAT@ TARGET_APPLE_CC = @TARGET_APPLE_CC@ OBJCONV = @OBJCONV@ -TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -nostdinc -isystem $(shell $(TARGET_CC) -print-file-name=include) -I$(srcdir)/include -I$(builddir) -I$(builddir)/include \ +TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I$(srcdir)/include -I$(builddir) -I$(builddir)/include \ -Wall -W TARGET_LDFLAGS = @TARGET_LDFLAGS@ TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@ diff --git a/configure.ac b/configure.ac index 1f7d6125c..cf43608d1 100644 --- a/configure.ac +++ b/configure.ac @@ -517,6 +517,19 @@ enable_efiemu=no fi AC_SUBST([enable_efiemu]) +AC_CACHE_CHECK([whether -nostdinc -isystem works], [grub_cv_cc_isystem], [ + SAVED_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include +int va_arg_func (int fixed, va_list args);]], [[]])], + [grub_cv_cc_isystem=yes], + [grub_cv_cc_isystem=no]) + CPPFLAGS="$SAVED_CPPFLAGS" +]) + +if test x"$grub_cv_cc_isystem" = xyes ; then + TARGET_CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`" +fi # Restore the flags. CC="$tmp_CC" From 2ac227c7f4262618bddc7f3e1a8bbf347bb48af6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Mar 2010 17:25:40 +0100 Subject: [PATCH 227/237] 2010-03-06 Vladimir Serbinenko * loader/i386/multiboot_mbi.c (grub_multiboot_set_bootdev): Free the right pointer. --- ChangeLog | 5 +++++ loader/i386/multiboot_mbi.c | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c9356b222..a7717dfae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-03-06 Vladimir Serbinenko + + * loader/i386/multiboot_mbi.c (grub_multiboot_set_bootdev): Free the + right pointer. + 2010-03-05 Vladimir Serbinenko Fix FreeBSD compilation. diff --git a/loader/i386/multiboot_mbi.c b/loader/i386/multiboot_mbi.c index 3f937c446..6391564d6 100644 --- a/loader/i386/multiboot_mbi.c +++ b/loader/i386/multiboot_mbi.c @@ -448,8 +448,8 @@ grub_multiboot_set_bootdev (void) dev = grub_device_open (0); if (dev && dev->disk && dev->disk->partition) { - - p = dev->disk->partition->partmap->get_name (dev->disk->partition); + char *p0; + p = p0 = dev->disk->partition->partmap->get_name (dev->disk->partition); if (p) { if ((p[0] >= '0') && (p[0] <= '9')) @@ -463,7 +463,7 @@ grub_multiboot_set_bootdev (void) if ((p[0] >= 'a') && (p[0] <= 'z')) part = p[0] - 'a'; } - grub_free (p); + grub_free (p0); } if (dev) grub_device_close (dev); From b1f6d291adc857f385ff7b6d33547cc4e3fad119 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Mar 2010 17:27:28 +0100 Subject: [PATCH 228/237] 2010-03-06 Vladimir Serbinenko * loader/i386/bsd.c (grub_bsd_get_device): Fix a memory leak. --- ChangeLog | 4 ++++ loader/i386/bsd.c | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a7717dfae..f444fe349 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-06 Vladimir Serbinenko + + * loader/i386/bsd.c (grub_bsd_get_device): Fix a memory leak. + 2010-03-06 Vladimir Serbinenko * loader/i386/multiboot_mbi.c (grub_multiboot_set_bootdev): Free the diff --git a/loader/i386/bsd.c b/loader/i386/bsd.c index 3dd3c70c5..949de408d 100644 --- a/loader/i386/bsd.c +++ b/loader/i386/bsd.c @@ -154,8 +154,8 @@ grub_bsd_get_device (grub_uint32_t * biosdev, dev = grub_device_open (0); if (dev && dev->disk && dev->disk->partition) { - - p = dev->disk->partition->partmap->get_name (dev->disk->partition); + char *p0; + p0 = p = dev->disk->partition->partmap->get_name (dev->disk->partition); if (p) { if ((p[0] >= '0') && (p[0] <= '9')) @@ -169,6 +169,7 @@ grub_bsd_get_device (grub_uint32_t * biosdev, if ((p[0] >= 'a') && (p[0] <= 'z')) *part = p[0] - 'a'; } + grub_free (p0); } if (dev) grub_device_close (dev); From 33e2e6f3735eca22021165c5f556b4d8aaafa0bf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Mar 2010 17:28:25 +0100 Subject: [PATCH 229/237] 2010-03-06 Vladimir Serbinenko * util/grub-mkrescue.in: Use mktemp with explicit template. --- ChangeLog | 4 ++++ util/grub-mkrescue.in | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index f444fe349..f42395304 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-06 Vladimir Serbinenko + + * util/grub-mkrescue.in: Use mktemp with explicit template. + 2010-03-06 Vladimir Serbinenko * loader/i386/bsd.c (grub_bsd_get_device): Fix a memory leak. diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index 6b3c9ecb8..592cf2df6 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -86,7 +86,15 @@ if [ "x${output_image}" = x ] ; then exit 1 fi -iso9660_dir=`mktemp -d` +if test "x$TMP" != x; then + MKTEMP_TEMPLATE="$TMP/grub-mkrescue.XXXXXXXXXX" +elif test "x$TEMP" != x; then + MKTEMP_TEMPLATE="$TEMP/grub-mkrescue.XXXXXXXXXX" +else + MKTEMP_TEMPLATE="/tmp/grub-mkrescue.XXXXXXXXXX" +fi + +iso9660_dir=`mktemp -d "$MKTEMP_TEMPLATE"` mkdir -p ${iso9660_dir}/boot/grub process_input_dir () @@ -133,8 +141,8 @@ fi # build coreboot core.img if test -e "${coreboot_dir}" ; then echo "Enabling coreboot support ..." - memdisk_img=`mktemp` - memdisk_dir=`mktemp -d` + memdisk_img=`mktemp "$MKTEMP_TEMPLATE"` + memdisk_dir=`mktemp -d "$MKTEMP_TEMPLATE"` mkdir -p ${memdisk_dir}/boot/grub # obtain date-based UUID iso_uuid=$(date +%Y-%m-%d-%H-%M-%S-00) @@ -162,12 +170,12 @@ fi # build BIOS core.img if test -e "${pc_dir}" ; then echo "Enabling BIOS support ..." - core_img=`mktemp` + core_img=`mktemp "$MKTEMP_TEMPLATE"` grub-mkimage -d ${pc_dir}/ -o ${core_img} --prefix=/boot/grub/i386-pc \ iso9660 biosdisk cat ${pc_dir}/cdboot.img ${core_img} > ${iso9660_dir}/boot/grub/i386-pc/eltorito.img - embed_img=`mktemp` + embed_img=`mktemp "$MKTEMP_TEMPLATE"` cat ${pc_dir}/boot.img ${core_img} > ${embed_img} rm -f ${core_img} From 696fd607c61b87309c0911744d266ef74514e6d9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Mar 2010 17:48:15 +0100 Subject: [PATCH 230/237] 2010-03-06 Vladimir Serbinenko * normal/cmdline.c (grub_cmdline_get): Fix gabled line after completition in the middle of string. --- ChangeLog | 5 +++++ normal/cmdline.c | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index f42395304..4792506a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-03-06 Vladimir Serbinenko + + * normal/cmdline.c (grub_cmdline_get): Fix gabled line after + completition in the middle of string. + 2010-03-06 Vladimir Serbinenko * util/grub-mkrescue.in: Use mktemp with explicit template. diff --git a/normal/cmdline.c b/normal/cmdline.c index f63953944..05d665411 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -303,8 +303,9 @@ grub_cmdline_get (const char *prompt) grub_memmove (buf + lpos, str, len * sizeof (grub_uint32_t)); llen += len; + cl_set_pos_all (); + cl_print_all (lpos, 0); lpos += len; - cl_print_all (lpos - len, 0); cl_set_pos_all (); } } @@ -473,7 +474,6 @@ grub_cmdline_get (const char *prompt) if (t != 1) cl_insert (insert); lpos++; - cl_set_pos_all (); } else { @@ -485,6 +485,7 @@ grub_cmdline_get (const char *prompt) grub_free (insertu8); grub_free (insert); } + cl_set_pos_all (); } break; From d1e8a02f11bdbd11b9e69c5e7b66ed5671b60125 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Mar 2010 21:27:04 +0100 Subject: [PATCH 231/237] 2010-03-06 Vladimir Serbinenko * configure.ac: Update CPPFLAGS and not CFLAGS when checking for ft2build.h. --- ChangeLog | 5 +++++ configure.ac | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4792506a9..33e87f310 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-03-06 Vladimir Serbinenko + + * configure.ac: Update CPPFLAGS and not CFLAGS when checking for + ft2build.h. + 2010-03-06 Vladimir Serbinenko * normal/cmdline.c (grub_cmdline_get): Fix gabled line after diff --git a/configure.ac b/configure.ac index cf43608d1..6deac6c6d 100644 --- a/configure.ac +++ b/configure.ac @@ -696,11 +696,11 @@ fi if test x"$grub_mkfont_excuse" = x ; then # Check for freetype libraries. - SAVED_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $freetype_cflags" + SAVED_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $freetype_cflags" AC_CHECK_HEADERS([ft2build.h], [], [grub_mkfont_excuse=["need freetype2 headers"]]) - CFLAGS="$SAVED_CFLAGS" + CPPFLAGS="$SAVED_CPPFLAGS" fi if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then From fce5d8ff62d3deb264ba5916b62df69998caf916 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 6 Mar 2010 21:49:59 +0100 Subject: [PATCH 232/237] 2010-03-06 Vladimir Serbinenko * NEWS: Put the date of 1.98 release. --- ChangeLog | 4 ++++ NEWS | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 33e87f310..56f19acde 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-06 Vladimir Serbinenko + + * NEWS: Put the date of 1.98 release. + 2010-03-06 Vladimir Serbinenko * configure.ac: Update CPPFLAGS and not CFLAGS when checking for diff --git a/NEWS b/NEWS index 66ac67904..1e3334f18 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -New in 1.98: +New in 1.98 - 2010-03-06: * Multiboot on EFI support. From 1f15fc1e0a37ec338d37ff4ef361a81514098f6a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Mar 2010 23:02:13 +0100 Subject: [PATCH 233/237] 2010-03-07 Vladimir Serbinenko * genmoddep.awk: Output all missing symbols and not only first. --- ChangeLog | 4 ++++ genmoddep.awk | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 56f19acde..667ff0c1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-07 Vladimir Serbinenko + + * genmoddep.awk: Output all missing symbols and not only first. + 2010-03-06 Vladimir Serbinenko * NEWS: Put the date of 1.98 release. diff --git a/genmoddep.awk b/genmoddep.awk index 19ac80c71..48419a091 100644 --- a/genmoddep.awk +++ b/genmoddep.awk @@ -32,13 +32,12 @@ FNR == 1 { else if ($1 != "__gnu_local_gp") { printf "%s in %s is not defined\n", $1, module >"/dev/stderr"; error++; - exit; } } # Output the result. END { - if (error == 1) + if (error >= 1) exit 1; for (mod in modtab) { From 4e02ed5014cc2c88a857581ff17f3de5ebb9b61f Mon Sep 17 00:00:00 2001 From: Matt Kraai Date: Mon, 8 Mar 2010 22:20:02 +0000 Subject: [PATCH 234/237] 2010-03-08 Matt Kraai * util/i386/pc/grub-setup.c (setup): Fix a grammatical error (Debian bug #559005). --- ChangeLog | 5 +++++ util/i386/pc/grub-setup.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 667ff0c1e..18eb66b51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-03-08 Matt Kraai + + * util/i386/pc/grub-setup.c (setup): Fix a grammatical error (Debian + bug #559005). + 2010-03-07 Vladimir Serbinenko * genmoddep.awk: Output all missing symbols and not only first. diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 4e2517ef2..ace577f37 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -418,7 +418,7 @@ unable_to_embed: 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.")); + "their use is discouraged.")); if (! force) grub_util_error (_("if you really want blocklists, use --force")); From d68b491ee2428b3160516d5f35a4eddf904ee114 Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sun, 14 Mar 2010 13:48:55 +0100 Subject: [PATCH 235/237] * util/grub-mkrescue.in: Base ISO UUID on UTC. --- ChangeLog | 4 ++++ util/grub-mkrescue.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 18eb66b51..1977f24ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-03-14 Thorsten Glaser + + * util/grub-mkrescue.in: Base ISO UUID on UTC. + 2010-03-08 Matt Kraai * util/i386/pc/grub-setup.c (setup): Fix a grammatical error (Debian diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index 592cf2df6..db29b0899 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -145,7 +145,7 @@ if test -e "${coreboot_dir}" ; then memdisk_dir=`mktemp -d "$MKTEMP_TEMPLATE"` mkdir -p ${memdisk_dir}/boot/grub # obtain date-based UUID - iso_uuid=$(date +%Y-%m-%d-%H-%M-%S-00) + iso_uuid=$(date -u +%Y-%m-%d-%H-%M-%S-00) modules="$(cat ${coreboot_dir}/partmap.lst) ${modules}" cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg From 18d4c6f0ce0c4021dcadf6275f6208502eb281ff Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Mar 2010 16:32:50 +0100 Subject: [PATCH 236/237] Fix address size in ofwfb on sparc64 (based on info by bvk) --- video/ieee1275.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/video/ieee1275.c b/video/ieee1275.c index 99c54f5ed..5c6bc1594 100644 --- a/video/ieee1275.c +++ b/video/ieee1275.c @@ -124,8 +124,7 @@ grub_video_ieee1275_setup (unsigned int width, unsigned int height, unsigned int mode_type __attribute__ ((unused)), unsigned int mode_mask __attribute__ ((unused))) { - grub_uint32_t current_width, current_height; - grub_addr_t address; + grub_uint32_t current_width, current_height, address; grub_err_t err; grub_ieee1275_phandle_t dev; @@ -167,7 +166,8 @@ grub_video_ieee1275_setup (unsigned int width, unsigned int height, sizeof (address), 0)) return grub_error (GRUB_ERR_IO, "Couldn't retrieve display address."); - framebuffer.ptr = (void *) address; + /* For some reason sparc64 uses 32-bit pointer too. */ + framebuffer.ptr = (void *) (grub_addr_t) address; grub_video_ieee1275_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS, grub_video_fbstd_colors); From 8d7f2981d06ab50e7aef4084ce56e33b1f3ed4c7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Mar 2010 16:55:51 +0100 Subject: [PATCH 237/237] Remove leftover date*.mo on sparc64 --- conf/sparc64-ieee1275.rmk | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index c29f15d14..f8a160e40 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -101,21 +101,4 @@ datetime_mod_SOURCES = lib/ieee1275/datetime.c datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) -pkglib_MODULES += datetime.mod date.mod datehook.mod - -# For datetime.mod -datetime_mod_SOURCES = lib/ieee1275/datetime.c -datetime_mod_CFLAGS = $(COMMON_CFLAGS) -datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For date.mod -date_mod_SOURCES = commands/date.c -date_mod_CFLAGS = $(COMMON_CFLAGS) -date_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For datehook.mod -datehook_mod_SOURCES = hook/datehook.c -datehook_mod_CFLAGS = $(COMMON_CFLAGS) -datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) - include $(srcdir)/conf/common.mk