mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master 1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported()
@ 2026-08-26  9:36 Ahmad Fatoum
  2026-08-26  9:36 ` [PATCH master 2/4] efi: loader: fix sign of the error passed to ERR_PTR() Ahmad Fatoum
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2026-08-26  9:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The return values of efi_set_variable_int() are efi_status_t, i.e. 64-bit
on 64-bit targets with the error bit in the topmost bit. Collecting them
in an int drops that bit, so the value returned to
efi_init_runtime_supported() is a small positive number that no longer
identifies an EFI error: EFI_OUT_OF_RESOURCES arrives as 9.

Callers only compared against EFI_SUCCESS so far, which happens to still
work, but the status is worth printing and the next commit does so.

Assisted-by: Claude:opus-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/loader/efi_var_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/efi/loader/efi_var_file.c b/efi/loader/efi_var_file.c
index 12543bce2851..fbafd901bd0c 100644
--- a/efi/loader/efi_var_file.c
+++ b/efi/loader/efi_var_file.c
@@ -191,8 +191,8 @@ efi_status_t efi_var_from_file(int dirfd, const char *filename)
 
 efi_status_t efi_init_runtime_variable_supported(void)
 {
+	efi_status_t ret;
 	u8 s = 0;
-	int ret;
 
 	if (!IS_ENABLED(CONFIG_EFI_RT_VOLATILE_STORE))
 		return EFI_SUCCESS;
-- 
2.47.3




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

* [PATCH master 2/4] efi: loader: fix sign of the error passed to ERR_PTR()
  2026-08-26  9:36 [PATCH master 1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported() Ahmad Fatoum
@ 2026-08-26  9:36 ` Ahmad Fatoum
  2026-08-26  9:36 ` [PATCH master 3/4] efi: loader: disk: don't require block-size aligned I/O buffers Ahmad Fatoum
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2026-08-26  9:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

efi_var_to_file() reports the reason it could not write the variable file
with %pe, but the one error it synthesizes itself is stored with the
wrong sign. ERR_PTR(ENOMEM) is not an error pointer, so IS_ERR() is false
and %pe prints the bogus pointer 0xc instead of "No memory".

The three other assignments to err already store negative errnos.

Assisted-by: Claude:opus-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/loader/efi_var_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/efi/loader/efi_var_file.c b/efi/loader/efi_var_file.c
index fbafd901bd0c..e4d350002ee8 100644
--- a/efi/loader/efi_var_file.c
+++ b/efi/loader/efi_var_file.c
@@ -52,7 +52,7 @@ efi_status_t efi_var_to_file(void)
 
 	efiret = efi_var_collect(&buf, &len, EFI_VARIABLE_NON_VOLATILE);
 	if (efiret != EFI_SUCCESS) {
-		err = ENOMEM;
+		err = -ENOMEM;
 		goto error;
 	}
 
-- 
2.47.3




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

* [PATCH master 3/4] efi: loader: disk: don't require block-size aligned I/O buffers
  2026-08-26  9:36 [PATCH master 1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported() Ahmad Fatoum
  2026-08-26  9:36 ` [PATCH master 2/4] efi: loader: fix sign of the error passed to ERR_PTR() Ahmad Fatoum
@ 2026-08-26  9:36 ` Ahmad Fatoum
  2026-08-26  9:36 ` [PATCH master 4/4] efi: loader: select PRINTF_WCHAR Ahmad Fatoum
  2026-08-28 11:59 ` [PATCH master 1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported() Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2026-08-26  9:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The Block I/O protocol's io_align member tells the consumer what
alignment the buffers passed to read_blocks()/write_blocks() need to
have. We set it to the block size, but our implementation services all
requests via cdev_read()/cdev_write(), which copy through the block
layer's cache chunks regardless of the caller's buffer alignment, so
there is no such requirement.

Report an io_align of 1 instead, which per UEFI specification, like 0,
means the buffer can be placed anywhere in memory. Prefer 1 over 0 as
a consumer computing the mask as io_align - 1 without checking for 0
first (as U-Boot's own producer side does) keeps working with 1, but
would reject every buffer with 0.

Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/loader/protocols/disk.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/efi/loader/protocols/disk.c b/efi/loader/protocols/disk.c
index 5c5447acca20..5376c9ec9a14 100644
--- a/efi/loader/protocols/disk.c
+++ b/efi/loader/protocols/disk.c
@@ -253,7 +253,13 @@ static efi_status_t efi_disk_add_cdev(efi_handle_t parent,
 	diskobj->media.removable_media = removable;
 	diskobj->media.media_present = true;
 	diskobj->media.read_only = cdev->flags & DEVFS_PARTITION_READONLY;
-	diskobj->media.block_size = diskobj->media.io_align = 1u << blockbits;
+	diskobj->media.block_size = 1u << blockbits;
+	/*
+	 * Reads and writes go through cdev_read()/cdev_write(), which
+	 * always copy through the block layer cache, so any buffer
+	 * alignment is acceptable.
+	 */
+	diskobj->media.io_align = 1;
 	diskobj->media.last_block = (cdev->size >> blockbits) - 1;
 	diskobj->blockbits = blockbits;
 
-- 
2.47.3




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

* [PATCH master 4/4] efi: loader: select PRINTF_WCHAR
  2026-08-26  9:36 [PATCH master 1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported() Ahmad Fatoum
  2026-08-26  9:36 ` [PATCH master 2/4] efi: loader: fix sign of the error passed to ERR_PTR() Ahmad Fatoum
  2026-08-26  9:36 ` [PATCH master 3/4] efi: loader: disk: don't require block-size aligned I/O buffers Ahmad Fatoum
@ 2026-08-26  9:36 ` Ahmad Fatoum
  2026-08-28 11:59 ` [PATCH master 1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported() Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2026-08-26  9:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The loader prints UEFI strings with %ls in a good two dozen places: the
variable name in the error path of efi_var_restore(), the EFI_ENTRY()
traces of the variable, console, HII and unicode collation protocols and
the exit data of a failed EFI payload.

%ls only formats UTF-16 when PRINTF_WCHAR is enabled; otherwise vsprintf
falls back to treating the argument as a C string, which for a UTF-16
string ends at the high byte of its first character:

  efi-loader: var-file: Failed to set EFI variable V

instead of "Var0430". EFI_PAYLOAD already selects the symbol, do the same
for EFI_LOADER.

Assisted-by: Claude:opus-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/efi/Kconfig b/efi/Kconfig
index b8f118a8812f..920705633cc7 100644
--- a/efi/Kconfig
+++ b/efi/Kconfig
@@ -38,6 +38,7 @@ config EFI_LOADER
 	select PARTITION_DISK
 	select MEMORY_ATTRIBUTES
 	select CRC32
+	select PRINTF_WCHAR
 	help
 	  Select this option if you want to run UEFI applications (like GNU
 	  GRUB or an EFI-stubbed kernel) on top of barebox.
-- 
2.47.3




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

* Re: [PATCH master 1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported()
  2026-08-26  9:36 [PATCH master 1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported() Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2026-08-26  9:36 ` [PATCH master 4/4] efi: loader: select PRINTF_WCHAR Ahmad Fatoum
@ 2026-08-28 11:59 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2026-08-28 11:59 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Wed, 26 Aug 2026 11:36:48 +0200, Ahmad Fatoum wrote:
> The return values of efi_set_variable_int() are efi_status_t, i.e. 64-bit
> on 64-bit targets with the error bit in the topmost bit. Collecting them
> in an int drops that bit, so the value returned to
> efi_init_runtime_supported() is a small positive number that no longer
> identifies an EFI error: EFI_OUT_OF_RESOURCES arrives as 9.
> 
> Callers only compared against EFI_SUCCESS so far, which happens to still
> work, but the status is worth printing and the next commit does so.
> 
> [...]

Applied, thanks!

[1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported()
      https://git.pengutronix.de/cgit/barebox/commit/?id=6d6c716a8028 (link may not be stable)
[2/4] efi: loader: fix sign of the error passed to ERR_PTR()
      https://git.pengutronix.de/cgit/barebox/commit/?id=da88be3df69e (link may not be stable)
[3/4] efi: loader: disk: don't require block-size aligned I/O buffers
      https://git.pengutronix.de/cgit/barebox/commit/?id=5fcc6e80e1c3 (link may not be stable)
[4/4] efi: loader: select PRINTF_WCHAR
      https://git.pengutronix.de/cgit/barebox/commit/?id=6904de3009df (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2026-08-28 12:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-26  9:36 [PATCH master 1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported() Ahmad Fatoum
2026-08-26  9:36 ` [PATCH master 2/4] efi: loader: fix sign of the error passed to ERR_PTR() Ahmad Fatoum
2026-08-26  9:36 ` [PATCH master 3/4] efi: loader: disk: don't require block-size aligned I/O buffers Ahmad Fatoum
2026-08-26  9:36 ` [PATCH master 4/4] efi: loader: select PRINTF_WCHAR Ahmad Fatoum
2026-08-28 11:59 ` [PATCH master 1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported() Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox