Skip to contentSkip to conversation

set prefix on PPC

PATCH In review Hollis Blanchard 3 participants 19 messages Feb 13, 2005 – Apr 17, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 set prefix on PPC

Any comments on this patch?

This code sets the GRUB "prefix" environment variable from the OF /chosen/bootpath property. It must therefore translate between the two syntaxes.

I believe most of this code could be moved to a kern/ieee1275/device.c file, but that can wait until there is another supported OF platform.

I have verified that this works (a config file is loaded) from disk, and netbooting is not broken. The subdirectory stuff works as well.

-Hollis

2005-02-13 Hollis Blanchard <[email protected]>

	* include/grub/powerpc/ieee1275/ieee1275.h
	(grub_ieee1275_get_dev_encoding): New prototype.
	(grub_ieee1275_get_filename): Likewise.
	* kern/powerpc/ieee1275/init.c (translate_path): New function.
	(grub_set_prefix): Likewise.
	(grub_machine_init): Call grub_set_prefix.
	* kern/powerpc/ieee1275/openfw.c (GRUB_PARSE_FILENAME): New
	constant.
	(GRUB_PARSE_PARTITION): Likewise.
	(grub_ieee1275_get_devargs): New function.
	(grub_ieee1275_get_devname): Likewise.
	(grub_ieee1275_parse_args): Likewise.
	(grub_ieee1275_get_filename): Likewise.
	(grub_ieee1275_get_dev_encoding): Likewise.

Index: include/grub/powerpc/ieee1275/ieee1275.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/ieee1275.h,v retrieving revision 1.14

grub/powerpc/ieee1275/ieee1275.h +3 -0
diff -u -p -r1.14 ieee1275.h
@@ -132,5 +132,8 @@ int EXPORT_FUNC(grub_claimmap) (grub_add
 
 void EXPORT_FUNC(abort) (void);
 
+char *EXPORT_FUNC(grub_ieee1275_get_dev_encoding) (const char *path);
+char *EXPORT_FUNC(grub_ieee1275_get_filename) (const char *path);
+
 
 #endif /* ! GRUB_IEEE1275_MACHINE_HEADER */

Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/init.c,v retrieving revision 1.13

powerpc/ieee1275/init.c +63 -1

76 lines not on this page · raw message

Index: kern/powerpc/ieee1275/openfw.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/openfw.c,v retrieving revision 1.7

powerpc/ieee1275/openfw.c +136 -1

152 lines not on this page · raw message

#1 lore raw

Hollis Blanchard <[email protected]> writes:

Hi,

Quoted 3 lines

This code sets the GRUB "prefix" environment variable from the OF /chosen/bootpath property. It must therefore translate between the two syntaxes.

Personally I don't like setting prefix to the path grubof was loaded from. Mainly because of the way how things work on the macintosh. It has a special HFS[+] boot partition (at least my installation, but I think this is the common practice).

I don't like installing all modules and the configuration file on this partition. There were some problems with writing to this partition IIRC and it is not comfortable to use. It should not be touched by a user, I just can't remember why. I will look that up.

What I would prefer is a way to encode the prefix into the grubof binary. The only disadvantage is that it might be hard to detect this install time.

What I would prefer is this:

1)  Set prefix to whatever was set in the binary.
2)  If nothing was set, use `bootpath'.
3)  Read the arguments and if a prefix was passed to GRUB, use it to

override the prefix.

For #3 I wrote a patch, but I forgot to send it to grub-devel... It's included with this email. As far as I am concerned #1 is what is really important for us.

Perhaps I might be confused by what I read last year and it is not really an issue. I just want to get things right.

Thanks,
Marco

2005-02-13 Marco Gerards <[email protected]>

* kern/powerpc/ieee1275/init.c (grub_machine_init): Initialize the prefix env variable with the bootargs when it has a valid value.

* loader/powerpc/ieee1275/linux.c (grub_rescue_cmd_linux): Don't initialize `init_addr' yet, set it to 0 instead.

Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/init.c,v retrieving revision 1.13

powerpc/ieee1275/init.c +16 -0
diff -u -p -r1.13 init.c
@@ -48,6 +48,8 @@ grub_machine_init (void)
   extern char _start;
   grub_addr_t heap_start;
   grub_addr_t heap_len;
+  grub_ieee1275_phandle_t chosen;
+  grub_size_t proplen;
 
   grub_console_init ();
 
@@ -67,6 +69,20 @@ grub_machine_init (void)
 
   grub_env_set ("prefix", "");
 
+  /* Try to override the prefix using the argument passed to GRUB.  */
+  grub_ieee1275_finddevice ("/chosen", &chosen);
+  grub_ieee1275_get_property_length (chosen, "bootargs", &proplen);
+  {
+    char args[proplen];
+    grub_size_t actual;
+    
+    grub_ieee1275_get_property (chosen, "bootargs", args, proplen, &actual);
+    
+    /* If the argument is a valid path, use it.  */
+    if (actual > 0 && args[0] == '(' && grub_strchr (args, ')'))
+      grub_env_set ("prefix", args);
+  }
+  
   grub_ofdisk_init ();
 }
 

Index: loader/powerpc/ieee1275/linux.c
===================================================================
RCS file: /cvsroot/grub/grub2/loader/powerpc/ieee1275/linux.c,v retrieving revision 1.5

powerpc/ieee1275/linux.c +1 -1
diff -u -p -r1.5 linux.c
@@ -258,7 +258,7 @@ grub_rescue_cmd_linux (int argc, char *a
   else
     {
       grub_loader_set (grub_linux_boot, grub_linux_unload);
-      initrd_addr = 0xc0000000;
+      initrd_addr = 0;
       loaded = 1;
     }
   
#2 lore raw
Quoted 11 lines · Marco Gerards
Quoted 3 lines · Hollis Blanchard

This code sets the GRUB "prefix" environment variable from the OF /chosen/bootpath property. It must therefore translate between the two syntaxes.

Personally I don't like setting prefix to the path grubof was loaded from. Mainly because of the way how things work on the macintosh. It has a special HFS[+] boot partition (at least my installation, but I think this is the common practice).

Quoted 4 lines

I don't like installing all modules and the configuration file on this partition. There were some problems with writing to this partition IIRC and it is not comfortable to use. It should not be touched by a user, I just can't remember why. I will look that up.

Please let me know if you find any actual data. I have heard the ybin author rant about this for years (see http://lists.penguinppc.org/yaboot-users/2002/yaboot-users-200210/msg00008.html as an example), but he doesn't like to substantiate his claims.

I believe there were two problems with keeping /boot on an HFS partition:
1) The Linux HFS driver wasn't overly reliable. That's unfortunate if you're writing a kernel there, or editing grub.cfg. For that reason, /boot is typically kept as a Linux-native filesystem, and to install a kernel ybin invokes hfsutils to do the copying to the "bootstrap" partition. (Note the similarity in names "boot" and "bootstrap" causes confusion.)
2) HFS has a concept called "blessed"; basically the firmware can automatically find and boot blessed executables without needing to specify a file name or even partition. Some versions of Mac OS allegedly will unbless a non-Mac OS blessed file. For that reason, ybin prefers the HFS "bootstrap" partition be of a type that Mac OS will not mount (and so will not alter).

However, please do not mistake "this is how ybin does it" for "this is the only way to do it". I have never seen these problems (though I personally ran an HFS /boot partition that Mac OS mounted), and I have never seen data as to what exact software versions or scenarios cause a problem. The user in the URL above claims no problems either, and I haven't heard of other users with these problems.

Quoted 3 lines

What I would prefer is a way to encode the prefix into the grubof binary. The only disadvantage is that it might be hard to detect this install time.

If possible, placing grub.cfg next to grubof will be the easiest solution. That way, no matter how or where you boot GRUB (even from rescue CD or whatever), you will always know what grub.cfg it will load.

Example: you're making a distribution installer and need to boot from CD. What prefix do you embed in GRUB? There is no guarantee that every machine out there has a "cd" devalias, nor would you want to require users to create that in OF before booting. Simply looking adjacent to the grubof binary is a much better solution.

Quoted 3 lines

What I would prefer is this:

1) Set prefix to whatever was set in the binary.

This would involve more post-compilation ELF manipulation. To accomplish that, if we do decide to go that route, I think it would be worth converting the existing module segment into a more general-purpose segment, containing all the added arguments.

Remember, right now we load modules at a fixed address. At runtime, GRUB finds at that address:
1. the size of the modules in memory
2. the module binaries

We can change this to be more general-purpose, e.g. a chain or "parameter" structures that could contain the module binaries, the size of modules, the prefix, etc.

Quoted 1 line

2) If nothing was set, use `bootpath'.

So it's not such a bad idea after all huh? :)

Quoted 11 lines

3) Read the arguments and if a prefix was passed to GRUB, use it to override the prefix.

For #3 I wrote a patch, but I forgot to send it to grub-devel... It's included with this email. As far as I am concerned #1 is what is really important for us.

2005-02-13 Marco Gerards <[email protected]>

* kern/powerpc/ieee1275/init.c (grub_machine_init): Initialize the prefix env variable with the bootargs when it has a valid value.

I don't like that this assumes bootargs only contains the prefix. For example, if we ever get our fancy debugging support, it would be very nice to boot grub with "debug=all" as an argument.

Quoted 2 lines

* loader/powerpc/ieee1275/linux.c (grub_rescue_cmd_linux): Don't initialize `init_addr' yet, set it to 0 instead.

Confused... how is this related to bootargs and prefix?

-Hollis

#3 lore raw
Quoted 18 lines · Hollis Blanchard
Quoted 11 lines · Marco Gerards
Quoted 3 lines · Hollis Blanchard

This code sets the GRUB "prefix" environment variable from the OF /chosen/bootpath property. It must therefore translate between the two syntaxes.

Personally I don't like setting prefix to the path grubof was loaded from. Mainly because of the way how things work on the macintosh. It has a special HFS[+] boot partition (at least my installation, but I think this is the common practice).

Quoted 4 lines

I don't like installing all modules and the configuration file on this partition. There were some problems with writing to this partition IIRC and it is not comfortable to use. It should not be touched by a user, I just can't remember why. I will look that up.

Quoted 5 lines

Please let me know if you find any actual data. I have heard the ybin author rant about this for years (see
http://lists.penguinppc.org/yaboot-users/2002/yaboot-users-200210/
msg00008.html as an example), but he doesn't like to substantiate his claims.

this is interesting. We could put a warning in the manual (when writing it), but I most certainly don't want to force people to use some kind of partition.

Quoted 8 lines

I believe there were two problems with keeping /boot on an HFS partition:
1) The Linux HFS driver wasn't overly reliable. That's unfortunate if you're writing a kernel there, or editing grub.cfg. For that reason, /boot is typically kept as a Linux-native filesystem, and to install a kernel ybin invokes hfsutils to do the copying to the "bootstrap" partition. (Note the similarity in names "boot" and "bootstrap" causes confusion.)

Yeah, ok. This is something we should not worry about at the moment. If the HFS filesystem is broken, which I doubt, we could either fix it or install GRUB there using a similar script.

Quoted 6 lines

2) HFS has a concept called "blessed"; basically the firmware can automatically find and boot blessed executables without needing to specify a file name or even partition. Some versions of Mac OS allegedly will unbless a non-Mac OS blessed file. For that reason, ybin prefers the HFS "bootstrap" partition be of a type that Mac OS will not mount (and so will not alter).

How is the file blessed and why does that make it a problem to keep /boot on a HFS partition?

Quoted 6 lines

However, please do not mistake "this is how ybin does it" for "this is the only way to do it". I have never seen these problems (though I personally ran an HFS /boot partition that Mac OS mounted), and I have never seen data as to what exact software versions or scenarios cause a problem. The user in the URL above claims no problems either, and I haven't heard of other users with these problems.

No, of course not. But I usually take warnings seriously. And yaboot is full of those. :)

Quoted 8 lines
Quoted 3 lines

What I would prefer is a way to encode the prefix into the grubof binary. The only disadvantage is that it might be hard to detect this install time.

If possible, placing grub.cfg next to grubof will be the easiest solution. That way, no matter how or where you boot GRUB (even from rescue CD or whatever), you will always know what grub.cfg it will load.

Right.

Quoted 8 lines
Quoted 3 lines

What I would prefer is this:

1) Set prefix to whatever was set in the binary.

This would involve more post-compilation ELF manipulation. To accomplish that, if we do decide to go that route, I think it would be worth converting the existing module segment into a more general-purpose segment, containing all the added arguments.

Ok. If we use your patch, this is not that important, I guess. If it works right that is.

Quoted 8 lines

Remember, right now we load modules at a fixed address. At runtime, GRUB finds at that address:
1. the size of the modules in memory
2. the module binaries

We can change this to be more general-purpose, e.g. a chain or "parameter" structures that could contain the module binaries, the size of modules, the prefix, etc.

This might be nice someday.

Quoted 3 lines
Quoted 1 line

2) If nothing was set, use `bootpath'.

So it's not such a bad idea after all huh? :)

:)

Quoted 7 lines
Quoted 7 lines

3) Read the arguments and if a prefix was passed to GRUB, use it to override the prefix.

For #3 I wrote a patch, but I forgot to send it to grub-devel... It's included with this email. As far as I am concerned #1 is what is really important for us.

Quoted 8 lines
Quoted 4 lines

2005-02-13 Marco Gerards <[email protected]>

* kern/powerpc/ieee1275/init.c (grub_machine_init): Initialize the prefix env variable with the bootargs when it has a valid value.

I don't like that this assumes bootargs only contains the prefix. For example, if we ever get our fancy debugging support, it would be very nice to boot grub with "debug=all" as an argument.

I don't want to add a fancy parser yet. At the moment we just use a single argument. If more will be used, this code has to be changed.

Quoted 4 lines
Quoted 2 lines

* loader/powerpc/ieee1275/linux.c (grub_rescue_cmd_linux): Don't initialize `init_addr' yet, set it to 0 instead.

Confused... how is this related to bootargs and prefix?

It is required to make GNU/Linux boot here, just like the bootargs stuff. ;)

It is separated with a blank line to make clear they do not serve the same purpose.

Thanks,
Marco

#4 lore raw
Quoted 11 lines · Marco Gerards
Quoted 6 lines · Hollis Blanchard

2) HFS has a concept called "blessed"; basically the firmware can automatically find and boot blessed executables without needing to specify a file name or even partition. Some versions of Mac OS allegedly will unbless a non-Mac OS blessed file. For that reason, ybin prefers the HFS "bootstrap" partition be of a type that Mac OS will not mount (and so will not alter).

How is the file blessed and why does that make it a problem to keep /boot on a HFS partition?

The file is blessed with hfsutils, spefically hattrib(1). I do not know if the in-kernel HFS(+) drivers allow for such changes (via ioctls for example). That will be worth investigating.

Actually it seems I was mistaken, and "blessed" refers to the directory rather than the file itself. I believe then the proper file to be booted is found from its 4-byte HFS file type, "tbxi" being the magic "Mac OS kernel" type.

Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

What I would prefer is this:

1) Set prefix to whatever was set in the binary.

This would involve more post-compilation ELF manipulation. To accomplish that, if we do decide to go that route, I think it would be worth converting the existing module segment into a more general-purpose segment, containing all the added arguments.

Ok. If we use your patch, this is not that important, I guess. If it works right that is.

Ok. I assume you want to test my patch and review it further, so I will wait for more comments before committing it.

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

3) Read the arguments and if a prefix was passed to GRUB, use it to override the prefix.

For #3 I wrote a patch, but I forgot to send it to grub-devel... It's included with this email. As far as I am concerned #1 is what is really important for us.

2005-02-13 Marco Gerards <[email protected]>

* kern/powerpc/ieee1275/init.c (grub_machine_init): Initialize the prefix env variable with the bootargs when it has a valid value.

Quoted 6 lines
Quoted 3 lines

I don't like that this assumes bootargs only contains the prefix. For example, if we ever get our fancy debugging support, it would be very nice to boot grub with "debug=all" as an argument.

I don't want to add a fancy parser yet. At the moment we just use a single argument. If more will be used, this code has to be changed.

And in that case, the format of "bootargs" will have to change too. It's never too early to think about backwards compatibility, especially if people are thinking of packaging and distributing a grub2.deb... :)

Quoted 10 lines
Quoted 4 lines
Quoted 2 lines

* loader/powerpc/ieee1275/linux.c (grub_rescue_cmd_linux): Don't initialize `init_addr' yet, set it to 0 instead.

Confused... how is this related to bootargs and prefix?

It is required to make GNU/Linux boot here, just like the bootargs stuff. ;)

It is separated with a blank line to make clear they do not serve the same purpose.

I thought each ChangeLog entry represented a distinct "changeset", with changesets being logically different changes to a group of files. The ChangeLog was explained to me as emulating a changeset in version control systems that lack the concept (such as CVS).

Since I believe the ChangeLog is an anachronism, I don't really care what it looks like or what format it's in. But since these changes are logically distinct, I believe they should at least be committed with separate "cvs commit" commands.

-Hollis

#5 lore raw
Quoted 11 lines · Hollis Blanchard
Quoted 2 lines

How is the file blessed and why does that make it a problem to keep /boot on a HFS partition?

The file is blessed with hfsutils, spefically hattrib(1). I do not know if the in-kernel HFS(+) drivers allow for such changes (via ioctls for example). That will be worth investigating.

Actually it seems I was mistaken, and "blessed" refers to the directory rather than the file itself. I believe then the proper file to be booted is found from its 4-byte HFS file type, "tbxi" being the magic "Mac OS kernel" type.

Ok. But the file does not need to be blessed to boot from it. It's just used so the user can use:

boot hd,0

instead of:

boot hd,0:grubof

To me the second sounds good enough. Or does that cause other problems?

Quoted 2 lines

Ok. I assume you want to test my patch and review it further, so I will wait for more comments before committing it.

Sure, I will test and review it on both of my PPC systems and review the patch. I hope you understand that it can take a while. :/

Quoted 7 lines
Quoted 2 lines

I don't want to add a fancy parser yet. At the moment we just use a single argument. If more will be used, this code has to be changed.

And in that case, the format of "bootargs" will have to change too. It's never too early to think about backwards compatibility, especially if people are thinking of packaging and distributing a grub2.deb... :)

Huh? Why would backward compatibility be broken?

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

Confused... how is this related to bootargs and prefix?

It is required to make GNU/Linux boot here, just like the bootargs stuff. ;)

Quoted 7 lines
Quoted 2 lines

It is separated with a blank line to make clear they do not serve the same purpose.

I thought each ChangeLog entry represented a distinct "changeset", with changesets being logically different changes to a group of files. The ChangeLog was explained to me as emulating a changeset in version control systems that lack the concept (such as CVS).

From the GCS:

"Separate unrelated change log entries with blank lines. When two
entries represent parts of the same change, so that they work together, then don't put blank lines between them. Then you can omit the file name and the asterisk when successive entries are in the same file."

Did I misinterpret this?

Quoted 4 lines

Since I believe the ChangeLog is an anachronism, I don't really care what it looks like or what format it's in. But since these changes are logically distinct, I believe they should at least be committed with separate "cvs commit" commands.

One commit it one ChangeLog entry, it's the same.

Thanks,
Marco

#6 lore raw
Quoted 10 lines · Marco Gerards

Ok. But the file does not need to be blessed to boot from it. It's just used so the user can use:

boot hd,0

instead of:

boot hd,0:grubof

To me the second sounds good enough. Or does that cause other problems?

Remember that resetting the PRAM (a rare but not unusual action on Macs) will revert to the stock firmware configuration, and if OS X is the only blessed OS, the user will find themselves unable to boot into Linux without a decent understanding of Open Firmware. Blessing GRUB would eliminate this problem*.

* If OS X is on a lower partition number, the user will still boot into OS X after a PRAM reset. However, if the firmware recognizes GRUB as a valid kernel, there is a graphical "select boot device" interface on newer machines that can be triggered by holding down the Option key at startup.

Quoted 5 lines
Quoted 2 lines

Ok. I assume you want to test my patch and review it further, so I will wait for more comments before committing it.

Sure, I will test and review it on both of my PPC systems and review the patch. I hope you understand that it can take a while. :/

I hope I can talk you into taking a look soon, as this functionality is essential if we want to actually *use* GRUB2.

It should be pretty easy to build and see what happens... :) (See my patch from earlier today since current CVS doesn't build.)

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

I don't want to add a fancy parser yet. At the moment we just use a single argument. If more will be used, this code has to be changed.

And in that case, the format of "bootargs" will have to change too. It's never too early to think about backwards compatibility, especially if people are thinking of packaging and distributing a grub2.deb... :)

Huh? Why would backward compatibility be broken?

If a user installs GRUB now with this bootargs patch, then later if we wish to add a debug option with "fancy parser" they will no longer be able to boot, as the syntax will change.

Now: "boot grubof hd0,6"
Later: "boot grubof prefix=hd0,6 debug=all"

Users trying to boot with the old syntax will fail.

-Hollis

#7 lore raw
Quoted 10 lines · Hollis Blanchard
Quoted 9 lines · Marco Gerards

Ok. But the file does not need to be blessed to boot from it. It's just used so the user can use:

boot hd,0

instead of:

boot hd,0:grubof

Quoted 8 lines
Quoted 2 lines

To me the second sounds good enough. Or does that cause other problems?

Remember that resetting the PRAM (a rare but not unusual action on Macs) will revert to the stock firmware configuration, and if OS X is the only blessed OS, the user will find themselves unable to boot into Linux without a decent understanding of Open Firmware. Blessing GRUB would eliminate this problem*.

This is a good explanation of the problem. When we have documentation we should have a text like this in it. :)

Quoted 5 lines

* If OS X is on a lower partition number, the user will still boot into OS X after a PRAM reset. However, if the firmware recognizes GRUB as a valid kernel, there is a graphical "select boot device" interface on newer machines that can be triggered by holding down the Option key at startup.

Ok.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Ok. I assume you want to test my patch and review it further, so I will wait for more comments before committing it.

Sure, I will test and review it on both of my PPC systems and review the patch. I hope you understand that it can take a while. :/

I hope I can talk you into taking a look soon, as this functionality is essential if we want to actually *use* GRUB2.

Ok.

Quoted 2 lines

It should be pretty easy to build and see what happens... :) (See my patch from earlier today since current CVS doesn't build.)

That's something I could do. :)

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

I don't want to add a fancy parser yet. At the moment we just use a single argument. If more will be used, this code has to be changed.

And in that case, the format of "bootargs" will have to change too. It's never too early to think about backwards compatibility, especially if people are thinking of packaging and distributing a grub2.deb... :)

Quoted 8 lines
Quoted 1 line

Huh? Why would backward compatibility be broken?

If a user installs GRUB now with this bootargs patch, then later if we wish to add a debug option with "fancy parser" they will no longer be able to boot, as the syntax will change.

Now: "boot grubof hd0,6"
Later: "boot grubof prefix=hd0,6 debug=all"

I do not like the prefix= syntax. What I want is:

Now: "boot grubof (hd0,6)"
Later: "boot grubof (hd0,6) --debug=all"

Quoted 1 line

Users trying to boot with the old syntax will fail.

In my case it will still work. :)

Thanks,
Marco

#8 lore raw
Quoted 8 lines · Marco Gerards
Quoted 7 lines

If a user installs GRUB now with this bootargs patch, then later if we wish to add a debug option with "fancy parser" they will no longer be able to boot, as the syntax will change.

Now: "boot grubof hd0,6"
Later: "boot grubof prefix=hd0,6 debug=all"

Quoted 8 lines

I do not like the prefix= syntax. What I want is:

Now: "boot grubof (hd0,6)"
Later: "boot grubof (hd0,6) --debug=all"

Quoted 1 line

Users trying to boot with the old syntax will fail.

In my case it will still work. :)

In your case we are stuck with an inflexible syntax forever. There is a reason that commandline tools use named switches, and do not require them in any particular order.

-Hollis

#9 lore raw
Quoted 7 lines · Hollis Blanchard
Quoted 3 lines
Quoted 1 line

Users trying to boot with the old syntax will fail.

In my case it will still work. :)

In your case we are stuck with an inflexible syntax forever. There is a reason that commandline tools use named switches, and do not require them in any particular order.

Why? If you add add a --debug it will still work:

boot grubof --debug=all (hd0,6)

If it is really important, I could change this, but I think a full featured argument parser would be a bit overkill. :)

--
Marco

#10 lore raw
In reply to Hollis Blanchard
Quoted 3 lines · Hollis Blanchard

This code sets the GRUB "prefix" environment variable from the OF /chosen/bootpath property. It must therefore translate between the two syntaxes.

Sven just told me bootpath does not work on the pegasos II, although it will be fixed. So the argument will still be required, I guess. I will send in a patch for that later (one that will work with this patch applied).

Quoted 2 lines

I believe most of this code could be moved to a kern/ieee1275/device.c file, but that can wait until there is another supported OF platform.

Right. A lot of code can be moved and shared.

Quoted 2 lines

I have verified that this works (a config file is loaded) from disk, and netbooting is not broken. The subdirectory stuff works as well.

Ok. I still have to test it... :/

Quoted 1 line

2005-02-13 Hollis Blanchard <[email protected]>

[...]

Quoted 1 line

(GRUB_PARSE_PARTITION): Likewise.

Just make this a new enum. So name the enum and say "New enum `foo'.". See my comment below.

Quoted 1 line

Index: kern/powerpc/ieee1275/init.c

[...]

powerpc/ieee1275/init.c abort (void) · line 48

Quoted 4 lines
powerpc/ieee1275/init.c +4 -0
+/* Translate an OF filesystem path (separated by backslashes), into a GRUB
+   path (separated by forward slashes).  */
+static void
+translate_path (char *filepath)

Can you add a prefix?

powerpc/ieee1275/init.c abort (void) · line 63

Quoted 4 lines
powerpc/ieee1275/init.c +4 -0
+static void
+grub_set_prefix (void)
+{
+  char bootpath[64]; /* XXX check length */

You could get the property length and use that. It would be clearer. See my patch for passing the prefix as an argument for an example of this. I think this was done like this before, but that should be changed as well. :)

Quoted 1 line

Index: kern/powerpc/ieee1275/openfw.c

[...]

Quoted 1 line

+enum {

Please put the { on a new line.

powerpc/ieee1275/openfw.c line 29

Quoted 3 lines
powerpc/ieee1275/openfw.c +3 -0
+  GRUB_PARSE_FILENAME,
+  GRUB_PARSE_PARTITION,
+};

I think there can be some problems with unnamed enums. I am not sure though...

Quoted 14 lines
powerpc/ieee1275/openfw.c +2 -1
+
 /* Walk children of 'devpath', calling hook for each.  */
 grub_err_t
 grub_children_iterate (char *devpath,
@@ -64,7 +69,7 @@ grub_children_iterate (char *devpath,
       if (actual == -1)
 	continue;
 
-      grub_sprintf(fullname, "%s/%s", devpath, childname);
+      grub_sprintf (fullname, "%s/%s", devpath, childname);
 
       alias.type = childtype;
       alias.path = childpath;

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 209

Quoted 6 lines
powerpc/ieee1275/openfw.c +3 -0
@@ -199,3 +204,133 @@ grub_claimmap (grub_addr_t addr, grub_si
 
   return 0;
 }
+
+/* Get the device arguments of the Open Firmware device specifier `path'.  */
+static char *

Device arguments are like the partition number or so?

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 238

Quoted 4 lines
powerpc/ieee1275/openfw.c +4 -0
+static char *
+grub_ieee1275_parse_args (const char *path, int field)
+{
+  char type[64]; /* XXX check size.  */

Same stuff as before. :)

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 246

Quoted 8 lines
powerpc/ieee1275/openfw.c +8 -0
+  char *device = grub_ieee1275_get_devname (path);
+  char *args = grub_ieee1275_get_devargs (path);
+  char *ret = 0;
+  grub_ieee1275_phandle_t dev;
+
+  if (!args)
+    /* Shouldn't happen.  */
+    return 0;

If I understood your code correctly it can't happen at all, in that case the test would be useless.

Quoted 8 lines
powerpc/ieee1275/openfw.c +8 -0
+
+  /* We need to know what type of device it is in order to parse the full
+     file path properly.  */
+  if (grub_ieee1275_finddevice (device, &dev))
+    {
+      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Device %s not found\n", device);
+      goto out;
+    }

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 264

Quoted 10 lines
powerpc/ieee1275/openfw.c +10 -0
+  if (grub_ieee1275_get_property (dev, "device_type", &type, sizeof type, 0))
+    {
+      grub_error (GRUB_ERR_UNKNOWN_DEVICE,
+		  "Device %s lacks a device_type property\n", device);
+      goto out;
+    }
+
+  if (!grub_strcmp ("block", type))
+    {
+      /* Example: "disk:<partition number>,<file name>".  */

Is it always like this without exceptions? Will this always be an alias or will this be copied from "boot"?

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 278

Quoted 6 lines
powerpc/ieee1275/openfw.c +6 -0
+	      ret = grub_malloc (grub_strlen (filepath) + 1);
+	      /* Make sure filepath has leading backslash.  */
+	      if (filepath[0] != '\\')
+		grub_sprintf (ret, "\\%s", filepath);
+	      else
+		grub_strcpy (ret, filepath);

Why is this required?

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 298

Quoted 1 line
powerpc/ieee1275/openfw.c +1 -0
+out:

Please use "fail:", just to be consistent.

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 320

Quoted 11 lines
powerpc/ieee1275/openfw.c +11 -0
+char *
+grub_ieee1275_get_dev_encoding (const char *path)
+{
+  char *device = grub_ieee1275_get_devname (path);
+  char *partition = grub_ieee1275_parse_args (path, GRUB_PARSE_PARTITION);
+  char *encoding;
+
+  if (partition)
+    {
+      unsigned int partno = grub_strtoul (partition, 0, 0);
+      partno--; /* GRUB partition numbering is 0-based.  */

Right. But how can you be sure both match?

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 323

Quoted 3 lines
powerpc/ieee1275/openfw.c +3 -0
+
+      /* XXX Assume partno will only require two bytes? */
+      encoding = grub_malloc (grub_strlen (device) + 5);

Can't you just calculate this? Otherwise you can better allocate a few bytes too much.

Thanks,
Marco

#11 lore raw
Quoted 7 lines · Marco Gerards

powerpc/ieee1275/init.c abort (void) · line 63

Quoted 5 lines
powerpc/ieee1275/init.c +4 -0
+static void
+grub_set_prefix (void)
+{
+  char bootpath[64]; /* XXX check length */

You could get the property length and use that. It would be clearer.

All these stack-based get_property calls are an accident waiting to happen, but you've advocated them until now. :-P Instead, we need a wrapper function that returns a malloced buffer of the proper size. That's what you're suggesting open-coding here anyways.

However I would rather not do that right now. The few developers (myself included) have other things going on, and there are still significant functionality gaps. Right now I don't want to spend time developing patches that produce lots of code churn and no user-visible improvement. Others are more than welcome to, of course. :)

Quoted 6 lines
Quoted 4 lines
(quoted diff) +2 -0
+
+/* Get the device arguments of the Open Firmware device specifier 

`path'. */
+static char *

Device arguments are like the partition number or so?

Yes. OF "node names" contain two parts, the device path and the device arguments. The device arguments are everything following a colon, and the syntax of the arguments is device-specific (but by convention they are separated by commas).

In the case of a node name like "disk:6,grubof", "6,grubof" are the device arguments.

I used the term "device specifier" incorrectly the comments; I will correct that. (IEEE1275 defines its terms at the beginning, which is quite helpful...)

Quoted 10 lines

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 246

Quoted 9 lines
powerpc/ieee1275/openfw.c +8 -0
+  char *device = grub_ieee1275_get_devname (path);
+  char *args = grub_ieee1275_get_devargs (path);
+  char *ret = 0;
+  grub_ieee1275_phandle_t dev;
+
+  if (!args)
+    /* Shouldn't happen.  */
+    return 0;
Quoted 2 lines

If I understood your code correctly it can't happen at all, in that case the test would be useless.

That is not the case:

+grub_ieee1275_get_devargs (const char *path)
+{
+ char *colon = grub_strchr (path, ':');
+ char *end;
+
+ if (! colon)
+ return 0;
...
+}

So if no colon is present, grub_ieee1275_get_devargs returns NULL (ahem "0" because we're silly), and then 'args' is NULL, and then we fail.

As a separate issue, I *believe* that bootpath should always be a fully-expanded node name, and so always contain a colon, but that depends on well-behaved firmware. Accordingly, I don't think a sanity check here is unreasonable.

Quoted 15 lines
Quoted 15 lines

+ /* We need to know what type of device it is in order to parse the full

powerpc/ieee1275/openfw.c +4 -0
+     file path properly.  */
+  if (grub_ieee1275_finddevice (device, &dev))
+    {
+      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Device %s not found\n", 

device);

powerpc/ieee1275/openfw.c +3 -0
+      goto out;
+    }
+  if (grub_ieee1275_get_property (dev, "device_type", &type, sizeof 

type, 0))

powerpc/ieee1275/openfw.c +4 -0
+    {
+      grub_error (GRUB_ERR_UNKNOWN_DEVICE,
+		  "Device %s lacks a device_type property\n", device);
+      goto out;
Quoted 8 lines

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 264

Quoted 5 lines
powerpc/ieee1275/openfw.c +5 -0
+    }
+
+  if (!grub_strcmp ("block", type))
+    {
+      /* Example: "disk:<partition number>,<file name>".  */

Is it always like this without exceptions? Will this always be an alias or will this be copied from "boot"?

Please see section 3.5, "Standard system nodes". From the /chosen table, we can see that bootpath contains a "device path". By definition that does not include the device arguments; it seems to have been the intent of the spec that the device arguments belong in bootargs.

However, as we can see experimentally, at least Apple firmware includes the device arguments in bootpath. My briQ's firmware does not, at least for netbooting:

	ok boot net:,grubof.chrp
	grub> suspend
	ok dev /chosen
	ok .properties
	...
	bootargs              "briqboot"
	bootpath              "/pci@FF500000/ethernet@7"
	...

... where "briqboot" is the contents of the the boot-file environment variable. This is likely the behavior Sven said was broken.

Quoted 8 lines

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 278

Quoted 6 lines
powerpc/ieee1275/openfw.c +6 -0
+	      ret = grub_malloc (grub_strlen (filepath) + 1);
+	      /* Make sure filepath has leading backslash.  */
+	      if (filepath[0] != '\\')
+		grub_sprintf (ret, "\\%s", filepath);
+	      else
+		grub_strcpy (ret, filepath);

Why is this required?

In OF, it is possible to boot from either "disk:foo" or "disk:\foo" (both are the same file).

However, our filesystem code fails when accessing a path like "(hd0,0)//foo", and it also fails on "(hd0,0)foo". The above code handles either case by ensuring that the resulting path always has a leading backslash (later translated into a forward slash before being passed to our filesystem code).

Quoted 6 lines
Quoted 6 lines
powerpc/ieee1275/openfw.c +5 -0
+char *
+grub_ieee1275_get_dev_encoding (const char *path)
+{
+  char *device = grub_ieee1275_get_devname (path);
+  char *partition = grub_ieee1275_parse_args (path, 

GRUB_PARSE_PARTITION);

Quoted 8 lines

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 320

Quoted 6 lines
powerpc/ieee1275/openfw.c +6 -0
+  char *encoding;
+
+  if (partition)
+    {
+      unsigned int partno = grub_strtoul (partition, 0, 0);
+      partno--; /* GRUB partition numbering is 0-based.  */

Right. But how can you be sure both match?

Eh? OF partition numbers are 1-based. To convert to GRUB's 0-based numbering, we subtract one. How could that not "match"?

Quoted 6 lines

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 323

Quoted 3 lines
powerpc/ieee1275/openfw.c +3 -0
+
+      /* XXX Assume partno will only require two bytes? */
+      encoding = grub_malloc (grub_strlen (device) + 5);

Can't you just calculate this? Otherwise you can better allocate a few bytes too much.

How exactly would you like to calculate what sprintf will do before it does it? We have no snprintf (with "sophisticated" return values), and I don't think it's worth the effort either.

I will change the 5 to an 8 if it makes you happy, though I would be very surprised to see a disk with partitions in even the (base 10) triple digits.

-Hollis

#12 lore raw

Hollis Blanchard <[email protected]> writes:

Hi Hollis,

Sorry for the late reply. For some reason I did not see this email.

Quoted 6 lines
Quoted 1 line

You could get the property length and use that. It would be clearer.

All these stack-based get_property calls are an accident waiting to happen, but you've advocated them until now. :-P Instead, we need a wrapper function that returns a malloced buffer of the proper size. That's what you're suggesting open-coding here anyways.

Using malloc is way better.

Quoted 5 lines

However I would rather not do that right now. The few developers (myself included) have other things going on, and there are still significant functionality gaps. Right now I don't want to spend time developing patches that produce lots of code churn and no user-visible improvement. Others are more than welcome to, of course. :)

Sure, I don't have a big problem with this in this case. But please don't do that all the time because that will just make a crap out of GRUB, which is something I don't want.

Quoted 9 lines
Quoted 1 line

Device arguments are like the partition number or so?

Yes. OF "node names" contain two parts, the device path and the device arguments. The device arguments are everything following a colon, and the syntax of the arguments is device-specific (but by convention they are separated by commas).

In the case of a node name like "disk:6,grubof", "6,grubof" are the device arguments.

Ok.

Quoted 3 lines

I used the term "device specifier" incorrectly the comments; I will correct that. (IEEE1275 defines its terms at the beginning, which is quite helpful...)

Great. :)

Quoted 4 lines

As a separate issue, I *believe* that bootpath should always be a fully-expanded node name, and so always contain a colon, but that depends on well-behaved firmware. Accordingly, I don't think a sanity check here is unreasonable.

When dealing with some open firmware implementations, it is better to be paranoid. ;)

Quoted 10 lines

However, as we can see experimentally, at least Apple firmware includes the device arguments in bootpath. My briQ's firmware does not, at least for netbooting:

	ok boot net:,grubof.chrp
	grub> suspend
	ok dev /chosen
	ok .properties
	...
	bootargs              "briqboot"
	bootpath              "/pci@FF500000/ethernet@7"

So we don't get an alias... hmm.

Doesn't this cause any problems?

Quoted 2 lines

... where "briqboot" is the contents of the the boot-file environment variable. This is likely the behavior Sven said was broken.

Ok..

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
powerpc/ieee1275/openfw.c +5 -0
+char *
+grub_ieee1275_get_dev_encoding (const char *path)
+{
+  char *device = grub_ieee1275_get_devname (path);
+  char *partition = grub_ieee1275_parse_args (path,

GRUB_PARSE_PARTITION);

Quoted 8 lines

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 320

Quoted 6 lines
powerpc/ieee1275/openfw.c +6 -0
+  char *encoding;
+
+  if (partition)
+    {
+      unsigned int partno = grub_strtoul (partition, 0, 0);
+      partno--; /* GRUB partition numbering is 0-based.  */

Right. But how can you be sure both match?

Quoted 2 lines

Eh? OF partition numbers are 1-based. To convert to GRUB's 0-based numbering, we subtract one. How could that not "match"?

Because not in all cases GRUB and the firmware will count partitions the same way. A good example is the PC partition map. In linux primary partitions are numbers from 1 to 4, extended partitions are numbered from 5 (IIRC). One other way to count these partitions is just by starting counting from 1.

This is just an example. There are a lot of partition table layouts and many ways to interpret partition numbers. I can imagine GRUB does not always work the same as a specific firmware implementation all the time.

Quoted 7 lines
Quoted 6 lines

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 323

Quoted 3 lines
powerpc/ieee1275/openfw.c +3 -0
+
+      /* XXX Assume partno will only require two bytes? */
+      encoding = grub_malloc (grub_strlen (device) + 5);

Can't you just calculate this? Otherwise you can better allocate a few bytes too much.

Quoted 7 lines

How exactly would you like to calculate what sprintf will do before it does it? We have no snprintf (with "sophisticated" return values), and I don't think it's worth the effort either.

I will change the 5 to an 8 if it makes you happy, though I would be very surprised to see a disk with partitions in even the (base 10) triple digits.

Please do.

--
Marco

#13 lore raw

Re: partition numbering (was: set prefix on PPC)

Quoted 14 lines · Marco Gerards
Quoted 7 lines
Quoted 4 lines

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 320

Quoted 2 lines
powerpc/ieee1275/openfw.c +2 -0
+      unsigned int partno = grub_strtoul (partition, 0, 0);
+      partno--; /* GRUB partition numbering is 0-based.  */

Right. But how can you be sure both match?

Eh? OF partition numbers are 1-based. To convert to GRUB's 0-based numbering, we subtract one. How could that not "match"?

Because not in all cases GRUB and the firmware will count partitions the same way. A good example is the PC partition map. In linux primary partitions are numbers from 1 to 4, extended partitions are numbered from 5 (IIRC). One other way to count these partitions is just by starting counting from 1.

Quoted 4 lines

This is just an example. There are a lot of partition table layouts and many ways to interpret partition numbers. I can imagine GRUB does not always work the same as a specific firmware implementation all the time.

If GRUB counts partition numbers different than Open Firmware, I consider this a bug that must be fixed. 0-based partition numbers are quite confusing enough.

In this case, due to the implicit numbering of Apple partition map entries, this shouldn't even be an issue.

-Hollis

#14 lore raw

Re: partition numbering

Quoted 16 lines · Hollis Blanchard
Quoted 14 lines · Marco Gerards
Quoted 7 lines
Quoted 4 lines

powerpc/ieee1275/openfw.c grub_claimmap (grub_addr_t addr, grub_si · line 320

Quoted 2 lines
powerpc/ieee1275/openfw.c +2 -0
+      unsigned int partno = grub_strtoul (partition, 0, 0);
+      partno--; /* GRUB partition numbering is 0-based.  */

Right. But how can you be sure both match?

Eh? OF partition numbers are 1-based. To convert to GRUB's 0-based numbering, we subtract one. How could that not "match"?

Because not in all cases GRUB and the firmware will count partitions the same way. A good example is the PC partition map. In linux primary partitions are numbers from 1 to 4, extended partitions are numbered from 5 (IIRC). One other way to count these partitions is just by starting counting from 1.

Quoted 8 lines
Quoted 4 lines

This is just an example. There are a lot of partition table layouts and many ways to interpret partition numbers. I can imagine GRUB does not always work the same as a specific firmware implementation all the time.

If GRUB counts partition numbers different than Open Firmware, I consider this a bug that must be fixed. 0-based partition numbers are quite confusing enough.

And I do not consider that a bug. We can not confirm to the way every OS/firmware implementation numbers its partitions. This is *not* about 0-basic partition numbers, but about how the same things can be handled differently. We can adapt to the most popular implementations. But I am sure things will fail someday.

Quoted 2 lines

In this case, due to the implicit numbering of Apple partition map entries, this shouldn't even be an issue.

Right. But this is not always true.

--
Marco

#15 lore raw

Re: partition numbering

Quoted 11 lines · Marco Gerards
Quoted 4 lines · Hollis Blanchard

If GRUB counts partition numbers different than Open Firmware, I consider this a bug that must be fixed. 0-based partition numbers are quite confusing enough.

And I do not consider that a bug. We can not confirm to the way every OS/firmware implementation numbers its partitions. This is *not* about 0-basic partition numbers, but about how the same things can be handled differently. We can adapt to the most popular implementations. But I am sure things will fail someday.

I agree we cannot match OS device names and numbering, though it would make users' lives much happier if we did. Actually, to brainstorm for a minute, what if we could install GRUB with a different device naming scheme per OS? Booting different OSs would then be a problem, but what about making each scheme easily distinguishable? For example, use "(linux:hda3)" or "(bsd:disk1s2)"?

Anyways, GRUB, as a bootloader that uses firmware services, surely must match firmware names and numbering. For example, on x86 you identify disks as "hd0" and "hd1" because this is how the firmware enumerates them.

-Hollis

#16 lore raw

Re: partition numbering

Quoted 14 lines · Hollis Blanchard
Quoted 11 lines · Marco Gerards
Quoted 4 lines · Hollis Blanchard

If GRUB counts partition numbers different than Open Firmware, I consider this a bug that must be fixed. 0-based partition numbers are quite confusing enough.

And I do not consider that a bug. We can not confirm to the way every OS/firmware implementation numbers its partitions. This is *not* about 0-basic partition numbers, but about how the same things can be handled differently. We can adapt to the most popular implementations. But I am sure things will fail someday.

Quoted 6 lines

I agree we cannot match OS device names and numbering, though it would make users' lives much happier if we did. Actually, to brainstorm for a minute, what if we could install GRUB with a different device naming scheme per OS? Booting different OSs would then be a problem, but what about making each scheme easily distinguishable? For example, use "(linux:hda3)" or "(bsd:disk1s2)"?

That is not possible. You can not say hda is the same as hd0. In GRUB on the PC hd0 means the first harddisk as the BIOS sees it AFAIK. On linux hda means the primary master disk on an IDE controller.

I think it is too much work to do this and not worth the effort. And it will cause more problems than convenience. Of course you can write a module that makes it possible what you propose...

Quoted 4 lines

Anyways, GRUB, as a bootloader that uses firmware services, surely must match firmware names and numbering. For example, on x86 you identify disks as "hd0" and "hd1" because this is how the firmware enumerates them.

Not for partitions, as I see it.

--
Marco

#17 lore raw

Re: partition numbering

In reply to Hollis Blanchard
Quoted 4 lines · Hollis Blanchard

Anyways, GRUB, as a bootloader that uses firmware services, surely must match firmware names and numbering. For example, on x86 you identify disks as "hd0" and "hd1" because this is how the firmware enumerates them.

Not true. It counts "128" and "129". The user interface wraps firmware for convenince. The view from GRUB is not always identical to what firmware gives.

What we must respect is what kind of view is convenient for the user, but not how a given firmwqare counts things.

Okuji

#18 lore raw

Re: partition numbering

Quoted 6 lines · Yoshinori K. Okuji
Quoted 4 lines · Hollis Blanchard

Anyways, GRUB, as a bootloader that uses firmware services, surely must match firmware names and numbering. For example, on x86 you identify disks as "hd0" and "hd1" because this is how the firmware enumerates them.

Quoted 6 lines

Not true. It counts "128" and "129". The user interface wraps firmware for convenince. The view from GRUB is not always identical to what firmware gives.

What we must respect is what kind of view is convenient for the user, but not how a given firmwqare counts things.

True, but what I meant is that the device numbers are related to the information as the BIOS gives you and are not related to how the hardware is connected and configured.

--
Marco