nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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