Skip to contentSkip to conversation

set environment from commandline

PATCH In review Hollis Blanchard 4 participants 18 messages May 9, 2005 – May 26, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 set environment from commandline

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

powerpc/ieee1275/cmain.c +0 -69
diff -u -p -r1.7 cmain.c
@@ -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

powerpc/ieee1275/init.c +38 -0
diff -u -p -r1.17 init.c
@@ -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
#1 lore raw

non boot-device was Re: [ppc] [patch] set environment from commandline

Quoted 5 lines · Hollis Blanchard

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

I thought this might work if I'm using grub with a different boot-device set. Built with cvs and this patch. Setting boot-device and then running boot works

Brought to you by " enet:telnet,10.13.0.202" io

I love OF packages :)

Connected to blueimac.install.boston.redhat.com (10.13.0.202). Escape character is '^]'.
ok
0 > printenv boot-device
-------------- Partition: common -------- Signature: 0x70
---------------
boot-device /pci@f2000000/mac-io@17/ata-4@1f000/disk@0:2,\
\:tbxi hd:,\\:tbxi
ok
0 > dir hd:2,\
bootstrap

    115  4/23/57  8:10:55  grub.cfg
 188960  5/11/ 5  4:52: 4  grubof.modules
   3191  5/11/ 5  2:23:43  ofboot.b
 141492  5/11/ 5  2:23:43  yaboot
    638  5/11/ 5  2:23:43  yaboot.conf ok

0 > boot hd:2,\grubof.modules load-size=2e220 adler32=e04b6e6d

Loading ELF
method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300
Welcome to GRUB!

DEFAULT CATCH!, code=300 at %SRR0: 001f9dac %SRR1: 00003030
ok
0 > .registers
Client's Fix Pt Regs:
00 7c7d1b78 0032af30 00000000 fffffff2 001f2340 ffffffff 001f21f0
2d3c2808
08 00000002 7c7d1b78 001fefc0 001f21f5 00000000 00000000 00000000
00000000
10 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000
18 00000000 001f2358 001f2348 00000003 001f2790 001f2340 001f396c
001f2210
Special Regs:

    %IV: 00000300   %SRR0: 001f9dac   %SRR1: 00003030
    %CR: 42000082     %LR: 001f9db4    %CTR: 00208644    %XER: 00000000

%DAR: 7c7d1b78 %DSISR: 40000000 %SDR1: 07fe0000
ok
0 >

#2 lore raw

Re: non boot-device was Re: [ppc] [patch] set environment from commandline

Quoted 1 line · Paul Nasrat

0 > boot hd:2,\grubof.modules load-size=2e220 adler32=e04b6e6d

What are load-size and adler32 used for? Don't you need a `;' here?

Quoted 9 lines

Loading ELF
method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300
Welcome to GRUB!

What kind of box are you using? Which modules are added to grub.modules?

Thanks,
Marco

#3 lore raw

Re: non boot-device was Re: [ppc] [patch] set environment from commandline

Quoted 5 lines · Marco Gerards
Quoted 1 line · Paul Nasrat

0 > boot hd:2,\grubof.modules load-size=2e220 adler32=e04b6e6d

What are load-size and adler32 used for? Don't you need a `;' here?

They were auto added to console by OF - not me. Hold on let me retry with just HEAD as it's broken for me with boot-device now without telnet.

It's an imac DV SE.

Paul

#4 lore raw

Re: non boot-device was Re: [ppc] [patch] set environment from commandline

In reply to Marco Gerards
Quoted 16 lines · Marco Gerards
Quoted 1 line · Paul Nasrat

0 > boot hd:2,\grubof.modules load-size=2e220 adler32=e04b6e6d

What are load-size and adler32 used for? Don't you need a `;' here?

Quoted 9 lines

Loading ELF
method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300
Welcome to GRUB!

Quoted 2 lines

What kind of box are you using? Which modules are added to grub.modules?

This happens with a working grub from hollis. I guess as I'm using telnet I see it go past:

Loading ELF
method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300

This could be as the telnet console doesn't support colour. We probably want to be less verbose about this.

Ignore the Default catch that seems to be resolved for me.

Paul

#5 lore raw

Re: non boot-device was Re: [ppc] [patch] set environment from commandline

Quoted 1 line · Paul Nasrat

Ignore the Default catch that seems to be resolved for me.

Hmm, if you have any ideas, I'd still like to know how you got that error... Experimental toolchain?

-Hollis

#6 lore raw

Re: console colors

In reply to Paul Nasrat
Quoted 11 lines · Paul Nasrat

Loading ELF
method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300 method <color!> not found; ihandle=ffbc6f80 phandle=ff848300

This could be as the telnet console doesn't support colour. We probably want to be less verbose about this.

Agreed.

Actually it's funny, I didn't even realize we were using the color code... because I have seen no colors anywhere. Marco, does that do anything for you?

-Hollis

#7 lore raw

Re: console colors

Quoted 3 lines · Hollis Blanchard

Actually it's funny, I didn't even realize we were using the color code... because I have seen no colors anywhere. Marco, does that do anything for you?

Colors are supported and used to draw the menu. One of the first things GRUB does is printing an inverted welcome text. I assume this triggers this problem. It seems we need to check if colors are supported or not.

Thanks,
Marco

#8 lore raw
In reply to Hollis Blanchard
Quoted 1 line · Hollis Blanchard

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

Agreed.

Quoted 3 lines

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

This looks like a nice feature to me, especially for development. I wonder what others think of it.

Quoted 1 line

Comments?

Where is the changelog entry? ;)

Thanks,
Marco

#9 lore raw
Quoted 8 lines · Marco Gerards
Quoted 3 lines · Hollis Blanchard

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

This looks like a nice feature to me, especially for development. I wonder what others think of it.

Yeah, I consider it absolutely required, so that when users say "it crashed before I could do anything" we can just ask them to boot with "debug=all".

Quoted 3 lines
Quoted 1 line

Comments?

Where is the changelog entry? ;)

I was looking for other comments first. I guess you have no problem with it...

2005-05-10 Hollis Blanchard <[email protected]>

* boot/powerpc/ieee1275/cmain.c (cmain): Remove code to parse /chosen/bootargs.
* kern/powerpc/ieee1275/init.c (grub_machine_init): Parse /chosen/bootargs as "variable=value" pairs.

-Hollis

#10 lore raw
Quoted 3 lines · Hollis Blanchard

Yeah, I consider it absolutely required, so that when users say "it crashed before I could do anything" we can just ask them to boot with "debug=all".

What I want to use it for is setting the prefix. Usually I have grub.cfg stored on the HD and I boot GRUB over the network for testing. If the prefix can not be configured, the menu is not shown. And loading the menu manually all the time sucks.

Quoted 2 lines

I was looking for other comments first. I guess you have no problem with it...

No, please commit it. :)

Thanks,
Marco

#11 lore raw
In reply to Hollis Blanchard
Quoted 5 lines · Hollis Blanchard

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

Can one override essential parts of grub that way? Like loading a different config file?

#12 lore raw
Quoted 6 lines · Olaf Hering
Quoted 3 lines

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

Can one override essential parts of grub that way? Like loading a different config file?

The configfile is loaded from the path set by prefix. So it is possible by pointing to another directory.

--
Marco

#13 lore raw
In reply to Olaf Hering
Quoted 8 lines · Olaf Hering
Quoted 4 lines · Hollis Blanchard

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

Can one override essential parts of grub that way? Like loading a different config file?

Yes, the config file is loaded from wherever "prefix" points to. Also, there is a "configfile" command in the GRUB UI to load a config file from anywhere (I've been using that too).

Do you have any other "essential parts" in mind?

-Hollis

#14 lore raw
Quoted 1 line · Hollis Blanchard

Do you have any other "essential parts" in mind?

Showing or hiding images depending on cpu capabilities. Essentially a 'title[64bit] install' and 'title[32bit] install'. There is really no need to show 64bit kernels on my ibook. So if you guys could extend the syntax to provide very simple conditionals, that would be real useful.

#15 lore raw
Quoted 9 lines · Olaf Hering
Quoted 1 line · Hollis Blanchard

Do you have any other "essential parts" in mind?

Showing or hiding images depending on cpu capabilities. Essentially a 'title[64bit] install' and 'title[32bit] install'. There is really no need to show 64bit kernels on my ibook. So if you guys could extend the syntax to provide very simple conditionals, that would be real useful.

Scripting support is planned. Variable support is there already, but default some variables should be set by GRUB, like the processor, perhaps the amount of memory, time and date, etc.

The most important thing that needs to be done in adding scripting support.

--
Marco

#16 lore raw
Quoted 1 line · Marco Gerards

perhaps the amount of memory, time and date, etc.

Why would anyone care about that in a bootloader?

#17 lore raw
Quoted 5 lines · Olaf Hering
Quoted 1 line · Marco Gerards

perhaps the amount of memory, time and date, etc.

Why would anyone care about that in a bootloader?

Some people want to boot a specific OS depending on the time. There have been a lot of requests for this.

--
Marco