From 40ea05dee4d26693cb03e3d3157626b64f671da4 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 24 Jun 2011 22:37:17 +0200 Subject: [PATCH 01/20] * grub-core/io/xzio.c: Fix code style issues --- ChangeLog | 4 ++++ grub-core/io/xzio.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f42719bc..286648a46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-06-24 Szymon Janc + + * grub-core/io/xzio.c: Fix code style issues + 2011-06-24 Vladimir Serbinenko 2011-06-24 Manoel Rebelo Abranches diff --git a/grub-core/io/xzio.c b/grub-core/io/xzio.c index 1f42cd242..1575ca236 100644 --- a/grub-core/io/xzio.c +++ b/grub-core/io/xzio.c @@ -48,7 +48,7 @@ static struct grub_fs grub_xzio_fs; static grub_size_t decode_vli (const grub_uint8_t buf[], grub_size_t size_max, - grub_uint64_t * num) + grub_uint64_t *num) { if (size_max == 0) return 0; @@ -71,7 +71,7 @@ decode_vli (const grub_uint8_t buf[], grub_size_t size_max, } static grub_ssize_t -read_vli (grub_file_t file, grub_uint64_t * num) +read_vli (grub_file_t file, grub_uint64_t *num) { grub_uint8_t buf[VLI_MAX_DIGITS]; grub_ssize_t read; @@ -92,6 +92,8 @@ static int test_header (grub_file_t file) { grub_xzio_t xzio = file->data; + enum xz_ret ret; + xzio->buf.in_size = grub_file_read (xzio->file, xzio->inbuf, STREAM_HEADER_SIZE); @@ -101,7 +103,7 @@ test_header (grub_file_t file) return 0; } - enum xz_ret ret = xz_dec_run (xzio->dec, &xzio->buf); + ret = xz_dec_run (xzio->dec, &xzio->buf); if (ret == XZ_FORMAT_ERROR) { @@ -132,8 +134,8 @@ test_footer (grub_file_t file) grub_uint64_t records; grub_file_seek (xzio->file, xzio->file->size - FOOTER_MAGIC_SIZE); - if (grub_file_read (xzio->file, footer, FOOTER_MAGIC_SIZE) != - FOOTER_MAGIC_SIZE + if (grub_file_read (xzio->file, footer, FOOTER_MAGIC_SIZE) + != FOOTER_MAGIC_SIZE || grub_memcmp (footer, FOOTER_MAGIC, FOOTER_MAGIC_SIZE) != 0) goto ERROR; @@ -150,8 +152,8 @@ test_footer (grub_file_t file) xzio->file->size - XZ_STREAM_FOOTER_SIZE - backsize); /* Test index marker. */ - if (grub_file_read (xzio->file, &imarker, sizeof (imarker)) != - sizeof (imarker) && imarker != 0x00) + if (grub_file_read (xzio->file, &imarker, sizeof (imarker)) + != sizeof (imarker) && imarker != 0x00) goto ERROR; if (read_vli (xzio->file, &records) <= 0) From 77c0840ba67302031363479dfbf8bf44ef1ab6d0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Jun 2011 00:18:36 +0200 Subject: [PATCH 02/20] * grub-core/net/i386/pc/pxe.c (grub_pxe_recv): Fix declaration. (grub_pxe_send): Likewise. (GRUB_MOD_INIT): Fix types. --- ChangeLog | 6 ++++++ grub-core/net/i386/pc/pxe.c | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 286648a46..4cac3cd65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-25 Vladimir Serbinenko + + * grub-core/net/i386/pc/pxe.c (grub_pxe_recv): Fix declaration. + (grub_pxe_send): Likewise. + (GRUB_MOD_INIT): Fix types. + 2011-06-24 Szymon Janc * grub-core/io/xzio.c: Fix code style issues diff --git a/grub-core/net/i386/pc/pxe.c b/grub-core/net/i386/pc/pxe.c index 27c4af17f..a23104bad 100644 --- a/grub-core/net/i386/pc/pxe.c +++ b/grub-core/net/i386/pc/pxe.c @@ -305,14 +305,14 @@ static struct grub_fs grub_pxefs_fs = }; static grub_ssize_t -grub_pxe_recv (struct grub_net_card *dev __attribute__ ((unused)), +grub_pxe_recv (const struct grub_net_card *dev __attribute__ ((unused)), struct grub_net_buff *buf __attribute__ ((unused))) { return 0; } static grub_err_t -grub_pxe_send (struct grub_net_card *dev __attribute__ ((unused)), +grub_pxe_send (const struct grub_net_card *dev __attribute__ ((unused)), struct grub_net_buff *buf __attribute__ ((unused))) { return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "not implemented"); @@ -424,7 +424,7 @@ GRUB_MOD_INIT(pxe) { struct grub_pxe_bangpxe *pxenv; struct grub_pxenv_get_cached_info ci; - struct grub_net_bootp_ack *bp; + struct grub_net_bootp_packet *bp; char *buf; pxenv = grub_pxe_scan (); From 6295b32f79acb93df2208321eec491aa6b214fa0 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 25 Jun 2011 01:09:32 +0200 Subject: [PATCH 03/20] * grub-core/kern/main.c (grub_load_normal_mode): Correct the comment. --- ChangeLog | 4 ++++ grub-core/kern/main.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4cac3cd65..c639cb9de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-06-25 Patrick + + * grub-core/kern/main.c (grub_load_normal_mode): Correct the comment. + 2011-06-25 Vladimir Serbinenko * grub-core/net/i386/pc/pxe.c (grub_pxe_recv): Fix declaration. diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c index cc9758988..447f0ae33 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -159,7 +159,7 @@ grub_load_normal_mode (void) /* Load the module. */ grub_dl_load ("normal"); - /* Something went wrong. Print errors here to let user know why we're entering rescue mode. */ + /* Print errors if any. */ grub_print_error (); grub_errno = 0; From cbf597afb158a54ff1d35d4e21f0f6df3c1a01b9 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sun, 26 Jun 2011 17:17:41 +0200 Subject: [PATCH 04/20] * grub-core/commands/cmp.c (grub_cmd_cmp): Remove unnecessary NULL pointer checks before calling grub_free(). * grub-core/commands/wildcard.c (match_devices): Likewise. * grub-core/commands/wildcard.c (match_files): Likewise. * grub-core/fs/cpio.c (grub_cpio_dir): Likewise. * grub-core/fs/cpio.c (grub_cpio_open): Likewise. * grub-core/fs/udf.c (grub_udf_read_block): Likewise. * grub-core/fs/xfs.c (grub_xfs_read_block): Likewise. * grub-core/loader/efi/chainloader.c (grub_cmd_chainloader): Likewise. * grub-core/normal/cmdline.c (grub_cmdline_get): Likewise. * grub-core/script/yylex.l (grub_lexer_unput): Likewise. * grub-core/video/readers/jpeg.c (grub_video_reader_jpeg): Likewise. * grub-core/video/readers/png.c (grub_png_output_byte): Likewise. --- ChangeLog | 16 ++++++++++++++++ grub-core/commands/cmp.c | 6 ++---- grub-core/commands/wildcard.c | 12 ++++-------- grub-core/fs/cpio.c | 13 ++++--------- grub-core/fs/udf.c | 3 +-- grub-core/fs/xfs.c | 3 +-- grub-core/loader/efi/chainloader.c | 3 +-- grub-core/normal/cmdline.c | 6 ++---- grub-core/script/yylex.l | 3 +-- grub-core/video/readers/jpeg.c | 3 +-- grub-core/video/readers/png.c | 3 +-- 11 files changed, 34 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index c639cb9de..17be445af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2011-06-26 Szymon Janc + + * grub-core/commands/cmp.c (grub_cmd_cmp): Remove unnecessary NULL + pointer checks before calling grub_free(). + * grub-core/commands/wildcard.c (match_devices): Likewise. + * grub-core/commands/wildcard.c (match_files): Likewise. + * grub-core/fs/cpio.c (grub_cpio_dir): Likewise. + * grub-core/fs/cpio.c (grub_cpio_open): Likewise. + * grub-core/fs/udf.c (grub_udf_read_block): Likewise. + * grub-core/fs/xfs.c (grub_xfs_read_block): Likewise. + * grub-core/loader/efi/chainloader.c (grub_cmd_chainloader): Likewise. + * grub-core/normal/cmdline.c (grub_cmdline_get): Likewise. + * grub-core/script/yylex.l (grub_lexer_unput): Likewise. + * grub-core/video/readers/jpeg.c (grub_video_reader_jpeg): Likewise. + * grub-core/video/readers/png.c (grub_png_output_byte): Likewise. + 2011-06-25 Patrick * grub-core/kern/main.c (grub_load_normal_mode): Correct the comment. diff --git a/grub-core/commands/cmp.c b/grub-core/commands/cmp.c index 0222927b6..526459311 100644 --- a/grub-core/commands/cmp.c +++ b/grub-core/commands/cmp.c @@ -94,10 +94,8 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)), cleanup: - if (buf1) - grub_free (buf1); - if (buf2) - grub_free (buf2); + grub_free (buf1); + grub_free (buf2); if (file1) grub_file_close (file1); if (file2) diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c index 45d819a3e..d2f4347d5 100644 --- a/grub-core/commands/wildcard.c +++ b/grub-core/commands/wildcard.c @@ -255,8 +255,7 @@ match_devices (const regex_t *regexp, int noparts) for (i = 0; devs && devs[i]; i++) grub_free (devs[i]); - if (devs) - grub_free (devs); + grub_free (devs); return 0; } @@ -342,20 +341,17 @@ match_files (const char *prefix, const char *suffix, const char *end, fail: - if (dir) - grub_free (dir); + grub_free (dir); for (i = 0; files && files[i]; i++) grub_free (files[i]); - if (files) - grub_free (files); + grub_free (files); if (dev) grub_device_close (dev); - if (device_name) - grub_free (device_name); + grub_free (device_name); grub_error_pop (); return 0; diff --git a/grub-core/fs/cpio.c b/grub-core/fs/cpio.c index 3a07873ec..0d84382ac 100644 --- a/grub-core/fs/cpio.c +++ b/grub-core/fs/cpio.c @@ -239,8 +239,7 @@ grub_cpio_dir (grub_device_t device, const char *path, info.mtimeset = 1; hook (name + len, &info); - if (prev) - grub_free (prev); + grub_free (prev); prev = name; } else @@ -251,11 +250,8 @@ grub_cpio_dir (grub_device_t device, const char *path, fail: - if (prev) - grub_free (prev); - - if (data) - grub_free (data); + grub_free (prev); + grub_free (data); grub_dl_unref (my_mod); @@ -326,8 +322,7 @@ grub_cpio_open (grub_file_t file, const char *name) fail: - if (data) - grub_free (data); + grub_free (data); grub_dl_unref (my_mod); diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 48906f84f..e1f115015 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -546,8 +546,7 @@ grub_udf_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) } fail: - if (buf) - grub_free (buf); + grub_free (buf); return 0; } diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c index 1e466465b..eb0783407 100644 --- a/grub-core/fs/xfs.c +++ b/grub-core/fs/xfs.c @@ -324,8 +324,7 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) } } - if (leaf) - grub_free (leaf); + grub_free (leaf); return GRUB_XFS_FSB_TO_BLOCK(node->data, ret); } diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c index 5dd5adab2..3ecdca534 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -329,8 +329,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), if (file) grub_file_close (file); - if (file_path) - grub_free (file_path); + grub_free (file_path); if (address) efi_call_2 (b->free_pages, address, pages); diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c index 09f2271ea..ea06b4cc7 100644 --- a/grub-core/normal/cmdline.c +++ b/grub-core/normal/cmdline.c @@ -500,8 +500,7 @@ grub_cmdline_get (const char *prompt) case GRUB_TERM_CTRL | 'k': if (lpos < llen) { - if (kill_buf) - grub_free (kill_buf); + grub_free (kill_buf); kill_buf = grub_malloc ((llen - lpos + 1) * sizeof (grub_uint32_t)); @@ -566,8 +565,7 @@ grub_cmdline_get (const char *prompt) { grub_size_t n = lpos; - if (kill_buf) - grub_free (kill_buf); + grub_free (kill_buf); kill_buf = grub_malloc (n + 1); if (grub_errno) diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l index 53ae4c54f..96f57dbe6 100644 --- a/grub-core/script/yylex.l +++ b/grub-core/script/yylex.l @@ -355,8 +355,7 @@ grub_lexer_unput (const char *text, yyscan_t yyscanner) { struct grub_lexer_param *lexerstate = yyget_extra (yyscanner)->lexerstate; - if (lexerstate->prefix) - grub_free (lexerstate->prefix); + grub_free (lexerstate->prefix); lexerstate->prefix = grub_strdup (text); if (! lexerstate->prefix) diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c index d61c90ec9..f2351dee9 100644 --- a/grub-core/video/readers/jpeg.c +++ b/grub-core/video/readers/jpeg.c @@ -750,8 +750,7 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap, grub_jpeg_decode_jpeg (data); for (i = 0; i < 4; i++) - if (data->huff_value[i]) - grub_free (data->huff_value[i]); + grub_free (data->huff_value[i]); grub_free (data); } diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c index 5728651e0..ae9879b16 100644 --- a/grub-core/video/readers/png.c +++ b/grub-core/video/readers/png.c @@ -625,8 +625,7 @@ grub_png_output_byte (struct grub_png_data *data, grub_uint8_t n) } } - if (blank_line) - grub_free (blank_line); + grub_free (blank_line); data->cur_column = 0; data->first_line = 0; From 9e322ce8de8526c2c752362749663e6c186f60e3 Mon Sep 17 00:00:00 2001 From: Yves Blusseau Date: Sun, 26 Jun 2011 21:48:52 +0200 Subject: [PATCH 05/20] Display the path of the file when file is not found * grub-core/fs/fat.c: Display the filename when file is not found. * grub-core/fs/fshelp.c: Likewise. * grub-core/fs/hfs.c: Likewise. * grub-core/fs/jfs.c: Likewise. * grub-core/fs/minix.c: Likewise. * grub-core/fs/ufs.c: Likewise. * grub-core/fs/btrfs.c: Likewise. * grub-core/commands/i386/pc/play.c: Likewise. --- ChangeLog | 13 +++++++++++++ grub-core/commands/i386/pc/play.c | 4 ++-- grub-core/fs/btrfs.c | 32 +++++++++++++++++++++++++++---- grub-core/fs/fat.c | 11 +++++++++-- grub-core/fs/fshelp.c | 2 +- grub-core/fs/hfs.c | 2 +- grub-core/fs/jfs.c | 2 +- grub-core/fs/minix.c | 2 +- grub-core/fs/ufs.c | 2 +- 9 files changed, 57 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17be445af..bd6e311bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2011-06-26 Yves Blusseau + + Display the path of the file when file is not found + + * grub-core/fs/fat.c: Display the filename when file is not found. + * grub-core/fs/fshelp.c: Likewise. + * grub-core/fs/hfs.c: Likewise. + * grub-core/fs/jfs.c: Likewise. + * grub-core/fs/minix.c: Likewise. + * grub-core/fs/ufs.c: Likewise. + * grub-core/fs/btrfs.c: Likewise. + * grub-core/commands/i386/pc/play.c: Likewise. + 2011-06-26 Szymon Janc * grub-core/commands/cmp.c (grub_cmd_cmp): Remove unnecessary NULL diff --git a/grub-core/commands/i386/pc/play.c b/grub-core/commands/i386/pc/play.c index 57980eb92..1adf296ec 100644 --- a/grub-core/commands/i386/pc/play.c +++ b/grub-core/commands/i386/pc/play.c @@ -192,7 +192,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), file = grub_file_open (args[0]); if (! file) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", args[0]); if (grub_file_read (file, &tempo, sizeof (tempo)) != sizeof (tempo)) { @@ -227,7 +227,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), 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"); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", args[0]); grub_dprintf ("play","tempo = %d\n", tempo); diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 533529e3f..6470c9819 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -1054,6 +1054,7 @@ find_path (struct grub_btrfs_data *data, const char *ctoken; grub_size_t ctokenlen; char *path_alloc = NULL; + char *origpath = NULL; unsigned symlinks_max = 32; *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; @@ -1062,6 +1063,9 @@ find_path (struct grub_btrfs_data *data, key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; key->offset = 0; skip_default = 1; + origpath = grub_strdup (path); + if (!origpath) + return grub_errno; while (1) { @@ -1086,6 +1090,7 @@ find_path (struct grub_btrfs_data *data, if (*type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY) { grub_free (path_alloc); + grub_free (origpath); return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); } @@ -1098,13 +1103,16 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return err; } if (key_cmp (key, &key_out) != 0) { grub_free (direl); grub_free (path_alloc); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath); + grub_free (origpath); + return err; } struct grub_btrfs_dir_item *cdirel; @@ -1116,6 +1124,7 @@ find_path (struct grub_btrfs_data *data, if (!direl) { grub_free (path_alloc); + grub_free (origpath); return grub_errno; } } @@ -1125,6 +1134,7 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return err; } @@ -1144,7 +1154,9 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath); + grub_free (origpath); + return err; } if (!skip_default) @@ -1158,6 +1170,7 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return grub_error (GRUB_ERR_SYMLINK_LOOP, "too deep nesting of symlinks"); } @@ -1168,6 +1181,7 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return err; } tmp = grub_malloc (grub_le_to_cpu64 (inode.size) @@ -1176,6 +1190,7 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return grub_errno; } @@ -1186,12 +1201,14 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); grub_free (tmp); return grub_errno; } grub_memcpy (tmp + grub_le_to_cpu64 (inode.size), path, grub_strlen (path) + 1); grub_free (path_alloc); + grub_free (origpath); path = path_alloc = tmp; if (path[0] == '/') { @@ -1218,6 +1235,7 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return err; } if (cdirel->key.object_id != key_out.object_id @@ -1225,7 +1243,9 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath); + grub_free (origpath); + return err; } err = grub_btrfs_read_logical (data, elemaddr, &ri, sizeof (ri)); @@ -1233,6 +1253,7 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return err; } key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; @@ -1246,7 +1267,9 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath); + grub_free (origpath); + return err; } *key = cdirel->key; if (*type == GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY) @@ -1254,6 +1277,7 @@ find_path (struct grub_btrfs_data *data, break; default: grub_free (path_alloc); + grub_free (origpath); grub_free (direl); return grub_error (GRUB_ERR_BAD_FS, "unrecognised object type 0x%x", cdirel->key.type); diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c index f617bb0f4..c78d3fbe6 100644 --- a/grub-core/fs/fat.c +++ b/grub-core/fs/fat.c @@ -565,6 +565,7 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, const struct grub_dirhook_info *info)) { char *dirname, *dirp; + char *origpath = NULL; int call_hook; int found = 0; @@ -605,6 +606,10 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, return 0; } + origpath = grub_strdup (path); + if (!origpath) + return 0; + /* Extract a directory name. */ while (*path == '/') path++; @@ -616,7 +621,7 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, dirname = grub_malloc (len + 1); if (! dirname) - return 0; + goto fail; grub_memcpy (dirname, path, len); dirname[len] = '\0'; @@ -629,9 +634,11 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, grub_fat_iterate_dir (disk, data, iter_hook); if (grub_errno == GRUB_ERR_NONE && ! found && !call_hook) - grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath); + fail: grub_free (dirname); + grub_free (origpath); return found ? dirp : 0; } diff --git a/grub-core/fs/fshelp.c b/grub-core/fs/fshelp.c index f879885ac..2ff78c423 100644 --- a/grub-core/fs/fshelp.c +++ b/grub-core/fs/fshelp.c @@ -197,7 +197,7 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode, name = next; } - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", path); } if (!path || path[0] != '/') diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c index cb7679ecb..6f27c69c4 100644 --- a/grub-core/fs/hfs.c +++ b/grub-core/fs/hfs.c @@ -921,7 +921,7 @@ grub_hfs_find_dir (struct grub_hfs_data *data, const char *path, if (! grub_hfs_find_node (data, (char *) &key, data->cat_root, 0, (char *) &fdrec.frec, sizeof (fdrec.frec))) { - grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath); goto fail; } diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c index c131169d8..36ec5fd25 100644 --- a/grub-core/fs/jfs.c +++ b/grub-core/fs/jfs.c @@ -699,7 +699,7 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path) } grub_jfs_closedir (diro); - grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", path); return grub_errno; } diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index 64a64cca0..055f89095 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -424,7 +424,7 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path) pos += sizeof (ino) + data->filename_size; } while (pos < GRUB_MINIX_INODE_SIZE (data)); - grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", path); return grub_errno; } diff --git a/grub-core/fs/ufs.c b/grub-core/fs/ufs.c index 86fe8af65..0f4ea0019 100644 --- a/grub-core/fs/ufs.c +++ b/grub-core/fs/ufs.c @@ -514,7 +514,7 @@ grub_ufs_find_file (struct grub_ufs_data *data, const char *path) pos += grub_le_to_cpu16 (dirent.direntlen); } while (pos < INODE_SIZE (data)); - grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", path); return grub_errno; } From ca80309d32c9d8890d5a16888eac80043a9a16ec Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 08:40:17 +0200 Subject: [PATCH 06/20] * grub-core/net/drivers/ieee1275/ofnet.c (send_card_buffer): Fix prototype. (get_card_packet): Likewise. --- ChangeLog | 6 ++++++ grub-core/net/drivers/ieee1275/ofnet.c | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd6e311bd..62976120f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/net/drivers/ieee1275/ofnet.c (send_card_buffer): Fix + prototype. + (get_card_packet): Likewise. + 2011-06-26 Yves Blusseau Display the path of the file when file is not found diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 2c264edb1..0394e0dc0 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -37,7 +37,7 @@ card_close (struct grub_net_card *dev) } static grub_err_t -send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) +send_card_buffer (const struct grub_net_card *dev, struct grub_net_buff *pack) { int actual; int status; @@ -52,9 +52,8 @@ send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) } static grub_ssize_t -get_card_packet (struct grub_net_card *dev, struct grub_net_buff *nb) +get_card_packet (const struct grub_net_card *dev, struct grub_net_buff *nb) { - int actual, rc; struct grub_ofnetcard_data *data = dev->data; grub_uint64_t start_time; From 41bec7fec9b8a56172ab99997d5c86de9cffd405 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 08:43:13 +0200 Subject: [PATCH 07/20] * grub-core/disk/ahci.c (grub_ahci_readwrite_real): Use proper definitions for dprintf. * grub-core/disk/pata.c (grub_pata_readwrite): Likewise. --- ChangeLog | 6 ++++++ grub-core/disk/ahci.c | 3 ++- grub-core/disk/pata.c | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 62976120f..df640a0ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/disk/ahci.c (grub_ahci_readwrite_real): Use proper + definitions for dprintf. + * grub-core/disk/pata.c (grub_pata_readwrite): Likewise. + 2011-06-27 Vladimir Serbinenko * grub-core/net/drivers/ieee1275/ofnet.c (send_card_buffer): Fix diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index 0f355aa53..415004fcf 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -590,7 +590,8 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev, dev->command_table[0].prdt[0].size = (parms->size + (parms->size & 1) - 1) | GRUB_AHCI_INTERRUPT_ON_COMPLETE; - grub_dprintf ("ahci", "PRDT = %" PRIxGRUB_UINT64_T ", %x, %x (%x)\n", + grub_dprintf ("ahci", "PRDT = %" PRIxGRUB_UINT64_T ", %x, %x (%" + PRIuGRUB_SIZE ")\n", dev->command_table[0].prdt[0].data_base, dev->command_table[0].prdt[0].unused, dev->command_table[0].prdt[0].size, diff --git a/grub-core/disk/pata.c b/grub-core/disk/pata.c index 1cb42d04b..ac3b91a41 100644 --- a/grub-core/disk/pata.c +++ b/grub-core/disk/pata.c @@ -156,7 +156,8 @@ grub_pata_readwrite (struct grub_ata *disk, parms->taskfile.cmd, parms->taskfile.features, parms->taskfile.sectors); - grub_dprintf ("pata", "lba_high=0x%x, lba_mid=0x%x, lba_low=0x%x, size=%d\n", + grub_dprintf ("pata", "lba_high=0x%x, lba_mid=0x%x, lba_low=0x%x, size=%" + PRIuGRUB_SIZE "\n", parms->taskfile.lba_high, parms->taskfile.lba_mid, parms->taskfile.lba_low, parms->size); From 9fc9ce3795196effead800fecffff70c0b3415bd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 08:54:55 +0200 Subject: [PATCH 08/20] Coreboot video support. * grub-core/Makefile.core.def (vga): Extend to coreboot and multiboot. (vbe): Likewise. * grub-core/kern/i386/coreboot/startup.S: Include int.S. * grub-core/kern/i386/pc/startup.S (grub_bios_interrupt): Moved from here ... * grub-core/kern/i386/int.S: ... here. * grub-core/video/i386/pc/vbe.c: Updated includes. * grub-core/video/i386/pc/vga.c: Likewise. * include/grub/i386/coreboot/memory.h (GRUB_MEMORY_MACHINE_SCRATCH_ADDR): New definition. (GRUB_MEMORY_MACHINE_SCRATCH_SEG): Likewise. (GRUB_MEMORY_MACHINE_SCRATCH_SIZE): Likewise. * include/grub/i386/pc/int.h (GRUB_CPU_INT_FLAGS_DEFAULT) [!PCBIOS]: Disable interrupts. * include/grub/i386/pc/vga.h: Removed. All users updated. --- ChangeLog | 20 ++++ grub-core/Makefile.am | 2 + grub-core/Makefile.core.def | 8 +- grub-core/kern/i386/coreboot/startup.S | 1 + grub-core/kern/i386/int.S | 140 +++++++++++++++++++++++++ grub-core/kern/i386/pc/startup.S | 100 +----------------- grub-core/video/i386/pc/vbe.c | 7 +- grub-core/video/i386/pc/vga.c | 5 +- include/grub/i386/coreboot/memory.h | 4 + include/grub/i386/pc/int.h | 5 + include/grub/i386/pc/vga.h | 28 ----- 11 files changed, 184 insertions(+), 136 deletions(-) create mode 100644 grub-core/kern/i386/int.S delete mode 100644 include/grub/i386/pc/vga.h diff --git a/ChangeLog b/ChangeLog index df640a0ef..311e65b05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2011-06-27 Vladimir Serbinenko + + Coreboot video support. + + * grub-core/Makefile.core.def (vga): Extend to coreboot and multiboot. + (vbe): Likewise. + * grub-core/kern/i386/coreboot/startup.S: Include int.S. + * grub-core/kern/i386/pc/startup.S (grub_bios_interrupt): Moved from + here ... + * grub-core/kern/i386/int.S: ... here. + * grub-core/video/i386/pc/vbe.c: Updated includes. + * grub-core/video/i386/pc/vga.c: Likewise. + * include/grub/i386/coreboot/memory.h + (GRUB_MEMORY_MACHINE_SCRATCH_ADDR): New definition. + (GRUB_MEMORY_MACHINE_SCRATCH_SEG): Likewise. + (GRUB_MEMORY_MACHINE_SCRATCH_SIZE): Likewise. + * include/grub/i386/pc/int.h (GRUB_CPU_INT_FLAGS_DEFAULT) [!PCBIOS]: + Disable interrupts. + * include/grub/i386/pc/vga.h: Removed. All users updated. + 2011-06-27 Vladimir Serbinenko * grub-core/disk/ahci.c (grub_ahci_readwrite_real): Use proper diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index a8862b309..c3ecba9cf 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -100,10 +100,12 @@ endif if COND_i386_coreboot KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/i386/pc/int.h endif if COND_i386_multiboot KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/i386/pc/int.h endif if COND_i386_qemu diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 927718359..7a0536b97 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1454,8 +1454,10 @@ module = { module = { name = vga; - i386_pc = video/i386/pc/vga.c; + common = video/i386/pc/vga.c; enable = i386_pc; + enable = i386_coreboot; + enable = i386_multiboot; }; module = { @@ -1533,8 +1535,10 @@ module = { module = { name = vbe; - i386_pc = video/i386/pc/vbe.c; + common = video/i386/pc/vbe.c; enable = i386_pc; + enable = i386_coreboot; + enable = i386_multiboot; }; module = { diff --git a/grub-core/kern/i386/coreboot/startup.S b/grub-core/kern/i386/coreboot/startup.S index cac023ddf..07c5437c0 100644 --- a/grub-core/kern/i386/coreboot/startup.S +++ b/grub-core/kern/i386/coreboot/startup.S @@ -87,3 +87,4 @@ codestart: */ #include "../realmode.S" +#include "../int.S" diff --git a/grub-core/kern/i386/int.S b/grub-core/kern/i386/int.S new file mode 100644 index 000000000..58ccfdaab --- /dev/null +++ b/grub-core/kern/i386/int.S @@ -0,0 +1,140 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010,2011 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 . + */ + +FUNCTION(grub_bios_interrupt) + pushf + cli +#ifndef GRUB_MACHINE_PCBIOS + sidt protidt +#endif + popf + pushl %ebp + pushl %ecx + pushl %eax + pushl %ebx + pushl %esi + pushl %edi + pushl %edx + + movb %al, intno + movl (%edx), %eax + movl %eax, LOCAL(bios_register_eax) + movw 4(%edx), %ax + movw %ax, LOCAL(bios_register_es) + movw 6(%edx), %ax + movw %ax, LOCAL(bios_register_ds) + movw 8(%edx), %ax + movw %ax, LOCAL(bios_register_flags) + + movl 12(%edx), %ebx + movl 16(%edx), %ecx + movl 20(%edx), %edi + movl 24(%edx), %esi + movl 28(%edx), %edx + + call prot_to_real + .code16 + pushf + cli +#ifndef GRUB_MACHINE_PCBIOS + lidt realidt +#endif + + mov %ds, %ax + push %ax + + /* movw imm16, %ax*/ + .byte 0xb8 +LOCAL(bios_register_es): + .short 0 + movw %ax, %es + /* movw imm16, %ax*/ + .byte 0xb8 +LOCAL(bios_register_ds): + .short 0 + movw %ax, %ds + + /* movw imm16, %ax*/ + .byte 0xb8 +LOCAL(bios_register_flags): + .short 0 + push %ax + popf + + /* movl imm32, %eax*/ + .byte 0x66, 0xb8 +LOCAL(bios_register_eax): + .long 0 + + /* int imm8. */ + .byte 0xcd +intno: + .byte 0 + + movl %eax, %cs:LOCAL(bios_register_eax) + movw %ds, %ax + movw %ax, %cs:LOCAL(bios_register_ds) + pop %ax + mov %ax, %ds + pushf + pop %ax + movw %ax, LOCAL(bios_register_flags) + mov %es, %ax + movw %ax, LOCAL(bios_register_es) + + popf + DATA32 call real_to_prot + .code32 + + popl %eax + + movl %ebx, 12(%eax) + movl %ecx, 16(%eax) + movl %edi, 20(%eax) + movl %esi, 24(%eax) + movl %edx, 28(%eax) + + movl %eax, %edx + + movl LOCAL(bios_register_eax), %eax + movl %eax, (%edx) + movw LOCAL(bios_register_es), %ax + movw %ax, 4(%edx) + movw LOCAL(bios_register_ds), %ax + movw %ax, 6(%edx) + movw LOCAL(bios_register_flags), %ax + movw %ax, 8(%edx) + + popl %edi + popl %esi + popl %ebx + popl %eax + popl %ecx + popl %ebp +#ifndef GRUB_MACHINE_PCBIOS + lidt protidt +#endif + ret +#ifndef GRUB_MACHINE_PCBIOS +realidt: + .word 0x100 + .long 0 +protidt: + .word 0 + .long 0 +#endif diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index e78a0aa9a..0fe114add 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -910,102 +910,4 @@ FUNCTION(grub_pxe_call) popl %ebp ret -FUNCTION(grub_bios_interrupt) - pushl %ebp - pushl %ecx - pushl %eax - pushl %ebx - pushl %esi - pushl %edi - pushl %edx - - movb %al, intno - movl (%edx), %eax - movl %eax, LOCAL(bios_register_eax) - movw 4(%edx), %ax - movw %ax, LOCAL(bios_register_es) - movw 6(%edx), %ax - movw %ax, LOCAL(bios_register_ds) - movw 8(%edx), %ax - movw %ax, LOCAL(bios_register_flags) - - movl 12(%edx), %ebx - movl 16(%edx), %ecx - movl 20(%edx), %edi - movl 24(%edx), %esi - movl 28(%edx), %edx - - call prot_to_real - .code16 - - mov %ds, %ax - push %ax - - /* movw imm16, %ax*/ - .byte 0xb8 -LOCAL(bios_register_es): - .short 0 - movw %ax, %es - /* movw imm16, %ax*/ - .byte 0xb8 -LOCAL(bios_register_ds): - .short 0 - movw %ax, %ds - - /* movw imm16, %ax*/ - .byte 0xb8 -LOCAL(bios_register_flags): - .short 0 - push %ax - popf - - /* movl imm32, %eax*/ - .byte 0x66, 0xb8 -LOCAL(bios_register_eax): - .long 0 - - /* int imm8. */ - .byte 0xcd -intno: - .byte 0 - - movl %eax, %cs:LOCAL(bios_register_eax) - movw %ds, %ax - movw %ax, %cs:LOCAL(bios_register_ds) - pop %ax - mov %ax, %ds - pushf - pop %ax - movw %ax, LOCAL(bios_register_flags) - mov %es, %ax - movw %ax, LOCAL(bios_register_es) - - DATA32 call real_to_prot - .code32 - - popl %eax - - movl %ebx, 12(%eax) - movl %ecx, 16(%eax) - movl %edi, 20(%eax) - movl %esi, 24(%eax) - movl %edx, 28(%eax) - - movl %eax, %edx - - movl LOCAL(bios_register_eax), %eax - movl %eax, (%edx) - movw LOCAL(bios_register_es), %ax - movw %ax, 4(%edx) - movw LOCAL(bios_register_ds), %ax - movw %ax, 6(%edx) - movw LOCAL(bios_register_flags), %ax - movw %ax, 8(%edx) - - popl %edi - popl %esi - popl %ebx - popl %eax - popl %ecx - popl %ebp - ret +#include "../int.S" diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index a109bcf43..c11b9a627 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -20,15 +20,14 @@ #include #include -#include -#include +#include #include #include #include #include #include #include -#include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -377,7 +376,7 @@ grub_vbe_set_video_mode (grub_uint32_t vbe_mode, if (vbe_mode < 0x100) { /* If this is not a VESA mode, guess address. */ - framebuffer.ptr = (grub_uint8_t *) GRUB_MEMORY_MACHINE_VGA_ADDR; + framebuffer.ptr = (grub_uint8_t *) 0xa0000; } else { diff --git a/grub-core/video/i386/pc/vga.c b/grub-core/video/i386/pc/vga.c index fe387a26b..08c9ca37d 100644 --- a/grub-core/video/i386/pc/vga.c +++ b/grub-core/video/i386/pc/vga.c @@ -18,8 +18,7 @@ #define grub_video_render_target grub_video_fbrender_target -#include -#include +#include #include #include #include @@ -34,7 +33,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define VGA_WIDTH 640 #define VGA_HEIGHT 350 -#define VGA_MEM ((grub_uint8_t *) GRUB_MEMORY_MACHINE_VGA_ADDR) +#define VGA_MEM ((grub_uint8_t *) 0xa0000) #define PAGE_OFFSET(x) ((x) * (VGA_WIDTH * VGA_HEIGHT / 8)) static unsigned char text_mode; diff --git a/include/grub/i386/coreboot/memory.h b/include/grub/i386/coreboot/memory.h index 0642280b9..2859b1d7c 100644 --- a/include/grub/i386/coreboot/memory.h +++ b/include/grub/i386/coreboot/memory.h @@ -28,6 +28,10 @@ #include #endif +#define GRUB_MEMORY_MACHINE_SCRATCH_ADDR 0x68000 +#define GRUB_MEMORY_MACHINE_SCRATCH_SEG (GRUB_MEMORY_MACHINE_SCRATCH_ADDR >> 4) +#define GRUB_MEMORY_MACHINE_SCRATCH_SIZE 0x10000 + #define GRUB_MEMORY_MACHINE_LOWER_USABLE 0x9fc00 /* 640 kiB - 1 kiB */ #define GRUB_MEMORY_MACHINE_UPPER_START 0x100000 /* 1 MiB */ diff --git a/include/grub/i386/pc/int.h b/include/grub/i386/pc/int.h index de23775d0..337752587 100644 --- a/include/grub/i386/pc/int.h +++ b/include/grub/i386/pc/int.h @@ -45,7 +45,12 @@ struct grub_bios_int_registers #define GRUB_CPU_INT_FLAGS_INTERRUPT 0x200 #define GRUB_CPU_INT_FLAGS_DIRECTION 0x400 #define GRUB_CPU_INT_FLAGS_OVERFLOW 0x800 +#ifdef GRUB_MACHINE_PCBIOS #define GRUB_CPU_INT_FLAGS_DEFAULT GRUB_CPU_INT_FLAGS_INTERRUPT +#else +#define GRUB_CPU_INT_FLAGS_DEFAULT 0 +#endif + void EXPORT_FUNC (grub_bios_interrupt) (grub_uint8_t intno, struct grub_bios_int_registers *regs); diff --git a/include/grub/i386/pc/vga.h b/include/grub/i386/pc/vga.h deleted file mode 100644 index ecc169022..000000000 --- a/include/grub/i386/pc/vga.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,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_VGA_MACHINE_HEADER -#define GRUB_VGA_MACHINE_HEADER 1 - -#include -#include - -/* The VGA (at the beginning of upper memory). */ -#define GRUB_MEMORY_MACHINE_VGA_ADDR GRUB_MEMORY_MACHINE_UPPER - -#endif /* ! GRUB_VGA_MACHINE_HEADER */ From efff4b1cc3e390533a7333420cf980d304bd10bc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 09:06:15 +0200 Subject: [PATCH 09/20] * util/grub-mkrescue.in: Rename "ata" to "pata" and add ahci when necessary. --- ChangeLog | 5 +++++ util/grub-mkrescue.in | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 311e65b05..ca4145e33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-27 Vladimir Serbinenko + + * util/grub-mkrescue.in: Rename "ata" to "pata" and add ahci when + necessary. + 2011-06-27 Vladimir Serbinenko Coreboot video support. diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index 8367c4dd4..f054c43a9 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -275,7 +275,7 @@ if test -e "${pc_dir}" ; then fi # build multiboot core.img -make_image "${multiboot_dir}" i386-multiboot "${iso9660_dir}/boot/multiboot.img" "ata at_keyboard" +make_image "${multiboot_dir}" i386-multiboot "${iso9660_dir}/boot/multiboot.img" "pata ahci at_keyboard" if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then efi_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 @@ -296,11 +296,11 @@ if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then grub_mkisofs_arguments="${grub_mkisofs_arguments} --efi-boot efi.img" fi -make_image "${qemu_dir}" i386-qemu "${iso9660_dir}/boot/qemu.img" "ata at_keyboard" +make_image "${qemu_dir}" i386-qemu "${iso9660_dir}/boot/qemu.img" "pata at_keyboard" if [ -e "${iso9660_dir}/boot/qemu.img" ] && [ -d "${rom_directory}" ]; then cp "${iso9660_dir}/boot/qemu.img" "${rom_directory}/qemu.img" fi -make_image "${coreboot_dir}" i386-coreboot "${iso9660_dir}/boot/coreboot.elf" "ata at_keyboard" +make_image "${coreboot_dir}" i386-coreboot "${iso9660_dir}/boot/coreboot.elf" "pata ahci at_keyboard" if [ -e "${iso9660_dir}/boot/coreboot.elf" ] && [ -d "${rom_directory}" ]; then cp "${iso9660_dir}/boot/coreboot.elf" "${rom_directory}/coreboot.elf" fi From 1e3d9b8612a3f2a4c907b98d6465fcf4e7a53c4e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 10:12:35 +0200 Subject: [PATCH 10/20] * grub-core/disk/scsi.c (grub_scsi_read): Limit SCSI reads to 32K because of underlying system restrictions. --- ChangeLog | 5 +++++ grub-core/disk/scsi.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca4145e33..360842279 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/disk/scsi.c (grub_scsi_read): Limit SCSI reads to 32K + because of underlying system restrictions. + 2011-06-27 Vladimir Serbinenko * util/grub-mkrescue.in: Rename "ata" to "pata" and add ahci when diff --git a/grub-core/disk/scsi.c b/grub-core/disk/scsi.c index 35b8525c2..902564164 100644 --- a/grub-core/disk/scsi.c +++ b/grub-core/disk/scsi.c @@ -524,17 +524,36 @@ grub_scsi_read (grub_disk_t disk, grub_disk_addr_t sector, scsi = disk->data; - /* Depending on the type, select a read function. */ - switch (scsi->devtype) + while (size) { - case grub_scsi_devtype_direct: - return grub_scsi_read10 (disk, sector, size, buf); + /* PATA doesn't support more than 32K reads. + Not sure about AHCI and USB. If it's confirmed that either of + them can do bigger reads reliably this value can be moved to 'scsi' + structure. */ + grub_size_t len = 32768 >> disk->log_sector_size; + grub_err_t err; + if (len > size) + len = size; + /* Depending on the type, select a read function. */ + switch (scsi->devtype) + { + case grub_scsi_devtype_direct: + err = grub_scsi_read10 (disk, sector, len, buf); + if (err) + return err; + break; - case grub_scsi_devtype_cdrom: - return grub_scsi_read12 (disk, sector, size, buf); + case grub_scsi_devtype_cdrom: + err = grub_scsi_read12 (disk, sector, len, buf); + if (err) + return err; + break; + } + size -= len; + sector += len; + buf += len << disk->log_sector_size; } - /* XXX: Never reached. */ return GRUB_ERR_NONE; #if 0 /* Workaround - it works - but very slowly, from some reason From f9b75e8a67f54b425b64c62ea68d7ced88c566bd Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 27 Jun 2011 10:47:02 +0100 Subject: [PATCH 11/20] * grub-core/commands/videoinfo.c (hook): Indicate current video mode with `*'. (grub_cmd_videoinfo): Fetch current video mode. --- ChangeLog | 6 ++++++ grub-core/commands/videoinfo.c | 25 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 360842279..1aabd6b18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-27 Colin Watson + + * grub-core/commands/videoinfo.c (hook): Indicate current video mode + with `*'. + (grub_cmd_videoinfo): Fetch current video mode. + 2011-06-27 Vladimir Serbinenko * grub-core/disk/scsi.c (grub_scsi_read): Limit SCSI reads to 32K diff --git a/grub-core/commands/videoinfo.c b/grub-core/commands/videoinfo.c index 3e0c1a12e..91a87fecc 100644 --- a/grub-core/commands/videoinfo.c +++ b/grub-core/commands/videoinfo.c @@ -28,6 +28,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); static unsigned height, width, depth; +static struct grub_video_mode_info *current_mode; static int hook (const struct grub_video_mode_info *info) @@ -41,7 +42,13 @@ hook (const struct grub_video_mode_info *info) if (info->mode_number == GRUB_VIDEO_MODE_NUMBER_INVALID) grub_printf (" "); else - grub_printf (" 0x%03x ", info->mode_number); + { + if (current_mode && info->mode_number == current_mode->mode_number) + grub_printf ("*"); + else + grub_printf (" "); + grub_printf (" 0x%03x ", info->mode_number); + } grub_printf ("%4d x %4d x %2d ", info->width, info->height, info->bpp); if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT) @@ -122,6 +129,8 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), FOR_VIDEO_ADAPTERS (adapter) { + struct grub_video_mode_info info; + grub_printf ("Adapter '%s':\n", adapter->name); if (!adapter->iterate) @@ -130,7 +139,17 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), continue; } - if (adapter->id != id) + current_mode = NULL; + + if (adapter->id == id) + { + if (grub_video_get_info (&info) == GRUB_ERR_NONE) + current_mode = &info; + else + /* Don't worry about errors. */ + grub_errno = GRUB_ERR_NONE; + } + else { if (adapter->init ()) { @@ -145,6 +164,8 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), adapter->iterate (hook); + current_mode = NULL; + if (adapter->id != id) { if (adapter->fini ()) From b6f945dccbf99c7126cca5b01f4cea807ccffc9e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 12:13:21 +0200 Subject: [PATCH 12/20] * grub-core/net/drivers/ieee1275/ofnet.c (send_card_buffer) Use right type in pointers on sparc64. (get_card_packet): Likewise. --- ChangeLog | 6 ++++++ grub-core/net/drivers/ieee1275/ofnet.c | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1aabd6b18..1a3237f88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/net/drivers/ieee1275/ofnet.c (send_card_buffer) Use right + type in pointers on sparc64. + (get_card_packet): Likewise. + 2011-06-27 Colin Watson * grub-core/commands/videoinfo.c (hook): Indicate current video mode diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 0394e0dc0..b5bb03dc8 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -39,7 +39,7 @@ card_close (struct grub_net_card *dev) static grub_err_t send_card_buffer (const struct grub_net_card *dev, struct grub_net_buff *pack) { - int actual; + grub_ssize_t actual; int status; struct grub_ofnetcard_data *data = dev->data; @@ -54,7 +54,8 @@ send_card_buffer (const struct grub_net_card *dev, struct grub_net_buff *pack) static grub_ssize_t get_card_packet (const struct grub_net_card *dev, struct grub_net_buff *nb) { - int actual, rc; + grub_ssize_t actual; + int rc; struct grub_ofnetcard_data *data = dev->data; grub_uint64_t start_time; From b28c56559b446bdc824fe650a641aa9e11923448 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 12:16:00 +0200 Subject: [PATCH 13/20] * util/ieee1275/grub-ofpathname.c (main): Handle --help and --version so that help2man doesn't fail. --- ChangeLog | 5 +++++ util/ieee1275/grub-ofpathname.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1a3237f88..37446af70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-27 Vladimir Serbinenko + + * util/ieee1275/grub-ofpathname.c (main): Handle --help and --version + so that help2man doesn't fail. + 2011-06-27 Vladimir Serbinenko * grub-core/net/drivers/ieee1275/ofnet.c (send_card_buffer) Use right diff --git a/util/ieee1275/grub-ofpathname.c b/util/ieee1275/grub-ofpathname.c index 3ac6fce8b..a9bc2cfda 100644 --- a/util/ieee1275/grub-ofpathname.c +++ b/util/ieee1275/grub-ofpathname.c @@ -32,11 +32,16 @@ int main(int argc, char **argv) grub_util_init_nls (); - if (argc != 2) + if (argc != 2 || strcmp (argv[1], "--help") == 0) { printf("Usage: %s DEVICE\n", program_name); return 1; } + if (strcmp (argv[1], "--version") == 0) + { + printf ("%s\n", PACKAGE_STRING); + return 1; + } of_path = grub_util_devname_to_ofpath (argv[1]); printf("%s\n", of_path); From bdea37983323f19d0cf8d2ef529d4d0f88ba2d81 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 12:18:44 +0200 Subject: [PATCH 14/20] * grub-core/lib/relocator.c (malloc_in_range): Fix a memory corruption when handling leftovers. --- ChangeLog | 5 +++++ grub-core/lib/relocator.c | 13 +++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37446af70..e35b7c7ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/lib/relocator.c (malloc_in_range): Fix a memory corruption + when handling leftovers. + 2011-06-27 Vladimir Serbinenko * util/ieee1275/grub-ofpathname.c (main): Handle --help and --version diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index 6eb20b865..aa404731f 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -764,6 +764,9 @@ malloc_in_range (struct grub_relocator *rel, int inreg = 0, regbeg = 0, ncol = 0; #if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS int fwin = 0, fwb = 0, fwlefto = 0; +#endif +#if GRUB_RELOCATOR_HAVE_LEFTOVERS + int last_lo = 0; #endif int last_start = 0; for (j = 0; j < N; j++) @@ -855,7 +858,7 @@ malloc_in_range (struct grub_relocator *rel, unsigned offend = alloc_end % GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT; struct grub_relocator_fw_leftover *lo - = events[last_start].leftover; + = events[last_lo].leftover; lo->freebytes[offstart / 8] &= ((1 << (8 - (start % 8))) - 1); grub_memset (lo->freebytes + (offstart + 7) / 8, 0, @@ -910,6 +913,7 @@ malloc_in_range (struct grub_relocator *rel, #if GRUB_RELOCATOR_HAVE_LEFTOVERS case REG_LEFTOVER_START: fwlefto++; + last_lo = j; break; case REG_LEFTOVER_END: @@ -1009,7 +1013,8 @@ malloc_in_range (struct grub_relocator *rel, curschu->extra = ne; } } -#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS + +#if GRUB_RELOCATOR_HAVE_LEFTOVERS if (!oom && typepre == CHUNK_TYPE_FIRMWARE) { grub_addr_t fstart, fend; @@ -1021,7 +1026,6 @@ malloc_in_range (struct grub_relocator *rel, = ALIGN_UP (alloc_end, GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT); -#if GRUB_RELOCATOR_HAVE_LEFTOVERS { struct grub_relocator_fw_leftover *lo1 = NULL; struct grub_relocator_fw_leftover *lo2 = NULL; @@ -1081,10 +1085,8 @@ malloc_in_range (struct grub_relocator *rel, curschu->pre = lo1; curschu->post = lo2; } -#endif } -#if GRUB_RELOCATOR_HAVE_LEFTOVERS if (typepre == CHUNK_TYPE_LEFTOVER) { curschu->pre = events[last_start].leftover; @@ -1092,7 +1094,6 @@ malloc_in_range (struct grub_relocator *rel, } #endif -#endif if (!oom) cural++; else From 5ebaad7eec21a1d209d781b8c0b17f993a238380 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 12:28:47 +0200 Subject: [PATCH 15/20] * include/grub/loader.h (grub_loader_unregister_preboot_hook): Export. --- ChangeLog | 4 ++++ include/grub/loader.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e35b7c7ff..866e2ccaf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-06-27 Vladimir Serbinenko + + * include/grub/loader.h (grub_loader_unregister_preboot_hook): Export. + 2011-06-27 Vladimir Serbinenko * grub-core/lib/relocator.c (malloc_in_range): Fix a memory corruption diff --git a/include/grub/loader.h b/include/grub/loader.h index c71e8dd10..f38deb96a 100644 --- a/include/grub/loader.h +++ b/include/grub/loader.h @@ -61,6 +61,6 @@ void *EXPORT_FUNC(grub_loader_register_preboot_hook) (grub_err_t (*preboot_func) grub_loader_preboot_hook_prio_t prio); /* Unregister given preboot hook. */ -void grub_loader_unregister_preboot_hook (void *hnd); +void EXPORT_FUNC (grub_loader_unregister_preboot_hook) (void *hnd); #endif /* ! GRUB_LOADER_HEADER */ From 5ff1d945ed89aa6203fdc005a55dbb83b3380ea1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 12:31:37 +0200 Subject: [PATCH 16/20] Implement time command. * grub-core/Makefile.core.def (time): New module. * grub-core/commands/time.c: New file. * grub-core/script/parser.y: Remove "time" keyword. * grub-core/script/yylex.l: Likewise. --- ChangeLog | 9 +++++ grub-core/Makefile.core.def | 5 +++ grub-core/commands/time.c | 68 +++++++++++++++++++++++++++++++++++++ grub-core/script/parser.y | 2 -- grub-core/script/yylex.l | 1 - 5 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 grub-core/commands/time.c diff --git a/ChangeLog b/ChangeLog index 866e2ccaf..4cdbc2b15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-06-27 Vladimir Serbinenko + + Implement time command. + + * grub-core/Makefile.core.def (time): New module. + * grub-core/commands/time.c: New file. + * grub-core/script/parser.y: Remove "time" keyword. + * grub-core/script/yylex.l: Likewise. + 2011-06-27 Vladimir Serbinenko * include/grub/loader.h (grub_loader_unregister_preboot_hook): Export. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 7a0536b97..b10c16d55 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1641,3 +1641,8 @@ module = { common = commands/keylayouts.c; enable = videomodules; }; + +module = { + name = time; + common = commands/time.c; +}; diff --git a/grub-core/commands/time.c b/grub-core/commands/time.c new file mode 100644 index 000000000..687495964 --- /dev/null +++ b/grub-core/commands/time.c @@ -0,0 +1,68 @@ +/* echo.c - Command to display a line of text */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 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 + +GRUB_MOD_LICENSE ("GPLv3+"); + + +static grub_err_t +grub_cmd_time (grub_command_t ctxt __attribute__ ((unused)), + int argc, char **args) +{ + grub_command_t cmd; + grub_uint32_t start; + grub_uint32_t end; + + if (argc == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "command expected"); + + cmd = grub_command_find (args[0]); + + if (!cmd) + return grub_error (GRUB_ERR_UNKNOWN_COMMAND, "Unknown command `%s'\n", + args[0]); + + start = grub_get_time_ms (); + (cmd->func) (cmd, argc - 1, &args[1]); + end = grub_get_time_ms (); + + grub_printf ("Elapsed time: %d.%03d seconds \n", (end - start) / 1000, + (end - start) % 1000); + + return grub_errno; +} + +static grub_command_t cmd; + +GRUB_MOD_INIT(time) +{ + cmd = grub_register_command ("time", grub_cmd_time, + N_("COMMAND [ARGS]"), + N_("Measure time used by COMMAND")); +} + +GRUB_MOD_FINI(time) +{ + grub_unregister_command (cmd); +} diff --git a/grub-core/script/parser.y b/grub-core/script/parser.y index 683b3ac4b..cc20b5479 100644 --- a/grub-core/script/parser.y +++ b/grub-core/script/parser.y @@ -74,7 +74,6 @@ %token GRUB_PARSER_TOKEN_THEN "then" %token GRUB_PARSER_TOKEN_UNTIL "until" %token GRUB_PARSER_TOKEN_WHILE "while" -%token GRUB_PARSER_TOKEN_TIME "time" %token GRUB_PARSER_TOKEN_FUNCTION "function" %token GRUB_PARSER_TOKEN_NAME "name" %token GRUB_PARSER_TOKEN_WORD "word" @@ -147,7 +146,6 @@ argument : "case" { $$ = grub_script_add_arglist (state, 0, $1); } | "until" { $$ = grub_script_add_arglist (state, 0, $1); } | "while" { $$ = grub_script_add_arglist (state, 0, $1); } | "function" { $$ = grub_script_add_arglist (state, 0, $1); } - | "time" { $$ = grub_script_add_arglist (state, 0, $1); } | word { $$ = $1; } ; diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l index 96f57dbe6..7195a880d 100644 --- a/grub-core/script/yylex.l +++ b/grub-core/script/yylex.l @@ -161,7 +161,6 @@ MULTILINE {WORD}?((\"{DQCHR}*)|(\'{SQCHR}*)|(\\\n)) "}" { RECORD; return GRUB_PARSER_TOKEN_RBR; } "[[" { RECORD; return GRUB_PARSER_TOKEN_RSQBR2; } "]]" { RECORD; return GRUB_PARSER_TOKEN_LSQBR2; } -"time" { RECORD; return GRUB_PARSER_TOKEN_TIME; } "case" { RECORD; return GRUB_PARSER_TOKEN_CASE; } "do" { RECORD; return GRUB_PARSER_TOKEN_DO; } "done" { RECORD; return GRUB_PARSER_TOKEN_DONE; } From d0b526b2778db75c5cfd01182de7f3808f466a1a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 13:57:03 +0200 Subject: [PATCH 17/20] * grub-core/loader/i386/bsd.c (grub_bsd_load): Handle relocator failure if it happens. --- ChangeLog | 5 +++++ grub-core/loader/i386/bsd.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4cdbc2b15..c097af2f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/loader/i386/bsd.c (grub_bsd_load): Handle relocator failure + if it happens. + 2011-06-27 Vladimir Serbinenko Implement time command. diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index 6487dc3df..dffe48257 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -1322,6 +1322,11 @@ grub_bsd_load (int argc, char *argv[]) goto fail; relocator = grub_relocator_new (); + if (!relocator) + { + grub_file_close (file); + goto fail; + } elf = grub_elf_file (file); if (elf) @@ -1343,7 +1348,7 @@ grub_bsd_load (int argc, char *argv[]) fail: if (grub_errno != GRUB_ERR_NONE) - grub_dl_unref (my_mod); + grub_dl_unref (my_mod); return grub_errno; } From ba7df45ee6be05bb9fd781041f915f112fa8e52c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 14:14:11 +0200 Subject: [PATCH 18/20] Chainloading on coreboot support. * grub-core/Makefile.core.def (chain): Add coreboot. * grub-core/loader/i386/coreboot/chainloader.c: New file. --- ChangeLog | 7 + grub-core/Makefile.core.def | 2 + grub-core/loader/i386/coreboot/chainloader.c | 145 +++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 grub-core/loader/i386/coreboot/chainloader.c diff --git a/ChangeLog b/ChangeLog index c097af2f7..9922f2a2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-06-27 Vladimir Serbinenko + + Chainloading on coreboot support. + + * grub-core/Makefile.core.def (chain): Add coreboot. + * grub-core/loader/i386/coreboot/chainloader.c: New file. + 2011-06-27 Vladimir Serbinenko * grub-core/loader/i386/bsd.c (grub_bsd_load): Handle relocator failure diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index b10c16d55..faed6cc85 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1298,7 +1298,9 @@ module = { name = chain; efi = loader/efi/chainloader.c; i386_pc = loader/i386/pc/chainloader.c; + i386_coreboot = loader/i386/corepayload.c; enable = i386_pc; + enable = i386_coreboot; enable = efi; }; diff --git a/grub-core/loader/i386/coreboot/chainloader.c b/grub-core/loader/i386/coreboot/chainloader.c new file mode 100644 index 000000000..3f85aa3a9 --- /dev/null +++ b/grub-core/loader/i386/coreboot/chainloader.c @@ -0,0 +1,145 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 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 + +GRUB_MOD_LICENSE ("GPLv3+"); + +static grub_addr_t entry; +static struct grub_relocator *relocator = NULL; + +static grub_err_t +grub_chain_boot (void) +{ + struct grub_relocator32_state state; + + grub_video_set_mode ("text", 0, 0); + + state.eip = entry; + return grub_relocator32_boot (relocator, state); +} + +static grub_err_t +grub_chain_unload (void) +{ + grub_relocator_unload (relocator); + relocator = NULL; + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_chain_elf32_hook (Elf32_Phdr * phdr, grub_addr_t * addr, int *do_load) +{ + grub_err_t err; + grub_relocator_chunk_t ch; + + if (phdr->p_type != PT_LOAD) + { + *do_load = 0; + return 0; + } + + *do_load = 1; + err = grub_relocator_alloc_chunk_addr (relocator, &ch, + phdr->p_paddr, phdr->p_memsz); + if (err) + return err; + + *addr = (grub_addr_t) get_virtual_current_address (ch); + + return GRUB_ERR_NONE; +} + + +static grub_err_t +grub_cmd_chain (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) +{ + grub_err_t err; + grub_file_t file; + grub_elf_t elf; + + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "filename expected"); + + grub_loader_unset (); + + file = grub_file_open (argv[0]); + if (!file) + return grub_errno; + + relocator = grub_relocator_new (); + if (!relocator) + { + grub_file_close (file); + return grub_errno; + } + + elf = grub_elf_file (file); + if (!elf) + { + grub_relocator_unload (relocator); + relocator = 0; + grub_file_close (file); + } + + if (!grub_elf_is_elf32 (elf)) + { + grub_relocator_unload (relocator); + relocator = 0; + grub_elf_close (elf); + } + + entry = elf->ehdr.ehdr32.e_entry & 0xFFFFFF; + + err = grub_elf32_load (elf, grub_chain_elf32_hook, 0, 0); + + grub_elf_close (elf); + if (err) + return err; + + grub_loader_set (grub_chain_boot, grub_chain_unload, 0); + return GRUB_ERR_NONE; +} + +static grub_command_t cmd_chain; + +GRUB_MOD_INIT (chain) +{ + cmd_chain = grub_register_command ("chainloader", grub_cmd_chain, + N_("FILE"), N_("Load another payload")); +} + +GRUB_MOD_FINI (chain) +{ + grub_unregister_command (cmd_chain); + grub_chain_unload (); +} From 5afeb5bdd615f18ef58316132112a3a9b6e4c823 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 19:26:52 +0200 Subject: [PATCH 19/20] * grub-core/disk/pata.c (grub_pata_initialize) [QEMU_MIPS]: Fix a mismerge. --- ChangeLog | 5 +++++ grub-core/disk/pata.c | 8 +++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9922f2a2b..a9dacd42b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/disk/pata.c (grub_pata_initialize) [QEMU_MIPS]: Fix a + mismerge. + 2011-06-27 Vladimir Serbinenko Chainloading on coreboot support. diff --git a/grub-core/disk/pata.c b/grub-core/disk/pata.c index ac3b91a41..95828e8f6 100644 --- a/grub-core/disk/pata.c +++ b/grub-core/disk/pata.c @@ -438,15 +438,13 @@ grub_pata_initialize (void) } #else static grub_err_t -grub_ata_initialize (void) +grub_pata_initialize (void) { int i; for (i = 0; i < 2; i++) { - grub_ata_device_initialize (i, 0, grub_ata_ioaddress[i], - grub_ata_ioaddress2[i]); - grub_ata_device_initialize (i, 1, grub_ata_ioaddress[i], - grub_ata_ioaddress2[i]); + grub_pata_device_initialize (i, 0, grub_pata_ioaddress[i]); + grub_pata_device_initialize (i, 1, grub_pata_ioaddress[i]); } return 0; } From 8d5d8444bd95338d487e715e9c93fa3328137b9d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 19:30:16 +0200 Subject: [PATCH 20/20] * grub-core/Makefile.core.def (chain): Fix coreboot filename. --- ChangeLog | 4 ++++ grub-core/Makefile.core.def | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a9dacd42b..81d98716d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/Makefile.core.def (chain): Fix coreboot filename. + 2011-06-27 Vladimir Serbinenko * grub-core/disk/pata.c (grub_pata_initialize) [QEMU_MIPS]: Fix a diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index faed6cc85..fd69e9c22 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1298,7 +1298,7 @@ module = { name = chain; efi = loader/efi/chainloader.c; i386_pc = loader/i386/pc/chainloader.c; - i386_coreboot = loader/i386/corepayload.c; + i386_coreboot = loader/i386/coreboot/chainloader.c; enable = i386_pc; enable = i386_coreboot; enable = efi;