ieee1275: obdisk driver
PATCH v3 1/1 ieee1275: obdisk driver
Add a new disk driver called obdisk for IEEE1275 platforms. Currently the only platform using this disk driver is SPARC, however other IEEE1275 platforms could start using it if they so choose. While the functionality within the current IEEE1275 ofdisk driver may be suitable for PPC and x86, it presented too many problems on SPARC hardware.
Within the old ofdisk, there is not a way to determine the true canonical name for the disk. Within Open Boot, the same disk can have multiple names but all reference the same disk. For example the same disk can be referenced by its SAS WWN, using this form:
/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@w5000cca02f037d6d,0
It can also be referenced by its PHY identifier using this form:
/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@p0
It can also be referenced by its Target identifier using this form:
/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@0
Also, when the LUN=0, it is legal to omit the ,0 from the device name. So with the disk above, before taking into account the device aliases, there are 6 ways to reference the same disk.
Then it is possible to have 0 .. n device aliases all representing the same disk. Within this new driver the true canonical name is determined using the the IEEE1275 encode-unit and decode-unit commands when address_cells == 4. This will determine the true single canonical name for the device so multiple ihandles are not opened for the same device. This is what frequently happens with the old ofdisk driver. With some devices when they are opened multiple times it causes the entire system to hang.
Another problem solved with this driver is devices that do not have a device alias can be booted and used within GRUB. Within the old ofdisk, this was not possible, unless it was the original boot device. All devices behind a SAS
or SCSI parent can be found. Within the old ofdisk, finding these disks
relied on there being an alias defined. The alias requirement is not necessary with this new driver. It can also find devices behind a parent after they have been hot-plugged. This is something that is not possible with the old ofdisk driver.
The old ofdisk driver also incorrectly assumes that the device pointing to by a device alias is in its true canonical form. This assumption is never made with this new driver.
Another issue solved with this driver is that it properly caches the ihandle for all open devices. The old ofdisk tries to do this by caching the last opened ihandle. However this does not work properly because the layer above does not use a consistent device name for the same disk when calling into the driver. This is because the upper layer uses the bootpath value returned within /chosen, other times it uses the device alias, and other times it uses the value within grub.cfg. It does not have a way to figure out that these devices are the same disk. This is not a problem with this new driver.
Due to the way GRUB repeatedly opens and closes the same disk. Caching the ihandle is important on SPARC. Without caching, some SAS devices can take 15 - 20 minutes to get to the GRUB menu. This ihandle caching is not possible without correctly having the canonical disk name.
When available, this driver also tries to use the deblocker #blocks and a way of determining the disk size.
Finally and probably most importantly, this new driver is also capable of seeing all partitions on a GPT disk. With the old driver, the GPT partition table can not be read and only the first partition on the disk can be seen.
---
Changes since V2 (all requested in the last review):
Changed all if (x) to if (x != NULL)
Removed static NULL initializations
Removed all code to allow a user to easily retrieve the disk name thru the shell without needing to understand the grub2 escaping policy for disk names with commas. SPARC disks frequently contain commas, figuring this out is now up to the user. Cut and pasting the disk name is no longer possible. Also, this will make automated testing thru the shell extremely difficult.
Changed the order of the functions to escape_commas(), replace_escaped_commas(), and finally count_commas().
Don't assume that grub_ieee1275_get_integer_property() does not touch address_cells if it fails.
Added additional comments where requested.
--- grub-core/Makefile.core.def | 1 + grub-core/commands/nativedisk.c | 1 + grub-core/disk/ieee1275/obdisk.c | 1081 ++++++++++++++++++++++++++++++++++++++ grub-core/kern/ieee1275/cmain.c | 3 + grub-core/kern/ieee1275/init.c | 12 +- include/grub/disk.h | 1 + include/grub/ieee1275/ieee1275.h | 2 + include/grub/ieee1275/obdisk.h | 25 + 8 files changed, 1125 insertions(+), 1 deletions(-) create mode 100644 grub-core/disk/ieee1275/obdisk.c create mode 100644 include/grub/ieee1275/obdisk.h
grub-core/Makefile.core.def +1 -0
@@ -317,6 +317,7 @@ kernel = { sparc64_ieee1275 = kern/sparc64/cache.S; sparc64_ieee1275 = kern/sparc64/dl.c; sparc64_ieee1275 = kern/sparc64/ieee1275/ieee1275.c; + sparc64_ieee1275 = disk/ieee1275/obdisk.c; arm = kern/arm/dl.c; arm = kern/arm/dl_helper.c;
grub-core/commands/nativedisk.c +1 -0
@@ -66,6 +66,7 @@ get_uuid (const char *name, char **uuid, int getnative)/* Firmware disks. */ case GRUB_DISK_DEVICE_BIOSDISK_ID :case GRUB_DISK_DEVICE_OFDISK_ID : +case GRUB_DISK_DEVICE_OBDISK_ID :case GRUB_DISK_DEVICE_EFIDISK_ID :case GRUB_DISK_DEVICE_NAND_ID :case GRUB_DISK_DEVICE_ARCDISK_ID :
grub-core/disk/ieee1275/obdisk.c new file +1081 -0
1,081 lines not on this page · raw message
grub-core/kern/ieee1275/cmain.c +3 -0
@@ -108,6 +108,9 @@ grub_ieee1275_find_options (void)if (rc >=0 ) {char *ptr; + +if (grub_strncmp (tmp,"sun4v" ,5 ) ==0 ) +grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_RAW_DEVNAMES );for (ptr = tmp; ptr - tmp < actual; ptr +=grub_strlen (ptr) +1 ) { if (grub_memcmp (ptr, "MacRISC", sizeof ("MacRISC") - 1) == 0
grub-core/kern/ieee1275/init.c +11 -1
@@ -30,6 +30,9 @@#include <grub/time.h> #include <grub/ieee1275/console.h> #include <grub/ieee1275/ofdisk.h> +#ifdef __sparc__ +#include <grub/ieee1275/obdisk.h> +#endif #include <grub/ieee1275/ieee1275.h> #include <grub/net.h> #include <grub/offsets.h>
@@ -280,8 +283,11 @@ grub_machine_init (void)grub_console_init_early ();grub_claim_heap ();grub_console_init_lately (); +#ifdef __sparc__ +grub_obdisk_init (); +#else grub_ofdisk_init (); - +#endif grub_parse_cmdline ();#ifdef __i386__
@@ -296,7 +302,11 @@ grub_machine_fini (int flags) {if (flags &GRUB_LOADER_FLAG_NORETURN ) { +#ifdef __sparc__ +grub_obdisk_fini (); +#else grub_ofdisk_fini (); +#endif grub_console_fini (); } }
include/grub/disk.h +1 -0
@@ -49,6 +49,7 @@ enum grub_disk_dev_idGRUB_DISK_DEVICE_CBFSDISK_ID ,GRUB_DISK_DEVICE_UBOOTDISK_ID ,GRUB_DISK_DEVICE_XEN , + GRUB_DISK_DEVICE_OBDISK_ID, };struct grub_disk ;
include/grub/ieee1275/ieee1275.h +2 -0
@@ -146,6 +146,8 @@ enum grub_ieee1275_flagGRUB_IEEE1275_FLAG_BROKEN_REPEAT ,GRUB_IEEE1275_FLAG_CURSORONOFF_ANSI_BROKEN , + + GRUB_IEEE1275_FLAG_RAW_DEVNAMES, };extern int EXPORT_FUNC (grub_ieee1275_test_flag ) (enum grub_ieee1275_flag flag);
include/grub/ieee1275/obdisk.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2019 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_OBDISK_HEADER +#define GRUB_OBDISK_HEADER 1 + +extern void grub_obdisk_init (void ); +extern void grub_obdisk_fini (void ); + +#endif
Signature · 1 line
1.7.1
Quoted 63 lines · Eric Snowberg
Add a new disk driver called obdisk for IEEE1275 platforms. Currently the only platform using this disk driver is SPARC, however other IEEE1275 platforms could start using it if they so choose. While the functionality within the current IEEE1275 ofdisk driver may be suitable for PPC and x86, it presented too many problems on SPARC hardware.
Within the old ofdisk, there is not a way to determine the true canonical name for the disk. Within Open Boot, the same disk can have multiple names but all reference the same disk. For example the same disk can be referenced by its SAS WWN, using this form:
/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@w5000cca02f037d6d,0
It can also be referenced by its PHY identifier using this form:
/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@p0
It can also be referenced by its Target identifier using this form:
/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@0
Also, when the LUN=0, it is legal to omit the ,0 from the device name. So with the disk above, before taking into account the device aliases, there are 6 ways to reference the same disk.
Then it is possible to have 0 .. n device aliases all representing the same disk. Within this new driver the true canonical name is determined using the the IEEE1275 encode-unit and decode-unit commands when
address_cells== 4. This will determine the true single canonical name for the device so multiple ihandles are not opened for the same device. This is what frequently happens with the old ofdisk driver. With some devices when they are opened multiple times it causes the entire system to hang.Another problem solved with this driver is devices that do not have a device alias can be booted and used within GRUB. Within the old ofdisk, this was not possible, unless it was the original boot device. All devices behind a SAS
or SCSI parent can be found. Within the old ofdisk, finding these disks
relied on there being an alias defined. The alias requirement is not necessary with this new driver. It can also find devices behind a parent after they have been hot-plugged. This is something that is not possible with the old ofdisk driver.The old ofdisk driver also incorrectly assumes that the device pointing to by a device alias is in its true canonical form. This assumption is never made with this new driver.
Another issue solved with this driver is that it properly caches the ihandle for all open devices. The old ofdisk tries to do this by caching the last opened ihandle. However this does not work properly because the layer above does not use a consistent device name for the same disk when calling into the driver. This is because the upper layer uses the bootpath value returned within /chosen, other times it uses the device alias, and other times it uses the value within grub.cfg. It does not have a way to figure out that these devices are the same disk. This is not a problem with this new driver.
Due to the way GRUB repeatedly opens and closes the same disk. Caching the ihandle is important on SPARC. Without caching, some SAS devices can take 15 - 20 minutes to get to the GRUB menu. This ihandle caching is not possible without correctly having the canonical disk name.
When available, this driver also tries to use the deblocker #blocks and a way of determining the disk size.
Quoted 6 lines
Finally and probably most importantly, this new driver is also capable of seeing all partitions on a GPT disk. With the old driver, the GPT partition table can not be read and only the first partition on the disk can be seen.
Signed-off-by Eric Snowberg <[email protected]>
In the general I am OK with the patch but...
Quoted 14 lines
---
Changes since V2 (all requested in the last review):Changed all if (x) to if (x != NULL)
Removed static NULL initializations
Removed all code to allow a user to easily retrieve the disk name thru the shell without needing to understand the grub2 escaping policy for disk names with commas. SPARC disks frequently contain commas, figuring this out is now up to the user. Cut and pasting the disk name is no longer possible. Also, this will make automated testing thru the shell extremely difficult.
Quoted 2 lines
Changed the order of the functions to
escape_commas(),replace_escaped_commas(), and finallycount_commas().
... I am a bit confused with this. You left escape_commas() and count_commas(). Both are used in encode_grub_devname(). IMO this does not agree with "Removed all code to allow a user to easily retrieve the disk name thru the shell without needing to understand the grub2 escaping policy for disk names with commas." Does it?
Daniel
Quoted 90 lines · Daniel Kiper
Quoted 63 lines · Eric Snowberg
Add a new disk driver called obdisk for IEEE1275 platforms. Currently the only platform using this disk driver is SPARC, however other IEEE1275 platforms could start using it if they so choose. While the functionality within the current IEEE1275 ofdisk driver may be suitable for PPC and x86, it presented too many problems on SPARC hardware.
Within the old ofdisk, there is not a way to determine the true canonical name for the disk. Within Open Boot, the same disk can have multiple names but all reference the same disk. For example the same disk can be referenced by its SAS WWN, using this form:
/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@w5000cca02f037d6d,0
It can also be referenced by its PHY identifier using this form:
/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@p0
It can also be referenced by its Target identifier using this form:
/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@0
Also, when the LUN=0, it is legal to omit the ,0 from the device name. So with the disk above, before taking into account the device aliases, there are 6 ways to reference the same disk.
Then it is possible to have 0 .. n device aliases all representing the same disk. Within this new driver the true canonical name is determined using the the IEEE1275 encode-unit and decode-unit commands when
address_cells== 4. This will determine the true single canonical name for the device so multiple ihandles are not opened for the same device. This is what frequently happens with the old ofdisk driver. With some devices when they are opened multiple times it causes the entire system to hang.Another problem solved with this driver is devices that do not have a device alias can be booted and used within GRUB. Within the old ofdisk, this was not possible, unless it was the original boot device. All devices behind a SAS
or SCSI parent can be found. Within the old ofdisk, finding these disks
relied on there being an alias defined. The alias requirement is not necessary with this new driver. It can also find devices behind a parent after they have been hot-plugged. This is something that is not possible with the old ofdisk driver.The old ofdisk driver also incorrectly assumes that the device pointing to by a device alias is in its true canonical form. This assumption is never made with this new driver.
Another issue solved with this driver is that it properly caches the ihandle for all open devices. The old ofdisk tries to do this by caching the last opened ihandle. However this does not work properly because the layer above does not use a consistent device name for the same disk when calling into the driver. This is because the upper layer uses the bootpath value returned within /chosen, other times it uses the device alias, and other times it uses the value within grub.cfg. It does not have a way to figure out that these devices are the same disk. This is not a problem with this new driver.
Due to the way GRUB repeatedly opens and closes the same disk. Caching the ihandle is important on SPARC. Without caching, some SAS devices can take 15 - 20 minutes to get to the GRUB menu. This ihandle caching is not possible without correctly having the canonical disk name.
When available, this driver also tries to use the deblocker #blocks and a way of determining the disk size.
Quoted 6 lines
Finally and probably most importantly, this new driver is also capable of seeing all partitions on a GPT disk. With the old driver, the GPT partition table can not be read and only the first partition on the disk can be seen.
Signed-off-by Eric Snowberg <[email protected]>In the general I am OK with the patch but...
Quoted 14 lines
---
Changes since V2 (all requested in the last review):Changed all if (x) to if (x != NULL)
Removed static NULL initializations
Removed all code to allow a user to easily retrieve the disk name thru the shell without needing to understand the grub2 escaping policy for disk names with commas. SPARC disks frequently contain commas, figuring this out is now up to the user. Cut and pasting the disk name is no longer possible. Also, this will make automated testing thru the shell extremely difficult.
Quoted 9 lines
Quoted 2 lines
Changed the order of the functions to
escape_commas(),replace_escaped_commas(), and finallycount_commas().... I am a bit confused with this. You left
escape_commas()andcount_commas(). Both are used inencode_grub_devname(). IMO this does not agree with "Removed all code to allow a user to easily retrieve the disk name thru the shell without needing to understand the grub2 escaping policy for disk names with commas." Does it?
The disk enumeration code within this driver retrieves device names. For example it can find all SAS disks in a system. These device names are not in a format understandable by GRUB2. These functions are required for converting a device name OpenFirmware understands to a device name GRUB2 understands. These functions have nothing to do with the code for a user to easily retrieve the disk name thru the shell.
Quoted 98 lines · Eric Snowberg
Quoted 88 lines · Daniel Kiper
Quoted 63 lines · Eric Snowberg
Add a new disk driver called obdisk for IEEE1275 platforms. Currently the only platform using this disk driver is SPARC, however other IEEE1275 platforms could start using it if they so choose. While the functionality within the current IEEE1275 ofdisk driver may be suitable for PPC and x86, it presented too many problems on SPARC hardware.
Within the old ofdisk, there is not a way to determine the true canonical name for the disk. Within Open Boot, the same disk can have multiple names but all reference the same disk. For example the same disk can be referenced by its SAS WWN, using this form:
/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@w5000cca02f037d6d,0
It can also be referenced by its PHY identifier using this form:
/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@p0
It can also be referenced by its Target identifier using this form:
/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@0
Also, when the LUN=0, it is legal to omit the ,0 from the device name. So with the disk above, before taking into account the device aliases, there are 6 ways to reference the same disk.
Then it is possible to have 0 .. n device aliases all representing the same disk. Within this new driver the true canonical name is determined using the the IEEE1275 encode-unit and decode-unit commands when
address_cells== 4. This will determine the true single canonical name for the device so multiple ihandles are not opened for the same device. This is what frequently happens with the old ofdisk driver. With some devices when they are opened multiple times it causes the entire system to hang.Another problem solved with this driver is devices that do not have a device alias can be booted and used within GRUB. Within the old ofdisk, this was not possible, unless it was the original boot device. All devices behind a SAS
or SCSI parent can be found. Within the old ofdisk, finding these disks
relied on there being an alias defined. The alias requirement is not necessary with this new driver. It can also find devices behind a parent after they have been hot-plugged. This is something that is not possible with the old ofdisk driver.The old ofdisk driver also incorrectly assumes that the device pointing to by a device alias is in its true canonical form. This assumption is never made with this new driver.
Another issue solved with this driver is that it properly caches the ihandle for all open devices. The old ofdisk tries to do this by caching the last opened ihandle. However this does not work properly because the layer above does not use a consistent device name for the same disk when calling into the driver. This is because the upper layer uses the bootpath value returned within /chosen, other times it uses the device alias, and other times it uses the value within grub.cfg. It does not have a way to figure out that these devices are the same disk. This is not a problem with this new driver.
Due to the way GRUB repeatedly opens and closes the same disk. Caching the ihandle is important on SPARC. Without caching, some SAS devices can take 15 - 20 minutes to get to the GRUB menu. This ihandle caching is not possible without correctly having the canonical disk name.
When available, this driver also tries to use the deblocker #blocks and a way of determining the disk size.
Quoted 6 lines
Finally and probably most importantly, this new driver is also capable of seeing all partitions on a GPT disk. With the old driver, the GPT partition table can not be read and only the first partition on the disk can be seen.
Signed-off-by Eric Snowberg <[email protected]>In the general I am OK with the patch but...
Quoted 14 lines
---
Changes since V2 (all requested in the last review):Changed all if (x) to if (x != NULL)
Removed static NULL initializations
Removed all code to allow a user to easily retrieve the disk name thru the shell without needing to understand the grub2 escaping policy for disk names with commas. SPARC disks frequently contain commas, figuring this out is now up to the user. Cut and pasting the disk name is no longer possible. Also, this will make automated testing thru the shell extremely difficult.
Quoted 9 lines
Quoted 2 lines
Changed the order of the functions to
escape_commas(),replace_escaped_commas(), and finallycount_commas().... I am a bit confused with this. You left
escape_commas()andcount_commas(). Both are used inencode_grub_devname(). IMO this does not agree with "Removed all code to allow a user to easily retrieve the disk name thru the shell without needing to understand the grub2 escaping policy for disk names with commas." Does it?
Quoted 6 lines
The disk enumeration code within this driver retrieves device names. For example it can find all SAS disks in a system. These device names are not in a format understandable by GRUB2. These functions are required for converting a device name OpenFirmware understands to a device name GRUB2 understands. These functions have nothing to do with the code for a user to easily retrieve the disk name thru the shell.
OK, thanks. Then Reviewed-by: Daniel Kiper <[email protected]>
If there are no objections I will apply this patch next week.
Thank you for doing the work.
Daniel
Quoted 5 lines · Daniel Kiper
OK, thanks. Then Reviewed-by: Daniel Kiper <[email protected]>
If there are no objections I will apply this patch next week.
Thank you for doing the work.
Yay, awesome \o/.
@Eric: What do you think about my patch to write the a.out header manually?
See: http://lists.gnu.org/archive/html/grub-devel/2019-02/msg00084.html
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913