All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miguel Arruga Vivas <rosen644835@gmail.com>
To: grub-devel@gnu.org
Cc: Daniel Kiper <dkiper@net-space.pl>
Subject: [PATCH 2/2] install: Add only-platform-installation option.
Date: Mon, 28 Oct 2019 22:01:01 +0100	[thread overview]
Message-ID: <20191028220101.7b4f4e3b@gmail.com> (raw)
In-Reply-To: <20191028122743.098fcb72@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 620 bytes --]

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

[-- Attachment #2: 0002-install-Add-only-platform-installation-option.patch --]
[-- Type: text/x-patch, Size: 8735 bytes --]

From 1c6dd7b456d9efc6fdd30cc5c170817cddb361ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
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)<OPTION_NO_NVRAM, OPTION_NO_BOOTSECTOR>: Add check.
<OPTION_ONLY_PLATFORM_INSTALLATION>: 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


      reply	other threads:[~2019-10-28 21:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-21 14:30 Reproducible grub-install Miguel Arruga Vivas
2019-10-23  9:09 ` Daniel Kiper
2019-10-28 11:25   ` Granularity of grub-install (was Re: Reproducibility of grub-install) Miguel Arruga Vivas
2019-10-28 11:27     ` [PATCH] install: Free allocated path for grub.efi Miguel Arruga Vivas
2019-10-28 21:01       ` Miguel Arruga Vivas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191028220101.7b4f4e3b@gmail.com \
    --to=rosen644835@gmail.com \
    --cc=dkiper@net-space.pl \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.