nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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