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

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