Skip to contentSkip to conversation

cmd: bootm: add ELF file support

PATCH In review Maxim Moskalets 3 participants 5 messages Jun 21, 2024 – Jul 5, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 cmd: bootm: add ELF file support

Some operating systems (e.g. seL4) and embedded applications are ELF images. It is convenient to use FIT-images to implement trusted boot. Added "elf" image type for booting using bootm command.

---
v5:
used func from lib/elf.c to avoid dependency form CLI

---
 boot/bootm_os.c  | 18 ++++++++++++++++++
 boot/image-fit.c |  3 ++-
 boot/image.c     |  5 ++++-
 cmd/Kconfig      |  7 +++++++
 include/image.h  |  1 +
 5 files changed, 32 insertions(+), 2 deletions(-)
boot/bootm_os.c +18 -0
index 15297ddb53..6a6621706f 100644
@@ -8,6 +8,7 @@
 #include <bootstage.h>
 #include <cpu_func.h>
 #include <efi_loader.h>
+#include <elf.h>
 #include <env.h>
 #include <fdt_support.h>
 #include <image.h>
@@ -394,6 +395,20 @@ static int do_bootm_qnxelf(int flag, struct bootm_info *bmi)
 }
 #endif
 
+#if defined(CONFIG_BOOTM_ELF)
+static int do_bootm_elf(int flag, struct bootm_info *bmi)
+{
+	Bootelf_flags flags = { .autostart = 1 };
+
+	if (flag != BOOTM_STATE_OS_GO)
+		return 0;
+
+	bootelf(bmi->images->ep, flags, 0, NULL);
+
+	return 1;
+}
+#endif
+
 #ifdef CONFIG_INTEGRITY
 static int do_bootm_integrity(int flag, struct bootm_info *bmi)
 {
@@ -535,6 +550,9 @@ static boot_os_fn *boot_os[] = {
 #ifdef CONFIG_BOOTM_EFI
 	[IH_OS_EFI] = do_bootm_efi,
 #endif
+#if defined(CONFIG_BOOTM_ELF)
+	[IH_OS_ELF] = do_bootm_elf,
+#endif
 };
 
 /* Allow for arch specific config before we boot */
boot/image-fit.c +2 -1
index f6464bcf62..9253f81fff 100644
@@ -2175,7 +2175,8 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
 		fit_image_check_os(fit, noffset, IH_OS_TEE) ||
 		fit_image_check_os(fit, noffset, IH_OS_OPENRTOS) ||
 		fit_image_check_os(fit, noffset, IH_OS_EFI) ||
-		fit_image_check_os(fit, noffset, IH_OS_VXWORKS);
+		fit_image_check_os(fit, noffset, IH_OS_VXWORKS) ||
+		fit_image_check_os(fit, noffset, IH_OS_ELF);
 
 	/*
 	 * If either of the checks fail, we should report an error, but
boot/image.c +4 -1
index fc774d605d..abac254e02 100644
@@ -130,7 +130,10 @@ static const table_entry_t uimage_os[] = {
 	{	IH_OS_OPENRTOS,	"openrtos",	"OpenRTOS",		},
 #endif
 	{	IH_OS_OPENSBI,	"opensbi",	"RISC-V OpenSBI",	},
-	{	IH_OS_EFI,	"efi",		"EFI Firmware" },
+	{	IH_OS_EFI,	"efi",		"EFI Firmware"		},
+#ifdef CONFIG_BOOTM_ELF
+	{	IH_OS_ELF,	"elf",		"ELF Image"		},
+#endif
 
 	{	-1,		"",		"",			},
 };
cmd/Kconfig +7 -0
index a2dee34689..613baa106e 100644
@@ -321,6 +321,13 @@ config BOOTM_EFI
 	help
 	  Support booting UEFI FIT images via the bootm command.
 
+config BOOTM_ELF
+	bool "Support booting ELF images"
+	depends on CMD_BOOTM && LIB_ELF
+	default n
+	help
+	  Support booting ELF images via the bootm command.
+
 config CMD_BOOTZ
 	bool "bootz"
 	help
include/image.h +1 -0
index c5b288f62b..9daaee15cd 100644
@@ -100,6 +100,7 @@ enum {
 	IH_OS_TEE,			/* Trusted Execution Environment */
 	IH_OS_OPENSBI,			/* RISC-V OpenSBI */
 	IH_OS_EFI,			/* EFI Firmware (e.g. GRUB2) */
+	IH_OS_ELF,			/* ELF Image (e.g. seL4) */
 
 	IH_OS_COUNT,
 };
Signature · 1 line
2.39.2
#1 lore raw
Quoted 5 lines · Maxim Moskalets

Some operating systems (e.g. seL4) and embedded applications are ELF images. It is convenient to use FIT-images to implement trusted boot. Added "elf" image type for booting using bootm command.

I guess a test could be added to test/py/tests/test_zynqmp_rpu.py which already uses the bootelf command?

Best regards

Heinrich

Quoted 114 lines

---
v5:
used func from lib/elf.c to avoid dependency form CLI

---
  boot/bootm_os.c  | 18 ++++++++++++++++++
  boot/image-fit.c |  3 ++-
  boot/image.c     |  5 ++++-
  cmd/Kconfig      |  7 +++++++
  include/image.h  |  1 +
  5 files changed, 32 insertions(+), 2 deletions(-)
boot/bootm_os.c +18 -0
index 15297ddb53..6a6621706f 100644
@@ -8,6 +8,7 @@
  #include <bootstage.h>
  #include <cpu_func.h>
  #include <efi_loader.h>
+#include <elf.h>
  #include <env.h>
  #include <fdt_support.h>
  #include <image.h>
@@ -394,6 +395,20 @@ static int do_bootm_qnxelf(int flag, struct bootm_info *bmi)
  }
  #endif
 
+#if defined(CONFIG_BOOTM_ELF)
+static int do_bootm_elf(int flag, struct bootm_info *bmi)
+{
+	Bootelf_flags flags = { .autostart = 1 };
+
+	if (flag != BOOTM_STATE_OS_GO)
+		return 0;
+
+	bootelf(bmi->images->ep, flags, 0, NULL);
+
+	return 1;
+}
+#endif
+
  #ifdef CONFIG_INTEGRITY
  static int do_bootm_integrity(int flag, struct bootm_info *bmi)
  {
@@ -535,6 +550,9 @@ static boot_os_fn *boot_os[] = {
  #ifdef CONFIG_BOOTM_EFI
  	[IH_OS_EFI] = do_bootm_efi,
  #endif
+#if defined(CONFIG_BOOTM_ELF)
+	[IH_OS_ELF] = do_bootm_elf,
+#endif
  };
 
  /* Allow for arch specific config before we boot */
boot/image-fit.c +2 -1
index f6464bcf62..9253f81fff 100644
@@ -2175,7 +2175,8 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
  		fit_image_check_os(fit, noffset, IH_OS_TEE) ||
  		fit_image_check_os(fit, noffset, IH_OS_OPENRTOS) ||
  		fit_image_check_os(fit, noffset, IH_OS_EFI) ||
-		fit_image_check_os(fit, noffset, IH_OS_VXWORKS);
+		fit_image_check_os(fit, noffset, IH_OS_VXWORKS) ||
+		fit_image_check_os(fit, noffset, IH_OS_ELF);
 
  	/*
  	 * If either of the checks fail, we should report an error, but
boot/image.c +4 -1
index fc774d605d..abac254e02 100644
@@ -130,7 +130,10 @@ static const table_entry_t uimage_os[] = {
  	{	IH_OS_OPENRTOS,	"openrtos",	"OpenRTOS",		},
  #endif
  	{	IH_OS_OPENSBI,	"opensbi",	"RISC-V OpenSBI",	},
-	{	IH_OS_EFI,	"efi",		"EFI Firmware" },
+	{	IH_OS_EFI,	"efi",		"EFI Firmware"		},
+#ifdef CONFIG_BOOTM_ELF
+	{	IH_OS_ELF,	"elf",		"ELF Image"		},
+#endif
 
  	{	-1,		"",		"",			},
  };
cmd/Kconfig +7 -0
index a2dee34689..613baa106e 100644
@@ -321,6 +321,13 @@ config BOOTM_EFI
  	help
  	  Support booting UEFI FIT images via the bootm command.
 
+config BOOTM_ELF
+	bool "Support booting ELF images"
+	depends on CMD_BOOTM && LIB_ELF
+	default n
+	help
+	  Support booting ELF images via the bootm command.
+
  config CMD_BOOTZ
  	bool "bootz"
  	help
include/image.h +1 -0
index c5b288f62b..9daaee15cd 100644
@@ -100,6 +100,7 @@ enum {
  	IH_OS_TEE,			/* Trusted Execution Environment */
  	IH_OS_OPENSBI,			/* RISC-V OpenSBI */
  	IH_OS_EFI,			/* EFI Firmware (e.g. GRUB2) */
+	IH_OS_ELF,			/* ELF Image (e.g. seL4) */
 
  	IH_OS_COUNT,
  };
#2 lore raw

пт, 21 июн. 2024 г. в 15:51, Heinrich Schuchardt <[email protected]>:

Quoted 11 lines · Maxim Moskalets
Quoted 5 lines

Some operating systems (e.g. seL4) and embedded applications are ELF images. It is convenient to use FIT-images to implement trusted boot. Added "elf" image type for booting using bootm command.

I guess a test could be added to test/py/tests/test_zynqmp_rpu.py which already uses the bootelf command?

Is it necessary to use specific hardware to run this test?

Best regards

Maxim

Quoted 122 lines

Best regards

Heinrich

boot/bootm_os.c static int do_bootm_qnxelf(int flag, struct

Quoted 24 lines

---
v5:
used func from lib/elf.c to avoid dependency form CLI

---
  boot/bootm_os.c  | 18 ++++++++++++++++++
  boot/image-fit.c |  3 ++-
  boot/image.c     |  5 ++++-
  cmd/Kconfig      |  7 +++++++
  include/image.h  |  1 +
  5 files changed, 32 insertions(+), 2 deletions(-)
boot/bootm_os.c +1 -0
index 15297ddb53..6a6621706f 100644
@@ -8,6 +8,7 @@
  #include <bootstage.h>
  #include <cpu_func.h>
  #include <efi_loader.h>
+#include <elf.h>
  #include <env.h>
  #include <fdt_support.h>
  #include <image.h>
@@ -394,6 +395,20 @@ static int do_bootm_qnxelf(int flag, struct

bootm_info *bmi)

boot/image-fit.c int fit_image_load(struct bootm_headers *images,

Quoted 35 lines
boot/bootm_os.c +17 -0
  }
  #endif
 
+#if defined(CONFIG_BOOTM_ELF)
+static int do_bootm_elf(int flag, struct bootm_info *bmi)
+{
+     Bootelf_flags flags = { .autostart = 1 };
+
+     if (flag != BOOTM_STATE_OS_GO)
+             return 0;
+
+     bootelf(bmi->images->ep, flags, 0, NULL);
+
+     return 1;
+}
+#endif
+
  #ifdef CONFIG_INTEGRITY
  static int do_bootm_integrity(int flag, struct bootm_info *bmi)
  {
@@ -535,6 +550,9 @@ static boot_os_fn *boot_os[] = {
  #ifdef CONFIG_BOOTM_EFI
      [IH_OS_EFI] = do_bootm_efi,
  #endif
+#if defined(CONFIG_BOOTM_ELF)
+     [IH_OS_ELF] = do_bootm_elf,
+#endif
  };
 
  /* Allow for arch specific config before we boot */
boot/image-fit.c +0 -0
index f6464bcf62..9253f81fff 100644
@@ -2175,7 +2175,8 @@ int fit_image_load(struct bootm_headers *images,

ulong addr,

Quoted 55 lines
boot/image-fit.c +2 -1
              fit_image_check_os(fit, noffset, IH_OS_TEE) ||
              fit_image_check_os(fit, noffset, IH_OS_OPENRTOS) ||
              fit_image_check_os(fit, noffset, IH_OS_EFI) ||
-             fit_image_check_os(fit, noffset, IH_OS_VXWORKS);
+             fit_image_check_os(fit, noffset, IH_OS_VXWORKS) ||
+             fit_image_check_os(fit, noffset, IH_OS_ELF);
 
      /*
       * If either of the checks fail, we should report an error, but
boot/image.c +4 -1
index fc774d605d..abac254e02 100644
@@ -130,7 +130,10 @@ static const table_entry_t uimage_os[] = {
      {       IH_OS_OPENRTOS, "openrtos",     "OpenRTOS",             },
  #endif
      {       IH_OS_OPENSBI,  "opensbi",      "RISC-V OpenSBI",       },
-     {       IH_OS_EFI,      "efi",          "EFI Firmware" },
+     {       IH_OS_EFI,      "efi",          "EFI Firmware"          },
+#ifdef CONFIG_BOOTM_ELF
+     {       IH_OS_ELF,      "elf",          "ELF Image"             },
+#endif
 
      {       -1,             "",             "",                     },
  };
cmd/Kconfig +7 -0
index a2dee34689..613baa106e 100644
@@ -321,6 +321,13 @@ config BOOTM_EFI
      help
        Support booting UEFI FIT images via the bootm command.
 
+config BOOTM_ELF
+     bool "Support booting ELF images"
+     depends on CMD_BOOTM && LIB_ELF
+     default n
+     help
+       Support booting ELF images via the bootm command.
+
  config CMD_BOOTZ
      bool "bootz"
      help
include/image.h +1 -0
index c5b288f62b..9daaee15cd 100644
@@ -100,6 +100,7 @@ enum {
      IH_OS_TEE,                      /* Trusted Execution Environment */
      IH_OS_OPENSBI,                  /* RISC-V OpenSBI */
      IH_OS_EFI,                      /* EFI Firmware (e.g. GRUB2) */
+     IH_OS_ELF,                      /* ELF Image (e.g. seL4) */
 
      IH_OS_COUNT,
  };
#3 lore raw
Quoted 14 lines · Максим Москалец

пт, 21 июн. 2024 г. в 15:51, Heinrich Schuchardt <[email protected]>:

Quoted 11 lines · Maxim Moskalets
Quoted 5 lines

Some operating systems (e.g. seL4) and embedded applications are ELF images. It is convenient to use FIT-images to implement trusted boot. Added "elf" image type for booting using bootm command.

I guess a test could be added to test/py/tests/test_zynqmp_rpu.py which already uses the bootelf command?

Is it necessary to use specific hardware to run this test?

In Gitlab CI xilinx_zynq_virt_defconfig is used with QEMU parameters from
https://source.denx.de/u-boot/u-boot-test-hooks/-/blob/master/bin/travis-ci/conf.xilinx_zynq_virt_qemu:

qemu-system-arm \
-machine xilinx-zynq-a9 \
-display none \
-m 1G \
-nographic \
-serial /dev/null \
-serial mon:stdio \
-monitor null \
-device loader,file=u-boot-dtb.bin,addr=0x4000000,cpu-num=0

See for instance this build:
https://source.denx.de/u-boot/custodians/u-boot-efi/-/jobs/852062

Best regards

Heinrich

Quoted 120 lines
Quoted 120 lines

Heinrich

boot/bootm_os.c static int do_bootm_qnxelf(int flag, struct

Quoted 24 lines

---
v5:
used func from lib/elf.c to avoid dependency form CLI

---
   boot/bootm_os.c  | 18 ++++++++++++++++++
   boot/image-fit.c |  3 ++-
   boot/image.c     |  5 ++++-
   cmd/Kconfig      |  7 +++++++
   include/image.h  |  1 +
   5 files changed, 32 insertions(+), 2 deletions(-)
boot/bootm_os.c +1 -0
index 15297ddb53..6a6621706f 100644
@@ -8,6 +8,7 @@
   #include <bootstage.h>
   #include <cpu_func.h>
   #include <efi_loader.h>
+#include <elf.h>
   #include <env.h>
   #include <fdt_support.h>
   #include <image.h>
@@ -394,6 +395,20 @@ static int do_bootm_qnxelf(int flag, struct

bootm_info *bmi)

boot/image-fit.c int fit_image_load(struct bootm_headers *images,

Quoted 35 lines
boot/bootm_os.c +17 -0
   }
   #endif
 
+#if defined(CONFIG_BOOTM_ELF)
+static int do_bootm_elf(int flag, struct bootm_info *bmi)
+{
+     Bootelf_flags flags = { .autostart = 1 };
+
+     if (flag != BOOTM_STATE_OS_GO)
+             return 0;
+
+     bootelf(bmi->images->ep, flags, 0, NULL);
+
+     return 1;
+}
+#endif
+
   #ifdef CONFIG_INTEGRITY
   static int do_bootm_integrity(int flag, struct bootm_info *bmi)
   {
@@ -535,6 +550,9 @@ static boot_os_fn *boot_os[] = {
   #ifdef CONFIG_BOOTM_EFI
       [IH_OS_EFI] = do_bootm_efi,
   #endif
+#if defined(CONFIG_BOOTM_ELF)
+     [IH_OS_ELF] = do_bootm_elf,
+#endif
   };
 
   /* Allow for arch specific config before we boot */
boot/image-fit.c +0 -0
index f6464bcf62..9253f81fff 100644
@@ -2175,7 +2175,8 @@ int fit_image_load(struct bootm_headers *images,

ulong addr,

Quoted 55 lines
boot/image-fit.c +2 -1
               fit_image_check_os(fit, noffset, IH_OS_TEE) ||
               fit_image_check_os(fit, noffset, IH_OS_OPENRTOS) ||
               fit_image_check_os(fit, noffset, IH_OS_EFI) ||
-             fit_image_check_os(fit, noffset, IH_OS_VXWORKS);
+             fit_image_check_os(fit, noffset, IH_OS_VXWORKS) ||
+             fit_image_check_os(fit, noffset, IH_OS_ELF);
 
       /*
        * If either of the checks fail, we should report an error, but
boot/image.c +4 -1
index fc774d605d..abac254e02 100644
@@ -130,7 +130,10 @@ static const table_entry_t uimage_os[] = {
       {       IH_OS_OPENRTOS, "openrtos",     "OpenRTOS",             },
   #endif
       {       IH_OS_OPENSBI,  "opensbi",      "RISC-V OpenSBI",       },
-     {       IH_OS_EFI,      "efi",          "EFI Firmware" },
+     {       IH_OS_EFI,      "efi",          "EFI Firmware"          },
+#ifdef CONFIG_BOOTM_ELF
+     {       IH_OS_ELF,      "elf",          "ELF Image"             },
+#endif
 
       {       -1,             "",             "",                     },
   };
cmd/Kconfig +7 -0
index a2dee34689..613baa106e 100644
@@ -321,6 +321,13 @@ config BOOTM_EFI
       help
         Support booting UEFI FIT images via the bootm command.
 
+config BOOTM_ELF
+     bool "Support booting ELF images"
+     depends on CMD_BOOTM && LIB_ELF
+     default n
+     help
+       Support booting ELF images via the bootm command.
+
   config CMD_BOOTZ
       bool "bootz"
       help
include/image.h +1 -0
index c5b288f62b..9daaee15cd 100644
@@ -100,6 +100,7 @@ enum {
       IH_OS_TEE,                      /* Trusted Execution Environment */
       IH_OS_OPENSBI,                  /* RISC-V OpenSBI */
       IH_OS_EFI,                      /* EFI Firmware (e.g. GRUB2) */
+     IH_OS_ELF,                      /* ELF Image (e.g. seL4) */
 
       IH_OS_COUNT,
   };
#4 lore raw
In reply to Maxim Moskalets
Quoted 5 lines · Maxim Moskalets

Some operating systems (e.g. seL4) and embedded applications are ELF images. It is convenient to use FIT-images to implement trusted boot. Added "elf" image type for booting using bootm command.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom