Blame SOURCES/0140-blscfg-handle-multiple-initramfs-images.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Peter Jones <pjones@redhat.com>
d9d99f
Date: Wed, 11 Apr 2018 13:44:29 -0400
d9d99f
Subject: [PATCH] blscfg: handle multiple initramfs images.
d9d99f
d9d99f
Signed-off-by: Peter Jones <pjones@redhat.com>
d9d99f
---
d9d99f
 grub-core/commands/blscfg.c | 54 ++++++++++++++++++++++++++++++++++++---------
d9d99f
 1 file changed, 44 insertions(+), 10 deletions(-)
d9d99f
d9d99f
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
d9d99f
index e775c6b8794..6ab85df6b3a 100644
d9d99f
--- a/grub-core/commands/blscfg.c
d9d99f
+++ b/grub-core/commands/blscfg.c
d9d99f
@@ -587,6 +587,7 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile)
d9d99f
   char *title = NULL;
d9d99f
   char *clinux = NULL;
d9d99f
   char *options = NULL;
d9d99f
+  char **initrds = NULL;
d9d99f
   char *initrd = NULL;
d9d99f
   char *id = NULL;
d9d99f
   char *hotkey = NULL;
d9d99f
@@ -609,7 +610,7 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile)
d9d99f
 
d9d99f
   title = bls_get_val (entry, "title", NULL);
d9d99f
   options = bls_get_val (entry, "options", NULL);
d9d99f
-  initrd = bls_get_val (entry, "initrd", NULL);
d9d99f
+  initrds = bls_make_list (entry, "initrd", NULL);
d9d99f
   id = bls_get_val (entry, "id", NULL);
d9d99f
 
d9d99f
   hotkey = bls_get_val (entry, "grub_hotkey", NULL);
d9d99f
@@ -624,30 +625,63 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile)
d9d99f
     argv[i] = args[i-1];
d9d99f
   argv[argc] = NULL;
d9d99f
 
d9d99f
-  grub_dprintf("blscfg", "adding menu entry for \"%s\"\n", title);
d9d99f
+  grub_dprintf ("blscfg", "adding menu entry for \"%s\"\n", title);
d9d99f
+  if (initrds)
d9d99f
+    {
d9d99f
+      int initrd_size = sizeof (GRUB_INITRD_CMD);
d9d99f
+      char *tmp;
d9d99f
+
d9d99f
+      for (i = 0; initrds != NULL && initrds[i] != NULL; i++)
d9d99f
+	initrd_size += sizeof (" " GRUB_BOOT_DEVICE) \
d9d99f
+		       + grub_strlen (initrds[i]) + 1;
d9d99f
+      initrd_size += 1;
d9d99f
+
d9d99f
+      initrd = grub_malloc (initrd_size);
d9d99f
+      if (!initrd)
d9d99f
+	{
d9d99f
+	  grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
d9d99f
+	  goto finish;
d9d99f
+	}
d9d99f
+
d9d99f
+
d9d99f
+      tmp = grub_stpcpy(initrd, GRUB_INITRD_CMD);
d9d99f
+      for (i = 0; initrds != NULL && initrds[i] != NULL; i++)
d9d99f
+	{
d9d99f
+	  grub_dprintf ("blscfg", "adding initrd %s\n", initrds[i]);
d9d99f
+	  tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE);
d9d99f
+	  tmp = grub_stpcpy (tmp, initrds[i]);
d9d99f
+	}
d9d99f
+      tmp = grub_stpcpy (tmp, "\n");
d9d99f
+    }
d9d99f
+
d9d99f
   src = grub_xasprintf ("load_video\n"
d9d99f
 			"set gfx_payload=keep\n"
d9d99f
 			"insmod gzio\n"
d9d99f
 			GRUB_LINUX_CMD " %s%s%s%s\n"
d9d99f
-			"%s%s%s%s",
d9d99f
+			"%s",
d9d99f
 			GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "",
d9d99f
-			initrd ? GRUB_INITRD_CMD " " : "", initrd ? GRUB_BOOT_DEVICE : "", initrd ? initrd : "", initrd ? "\n" : "");
d9d99f
+			initrd ? initrd : "");
d9d99f
 
d9d99f
   grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0);
d9d99f
 
d9d99f
 finish:
d9d99f
+  if (initrd)
d9d99f
+    grub_free (initrd);
d9d99f
+
d9d99f
+  if (initrds)
d9d99f
+    grub_free (initrds);
d9d99f
+
d9d99f
   if (classes)
d9d99f
-      grub_free (classes);
d9d99f
-  grub_dprintf("blscfg", "%s got here\n", __func__);
d9d99f
+    grub_free (classes);
d9d99f
+
d9d99f
   if (args)
d9d99f
-      grub_free (args);
d9d99f
+    grub_free (args);
d9d99f
 
d9d99f
   if (argv)
d9d99f
-      grub_free (argv);
d9d99f
+    grub_free (argv);
d9d99f
 
d9d99f
   if (src)
d9d99f
-      grub_free (src);
d9d99f
-  grub_dprintf("blscfg", "%s got here\n", __func__);
d9d99f
+    grub_free (src);
d9d99f
 }
d9d99f
 
d9d99f
 struct find_entry_info {