Blame SOURCES/0096-IBM-client-architecture-CAS-reboot-support.patch

f731ee
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f731ee
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
f731ee
Date: Thu, 20 Sep 2012 18:07:39 -0300
f731ee
Subject: [PATCH] IBM client architecture (CAS) reboot support
f731ee
f731ee
This is an implementation of IBM client architecture (CAS) reboot for GRUB.
f731ee
f731ee
There are cases where the POWER firmware must reboot in order to support
f731ee
specific features requested by a kernel. The kernel calls
f731ee
ibm,client-architecture-support and it may either return or reboot with the new
f731ee
feature set. eg:
f731ee
f731ee
Calling ibm,client-architecture-support.../
f731ee
Elapsed time since release of system processors: 70959 mins 50 secs
f731ee
Welcome to GRUB!
f731ee
f731ee
Instead of return to the GRUB menu, it will check if the flag for CAS reboot is
f731ee
set. If so, grub will automatically boot the last booted kernel using the same
f731ee
parameters
f731ee
---
f731ee
 grub-core/kern/ieee1275/openfw.c | 62 ++++++++++++++++++++++++++++++++++++++++
f731ee
 grub-core/normal/main.c          | 19 ++++++++++++
f731ee
 grub-core/script/execute.c       |  7 +++++
f731ee
 include/grub/ieee1275/ieee1275.h |  2 ++
f731ee
 4 files changed, 90 insertions(+)
f731ee
f731ee
diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c
f731ee
index ddb778340e4..6db8b986551 100644
f731ee
--- a/grub-core/kern/ieee1275/openfw.c
f731ee
+++ b/grub-core/kern/ieee1275/openfw.c
f731ee
@@ -561,3 +561,65 @@ grub_ieee1275_canonicalise_devname (const char *path)
f731ee
   return NULL;
f731ee
 }
f731ee
 
f731ee
+/* Check if it's a CAS reboot. If so, set the script to be executed.  */
f731ee
+int
f731ee
+grub_ieee1275_cas_reboot (char *script)
f731ee
+{
f731ee
+  grub_uint32_t ibm_ca_support_reboot;
f731ee
+  grub_uint32_t ibm_fw_nbr_reboots;
f731ee
+  char property_value[10];
f731ee
+  grub_ssize_t actual;
f731ee
+  grub_ieee1275_ihandle_t options;
f731ee
+
f731ee
+  if (grub_ieee1275_finddevice ("/options", &options) < 0)
f731ee
+    return -1;
f731ee
+
f731ee
+  /* Check two properties, one is enough to get cas reboot value */
f731ee
+  ibm_ca_support_reboot = 0;
f731ee
+  if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen,
f731ee
+                                          "ibm,client-architecture-support-reboot",
f731ee
+                                          &ibm_ca_support_reboot,
f731ee
+                                          sizeof (ibm_ca_support_reboot),
f731ee
+                                          &actual) >= 0)
f731ee
+    grub_dprintf("ieee1275", "ibm,client-architecture-support-reboot: %u\n",
f731ee
+                 ibm_ca_support_reboot);
f731ee
+
f731ee
+  ibm_fw_nbr_reboots = 0;
f731ee
+  if (grub_ieee1275_get_property (options, "ibm,fw-nbr-reboots",
f731ee
+                                  property_value, sizeof (property_value),
f731ee
+                                  &actual) >= 0)
f731ee
+    {
f731ee
+      property_value[sizeof (property_value) - 1] = 0;
f731ee
+      ibm_fw_nbr_reboots = (grub_uint8_t) grub_strtoul (property_value, 0, 10);
f731ee
+      grub_dprintf("ieee1275", "ibm,fw-nbr-reboots: %u\n", ibm_fw_nbr_reboots);
f731ee
+    }
f731ee
+
f731ee
+  if (ibm_ca_support_reboot || ibm_fw_nbr_reboots)
f731ee
+    {
f731ee
+      if (! grub_ieee1275_get_property_length (options, "boot-last-label", &actual))
f731ee
+        {
f731ee
+          if (actual > 1024)
f731ee
+            script = grub_realloc (script, actual + 1);
f731ee
+          grub_ieee1275_get_property (options, "boot-last-label", script, actual,
f731ee
+                                      &actual);
f731ee
+          return 0;
f731ee
+        }
f731ee
+    }
f731ee
+
f731ee
+  grub_ieee1275_set_boot_last_label ("");
f731ee
+
f731ee
+  return -1;
f731ee
+}
f731ee
+
f731ee
+int grub_ieee1275_set_boot_last_label (const char *text)
f731ee
+{
f731ee
+  grub_ieee1275_ihandle_t options;
f731ee
+  grub_ssize_t actual;
f731ee
+
f731ee
+  grub_dprintf("ieee1275", "set boot_last_label (size: %u)\n", grub_strlen(text));
f731ee
+  if (! grub_ieee1275_finddevice ("/options", &options) &&
f731ee
+      options != (grub_ieee1275_ihandle_t) -1)
f731ee
+    grub_ieee1275_set_property (options, "boot-last-label", text,
f731ee
+                                grub_strlen (text), &actual);
f731ee
+  return 0;
f731ee
+}
f731ee
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
f731ee
index 6f4970f71c1..f72844c9f37 100644
f731ee
--- a/grub-core/normal/main.c
f731ee
+++ b/grub-core/normal/main.c
f731ee
@@ -33,6 +33,9 @@
f731ee
 #include <grub/charset.h>
f731ee
 #include <grub/script_sh.h>
f731ee
 #include <grub/bufio.h>
f731ee
+#ifdef GRUB_MACHINE_IEEE1275
f731ee
+#include <grub/ieee1275/ieee1275.h>
f731ee
+#endif
f731ee
 
f731ee
 GRUB_MOD_LICENSE ("GPLv3+");
f731ee
 
f731ee
@@ -275,6 +278,22 @@ grub_normal_execute (const char *config, int nested, int batch)
f731ee
     {
f731ee
       menu = read_config_file (config);
f731ee
 
f731ee
+#ifdef GRUB_MACHINE_IEEE1275
f731ee
+      int boot;
f731ee
+      boot = 0;
f731ee
+      char *script;
f731ee
+      script = grub_malloc (1024);
f731ee
+      if (! grub_ieee1275_cas_reboot (script))
f731ee
+        {
f731ee
+          char *dummy[1] = { NULL };
f731ee
+          if (! grub_script_execute_sourcecode (script, 0, dummy))
f731ee
+            boot = 1;
f731ee
+        }
f731ee
+      grub_free (script);
f731ee
+      if (boot)
f731ee
+        grub_command_execute ("boot", 0, 0);
f731ee
+#endif
f731ee
+
f731ee
       /* Ignore any error.  */
f731ee
       grub_errno = GRUB_ERR_NONE;
f731ee
     }
f731ee
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
f731ee
index 8f01c1bbfa2..cec9539a47c 100644
f731ee
--- a/grub-core/script/execute.c
f731ee
+++ b/grub-core/script/execute.c
f731ee
@@ -27,6 +27,9 @@
f731ee
 #include <grub/normal.h>
f731ee
 #include <grub/extcmd.h>
f731ee
 #include <grub/i18n.h>
f731ee
+#ifdef GRUB_MACHINE_IEEE1275
f731ee
+#include <grub/ieee1275/ieee1275.h>
f731ee
+#endif
f731ee
 
f731ee
 /* Max digits for a char is 3 (0xFF is 255), similarly for an int it
f731ee
    is sizeof (int) * 3, and one extra for a possible -ve sign.  */
f731ee
@@ -892,6 +895,10 @@ grub_script_execute_sourcecode (const char *source)
f731ee
   grub_err_t ret = 0;
f731ee
   struct grub_script *parsed_script;
f731ee
 
f731ee
+#ifdef GRUB_MACHINE_IEEE1275
f731ee
+  grub_ieee1275_set_boot_last_label (source);
f731ee
+#endif
f731ee
+
f731ee
   while (source)
f731ee
     {
f731ee
       char *line;
f731ee
diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h
f731ee
index 8e425130327..9f26c69a2df 100644
f731ee
--- a/include/grub/ieee1275/ieee1275.h
f731ee
+++ b/include/grub/ieee1275/ieee1275.h
f731ee
@@ -234,6 +234,8 @@ int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *ali
f731ee
 void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);
f731ee
 void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,
f731ee
 						struct grub_ieee1275_devalias *alias);
f731ee
+int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char *script);
f731ee
+int EXPORT_FUNC(grub_ieee1275_set_boot_last_label) (const char *text);
f731ee
 
f731ee
 #define FOR_IEEE1275_DEVALIASES(alias) for (grub_ieee1275_devalias_init_iterator (&(alias)); grub_ieee1275_devalias_next (&(alias));)
f731ee