From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1iPCA9-00053S-NK for mharc-grub-devel@gnu.org; Mon, 28 Oct 2019 17:02:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37537) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iPCA5-0004yB-K4 for grub-devel@gnu.org; Mon, 28 Oct 2019 17:02:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iPCA3-0000Gf-R3 for grub-devel@gnu.org; Mon, 28 Oct 2019 17:02:49 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:35894) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iPCA3-0000G5-GD for grub-devel@gnu.org; Mon, 28 Oct 2019 17:02:47 -0400 Received: by mail-wr1-x42c.google.com with SMTP id w18so11399132wrt.3 for ; Mon, 28 Oct 2019 14:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version; bh=LiBKGB1IGtAxqC2f1hqBrnkFF5B8JyX/WABzbNtGuDo=; b=YINpfrNPW6WI6KKBU+lkjUuQGPjeazugEQchtzLSfc7fzeF5OSKy8MW/Gv7aqGljDA bAXw8p9/5vKyXWDO0HQp+mlTae/uxlCZIh6nNmNdR1JeZnE2LPeR0x/b9R+gxVwpnxl0 AuHUiFMinxS7HkN8z/CNftaVdLgkK7iw1ipJaCuOsNQwlKPUMXPxkz+4yluHh7m2oL6s oNXMHwUkMY3vVWJcwROhCQ7FOxOfMYzDnHJnqe8fj+5VjyU/6X0VHOpMBUm8HdRHEpFp RJMR/QIl3cXwtXYU7b4/2ivc00ourMG2kZCNQF6tp9eGNaGJb53BU4h8r5dNCqiqSHbS 2Uig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version; bh=LiBKGB1IGtAxqC2f1hqBrnkFF5B8JyX/WABzbNtGuDo=; b=our6krw+iQzmPA44i5ZSxC4DGX2OZouCWf9CBdVs9NZv1bb+8McduhOEt7qHa5fWoY /dXDh8Dj8yH6N++TQjw4KOqXZI4TO4S4OES0G2D4tFEySYwm6OK09mk+UkTaiNMmipqy BIMauMEBiH8ZgNsBwhSpYBkqGD9W152Yn/+Utj/UD6+87Mj2G/CbyNW+su6sGUU3tBOx fwJ9kkB5yK/fH04gmbS6iRHli1zGvNqHorHZVLKGTcaGhTTL50/rKrWA1Se2Czqu0YG/ i7WyUYUFF4R4mFGzNsHj/zx/TpM/mhhAbSBEvXlhl13E78C3LH0L6B+FnYAJVwPLjpre KAUA== X-Gm-Message-State: APjAAAX3xXAAe9o6hptqwvZo2apsb6FxvokeLnK0mm5Qc93F+WZpopyX Ax9RdgBwworeHFVDK7K4BILiNJetBA4= X-Google-Smtp-Source: APXvYqwW/MY1UT8TsySGBRK0eseF0RIDoLxC9riHgZSJ5Vpo+GRq3SmiCh7T3ZiIs89a/N6pffTV6A== X-Received: by 2002:a5d:4eca:: with SMTP id s10mr17016924wrv.161.1572296566100; Mon, 28 Oct 2019 14:02:46 -0700 (PDT) Received: from localhost (115.201.218.87.dynamic.jazztel.es. [87.218.201.115]) by smtp.gmail.com with ESMTPSA id x12sm830725wmc.4.2019.10.28.14.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 14:02:45 -0700 (PDT) Date: Mon, 28 Oct 2019 22:01:01 +0100 From: Miguel Arruga Vivas To: grub-devel@gnu.org Cc: Daniel Kiper Subject: [PATCH 2/2] install: Add only-platform-installation option. Message-ID: <20191028220101.7b4f4e3b@gmail.com> In-Reply-To: <20191028122743.098fcb72@gmail.com> References: <20191021163021.1a3ca543@gmail.com> <20191023090907.6sfuq6ne5mipdc5r@tomti.i.net-space.pl> <20191028122531.188744b3@gmail.com> <20191028122743.098fcb72@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/DBmwFpF.uYTDfPl3_1MlWm_" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42c X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Oct 2019 21:02:51 -0000 --MP_/DBmwFpF.uYTDfPl3_1MlWm_ Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello again, I've tested this patch on BIOS x86 (on a vm) and x86_64 EFI. Surely it does extra work, plenty of checks and string allocations are not needed at all, because it skips only calls that write files into grubdir or platdir (not macppcdir nor efidir). What do you think? Refactoring the main method may help clarify the flow (checks for the actual hardware/partition configuration -> write files into grub's directory for boot, including early-boot related files -> platform dependant installation), but I'd like to hear some comments on the minimal change before moving code around. Happy hacking! Miguel --MP_/DBmwFpF.uYTDfPl3_1MlWm_ Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0002-install-Add-only-platform-installation-option.patch >From 1c6dd7b456d9efc6fdd30cc5c170817cddb361ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?= Date: Mon, 28 Oct 2019 09:56:06 +0100 Subject: [PATCH 2/2] install: Add only-platform-installation option. * util/grub-install.c (only_platform_installation): New variable. (unnamed enum): Add OPTION_ONLY_PLATFORM_INSTALLATION. (argp_parser): Add check. : New case. (options): Add only-platform-installation option. (main): Do not write into grubdir and platdir when only-platform-installation option is seleted. --- util/grub-install.c | 105 ++++++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 39 deletions(-) diff --git a/util/grub-install.c b/util/grub-install.c index 8f84bf8cd..2b446717e 100644 --- a/util/grub-install.c +++ b/util/grub-install.c @@ -79,6 +79,7 @@ static char *label_color; static char *label_bgcolor; static char *product_version; static int add_rs_codes = 1; +static int only_platform_installation = 0; enum { @@ -109,7 +110,8 @@ enum OPTION_LABEL_FONT, OPTION_LABEL_COLOR, OPTION_LABEL_BGCOLOR, - OPTION_PRODUCT_VERSION + OPTION_PRODUCT_VERSION, + OPTION_ONLY_PLATFORM_INSTALLATION }; static int fs_probe = 1; @@ -197,6 +199,9 @@ argp_parser (int key, char *arg, struct argp_state *state) return 0; case OPTION_NO_NVRAM: + if (only_platform_installation) + grub_util_error ("%s", _("Option --only-platform-installation is " + "incompatible with --no-bootsector/nvram.")); update_nvram = 0; return 0; @@ -217,6 +222,9 @@ argp_parser (int key, char *arg, struct argp_state *state) return 0; case OPTION_NO_BOOTSECTOR: + if (only_platform_installation) + grub_util_error ("%s", _("Option --only-platform-installation is " + "incompatible with --no-bootsector/nvram.")); install_bootsector = 0; return 0; @@ -233,6 +241,13 @@ argp_parser (int key, char *arg, struct argp_state *state) bootloader_id = xstrdup (arg); return 0; + case OPTION_ONLY_PLATFORM_INSTALLATION: + if (!install_bootsector && !update_nvram) + grub_util_error ("%s", _("Option --only-platform-installation is " + "incompatible with --no-bootsector/nvram.")); + only_platform_installation = 1; + return 0; + case ARGP_KEY_ARG: if (install_device) grub_util_error ("%s", _("More than one install device?")); @@ -275,6 +290,8 @@ static struct argp_option options[] = { {"disk-module", OPTION_DISK_MODULE, N_("MODULE"), 0, N_("disk module to use (biosdisk or native). " "This option is only available on BIOS target."), 2}, + {"only-platform-installation", OPTION_ONLY_PLATFORM_INSTALLATION, 0, 0, + N_("only perform the platform-dependant installation."), 0}, {"no-nvram", OPTION_NO_NVRAM, 0, 0, N_("don't update the `boot-device'/`Boot*' NVRAM variables. " "This option is only available on EFI and IEEE1275 targets."), 2}, @@ -533,7 +550,8 @@ probe_cryptodisk_uuid (grub_disk_t disk) free (list); list = tmp; } - if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID) + if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID + && !only_platform_installation) { const char *uuid = grub_util_cryptodisk_get_uuid (disk); if (!load_cfg_f) @@ -1247,11 +1265,12 @@ main (int argc, char *argv[]) } } - grub_install_copy_files (grub_install_source_directory, - grubdir, platform); + if (!only_platform_installation) + grub_install_copy_files (grub_install_source_directory, + grubdir, platform); char *envfile = grub_util_path_concat (2, grubdir, "grubenv"); - if (!grub_util_is_regular (envfile)) + if (!grub_util_is_regular (envfile) && !only_platform_installation) grub_util_create_envblk_file (envfile); size_t ndev = 0; @@ -1343,9 +1362,10 @@ main (int argc, char *argv[]) load_cfg = grub_util_path_concat (2, platdir, "load.cfg"); - grub_util_unlink (load_cfg); + if (!only_platform_installation) + grub_util_unlink (load_cfg); - if (debug_image && debug_image[0]) + if (debug_image && debug_image[0] && !only_platform_installation) { load_cfg_f = grub_util_fopen (load_cfg, "wb"); have_load_cfg = 1; @@ -1375,7 +1395,7 @@ main (int argc, char *argv[]) } } - if (!have_abstractions) + if (!have_abstractions && !only_platform_installation) { if ((disk_module && grub_strcmp (disk_module, "biosdisk") != 0) || grub_drives[1] @@ -1418,8 +1438,9 @@ main (int argc, char *argv[]) grub_util_error (_("Can't create file: %s"), strerror (errno)); fclose (flf); relfl = grub_make_system_path_relative_to_its_root (fl); - fprintf (load_cfg_f, "search.file %s root ", - relfl); + if (!only_platform_installation) + fprintf (load_cfg_f, "search.file %s root ", + relfl); grub_install_push_module ("search_fs_file"); } for (curdev = grub_devices, curdrive = grub_drives; *curdev; curdev++, @@ -1534,7 +1555,7 @@ main (int argc, char *argv[]) prefix_drive = xasprintf ("(%s)", p); } } - else + else if (!only_platform_installation) { if (config.is_cryptodisk_enabled) { @@ -1628,44 +1649,48 @@ main (int argc, char *argv[]) core_name); char *prefix = xasprintf ("%s%s", prefix_drive ? : "", relative_grubdir); - grub_install_make_image_wrap (/* source dir */ grub_install_source_directory, - /*prefix */ prefix, - /* output */ imgfile, - /* memdisk */ NULL, - have_load_cfg ? load_cfg : NULL, - /* image target */ mkimage_target, 0); + if (!only_platform_installation) + grub_install_make_image_wrap (/* source dir */ grub_install_source_directory, + /*prefix */ prefix, + /* output */ imgfile, + /* memdisk */ NULL, + have_load_cfg ? load_cfg : NULL, + /* image target */ mkimage_target, 0); /* Backward-compatibility kludges. */ switch (platform) { case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON: - { - char *dst = grub_util_path_concat (2, bootdir, "grub.elf"); - grub_install_copy_file (imgfile, dst, 1); - free (dst); - } + if (!only_platform_installation) + { + char *dst = grub_util_path_concat (2, bootdir, "grub.elf"); + grub_install_copy_file (imgfile, dst, 1); + free (dst); + } break; case GRUB_INSTALL_PLATFORM_I386_IEEE1275: case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275: - { - char *dst = grub_util_path_concat (2, grubdir, "grub"); - grub_install_copy_file (imgfile, dst, 1); - free (dst); - } + if (!only_platform_installation) + { + char *dst = grub_util_path_concat (2, grubdir, "grub"); + grub_install_copy_file (imgfile, dst, 1); + free (dst); + } break; case GRUB_INSTALL_PLATFORM_I386_EFI: case GRUB_INSTALL_PLATFORM_X86_64_EFI: - { - char *dst = grub_util_path_concat (2, platdir, "grub.efi"); - grub_install_make_image_wrap (/* source dir */ grub_install_source_directory, - /* prefix */ "", - /* output */ dst, - /* memdisk */ NULL, - have_load_cfg ? load_cfg : NULL, - /* image target */ mkimage_target, 0); - free (dst); - } + if (!only_platform_installation) + { + char *dst = grub_util_path_concat (2, platdir, "grub.efi"); + grub_install_make_image_wrap (/* source dir */ grub_install_source_directory, + /* prefix */ "", + /* output */ dst, + /* memdisk */ NULL, + have_load_cfg ? load_cfg : NULL, + /* image target */ mkimage_target, 0); + free (dst); + } break; case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI: @@ -1703,7 +1728,8 @@ main (int argc, char *argv[]) "boot.img"); char *boot_img = grub_util_path_concat (2, platdir, "boot.img"); - grub_install_copy_file (boot_img_src, boot_img, 1); + if (!only_platform_installation) + grub_install_copy_file (boot_img_src, boot_img, 1); grub_util_info ("%sgrub-bios-setup %s %s %s %s %s --directory='%s' --device-map='%s' '%s'", /* TRANSLATORS: This is a prefix in the log to indicate that usually @@ -1732,7 +1758,8 @@ main (int argc, char *argv[]) "boot.img"); char *boot_img = grub_util_path_concat (2, platdir, "boot.img"); - grub_install_copy_file (boot_img_src, boot_img, 1); + if (!only_platform_installation) + grub_install_copy_file (boot_img_src, boot_img, 1); grub_util_info ("%sgrub-sparc64-setup %s %s %s %s --directory='%s' --device-map='%s' '%s'", install_bootsector ? "" : "NOT RUNNING: ", -- 2.23.0 --MP_/DBmwFpF.uYTDfPl3_1MlWm_--