All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hollis Blanchard <hollis@penguinppc.org>
To: grub-devel@gnu.org
Subject: [ppc] [patch] set environment from commandline
Date: Mon, 9 May 2005 00:05:26 -0500	[thread overview]
Message-ID: <20050509050526.GA18510@miracle> (raw)

We're doing a lot of useless work in cmain().

Also, this patch allows you to boot from the OF commandline, overriding
the defaults. Example:
    boot enet:,grubof prefix=foo; debug=bar

Comments?

-Hollis

Index: boot/powerpc/ieee1275/cmain.c
===================================================================
RCS file: /cvsroot/grub/grub2/boot/powerpc/ieee1275/cmain.c,v
retrieving revision 1.7
diff -u -p -r1.7 cmain.c
--- boot/powerpc/ieee1275/cmain.c	1 May 2005 03:45:35 -0000	1.7
+++ boot/powerpc/ieee1275/cmain.c	9 May 2005 05:01:07 -0000
@@ -71,15 +71,9 @@ grub_ieee1275_find_options (void)
 }
 
 void cmain (uint32_t r3, uint32_t r4, uint32_t r5);
-/* Setup the argument vector and pass control over to the main
-   function.  */
 void
 cmain (uint32_t r3, uint32_t r4 __attribute__((unused)), uint32_t r5)
 {
-  char **argv, args[256];
-  grub_ieee1275_phandle_t chosen;
-  int argc = 0, actual;
-
   if (r5 == 0xdeadbeef)
     {
       /* Entered from Old World stage1.  */
@@ -106,70 +100,7 @@ cmain (uint32_t r3, uint32_t r4 __attrib
 
   grub_ieee1275_find_options ();
 
-  /* If any argument was passed to the kernel (us), they are
-     put in the bootargs property of /chosen.  The string can
-     be null (just the nul-character), so check that the size
-     is actually greater than one.  */
-
-  grub_ieee1275_finddevice ("/chosen", &chosen);
-  if (grub_ieee1275_get_property (chosen, "bootargs", args,
-				  sizeof args, &actual) == 0
-      && actual > 1)
-    {
-      /* A command line was passed.  */
-      char *str = args;
-      int nr = 1;
-
-      /* First time around we count the number of arguments.  */
-      argc = 2;
-      while (*str && *str == ' ')
-	str++;
-
-      while (*str)
-	if (*(str++) == ' ')
-	  {
-	    while (*str && *str == ' ')
-	      str++;
-	    if (*str)
-	      argc++;
-	  }
-      argv = alloca (sizeof (char *) * (argc + 2));
-
-      /* The bootargs property does not contain the program
-	 name, just the arguments.  */
-      argv[0] = "grub";
-
-      /* Second time around we fill in the argv.  */
-      str = args;
-
-      while (*str && *str == ' ')
-	str++;
-      argv[nr++] = str;
-
-      while (*str)
-	{
-	  if (*str == ' ')
-	    {
-	      *(str++) = '\0';
-	      while (*str && *str == ' ')
-		str++;
-	      if (*str)
-		argv[nr++] = str;
-	    }
-	  else
-	    str++;
-	}
-      argv[nr] = 0;
-    }
-  else
-    {
-      argv = alloca (sizeof (char *) * 2);
-      argv[0] = "grub";
-      argv[1] = 0;
-      argc = 1;
-    }
   /* Now invoke the main function.  */
-  /* XXX: grub_main does not parse arguments yet.  */
   grub_main ();
 
   /* Never reached.  */
Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/init.c,v
retrieving revision 1.17
diff -u -p -r1.17 init.c
--- kern/powerpc/ieee1275/init.c	1 May 2005 03:45:36 -0000	1.17
+++ kern/powerpc/ieee1275/init.c	9 May 2005 05:01:13 -0000
@@ -113,6 +113,9 @@ grub_set_prefix (void)
 void
 grub_machine_init (void)
 {
+  char args[256];
+  grub_ieee1275_phandle_t chosen;
+  int actual;
   extern char _start;
 
   grub_console_init ();
@@ -132,6 +135,41 @@ grub_machine_init (void)
   grub_set_prefix ();
 
   grub_ofdisk_init ();
+
+  /* Process commandline. */
+  grub_ieee1275_finddevice ("/chosen", &chosen);
+  if (grub_ieee1275_get_property (chosen, "bootargs", &args,
+				  sizeof args, &actual) == 0
+      && actual > 1)
+    {
+      int i = 0;
+
+      while (i < actual)
+	{
+	  char *command = &args[i];
+	  char *end;
+	  char *val;
+
+	  end = grub_strchr (command, ';');
+	  if (end == 0)
+	    i = actual; /* No more commands after this one.  */
+	  else
+	    {
+	      *end = '\0';
+	      i += end - command + 1;
+	      while (grub_isspace(args[i]))
+		i++;
+	    }
+
+	  /* Process command.  */
+	  val = grub_strchr (command, '=');
+	  if (val)
+	    {
+	      *val = '\0';
+	      grub_env_set (command, val + 1);
+	    }
+	}
+    }
 }
 
 void



             reply	other threads:[~2005-05-09  5:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-09  5:05 Hollis Blanchard [this message]
2005-05-10 18:05 ` non boot-device was Re: [ppc] [patch] set environment from commandline Paul Nasrat
2005-05-10 18:16   ` Marco Gerards
2005-05-10 18:56     ` Paul Nasrat
2005-05-10 19:59     ` Paul Nasrat
2005-05-10 23:04       ` Hollis Blanchard
2005-05-10 23:10       ` console colors Hollis Blanchard
2005-05-11  6:26         ` Marco Gerards
2005-05-10 18:11 ` [ppc] [patch] set environment from commandline Marco Gerards
2005-05-10 23:47   ` Hollis Blanchard
2005-05-11  6:36     ` Marco Gerards
2005-05-13 12:43 ` Olaf Hering
2005-05-13 14:20   ` Marco Gerards
2005-05-13 14:25   ` Hollis Blanchard
2005-05-18 19:54     ` Olaf Hering
2005-05-23 16:33       ` Marco Gerards
2005-05-25 16:58         ` Olaf Hering
2005-05-26  6:51           ` Marco Gerards

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050509050526.GA18510@miracle \
    --to=hollis@penguinppc.org \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.