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

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