mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] efi: payload: image: set LoaderTimeExecUSec for kernel images
@ 2025-11-28 17:21 Ahmad Fatoum
  2025-11-28 17:21 ` [PATCH 2/3] efi: payload: fold setup_header.h into handover.c Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-11-28 17:21 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We already do this for handover, so systemd can show time spent since
barebox kicked off kernel boot.

Populate it for the non-legacy boot as well.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/payload/image.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/efi/payload/image.c b/efi/payload/image.c
index 22ff5d27ced6..5e268ed0ce35 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -10,6 +10,7 @@
 #include <clock.h>
 #include <common.h>
 #include <linux/sizes.h>
+#include <linux/ktime.h>
 #include <memory.h>
 #include <init.h>
 #include <driver.h>
@@ -129,6 +130,9 @@ int efi_execute_image(efi_handle_t handle,
 		}
 		printf("...\n");
 
+		efi_set_variable_usec("LoaderTimeExecUSec", &efi_systemd_vendor_guid,
+				      ktime_to_us(ktime_get()));
+
 		shutdown_barebox();
 	}
 
-- 
2.47.3




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

* [PATCH 2/3] efi: payload: fold setup_header.h into handover.c
  2025-11-28 17:21 [PATCH 1/3] efi: payload: image: set LoaderTimeExecUSec for kernel images Ahmad Fatoum
@ 2025-11-28 17:21 ` Ahmad Fatoum
  2025-11-28 17:21 ` [PATCH 3/3] efi: add option to generate vfat file for barebox.efi Ahmad Fatoum
  2025-12-01  9:04 ` [PATCH 1/3] efi: payload: image: set LoaderTimeExecUSec for kernel images Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-11-28 17:21 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The x86_setup_header is only used for x86 handover, so move it there and
replace is_linux_image by a helper that doesn't depend on it.

No functional change expected.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/filetype.c          | 12 ++++++++
 efi/payload/bootm.c        |  1 -
 efi/payload/handover.c     | 57 +++++++++++++++++++++++++++++++++-
 efi/payload/image.c        | 15 +--------
 efi/payload/setup_header.h | 63 --------------------------------------
 include/filetype.h         |  1 +
 6 files changed, 70 insertions(+), 79 deletions(-)
 delete mode 100644 efi/payload/setup_header.h

diff --git a/common/filetype.c b/common/filetype.c
index a1807d285258..3e3e18dae0b3 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -586,3 +586,15 @@ bool filetype_is_barebox_image(enum filetype ft)
 		return false;
 	}
 }
+
+bool filetype_is_linux_efi_image(enum filetype ft)
+{
+	switch (ft) {
+	case filetype_arm64_efi_linux_image:
+	case filetype_riscv_efi_linux_image:
+	case filetype_x86_efi_linux_image:
+		return true;
+	default:
+		return false;
+	}
+}
diff --git a/efi/payload/bootm.c b/efi/payload/bootm.c
index 2e060762f238..c81211d896ad 100644
--- a/efi/payload/bootm.c
+++ b/efi/payload/bootm.c
@@ -33,7 +33,6 @@
 #include <efi/efi-device.h>
 
 #include "image.h"
-#include "setup_header.h"
 
 static bool ramdisk_is_fit(struct image_data *data)
 {
diff --git a/efi/payload/handover.c b/efi/payload/handover.c
index 8c6dd2896f47..68180d820e53 100644
--- a/efi/payload/handover.c
+++ b/efi/payload/handover.c
@@ -31,7 +31,62 @@
 #include <efi/efi-device.h>
 
 #include "image.h"
-#include "setup_header.h"
+
+struct x86_setup_header {
+	/* first sector of the image */
+	uint8_t code1[0x0020];
+	uint16_t cl_magic;		/**< Magic number 0xA33F */
+	uint16_t cl_offset;		/**< The offset of command line */
+	uint8_t code2[0x01F1 - 0x0020 - 2 - 2];
+	uint8_t setup_sects;		/**< The size of the setup in sectors */
+	uint16_t root_flags;		/**< If the root is mounted readonly */
+	uint16_t syssize;		/**< obsolete */
+	uint16_t swap_dev;		/**< obsolete */
+	uint16_t ram_size;		/**< obsolete */
+	uint16_t vid_mode;		/**< Video mode control */
+	uint16_t root_dev;		/**< Default root device number */
+	uint16_t boot_flag;		/**< 0xAA55 magic number */
+
+	/* second sector of the image */
+	uint16_t jump;			/**< Jump instruction (this is code!) */
+	uint32_t header;		/**< Magic signature "HdrS" */
+	uint16_t version;		/**< Boot protocol version supported */
+	uint32_t realmode_swtch;	/**< Boot loader hook */
+	uint16_t start_sys;		/**< The load-low segment (obsolete) */
+	uint16_t kernel_version;	/**< Points to kernel version string */
+	uint8_t type_of_loader;		/**< Boot loader identifier */
+	uint8_t loadflags;		/**< Boot protocol option flags */
+	uint16_t setup_move_size;	/**< Move to high memory size */
+	uint32_t code32_start;		/**< Boot loader hook */
+	uint32_t ramdisk_image;		/**< initrd load address */
+	uint32_t ramdisk_size;		/**< initrd size */
+	uint32_t bootsect_kludge;	/**< obsolete */
+	uint16_t heap_end_ptr;		/**< Free memory after setup end */
+	uint8_t ext_loader_ver;		/**< boot loader's extension of the version number */
+	uint8_t ext_loader_type;	/**< boot loader's extension of its type */
+	uint32_t cmd_line_ptr;		/**< Points to the kernel command line */
+	uint32_t initrd_addr_max;	/**< Highest address for initrd */
+	uint32_t kernel_alignment;	/**< Alignment unit required by the kernel */
+	uint8_t relocatable_kernel;	/** */
+	uint8_t min_alignment;		/** */
+	uint16_t xloadflags;		/** */
+	uint32_t cmdline_size;		/** */
+	uint32_t hardware_subarch;	/** */
+	uint64_t hardware_subarch_data;	/** */
+	uint32_t payload_offset;	/** */
+	uint32_t payload_length;	/** */
+	uint64_t setup_data;		/** */
+	uint64_t pref_address;		/** */
+	uint32_t init_size;		/** */
+	uint32_t handover_offset;	/** */
+} __attribute__ ((packed));
+
+static inline bool is_x86_setup_header(const void *base)
+{
+	const struct x86_setup_header *hdr = base;
+
+	return hdr->boot_flag == 0xAA55 && hdr->header == 0x53726448;
+}
 
 typedef void(*handover_fn)(void *image, struct efi_system_table *table,
 			   struct x86_setup_header *header);
diff --git a/efi/payload/image.c b/efi/payload/image.c
index 5e268ed0ce35..ed4307aab909 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -29,7 +29,6 @@
 #include <efi/efi-device.h>
 
 #include "image.h"
-#include "setup_header.h"
 
 static void *efi_read_file(const char *file, size_t *size)
 {
@@ -96,18 +95,6 @@ int efi_load_image(const char *file, struct efi_loaded_image **loaded_image,
 	return -efi_errno(efiret);
 }
 
-static bool is_linux_image(enum filetype filetype, const void *base)
-{
-	if (IS_ENABLED(CONFIG_X86) && is_x86_setup_header(base))
-		return true;
-
-	if (IS_ENABLED(CONFIG_ARM64) &&
-	    filetype == filetype_arm64_efi_linux_image)
-		return true;
-
-	return false;
-}
-
 int efi_execute_image(efi_handle_t handle,
 		      struct efi_loaded_image *loaded_image,
 		      enum filetype filetype)
@@ -119,7 +106,7 @@ int efi_execute_image(efi_handle_t handle,
 	is_driver = (loaded_image->image_code_type == EFI_BOOT_SERVICES_CODE) ||
 		(loaded_image->image_code_type == EFI_RUNTIME_SERVICES_CODE);
 
-	if (is_linux_image(filetype, loaded_image->image_base)) {
+	if (filetype_is_linux_efi_image(filetype)) {
 		options = linux_bootargs_get();
 		printf("Booting kernel via StartImage");
 		if (options) {
diff --git a/efi/payload/setup_header.h b/efi/payload/setup_header.h
deleted file mode 100644
index 4f094b844415..000000000000
--- a/efi/payload/setup_header.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-#ifndef __EFI_PAYLOAD_SETUP_HEADER_H__
-#define __EFI_PAYLOAD_SETUP_HEADER_H__
-
-#include <linux/types.h>
-
-struct x86_setup_header {
-	/* first sector of the image */
-	uint8_t code1[0x0020];
-	uint16_t cl_magic;		/**< Magic number 0xA33F */
-	uint16_t cl_offset;		/**< The offset of command line */
-	uint8_t code2[0x01F1 - 0x0020 - 2 - 2];
-	uint8_t setup_sects;		/**< The size of the setup in sectors */
-	uint16_t root_flags;		/**< If the root is mounted readonly */
-	uint16_t syssize;		/**< obsolete */
-	uint16_t swap_dev;		/**< obsolete */
-	uint16_t ram_size;		/**< obsolete */
-	uint16_t vid_mode;		/**< Video mode control */
-	uint16_t root_dev;		/**< Default root device number */
-	uint16_t boot_flag;		/**< 0xAA55 magic number */
-
-	/* second sector of the image */
-	uint16_t jump;			/**< Jump instruction (this is code!) */
-	uint32_t header;		/**< Magic signature "HdrS" */
-	uint16_t version;		/**< Boot protocol version supported */
-	uint32_t realmode_swtch;	/**< Boot loader hook */
-	uint16_t start_sys;		/**< The load-low segment (obsolete) */
-	uint16_t kernel_version;	/**< Points to kernel version string */
-	uint8_t type_of_loader;		/**< Boot loader identifier */
-	uint8_t loadflags;		/**< Boot protocol option flags */
-	uint16_t setup_move_size;	/**< Move to high memory size */
-	uint32_t code32_start;		/**< Boot loader hook */
-	uint32_t ramdisk_image;		/**< initrd load address */
-	uint32_t ramdisk_size;		/**< initrd size */
-	uint32_t bootsect_kludge;	/**< obsolete */
-	uint16_t heap_end_ptr;		/**< Free memory after setup end */
-	uint8_t ext_loader_ver;		/**< boot loader's extension of the version number */
-	uint8_t ext_loader_type;	/**< boot loader's extension of its type */
-	uint32_t cmd_line_ptr;		/**< Points to the kernel command line */
-	uint32_t initrd_addr_max;	/**< Highest address for initrd */
-	uint32_t kernel_alignment;	/**< Alignment unit required by the kernel */
-	uint8_t relocatable_kernel;	/** */
-	uint8_t min_alignment;		/** */
-	uint16_t xloadflags;		/** */
-	uint32_t cmdline_size;		/** */
-	uint32_t hardware_subarch;	/** */
-	uint64_t hardware_subarch_data;	/** */
-	uint32_t payload_offset;	/** */
-	uint32_t payload_length;	/** */
-	uint64_t setup_data;		/** */
-	uint64_t pref_address;		/** */
-	uint32_t init_size;		/** */
-	uint32_t handover_offset;	/** */
-} __attribute__ ((packed));
-
-static inline bool is_x86_setup_header(const void *base)
-{
-	const struct x86_setup_header *hdr = base;
-
-	return hdr->boot_flag == 0xAA55 && hdr->header == 0x53726448;
-}
-
-#endif
diff --git a/include/filetype.h b/include/filetype.h
index ecbbd5873b00..440eb95bfb0c 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -89,6 +89,7 @@ int cdev_detect_type(struct cdev *cdev, enum filetype *type);
 enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec);
 int is_fat_boot_sector(const void *_buf);
 bool filetype_is_barebox_image(enum filetype ft);
+bool filetype_is_linux_efi_image(enum filetype ft);
 
 static inline bool file_is_compressed_file(enum filetype ft)
 {
-- 
2.47.3




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

* [PATCH 3/3] efi: add option to generate vfat file for barebox.efi
  2025-11-28 17:21 [PATCH 1/3] efi: payload: image: set LoaderTimeExecUSec for kernel images Ahmad Fatoum
  2025-11-28 17:21 ` [PATCH 2/3] efi: payload: fold setup_header.h into handover.c Ahmad Fatoum
@ 2025-11-28 17:21 ` Ahmad Fatoum
  2025-12-01  9:04 ` [PATCH 1/3] efi: payload: image: set LoaderTimeExecUSec for kernel images Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-11-28 17:21 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

This can be fairly useful for testing and may in future, even be
extended to hold the state.dtb.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/Kconfig       |  4 ++++
 images/.gitignore |  3 +++
 images/Makefile   | 10 ++++++++++
 scripts/mkesp     | 14 ++++++++++++++
 scripts/mkvfat    | 20 ++++++++++++++++++++
 5 files changed, 51 insertions(+)
 create mode 100755 scripts/mkesp
 create mode 100755 scripts/mkvfat

diff --git a/efi/Kconfig b/efi/Kconfig
index 35850b20ef50..49839f8466ea 100644
--- a/efi/Kconfig
+++ b/efi/Kconfig
@@ -4,6 +4,10 @@ menu "EFI (Extensible Firmware Interface) Support"
 
 source "efi/payload/Kconfig"
 
+config EFI_PAYLOAD_ESP_IMAGE
+	bool "Generate barebox.esp image from payload"
+	depends on EFI_PAYLOAD
+
 config EFI
 	bool
 
diff --git a/images/.gitignore b/images/.gitignore
index fc464ff2e3cb..0e0d2fa71859 100644
--- a/images/.gitignore
+++ b/images/.gitignore
@@ -43,3 +43,6 @@ barebox.sum
 *.missing-firmware
 *.k3img
 fuzz-*
+*.efi
+*.esp
+*.vfat
diff --git a/images/Makefile b/images/Makefile
index 448479ee8cf3..119e7a6e2b8e 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -215,6 +215,16 @@ FILE_barebox.img = start_pbl.pblb
 image-$(CONFIG_PBL_SINGLE_IMAGE) += barebox.img
 endif
 
+FILE_barebox.vfat = $(if CONFIG_EFI_STUB,barebox-dt-2nd.img,../barebox.efi)
+FILE_barebox.esp = barebox.vfat
+image-$(CONFIG_EFI_PAYLOAD_ESP_IMAGE) += barebox.esp barebox.vfat
+
+.SECONDEXPANSION:
+$(obj)/barebox.vfat: $(obj)/$$(FILE_$$(@F))
+	$(Q)$(srctree)/scripts/mkvfat $@ $< $(CONFIG_EFI_PAYLOAD_DEFAULT_PATH)
+$(obj)/barebox.esp: $(obj)/$$(FILE_$$(@F))
+	$(Q)$(srctree)/scripts/mkesp $@ $<
+
 ifneq ($(pblx-y)$(pblx-),)
   $(error pblx- has been removed. Please use pblb- instead.)
 endif
diff --git a/scripts/mkesp b/scripts/mkesp
new file mode 100755
index 000000000000..08772fb0f163
--- /dev/null
+++ b/scripts/mkesp
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+set -e
+
+img="$1"
+part="$2"
+
+# We operate on local files only, so sfdisk in /sbin is still ok
+export PATH="$PATH:/sbin"
+
+truncate -s 4114KiB "$img"
+dd if="/dev/zero" of="$img" seek=2048 count=1 conv=notrunc status=none
+echo ',2M,U' | sfdisk --quiet --force --label gpt "$img"
+dd if="$part" of="$img" seek=2048 conv=notrunc status=none
diff --git a/scripts/mkvfat b/scripts/mkvfat
new file mode 100755
index 000000000000..6ccbffe093ce
--- /dev/null
+++ b/scripts/mkvfat
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+set -e
+
+img="$1"
+bb="$2"
+fullpath="$3"
+
+truncate -s 2048KiB "$img"
+mkdosfs "$img" >/dev/null
+
+path="$fullpath"
+while true; do
+    path="$(dirname "$path")"
+    if [ "$path" = "." ]; then break; fi
+    components="::$path $components"
+done
+
+mmd -DsS -i "$img" $components
+mcopy -sp -D overwrite -i "$img" "$bb" "::$fullpath"
-- 
2.47.3




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

* Re: [PATCH 1/3] efi: payload: image: set LoaderTimeExecUSec for kernel images
  2025-11-28 17:21 [PATCH 1/3] efi: payload: image: set LoaderTimeExecUSec for kernel images Ahmad Fatoum
  2025-11-28 17:21 ` [PATCH 2/3] efi: payload: fold setup_header.h into handover.c Ahmad Fatoum
  2025-11-28 17:21 ` [PATCH 3/3] efi: add option to generate vfat file for barebox.efi Ahmad Fatoum
@ 2025-12-01  9:04 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2025-12-01  9:04 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Fri, 28 Nov 2025 18:21:53 +0100, Ahmad Fatoum wrote:
> We already do this for handover, so systemd can show time spent since
> barebox kicked off kernel boot.
> 
> Populate it for the non-legacy boot as well.
> 
> 

Applied, thanks!

[1/3] efi: payload: image: set LoaderTimeExecUSec for kernel images
      https://git.pengutronix.de/cgit/barebox/commit/?id=5a87d9e6f5a7 (link may not be stable)
[2/3] efi: payload: fold setup_header.h into handover.c
      https://git.pengutronix.de/cgit/barebox/commit/?id=a42e9c5f2a6a (link may not be stable)
[3/3] efi: add option to generate vfat file for barebox.efi
      https://git.pengutronix.de/cgit/barebox/commit/?id=b087adf31b7a (link may not be stable)

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




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

end of thread, other threads:[~2025-12-01  9:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-28 17:21 [PATCH 1/3] efi: payload: image: set LoaderTimeExecUSec for kernel images Ahmad Fatoum
2025-11-28 17:21 ` [PATCH 2/3] efi: payload: fold setup_header.h into handover.c Ahmad Fatoum
2025-11-28 17:21 ` [PATCH 3/3] efi: add option to generate vfat file for barebox.efi Ahmad Fatoum
2025-12-01  9:04 ` [PATCH 1/3] efi: payload: image: set LoaderTimeExecUSec for kernel images Sascha Hauer

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