Skip to contentSkip to conversation

ieee1275/openfw: IBM client architecture(CAS) reboot support

PATCH avnish 2 participants 3 messages Nov 5, 2024 – Nov 12, 2024 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

avnish

author Reviewed-by Avnish Chouhan
#1 lore raw
Quoted 197 lines · On 2024-10-11 03:13, [email protected] wrote:

Message: 1
Date: Thu, 10 Oct 2024 15:43:19 -0600
From: Leo Sandoval <[email protected]>
To: [email protected]
Subject: [PATCH v3 01/16] ieee1275/openfw: IBM client architecture
(CAS) reboot support
Message-ID: <[email protected]>
Content-Type: text/plain; charset="US-ASCII"; x-default=true

From: Paulo Flabiano Smorigo <[email protected]>

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

---
 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(+)
grub-core/kern/ieee1275/openfw.c +2 -0
index 11b2beb2f..e2ecc65d2 100644
@@ -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.  

*/

grub-core/kern/ieee1275/openfw.c +16 -0
+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",

grub-core/kern/ieee1275/openfw.c +2 -0
+                                          &ibm_ca_support_reboot,
+                                          sizeof 

(ibm_ca_support_reboot),

grub-core/kern/ieee1275/openfw.c +2 -0
+                                          &actual) >= 0)
+    grub_dprintf("ieee1275", "ibm,client-architecture-support-reboot: 

%u\n",

grub-core/kern/ieee1275/openfw.c +5 -0
+                 ibm_ca_support_reboot);
+
+  ibm_fw_nbr_reboots = 0;
+  if (grub_ieee1275_get_property (options, "ibm,fw-nbr-reboots",
+                                  property_value, sizeof 

(property_value),

grub-core/kern/ieee1275/openfw.c +4 -0
+                                  &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);

grub-core/kern/ieee1275/openfw.c +5 -0
+    }
+
+  if (ibm_ca_support_reboot || ibm_fw_nbr_reboots)
+    {
+      if (! grub_ieee1275_get_property_length (options,

"boot-last-label", &actual))

grub-core/kern/ieee1275/openfw.c +4 -0
+        {
+          if (actual > 1024)
+            script = grub_realloc (script, actual + 1);
+          grub_ieee1275_get_property (options, "boot-last-label",

script, actual,

grub-core/kern/ieee1275/openfw.c +16 -0
+                                      &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));

grub-core/kern/ieee1275/openfw.c +6 -0
+  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;
+}
grub-core/normal/main.c +19 -0
index bd4431000..d3f53d93d 100644
@@ -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;
     }
grub-core/script/execute.c +7 -0
index 14ff09094..dab8fd2ae 100644
@@ -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;
include/grub/ieee1275/ieee1275.h +0 -0
index dddb38514..4f6e6aaa0 100644
@@ -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,

include/grub/ieee1275/ieee1275.h +2 -1
 						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);
 
--
Quoted 2 lines

2.46.2

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

author Reviewed-by Avnish Chouhan
#2 lore raw

Re: [PATCH v3 03/16] ieee1275: Disable GRUB video support for IBM power machines

In reply to a message not in the archive
Quoted 87 lines

Message: 3
Date: Thu, 10 Oct 2024 15:43:21 -0600
From: Leo Sandoval <[email protected]>
To: [email protected]
Subject: [PATCH v3 03/16] ieee1275: Disable GRUB video support for IBM
power machines
Message-ID: <[email protected]>
Content-Type: text/plain; charset="US-ASCII"; x-default=true

From: Paulo Flabiano Smorigo <[email protected]>

GRUB gets the display card node address from OpenFirmware, however this address is truncated to 32-bits (OpenFirmware works on 32-bits, so GRUB) effectively getting an invalid address. This change disables the video support on IBM power machines. More details can be found at [1].

[1] https://bugzilla.redhat.com/show_bug.cgi?id=973205

---
 grub-core/kern/ieee1275/cmain.c  | 5 ++++-
 grub-core/video/ieee1275.c       | 9 ++++++---
 include/grub/ieee1275/ieee1275.h | 2 ++
 3 files changed, 12 insertions(+), 4 deletions(-)
grub-core/kern/ieee1275/cmain.c +4 -1
index e74de3248..810a089a9 100644
@@ -89,7 +89,10 @@ grub_ieee1275_find_options (void)
   }
 
   if (rc >= 0 && grub_strncmp (tmp, "IBM", 3) == 0)
-    grub_ieee1275_set_flag 
 (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS);
+    {
+      grub_ieee1275_set_flag 
 (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS);
+      grub_ieee1275_set_flag 
 (GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT);
+    }

/* Old Macs have no key repeat, newer ones have fully working one.
The ones inbetween when repeated key generates an escaoe sequence

grub-core/video/ieee1275.c +0 -0
index ca3d3c3b2..5592e4bb7 100644
@@ -351,9 +351,12 @@ static struct grub_video_adapter

grub_video_ieee1275_adapter =

GRUB_MOD_INIT(ieee1275_fb)
{

grub-core/video/ieee1275.c +1 -3
-  find_display ();
-  if (display)
-    grub_video_register (&grub_video_ieee1275_adapter);
+  if (! grub_ieee1275_test_flag 

(GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT))

grub-core/video/ieee1275.c +5 -0
+    {
+      find_display ();
+      if (display)
+        grub_video_register (&grub_video_ieee1275_adapter);
+    }
 }
 
 GRUB_MOD_FINI(ieee1275_fb)
include/grub/ieee1275/ieee1275.h +2 -0
index 4f6e6aaa0..db0ec5f4c 100644
@@ -145,6 +145,8 @@ enum grub_ieee1275_flag
   GRUB_IEEE1275_FLAG_POWER_VM,
 
   GRUB_IEEE1275_FLAG_POWER_KVM,
+
+  GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT
 };
 
 extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum 

grub_ieee1275_flag flag);
--
2.46.2

Quoted 1 line

------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reviewed-by
#3 lore raw

Re: [PATCH v3 02/16] term/terminfo: for ppc, reset console display attr when clear screen

In reply to a message not in the archive
Quoted 47 lines

Message: 4
Date: Thu, 10 Oct 2024 15:43:20 -0600
From: Leo Sandoval <[email protected]>
To: [email protected]
Subject: [PATCH v3 02/16] term/terminfo: for ppc, reset console
display attr when clear screen
Message-ID: <[email protected]>
Content-Type: text/plain; charset="US-ASCII"; x-default=true

From: Paulo Flabiano Smorigo <[email protected]>

v2: Also use \x0c instead of a literal ^L to make future patches less awkward.

This should fix this bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=908519

---
 grub-core/term/terminfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/term/terminfo.c +0 -0
index 4e534c683..3dbe88e89 100644
@@ -151,7 +151,7 @@ grub_terminfo_set_current (struct grub_term_output 
 *term,
       /* Clear the screen.  Using serial console, screen(1) only 

recognizes the
* ANSI escape sequence. Using video console, Apple Open
Firmware
* (version 3.1.1) only recognizes the literal ^L. So use both.
*/

grub-core/term/terminfo.c +1 -2
-      data->cls               = grub_strdup ("\e[2J");
+      data->cls               = grub_strdup ("\x0c\e[2J\e[m");
       data->reverse_video_on  = grub_strdup ("\e[7m");
       data->reverse_video_off = grub_strdup ("\e[m");
       if (grub_strcmp ("ieee1275", str) == 0)
--

2.46.2

Quoted 1 line

------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel