Received: from list by lists.gnu.org with archive (Exim 4.71) id 1VlKs9-0007VM-Au for mharc-grub-devel@gnu.org; Tue, 26 Nov 2013 10:48:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlKs5-0007VA-Ef for grub-devel@gnu.org; Tue, 26 Nov 2013 10:48:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VlKs3-0007AD-4Z for grub-devel@gnu.org; Tue, 26 Nov 2013 10:48:17 -0500 Received: from mail-ve0-x249.google.com ([2607:f8b0:400c:c01::249]:53134) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlKs2-0007A5-Ua for grub-devel@gnu.org; Tue, 26 Nov 2013 10:48:15 -0500 Received: by mail-ve0-f201.google.com with SMTP id jw12so615307veb.2 for ; Tue, 26 Nov 2013 07:48:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=yOO8oDslNb0AKzyfk2oHDe5GPbnxY64tIQxuNslK6+M=; b=MvBavYC2rXb5TvlQn4lyXiTU5/Gll2aWBgTYO+TzdXGOwk3zt0rl2y9/ioEdoU/if1 IJn+Bn6ubeABDD5pNtTDe3AgPbRRRJ3mz3xAuXmj8AbdUz6GcUtguMq4OP1GAnbIpCI2 yZWE+vuvj8TjyUEYQgwmaiaAFO0PV7Ff0lgdN98J4pL7tpx6DJ0UWtLTc0mDCrCHNTM0 DbIVMyeouR5z08SG+QSU/7l87PXYrEmQH7irjEJtxU2jzhS+hqkPzHZArELRXVkUlg1W H0PKQaHQ+B2CLDR4ogxDC9BUGXf58OHchkHA+c8Vc7qWWWL1qQuH6R37KE+3p3UeZM7P bB3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=yOO8oDslNb0AKzyfk2oHDe5GPbnxY64tIQxuNslK6+M=; b=Xsh8soP01PsBSC9L1R1YFaNQKu2GMbiLuWQWwzmLFH4vQ+DNCBUwowgEZig2s2sj/C Q5xdA5t6TCQfvWawofIrfhCL7evRnD2/VnozTiOlQQoqKuivxb0DtN7KiS0A2eqPtH/i LZiKtw/ceeBd0EwcTpsSxzZH3Vp0xmxqiVh1lf/HuzYjDQXFsfk4aF1A7u/sk6TKhRG4 teCMw7XyEl6Yx7T0wCTNcB0Ypi5qKv5X2HZqb41iYoY1aKy6nfb6jhWHxaF6ZrOLWTHJ HlaaWReGgKkKoa5tEnBFtvjc3bzifuE3rkVoc9ZfgMdAUjlzZn2/By9+Z2o93qoQWnhn ElYQ== X-Gm-Message-State: ALoCoQkMw62fdFVUli8WSp591Y8MGKxJ3uzQO/xRP++fTO9gQR1w31WsOfv4LfonWBcpBuZR1nt7oJaGTkvuKx2vdem+RF6u/9pDcjy0cS8CuHZoEh+owFMmm0D32ok6PWNVKfbWIvvCyoP20wsfJi0IdlBh6m52YFb+c9sUGqbAQ49aN0qEynljvDpksdaY8JCPwG81GFeJR93qslRExoPfZ2A36EqJLFlyCzumvdPJIT3orUrhW4E= X-Received: by 10.52.119.205 with SMTP id kw13mr5321606vdb.3.1385480894417; Tue, 26 Nov 2013 07:48:14 -0800 (PST) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id h47si3275087yhn.0.2013.11.26.07.48.14 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Nov 2013 07:48:14 -0800 (PST) Received: from yinz.mtv.corp.google.com (yinz.mtv.corp.google.com [172.17.81.122]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 34A9031C1DD; Tue, 26 Nov 2013 07:48:14 -0800 (PST) Received: by yinz.mtv.corp.google.com (Postfix, from userid 184367) id D2948C0BB1; Tue, 26 Nov 2013 07:48:13 -0800 (PST) From: Jon McCune To: grub-devel@gnu.org Subject: [PATCH v3] Support to disable reed-solomon codes Date: Tue, 26 Nov 2013 07:48:09 -0800 Message-Id: <1385480889-3249-1-git-send-email-jonmccune@google.com> X-Mailer: git-send-email 1.8.4.1 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400c:c01::249 Cc: Jon McCune X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Nov 2013 15:48:19 -0000 [v0] new grub-*-setup flag to disable insertion of reed solomon codes [v0] grub-install support for option --no-rs-codes [v1] bugfix: also change the maxsec value in util/setup.c [v2] Modified to support new C-language install utilities, added documentation [v3] Incorporate feedback from ML. Most significant changes: Clarify Reed Solomon code behavior in documentation Use positive logic within code Move core.img version check outside add_rs_codes conditional Signed-off-by: Jon McCune --- docs/grub.texi | 14 +++++++++++++- include/grub/util/install.h | 6 ++++-- util/grub-install.c | 19 +++++++++++++++---- util/grub-setup.c | 19 +++++++++++++++++-- util/setup.c | 34 +++++++++++++++++++++------------- 5 files changed, 70 insertions(+), 22 deletions(-) diff --git a/docs/grub.texi b/docs/grub.texi index 6aee292..0cd6af6 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -5937,8 +5937,20 @@ mounted on Recheck the device map, even if @file{/boot/grub/device.map} already exists. You should use this option whenever you add/remove a disk into/from your computer. -@end table +@item --no-rs-codes +By default on x86 BIOS systems, @command{grub-install} will use some +extra space in the bootloader embedding area for Reed-Solomon +error-correcting codes. This enables GRUB to still boot successfully +if some blocks are corrupted. The exact amount of protection offered +is dependent on available space in the embedding area. R sectors of +redundancy can tolerate up to R/2 corrupted sectors. This +redundancy may be cumbersome if attempting to cryptographically +validate the contents of the bootloader embedding area, or in more +modern systems with GPT-style partition tables (@pxref{BIOS +installation}) where GRUB does not reside in any unpartitioned space +outside of the MBR. Disable the Reed-Solomon codes with this option. +@end table @node Invoking grub-mkconfig @chapter Invoking grub-mkconfig diff --git a/include/grub/util/install.h b/include/grub/util/install.h index 5cb33fc..39e87b8 100644 --- a/include/grub/util/install.h +++ b/include/grub/util/install.h @@ -176,12 +176,14 @@ void grub_util_bios_setup (const char *dir, const char *boot_file, const char *core_file, const char *dest, int force, - int fs_probe, int allow_floppy); + int fs_probe, int allow_floppy, + int add_rs_codes); void grub_util_sparc_setup (const char *dir, const char *boot_file, const char *core_file, const char *dest, int force, - int fs_probe, int allow_floppy); + int fs_probe, int allow_floppy, + int add_rs_codes __attribute__ ((unused))); char * grub_install_get_image_targets_string (void); diff --git a/util/grub-install.c b/util/grub-install.c index 5354a6d..88215e2 100644 --- a/util/grub-install.c +++ b/util/grub-install.c @@ -68,6 +68,7 @@ static int have_load_cfg = 0; static FILE * load_cfg_f = NULL; static char *load_cfg; static int install_bootsector = 1; +static int add_rs_codes = 1; enum { @@ -93,7 +94,8 @@ enum OPTION_DEBUG_IMAGE, OPTION_NO_FLOPPY, OPTION_DISK_MODULE, - OPTION_NO_BOOTSECTOR + OPTION_NO_BOOTSECTOR, + OPTION_NO_RS_CODES, }; static int fs_probe = 1; @@ -180,6 +182,10 @@ argp_parser (int key, char *arg, struct argp_state *state) install_bootsector = 0; return 0; + case OPTION_NO_RS_CODES: + add_rs_codes = 0; + return 0; + case OPTION_DEBUG: verbosity++; return 0; @@ -238,6 +244,9 @@ static struct argp_option options[] = { N_("do not probe for filesystems in DEVICE"), 0}, {"no-bootsector", OPTION_NO_BOOTSECTOR, 0, 0, N_("do not install bootsector"), 0}, + {"no-rs-codes", OPTION_NO_RS_CODES, 0, 0, + N_("Do not apply any reed-solomon codes when embedding core.img. " + "This option is only available on x86 BIOS targets."), 0}, {"debug", OPTION_DEBUG, 0, OPTION_HIDDEN, 0, 2}, {"no-floppy", OPTION_NO_FLOPPY, 0, OPTION_HIDDEN, 0, 2}, @@ -1412,12 +1421,13 @@ main (int argc, char *argv[]) "boot.img"); grub_install_copy_file (boot_img_src, boot_img, 1); - grub_util_info ("%sgrub-bios-setup %s %s %s %s --directory='%s' --device-map='%s' '%s'", + grub_util_info ("%sgrub-bios-setup %s %s %s %s %s --directory='%s' --device-map='%s' '%s'", install_bootsector ? "" : "NOT RUNNING: ", allow_floppy ? "--allow-floppy " : "", verbosity ? "--verbose " : "", force ? "--force " : "", !fs_probe ? "--skip-fs-probe" : "", + !add_rs_codes ? "--no-rs-codes" : "", platdir, device_map, install_device); @@ -1426,7 +1436,7 @@ main (int argc, char *argv[]) if (install_bootsector) grub_util_bios_setup (platdir, "boot.img", "core.img", install_drive, force, - fs_probe, allow_floppy); + fs_probe, allow_floppy, add_rs_codes); break; } case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275: @@ -1452,7 +1462,8 @@ main (int argc, char *argv[]) if (install_bootsector) grub_util_sparc_setup (platdir, "boot.img", "core.img", install_device, force, - fs_probe, allow_floppy); + fs_probe, allow_floppy, + 0 /* unused */ ); break; } diff --git a/util/grub-setup.c b/util/grub-setup.c index 90b9de0..338fdda 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -64,6 +64,12 @@ #define DEFAULT_BOOT_FILE "boot.img" #define DEFAULT_CORE_FILE "core.img" +/* The short form of options is described in util/argp.h as: + * "What key is returned for this option. If > 0 and printable, then it's + * also accepted as a short option." + * We use a negative value so that only the long form is accepted. */ +#define NO_RS_CODES_KEY -1 + static struct argp_option options[] = { {"boot-image", 'b', N_("FILE"), 0, N_("use FILE as the boot image [default=%s]"), 0}, @@ -82,7 +88,9 @@ static struct argp_option options[] = { /* TRANSLATORS: The potential breakage isn't limited to floppies but it's likely to make the install unbootable from HDD. */ N_("make the drive also bootable as floppy (default for fdX devices). May break on some BIOSes."), 0}, - + {"no-rs-codes", NO_RS_CODES_KEY, 0, 0, + N_("Do not apply any reed-solomon codes when embedding core.img. " + "This option is only available on x86 BIOS targets."), 0}, { 0, 0, 0, 0, 0, 0 } }; @@ -118,6 +126,7 @@ struct arguments int fs_probe; int allow_floppy; char *device; + int add_rs_codes; }; static error_t @@ -173,6 +182,10 @@ argp_parser (int key, char *arg, struct argp_state *state) verbosity++; break; + case NO_RS_CODES_KEY: + arguments->add_rs_codes = 0; + break; + case ARGP_KEY_ARG: if (state->arg_num == 0) arguments->device = xstrdup(arg); @@ -233,6 +246,7 @@ main (int argc, char *argv[]) /* Default option values. */ memset (&arguments, 0, sizeof (struct arguments)); arguments.fs_probe = 1; + arguments.add_rs_codes = 1; /* Parse our arguments */ if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0) @@ -292,7 +306,8 @@ main (int argc, char *argv[]) arguments.boot_file ? : DEFAULT_BOOT_FILE, arguments.core_file ? : DEFAULT_CORE_FILE, dest_dev, arguments.force, - arguments.fs_probe, arguments.allow_floppy); + arguments.fs_probe, arguments.allow_floppy, + arguments.add_rs_codes); /* Free resources. */ grub_fini_all (); diff --git a/util/setup.c b/util/setup.c index 337c304..e8028d6 100644 --- a/util/setup.c +++ b/util/setup.c @@ -248,7 +248,7 @@ void SETUP (const char *dir, const char *boot_file, const char *core_file, const char *dest, int force, - int fs_probe, int allow_floppy) + int fs_probe, int allow_floppy, int add_rs_codes) { char *core_path; char *boot_img, *core_img, *boot_path; @@ -486,7 +486,11 @@ SETUP (const char *dir, nsec = core_sectors; - maxsec = 2 * core_sectors; + if (add_rs_codes) + maxsec = 2 * core_sectors; + else + maxsec = core_sectors; + if (maxsec > ((0x78000 - GRUB_KERNEL_I386_PC_LINK_ADDR) >> GRUB_DISK_SECTOR_BITS)) maxsec = ((0x78000 - GRUB_KERNEL_I386_PC_LINK_ADDR) @@ -549,9 +553,6 @@ SETUP (const char *dir, - sizeof (*bl.block)); grub_size_t no_rs_length; - grub_set_unaligned32 ((core_img + GRUB_DISK_SECTOR_SIZE - + GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY), - grub_host_to_target32 (nsec * GRUB_DISK_SECTOR_SIZE - core_size)); no_rs_length = grub_target_to_host16 (grub_get_unaligned16 (core_img + GRUB_DISK_SECTOR_SIZE @@ -560,14 +561,21 @@ SETUP (const char *dir, if (no_rs_length == 0xffff) grub_util_error ("%s", _("core.img version mismatch")); - void *tmp = xmalloc (core_size); - grub_memcpy (tmp, core_img, core_size); - grub_reed_solomon_add_redundancy (core_img + no_rs_length + GRUB_DISK_SECTOR_SIZE, - core_size - no_rs_length - GRUB_DISK_SECTOR_SIZE, - nsec * GRUB_DISK_SECTOR_SIZE - - core_size); - assert (grub_memcmp (tmp, core_img, core_size) == 0); - free (tmp); + if (add_rs_codes) + { + grub_set_unaligned32 ((core_img + GRUB_DISK_SECTOR_SIZE + + GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY), + grub_host_to_target32 (nsec * GRUB_DISK_SECTOR_SIZE - core_size)); + + void *tmp = xmalloc (core_size); + grub_memcpy (tmp, core_img, core_size); + grub_reed_solomon_add_redundancy (core_img + no_rs_length + GRUB_DISK_SECTOR_SIZE, + core_size - no_rs_length - GRUB_DISK_SECTOR_SIZE, + nsec * GRUB_DISK_SECTOR_SIZE + - core_size); + assert (grub_memcmp (tmp, core_img, core_size) == 0); + free (tmp); + } /* Write the core image onto the disk. */ for (i = 0; i < nsec; i++) -- 1.8.4.1