From ca74c50c0bf5be773f645234daf22e740b844889 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 23 Dec 2011 18:46:06 +0100 Subject: [PATCH 1/6] merge mainline into hints --- grub-core/disk/ieee1275/ofdisk.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index 2cd43d80a..b4a8d969c 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -198,8 +198,14 @@ grub_ofdisk_iterate (int (*hook) (const char *name), if (grub_strncmp (ent->shortest, "cdrom", 5) == 0) continue; - if (hook (ent->shortest)) - return 1; + { + char buffer[sizeof ("ieee1275/") + grub_strlen (env->shortest)]; + char *ptr; + ptr = grub_stpcpy (buffer, "ieee1275/"); + grub_strcpy (ptr, env->shortest); + if (hook (buffer)) + return 1; + } } } return 0; @@ -241,7 +247,10 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) char prop[64]; grub_ssize_t actual; - devpath = compute_dev_path (name); + if (grub_strncmp (devpath, "ieee1275/", sizeof ("ieee1275/") - 1) != 0) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "not IEEE1275 device"); + devpath = compute_dev_path (name + sizeof ("ieee1275/") - 1); if (! devpath) return grub_errno; From 9197b0ade5b9e1a923122ab8aa51a941ee3bd15b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 24 Dec 2011 02:40:18 +0100 Subject: [PATCH 2/6] * grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Add ieee1275/ prefix. (grub_ofdisk_open): Check and discard ieee1275 prefix. * grub-core/kern/ieee1275/openfw.c (grub_ieee1275_encode_devname): Add ieee1275 prefix. --- ChangeLog | 8 ++++++++ grub-core/disk/ieee1275/ofdisk.c | 6 +++--- grub-core/kern/ieee1275/openfw.c | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8a409fabc..8c4a5b468 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-12-24 Vladimir Serbinenko + + * grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Add ieee1275/ + prefix. + (grub_ofdisk_open): Check and discard ieee1275 prefix. + * grub-core/kern/ieee1275/openfw.c (grub_ieee1275_encode_devname): + Add ieee1275 prefix. + 2011-12-23 Vladimir Serbinenko * docs/grub.texi (Filesystems): Update. diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index b4a8d969c..0cbeab802 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -199,10 +199,10 @@ grub_ofdisk_iterate (int (*hook) (const char *name), continue; { - char buffer[sizeof ("ieee1275/") + grub_strlen (env->shortest)]; + char buffer[sizeof ("ieee1275/") + grub_strlen (ent->shortest)]; char *ptr; ptr = grub_stpcpy (buffer, "ieee1275/"); - grub_strcpy (ptr, env->shortest); + grub_strcpy (ptr, ent->shortest); if (hook (buffer)) return 1; } @@ -247,7 +247,7 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) char prop[64]; grub_ssize_t actual; - if (grub_strncmp (devpath, "ieee1275/", sizeof ("ieee1275/") - 1) != 0) + if (grub_strncmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) != 0) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not IEEE1275 device"); devpath = compute_dev_path (name + sizeof ("ieee1275/") - 1); diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index ee81b4ef9..a063cfe63 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -446,7 +446,7 @@ grub_ieee1275_encode_devname (const char *path) /* GRUB partition 1 is OF partition 0. */ partno++; - encoding = grub_xasprintf ("%s,%d", device, partno); + encoding = grub_xasprintf ("ieee1275/%s,%d", device, partno); } else encoding = grub_strdup (device); From 379586ad7d3093379d6543edb2607b8dcf1c37df Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 24 Dec 2011 02:43:21 +0100 Subject: [PATCH 3/6] * grub-core/kern/disk.c (grub_disk_read): Fix hook calling for unaligned segments. --- ChangeLog | 5 +++++ grub-core/kern/disk.c | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c4a5b468..18f6778c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-12-24 Vladimir Serbinenko + + * grub-core/kern/disk.c (grub_disk_read): Fix hook calling for + unaligned segments. + 2011-12-24 Vladimir Serbinenko * grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Add ieee1275/ diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index 460d8778f..fb9782ff9 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -607,12 +607,13 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, while (l) { - (disk->read_hook) (s, o, - ((l > GRUB_DISK_SECTOR_SIZE) - ? GRUB_DISK_SECTOR_SIZE - : l)); + grub_size_t cl; + cl = GRUB_DISK_SECTOR_SIZE - o; + if (cl > l) + cl = l; + (disk->read_hook) (s, o, cl); s++; - l -= GRUB_DISK_SECTOR_SIZE - o; + l -= cl; o = 0; } } From ce4a999d4d84d02cce50d74e498a4faca73ce2c2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 24 Dec 2011 02:45:17 +0100 Subject: [PATCH 4/6] * grub-core/kern/ieee1275/openfw.c (grub_devalias_iterate): Fix allocation and zero-setting. (grub_ieee1275_get_devname): Check that alias is complete. --- ChangeLog | 6 ++++++ grub-core/kern/ieee1275/openfw.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 18f6778c5..f62a3a11b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-12-24 Vladimir Serbinenko + + * grub-core/kern/ieee1275/openfw.c (grub_devalias_iterate): Fix + allocation and zero-setting. + (grub_ieee1275_get_devname): Check that alias is complete. + 2011-12-24 Vladimir Serbinenko * grub-core/kern/disk.c (grub_disk_read): Fix hook calling for diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index a063cfe63..2c081e57d 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -164,7 +164,7 @@ grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias)) strings, so we will add a NULL byte at the end explicitly. */ pathlen += 1; - devpath = grub_malloc (pathlen); + devpath = grub_malloc (pathlen + 1); if (! devpath) { grub_free (devtype); @@ -173,12 +173,15 @@ grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias)) } if (grub_ieee1275_get_property (aliases, aliasname, devpath, pathlen, - &actual)) + &actual) || actual < 0) { grub_dprintf ("devalias", "get_property (%s) failed\n", aliasname); goto nextprop; } - devpath [actual] = '\0'; + if (actual > pathlen) + actual = pathlen; + devpath[actual] = '\0'; + devpath[pathlen] = '\0'; if (grub_ieee1275_finddevice (devpath, &dev)) { @@ -294,7 +297,8 @@ grub_ieee1275_get_devname (const char *path) int match_alias (struct grub_ieee1275_devalias *curalias) { /* briQ firmware can change capitalization in /chosen/bootpath. */ - if (! grub_strncasecmp (curalias->path, path, pathlen)) + if (grub_strncasecmp (curalias->path, path, pathlen) == 0 + && curalias->path[pathlen] == 0) { newpath = grub_strdup (curalias->name); return 1; From 165099ea423194e279f1832ccf3980aaca804320 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 24 Dec 2011 02:46:47 +0100 Subject: [PATCH 5/6] * util/ieee1275/ofpath.c (of_path_of_ide): Fix address for secondary channel. --- ChangeLog | 5 +++++ util/ieee1275/ofpath.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f62a3a11b..15ce35207 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-12-24 Vladimir Serbinenko + + * util/ieee1275/ofpath.c (of_path_of_ide): Fix address for secondary + channel. + 2011-12-24 Vladimir Serbinenko * grub-core/kern/ieee1275/openfw.c (grub_devalias_iterate): Fix diff --git a/util/ieee1275/ofpath.c b/util/ieee1275/ofpath.c index 20a571191..dc16bfde9 100644 --- a/util/ieee1275/ofpath.c +++ b/util/ieee1275/ofpath.c @@ -233,7 +233,7 @@ of_path_of_ide(char *of_path, p = get_basename (sysfs_path); sscanf(p, "%d.%d", &chan, &devno); - __of_path_common(of_path, sysfs_path, device, devno); + __of_path_common(of_path, sysfs_path, device, 2 * chan + devno); free (sysfs_path); } From e77e325f6f9ea8c3d4e777ed010e8e021d486abc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 24 Dec 2011 02:50:30 +0100 Subject: [PATCH 6/6] * util/grub-install.in: Account for possible escaped comma in device name. --- ChangeLog | 5 +++++ util/grub-install.in | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15ce35207..529ab3d71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-12-24 Vladimir Serbinenko + + * util/grub-install.in: Account for possible escaped comma in device + name. + 2011-12-24 Vladimir Serbinenko * util/ieee1275/ofpath.c (of_path_of_ide): Fix address for secondary diff --git a/util/grub-install.in b/util/grub-install.in index ea8699a44..78a7fed74 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -538,13 +538,13 @@ if [ "x${devabstraction_module}" = "x" ] ; then else install_drive="`"$grub_probe" --device-map="${device_map}" --target=drive --device "${install_device}"`" || exit 1 fi - install_drive="`echo "${install_drive}" | sed -e s/,[a-z0-9,]*//g`" + install_drive="`echo "${install_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\1/'`" fi grub_drive="`"$grub_probe" --device-map="${device_map}" --target=drive --device "${grub_device}"`" || exit 1 # Strip partition number - grub_partition="`echo "${grub_drive}" | sed -e 's/^[^,]*[,)]//; s/)$//'`" - grub_drive="`echo "${grub_drive}" | sed -e s/,[a-z0-9,]*//g`" + grub_partition="`echo "${grub_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\3/'`" + grub_drive="`echo "${grub_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\1/'`" if ([ "x$disk_module" != x ] && [ "x$disk_module" != xbiosdisk ]) || [ "x${grub_drive}" != "x${install_drive}" ] || ([ "x$platform" != xefi ] && [ "x$platform" != xpc ] && [ x"${platform}" != x"ieee1275" ]); then # generic method (used on coreboot and ata mod) uuid="`"$grub_probe" --device-map="${device_map}" --target=fs_uuid --device "${grub_device}"`" @@ -569,7 +569,8 @@ if [ "x${devabstraction_module}" = "x" ] ; then if [ x"$grub_partition" = x ]; then prefix_drive="()" else - prefix_drive="(,$grub_partition)" + # Comma is already there + prefix_drive="($grub_partition)" fi fi else