u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/3] efi: Add debugging to efi_set_bootdev()
@ 2022-01-29 21:58 Simon Glass
  2022-01-29 21:58 ` [PATCH v2 2/3] efi: Use device_get_uclass_id() where appropriate Simon Glass
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Simon Glass @ 2022-01-29 21:58 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Heinrich Schuchardt, Simon Glass, Alexander Graf

The operation of this function can be confusing. Add some debugging so
we can see what it is doing and when it is called.

Also drop the preprocessor usage.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Update one of the debug messages

 cmd/bootefi.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 3a8b2b60618..94d18ca73fa 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -65,6 +65,9 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
 	struct efi_device_path *device, *image;
 	efi_status_t ret;
 
+	log_debug("dev=%s, devnr=%s, path=%s, buffer=%p, size=%zx\n", dev,
+		  devnr, path, buffer, buffer_size);
+
 	/* Forget overwritten image */
 	if (buffer + buffer_size >= image_addr &&
 	    image_addr + image_size >= buffer)
@@ -72,18 +75,19 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
 
 	/* Remember only PE-COFF and FIT images */
 	if (efi_check_pe(buffer, buffer_size, NULL) != EFI_SUCCESS) {
-#ifdef CONFIG_FIT
-		if (fit_check_format(buffer, IMAGE_SIZE_INVAL))
+		if (IS_ENABLED(CONFIG_FIT) &&
+		    !fit_check_format(buffer, IMAGE_SIZE_INVAL)) {
+			/*
+			 * FIT images of type EFI_OS are started via command
+			 * bootm. We should not use their boot device with the
+			 * bootefi command.
+			 */
+			buffer = 0;
+			buffer_size = 0;
+		} else {
+			log_debug("- not remembering image\n");
 			return;
-		/*
-		 * FIT images of type EFI_OS are started via command bootm.
-		 * We should not use their boot device with the bootefi command.
-		 */
-		buffer = 0;
-		buffer_size = 0;
-#else
-		return;
-#endif
+		}
 	}
 
 	/* efi_set_bootdev() is typically called repeatedly, recover memory */
@@ -103,7 +107,11 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
 			efi_free_pool(image_tmp);
 		}
 		bootefi_image_path = image;
+		log_debug("- recorded device %ls\n", efi_dp_str(device));
+		if (image)
+			log_debug("- and image %ls\n", efi_dp_str(image));
 	} else {
+		log_debug("- efi_dp_from_name() failed, err=%lx\n", ret);
 		efi_clear_bootdev();
 	}
 }
@@ -451,6 +459,7 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size)
 	u16 *load_options;
 
 	if (!bootefi_device_path || !bootefi_image_path) {
+		log_debug("Not loaded from disk\n");
 		/*
 		 * Special case for efi payload not loaded from disk,
 		 * such as 'bootefi hello' or for example payload
@@ -476,6 +485,7 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size)
 		file_path = efi_dp_append(bootefi_device_path,
 					  bootefi_image_path);
 		msg_path = bootefi_image_path;
+		log_debug("Loaded from disk\n");
 	}
 
 	log_info("Booting %pD\n", msg_path);
-- 
2.35.0.rc2.247.g8bbb082509-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] efi: Use device_get_uclass_id() where appropriate
  2022-01-29 21:58 [PATCH v2 1/3] efi: Add debugging to efi_set_bootdev() Simon Glass
@ 2022-01-29 21:58 ` Simon Glass
  2022-02-05  8:25   ` Heinrich Schuchardt
  2022-01-29 21:58 ` [PATCH v2 3/3] efi: Drop unnecessary calls to blk_find_device() Simon Glass
  2022-02-05  8:23 ` [PATCH v2 1/3] efi: Add debugging to efi_set_bootdev() Heinrich Schuchardt
  2 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2022-01-29 21:58 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Heinrich Schuchardt, Simon Glass, Alexander Graf

Use this function rather than following the pointers, since it is there
for this purpose.

Add the uclass name to the debug call at the end of dp_fill() since it is
quite useful.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Drop the uclass id

 lib/efi_loader/efi_device_path.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index c61f4859330..75ab4de7070 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -494,7 +494,7 @@ __maybe_unused static unsigned int dp_size(struct udevice *dev)
 	if (!dev || !dev->driver)
 		return sizeof(ROOT);
 
-	switch (dev->driver->id) {
+	switch (device_get_uclass_id(dev)) {
 	case UCLASS_ROOT:
 	case UCLASS_SIMPLE_BUS:
 		/* stop traversing parents at this point: */
@@ -579,7 +579,7 @@ __maybe_unused static void *dp_fill(void *buf, struct udevice *dev)
 	if (!dev || !dev->driver)
 		return buf;
 
-	switch (dev->driver->id) {
+	switch (device_get_uclass_id(dev)) {
 	case UCLASS_ROOT:
 	case UCLASS_SIMPLE_BUS: {
 		/* stop traversing parents at this point: */
@@ -759,9 +759,9 @@ __maybe_unused static void *dp_fill(void *buf, struct udevice *dev)
 		return &udp[1];
 	}
 	default:
-		debug("%s(%u) %s: unhandled device class: %s (%u)\n",
-		      __FILE__, __LINE__, __func__,
-		      dev->name, dev->driver->id);
+		/* If the uclass driver is missing, this will show NULL */
+		log_debug("unhandled device class: %s (%s)\n", dev->name,
+			  dev_get_uclass_name(dev));
 		return dp_fill(buf, dev->parent);
 	}
 }
-- 
2.35.0.rc2.247.g8bbb082509-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] efi: Drop unnecessary calls to blk_find_device()
  2022-01-29 21:58 [PATCH v2 1/3] efi: Add debugging to efi_set_bootdev() Simon Glass
  2022-01-29 21:58 ` [PATCH v2 2/3] efi: Use device_get_uclass_id() where appropriate Simon Glass
@ 2022-01-29 21:58 ` Simon Glass
  2022-02-05  8:26   ` Heinrich Schuchardt
  2022-02-05  8:23 ` [PATCH v2 1/3] efi: Add debugging to efi_set_bootdev() Heinrich Schuchardt
  2 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2022-01-29 21:58 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Heinrich Schuchardt, Simon Glass, Alexander Graf

When we have the block descriptor we can simply access the device. Drop
the unnecessary function call.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 lib/efi_loader/efi_device_path.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index 75ab4de7070..dc787b4d3dd 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -769,13 +769,8 @@ __maybe_unused static void *dp_fill(void *buf, struct udevice *dev)
 static unsigned dp_part_size(struct blk_desc *desc, int part)
 {
 	unsigned dpsize;
-	struct udevice *dev;
-	int ret;
+	struct udevice *dev = desc->bdev;
 
-	ret = blk_find_device(desc->if_type, desc->devnum, &dev);
-
-	if (ret)
-		dev = desc->bdev->parent;
 	dpsize = dp_size(dev);
 
 	if (part == 0) /* the actual disk, not a partition */
@@ -866,13 +861,8 @@ static void *dp_part_node(void *buf, struct blk_desc *desc, int part)
  */
 static void *dp_part_fill(void *buf, struct blk_desc *desc, int part)
 {
-	struct udevice *dev;
-	int ret;
-
-	ret = blk_find_device(desc->if_type, desc->devnum, &dev);
+	struct udevice *dev = desc->bdev;
 
-	if (ret)
-		dev = desc->bdev->parent;
 	buf = dp_fill(buf, dev);
 
 	if (part == 0) /* the actual disk, not a partition */
-- 
2.35.0.rc2.247.g8bbb082509-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/3] efi: Add debugging to efi_set_bootdev()
  2022-01-29 21:58 [PATCH v2 1/3] efi: Add debugging to efi_set_bootdev() Simon Glass
  2022-01-29 21:58 ` [PATCH v2 2/3] efi: Use device_get_uclass_id() where appropriate Simon Glass
  2022-01-29 21:58 ` [PATCH v2 3/3] efi: Drop unnecessary calls to blk_find_device() Simon Glass
@ 2022-02-05  8:23 ` Heinrich Schuchardt
  2 siblings, 0 replies; 6+ messages in thread
From: Heinrich Schuchardt @ 2022-02-05  8:23 UTC (permalink / raw)
  To: Simon Glass, U-Boot Mailing List; +Cc: Alexander Graf

On 1/29/22 22:58, Simon Glass wrote:
> The operation of this function can be confusing. Add some debugging so
> we can see what it is doing and when it is called.
>
> Also drop the preprocessor usage.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: heinrich Schuchardt <xypron.glpk@gmx.de>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/3] efi: Use device_get_uclass_id() where appropriate
  2022-01-29 21:58 ` [PATCH v2 2/3] efi: Use device_get_uclass_id() where appropriate Simon Glass
@ 2022-02-05  8:25   ` Heinrich Schuchardt
  0 siblings, 0 replies; 6+ messages in thread
From: Heinrich Schuchardt @ 2022-02-05  8:25 UTC (permalink / raw)
  To: Simon Glass, U-Boot Mailing List; +Cc: Alexander Graf

On 1/29/22 22:58, Simon Glass wrote:
> Use this function rather than following the pointers, since it is there
> for this purpose.
>
> Add the uclass name to the debug call at the end of dp_fill() since it is
> quite useful.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 3/3] efi: Drop unnecessary calls to blk_find_device()
  2022-01-29 21:58 ` [PATCH v2 3/3] efi: Drop unnecessary calls to blk_find_device() Simon Glass
@ 2022-02-05  8:26   ` Heinrich Schuchardt
  0 siblings, 0 replies; 6+ messages in thread
From: Heinrich Schuchardt @ 2022-02-05  8:26 UTC (permalink / raw)
  To: Simon Glass, U-Boot Mailing List; +Cc: Heinrich Schuchardt, Alexander Graf

On 1/29/22 22:58, Simon Glass wrote:
> When we have the block descriptor we can simply access the device. Drop
> the unnecessary function call.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-02-05  8:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-29 21:58 [PATCH v2 1/3] efi: Add debugging to efi_set_bootdev() Simon Glass
2022-01-29 21:58 ` [PATCH v2 2/3] efi: Use device_get_uclass_id() where appropriate Simon Glass
2022-02-05  8:25   ` Heinrich Schuchardt
2022-01-29 21:58 ` [PATCH v2 3/3] efi: Drop unnecessary calls to blk_find_device() Simon Glass
2022-02-05  8:26   ` Heinrich Schuchardt
2022-02-05  8:23 ` [PATCH v2 1/3] efi: Add debugging to efi_set_bootdev() Heinrich Schuchardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).