All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] efi_loader: disk: Fix CONFIG_BLK breakage
Date: Fri,  5 Aug 2016 14:49:53 +0200	[thread overview]
Message-ID: <1470401393-3399-1-git-send-email-agraf@suse.de> (raw)

When using CONFIG_BLK, there were 2 issues:

  1) The name we generate the device with has to match the
     name we set in efi_set_bootdev()

  2) The device we pass into our block functions was wrong,
     we should not rediscover it but just use the already known
     pointer.

This patch fixes both issues.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 cmd/bootefi.c             | 23 ++++++++++++++++++-----
 lib/efi_loader/efi_disk.c | 18 +++++++++++-------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index b8ecf4c..53a6ee3 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -8,6 +8,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <dm/device.h>
 #include <efi_loader.h>
 #include <errno.h>
 #include <libfdt.h>
@@ -269,18 +270,30 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path)
 	char devname[32] = { 0 }; /* dp->str is u16[32] long */
 	char *colon;
 
-	/* Assemble the condensed device name we use in efi_disk.c */
-	snprintf(devname, sizeof(devname), "%s%s", dev, devnr);
+#if defined(CONFIG_BLK) || defined(CONFIG_ISO_PARTITION)
+	desc = blk_get_dev(dev, simple_strtol(devnr, NULL, 10));
+#endif
+
+#ifdef CONFIG_BLK
+	if (desc) {
+		snprintf(devname, sizeof(devname), "%s", desc->bdev->name);
+	} else
+#endif
+
+	{
+		/* Assemble the condensed device name we use in efi_disk.c */
+		snprintf(devname, sizeof(devname), "%s%s", dev, devnr);
+	}
+
 	colon = strchr(devname, ':');
 
 #ifdef CONFIG_ISO_PARTITION
 	/* For ISOs we create partition block devices */
-	desc = blk_get_dev(dev, simple_strtol(devnr, NULL, 10));
 	if (desc && (desc->type != DEV_TYPE_UNKNOWN) &&
 	    (desc->part_type == PART_TYPE_ISO)) {
 		if (!colon)
-			snprintf(devname, sizeof(devname), "%s%s:1", dev,
-				 devnr);
+			snprintf(devname, sizeof(devname), "%s:1", devname);
+
 		colon = NULL;
 	}
 #endif
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index c434c92..e00a747 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -31,6 +31,8 @@ struct efi_disk_obj {
 	struct efi_device_path_file_path *dp;
 	/* Offset into disk for simple partitions */
 	lbaint_t offset;
+	/* Internal block device */
+	const struct blk_desc *desc;
 };
 
 static efi_status_t efi_disk_open_block(void *handle, efi_guid_t *protocol,
@@ -78,8 +80,7 @@ static efi_status_t EFIAPI efi_disk_rw_blocks(struct efi_block_io *this,
 	unsigned long n;
 
 	diskobj = container_of(this, struct efi_disk_obj, ops);
-	if (!(desc = blk_get_dev(diskobj->ifname, diskobj->dev_index)))
-		return EFI_EXIT(EFI_DEVICE_ERROR);
+	desc = (struct blk_desc *) diskobj->desc;
 	blksz = desc->blksz;
 	blocks = buffer_size / blksz;
 	lba += diskobj->offset;
@@ -213,6 +214,7 @@ static void efi_disk_add_dev(const char *name,
 	diskobj->ifname = if_typename;
 	diskobj->dev_index = dev_index;
 	diskobj->offset = offset;
+	diskobj->desc = desc;
 
 	/* Fill in EFI IO Media info (for read/write callbacks) */
 	diskobj->media.removable_media = desc->removable;
@@ -240,7 +242,8 @@ static void efi_disk_add_dev(const char *name,
 
 static int efi_disk_create_eltorito(struct blk_desc *desc,
 				    const char *if_typename,
-				    int diskid)
+				    int diskid,
+				    const char *pdevname)
 {
 	int disks = 0;
 #ifdef CONFIG_ISO_PARTITION
@@ -252,8 +255,8 @@ static int efi_disk_create_eltorito(struct blk_desc *desc,
 		return 0;
 
 	while (!part_get_info(desc, part, &info)) {
-		snprintf(devname, sizeof(devname), "%s%d:%d", if_typename,
-			 diskid, part);
+		snprintf(devname, sizeof(devname), "%s:%d", pdevname,
+			 part);
 		efi_disk_add_dev(devname, if_typename, desc, diskid,
 				 info.start);
 		part++;
@@ -296,7 +299,7 @@ int efi_disk_register(void)
 		* so let's create them here
 		*/
 		disks += efi_disk_create_eltorito(desc, if_typename,
-						  desc->devnum);
+						  desc->devnum, dev->name);
 	}
 #else
 	int i, if_type;
@@ -331,7 +334,8 @@ int efi_disk_register(void)
 			 * El Torito images show up as block devices
 			 * in an EFI world, so let's create them here
 			 */
-			disks += efi_disk_create_eltorito(desc, if_typename, i);
+			disks += efi_disk_create_eltorito(desc, if_typename,
+							  i, devname);
 		}
 	}
 #endif
-- 
2.6.6

             reply	other threads:[~2016-08-05 12:49 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-05 12:49 Alexander Graf [this message]
2016-08-08 21:44 ` [U-Boot] [PATCH] efi_loader: disk: Fix CONFIG_BLK breakage Simon Glass
2016-08-10  1:43   ` Tom Rini
2016-08-10  7:47   ` Alexander Graf
2016-08-10 12:56     ` Simon Glass
2016-08-10 13:02       ` Alexander Graf
2016-08-10 13:16         ` Simon Glass
2016-08-10 13:25           ` Alexander Graf
2016-08-10 13:33             ` Simon Glass
2016-08-10 13:41               ` Alexander Graf
2016-08-10 13:47                 ` Simon Glass
2016-08-10 16:25             ` Tom Rini
2016-08-10 19:01               ` Alexander Graf
2016-08-12 17:20                 ` Simon Glass
2016-08-12 18:19                   ` Alexander Graf
2016-08-19 18:14                     ` Tom Rini
2016-08-22  4:22                       ` Alexander Graf
2016-08-22 15:56                         ` Tom Rini
2016-08-10  0:46 ` [U-Boot] " Tom Rini

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=1470401393-3399-1-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

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

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