[PATCH v2] bootstd: Tidy up reporting of errors

Simon Glass sjg at chromium.org
Thu May 11 00:34:26 CEST 2023


In a few cases the error handling is not quite right. Make sure we
return the actual error in distro_efi_read_bootflow_file() rather than
-EINVAL. Return -IO when a file cannot be read. Also show the error name
if available.

This does not change operation, but does make it easier to diagnose
problems.

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

Changes in v2:
- Update affected tests too

 boot/bootmeth-uclass.c |  2 +-
 boot/bootmeth_efi.c    |  2 +-
 cmd/bootflow.c         |  2 +-
 test/boot/bootflow.c   | 10 +++++-----
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c
index 2aee1e0f0c5..3b3e0614daf 100644
--- a/boot/bootmeth-uclass.c
+++ b/boot/bootmeth-uclass.c
@@ -319,7 +319,7 @@ static int alloc_file(const char *fname, uint size, void **bufp)
 		return log_msg_ret("read", ret);
 	}
 	if (size != bytes_read)
-		return log_msg_ret("bread", -EINVAL);
+		return log_msg_ret("bread", -EIO);
 	buf[size] = '\0';
 
 	*bufp = buf;
diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c
index 6f70f2229b9..af31fbfc85d 100644
--- a/boot/bootmeth_efi.c
+++ b/boot/bootmeth_efi.c
@@ -235,7 +235,7 @@ static int distro_efi_read_bootflow_file(struct udevice *dev,
 
 	ret = efiload_read_file(desc, bflow);
 	if (ret)
-		return log_msg_ret("read", -EINVAL);
+		return log_msg_ret("read", ret);
 
 	fdt_addr = env_get_hex("fdt_addr_r", 0);
 
diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index 6cc58e48c7d..5c61286a2a7 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -55,7 +55,7 @@ static void report_bootflow_err(struct bootflow *bflow, int err)
 		break;
 	}
 
-	printf(", err=%d\n", err);
+	printf(", err=%dE\n", err);
 }
 
 /**
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index fd0e1d62435..bb53bab0c0c 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -168,21 +168,21 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts)
 	ut_assert_nextlinen("---");
 	ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
 	ut_assert_nextline("  0  syslinux     media   mmc          0  mmc2.bootdev.whole        <NULL>");
-	ut_assert_nextline("     ** No partition found, err=-93");
+	ut_assert_nextline("     ** No partition found, err=-93: Protocol not supported");
 	ut_assert_nextline("  1  efi          media   mmc          0  mmc2.bootdev.whole        <NULL>");
-	ut_assert_nextline("     ** No partition found, err=-93");
+	ut_assert_nextline("     ** No partition found, err=-93: Protocol not supported");
 
 	ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
 	ut_assert_nextline("  2  syslinux     media   mmc          0  mmc1.bootdev.whole        <NULL>");
-	ut_assert_nextline("     ** No partition found, err=-2");
+	ut_assert_nextline("     ** No partition found, err=-2: No such file or directory");
 	ut_assert_nextline("  3  efi          media   mmc          0  mmc1.bootdev.whole        <NULL>");
-	ut_assert_nextline("     ** No partition found, err=-2");
+	ut_assert_nextline("     ** No partition found, err=-2: No such file or directory");
 	ut_assert_nextline("  4  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
 	ut_assert_nextline("  5  efi          fs      mmc          1  mmc1.bootdev.part_1       efi/boot/bootsbox.efi");
 
 	ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':");
 	ut_assert_skip_to_line(" 3f  efi          media   mmc          0  mmc0.bootdev.whole        <NULL>");
-	ut_assert_nextline("     ** No partition found, err=-93");
+	ut_assert_nextline("     ** No partition found, err=-93: Protocol not supported");
 	ut_assert_nextline("No more bootdevs");
 	ut_assert_nextlinen("---");
 	ut_assert_nextline("(64 bootflows, 1 valid)");
-- 
2.40.1.521.gf1e218fcd8-goog



More information about the U-Boot mailing list