2018-07-12 14:56:34 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2012-10-18 17:47:39 +00:00
|
|
|
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
|
|
|
|
Date: Thu, 20 Sep 2012 18:07:39 -0300
|
2018-07-10 18:39:10 +00:00
|
|
|
Subject: [PATCH] IBM client architecture (CAS) reboot support
|
2012-10-18 17:47:39 +00:00
|
|
|
|
|
|
|
This is an implementation of IBM client architecture (CAS) reboot for GRUB.
|
|
|
|
|
|
|
|
There are cases where the POWER firmware must reboot in order to support
|
|
|
|
specific features requested by a kernel. The kernel calls
|
2022-01-17 23:06:55 +00:00
|
|
|
ibm,client-architecture-support and it may either return or reboot with
|
|
|
|
the new feature set. eg:
|
2012-10-18 17:47:39 +00:00
|
|
|
|
|
|
|
Calling ibm,client-architecture-support.../
|
|
|
|
Elapsed time since release of system processors: 70959 mins 50 secs
|
|
|
|
Welcome to GRUB!
|
|
|
|
|
2022-01-17 23:06:55 +00:00
|
|
|
Instead of return to the GRUB menu, it will check if the flag for CAS
|
|
|
|
reboot is set. If so, grub will automatically boot the last booted
|
|
|
|
kernel using the same parameters
|
|
|
|
|
|
|
|
Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
|
|
|
|
[rharwood@redhat.com: commit message rewrap]
|
|
|
|
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
|
2012-10-18 17:47:39 +00:00
|
|
|
---
|
2018-07-10 19:08:14 +00:00
|
|
|
grub-core/kern/ieee1275/openfw.c | 63 ++++++++++++++++++++++++++++++++++++++++
|
2013-05-02 20:54:52 +00:00
|
|
|
grub-core/normal/main.c | 19 ++++++++++++
|
|
|
|
grub-core/script/execute.c | 7 +++++
|
|
|
|
include/grub/ieee1275/ieee1275.h | 2 ++
|
2018-07-10 19:08:14 +00:00
|
|
|
4 files changed, 91 insertions(+)
|
2012-10-18 17:47:39 +00:00
|
|
|
|
|
|
|
diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index 11b2beb2ff2..e2ecc65d2d8 100644
|
2012-10-18 17:47:39 +00:00
|
|
|
--- a/grub-core/kern/ieee1275/openfw.c
|
|
|
|
+++ b/grub-core/kern/ieee1275/openfw.c
|
2019-08-15 06:01:31 +00:00
|
|
|
@@ -591,3 +591,66 @@ grub_ieee1275_get_boot_dev (void)
|
2012-10-18 17:47:39 +00:00
|
|
|
|
2018-07-10 19:08:14 +00:00
|
|
|
return bootpath;
|
|
|
|
}
|
|
|
|
+
|
2012-10-18 17:47:39 +00:00
|
|
|
+/* Check if it's a CAS reboot. If so, set the script to be executed. */
|
|
|
|
+int
|
|
|
|
+grub_ieee1275_cas_reboot (char *script)
|
|
|
|
+{
|
|
|
|
+ grub_uint32_t ibm_ca_support_reboot;
|
|
|
|
+ grub_uint32_t ibm_fw_nbr_reboots;
|
|
|
|
+ char property_value[10];
|
|
|
|
+ grub_ssize_t actual;
|
|
|
|
+ grub_ieee1275_ihandle_t options;
|
|
|
|
+
|
|
|
|
+ if (grub_ieee1275_finddevice ("/options", &options) < 0)
|
|
|
|
+ return -1;
|
|
|
|
+
|
|
|
|
+ /* Check two properties, one is enough to get cas reboot value */
|
|
|
|
+ ibm_ca_support_reboot = 0;
|
|
|
|
+ if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen,
|
|
|
|
+ "ibm,client-architecture-support-reboot",
|
|
|
|
+ &ibm_ca_support_reboot,
|
|
|
|
+ sizeof (ibm_ca_support_reboot),
|
|
|
|
+ &actual) >= 0)
|
|
|
|
+ grub_dprintf("ieee1275", "ibm,client-architecture-support-reboot: %u\n",
|
|
|
|
+ ibm_ca_support_reboot);
|
|
|
|
+
|
|
|
|
+ ibm_fw_nbr_reboots = 0;
|
|
|
|
+ if (grub_ieee1275_get_property (options, "ibm,fw-nbr-reboots",
|
|
|
|
+ property_value, sizeof (property_value),
|
|
|
|
+ &actual) >= 0)
|
|
|
|
+ {
|
|
|
|
+ property_value[sizeof (property_value) - 1] = 0;
|
|
|
|
+ ibm_fw_nbr_reboots = (grub_uint8_t) grub_strtoul (property_value, 0, 10);
|
|
|
|
+ grub_dprintf("ieee1275", "ibm,fw-nbr-reboots: %u\n", ibm_fw_nbr_reboots);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ibm_ca_support_reboot || ibm_fw_nbr_reboots)
|
|
|
|
+ {
|
|
|
|
+ if (! grub_ieee1275_get_property_length (options, "boot-last-label", &actual))
|
|
|
|
+ {
|
|
|
|
+ if (actual > 1024)
|
|
|
|
+ script = grub_realloc (script, actual + 1);
|
|
|
|
+ grub_ieee1275_get_property (options, "boot-last-label", script, actual,
|
|
|
|
+ &actual);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ grub_ieee1275_set_boot_last_label ("");
|
|
|
|
+
|
|
|
|
+ return -1;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int grub_ieee1275_set_boot_last_label (const char *text)
|
|
|
|
+{
|
|
|
|
+ grub_ieee1275_ihandle_t options;
|
|
|
|
+ grub_ssize_t actual;
|
|
|
|
+
|
|
|
|
+ grub_dprintf("ieee1275", "set boot_last_label (size: %u)\n", grub_strlen(text));
|
|
|
|
+ if (! grub_ieee1275_finddevice ("/options", &options) &&
|
|
|
|
+ options != (grub_ieee1275_ihandle_t) -1)
|
|
|
|
+ grub_ieee1275_set_property (options, "boot-last-label", text,
|
|
|
|
+ grub_strlen (text), &actual);
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index bd44310005d..d3f53d93d87 100644
|
2012-10-18 17:47:39 +00:00
|
|
|
--- a/grub-core/normal/main.c
|
|
|
|
+++ b/grub-core/normal/main.c
|
2021-03-12 21:54:28 +00:00
|
|
|
@@ -34,6 +34,9 @@
|
2012-10-18 17:47:39 +00:00
|
|
|
#include <grub/charset.h>
|
|
|
|
#include <grub/script_sh.h>
|
2014-03-13 18:02:22 +00:00
|
|
|
#include <grub/bufio.h>
|
2012-10-18 17:47:39 +00:00
|
|
|
+#ifdef GRUB_MACHINE_IEEE1275
|
|
|
|
+#include <grub/ieee1275/ieee1275.h>
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
|
|
2021-03-12 21:54:28 +00:00
|
|
|
@@ -276,6 +279,22 @@ grub_normal_execute (const char *config, int nested, int batch)
|
2012-10-18 17:47:39 +00:00
|
|
|
{
|
|
|
|
menu = read_config_file (config);
|
|
|
|
|
|
|
|
+#ifdef GRUB_MACHINE_IEEE1275
|
|
|
|
+ int boot;
|
|
|
|
+ boot = 0;
|
|
|
|
+ char *script;
|
|
|
|
+ script = grub_malloc (1024);
|
|
|
|
+ if (! grub_ieee1275_cas_reboot (script))
|
|
|
|
+ {
|
|
|
|
+ char *dummy[1] = { NULL };
|
2016-03-04 18:32:29 +00:00
|
|
|
+ if (! grub_script_execute_sourcecode (script))
|
2012-10-18 17:47:39 +00:00
|
|
|
+ boot = 1;
|
|
|
|
+ }
|
|
|
|
+ grub_free (script);
|
|
|
|
+ if (boot)
|
|
|
|
+ grub_command_execute ("boot", 0, 0);
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/* Ignore any error. */
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index 14ff09094f0..dab8fd2aeb0 100644
|
2012-10-18 17:47:39 +00:00
|
|
|
--- a/grub-core/script/execute.c
|
|
|
|
+++ b/grub-core/script/execute.c
|
2019-08-15 06:01:31 +00:00
|
|
|
@@ -28,6 +28,9 @@
|
2012-10-18 17:47:39 +00:00
|
|
|
#include <grub/extcmd.h>
|
|
|
|
#include <grub/i18n.h>
|
2019-08-15 06:01:31 +00:00
|
|
|
#include <grub/verify.h>
|
2012-10-18 17:47:39 +00:00
|
|
|
+#ifdef GRUB_MACHINE_IEEE1275
|
|
|
|
+#include <grub/ieee1275/ieee1275.h>
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
/* Max digits for a char is 3 (0xFF is 255), similarly for an int it
|
|
|
|
is sizeof (int) * 3, and one extra for a possible -ve sign. */
|
2021-03-12 21:54:28 +00:00
|
|
|
@@ -883,6 +886,10 @@ grub_script_execute_sourcecode (const char *source)
|
2014-01-06 16:39:16 +00:00
|
|
|
grub_err_t ret = 0;
|
|
|
|
struct grub_script *parsed_script;
|
2012-10-18 17:47:39 +00:00
|
|
|
|
|
|
|
+#ifdef GRUB_MACHINE_IEEE1275
|
|
|
|
+ grub_ieee1275_set_boot_last_label (source);
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
while (source)
|
|
|
|
{
|
|
|
|
char *line;
|
|
|
|
diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h
|
2024-10-18 18:18:00 +00:00
|
|
|
index dddb385149e..4f6e6aaa098 100644
|
2012-10-18 17:47:39 +00:00
|
|
|
--- a/include/grub/ieee1275/ieee1275.h
|
|
|
|
+++ b/include/grub/ieee1275/ieee1275.h
|
2024-10-18 18:18:00 +00:00
|
|
|
@@ -251,6 +251,8 @@ int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *ali
|
2013-05-02 20:54:52 +00:00
|
|
|
void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);
|
|
|
|
void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,
|
|
|
|
struct grub_ieee1275_devalias *alias);
|
2012-10-18 17:47:39 +00:00
|
|
|
+int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char *script);
|
|
|
|
+int EXPORT_FUNC(grub_ieee1275_set_boot_last_label) (const char *text);
|
|
|
|
|
2018-07-10 19:08:14 +00:00
|
|
|
char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void);
|
2016-04-05 19:28:47 +00:00
|
|
|
|