nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0042-util-grub-install.c-List-available-targets.patch

f725e3
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f725e3
From: Vladimir Serbinenko <phcoder@gmail.com>
f725e3
Date: Fri, 24 Jan 2014 18:09:25 +0100
f725e3
Subject: [PATCH] * util/grub-install.c: List available targets.
f725e3
f725e3
---
f725e3
 util/grub-install-common.c  | 30 ++++++++++++++++++++++++++++++
f725e3
 util/grub-install.c         | 10 ++++++++--
f725e3
 include/grub/util/install.h |  2 ++
f725e3
 ChangeLog                   |  4 ++++
f725e3
 4 files changed, 44 insertions(+), 2 deletions(-)
f725e3
f725e3
diff --git a/util/grub-install-common.c b/util/grub-install-common.c
f725e3
index 6ea0a8e1795..c8bedcb2e59 100644
f725e3
--- a/util/grub-install-common.c
f725e3
+++ b/util/grub-install-common.c
f725e3
@@ -667,6 +667,36 @@ static struct
f725e3
     [GRUB_INSTALL_PLATFORM_ARM_UBOOT] =        { "arm",     "uboot"     },
f725e3
   }; 
f725e3
 
f725e3
+char *
f725e3
+grub_install_get_platforms_string (void)
f725e3
+{
f725e3
+  char **arr = xmalloc (sizeof (char *) * ARRAY_SIZE (platforms));
f725e3
+  int platform_strins_len = 0;
f725e3
+  char *platforms_string;
f725e3
+  char *ptr;
f725e3
+  unsigned i;
f725e3
+  for (i = 0; i < ARRAY_SIZE (platforms); i++)
f725e3
+    {
f725e3
+      arr[i] = xasprintf ("%s-%s", platforms[i].cpu,
f725e3
+			  platforms[i].platform);
f725e3
+      platform_strins_len += strlen (arr[i]) + 2;
f725e3
+    }
f725e3
+  ptr = platforms_string = xmalloc (platform_strins_len);
f725e3
+  qsort (arr, ARRAY_SIZE (platforms), sizeof (char *), grub_qsort_strcmp);
f725e3
+  for (i = 0; i < ARRAY_SIZE (platforms); i++)
f725e3
+    {
f725e3
+      strcpy (ptr, arr[i]);
f725e3
+      ptr += strlen (arr[i]);
f725e3
+      *ptr++ = ',';
f725e3
+      *ptr++ = ' ';
f725e3
+      free (arr[i]);
f725e3
+    }
f725e3
+  ptr[-2] = 0;
f725e3
+  free (arr);
f725e3
+ 
f725e3
+  return platforms_string;
f725e3
+}
f725e3
+
f725e3
 char *
f725e3
 grub_install_get_platform_name (enum grub_install_plat platid)
f725e3
 {
f725e3
diff --git a/util/grub-install.c b/util/grub-install.c
f725e3
index 787dc90fce5..2e6226a3716 100644
f725e3
--- a/util/grub-install.c
f725e3
+++ b/util/grub-install.c
f725e3
@@ -256,7 +256,7 @@ static struct argp_option options[] = {
f725e3
    OPTION_HIDDEN, 0, 2},
f725e3
   {"target", OPTION_TARGET, N_("TARGET"),
f725e3
    /* TRANSLATORS: "TARGET" as in "target platform".  */
f725e3
-   0, N_("install GRUB for TARGET platform [default=%s]"), 2},
f725e3
+   0, N_("install GRUB for TARGET platform [default=%s]; available targets: %s"), 2},
f725e3
   {"grub-setup", OPTION_SETUP, "FILE", OPTION_HIDDEN, 0, 2},
f725e3
   {"grub-mkrelpath", OPTION_MKRELPATH, "FILE", OPTION_HIDDEN, 0, 2},
f725e3
   {"grub-mkdevicemap", OPTION_MKDEVICEMAP, "FILE", OPTION_HIDDEN, 0, 2},
f725e3
@@ -340,7 +340,13 @@ help_filter (int key, const char *text, void *input __attribute__ ((unused)))
f725e3
     case OPTION_BOOT_DIRECTORY:
f725e3
       return xasprintf (text, GRUB_DIR_NAME, GRUB_BOOT_DIR_NAME "/" GRUB_DIR_NAME);
f725e3
     case OPTION_TARGET:
f725e3
-      return xasprintf (text, get_default_platform ());
f725e3
+      {
f725e3
+	char *plats = grub_install_get_platforms_string ();
f725e3
+	char *ret;
f725e3
+	ret = xasprintf (text, get_default_platform (), plats);
f725e3
+	free (plats);
f725e3
+	return ret;
f725e3
+      }
f725e3
     case ARGP_KEY_HELP_POST_DOC:
f725e3
       return xasprintf (text, program_name, GRUB_BOOT_DIR_NAME "/" GRUB_DIR_NAME);
f725e3
     default:
f725e3
diff --git a/include/grub/util/install.h b/include/grub/util/install.h
f725e3
index bc987aadc16..aedcd29f905 100644
f725e3
--- a/include/grub/util/install.h
f725e3
+++ b/include/grub/util/install.h
f725e3
@@ -138,6 +138,8 @@ grub_install_get_platform_cpu (enum grub_install_plat platid);
f725e3
 const char *
f725e3
 grub_install_get_platform_platform (enum grub_install_plat platid);
f725e3
 
f725e3
+char *
f725e3
+grub_install_get_platforms_string (void);
f725e3
 
f725e3
 typedef enum {
f725e3
   GRUB_COMPRESSION_AUTO,
f725e3
diff --git a/ChangeLog b/ChangeLog
f725e3
index eee8e78a726..20e8baaa23e 100644
f725e3
--- a/ChangeLog
f725e3
+++ b/ChangeLog
f725e3
@@ -1,3 +1,7 @@
f725e3
+2014-01-24  Vladimir Serbinenko  <phcoder@gmail.com>
f725e3
+
f725e3
+	* util/grub-install.c: List available targets.
f725e3
+
f725e3
 2014-01-23  Colin Watson  <cjwatson@ubuntu.com>
f725e3
 
f725e3
 	* util/grub-install.c (write_to_disk): Add an info message.