dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0059-add-bootpath-parser-for-open-firmware.patch

0dc71c
From 1a768cc5a65094e19c216caf92dd190317df25fc Mon Sep 17 00:00:00 2001
0dc71c
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
0dc71c
Date: Tue, 4 Feb 2014 19:00:55 -0200
0dc71c
Subject: [PATCH 059/143] add bootpath parser for open firmware
0dc71c
0dc71c
It enables net boot even when there is no bootp/dhcp server.
0dc71c
0dc71c
* grub-core/net/drivers/ieee1275/ofnet.c: Add grub_ieee1275_parse_bootpath and
0dc71c
call it at grub_ieee1275_net_config_real.
0dc71c
* grub-core/kern/ieee1275/init.c: Add bootpath to grub_ieee1275_net_config.
0dc71c
* include/grub/ieee1275/ieee1275.h: Likewise.
0dc71c
---
0dc71c
 ChangeLog                              |  13 ++++
0dc71c
 grub-core/kern/ieee1275/init.c         |   7 +--
0dc71c
 grub-core/net/drivers/ieee1275/ofnet.c | 107 ++++++++++++++++++++++++++++++++-
0dc71c
 include/grub/ieee1275/ieee1275.h       |   5 +-
0dc71c
 4 files changed, 125 insertions(+), 7 deletions(-)
0dc71c
0dc71c
diff --git a/ChangeLog b/ChangeLog
0dc71c
index 63f5aa3..5237631 100644
0dc71c
--- a/ChangeLog
0dc71c
+++ b/ChangeLog
0dc71c
@@ -1,5 +1,18 @@
0dc71c
 2014-02-04  Paulo Flabiano Smorigo  <pfsmorigo@br.ibm.com>
0dc71c
 
0dc71c
+	Add bootpath parser for open firmware.
0dc71c
+
0dc71c
+	It enables net boot even when there is no bootp/dhcp server.
0dc71c
+
0dc71c
+	* grub-core/net/drivers/ieee1275/ofnet.c: Add grub_ieee1275_parse_bootpath
0dc71c
+	and call it at grub_ieee1275_net_config_real.
0dc71c
+	* grub-core/kern/ieee1275/init.c: Add bootpath to
0dc71c
+	grub_ieee1275_net_config.
0dc71c
+	* include/grub/ieee1275/ieee1275.h: Likewise.
0dc71c
+
0dc71c
+
0dc71c
+2014-02-04  Paulo Flabiano Smorigo  <pfsmorigo@br.ibm.com>
0dc71c
+
0dc71c
 	Add grub_env_set_net_property function.
0dc71c
 
0dc71c
 	* grub-core/net/bootp.c: Remove set_env_limn_ro.
0dc71c
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
0dc71c
index 89b2822..d5bd74d 100644
0dc71c
--- a/grub-core/kern/ieee1275/init.c
0dc71c
+++ b/grub-core/kern/ieee1275/init.c
0dc71c
@@ -80,9 +80,8 @@ grub_translate_ieee1275_path (char *filepath)
0dc71c
     }
0dc71c
 }
0dc71c
 
0dc71c
-void (*grub_ieee1275_net_config) (const char *dev,
0dc71c
-				  char **device,
0dc71c
-				  char **path);
0dc71c
+void (*grub_ieee1275_net_config) (const char *dev, char **device, char **path,
0dc71c
+                                  char *bootpath);
0dc71c
 void
0dc71c
 grub_machine_get_bootlocation (char **device, char **path)
0dc71c
 {
0dc71c
@@ -126,7 +125,7 @@ grub_machine_get_bootlocation (char **device, char **path)
0dc71c
       *ptr = 0;
0dc71c
 
0dc71c
       if (grub_ieee1275_net_config)
0dc71c
-	grub_ieee1275_net_config (canon, device, path);
0dc71c
+	grub_ieee1275_net_config (canon, device, path, bootpath);
0dc71c
       grub_free (dev);
0dc71c
       grub_free (canon);
0dc71c
     }
0dc71c
diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c
0dc71c
index 4483c91..eea8e71 100644
0dc71c
--- a/grub-core/net/drivers/ieee1275/ofnet.c
0dc71c
+++ b/grub-core/net/drivers/ieee1275/ofnet.c
0dc71c
@@ -127,8 +127,111 @@ bootp_response_properties[] =
0dc71c
     { .name = "bootpreply-packet", .offset = 0x2a},
0dc71c
   };
0dc71c
 
0dc71c
+enum
0dc71c
+{
0dc71c
+  BOOTARGS_SERVER_ADDR,
0dc71c
+  BOOTARGS_FILENAME,
0dc71c
+  BOOTARGS_CLIENT_ADDR,
0dc71c
+  BOOTARGS_GATEWAY_ADDR,
0dc71c
+  BOOTARGS_BOOTP_RETRIES,
0dc71c
+  BOOTARGS_TFTP_RETRIES,
0dc71c
+  BOOTARGS_SUBNET_MASK,
0dc71c
+  BOOTARGS_BLOCKSIZE
0dc71c
+};
0dc71c
+
0dc71c
+static int
0dc71c
+grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath,
0dc71c
+                              char **device, struct grub_net_card **card)
0dc71c
+{
0dc71c
+  char *args;
0dc71c
+  char *comma_char = 0;
0dc71c
+  char *equal_char = 0;
0dc71c
+  grub_size_t field_counter = 0;
0dc71c
+
0dc71c
+  grub_net_network_level_address_t client_addr, gateway_addr, subnet_mask;
0dc71c
+  grub_net_link_level_address_t hw_addr;
0dc71c
+  grub_net_interface_flags_t flags = 0;
0dc71c
+  struct grub_net_network_level_interface *inter;
0dc71c
+
0dc71c
+  hw_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
0dc71c
+
0dc71c
+  args = bootpath + grub_strlen (devpath) + 1;
0dc71c
+  do
0dc71c
+    {
0dc71c
+      comma_char = grub_strchr (args, ',');
0dc71c
+      if (comma_char != 0)
0dc71c
+        *comma_char = 0;
0dc71c
+
0dc71c
+      /* Check if it's an option (like speed=auto) and not a default parameter */
0dc71c
+      equal_char = grub_strchr (args, '=');
0dc71c
+      if (equal_char != 0)
0dc71c
+        {
0dc71c
+          *equal_char = 0;
0dc71c
+          grub_env_set_net_property ((*card)->name, args, equal_char + 1,
0dc71c
+                                     grub_strlen(equal_char + 1));
0dc71c
+          *equal_char = '=';
0dc71c
+        }
0dc71c
+      else
0dc71c
+        {
0dc71c
+          switch (field_counter++)
0dc71c
+            {
0dc71c
+            case BOOTARGS_SERVER_ADDR:
0dc71c
+              *device = grub_xasprintf ("tftp,%s", args);
0dc71c
+              if (!*device)
0dc71c
+                return grub_errno;
0dc71c
+              break;
0dc71c
+
0dc71c
+            case BOOTARGS_CLIENT_ADDR:
0dc71c
+              grub_net_resolve_address (args, &client_addr);
0dc71c
+              break;
0dc71c
+
0dc71c
+            case BOOTARGS_GATEWAY_ADDR:
0dc71c
+              grub_net_resolve_address (args, &gateway_addr);
0dc71c
+              break;
0dc71c
+
0dc71c
+            case BOOTARGS_SUBNET_MASK:
0dc71c
+              grub_net_resolve_address (args, &subnet_mask);
0dc71c
+              break;
0dc71c
+            }
0dc71c
+        }
0dc71c
+      args = comma_char + 1;
0dc71c
+      if (comma_char != 0)
0dc71c
+        *comma_char = ',';
0dc71c
+    } while (comma_char != 0);
0dc71c
+
0dc71c
+  if ((client_addr.ipv4 != 0) && (subnet_mask.ipv4 != 0))
0dc71c
+    {
0dc71c
+      grub_ieee1275_phandle_t devhandle;
0dc71c
+      grub_ieee1275_finddevice (devpath, &devhandle);
0dc71c
+      grub_ieee1275_get_property (devhandle, "mac-address",
0dc71c
+                                  hw_addr.mac, sizeof(hw_addr.mac), 0);
0dc71c
+      inter = grub_net_add_addr ((*card)->name, *card, &client_addr, &hw_addr,
0dc71c
+                                 flags);
0dc71c
+      grub_net_add_ipv4_local (inter,
0dc71c
+                          __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4)));
0dc71c
+    }
0dc71c
+
0dc71c
+  if (gateway_addr.ipv4 != 0)
0dc71c
+    {
0dc71c
+      grub_net_network_level_netaddress_t target;
0dc71c
+      char *rname;
0dc71c
+
0dc71c
+      target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
0dc71c
+      target.ipv4.base = 0;
0dc71c
+      target.ipv4.masksize = 0;
0dc71c
+      rname = grub_xasprintf ("%s:default", ((*card)->name));
0dc71c
+      if (rname)
0dc71c
+        grub_net_add_route_gw (rname, target, gateway_addr);
0dc71c
+      else
0dc71c
+        return grub_errno;
0dc71c
+    }
0dc71c
+
0dc71c
+  return 0;
0dc71c
+}
0dc71c
+
0dc71c
 static void
0dc71c
-grub_ieee1275_net_config_real (const char *devpath, char **device, char **path)
0dc71c
+grub_ieee1275_net_config_real (const char *devpath, char **device, char **path,
0dc71c
+                               char *bootpath)
0dc71c
 {
0dc71c
   struct grub_net_card *card;
0dc71c
 
0dc71c
@@ -158,6 +261,8 @@ grub_ieee1275_net_config_real (const char *devpath, char **device, char **path)
0dc71c
       }
0dc71c
     grub_free (canon);
0dc71c
 
0dc71c
+    grub_ieee1275_parse_bootpath (devpath, bootpath, device, &card;;
0dc71c
+
0dc71c
     for (i = 0; i < ARRAY_SIZE (bootp_response_properties); i++)
0dc71c
       if (grub_ieee1275_get_property_length (grub_ieee1275_chosen,
0dc71c
 					     bootp_response_properties[i].name,
0dc71c
diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h
0dc71c
index dc54bea..8e42513 100644
0dc71c
--- a/include/grub/ieee1275/ieee1275.h
0dc71c
+++ b/include/grub/ieee1275/ieee1275.h
0dc71c
@@ -70,8 +70,9 @@ struct grub_ieee1275_devalias
0dc71c
 };
0dc71c
 
0dc71c
 extern void (*EXPORT_VAR(grub_ieee1275_net_config)) (const char *dev,
0dc71c
-						     char **device,
0dc71c
-						     char **path);
0dc71c
+                                                     char **device,
0dc71c
+                                                     char **path,
0dc71c
+                                                     char *bootargs);
0dc71c
 
0dc71c
 /* Maps a device alias to a pathname.  */
0dc71c
 extern grub_ieee1275_phandle_t EXPORT_VAR(grub_ieee1275_chosen);
0dc71c
-- 
0dc71c
1.9.3
0dc71c