All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leo Sandoval <lsandova@redhat.com>
To: grub-devel@gnu.org
Subject: [PATCH v3 01/16] ieee1275/openfw: IBM client architecture (CAS) reboot support
Date: Thu, 10 Oct 2024 15:43:19 -0600	[thread overview]
Message-ID: <20241010214334.1749167-2-lsandova@redhat.com> (raw)
In-Reply-To: <20241010214334.1749167-1-lsandova@redhat.com>

From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>

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
ibm,client-architecture-support and it may either return or reboot with
the new feature set. eg:

Calling ibm,client-architecture-support.../
Elapsed time since release of system processors: 70959 mins 50 secs
Welcome to GRUB!

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>
---
 grub-core/kern/ieee1275/openfw.c | 63 ++++++++++++++++++++++++++++++++
 grub-core/normal/main.c          | 19 ++++++++++
 grub-core/script/execute.c       |  7 ++++
 include/grub/ieee1275/ieee1275.h |  2 +
 4 files changed, 91 insertions(+)

diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c
index 11b2beb2f..e2ecc65d2 100644
--- a/grub-core/kern/ieee1275/openfw.c
+++ b/grub-core/kern/ieee1275/openfw.c
@@ -591,3 +591,66 @@ grub_ieee1275_get_boot_dev (void)
 
   return bootpath;
 }
+
+/* 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
index bd4431000..d3f53d93d 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -34,6 +34,9 @@
 #include <grub/charset.h>
 #include <grub/script_sh.h>
 #include <grub/bufio.h>
+#ifdef GRUB_MACHINE_IEEE1275
+#include <grub/ieee1275/ieee1275.h>
+#endif
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -276,6 +279,22 @@ grub_normal_execute (const char *config, int nested, int batch)
     {
       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 };
+          if (! grub_script_execute_sourcecode (script))
+            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
index 14ff09094..dab8fd2ae 100644
--- a/grub-core/script/execute.c
+++ b/grub-core/script/execute.c
@@ -28,6 +28,9 @@
 #include <grub/extcmd.h>
 #include <grub/i18n.h>
 #include <grub/verify.h>
+#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.  */
@@ -883,6 +886,10 @@ grub_script_execute_sourcecode (const char *source)
   grub_err_t ret = 0;
   struct grub_script *parsed_script;
 
+#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
index dddb38514..4f6e6aaa0 100644
--- a/include/grub/ieee1275/ieee1275.h
+++ b/include/grub/ieee1275/ieee1275.h
@@ -251,6 +251,8 @@ int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *ali
 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);
+int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char *script);
+int EXPORT_FUNC(grub_ieee1275_set_boot_last_label) (const char *text);
 
 char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void);
 
-- 
2.46.2


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  reply	other threads:[~2024-10-10 21:46 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
2024-10-10 21:43 ` Leo Sandoval [this message]
2024-10-10 21:43 ` [PATCH v3 02/16] term/terminfo: for ppc, reset console display attr when clear screen Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 03/16] ieee1275: Disable GRUB video support for IBM power machines Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 04/16] configure.ac: Move bash completion script Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 05/16] misc: Make "exit" take a return code Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 06/16] efi/init: Make efi machines load an env block from a variable Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 07/16] 20_ppc_terminfo.in: Migrate ieee1275/PPC from Yaboot to Grub2 Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 08/16] normal: Add fw_path variable (revised) Leo Sandoval
2024-10-15  5:23   ` Michael Chang via Grub-devel
2024-10-15  9:01     ` Vladimir 'phcoder' Serbinenko
2024-10-10 21:43 ` [PATCH v3 09/16] commands: Pass "\x[[:hex:]][[:hex:]]" straight through unmolested Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 10/16] 10_linux.in: Add devicetree loading Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 11/16] Makefile.common: Add .eh_frame to list of relocations stripped Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 12/16] 10_linux.in: Don't require a password to boot entries generated by grub-mkconfig Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 13/16] normal/main: fw_path prefix when fallback searching for grub config Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 14/16] normal/main: Try mac/guid/etc before grub.cfg on tftp config files Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 15/16] 10_linux.in: Generate OS and CLASS in 10_linux from /etc/os-release Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 16/16] normal/main: Try $prefix if $fw_path doesn't work Leo Sandoval
2024-10-30 16:39 ` [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Daniel Kiper
2024-10-30 17:03   ` Leo Sandoval
     [not found] <mailman.5684.1728596634.1206.grub-devel@gnu.org>
2024-11-05 12:01 ` [PATCH v3 01/16] ieee1275/openfw: IBM client architecture(CAS) reboot support avnish

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=20241010214334.1749167-2-lsandova@redhat.com \
    --to=lsandova@redhat.com \
    --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.