Skip to contentSkip to conversation

qemu: arm64: Add support for uefi firmware management protocol routines

PATCH New Sughosh Ganu 6 participants 41 messages Apr 30, 2020 – May 18, 2020 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

cover qemu: arm64: Add support for uefi firmware management protocol routines

This series is based on the capsule update series sent by Takahiro Akashi[1].

These routines have been tested on the qemu arm64 platform for updating the u-boot firmware through the capsule-on-disk functionality of the uefi spec. This series supports updating the u-boot binary image on platforms booting from arm trusted firmware(tf-a), where the u-boot image gets booted as the BL33 payload. Support has also been added for authenticating the capsule file using the public key contained in the root certificate stored as an efi variable.

The capsule file is placed on the efi system partition(esp), under the EFI/UpdateCapsule directory. The BootNext and BootXXXX variables are set accordingly by using the 'efidebug boot add' command. More details added as part of the documentation patch.

[1] - https://lists.denx.de/pipermail/u-boot/2020-April/408760.html

Sughosh Ganu (8):
semihosting: Change semihosting file operation functions into global
symbols
semihosting: Add support for writing to a file
qemu: arm64: Add support for efi firmware management protocol routines
efi_loader: Allow parsing of miscellaneous signature database
variables
efi_loader: Make the pkcs7 header parsing function an extern
efi: capsule: Add support for uefi capsule authentication
qemu: arm64: Add support for uefi capsule authentication
qemu: arm64: Add documentation for capsule update

 arch/arm/lib/semihosting.c              |  48 ++++-
 board/emulation/qemu-arm/Kconfig        |  12 ++
 board/emulation/qemu-arm/Makefile       |   1 +
 board/emulation/qemu-arm/qemu_efi_fmp.c | 243 ++++++++++++++++++++++++
 doc/board/emulation/qemu-arm.rst        | 112 +++++++++++
 include/efi_api.h                       |  17 ++
 include/efi_loader.h                    |  13 +-
 include/semihosting.h                   |  14 ++
 lib/efi_loader/Kconfig                  |  16 ++
 lib/efi_loader/efi_capsule.c            | 126 ++++++++++++
 lib/efi_loader/efi_image_loader.c       |  11 +-
 lib/efi_loader/efi_signature.c          |  96 ++++++++--
 lib/efi_loader/efi_variable.c           |  91 +--------
 13 files changed, 692 insertions(+), 108 deletions(-)
 create mode 100644 board/emulation/qemu-arm/qemu_efi_fmp.c
 create mode 100644 include/semihosting.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/8 semihosting: Change semihosting file operation functions into global symbols

Change the semihosting file operation functions into external symbols so that they can be called from outside the file. These functions would be required to be called for implementing firmware update functionality for the qemu arm64 platform.

---
 arch/arm/lib/semihosting.c |  7 ++++---
 include/semihosting.h      | 13 +++++++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 include/semihosting.h
arch/arm/lib/semihosting.c +4 -3
index 2658026cf4..3aeda1303a 100644
@@ -13,6 +13,7 @@
  */
 #include <common.h>
 #include <command.h>
+#include <semihosting.h>
 
 #define SYSOPEN		0x01
 #define SYSCLOSE	0x02
@@ -43,7 +44,7 @@ static noinline long smh_trap(unsigned int sysnum, void *addr)
  * Open a file on the host. Mode is "r" or "rb" currently. Returns a file
  * descriptor or -1 on error.
  */
-static long smh_open(const char *fname, char *modestr)
+long smh_open(const char *fname, char *modestr)
 {
 	long fd;
 	unsigned long mode;
@@ -82,7 +83,7 @@ static long smh_open(const char *fname, char *modestr)
 /*
  * Read 'len' bytes of file into 'memp'. Returns 0 on success, else failure
  */
-static long smh_read(long fd, void *memp, size_t len)
+long smh_read(long fd, void *memp, size_t len)
 {
 	long ret;
 	struct smh_read_s {
@@ -116,7 +117,7 @@ static long smh_read(long fd, void *memp, size_t len)
 /*
  * Close the file using the file descriptor
  */
-static long smh_close(long fd)
+long smh_close(long fd)
 {
 	long ret;
 
include/semihosting.h new file +13 -0
new file mode 100644
index 0000000000..f1bf419275
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2020, Linaro Limited
+ */
+
+#if !defined _SEMIHOSTING_H_
+#define _SEMIHOSTING_H_
+
+long smh_open(const char *fname, char *modestr);
+long smh_read(long fd, void *memp, size_t len);
+long smh_close(long fd);
+
+#endif /* _SEMIHOSTING_H_ */
Signature · 1 line
2.17.1
#2 lore raw

PATCH 1/8 semihosting: Change semihosting file operation functions into global symbols

Quoted 17 lines · Sughosh Ganu

Change the semihosting file operation functions into external symbols so that they can be called from outside the file. These functions would be required to be called for implementing firmware update functionality for the qemu arm64 platform.

---
 arch/arm/lib/semihosting.c |  7 ++++---
 include/semihosting.h      | 13 +++++++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 include/semihosting.h
arch/arm/lib/semihosting.c +0 -0
index 2658026cf4..3aeda1303a 100644

arch/arm/lib/semihosting.c line 16

Quoted 4 lines
arch/arm/lib/semihosting.c +1 -0
@@ -13,6 +13,7 @@
  */
 #include <common.h>
 #include <command.h>
+#include <semihosting.h>

Do we need this file here?

-Takahiro Akashi

Quoted 51 lines
arch/arm/lib/semihosting.c +3 -3
 #define SYSOPEN		0x01
 #define SYSCLOSE	0x02
@@ -43,7 +44,7 @@ static noinline long smh_trap(unsigned int sysnum, void *addr)
  * Open a file on the host. Mode is "r" or "rb" currently. Returns a file
  * descriptor or -1 on error.
  */
-static long smh_open(const char *fname, char *modestr)
+long smh_open(const char *fname, char *modestr)
 {
 	long fd;
 	unsigned long mode;
@@ -82,7 +83,7 @@ static long smh_open(const char *fname, char *modestr)
 /*
  * Read 'len' bytes of file into 'memp'. Returns 0 on success, else failure
  */
-static long smh_read(long fd, void *memp, size_t len)
+long smh_read(long fd, void *memp, size_t len)
 {
 	long ret;
 	struct smh_read_s {
@@ -116,7 +117,7 @@ static long smh_read(long fd, void *memp, size_t len)
 /*
  * Close the file using the file descriptor
  */
-static long smh_close(long fd)
+long smh_close(long fd)
 {
 	long ret;
 
include/semihosting.h new file +13 -0
new file mode 100644
index 0000000000..f1bf419275
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2020, Linaro Limited
+ */
+
+#if !defined _SEMIHOSTING_H_
+#define _SEMIHOSTING_H_
+
+long smh_open(const char *fname, char *modestr);
+long smh_read(long fd, void *memp, size_t len);
+long smh_close(long fd);
+
+#endif /* _SEMIHOSTING_H_ */
Signature · 1 line
2.17.1
#3 lore raw

PATCH 1/8 semihosting: Change semihosting file operation functions into global symbols

Quoted 13 lines · Akashi Takahiro
Quoted 12 lines · Sughosh Ganu

Change the semihosting file operation functions into external symbols so that they can be called from outside the file. These functions would be required to be called for implementing firmware update functionality for the qemu arm64 platform.

---
 arch/arm/lib/semihosting.c |  7 ++++---
 include/semihosting.h      | 13 +++++++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 include/semihosting.h
Quoted 4 lines

arch/arm/lib/semihosting.c

Quoted 4 lines
arch/arm/lib/semihosting.c +0 -0
index 2658026cf4..3aeda1303a 100644

Semihosting in QEMU is not ARM specific but exists also for the M68K, Xtensa, MIPS, and NIOS2 architecture. arch/arm/lib/ is the wrong place for this file. This file should be moved to lib/.

The smhload command should be moved to cmd/smhload.c

Quoted 7 lines

arch/arm/lib/semihosting.c line 16

Quoted 5 lines
arch/arm/lib/semihosting.c +1 -0
@@ -13,6 +13,7 @@
  */
 #include <common.h>
 #include <command.h>
+#include <semihosting.h>

Do we need this file here?

This patch is about turning the functions defined in semihosting.h into global functions. In patch 3/8 the functions are called from other parts of the U-Boot code. We need the include here to ensure that the definitions match.

Quoted 32 lines

-Takahiro Akashi

Quoted 29 lines
arch/arm/lib/semihosting.c +3 -3
 #define SYSOPEN		0x01
 #define SYSCLOSE	0x02
@@ -43,7 +44,7 @@ static noinline long smh_trap(unsigned int sysnum, void *addr)
  * Open a file on the host. Mode is "r" or "rb" currently. Returns a file
  * descriptor or -1 on error.
  */
-static long smh_open(const char *fname, char *modestr)
+long smh_open(const char *fname, char *modestr)
 {
 	long fd;
 	unsigned long mode;
@@ -82,7 +83,7 @@ static long smh_open(const char *fname, char *modestr)
 /*
  * Read 'len' bytes of file into 'memp'. Returns 0 on success, else failure
  */
-static long smh_read(long fd, void *memp, size_t len)
+long smh_read(long fd, void *memp, size_t len)
 {
 	long ret;
 	struct smh_read_s {
@@ -116,7 +117,7 @@ static long smh_read(long fd, void *memp, size_t len)
 /*
  * Close the file using the file descriptor
  */
-static long smh_close(long fd)
+long smh_close(long fd)
 {
 	long ret;
 
Quoted 14 lines
Quoted 6 lines
include/semihosting.h new file +0 -0
new file mode 100644
index 0000000000..f1bf419275

include/semihosting.h line 8

Quoted 8 lines
include/semihosting.h new file +8 -0
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2020, Linaro Limited
+ */
+
+#if !defined _SEMIHOSTING_H_
+#define _SEMIHOSTING_H_
+

If these functions become global symbols, we should provide a function description according to

https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation

and merge this file into doc/api/index.rst to produce HTML documentation with 'make htmldoc'.

Cf. https://u-boot.readthedocs.io/en/latest/api/index.html

Best regards

Heinrich

Quoted 8 lines
Quoted 8 lines
include/semihosting.h new file +5 -1
+long smh_open(const char *fname, char *modestr);
+long smh_read(long fd, void *memp, size_t len);
+long smh_close(long fd);
+
+#endif /* _SEMIHOSTING_H_ */
--

2.17.1

#4 lore raw

PATCH 2/8 semihosting: Add support for writing to a file

In reply to Sughosh Ganu

Add a function to enable writing to a file. Currently, support is added for writing to a binary file. This would be used for implementing the firmware update functionality for the qemu arm64 platform.

---
 arch/arm/lib/semihosting.c | 41 ++++++++++++++++++++++++++++++++++++--
 include/semihosting.h      |  1 +
 2 files changed, 40 insertions(+), 2 deletions(-)
arch/arm/lib/semihosting.c +39 -2
index 3aeda1303a..08181132d1 100644
@@ -17,11 +17,18 @@
 
 #define SYSOPEN		0x01
 #define SYSCLOSE	0x02
+#define SYSWRITE	0x5
 #define SYSREAD		0x06
 #define SYSFLEN		0x0C
 
-#define MODE_READ	0x0
-#define MODE_READBIN	0x1
+#define MODE_READ		0x0
+#define MODE_READBIN		0x1
+#define MODE_READPLUS		0x2
+#define MODE_READPLUSBIN	0x3
+#define MODE_WRITE		0x4
+#define MODE_WRITEBIN		0x5
+#define MODE_WRITEPLUS		0x6
+#define MODE_WRITEPLUSBIN	0x7
 
 /*
  * Call the handler
@@ -61,6 +68,8 @@ long smh_open(const char *fname, char *modestr)
 		mode = MODE_READ;
 	} else if (!(strcmp(modestr, "rb"))) {
 		mode = MODE_READBIN;
+	} else if (!strcmp(modestr, "w+b")) {
+		mode = MODE_WRITEPLUSBIN;
 	} else {
 		printf("%s: ERROR mode \'%s\' not supported\n", __func__,
 		       modestr);
@@ -114,6 +123,34 @@ long smh_read(long fd, void *memp, size_t len)
 	return 0;
 }
 
+/*
+ * Write 'len' bytes into the file referenced by the fd. Returns 0 on success, else
+ * a negavite value for failure
+ */
+long smh_write(long fd, void *memp, size_t len)
+{
+	long ret;
+	struct smh_write_s {
+		long fd;
+		void *memp;
+		size_t len;
+	} write;
+
+	debug("%s: fd %ld, memp %p, len %zu\n", __func__, fd, memp, len);
+
+	write.fd = fd;
+	write.memp = memp;
+	write.len = len;
+
+	ret = smh_trap(SYSWRITE, &write);
+
+	if (ret > 0)
+		printf("%s: ERROR ret %ld, fd %ld, len %zu, memp %p\n",
+		       __func__, ret, fd, len, memp);
+
+	return ret == 0 ? 0 : -1;
+}
+
 /*
  * Close the file using the file descriptor
  */
include/semihosting.h +1 -0
index f1bf419275..fa5cecddf2 100644
@@ -8,6 +8,7 @@
 
 long smh_open(const char *fname, char *modestr);
 long smh_read(long fd, void *memp, size_t len);
+long smh_write(long fd, void *memp, size_t len);
 long smh_close(long fd);
 
 #endif /* _SEMIHOSTING_H_ */
Signature · 1 line
2.17.1
#5 lore raw

PATCH 2/8 semihosting: Add support for writing to a file

Quoted 37 lines · Sughosh Ganu

Add a function to enable writing to a file. Currently, support is added for writing to a binary file. This would be used for implementing the firmware update functionality for the qemu arm64 platform.

---
 arch/arm/lib/semihosting.c | 41 ++++++++++++++++++++++++++++++++++++--
 include/semihosting.h      |  1 +
 2 files changed, 40 insertions(+), 2 deletions(-)
arch/arm/lib/semihosting.c +9 -2
index 3aeda1303a..08181132d1 100644
@@ -17,11 +17,18 @@
 
 #define SYSOPEN		0x01
 #define SYSCLOSE	0x02
+#define SYSWRITE	0x5
 #define SYSREAD		0x06
 #define SYSFLEN		0x0C
 
-#define MODE_READ	0x0
-#define MODE_READBIN	0x1
+#define MODE_READ		0x0
+#define MODE_READBIN		0x1
+#define MODE_READPLUS		0x2
+#define MODE_READPLUSBIN	0x3
+#define MODE_WRITE		0x4
+#define MODE_WRITEBIN		0x5
+#define MODE_WRITEPLUS		0x6
+#define MODE_WRITEPLUSBIN	0x7
 
 /*
  * Call the handler

arch/arm/lib/semihosting.c long smh_open(const char *fname, char *modestr) · line 72

Quoted 5 lines
arch/arm/lib/semihosting.c +2 -0
@@ -61,6 +68,8 @@ long smh_open(const char *fname, char *modestr)
 		mode = MODE_READ;
 	} else if (!(strcmp(modestr, "rb"))) {
 		mode = MODE_READBIN;
+	} else if (!strcmp(modestr, "w+b")) {
+		mode = MODE_WRITEPLUSBIN;

We could have a string matching each of the 8 constants above:

static char modes[] = "r\0\0\0rb\0\0r+\0\0r+b\0w\0\0\0wb\0\0w+\0\0w+b"; // This should use less bytes than 8 separate strings.

        for (mode = 0; mode < 8; ++mode) {
                if (!strcmp(&modes[4 * mode], modestr))
                        break;
        }
        if (mode & 8)
		printf("%s: ERROR mode \'%s\' not supported\n" ...

But why are we passing the mode as string anyway?
We should use an enum parameter instead.

Best regards

Heinrich

Quoted 51 lines
arch/arm/lib/semihosting.c +28 -0
 	} else {
 		printf("%s: ERROR mode \'%s\' not supported\n", __func__,
 		       modestr);
@@ -114,6 +123,34 @@ long smh_read(long fd, void *memp, size_t len)
 	return 0;
 }
 
+/*
+ * Write 'len' bytes into the file referenced by the fd. Returns 0 on success, else
+ * a negavite value for failure
+ */
+long smh_write(long fd, void *memp, size_t len)
+{
+	long ret;
+	struct smh_write_s {
+		long fd;
+		void *memp;
+		size_t len;
+	} write;
+
+	debug("%s: fd %ld, memp %p, len %zu\n", __func__, fd, memp, len);
+
+	write.fd = fd;
+	write.memp = memp;
+	write.len = len;
+
+	ret = smh_trap(SYSWRITE, &write);
+
+	if (ret > 0)
+		printf("%s: ERROR ret %ld, fd %ld, len %zu, memp %p\n",
+		       __func__, ret, fd, len, memp);
+
+	return ret == 0 ? 0 : -1;
+}
+
 /*
  * Close the file using the file descriptor
  */
include/semihosting.h +1 -0
index f1bf419275..fa5cecddf2 100644
@@ -8,6 +8,7 @@
 
 long smh_open(const char *fname, char *modestr);
 long smh_read(long fd, void *memp, size_t len);
+long smh_write(long fd, void *memp, size_t len);
 long smh_close(long fd);
 
 #endif /* _SEMIHOSTING_H_ */
#6 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

In reply to Sughosh Ganu

Add support for the get_image_info and set_image routines, which are part of the efi firmware management protocol.

The current implementation uses the set_image routine for updating the u-boot binary image for the qemu arm64 platform. This is supported using the capsule-on-disk feature of the uefi specification, wherein the firmware image to be updated is placed on the efi system partition as a efi capsule under EFI/UpdateCapsule/ directory. Support has been added for updating the u-boot image on platforms booting with arm trusted firmware(tf-a), where the u-boot image gets booted as the BL33 payload(bl33.bin).

The feature can be enabled by the following config options

CONFIG_EFI_CAPSULE_ON_DISK=y
CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y

---
 board/emulation/qemu-arm/Kconfig        |  12 ++
 board/emulation/qemu-arm/Makefile       |   1 +
 board/emulation/qemu-arm/qemu_efi_fmp.c | 210 ++++++++++++++++++++++++
 3 files changed, 223 insertions(+)
 create mode 100644 board/emulation/qemu-arm/qemu_efi_fmp.c
board/emulation/qemu-arm/Kconfig +12 -0
index 02ae4d9884..f1b2de8e41 100644
@@ -11,3 +11,15 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	imply VIRTIO_BLK
 
 endif
+
+if TARGET_QEMU_ARM_64BIT && TFABOOT
+
+config EFI_FIRMWARE_MANAGEMENT_PROTOCOL
+	bool "EFI Firmware Management protocol for Qemu arm64 platform"
+	depends on EFI_CAPSULE_ON_DISK
+	default n
+	help
+	  Select this option for enabling firmware management protocol
+	  for qemu arm64 platform
+
+endif
board/emulation/qemu-arm/Makefile +1 -0
index a22d1237ff..c95ac6d233 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 obj-y	+= qemu-arm.o
+obj-$(CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL) += qemu_efi_fmp.o
board/emulation/qemu-arm/qemu_efi_fmp.c new file +210 -0

210 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

Quoted 12 lines · Sughosh Ganu

Add support for the get_image_info and set_image routines, which are part of the efi firmware management protocol.

The current implementation uses the set_image routine for updating the u-boot binary image for the qemu arm64 platform. This is supported using the capsule-on-disk feature of the uefi specification, wherein the firmware image to be updated is placed on the efi system partition as a efi capsule under EFI/UpdateCapsule/ directory. Support has been added for updating the u-boot image on platforms booting with arm trusted firmware(tf-a), where the u-boot image gets booted as the BL33 payload(bl33.bin).

Quoted 6 lines

The feature can be enabled by the following config options

CONFIG_EFI_CAPSULE_ON_DISK=y
CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y

U-Boot's UEFI subsystem should work in the same way for x86, ARM, and RISC-V. Please, come up with an architecture independent solution.

Best regards

Heinrich

Quoted 253 lines
---
 board/emulation/qemu-arm/Kconfig        |  12 ++
 board/emulation/qemu-arm/Makefile       |   1 +
 board/emulation/qemu-arm/qemu_efi_fmp.c | 210 ++++++++++++++++++++++++
 3 files changed, 223 insertions(+)
 create mode 100644 board/emulation/qemu-arm/qemu_efi_fmp.c
board/emulation/qemu-arm/Kconfig +12 -0
index 02ae4d9884..f1b2de8e41 100644
@@ -11,3 +11,15 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	imply VIRTIO_BLK
 
 endif
+
+if TARGET_QEMU_ARM_64BIT && TFABOOT
+
+config EFI_FIRMWARE_MANAGEMENT_PROTOCOL
+	bool "EFI Firmware Management protocol for Qemu arm64 platform"
+	depends on EFI_CAPSULE_ON_DISK
+	default n
+	help
+	  Select this option for enabling firmware management protocol
+	  for qemu arm64 platform
+
+endif
board/emulation/qemu-arm/Makefile +1 -0
index a22d1237ff..c95ac6d233 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 obj-y	+= qemu-arm.o
+obj-$(CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL) += qemu_efi_fmp.o
board/emulation/qemu-arm/qemu_efi_fmp.c new file +210 -0
new file mode 100644
index 0000000000..9baea94e6c
@@ -0,0 +1,210 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020, Linaro Limited
+ */
+
+#include <common.h>
+#include <charset.h>
+#include <efi_api.h>
+#include <efi_loader.h>
+#include <malloc.h>
+#include <semihosting.h>
+
+#define QEMU_UBOOT_IMAGE_INDEX	0x1
+#define QEMU_UBOOT_IMAGE	0x1
+
+#define UBOOT_FILE		"bl33.bin"
+
+#define EFI_FMP_QEMU_ARM64_UBOOT_CAPSULE_ID_GUID \
+	EFI_GUID(0xfb90808a, 0xba9a, 0x4d42, 0xb9, 0xa2, \
+		 0xa7, 0xa9, 0x37, 0x14, 0x4a, 0xee)
+
+/**
+ * qemu_arm64_fmp_get_image_info() - Implement get_image_info
+ *
+ * @this:			instance of the efi_firmware_management_protocol
+ * @image_info_size:		pointer to the size of image_info buffer
+ * @image_info:			pointer to buffer which contains info on the
+ *				image
+ * @desc_version:		pointer to version number of the
+ *				efi_firmware_image_descriptor
+ * @desc_count:			pointer to the number of descriptors of the
+ *				firmware images on the device
+ * @desc_size:			pointer to the size of an individual descriptor
+ * @package_version:		version for all firmware images on the device
+ * @package_version_name:	string representing the package version name
+ *
+ * Implement the get_image_info function of the
+ * efi_firmware_management_protocol for the platform.
+ *
+ * Return: status code
+ */
+static efi_status_t EFIAPI qemu_arm64_fmp_get_image_info(
+	struct efi_firmware_management_protocol *this,
+	efi_uintn_t *image_info_size,
+	struct efi_firmware_image_descriptor *image_info,
+	u32 *desc_version, u8 *desc_count,
+	efi_uintn_t *desc_size, u32 *package_version,
+	u16 **package_version_name)
+{
+	efi_status_t status = EFI_SUCCESS;
+	u16 *image_id_name;
+	const char *image_name = "Qemu Aarch64 U-Boot";
+	const efi_guid_t image_guid = EFI_FMP_QEMU_ARM64_UBOOT_CAPSULE_ID_GUID;
+
+	EFI_ENTRY("%p %p %p %p %p %p %p %p\n", this, image_info_size,
+		  image_info, desc_version, desc_count, desc_size,
+		  package_version, package_version_name);
+
+	/* Sanity checks */
+	if (*image_info_size && !image_info) {
+		status = EFI_INVALID_PARAMETER;
+		goto back;
+	}
+
+	if (*image_info_size &&
+	    (!desc_version || !desc_count || !desc_size)) {
+		status = EFI_INVALID_PARAMETER;
+		goto back;
+	}
+
+	if (*image_info_size < sizeof(*image_info)) {
+		*image_info_size = sizeof(*image_info);
+		status = EFI_BUFFER_TOO_SMALL;
+		goto back;
+	}
+
+	if (desc_version)
+		*desc_version = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;
+
+	*desc_count = 0x1;
+	*desc_size = sizeof(*image_info);
+
+	if (package_version)
+		*package_version = 0xffffffff;
+
+	if (package_version_name)
+		*package_version_name = NULL;
+
+	image_info[0].image_type_id = image_guid;
+	image_info[0].image_id = QEMU_UBOOT_IMAGE;
+
+	image_id_name = malloc(40);
+	utf8_utf16_strcpy(&image_id_name, image_name);
+	image_info[0].image_id_name = image_id_name;
+
+	/* Todo: Get a mechanism to store version information */
+	image_info[0]. version = 0x1;
+	image_info[0].version_name = NULL;
+
+	/* Todo: Need to find a mechanism to get the image size */
+	image_info[0].size = 0;
+
+	image_info[0].attributes_supported =
+		EFI_IMAGE_ATTRIBUTE_IMAGE_UPDATABLE;
+	image_info[0].attributes_setting = EFI_IMAGE_ATTRIBUTE_IMAGE_UPDATABLE;
+
+	image_info[0].lowest_supported_image_version = 1;
+	image_info[0].last_attempt_version = 0;
+	image_info[0].last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS;
+	image_info[0].hardware_instance = 0;
+
+back:
+	return EFI_EXIT(status);
+}
+
+/**
+ * qemu_arm64_fmp_set_image() - Implement set_image
+ *
+ * @this:			instance of the efi_firmware_management_protocol
+ * @image_index:		a unique number identifying the firmware image
+ * @image:			pointer to the buffer containing the firmware
+ *				image to be updated
+ * @image_size:			pointer to size of the firmware image
+ * @vendor_code:		pointer to the vendor specific update policy
+ * @completion:			function pointer that can be invoked to report
+ *				firmware update progress
+ * @abort_reason:		string providing details if update is aborted
+ *
+ * Implement the set_image function of the efi_firmware_management_protocol
+ * for the platform. This updates the firmware image and authenticates the
+ * capsule, if authentication is enabled
+ *
+ * Return: status code
+ */
+static efi_status_t EFIAPI qemu_arm64_fmp_set_image(
+	struct efi_firmware_management_protocol *this,
+	u8 image_index, const void *image,
+	efi_uintn_t image_size, const void *vendor_code,
+	efi_status_t (*progress)(efi_uintn_t completion),
+	u16 **abort_reason)
+{
+	long fd, ret;
+	efi_status_t status = EFI_SUCCESS;
+	char *mode = "w+b";
+
+	EFI_ENTRY("%p %d %p %ld %p %p %p\n", this, image_index, image,
+		  image_size, vendor_code, progress, abort_reason);
+
+	/*
+	 * Put a hack here to offset the size of
+	 * the FMP_PAYLOAD_HEADER that gets added
+	 * by the GenerateCapsule script in edk2.
+	 */
+	image += 0x10;
+	image_size -= 0x10;
+
+	/* Do all the sanity checks first */
+	if (!image) {
+		status = EFI_INVALID_PARAMETER;
+		goto back;
+	}
+
+	if (image_size == 0) {
+		status = EFI_INVALID_PARAMETER;
+		goto back;
+	}
+
+	if (image_index != QEMU_UBOOT_IMAGE_INDEX) {
+		status = EFI_INVALID_PARAMETER;
+		goto back;
+	}
+
+	/* Do the update */
+	fd = smh_open(UBOOT_FILE, mode);
+	if (fd == -1) {
+		printf("Unable to open the firmware image for writing\n");
+		status = EFI_DEVICE_ERROR;
+		goto back;
+	}
+
+	ret = smh_write(fd, (void *)image, image_size);
+	if (ret == -1) {
+		printf("Error writing to the firmware image!");
+		smh_close(fd);
+		status = EFI_DEVICE_ERROR;
+		goto back;
+	}
+
+	printf("Capsule Update Complete\n");
+	smh_close(fd);
+back:
+	return EFI_EXIT(status);
+}
+
+const struct efi_firmware_management_protocol efi_qemu_arm64_fmp = {
+	.get_image_info = qemu_arm64_fmp_get_image_info,
+	.set_image = qemu_arm64_fmp_set_image,
+};
+
+efi_status_t arch_efi_load_capsule_drivers(void)
+{
+	efi_status_t ret;
+
+	ret = EFI_CALL(efi_install_multiple_protocol_interfaces(&efi_root,
+					&efi_guid_firmware_management_protocol,
+					&efi_qemu_arm64_fmp,
+					NULL));
+
+	return ret;
+}
#8 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

Quoted 15 lines · Heinrich Schuchardt
Quoted 14 lines · Sughosh Ganu

Add support for the get_image_info and set_image routines, which are part of the efi firmware management protocol.

The current implementation uses the set_image routine for updating the u-boot binary image for the qemu arm64 platform. This is supported using the capsule-on-disk feature of the uefi specification, wherein the firmware image to be updated is placed on the efi system partition as a efi capsule under EFI/UpdateCapsule/ directory. Support has been added for updating the u-boot image on platforms booting with arm trusted firmware(tf-a), where the u-boot image gets booted as the BL33 payload(bl33.bin).

The feature can be enabled by the following config options

Quoted 8 lines
Quoted 4 lines

CONFIG_EFI_CAPSULE_ON_DISK=y
CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y

U-Boot's UEFI subsystem should work in the same way for x86, ARM, and RISC-V. Please, come up with an architecture independent solution.

Please check the explanation that I gave in the other mail. If you check the patch series, the actual capsule authentication logic has been kept architecture agnostic, in efi_capsule.c. The fmp protocol is very much intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

-sughosh

Quoted 281 lines

Best regards

Heinrich

Review

Quoted 8 lines
---
 board/emulation/qemu-arm/Kconfig        |  12 ++
 board/emulation/qemu-arm/Makefile       |   1 +
 board/emulation/qemu-arm/qemu_efi_fmp.c | 210 ++++++++++++++++++++++++
 3 files changed, 223 insertions(+)
 create mode 100644 board/emulation/qemu-arm/qemu_efi_fmp.c
(quoted diff) +0 -0

b/board/emulation/qemu-arm/Kconfig

Review

Quoted 20 lines

index 02ae4d9884..f1b2de8e41 100644

board/emulation/qemu-arm/Kconfig +12 -0
@@ -11,3 +11,15 @@ config BOARD_SPECIFIC_OPTIONS # dummy
      imply VIRTIO_BLK
 
 endif
+
+if TARGET_QEMU_ARM_64BIT && TFABOOT
+
+config EFI_FIRMWARE_MANAGEMENT_PROTOCOL
+     bool "EFI Firmware Management protocol for Qemu arm64 platform"
+     depends on EFI_CAPSULE_ON_DISK
+     default n
+     help
+       Select this option for enabling firmware management protocol
+       for qemu arm64 platform
+
+endif
(quoted diff) +0 -0

b/board/emulation/qemu-arm/Makefile

Review

Quoted 9 lines

index a22d1237ff..c95ac6d233 100644

board/emulation/qemu-arm/Makefile +1 -0
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 obj-y        += qemu-arm.o
+obj-$(CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL) += qemu_efi_fmp.o
(quoted diff) +0 -0

b/board/emulation/qemu-arm/qemu_efi_fmp.c

Quoted 20 lines

new file mode 100644
index 0000000000..9baea94e6c

board/emulation/qemu-arm/qemu_efi_fmp.c new file +15 -0
@@ -0,0 +1,210 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020, Linaro Limited
+ */
+
+#include <common.h>
+#include <charset.h>
+#include <efi_api.h>
+#include <efi_loader.h>
+#include <malloc.h>
+#include <semihosting.h>
+
+#define QEMU_UBOOT_IMAGE_INDEX       0x1
+#define QEMU_UBOOT_IMAGE     0x1
+

board/emulation/qemu-arm/qemu_efi_fmp.c line 25

Quoted 10 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +10 -0
+#define UBOOT_FILE           "bl33.bin"
+
+#define EFI_FMP_QEMU_ARM64_UBOOT_CAPSULE_ID_GUID \
+     EFI_GUID(0xfb90808a, 0xba9a, 0x4d42, 0xb9, 0xa2, \
+              0xa7, 0xa9, 0x37, 0x14, 0x4a, 0xee)
+
+/**
+ * qemu_arm64_fmp_get_image_info() - Implement get_image_info
+ *
+ * @this:                    instance of the

efi_firmware_management_protocol

board/emulation/qemu-arm/qemu_efi_fmp.c line 27

Quoted 2 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +2 -0
+ * @image_info_size:         pointer to the size of image_info buffer
+ * @image_info:                      pointer to buffer which contains

info on the

board/emulation/qemu-arm/qemu_efi_fmp.c

Quoted 4 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +4 -0
+ *                           image
+ * @desc_version:            pointer to version number of the
+ *                           efi_firmware_image_descriptor
+ * @desc_count:                      pointer to the number of

descriptors of the

board/emulation/qemu-arm/qemu_efi_fmp.c line 33

Quoted 2 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +2 -0
+ *                           firmware images on the device
+ * @desc_size:                       pointer to the size of an

individual descriptor

board/emulation/qemu-arm/qemu_efi_fmp.c line 34

Quoted 1 line
board/emulation/qemu-arm/qemu_efi_fmp.c new file +1 -0
+ * @package_version:         version for all firmware images on the

device

board/emulation/qemu-arm/qemu_efi_fmp.c line 35

Quoted 1 line
board/emulation/qemu-arm/qemu_efi_fmp.c new file +1 -0
+ * @package_version_name:    string representing the package version

name

Quoted 8 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +8 -0
+ *
+ * Implement the get_image_info function of the
+ * efi_firmware_management_protocol for the platform.
+ *
+ * Return: status code
+ */
+static efi_status_t EFIAPI qemu_arm64_fmp_get_image_info(
+     struct efi_firmware_management_protocol *this,

board/emulation/qemu-arm/qemu_efi_fmp.c

Quoted 10 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +10 -0
+     efi_uintn_t *image_info_size,
+     struct efi_firmware_image_descriptor *image_info,
+     u32 *desc_version, u8 *desc_count,
+     efi_uintn_t *desc_size, u32 *package_version,
+     u16 **package_version_name)
+{
+     efi_status_t status = EFI_SUCCESS;
+     u16 *image_id_name;
+     const char *image_name = "Qemu Aarch64 U-Boot";
+     const efi_guid_t image_guid =

EFI_FMP_QEMU_ARM64_UBOOT_CAPSULE_ID_GUID;

Quoted 42 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +42 -0
+
+     EFI_ENTRY("%p %p %p %p %p %p %p %p\n", this, image_info_size,
+               image_info, desc_version, desc_count, desc_size,
+               package_version, package_version_name);
+
+     /* Sanity checks */
+     if (*image_info_size && !image_info) {
+             status = EFI_INVALID_PARAMETER;
+             goto back;
+     }
+
+     if (*image_info_size &&
+         (!desc_version || !desc_count || !desc_size)) {
+             status = EFI_INVALID_PARAMETER;
+             goto back;
+     }
+
+     if (*image_info_size < sizeof(*image_info)) {
+             *image_info_size = sizeof(*image_info);
+             status = EFI_BUFFER_TOO_SMALL;
+             goto back;
+     }
+
+     if (desc_version)
+             *desc_version = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;
+
+     *desc_count = 0x1;
+     *desc_size = sizeof(*image_info);
+
+     if (package_version)
+             *package_version = 0xffffffff;
+
+     if (package_version_name)
+             *package_version_name = NULL;
+
+     image_info[0].image_type_id = image_guid;
+     image_info[0].image_id = QEMU_UBOOT_IMAGE;
+
+     image_id_name = malloc(40);
+     utf8_utf16_strcpy(&image_id_name, image_name);
+     image_info[0].image_id_name = image_id_name;
+

board/emulation/qemu-arm/qemu_efi_fmp.c

Quoted 10 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +10 -0
+     /* Todo: Get a mechanism to store version information */
+     image_info[0]. version = 0x1;
+     image_info[0].version_name = NULL;
+
+     /* Todo: Need to find a mechanism to get the image size */
+     image_info[0].size = 0;
+
+     image_info[0].attributes_supported =
+             EFI_IMAGE_ATTRIBUTE_IMAGE_UPDATABLE;
+     image_info[0].attributes_setting =

EFI_IMAGE_ATTRIBUTE_IMAGE_UPDATABLE;

Quoted 4 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +4 -0
+
+     image_info[0].lowest_supported_image_version = 1;
+     image_info[0].last_attempt_version = 0;
+     image_info[0].last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS;

board/emulation/qemu-arm/qemu_efi_fmp.c

Quoted 10 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +10 -0
+     image_info[0].hardware_instance = 0;
+
+back:
+     return EFI_EXIT(status);
+}
+
+/**
+ * qemu_arm64_fmp_set_image() - Implement set_image
+ *
+ * @this:                    instance of the

efi_firmware_management_protocol

board/emulation/qemu-arm/qemu_efi_fmp.c line 120

Quoted 1 line
board/emulation/qemu-arm/qemu_efi_fmp.c new file +1 -0
+ * @image_index:             a unique number identifying the firmware

image

board/emulation/qemu-arm/qemu_efi_fmp.c line 121

Quoted 1 line
board/emulation/qemu-arm/qemu_efi_fmp.c new file +1 -0
+ * @image:                   pointer to the buffer containing the

firmware

board/emulation/qemu-arm/qemu_efi_fmp.c line 123

Quoted 2 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +2 -0
+ *                           image to be updated
+ * @image_size:                      pointer to size of the firmware

image

board/emulation/qemu-arm/qemu_efi_fmp.c line 124

Quoted 1 line
board/emulation/qemu-arm/qemu_efi_fmp.c new file +1 -0
+ * @vendor_code:             pointer to the vendor specific update

policy

board/emulation/qemu-arm/qemu_efi_fmp.c line 125

Quoted 1 line
board/emulation/qemu-arm/qemu_efi_fmp.c new file +1 -0
+ * @completion:                      function pointer that can be

invoked to report

board/emulation/qemu-arm/qemu_efi_fmp.c line 127

Quoted 2 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +2 -0
+ *                           firmware update progress
+ * @abort_reason:            string providing details if update is

aborted

board/emulation/qemu-arm/qemu_efi_fmp.c line 129

Quoted 2 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +2 -0
+ *
+ * Implement the set_image function of the

efi_firmware_management_protocol

board/emulation/qemu-arm/qemu_efi_fmp.c line 130

Quoted 1 line
board/emulation/qemu-arm/qemu_efi_fmp.c new file +1 -0
+ * for the platform. This updates the firmware image and authenticates

the

Quoted 65 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +65 -0
+ * capsule, if authentication is enabled
+ *
+ * Return: status code
+ */
+static efi_status_t EFIAPI qemu_arm64_fmp_set_image(
+     struct efi_firmware_management_protocol *this,
+     u8 image_index, const void *image,
+     efi_uintn_t image_size, const void *vendor_code,
+     efi_status_t (*progress)(efi_uintn_t completion),
+     u16 **abort_reason)
+{
+     long fd, ret;
+     efi_status_t status = EFI_SUCCESS;
+     char *mode = "w+b";
+
+     EFI_ENTRY("%p %d %p %ld %p %p %p\n", this, image_index, image,
+               image_size, vendor_code, progress, abort_reason);
+
+     /*
+      * Put a hack here to offset the size of
+      * the FMP_PAYLOAD_HEADER that gets added
+      * by the GenerateCapsule script in edk2.
+      */
+     image += 0x10;
+     image_size -= 0x10;
+
+     /* Do all the sanity checks first */
+     if (!image) {
+             status = EFI_INVALID_PARAMETER;
+             goto back;
+     }
+
+     if (image_size == 0) {
+             status = EFI_INVALID_PARAMETER;
+             goto back;
+     }
+
+     if (image_index != QEMU_UBOOT_IMAGE_INDEX) {
+             status = EFI_INVALID_PARAMETER;
+             goto back;
+     }
+
+     /* Do the update */
+     fd = smh_open(UBOOT_FILE, mode);
+     if (fd == -1) {
+             printf("Unable to open the firmware image for writing\n");
+             status = EFI_DEVICE_ERROR;
+             goto back;
+     }
+
+     ret = smh_write(fd, (void *)image, image_size);
+     if (ret == -1) {
+             printf("Error writing to the firmware image!");
+             smh_close(fd);
+             status = EFI_DEVICE_ERROR;
+             goto back;
+     }
+
+     printf("Capsule Update Complete\n");
+     smh_close(fd);
+back:
+     return EFI_EXIT(status);
+}
+
+const struct efi_firmware_management_protocol efi_qemu_arm64_fmp = {

board/emulation/qemu-arm/qemu_efi_fmp.c line 208

Quoted 10 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +10 -0
+     .get_image_info = qemu_arm64_fmp_get_image_info,
+     .set_image = qemu_arm64_fmp_set_image,
+};
+
+efi_status_t arch_efi_load_capsule_drivers(void)
+{
+     efi_status_t ret;
+
+     ret = EFI_CALL(efi_install_multiple_protocol_interfaces(&efi_root,
+

&efi_guid_firmware_management_protocol,

Quoted 6 lines
board/emulation/qemu-arm/qemu_efi_fmp.c new file +5 -0
+                                     &efi_qemu_arm64_fmp,
+                                     NULL));
+
+     return ret;
+}
#9 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

Quoted 36 lines · Sughosh Ganu

On Fri, 1 May 2020 at 00:09, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

On 4/30/20 7:36 PM, Sughosh Ganu wrote:
> Add support for the get_image_info and set_image routines, which are > part of the efi firmware management protocol.
>
> The current implementation uses the set_image routine for updating the > u-boot binary image for the qemu arm64 platform. This is supported > using the capsule-on-disk feature of the uefi specification, wherein > the firmware image to be updated is placed on the efi system partition > as a efi capsule under EFI/UpdateCapsule/ directory. Support has been > added for updating the u-boot image on platforms booting with arm > trusted firmware(tf-a), where the u-boot image gets booted as the BL33 > payload(bl33.bin).
>
> The feature can be enabled by the following config options >
> CONFIG_EFI_CAPSULE_ON_DISK=y
> CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
>
> Signed-off-by: Sughosh Ganu <[email protected] <mailto:[email protected]>>

U-Boot's UEFI subsystem should work in the same way for x86, ARM, and RISC-V. Please, come up with an architecture independent solution.

Please check the explanation that I gave in the other mail. If you check the patch series, the actual capsule authentication logic has been kept architecture agnostic, in efi_capsule.c. The fmp protocol is very much intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

Quoted 3 lines

-sughosh
?

My idea is that for most platforms it will be enough to have a common FMP implementation that consumes a capsule

* with one or more binaries
* a media device path, a start address, and a truncation flag for each of the binaries

The protocol implementation then will write the binaries to the device paths:

* to an SD-Card or eMMC exposing the Block IO protocol for most devices
* to a file in case of the Raspberry Pi or the Sandbox or QEMU (and truncate it if the truncation flag is set)

If for some devices like a SPI flash we do not have a media device path yet, then the only platform specific bit would be the block device driver exposing the media device path.

Same with a semi-hosted file: just add a driver exposing it as a media path with an EFI_BLOCK_IO_PROTOCOL.

For security reasons it may be advisable to make the device read-only when reaching ExitBootServices() or even better before the first execution of StartImage(). For this purpose we could use the Reset() service of the EFI_BLOCK_IO_PROTOCOL or provide a U-Boot specific service in the EFI_BLOCK_IO_PROTOCOL.

Best regards

Heinrich

#10 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

Quoted 48 lines · Heinrich Schuchardt
Quoted 29 lines · Sughosh Ganu

On Fri, 1 May 2020 at 00:09, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

On 4/30/20 7:36 PM, Sughosh Ganu wrote:
> Add support for the get_image_info and set_image routines, which are > part of the efi firmware management protocol.
>
> The current implementation uses the set_image routine for updating the > u-boot binary image for the qemu arm64 platform. This is supported > using the capsule-on-disk feature of the uefi specification, wherein > the firmware image to be updated is placed on the efi system partition > as a efi capsule under EFI/UpdateCapsule/ directory. Support has been > added for updating the u-boot image on platforms booting with arm > trusted firmware(tf-a), where the u-boot image gets booted as the BL33 > payload(bl33.bin).
>
> The feature can be enabled by the following config options >
> CONFIG_EFI_CAPSULE_ON_DISK=y
> CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
>
> Signed-off-by: Sughosh Ganu <[email protected] <mailto:[email protected]>>

U-Boot's UEFI subsystem should work in the same way for x86, ARM, and RISC-V. Please, come up with an architecture independent solution.

Quoted 10 lines

Please check the explanation that I gave in the other mail. If you check the patch series, the actual capsule authentication logic has been kept architecture agnostic, in efi_capsule.c. The fmp protocol is very much intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

-sughosh

My idea is that for most platforms it will be enough to have a common FMP implementation that consumes a capsule

* with one or more binaries
* a media device path, a start address, and a truncation flag for each of the binaries

Quoted 7 lines

The protocol implementation then will write the binaries to the device paths:

* to an SD-Card or eMMC exposing the Block IO protocol for most devices
* to a file in case of the Raspberry Pi or the Sandbox or QEMU (and truncate it if the truncation flag is set)

Does U-Boot have a common device path protocol that can be backed by either a block device or a file on a filesystem? I didn't think it did.

In the mean time, there are at least three backends that the FMP is going to have to deal with; the two you list above (block device & file) and SMC backed when updating firmware is managed by the secure world. This first implementation only handles the file-backed use case. Can we start with that limitation and refactor when the block-device and SMC use cases are added in? I would hate to see this functionality held up on having to refactor other functionality in U-Boot.

Quoted 6 lines

If for some devices like a SPI flash we do not have a media device path yet, then the only platform specific bit would be the block device driver exposing the media device path.

Same with a semi-hosted file: just add a driver exposing it as a media path with an EFI_BLOCK_IO_PROTOCOL.

Sughosh and I chatted about this and took a look a the semihosting driver. Right now it is a standalone component implementing only the smhload command. It looks like it easily maps onto fstype_info operations which would be a better fit than the block IO protocol. Am I correct in assuming that would also make semihosting available to the EFI_FILE_PROTOCOL? The FMP backend code could be common for all filesystem targets, with the only platform specific bit being the path to the firmware files.

How does that sound?

g.

Quoted 10 lines

For security reasons it may be advisable to make the device read-only when reaching ExitBootServices() or even better before the first execution of StartImage(). For this purpose we could use the Reset() service of the EFI_BLOCK_IO_PROTOCOL or provide a U-Boot specific service in the EFI_BLOCK_IO_PROTOCOL.

Best regards

Heinrich

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#11 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

Quoted 62 lines · Grant Likely
Quoted 59 lines · Heinrich Schuchardt
Quoted 37 lines · Sughosh Ganu

On Fri, 1 May 2020 at 00:09, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

???? On 4/30/20 7:36 PM, Sughosh Ganu wrote:
???? > Add support for the get_image_info and set_image routines, which are
???? > part of the efi firmware management protocol.
???? >
???? > The current implementation uses the set_image routine for updating the
???? > u-boot binary image for the qemu arm64 platform. This is supported
???? > using the capsule-on-disk feature of the uefi specification, wherein
???? > the firmware image to be updated is placed on the efi system partition
???? > as a efi capsule under EFI/UpdateCapsule/ directory. Support has been
???? > added for updating the u-boot image on platforms booting with arm ???? > trusted firmware(tf-a), where the u-boot image gets booted as the BL33
???? > payload(bl33.bin).
???? >
???? > The feature can be enabled by the following config options ???? >
???? > CONFIG_EFI_CAPSULE_ON_DISK=y
???? > CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
???? >
???? > Signed-off-by: Sughosh Ganu <[email protected] ???? <mailto:[email protected]>>

???? U-Boot's UEFI subsystem should work in the same way for x86, ARM, and
???? RISC-V. Please, come up with an architecture independent solution.

Quoted 10 lines

Please check the explanation that I gave in the other mail. If you check the patch series, the actual capsule authentication logic has been kept architecture agnostic, in efi_capsule.c. The fmp protocol is very much intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

-sughosh

My idea is that for most platforms it will be enough to have a common FMP implementation that consumes a capsule

* with one or more binaries
* a media device path, a start address, and a truncation flag ?? for each of the binaries

The protocol implementation then will write the binaries to the device paths:

Quoted 7 lines
Quoted 4 lines

* to an SD-Card or eMMC exposing the Block IO protocol ?? for most devices
* to a file in case of the Raspberry Pi or the Sandbox or QEMU ?? (and truncate it if the truncation flag is set)

Does U-Boot have a common device path protocol that can be backed by either a block device or a file on a filesystem? I didn't think it did.

A block device, a partition, and a file all can be described by an UEFI media device path.

Quoted 8 lines

In the mean time, there are at least three backends that the FMP is going to have to deal with; the two you list above (block device & file) and SMC backed when updating firmware is managed by the secure world. This first implementation only handles the file-backed use case. Can we start with that limitation and refactor when the block-device and SMC use cases are added in? I would hate to see this functionality held up on having to refactor other functionality in U-Boot.

I would prefer one single FMP driver for all SMC use cases. Everything device specific should be handled in the secure world.

Is there already a protocol defined for the communication of capsule updates between the firmware and the secure monitor, e.g. in EDK2?

Would we simply use the UpdateCapsule() call parameters and pass them via an SMC call?

Quoted 8 lines
Quoted 7 lines

If for some devices like a SPI flash we do not have a media device path yet, then the only platform specific bit would be the block device driver exposing the media device path.

Same with a semi-hosted file: just add a driver exposing it as a media path with an EFI_BLOCK_IO_PROTOCOL.

Quoted 8 lines

Sughosh and I chatted about this and took a look a the semihosting driver. Right now it is a standalone component implementing only the smhload command. It looks like it easily maps onto fstype_info operations which would be a better fit than the block IO protocol. Am I correct in assuming that would also make semihosting available to the EFI_FILE_PROTOCOL? The FMP backend code could be common for all filesystem targets, with the only platform specific bit being the path to the firmware files.

According to my call with Sughosh the whole semihosting thing is about providing a testing possibility not about any real use case.

On QEMU you can easily mount an image as block device using parameters of the qemu-system-* command. On the mounted image/block-device you can test both file and block device based firmware updates. On the sandbox you could use the 'host bind' command for mounting an image.

For creating a Python unit test using the sandbox is the best fit. Takahiro already did this for his secure boot patches.

Best regards

Heinrich

Quoted 20 lines

How does that sound?

g.

Quoted 10 lines

For security reasons it may be advisable to make the device read-only when reaching ExitBootServices() or even better before the first execution of StartImage(). For this purpose we could use the Reset() service of the EFI_BLOCK_IO_PROTOCOL or provide a U-Boot specific service in the EFI_BLOCK_IO_PROTOCOL.

Best regards

Heinrich

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#12 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

Quoted 68 lines · Heinrich Schuchardt
Quoted 67 lines · Grant Likely
Quoted 63 lines · Heinrich Schuchardt
Quoted 37 lines · Sughosh Ganu

On Fri, 1 May 2020 at 00:09, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

On 4/30/20 7:36 PM, Sughosh Ganu wrote:
> Add support for the get_image_info and set_image routines,
which are
> part of the efi firmware management protocol.
>
> The current implementation uses the set_image routine for
updating the
> u-boot binary image for the qemu arm64 platform. This is
supported
> using the capsule-on-disk feature of the uefi specification,
wherein
> the firmware image to be updated is placed on the efi system
partition
> as a efi capsule under EFI/UpdateCapsule/ directory. Support
has been
> added for updating the u-boot image on platforms booting with arm > trusted firmware(tf-a), where the u-boot image gets booted as
the BL33

      > payload(bl33.bin).
      >
      > The feature can be enabled by the following config options
      >
      > CONFIG_EFI_CAPSULE_ON_DISK=y
      > CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
      >
      > Signed-off-by: Sughosh Ganu <[email protected]
      <mailto:[email protected]>>

      U-Boot's UEFI subsystem should work in the same way for x86,

ARM, and
RISC-V. Please, come up with an architecture independent solution.

Quoted 10 lines

Please check the explanation that I gave in the other mail. If you check the patch series, the actual capsule authentication logic has been kept architecture agnostic, in efi_capsule.c. The fmp protocol is very much intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

-sughosh

My idea is that for most platforms it will be enough to have a common FMP implementation that consumes a capsule

* with one or more binaries
* a media device path, a start address, and a truncation flag for each of the binaries

The protocol implementation then will write the binaries to the device paths:

* to an SD-Card or eMMC exposing the Block IO protocol for most devices
* to a file in case of the Raspberry Pi or the Sandbox or QEMU (and truncate it if the truncation flag is set)

Quoted 5 lines
Quoted 2 lines

Does U-Boot have a common device path protocol that can be backed by either a block device or a file on a filesystem? I didn't think it did.

A block device, a partition, and a file all can be described by an UEFI media device path.

Sure, from a UEFI media path, but does the underlying U-Boot implementation have that abstraction?

Quoted 10 lines
Quoted 7 lines

In the mean time, there are at least three backends that the FMP is going to have to deal with; the two you list above (block device & file) and SMC backed when updating firmware is managed by the secure world. This first implementation only handles the file-backed use case. Can we start with that limitation and refactor when the block-device and SMC use cases are added in? I would hate to see this functionality held up on having to refactor other functionality in U-Boot.

I would prefer one single FMP driver for all SMC use cases. Everything device specific should be handled in the secure world.

Not all platforms will be able to put firmware update into the secure world. For instance, Not many Arm v7 platforms have trustzone accessible to open source developers. On non-secure platforms (e.g., anything that loads firmware from a regular filesystem on SD or eMMC) it doesn't make much sense to loop out to secure firmware when U-Boot owns the filesystem and the secure world would then need to coordinate with U-Boot to commit the writes.

All of the code can certainly be in the same location, but I do think there are three distinct generic backends for firmware updates:
- normal-world file-backed (using filesystem)
- normal-world block-backed (offsets from start of device)
- secure device backed (needs to go into secure world for unpacking and processing regardless)

There doesn't need to be platform-specific code in any of those back ends, but they do have different behaviour.

Quoted 3 lines

Is there already a protocol defined for the communication of capsule updates between the firmware and the secure monitor, e.g. in EDK2?

Nothing defined yet (see below)

Quoted 2 lines

Would we simply use the UpdateCapsule() call parameters and pass them via an SMC call?

If secure world is handling the update? Yes, I think a thin UpdateCapsule() SMC makes sense, with the bonus that UpdateCapsule() at runtime becomes feasible on U-Boot. There are a couple of people inside Arm looking at possible interfaces. In this situation there is very little done in normal-world at all.

[...]

Quoted 3 lines

According to my call with Sughosh the whole semihosting thing is about providing a testing possibility not about any real use case.

Yes, it's for testing, but it is particularly valuable testing because it allows the host filesystem to be exposed into QEMU. Exposing semihosting as a generic fstype_info in U-Boot is generically useful apart from this entire discussion! :-)

If we rework the semihosting code to be just another FS driver, then I think it is just an implementation detail on the file-backed firmware update path.

Quoted 4 lines

On QEMU you can easily mount an image as block device using parameters of the qemu-system-* command. On the mounted image/block-device you can test both file and block device based firmware updates. On the sandbox you could use the 'host bind' command for mounting an image.

Similar to the above, this would be an implementation detail on the block-device backed firmware update path. We need both.

g.
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#13 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

Quoted 75 lines · Grant Likely
Quoted 72 lines · Heinrich Schuchardt
Quoted 71 lines · Grant Likely
Quoted 67 lines · Heinrich Schuchardt
Quoted 48 lines · Sughosh Ganu

On Fri, 1 May 2020 at 00:09, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

????? On 4/30/20 7:36 PM, Sughosh Ganu wrote:
????? > Add support for the get_image_info and set_image routines, which are
????? > part of the efi firmware management protocol. ????? >
????? > The current implementation uses the set_image routine for updating the
????? > u-boot binary image for the qemu arm64 platform. This is supported
????? > using the capsule-on-disk feature of the uefi specification, wherein
????? > the firmware image to be updated is placed on the efi system partition
????? > as a efi capsule under EFI/UpdateCapsule/ directory. Support has been
????? > added for updating the u-boot image on platforms booting with arm
????? > trusted firmware(tf-a), where the u-boot image gets booted as the BL33
????? > payload(bl33.bin).
????? >
????? > The feature can be enabled by the following config options ????? >
????? > CONFIG_EFI_CAPSULE_ON_DISK=y
????? > CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
????? >
????? > Signed-off-by: Sughosh Ganu <[email protected] ????? <mailto:[email protected]>>

????? U-Boot's UEFI subsystem should work in the same way for x86, ARM, and
????? RISC-V. Please, come up with an architecture independent solution.

Please check the explanation that I gave in the other mail. If you check
the patch series, the actual capsule authentication logic has been kept
architecture agnostic, in efi_capsule.c. The fmp protocol is very much intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

Quoted 3 lines

-sughosh

My idea is that for most platforms it will be enough to have a common FMP implementation that consumes a capsule

* with one or more binaries
* a media device path, a start address, and a truncation flag ??? for each of the binaries

The protocol implementation then will write the binaries to the device paths:

* to an SD-Card or eMMC exposing the Block IO protocol ??? for most devices
* to a file in case of the Raspberry Pi or the Sandbox or QEMU ??? (and truncate it if the truncation flag is set)

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Does U-Boot have a common device path protocol that can be backed by either a block device or a file on a filesystem? I didn't think it did.

A block device, a partition, and a file all can be described by an UEFI media device path.

Sure, from a UEFI media path, but does the underlying U-Boot implementation have that abstraction?

With a file media path we can find the partition device path on which the Simple file protocol is already installed by U-Boot.

Quoted 20 lines
Quoted 11 lines
Quoted 8 lines

In the mean time, there are at least three backends that the FMP is going to have to deal with; the two you list above (block device & file) and SMC backed when updating firmware is managed by the secure world. This first implementation only handles the file-backed use case. Can we start with that limitation and refactor when the block-device and SMC use cases are added in? I would hate to see this functionality held up on having to refactor other functionality in U-Boot.

I would prefer one single FMP driver for all SMC use cases. Everything device specific should be handled in the secure world.

Not all platforms will be able to put firmware update into the secure world. For instance, Not many Arm v7 platforms have trustzone accessible to open source developers. On non-secure platforms (e.g., anything that loads firmware from a regular filesystem on SD or eMMC) it doesn't make much sense to loop out to secure firmware when U-Boot owns the filesystem and the secure world would then need to coordinate with U-Boot to commit the writes.

Quoted 4 lines

All of the code can certainly be in the same location, but I do think there are three distinct generic backends for firmware updates:
- normal-world file-backed (using filesystem)
- normal-world block-backed (offsets from start of device)

These two could be in one instance of the FMP protocol.

Quoted 27 lines

- secure device backed (needs to go into secure world for unpacking and processing regardless)

There doesn't need to be platform-specific code in any of those back ends, but they do have different behaviour.

Quoted 3 lines

Is there already a protocol defined for the communication of capsule updates between the firmware and the secure monitor, e.g. in EDK2?

Nothing defined yet (see below)

Quoted 2 lines

Would we simply use the UpdateCapsule() call parameters and pass them via an SMC call?

If secure world is handling the update? Yes, I think a thin UpdateCapsule() SMC makes sense, with the bonus that UpdateCapsule() at runtime becomes feasible on U-Boot. There are a couple of people inside Arm looking at possible interfaces. In this situation there is very little done in normal-world at all.

[...]

Quoted 3 lines

According to my call with Sughosh the whole semihosting thing is about providing a testing possibility not about any real use case.

Quoted 8 lines

Yes, it's for testing, but it is particularly valuable testing because it allows the host filesystem to be exposed into QEMU. Exposing semihosting as a generic fstype_info in U-Boot is generically useful apart from this entire discussion!? :-)

If we rework the semihosting code to be just another FS driver, then I think it is just an implementation detail on the file-backed firmware update path.

In this case it could be completely separate from this patch series.

Where do you see the benefit of semi-hosting compared to mounting an image?

Best regards

Heinrich

Quoted 15 lines
Quoted 5 lines

On QEMU you can easily mount an image as block device using parameters of the qemu-system-* command. On the mounted image/block-device you can test both file and block device based firmware updates. On the sandbox you could use the 'host bind' command for mounting an image.

Similar to the above, this would be an implementation detail on the block-device backed firmware update path. We need both.

g.
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#14 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

Quoted 148 lines · Heinrich Schuchardt
Quoted 75 lines · Grant Likely
Quoted 72 lines · Heinrich Schuchardt
Quoted 71 lines · Grant Likely
Quoted 67 lines · Heinrich Schuchardt
Quoted 48 lines · Sughosh Ganu

On Fri, 1 May 2020 at 00:09, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

On 4/30/20 7:36 PM, Sughosh Ganu wrote:
> Add support for the get_image_info and set_image routines,
which are
> part of the efi firmware management protocol.
>
> The current implementation uses the set_image routine for
updating the
> u-boot binary image for the qemu arm64 platform. This is
supported
> using the capsule-on-disk feature of the uefi specification,
wherein
> the firmware image to be updated is placed on the efi system
partition
> as a efi capsule under EFI/UpdateCapsule/ directory. Support
has been
> added for updating the u-boot image on platforms booting
with arm
> trusted firmware(tf-a), where the u-boot image gets booted as
the BL33

       > payload(bl33.bin).
       >
       > The feature can be enabled by the following config options
       >
       > CONFIG_EFI_CAPSULE_ON_DISK=y
       > CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
       >
       > Signed-off-by: Sughosh Ganu <[email protected]
       <mailto:[email protected]>>

       U-Boot's UEFI subsystem should work in the same way for x86,

ARM, and
RISC-V. Please, come up with an architecture independent
solution.

Please check the explanation that I gave in the other mail. If you check
the patch series, the actual capsule authentication logic has been kept
architecture agnostic, in efi_capsule.c. The fmp protocol is very much intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

Quoted 3 lines

-sughosh

My idea is that for most platforms it will be enough to have a common FMP implementation that consumes a capsule

* with one or more binaries
* a media device path, a start address, and a truncation flag for each of the binaries

The protocol implementation then will write the binaries to the device paths:

* to an SD-Card or eMMC exposing the Block IO protocol for most devices
* to a file in case of the Raspberry Pi or the Sandbox or QEMU (and truncate it if the truncation flag is set)

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Does U-Boot have a common device path protocol that can be backed by either a block device or a file on a filesystem? I didn't think it did.

A block device, a partition, and a file all can be described by an UEFI media device path.

Sure, from a UEFI media path, but does the underlying U-Boot implementation have that abstraction?

With a file media path we can find the partition device path on which the Simple file protocol is already installed by U-Boot.

Quoted 20 lines
Quoted 11 lines
Quoted 8 lines

In the mean time, there are at least three backends that the FMP is going to have to deal with; the two you list above (block device & file) and SMC backed when updating firmware is managed by the secure world. This first implementation only handles the file-backed use case. Can we start with that limitation and refactor when the block-device and SMC use cases are added in? I would hate to see this functionality held up on having to refactor other functionality in U-Boot.

I would prefer one single FMP driver for all SMC use cases. Everything device specific should be handled in the secure world.

Not all platforms will be able to put firmware update into the secure world. For instance, Not many Arm v7 platforms have trustzone accessible to open source developers. On non-secure platforms (e.g., anything that loads firmware from a regular filesystem on SD or eMMC) it doesn't make much sense to loop out to secure firmware when U-Boot owns the filesystem and the secure world would then need to coordinate with U-Boot to commit the writes.

Quoted 4 lines

All of the code can certainly be in the same location, but I do think there are three distinct generic backends for firmware updates:
- normal-world file-backed (using filesystem)
- normal-world block-backed (offsets from start of device)

These two could be in one instance of the FMP protocol.

Quoted 32 lines

- secure device backed (needs to go into secure world for unpacking and processing regardless)

There doesn't need to be platform-specific code in any of those back ends, but they do have different behaviour.

Quoted 3 lines

Is there already a protocol defined for the communication of capsule updates between the firmware and the secure monitor, e.g. in EDK2?

Nothing defined yet (see below)

Quoted 2 lines

Would we simply use the UpdateCapsule() call parameters and pass them via an SMC call?

If secure world is handling the update? Yes, I think a thin UpdateCapsule() SMC makes sense, with the bonus that UpdateCapsule() at runtime becomes feasible on U-Boot. There are a couple of people inside Arm looking at possible interfaces. In this situation there is very little done in normal-world at all.

[...]

Quoted 3 lines

According to my call with Sughosh the whole semihosting thing is about providing a testing possibility not about any real use case.

Yes, it's for testing, but it is particularly valuable testing because it allows the host filesystem to be exposed into QEMU. Exposing semihosting as a generic fstype_info in U-Boot is generically useful apart from this entire discussion! :-)

Quoted 7 lines
Quoted 3 lines

If we rework the semihosting code to be just another FS driver, then I think it is just an implementation detail on the file-backed firmware update path.

In this case it could be completely separate from this patch series.

Where do you see the benefit of semi-hosting compared to mounting an image?

Both are important. We need test benches for both file and block device update scenarios.

g.

Quoted 21 lines

Best regards

Heinrich

Quoted 15 lines
Quoted 5 lines

On QEMU you can easily mount an image as block device using parameters of the qemu-system-* command. On the mounted image/block-device you can test both file and block device based firmware updates. On the sandbox you could use the 'host bind' command for mounting an image.

Similar to the above, this would be an implementation detail on the block-device backed firmware update path. We need both.

g.
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#15 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

Quoted 195 lines · Grant Likely
Quoted 157 lines · Heinrich Schuchardt
Quoted 85 lines · Grant Likely
Quoted 82 lines · Heinrich Schuchardt
Quoted 80 lines · Grant Likely
Quoted 65 lines · Heinrich Schuchardt
Quoted 53 lines · Sughosh Ganu

On Fri, 1 May 2020 at 00:09, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

?????? On 4/30/20 7:36 PM, Sughosh Ganu wrote:
?????? > Add support for the get_image_info and set_image routines, which are
?????? > part of the efi firmware management protocol. ?????? >
?????? > The current implementation uses the set_image routine for updating the
?????? > u-boot binary image for the qemu arm64 platform. This is supported
?????? > using the capsule-on-disk feature of the uefi specification,
wherein
?????? > the firmware image to be updated is placed on the efi system
partition
?????? > as a efi capsule under EFI/UpdateCapsule/ directory. Support
has been
?????? > added for updating the u-boot image on platforms booting with arm
?????? > trusted firmware(tf-a), where the u-boot image gets booted as
the BL33
?????? > payload(bl33.bin).
?????? >
?????? > The feature can be enabled by the following config options ?????? >
?????? > CONFIG_EFI_CAPSULE_ON_DISK=y
?????? > CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y ?????? >
?????? > Signed-off-by: Sughosh Ganu <[email protected] ?????? <mailto:[email protected]>>

?????? U-Boot's UEFI subsystem should work in the same way for x86, ARM, and
?????? RISC-V. Please, come up with an architecture independent solution.

Please check the explanation that I gave in the other mail. If you check
the patch series, the actual capsule authentication logic has been kept
architecture agnostic, in efi_capsule.c. The fmp protocol is very much
intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

Quoted 3 lines

-sughosh

My idea is that for most platforms it will be enough to have a common FMP implementation that consumes a capsule

* with one or more binaries
* a media device path, a start address, and a truncation flag ???? for each of the binaries

Quoted 8 lines

The protocol implementation then will write the binaries to the device
paths:

* to an SD-Card or eMMC exposing the Block IO protocol ???? for most devices
* to a file in case of the Raspberry Pi or the Sandbox or QEMU ???? (and truncate it if the truncation flag is set)

Does U-Boot have a common device path protocol that can be backed by either a block device or a file on a filesystem? I didn't think it did.

Quoted 5 lines
Quoted 2 lines

A block device, a partition, and a file all can be described by an UEFI media device path.

Sure, from a UEFI media path, but does the underlying U-Boot implementation have that abstraction?

With a file media path we can find the partition device path on which the Simple file protocol is already installed by U-Boot.

Quoted 22 lines
Quoted 11 lines
Quoted 10 lines

In the mean time, there are at least three backends that the FMP is going to have to deal with; the two you list above (block device & file)
and SMC backed when updating firmware is managed by the secure world. This first implementation only handles the file-backed use case. Can we
start with that limitation and refactor when the block-device and SMC use cases are added in? I would hate to see this functionality held up on having to refactor other functionality in U-Boot.

Quoted 2 lines

I would prefer one single FMP driver for all SMC use cases. Everything device specific should be handled in the secure world.

Not all platforms will be able to put firmware update into the secure world. For instance, Not many Arm v7 platforms have trustzone accessible to open source developers. On non-secure platforms (e.g., anything that loads firmware from a regular filesystem on SD or eMMC) it doesn't make much sense to loop out to secure firmware when U-Boot owns the filesystem and the secure world would then need to coordinate with U-Boot to commit the writes.

Quoted 4 lines

All of the code can certainly be in the same location, but I do think there are three distinct generic backends for firmware updates:
- normal-world file-backed (using filesystem)
- normal-world block-backed (offsets from start of device)

These two could be in one instance of the FMP protocol.

Quoted 32 lines

- secure device backed (needs to go into secure world for unpacking and processing regardless)

There doesn't need to be platform-specific code in any of those back ends, but they do have different behaviour.

Quoted 3 lines

Is there already a protocol defined for the communication of capsule updates between the firmware and the secure monitor, e.g. in EDK2?

Nothing defined yet (see below)

Quoted 2 lines

Would we simply use the UpdateCapsule() call parameters and pass them via an SMC call?

If secure world is handling the update? Yes, I think a thin UpdateCapsule() SMC makes sense, with the bonus that UpdateCapsule() at runtime becomes feasible on U-Boot. There are a couple of people inside Arm looking at possible interfaces. In this situation there is very little done in normal-world at all.

[...]

Quoted 3 lines

According to my call with Sughosh the whole semihosting thing is about providing a testing possibility not about any real use case.

Yes, it's for testing, but it is particularly valuable testing because it allows the host filesystem to be exposed into QEMU. Exposing semihosting as a generic fstype_info in U-Boot is generically useful apart from this entire discussion!? :-)

Quoted 8 lines
Quoted 3 lines

If we rework the semihosting code to be just another FS driver, then I think it is just an implementation detail on the file-backed firmware update path.

In this case it could be completely separate from this patch series.

Where do you see the benefit of semi-hosting compared to mounting an image?

Both are important. We need test benches for both file and block device update scenarios.

g.

Quoted 21 lines

Best regards

Heinrich

Quoted 15 lines
Quoted 5 lines

On QEMU you can easily mount an image as block device using parameters of the qemu-system-* command. On the mounted image/block-device you can test both file and block device based firmware updates. On the sandbox you could use the 'host bind' command for mounting an image.

Similar to the above, this would be an implementation detail on the block-device backed firmware update path. We need both.

g.
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Quoted 5 lines

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

[08.05 23:22] <apalos> who will provide the file path protocol and potential offsets?
[09.05 12:02] <xypron> The media device path and the offsets have to be provided by the one who builds the capsule and the must be integral part of the capsule.

Best regards

Heinrich

#16 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

Quoted 208 lines · Heinrich Schuchardt
Quoted 6 lines · Grant Likely
Quoted 3 lines · Heinrich Schuchardt
Quoted 2 lines · Grant Likely
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Heinrich Schuchardt
Quoted 7 lines · Grant Likely
Quoted 6 lines · Heinrich Schuchardt
Quoted 3 lines · Sughosh Ganu
Quoted 2 lines

On Fri, 1 May 2020 at 00:09, Heinrich Schuchardt <

xypron.glpk at gmx.de

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines

<mailto:[email protected]>> wrote:

On 4/30/20 7:36 PM, Sughosh Ganu wrote:
> Add support for the get_image_info and set_image routines,
which are
> part of the efi firmware management protocol.
>
> The current implementation uses the set_image routine for
updating the
> u-boot binary image for the qemu arm64 platform. This is
supported
> using the capsule-on-disk feature of the uefi
specification,
wherein
> the firmware image to be updated is placed on the efi
system
partition
> as a efi capsule under EFI/UpdateCapsule/ directory.
Support
has been
> added for updating the u-boot image on platforms booting
with arm
> trusted firmware(tf-a), where the u-boot image gets
booted as
the BL33

       > payload(bl33.bin).
       >
       > The feature can be enabled by the following config options
       >
       > CONFIG_EFI_CAPSULE_ON_DISK=y
       > CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
       >
       > Signed-off-by: Sughosh Ganu <[email protected]
       <mailto:[email protected]>>

       U-Boot's UEFI subsystem should work in the same way for x86,

ARM, and
RISC-V. Please, come up with an architecture independent
solution.

Please check the explanation that I gave in the other mail. If you check
the patch series, the actual capsule authentication logic has been kept
architecture agnostic, in efi_capsule.c. The fmp protocol is very much
intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

-sughosh

My idea is that for most platforms it will be enough to have a

common

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

FMP implementation that consumes a capsule

* with one or more binaries
* a media device path, a start address, and a truncation flag for each of the binaries

The protocol implementation then will write the binaries to the device
paths:

* to an SD-Card or eMMC exposing the Block IO protocol for most devices
* to a file in case of the Raspberry Pi or the Sandbox or QEMU (and truncate it if the truncation flag is set)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Does U-Boot have a common device path protocol that can be backed by either a block device or a file on a filesystem? I didn't think it did.

A block device, a partition, and a file all can be described by an

UEFI

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 1 line

media device path.

Sure, from a UEFI media path, but does the underlying U-Boot implementation have that abstraction?

With a file media path we can find the partition device path on which the Simple file protocol is already installed by U-Boot.

Quoted 1 line
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

In the mean time, there are at least three backends that the FMP is going to have to deal with; the two you list above (block device & file)
and SMC backed when updating firmware is managed by the secure world. This first implementation only handles the file-backed use case. Can we
start with that limitation and refactor when the block-device and SMC use cases are added in? I would hate to see this functionality held

up

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

on having to refactor other functionality in U-Boot.

I would prefer one single FMP driver for all SMC use cases. Everything device specific should be handled in the secure world.

Not all platforms will be able to put firmware update into the secure world. For instance, Not many Arm v7 platforms have trustzone

accessible

Quoted 51 lines
Quoted 51 lines
Quoted 10 lines

to open source developers. On non-secure platforms (e.g., anything that loads firmware from a regular filesystem on SD or eMMC) it doesn't make much sense to loop out to secure firmware when U-Boot owns the filesystem and the secure world would then need to coordinate with U-Boot to commit the writes.

All of the code can certainly be in the same location, but I do think there are three distinct generic backends for firmware updates:
- normal-world file-backed (using filesystem)
- normal-world block-backed (offsets from start of device)

These two could be in one instance of the FMP protocol.

Quoted 27 lines

- secure device backed (needs to go into secure world for unpacking and processing regardless)

There doesn't need to be platform-specific code in any of those back ends, but they do have different behaviour.

Quoted 3 lines

Is there already a protocol defined for the communication of capsule updates between the firmware and the secure monitor, e.g. in EDK2?

Nothing defined yet (see below)

Quoted 2 lines

Would we simply use the UpdateCapsule() call parameters and pass them via an SMC call?

If secure world is handling the update? Yes, I think a thin UpdateCapsule() SMC makes sense, with the bonus that UpdateCapsule() at runtime becomes feasible on U-Boot. There are a couple of people inside Arm looking at possible interfaces. In this situation there is very little done in normal-world at all.

[...]

Quoted 3 lines

According to my call with Sughosh the whole semihosting thing is about providing a testing possibility not about any real use case.

Quoted 8 lines

Yes, it's for testing, but it is particularly valuable testing because it allows the host filesystem to be exposed into QEMU. Exposing semihosting as a generic fstype_info in U-Boot is generically useful apart from this entire discussion! :-)

If we rework the semihosting code to be just another FS driver, then I think it is just an implementation detail on the file-backed firmware update path.

In this case it could be completely separate from this patch series.

Quoted 16 lines
Quoted 2 lines

Where do you see the benefit of semi-hosting compared to mounting an image?

Both are important. We need test benches for both file and block device update scenarios.

g.

Quoted 8 lines

Best regards

Heinrich

Quoted 3 lines
Quoted 3 lines

On QEMU you can easily mount an image as block device using parameters of the qemu-system-* command. On the mounted image/block-device you

can

Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

test both file and block device based firmware updates. On the sandbox you could use the 'host bind' command for mounting an image.

Similar to the above, this would be an implementation detail on the block-device backed firmware update path. We need both.

Quoted 7 lines
Quoted 6 lines

g.
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Quoted 5 lines

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Quoted 6 lines

[08.05 23:22] <apalos> who will provide the file path protocol and potential offsets?
[09.05 12:02] <xypron> The media device path and the offsets have to be provided by the one who builds the capsule and the must be integral part of the capsule.

Which part of the capsule do you propose to have this information. The Firmware management protocol capsule structure does have vendor code, which, as per the spec is vendor specific binary code which can be used to "implement vendor-specific firmware image update policy". There is no provision for passing such information as part of the capsule. Why can we not get this information from the platform code. Is there any issue with getting the media device path and offset information from the platform.

-sughosh

#17 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

In reply to Heinrich Schuchardt
Quoted 202 lines · Heinrich Schuchardt
Quoted 195 lines · Grant Likely
Quoted 157 lines · Heinrich Schuchardt
Quoted 85 lines · Grant Likely
Quoted 82 lines · Heinrich Schuchardt
Quoted 80 lines · Grant Likely
Quoted 65 lines · Heinrich Schuchardt
Quoted 53 lines · Sughosh Ganu

On Fri, 1 May 2020 at 00:09, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

On 4/30/20 7:36 PM, Sughosh Ganu wrote:
> Add support for the get_image_info and set_image routines,
which are
> part of the efi firmware management protocol.
>
> The current implementation uses the set_image routine for
updating the
> u-boot binary image for the qemu arm64 platform. This is
supported
> using the capsule-on-disk feature of the uefi
specification,
wherein
> the firmware image to be updated is placed on the efi
system
partition
> as a efi capsule under EFI/UpdateCapsule/ directory.
Support
has been
> added for updating the u-boot image on platforms booting
with arm
> trusted firmware(tf-a), where the u-boot image gets
booted as
the BL33

        > payload(bl33.bin).
        >
        > The feature can be enabled by the following config options
        >
        > CONFIG_EFI_CAPSULE_ON_DISK=y
        > CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
        >
        > Signed-off-by: Sughosh Ganu <[email protected]
        <mailto:[email protected]>>

        U-Boot's UEFI subsystem should work in the same way for x86,

ARM, and
RISC-V. Please, come up with an architecture independent
solution.

Please check the explanation that I gave in the other mail. If you check
the patch series, the actual capsule authentication logic has been kept
architecture agnostic, in efi_capsule.c. The fmp protocol is very much
intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

Quoted 3 lines

-sughosh

My idea is that for most platforms it will be enough to have a common FMP implementation that consumes a capsule

* with one or more binaries
* a media device path, a start address, and a truncation flag for each of the binaries

Quoted 8 lines

The protocol implementation then will write the binaries to the device
paths:

* to an SD-Card or eMMC exposing the Block IO protocol for most devices
* to a file in case of the Raspberry Pi or the Sandbox or QEMU (and truncate it if the truncation flag is set)

Does U-Boot have a common device path protocol that can be backed by either a block device or a file on a filesystem? I didn't think it did.

Quoted 5 lines
Quoted 2 lines

A block device, a partition, and a file all can be described by an UEFI media device path.

Sure, from a UEFI media path, but does the underlying U-Boot implementation have that abstraction?

With a file media path we can find the partition device path on which the Simple file protocol is already installed by U-Boot.

Quoted 22 lines
Quoted 11 lines
Quoted 10 lines

In the mean time, there are at least three backends that the FMP is going to have to deal with; the two you list above (block device & file)
and SMC backed when updating firmware is managed by the secure world. This first implementation only handles the file-backed use case. Can we
start with that limitation and refactor when the block-device and SMC use cases are added in? I would hate to see this functionality held up on having to refactor other functionality in U-Boot.

Quoted 2 lines

I would prefer one single FMP driver for all SMC use cases. Everything device specific should be handled in the secure world.

Not all platforms will be able to put firmware update into the secure world. For instance, Not many Arm v7 platforms have trustzone accessible to open source developers. On non-secure platforms (e.g., anything that loads firmware from a regular filesystem on SD or eMMC) it doesn't make much sense to loop out to secure firmware when U-Boot owns the filesystem and the secure world would then need to coordinate with U-Boot to commit the writes.

Quoted 4 lines

All of the code can certainly be in the same location, but I do think there are three distinct generic backends for firmware updates:
- normal-world file-backed (using filesystem)
- normal-world block-backed (offsets from start of device)

These two could be in one instance of the FMP protocol.

Quoted 32 lines

- secure device backed (needs to go into secure world for unpacking and processing regardless)

There doesn't need to be platform-specific code in any of those back ends, but they do have different behaviour.

Quoted 3 lines

Is there already a protocol defined for the communication of capsule updates between the firmware and the secure monitor, e.g. in EDK2?

Nothing defined yet (see below)

Quoted 2 lines

Would we simply use the UpdateCapsule() call parameters and pass them via an SMC call?

If secure world is handling the update? Yes, I think a thin UpdateCapsule() SMC makes sense, with the bonus that UpdateCapsule() at runtime becomes feasible on U-Boot. There are a couple of people inside Arm looking at possible interfaces. In this situation there is very little done in normal-world at all.

[...]

Quoted 3 lines

According to my call with Sughosh the whole semihosting thing is about providing a testing possibility not about any real use case.

Yes, it's for testing, but it is particularly valuable testing because it allows the host filesystem to be exposed into QEMU. Exposing semihosting as a generic fstype_info in U-Boot is generically useful apart from this entire discussion! :-)

Quoted 8 lines
Quoted 3 lines

If we rework the semihosting code to be just another FS driver, then I think it is just an implementation detail on the file-backed firmware update path.

In this case it could be completely separate from this patch series.

Where do you see the benefit of semi-hosting compared to mounting an image?

Both are important. We need test benches for both file and block device update scenarios.

g.

Quoted 21 lines

Best regards

Heinrich

Quoted 15 lines
Quoted 5 lines

On QEMU you can easily mount an image as block device using parameters of the qemu-system-* command. On the mounted image/block-device you can test both file and block device based firmware updates. On the sandbox you could use the 'host bind' command for mounting an image.

Similar to the above, this would be an implementation detail on the block-device backed firmware update path. We need both.

g.
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Quoted 5 lines

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Quoted 7 lines

[08.05 23:22] <apalos> who will provide the file path protocol and potential offsets?
[09.05 12:02] <xypron> The media device path and the offsets have to be provided by the one who builds the capsule and the must be integral part of the capsule.

Best regards

I'm not convinced that is true. The capsule may not be able to have that information. In the case of A/B updates, the firmware needs to track between the active and inactive copies, and always write the firmware to the appropriate location. I think it makes more sense for each firmware blob to be identified for what it is, and the firmware know the location where each image should be written (or at least have a default write location built in; there will probably be exceptions once in a while)

g.

Quoted 3 lines

Heinrich

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#18 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

In reply to Heinrich Schuchardt
Quoted 37 lines · Heinrich Schuchardt
Quoted 36 lines · Sughosh Ganu

On Fri, 1 May 2020 at 00:09, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

On 4/30/20 7:36 PM, Sughosh Ganu wrote:
> Add support for the get_image_info and set_image routines, which are > part of the efi firmware management protocol.
>
> The current implementation uses the set_image routine for updating the > u-boot binary image for the qemu arm64 platform. This is supported > using the capsule-on-disk feature of the uefi specification, wherein > the firmware image to be updated is placed on the efi system partition > as a efi capsule under EFI/UpdateCapsule/ directory. Support has been > added for updating the u-boot image on platforms booting with arm > trusted firmware(tf-a), where the u-boot image gets booted as the BL33 > payload(bl33.bin).
>
> The feature can be enabled by the following config options >
> CONFIG_EFI_CAPSULE_ON_DISK=y
> CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
>
> Signed-off-by: Sughosh Ganu <[email protected] <mailto:[email protected]>>

U-Boot's UEFI subsystem should work in the same way for x86, ARM, and RISC-V. Please, come up with an architecture independent solution.

Please check the explanation that I gave in the other mail. If you check the patch series, the actual capsule authentication logic has been kept architecture agnostic, in efi_capsule.c. The fmp protocol is very much intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

Quoted 8 lines
Quoted 3 lines

-sughosh
?

My idea is that for most platforms it will be enough to have a common FMP implementation that consumes a capsule

* with one or more binaries

Does this assumption apply to most platforms?
If so ("one"),

Quoted 2 lines

* a media device path, a start address, and a truncation flag for each of the binaries

my FIT-based patch[1] meets this assumption and there already are backend drivers for many media (but not for semihosting :) as dfu.
(I see little reason to re-invent another set of backend drivers.)

[1] https://lists.denx.de/pipermail/u-boot/2020-April/408767.html

Quoted 24 lines

The protocol implementation then will write the binaries to the device paths:

* to an SD-Card or eMMC exposing the Block IO protocol for most devices
* to a file in case of the Raspberry Pi or the Sandbox or QEMU (and truncate it if the truncation flag is set)

If for some devices like a SPI flash we do not have a media device path yet, then the only platform specific bit would be the block device driver exposing the media device path.

Same with a semi-hosted file: just add a driver exposing it as a media path with an EFI_BLOCK_IO_PROTOCOL.

For security reasons it may be advisable to make the device read-only when reaching ExitBootServices() or even better before the first execution of StartImage(). For this purpose we could use the Reset() service of the EFI_BLOCK_IO_PROTOCOL or provide a U-Boot specific service in the EFI_BLOCK_IO_PROTOCOL.

Best regards

Heinrich

#19 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

Quoted 42 lines · Akashi Takahiro
Quoted 41 lines · Heinrich Schuchardt
Quoted 39 lines · Sughosh Ganu

On Fri, 1 May 2020 at 00:09, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

On 4/30/20 7:36 PM, Sughosh Ganu wrote:
> Add support for the get_image_info and set_image routines, which are > part of the efi firmware management protocol.
>
> The current implementation uses the set_image routine for updating the > u-boot binary image for the qemu arm64 platform. This is supported > using the capsule-on-disk feature of the uefi specification, wherein > the firmware image to be updated is placed on the efi system partition > as a efi capsule under EFI/UpdateCapsule/ directory. Support has been > added for updating the u-boot image on platforms booting with arm > trusted firmware(tf-a), where the u-boot image gets booted as the BL33 > payload(bl33.bin).
>
> The feature can be enabled by the following config options >
> CONFIG_EFI_CAPSULE_ON_DISK=y
> CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
>
> Signed-off-by: Sughosh Ganu <[email protected] <mailto:[email protected]>>

U-Boot's UEFI subsystem should work in the same way for x86, ARM, and RISC-V. Please, come up with an architecture independent solution.

Please check the explanation that I gave in the other mail. If you check the patch series, the actual capsule authentication logic has been kept architecture agnostic, in efi_capsule.c. The fmp protocol is very much intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

-sughosh
?

Quoted 7 lines
Quoted 4 lines

My idea is that for most platforms it will be enough to have a common FMP implementation that consumes a capsule

* with one or more binaries

Does this assumption apply to most platforms?
If so ("one"),

Raspberry uses a file in the first partition which must be FAT to store U-Boot. The file name of U-Boot is indicated in file config.txt to the primary boot loader.

On all other devices I own U-Boot is installed by command 'dd' writing to the SD-Card somewhere after the DOS partition table. (When using a GUID partition table often you have to shorten it or relocated it to after U-Boot.) Some of the devices could alternativley use eMMC for U-Boot (e.g. Odroid C2).

For reference have a look at
doc/README.rockchip
https://a-delacruz.github.io/ubuntu/rpi3-setup-64bit-uboot.html

Best regards

Heinrich

Quoted 36 lines
Quoted 3 lines

* a media device path, a start address, and a truncation flag for each of the binaries

my FIT-based patch[1] meets this assumption and there already are backend drivers for many media (but not for semihosting :) as dfu.
(I see little reason to re-invent another set of backend drivers.)

[1] https://lists.denx.de/pipermail/u-boot/2020-April/408767.html

Quoted 24 lines

The protocol implementation then will write the binaries to the device paths:

* to an SD-Card or eMMC exposing the Block IO protocol for most devices
* to a file in case of the Raspberry Pi or the Sandbox or QEMU (and truncate it if the truncation flag is set)

If for some devices like a SPI flash we do not have a media device path yet, then the only platform specific bit would be the block device driver exposing the media device path.

Same with a semi-hosted file: just add a driver exposing it as a media path with an EFI_BLOCK_IO_PROTOCOL.

For security reasons it may be advisable to make the device read-only when reaching ExitBootServices() or even better before the first execution of StartImage(). For this purpose we could use the Reset() service of the EFI_BLOCK_IO_PROTOCOL or provide a U-Boot specific service in the EFI_BLOCK_IO_PROTOCOL.

Best regards

Heinrich

#20 lore raw

PATCH 3/8 qemu: arm64: Add support for efi firmware management protocol routines

Quoted 55 lines · Heinrich Schuchardt
Quoted 42 lines · Akashi Takahiro
Quoted 41 lines · Heinrich Schuchardt
Quoted 39 lines · Sughosh Ganu

On Fri, 1 May 2020 at 00:09, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

On 4/30/20 7:36 PM, Sughosh Ganu wrote:
> Add support for the get_image_info and set_image routines, which are > part of the efi firmware management protocol.
>
> The current implementation uses the set_image routine for updating the > u-boot binary image for the qemu arm64 platform. This is supported > using the capsule-on-disk feature of the uefi specification, wherein > the firmware image to be updated is placed on the efi system partition > as a efi capsule under EFI/UpdateCapsule/ directory. Support has been > added for updating the u-boot image on platforms booting with arm > trusted firmware(tf-a), where the u-boot image gets booted as the BL33 > payload(bl33.bin).
>
> The feature can be enabled by the following config options >
> CONFIG_EFI_CAPSULE_ON_DISK=y
> CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
>
> Signed-off-by: Sughosh Ganu <[email protected] <mailto:[email protected]>>

U-Boot's UEFI subsystem should work in the same way for x86, ARM, and RISC-V. Please, come up with an architecture independent solution.

Please check the explanation that I gave in the other mail. If you check the patch series, the actual capsule authentication logic has been kept architecture agnostic, in efi_capsule.c. The fmp protocol is very much intended for allowing platforms to define their firmware update routines. Edk2 also has platform specific implementation of the fmp protocol under the edk2-platforms directory.

-sughosh
?

Quoted 7 lines
Quoted 4 lines

My idea is that for most platforms it will be enough to have a common FMP implementation that consumes a capsule

* with one or more binaries

Does this assumption apply to most platforms?
If so ("one"),

Raspberry uses a file in the first partition which must be FAT to store U-Boot. The file name of U-Boot is indicated in file config.txt to the primary boot loader.

Quoted 5 lines

On all other devices I own U-Boot is installed by command 'dd' writing to the SD-Card somewhere after the DOS partition table. (When using a GUID partition table often you have to shorten it or relocated it to after U-Boot.) Some of the devices could alternativley use eMMC for U-Boot (e.g. Odroid C2).

"Firmware" doesn't always mean U-Boot binary.
What I had in my mind is that it can be
- storage for U-Boot environment variables
- firmware for other peripherals, or even
- kernel(/initfs/dtb)
(Remember that FIT format potentially allows for holding them.) So I believe that it's totally up to systems.

-Takahiro Akashi

Quoted 45 lines

For reference have a look at
doc/README.rockchip
https://a-delacruz.github.io/ubuntu/rpi3-setup-64bit-uboot.html

Best regards

Heinrich

Quoted 36 lines
Quoted 3 lines

* a media device path, a start address, and a truncation flag for each of the binaries

my FIT-based patch[1] meets this assumption and there already are backend drivers for many media (but not for semihosting :) as dfu.
(I see little reason to re-invent another set of backend drivers.)

[1] https://lists.denx.de/pipermail/u-boot/2020-April/408767.html

Quoted 24 lines

The protocol implementation then will write the binaries to the device paths:

* to an SD-Card or eMMC exposing the Block IO protocol for most devices
* to a file in case of the Raspberry Pi or the Sandbox or QEMU (and truncate it if the truncation flag is set)

If for some devices like a SPI flash we do not have a media device path yet, then the only platform specific bit would be the block device driver exposing the media device path.

Same with a semi-hosted file: just add a driver exposing it as a media path with an EFI_BLOCK_IO_PROTOCOL.

For security reasons it may be advisable to make the device read-only when reaching ExitBootServices() or even better before the first execution of StartImage(). For this purpose we could use the Reset() service of the EFI_BLOCK_IO_PROTOCOL or provide a U-Boot specific service in the EFI_BLOCK_IO_PROTOCOL.

Best regards

Heinrich

#21 lore raw

PATCH 4/8 efi_loader: Allow parsing of miscellaneous signature database variables

In reply to Sughosh Ganu

The current function to parse the signature database(sigdb) only allows parsing of secure boot related sigdb variables, namely PK, KEK, db and dbx. Allow the function to parse any other sigdb variables. This would be useful for the capsule authenticate feature, which would be storing it's root certificate in a non secure-boot sigdb. This is done by passing the vendor guid as a function argument.

---
 include/efi_loader.h              |  3 ++-
 lib/efi_loader/efi_image_loader.c | 11 +++++++----
 lib/efi_loader/efi_signature.c    | 14 +++-----------
 lib/efi_loader/efi_variable.c     |  9 ++++++---
 4 files changed, 18 insertions(+), 19 deletions(-)
include/efi_loader.h +2 -1
index ad99ab660f..b7638d5825 100644
@@ -774,7 +774,8 @@ efi_status_t efi_image_region_add(struct efi_image_regions *regs,
 				  int nocheck);
 
 void efi_sigstore_free(struct efi_signature_store *sigstore);
-struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name);
+struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name,
+						     const efi_guid_t *vendor);
 
 bool efi_secure_boot_enabled(void);
 
lib/efi_loader/efi_image_loader.c +7 -4
index 6c270ce94f..e07dc290a3 100644
@@ -418,13 +418,15 @@ static bool efi_image_unsigned_authenticate(struct efi_image_regions *regs)
 	struct efi_signature_store *db = NULL, *dbx = NULL;
 	bool ret = false;
 
-	dbx = efi_sigstore_parse_sigdb(L"dbx");
+	dbx = efi_sigstore_parse_sigdb(L"dbx",
+				       &efi_guid_image_security_database);
 	if (!dbx) {
 		debug("Getting signature database(dbx) failed\n");
 		goto out;
 	}
 
-	db = efi_sigstore_parse_sigdb(L"db");
+	db = efi_sigstore_parse_sigdb(L"db",
+				      &efi_guid_image_security_database);
 	if (!db) {
 		debug("Getting signature database(db) failed\n");
 		goto out;
@@ -515,13 +517,14 @@ static bool efi_image_authenticate(void *efi, size_t efi_size)
 	/*
 	 * verify signature using db and dbx
 	 */
-	db = efi_sigstore_parse_sigdb(L"db");
+	db = efi_sigstore_parse_sigdb(L"db", &efi_guid_image_security_database);
 	if (!db) {
 		debug("Getting signature database(db) failed\n");
 		goto err;
 	}
 
-	dbx = efi_sigstore_parse_sigdb(L"dbx");
+	dbx = efi_sigstore_parse_sigdb(L"dbx",
+				       &efi_guid_image_security_database);
 	if (!dbx) {
 		debug("Getting signature database(dbx) failed\n");
 		goto err;
lib/efi_loader/efi_signature.c +3 -11
index 658e3547da..bf6f39aab2 100644
@@ -714,30 +714,22 @@ err:
 /**
  * efi_sigstore_parse_sigdb - parse a signature database variable
  * @name:	Variable's name
+ * @vendor:	Vendor guid
  *
  * Read in a value of signature database variable pointed to by
  * @name, parse it and instantiate a signature store structure.
  *
  * Return:	Pointer to signature store on success, NULL on error
  */
-struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name)
+struct efi_signature_store *efi_sigstore_parse_sigdb(
+	u16 *name, const efi_guid_t *vendor)
 {
 	struct efi_signature_store *sigstore = NULL, *siglist;
 	struct efi_signature_list *esl;
-	const efi_guid_t *vendor;
 	void *db;
 	efi_uintn_t db_size;
 	efi_status_t ret;
 
-	if (!u16_strcmp(name, L"PK") || !u16_strcmp(name, L"KEK")) {
-		vendor = &efi_global_variable_guid;
-	} else if (!u16_strcmp(name, L"db") || !u16_strcmp(name, L"dbx")) {
-		vendor = &efi_guid_image_security_database;
-	} else {
-		debug("unknown signature database, %ls\n", name);
-		return NULL;
-	}
-
 	/* retrieve variable data */
 	db_size = 0;
 	ret = EFI_CALL(efi_get_variable(name, vendor, NULL, &db_size, NULL));
lib/efi_loader/efi_variable.c +6 -3
index 7df881a74b..6c2dd82306 100644
@@ -604,14 +604,17 @@ static efi_status_t efi_variable_authenticate(u16 *variable,
 	if (u16_strcmp(variable, L"PK") == 0 ||
 	    u16_strcmp(variable, L"KEK") == 0) {
 		/* with PK */
-		truststore = efi_sigstore_parse_sigdb(L"PK");
+		truststore = efi_sigstore_parse_sigdb(L"PK",
+			&efi_global_variable_guid);
 		if (!truststore)
 			goto err;
 	} else if (u16_strcmp(variable, L"db") == 0 ||
 		   u16_strcmp(variable, L"dbx") == 0) {
 		/* with PK and KEK */
-		truststore = efi_sigstore_parse_sigdb(L"KEK");
-		truststore2 = efi_sigstore_parse_sigdb(L"PK");
+		truststore = efi_sigstore_parse_sigdb(L"KEK",
+			&efi_global_variable_guid);
+		truststore2 = efi_sigstore_parse_sigdb(L"PK",
+			&efi_global_variable_guid);
 
 		if (!truststore) {
 			if (!truststore2)
Signature · 1 line
2.17.1
#22 lore raw

PATCH 5/8 efi_loader: Make the pkcs7 header parsing function an extern

In reply to Sughosh Ganu

The pkcs7 header parsing functionality is pretty generic, and can be used by other features like capsule authentication. Make the function as an extern, also changing it's name to efi_parse_pkcs7_header.

---
 include/efi_loader.h           |  2 +
 lib/efi_loader/efi_signature.c | 78 ++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_variable.c  | 82 +---------------------------------
 3 files changed, 82 insertions(+), 80 deletions(-)
include/efi_loader.h +2 -0
index b7638d5825..8d923451ce 100644
@@ -781,6 +781,8 @@ bool efi_secure_boot_enabled(void);
 
 bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
 		     WIN_CERTIFICATE **auth, size_t *auth_len);
+struct pkcs7_message *efi_parse_pkcs7_header(const void *buf, size_t buflen);
+
 #endif /* CONFIG_EFI_SECURE_BOOT */
 
 #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
lib/efi_loader/efi_signature.c +78 -0

84 lines not on this page · raw message

lib/efi_loader/efi_variable.c +2 -80

94 lines not on this page · raw message

Signature · 1 line
2.17.1
#23 lore raw

PATCH 5/8 efi_loader: Make the pkcs7 header parsing function an extern

Quoted 3 lines · Sughosh Ganu

The pkcs7 header parsing functionality is pretty generic, and can be used by other features like capsule authentication. Make the function as an extern, also changing it's name to efi_parse_pkcs7_header.

The patch itself is fine to me, but is "pkcs7 header" a common term?

-Takahiro Akashi

Quoted 213 lines
---
 include/efi_loader.h           |  2 +
 lib/efi_loader/efi_signature.c | 78 ++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_variable.c  | 82 +---------------------------------
 3 files changed, 82 insertions(+), 80 deletions(-)
include/efi_loader.h +2 -0
index b7638d5825..8d923451ce 100644
@@ -781,6 +781,8 @@ bool efi_secure_boot_enabled(void);
 
 bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
 		     WIN_CERTIFICATE **auth, size_t *auth_len);
+struct pkcs7_message *efi_parse_pkcs7_header(const void *buf, size_t buflen);
+
 #endif /* CONFIG_EFI_SECURE_BOOT */
 
 #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
lib/efi_loader/efi_signature.c +78 -0
index bf6f39aab2..9897f5418e 100644
@@ -25,6 +25,84 @@ const efi_guid_t efi_guid_cert_x509_sha256 = EFI_CERT_X509_SHA256_GUID;
 
 #ifdef CONFIG_EFI_SECURE_BOOT
 
+static u8 pkcs7_hdr[] = {
+	/* SEQUENCE */
+	0x30, 0x82, 0x05, 0xc7,
+	/* OID: pkcs7-signedData */
+	0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02,
+	/* Context Structured? */
+	0xa0, 0x82, 0x05, 0xb8,
+};
+
+/**
+ * efi_parse_pkcs7_header - parse a signature in variable
+ * @buf:	Pointer to the payload's value
+ * @buflen:	Length of @buf
+ *
+ * Parse a signature embedded in variable's value and instantiate
+ * a pkcs7_message structure. Since pkcs7_parse_message() accepts only
+ * pkcs7's signedData, some header needed be prepended for correctly
+ * parsing authentication data, particularly for variable's.
+ *
+ * Return:	Pointer to pkcs7_message structure on success, NULL on error
+ */
+struct pkcs7_message *efi_parse_pkcs7_header(const void *buf, size_t buflen)
+{
+	u8 *ebuf;
+	size_t ebuflen, len;
+	struct pkcs7_message *msg;
+
+	/*
+	 * This is the best assumption to check if the binary is
+	 * already in a form of pkcs7's signedData.
+	 */
+	if (buflen > sizeof(pkcs7_hdr) &&
+	    !memcmp(&((u8 *)buf)[4], &pkcs7_hdr[4], 11)) {
+		msg = pkcs7_parse_message(buf, buflen);
+		goto out;
+	}
+
+	/*
+	 * Otherwise, we should add a dummy prefix sequence for pkcs7
+	 * message parser to be able to process.
+	 * NOTE: EDK2 also uses similar hack in WrapPkcs7Data()
+	 * in CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyCommon.c
+	 * TODO:
+	 * The header should be composed in a more refined manner.
+	 */
+	debug("Makeshift prefix added to authentication data\n");
+	ebuflen = sizeof(pkcs7_hdr) + buflen;
+	if (ebuflen <= 0x7f) {
+		debug("Data is too short\n");
+		return NULL;
+	}
+
+	ebuf = malloc(ebuflen);
+	if (!ebuf) {
+		debug("Out of memory\n");
+		return NULL;
+	}
+
+	memcpy(ebuf, pkcs7_hdr, sizeof(pkcs7_hdr));
+	memcpy(ebuf + sizeof(pkcs7_hdr), buf, buflen);
+	len = ebuflen - 4;
+	ebuf[2] = (len >> 8) & 0xff;
+	ebuf[3] = len & 0xff;
+	len = ebuflen - 0x13;
+	ebuf[0x11] = (len >> 8) & 0xff;
+	ebuf[0x12] = len & 0xff;
+
+	msg = pkcs7_parse_message(ebuf, ebuflen);
+
+	free(ebuf);
+
+out:
+	if (IS_ERR(msg))
+		return NULL;
+
+	return msg;
+}
+
 /**
  * efi_hash_regions - calculate a hash value
  * @regs:	List of regions
lib/efi_loader/efi_variable.c +2 -80
index 6c2dd82306..be34a2cadd 100644
@@ -415,85 +415,7 @@ bool efi_secure_boot_enabled(void)
 	return efi_secure_boot;
 }
 
-#ifdef CONFIG_EFI_SECURE_BOOT
-static u8 pkcs7_hdr[] = {
-	/* SEQUENCE */
-	0x30, 0x82, 0x05, 0xc7,
-	/* OID: pkcs7-signedData */
-	0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02,
-	/* Context Structured? */
-	0xa0, 0x82, 0x05, 0xb8,
-};
-
-/**
- * efi_variable_parse_signature - parse a signature in variable
- * @buf:	Pointer to variable's value
- * @buflen:	Length of @buf
- *
- * Parse a signature embedded in variable's value and instantiate
- * a pkcs7_message structure. Since pkcs7_parse_message() accepts only
- * pkcs7's signedData, some header needed be prepended for correctly
- * parsing authentication data, particularly for variable's.
- *
- * Return:	Pointer to pkcs7_message structure on success, NULL on error
- */
-static struct pkcs7_message *efi_variable_parse_signature(const void *buf,
-							  size_t buflen)
-{
-	u8 *ebuf;
-	size_t ebuflen, len;
-	struct pkcs7_message *msg;
-
-	/*
-	 * This is the best assumption to check if the binary is
-	 * already in a form of pkcs7's signedData.
-	 */
-	if (buflen > sizeof(pkcs7_hdr) &&
-	    !memcmp(&((u8 *)buf)[4], &pkcs7_hdr[4], 11)) {
-		msg = pkcs7_parse_message(buf, buflen);
-		goto out;
-	}
-
-	/*
-	 * Otherwise, we should add a dummy prefix sequence for pkcs7
-	 * message parser to be able to process.
-	 * NOTE: EDK2 also uses similar hack in WrapPkcs7Data()
-	 * in CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyCommon.c
-	 * TODO:
-	 * The header should be composed in a more refined manner.
-	 */
-	debug("Makeshift prefix added to authentication data\n");
-	ebuflen = sizeof(pkcs7_hdr) + buflen;
-	if (ebuflen <= 0x7f) {
-		debug("Data is too short\n");
-		return NULL;
-	}
-
-	ebuf = malloc(ebuflen);
-	if (!ebuf) {
-		debug("Out of memory\n");
-		return NULL;
-	}
-
-	memcpy(ebuf, pkcs7_hdr, sizeof(pkcs7_hdr));
-	memcpy(ebuf + sizeof(pkcs7_hdr), buf, buflen);
-	len = ebuflen - 4;
-	ebuf[2] = (len >> 8) & 0xff;
-	ebuf[3] = len & 0xff;
-	len = ebuflen - 0x13;
-	ebuf[0x11] = (len >> 8) & 0xff;
-	ebuf[0x12] = len & 0xff;
-
-	msg = pkcs7_parse_message(ebuf, ebuflen);
-
-	free(ebuf);
-
-out:
-	if (IS_ERR(msg))
-		return NULL;
-
-	return msg;
-}
+#ifdef CONFIG_SECURE_BOOT
 
 /**
  * efi_variable_authenticate - authenticate a variable
@@ -591,7 +513,7 @@ static efi_status_t efi_variable_authenticate(u16 *variable,
 	/* variable's signature list */
 	if (auth->auth_info.hdr.dwLength < sizeof(auth->auth_info))
 		goto err;
-	var_sig = efi_variable_parse_signature(auth->auth_info.cert_data,
+	var_sig = efi_parse_pkcs7_header(auth->auth_info.cert_data,
 					       auth->auth_info.hdr.dwLength
 						   - sizeof(auth->auth_info));
 	if (IS_ERR(var_sig)) {
Signature · 1 line
2.17.1
#24 lore raw

PATCH 5/8 efi_loader: Make the pkcs7 header parsing function an extern

Quoted 7 lines · Akashi Takahiro
Quoted 3 lines · Sughosh Ganu

The pkcs7 header parsing functionality is pretty generic, and can be used by other features like capsule authentication. Make the function as an extern, also changing it's name to efi_parse_pkcs7_header.

The patch itself is fine to me, but is "pkcs7 header" a common term?

I haven't come across it in any other code base. I used it since in the concept of a capsule, the signature is prepended to the capsule payload. If you can think of a better name, please suggest so. I will change it in the next version.

-sughosh

Quoted 228 lines

-Takahiro Akashi

Quoted 13 lines
---
 include/efi_loader.h           |  2 +
 lib/efi_loader/efi_signature.c | 78 ++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_variable.c  | 82 +---------------------------------
 3 files changed, 82 insertions(+), 80 deletions(-)
include/efi_loader.h +0 -0
index b7638d5825..8d923451ce 100644

include/efi_loader.h bool efi_secure_boot_enabled(void); · line 782

Quoted 2 lines
include/efi_loader.h +0 -0
@@ -781,6 +781,8 @@ bool efi_secure_boot_enabled(void);
 
 bool efi_image_parse(void *efi, size_t len, struct efi_image_regions

**regp,

include/efi_loader.h bool efi_secure_boot_enabled(void); · line 784

Quoted 2 lines
include/efi_loader.h +1 -0
                   WIN_CERTIFICATE **auth, size_t *auth_len);
+struct pkcs7_message *efi_parse_pkcs7_header(const void *buf, size_t

buflen);

Review

Quoted 5 lines
include/efi_loader.h +1 -0
+
 #endif /* CONFIG_EFI_SECURE_BOOT */
 
 #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
(quoted diff) +0 -0

b/lib/efi_loader/efi_signature.c

lib/efi_loader/efi_signature.c const efi_guid_t efi_guid_cert_x509_sha256 =

Quoted 4 lines

index bf6f39aab2..9897f5418e 100644

lib/efi_loader/efi_signature.c +0 -0
@@ -25,6 +25,84 @@ const efi_guid_t efi_guid_cert_x509_sha256 =

EFI_CERT_X509_SHA256_GUID;

Quoted 13 lines
lib/efi_loader/efi_signature.c +10 -0
 #ifdef CONFIG_EFI_SECURE_BOOT
 
+static u8 pkcs7_hdr[] = {
+     /* SEQUENCE */
+     0x30, 0x82, 0x05, 0xc7,
+     /* OID: pkcs7-signedData */
+     0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02,
+     /* Context Structured? */
+     0xa0, 0x82, 0x05, 0xb8,
+};
+
+/**

lib/efi_loader/efi_signature.c const efi_guid_t efi_guid_cert_x509_sha256 = EFI_CERT_X509_SHA256_GUID;

Quoted 10 lines
lib/efi_loader/efi_signature.c +10 -0
+ * efi_parse_pkcs7_header - parse a signature in variable
+ * @buf:     Pointer to the payload's value
+ * @buflen:  Length of @buf
+ *
+ * Parse a signature embedded in variable's value and instantiate
+ * a pkcs7_message structure. Since pkcs7_parse_message() accepts only
+ * pkcs7's signedData, some header needed be prepended for correctly
+ * parsing authentication data, particularly for variable's.
+ *
+ * Return:   Pointer to pkcs7_message structure on success, NULL on

error

lib/efi_loader/efi_signature.c const efi_guid_t efi_guid_cert_x509_sha256 = · line 48

Quoted 2 lines
lib/efi_loader/efi_signature.c +2 -0
+ */
+struct pkcs7_message *efi_parse_pkcs7_header(const void *buf, size_t

buflen)

Review

Quoted 60 lines
lib/efi_loader/efi_signature.c +56 -0
+{
+     u8 *ebuf;
+     size_t ebuflen, len;
+     struct pkcs7_message *msg;
+
+     /*
+      * This is the best assumption to check if the binary is
+      * already in a form of pkcs7's signedData.
+      */
+     if (buflen > sizeof(pkcs7_hdr) &&
+         !memcmp(&((u8 *)buf)[4], &pkcs7_hdr[4], 11)) {
+             msg = pkcs7_parse_message(buf, buflen);
+             goto out;
+     }
+
+     /*
+      * Otherwise, we should add a dummy prefix sequence for pkcs7
+      * message parser to be able to process.
+      * NOTE: EDK2 also uses similar hack in WrapPkcs7Data()
+      * in CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyCommon.c
+      * TODO:
+      * The header should be composed in a more refined manner.
+      */
+     debug("Makeshift prefix added to authentication data\n");
+     ebuflen = sizeof(pkcs7_hdr) + buflen;
+     if (ebuflen <= 0x7f) {
+             debug("Data is too short\n");
+             return NULL;
+     }
+
+     ebuf = malloc(ebuflen);
+     if (!ebuf) {
+             debug("Out of memory\n");
+             return NULL;
+     }
+
+     memcpy(ebuf, pkcs7_hdr, sizeof(pkcs7_hdr));
+     memcpy(ebuf + sizeof(pkcs7_hdr), buf, buflen);
+     len = ebuflen - 4;
+     ebuf[2] = (len >> 8) & 0xff;
+     ebuf[3] = len & 0xff;
+     len = ebuflen - 0x13;
+     ebuf[0x11] = (len >> 8) & 0xff;
+     ebuf[0x12] = len & 0xff;
+
+     msg = pkcs7_parse_message(ebuf, ebuflen);
+
+     free(ebuf);
+
+out:
+     if (IS_ERR(msg))
+             return NULL;
+
+     return msg;
+}
+
 /**
  * efi_hash_regions - calculate a hash value
  * @regs:    List of regions
(quoted diff) +0 -0

b/lib/efi_loader/efi_variable.c

Quoted 18 lines

index 6c2dd82306..be34a2cadd 100644

lib/efi_loader/efi_variable.c +0 -11
@@ -415,85 +415,7 @@ bool efi_secure_boot_enabled(void)
      return efi_secure_boot;
 }
 
-#ifdef CONFIG_EFI_SECURE_BOOT
-static u8 pkcs7_hdr[] = {
-     /* SEQUENCE */
-     0x30, 0x82, 0x05, 0xc7,
-     /* OID: pkcs7-signedData */
-     0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02,
-     /* Context Structured? */
-     0xa0, 0x82, 0x05, 0xb8,
-};
-
-/**

lib/efi_loader/efi_variable.c bool efi_secure_boot_enabled(void) · line 438

Quoted 10 lines
lib/efi_loader/efi_variable.c +0 -10
- * efi_variable_parse_signature - parse a signature in variable
- * @buf:     Pointer to variable's value
- * @buflen:  Length of @buf
- *
- * Parse a signature embedded in variable's value and instantiate
- * a pkcs7_message structure. Since pkcs7_parse_message() accepts only
- * pkcs7's signedData, some header needed be prepended for correctly
- * parsing authentication data, particularly for variable's.
- *
- * Return:   Pointer to pkcs7_message structure on success, NULL on

error

lib/efi_loader/efi_variable.c bool efi_secure_boot_enabled(void) · line 440

Quoted 2 lines
lib/efi_loader/efi_variable.c +0 -2
- */
-static struct pkcs7_message *efi_variable_parse_signature(const void

*buf,

lib/efi_loader/efi_variable.c static efi_status_t efi_variable_authenticate(u16

Quoted 61 lines
lib/efi_loader/efi_variable.c +1 -56
-                                                       size_t buflen)
-{
-     u8 *ebuf;
-     size_t ebuflen, len;
-     struct pkcs7_message *msg;
-
-     /*
-      * This is the best assumption to check if the binary is
-      * already in a form of pkcs7's signedData.
-      */
-     if (buflen > sizeof(pkcs7_hdr) &&
-         !memcmp(&((u8 *)buf)[4], &pkcs7_hdr[4], 11)) {
-             msg = pkcs7_parse_message(buf, buflen);
-             goto out;
-     }
-
-     /*
-      * Otherwise, we should add a dummy prefix sequence for pkcs7
-      * message parser to be able to process.
-      * NOTE: EDK2 also uses similar hack in WrapPkcs7Data()
-      * in CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyCommon.c
-      * TODO:
-      * The header should be composed in a more refined manner.
-      */
-     debug("Makeshift prefix added to authentication data\n");
-     ebuflen = sizeof(pkcs7_hdr) + buflen;
-     if (ebuflen <= 0x7f) {
-             debug("Data is too short\n");
-             return NULL;
-     }
-
-     ebuf = malloc(ebuflen);
-     if (!ebuf) {
-             debug("Out of memory\n");
-             return NULL;
-     }
-
-     memcpy(ebuf, pkcs7_hdr, sizeof(pkcs7_hdr));
-     memcpy(ebuf + sizeof(pkcs7_hdr), buf, buflen);
-     len = ebuflen - 4;
-     ebuf[2] = (len >> 8) & 0xff;
-     ebuf[3] = len & 0xff;
-     len = ebuflen - 0x13;
-     ebuf[0x11] = (len >> 8) & 0xff;
-     ebuf[0x12] = len & 0xff;
-
-     msg = pkcs7_parse_message(ebuf, ebuflen);
-
-     free(ebuf);
-
-out:
-     if (IS_ERR(msg))
-             return NULL;
-
-     return msg;
-}
+#ifdef CONFIG_SECURE_BOOT
 
 /**
  * efi_variable_authenticate - authenticate a variable
@@ -591,7 +513,7 @@ static efi_status_t efi_variable_authenticate(u16

*variable,

lib/efi_loader/efi_variable.c static efi_status_t efi_variable_authenticate(u16 *variable,

Quoted 7 lines
lib/efi_loader/efi_variable.c +1 -1
      /* variable's signature list */
      if (auth->auth_info.hdr.dwLength < sizeof(auth->auth_info))
              goto err;
-     var_sig = efi_variable_parse_signature(auth->auth_info.cert_data,
+     var_sig = efi_parse_pkcs7_header(auth->auth_info.cert_data,
                                             auth->auth_info.hdr.dwLength
                                                 -

sizeof(auth->auth_info));

Quoted 4 lines
lib/efi_loader/efi_variable.c +0 -1
      if (IS_ERR(var_sig)) {
--

2.17.1

#25 lore raw

PATCH 5/8 efi_loader: Make the pkcs7 header parsing function an extern

Quoted 8 lines · Sughosh Ganu
Quoted 5 lines · Akashi Takahiro
Quoted 3 lines · Sughosh Ganu

The pkcs7 header parsing functionality is pretty generic, and can be used by other features like capsule authentication. Make the function as an extern, also changing it's name to efi_parse_pkcs7_header.

Quoted 7 lines
Quoted 2 lines

The patch itself is fine to me, but is "pkcs7 header" a common term?

I haven't come across it in any other code base. I used it since in the concept of a capsule, the signature is prepended to the capsule payload. If you can think of a better name, please suggest so. I will change it in the next version.

Simply, efi_parse_pkcs7_signature()?

In addition, please update the function description, which still mentions "variable."

-Takahiro Akashi

Quoted 231 lines

-sughosh

Quoted 228 lines

-Takahiro Akashi

Quoted 13 lines
---
 include/efi_loader.h           |  2 +
 lib/efi_loader/efi_signature.c | 78 ++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_variable.c  | 82 +---------------------------------
 3 files changed, 82 insertions(+), 80 deletions(-)
include/efi_loader.h +0 -0
index b7638d5825..8d923451ce 100644

include/efi_loader.h bool efi_secure_boot_enabled(void); · line 782

Quoted 2 lines
include/efi_loader.h +0 -0
@@ -781,6 +781,8 @@ bool efi_secure_boot_enabled(void);
 
 bool efi_image_parse(void *efi, size_t len, struct efi_image_regions

**regp,

include/efi_loader.h bool efi_secure_boot_enabled(void); · line 784

Quoted 2 lines
include/efi_loader.h +1 -0
                   WIN_CERTIFICATE **auth, size_t *auth_len);
+struct pkcs7_message *efi_parse_pkcs7_header(const void *buf, size_t

buflen);

Review

Quoted 5 lines
include/efi_loader.h +1 -0
+
 #endif /* CONFIG_EFI_SECURE_BOOT */
 
 #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
(quoted diff) +0 -0

b/lib/efi_loader/efi_signature.c

lib/efi_loader/efi_signature.c const efi_guid_t efi_guid_cert_x509_sha256 =

Quoted 4 lines

index bf6f39aab2..9897f5418e 100644

lib/efi_loader/efi_signature.c +0 -0
@@ -25,6 +25,84 @@ const efi_guid_t efi_guid_cert_x509_sha256 =

EFI_CERT_X509_SHA256_GUID;

Quoted 13 lines
lib/efi_loader/efi_signature.c +10 -0
 #ifdef CONFIG_EFI_SECURE_BOOT
 
+static u8 pkcs7_hdr[] = {
+     /* SEQUENCE */
+     0x30, 0x82, 0x05, 0xc7,
+     /* OID: pkcs7-signedData */
+     0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02,
+     /* Context Structured? */
+     0xa0, 0x82, 0x05, 0xb8,
+};
+
+/**

lib/efi_loader/efi_signature.c const efi_guid_t efi_guid_cert_x509_sha256 = EFI_CERT_X509_SHA256_GUID;

Quoted 10 lines
lib/efi_loader/efi_signature.c +10 -0
+ * efi_parse_pkcs7_header - parse a signature in variable
+ * @buf:     Pointer to the payload's value
+ * @buflen:  Length of @buf
+ *
+ * Parse a signature embedded in variable's value and instantiate
+ * a pkcs7_message structure. Since pkcs7_parse_message() accepts only
+ * pkcs7's signedData, some header needed be prepended for correctly
+ * parsing authentication data, particularly for variable's.
+ *
+ * Return:   Pointer to pkcs7_message structure on success, NULL on

error

lib/efi_loader/efi_signature.c const efi_guid_t efi_guid_cert_x509_sha256 = · line 48

Quoted 2 lines
lib/efi_loader/efi_signature.c +2 -0
+ */
+struct pkcs7_message *efi_parse_pkcs7_header(const void *buf, size_t

buflen)

Review

Quoted 60 lines
lib/efi_loader/efi_signature.c +56 -0
+{
+     u8 *ebuf;
+     size_t ebuflen, len;
+     struct pkcs7_message *msg;
+
+     /*
+      * This is the best assumption to check if the binary is
+      * already in a form of pkcs7's signedData.
+      */
+     if (buflen > sizeof(pkcs7_hdr) &&
+         !memcmp(&((u8 *)buf)[4], &pkcs7_hdr[4], 11)) {
+             msg = pkcs7_parse_message(buf, buflen);
+             goto out;
+     }
+
+     /*
+      * Otherwise, we should add a dummy prefix sequence for pkcs7
+      * message parser to be able to process.
+      * NOTE: EDK2 also uses similar hack in WrapPkcs7Data()
+      * in CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyCommon.c
+      * TODO:
+      * The header should be composed in a more refined manner.
+      */
+     debug("Makeshift prefix added to authentication data\n");
+     ebuflen = sizeof(pkcs7_hdr) + buflen;
+     if (ebuflen <= 0x7f) {
+             debug("Data is too short\n");
+             return NULL;
+     }
+
+     ebuf = malloc(ebuflen);
+     if (!ebuf) {
+             debug("Out of memory\n");
+             return NULL;
+     }
+
+     memcpy(ebuf, pkcs7_hdr, sizeof(pkcs7_hdr));
+     memcpy(ebuf + sizeof(pkcs7_hdr), buf, buflen);
+     len = ebuflen - 4;
+     ebuf[2] = (len >> 8) & 0xff;
+     ebuf[3] = len & 0xff;
+     len = ebuflen - 0x13;
+     ebuf[0x11] = (len >> 8) & 0xff;
+     ebuf[0x12] = len & 0xff;
+
+     msg = pkcs7_parse_message(ebuf, ebuflen);
+
+     free(ebuf);
+
+out:
+     if (IS_ERR(msg))
+             return NULL;
+
+     return msg;
+}
+
 /**
  * efi_hash_regions - calculate a hash value
  * @regs:    List of regions
(quoted diff) +0 -0

b/lib/efi_loader/efi_variable.c

Quoted 18 lines

index 6c2dd82306..be34a2cadd 100644

lib/efi_loader/efi_variable.c +0 -11
@@ -415,85 +415,7 @@ bool efi_secure_boot_enabled(void)
      return efi_secure_boot;
 }
 
-#ifdef CONFIG_EFI_SECURE_BOOT
-static u8 pkcs7_hdr[] = {
-     /* SEQUENCE */
-     0x30, 0x82, 0x05, 0xc7,
-     /* OID: pkcs7-signedData */
-     0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02,
-     /* Context Structured? */
-     0xa0, 0x82, 0x05, 0xb8,
-};
-
-/**

lib/efi_loader/efi_variable.c bool efi_secure_boot_enabled(void) · line 438

Quoted 10 lines
lib/efi_loader/efi_variable.c +0 -10
- * efi_variable_parse_signature - parse a signature in variable
- * @buf:     Pointer to variable's value
- * @buflen:  Length of @buf
- *
- * Parse a signature embedded in variable's value and instantiate
- * a pkcs7_message structure. Since pkcs7_parse_message() accepts only
- * pkcs7's signedData, some header needed be prepended for correctly
- * parsing authentication data, particularly for variable's.
- *
- * Return:   Pointer to pkcs7_message structure on success, NULL on

error

lib/efi_loader/efi_variable.c bool efi_secure_boot_enabled(void) · line 440

Quoted 2 lines
lib/efi_loader/efi_variable.c +0 -2
- */
-static struct pkcs7_message *efi_variable_parse_signature(const void

*buf,

lib/efi_loader/efi_variable.c static efi_status_t efi_variable_authenticate(u16

Quoted 61 lines
lib/efi_loader/efi_variable.c +1 -56
-                                                       size_t buflen)
-{
-     u8 *ebuf;
-     size_t ebuflen, len;
-     struct pkcs7_message *msg;
-
-     /*
-      * This is the best assumption to check if the binary is
-      * already in a form of pkcs7's signedData.
-      */
-     if (buflen > sizeof(pkcs7_hdr) &&
-         !memcmp(&((u8 *)buf)[4], &pkcs7_hdr[4], 11)) {
-             msg = pkcs7_parse_message(buf, buflen);
-             goto out;
-     }
-
-     /*
-      * Otherwise, we should add a dummy prefix sequence for pkcs7
-      * message parser to be able to process.
-      * NOTE: EDK2 also uses similar hack in WrapPkcs7Data()
-      * in CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyCommon.c
-      * TODO:
-      * The header should be composed in a more refined manner.
-      */
-     debug("Makeshift prefix added to authentication data\n");
-     ebuflen = sizeof(pkcs7_hdr) + buflen;
-     if (ebuflen <= 0x7f) {
-             debug("Data is too short\n");
-             return NULL;
-     }
-
-     ebuf = malloc(ebuflen);
-     if (!ebuf) {
-             debug("Out of memory\n");
-             return NULL;
-     }
-
-     memcpy(ebuf, pkcs7_hdr, sizeof(pkcs7_hdr));
-     memcpy(ebuf + sizeof(pkcs7_hdr), buf, buflen);
-     len = ebuflen - 4;
-     ebuf[2] = (len >> 8) & 0xff;
-     ebuf[3] = len & 0xff;
-     len = ebuflen - 0x13;
-     ebuf[0x11] = (len >> 8) & 0xff;
-     ebuf[0x12] = len & 0xff;
-
-     msg = pkcs7_parse_message(ebuf, ebuflen);
-
-     free(ebuf);
-
-out:
-     if (IS_ERR(msg))
-             return NULL;
-
-     return msg;
-}
+#ifdef CONFIG_SECURE_BOOT
 
 /**
  * efi_variable_authenticate - authenticate a variable
@@ -591,7 +513,7 @@ static efi_status_t efi_variable_authenticate(u16

*variable,

lib/efi_loader/efi_variable.c static efi_status_t efi_variable_authenticate(u16 *variable,

Quoted 7 lines
lib/efi_loader/efi_variable.c +1 -1
      /* variable's signature list */
      if (auth->auth_info.hdr.dwLength < sizeof(auth->auth_info))
              goto err;
-     var_sig = efi_variable_parse_signature(auth->auth_info.cert_data,
+     var_sig = efi_parse_pkcs7_header(auth->auth_info.cert_data,
                                             auth->auth_info.hdr.dwLength
                                                 -

sizeof(auth->auth_info));

Quoted 4 lines
lib/efi_loader/efi_variable.c +0 -1
      if (IS_ERR(var_sig)) {
--

2.17.1

#26 lore raw

PATCH 5/8 efi_loader: Make the pkcs7 header parsing function an extern

Quoted 16 lines · Akashi Takahiro
Quoted 9 lines · Sughosh Ganu

On Thu, 7 May 2020 at 13:04, Akashi Takahiro <[email protected]

Quoted 5 lines · wrote:
Quoted 3 lines · Sughosh Ganu

The pkcs7 header parsing functionality is pretty generic, and can be used by other features like capsule authentication. Make the function as an extern, also changing it's name to efi_parse_pkcs7_header.

Quoted 5 lines
Quoted 2 lines

The patch itself is fine to me, but is "pkcs7 header" a common term?

I haven't come across it in any other code base. I used it since in the concept of a capsule, the signature is prepended to the capsule payload.

If

Quoted 9 lines
Quoted 1 line

you can think of a better name, please suggest so. I will change it in

the

Quoted 1 line

next version.

Simply, efi_parse_pkcs7_signature()?

In addition, please update the function description, which still mentions "variable."

Ok. Will change.

-sughosh

#27 lore raw

PATCH 6/8 efi: capsule: Add support for uefi capsule authentication

In reply to Sughosh Ganu

Add support for authenticating uefi capsules. Most of the signature verification functionality is shared with the uefi secure boot feature.

The root certificate containing the public key used for the signature verification is stored as an efi variable, similar to the variables used for uefi secure boot. The root certificate is stored as an efi signature list(esl) file -- this file contains the x509 certificate which is the root certificate.

---
 include/efi_api.h              |  17 +++++
 include/efi_loader.h           |   8 ++-
 lib/efi_loader/Kconfig         |  16 +++++
 lib/efi_loader/efi_capsule.c   | 126 +++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_signature.c |   4 +-
 5 files changed, 167 insertions(+), 4 deletions(-)
include/efi_api.h +17 -0
index e518ffa838..8dfa479db4 100644
@@ -1794,6 +1794,23 @@ struct efi_variable_authentication_2 {
 	struct win_certificate_uefi_guid auth_info;
 } __attribute__((__packed__));
 
+/**
+ * efi_firmware_image_authentication - Capsule authentication method
+ * descriptor
+ *
+ * This structure describes an authentication information for
+ * a capsule with IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED set
+ * and should be included as part of the capsule.
+ * Only EFI_CERT_TYPE_PKCS7_GUID is accepted.
+ *
+ * @monotonic_count: Count to prevent replay
+ * @auth_info:	Authentication info
+ */
+struct efi_firmware_image_authentication {
+	uint64_t monotonic_count;
+	struct win_certificate_uefi_guid auth_info;
+} __attribute__((__packed__));
+
 /**
  * efi_signature_data - A format of signature
  *
include/efi_loader.h +6 -2
index 8d923451ce..897710ae3f 100644
@@ -708,7 +708,7 @@ void efi_deserialize_load_option(struct efi_load_option *lo, u8 *data);
 unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data);
 efi_status_t efi_bootmgr_load(efi_handle_t *handle);
 
-#ifdef CONFIG_EFI_SECURE_BOOT
+#if defined(CONFIG_EFI_SECURE_BOOT) || defined(CONFIG_EFI_CAPSULE_AUTHENTICATE)
 #include <image.h>
 
 /**
@@ -783,7 +783,7 @@ bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
 		     WIN_CERTIFICATE **auth, size_t *auth_len);
 struct pkcs7_message *efi_parse_pkcs7_header(const void *buf, size_t buflen);
 
-#endif /* CONFIG_EFI_SECURE_BOOT */
+#endif /* CONFIG_EFI_SECURE_BOOT || CONFIG_EFI_CAPSULE_AUTHENTICATE */
 
 #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
 /* Capsule update */
@@ -798,6 +798,10 @@ efi_status_t EFIAPI efi_query_capsule_caps(
 		u32 *reset_type);
 #endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT */
 
+efi_status_t efi_capsule_authenticate(const void *capsule,
+				      efi_uintn_t capsule_size,
+				      void **image, efi_uintn_t *image_size);
+
 #ifdef CONFIG_EFI_CAPSULE_ON_DISK
 #define EFI_CAPSULE_DIR L"\\EFI\\UpdateCapsule\\"
 
lib/efi_loader/Kconfig +16 -0
index ec2976ceba..245deabbed 100644
@@ -110,6 +110,22 @@ config EFI_CAPSULE_FIT_DEVICE
 	help
 	  Define storage device, say 1:1, for storing FIT image
 
+config EFI_CAPSULE_AUTHENTICATE
+	bool "Update Capsule authentication"
+	depends on EFI_HAVE_CAPSULE_SUPPORT
+	depends on EFI_CAPSULE_ON_DISK
+	depends on EFI_FIRMWARE_MANAGEMENT_PROTOCOL
+	select SHA256
+	select RSA
+	select RSA_VERIFY
+	select RSA_VERIFY_WITH_PKEY
+	select X509_CERTIFICATE_PARSER
+	select PKCS7_MESSAGE_PARSER
+	default n
+	help
+	  Select this option if you want to enable capsule
+	  authentication
+
 config EFI_DEVICE_PATH_TO_TEXT
 	bool "Device path to text protocol"
 	default y
lib/efi_loader/efi_capsule.c +126 -0

138 lines not on this page · raw message

lib/efi_loader/efi_signature.c +2 -2
index 9897f5418e..4c722e0da9 100644
@@ -23,7 +23,7 @@ const efi_guid_t efi_guid_cert_rsa2048 = EFI_CERT_RSA2048_GUID;
 const efi_guid_t efi_guid_cert_x509 = EFI_CERT_X509_GUID;
 const efi_guid_t efi_guid_cert_x509_sha256 = EFI_CERT_X509_SHA256_GUID;
 
-#ifdef CONFIG_EFI_SECURE_BOOT
+#if defined(CONFIG_EFI_SECURE_BOOT) || defined(CONFIG_EFI_CAPSULE_AUTHENTICATE)
 
 static u8 pkcs7_hdr[] = {
 	/* SEQUENCE */
@@ -871,4 +871,4 @@ err:
 
 	return NULL;
 }
-#endif /* CONFIG_EFI_SECURE_BOOT */
+#endif /* CONFIG_EFI_SECURE_BOOT || CONFIG_EFI_CAPSULE_AUTHENTICATE */
Signature · 1 line
2.17.1
#28 lore raw

PATCH 6/8 efi: capsule: Add support for uefi capsule authentication

Sughosh,

Quoted 85 lines · Sughosh Ganu

Add support for authenticating uefi capsules. Most of the signature verification functionality is shared with the uefi secure boot feature.

The root certificate containing the public key used for the signature verification is stored as an efi variable, similar to the variables used for uefi secure boot. The root certificate is stored as an efi signature list(esl) file -- this file contains the x509 certificate which is the root certificate.

---
 include/efi_api.h              |  17 +++++
 include/efi_loader.h           |   8 ++-
 lib/efi_loader/Kconfig         |  16 +++++
 lib/efi_loader/efi_capsule.c   | 126 +++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_signature.c |   4 +-
 5 files changed, 167 insertions(+), 4 deletions(-)
include/efi_api.h +17 -0
index e518ffa838..8dfa479db4 100644
@@ -1794,6 +1794,23 @@ struct efi_variable_authentication_2 {
 	struct win_certificate_uefi_guid auth_info;
 } __attribute__((__packed__));
 
+/**
+ * efi_firmware_image_authentication - Capsule authentication method
+ * descriptor
+ *
+ * This structure describes an authentication information for
+ * a capsule with IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED set
+ * and should be included as part of the capsule.
+ * Only EFI_CERT_TYPE_PKCS7_GUID is accepted.
+ *
+ * @monotonic_count: Count to prevent replay
+ * @auth_info:	Authentication info
+ */
+struct efi_firmware_image_authentication {
+	uint64_t monotonic_count;
+	struct win_certificate_uefi_guid auth_info;
+} __attribute__((__packed__));
+
 /**
  * efi_signature_data - A format of signature
  *
include/efi_loader.h +6 -2
index 8d923451ce..897710ae3f 100644
@@ -708,7 +708,7 @@ void efi_deserialize_load_option(struct efi_load_option *lo, u8 *data);
 unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data);
 efi_status_t efi_bootmgr_load(efi_handle_t *handle);
 
-#ifdef CONFIG_EFI_SECURE_BOOT
+#if defined(CONFIG_EFI_SECURE_BOOT) || defined(CONFIG_EFI_CAPSULE_AUTHENTICATE)
 #include <image.h>
 
 /**
@@ -783,7 +783,7 @@ bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
 		     WIN_CERTIFICATE **auth, size_t *auth_len);
 struct pkcs7_message *efi_parse_pkcs7_header(const void *buf, size_t buflen);
 
-#endif /* CONFIG_EFI_SECURE_BOOT */
+#endif /* CONFIG_EFI_SECURE_BOOT || CONFIG_EFI_CAPSULE_AUTHENTICATE */
 
 #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
 /* Capsule update */
@@ -798,6 +798,10 @@ efi_status_t EFIAPI efi_query_capsule_caps(
 		u32 *reset_type);
 #endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT */
 
+efi_status_t efi_capsule_authenticate(const void *capsule,
+				      efi_uintn_t capsule_size,
+				      void **image, efi_uintn_t *image_size);
+
 #ifdef CONFIG_EFI_CAPSULE_ON_DISK
 #define EFI_CAPSULE_DIR L"\\EFI\\UpdateCapsule\\"
 
lib/efi_loader/Kconfig +0 -0
index ec2976ceba..245deabbed 100644

lib/efi_loader/Kconfig config EFI_CAPSULE_FIT_DEVICE · line 117

Quoted 8 lines
lib/efi_loader/Kconfig +5 -0
@@ -110,6 +110,22 @@ config EFI_CAPSULE_FIT_DEVICE
 	help
 	  Define storage device, say 1:1, for storing FIT image
 
+config EFI_CAPSULE_AUTHENTICATE
+	bool "Update Capsule authentication"
+	depends on EFI_HAVE_CAPSULE_SUPPORT
+	depends on EFI_CAPSULE_ON_DISK
+	depends on EFI_FIRMWARE_MANAGEMENT_PROTOCOL

Do we need those two configurations?

Quoted 19 lines
lib/efi_loader/Kconfig +11 -0
+	select SHA256
+	select RSA
+	select RSA_VERIFY
+	select RSA_VERIFY_WITH_PKEY
+	select X509_CERTIFICATE_PARSER
+	select PKCS7_MESSAGE_PARSER
+	default n
+	help
+	  Select this option if you want to enable capsule
+	  authentication
+
 config EFI_DEVICE_PATH_TO_TEXT
 	bool "Device path to text protocol"
 	default y
lib/efi_loader/efi_capsule.c +0 -0
index 931d363edc..a265d36ff0 100644

lib/efi_loader/efi_capsule.c line 16

Quoted 5 lines
lib/efi_loader/efi_capsule.c +2 -0
@@ -12,6 +12,10 @@
 #include <malloc.h>
 #include <mapmem.h>
 #include <sort.h>
+#include "../lib/crypto/pkcs7_parser.h"
+

As you might notice, the location was changed by
my recent patch.

Quoted 8 lines
lib/efi_loader/efi_capsule.c +2 -0
+#include <crypto/pkcs7.h>
+#include <linux/err.h>
 
 const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
 static const efi_guid_t efi_guid_firmware_management_capsule_id =
@@ -245,6 +249,128 @@ out:
 
 	return ret;

lib/efi_loader/efi_capsule.c out: · line 260

Quoted 10 lines
lib/efi_loader/efi_capsule.c +9 -0
 }
+
+#if defined(CONFIG_EFI_CAPSULE_AUTHENTICATE)
+
+const efi_guid_t efi_guid_capsule_root_cert_guid =
+	EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
+
+__weak u16 *efi_get_truststore_name(void)
+{
+	return L"CRT";

This variable is not defined by UEFI specification, isn't it? How can this variable be protected?

Quoted 64 lines
lib/efi_loader/efi_capsule.c +64 -0
+}
+
+__weak const efi_guid_t *efi_get_truststore_vendor(void)
+{
+
+	return &efi_guid_capsule_root_cert_guid;
+}
+
+/**
+ * efi_capsule_authenticate() - Authenticate a uefi capsule
+ *
+ * @capsule:		Capsule file with the authentication
+ *			header
+ * @capsule_size:	Size of the entire capsule
+ * @image:		pointer to the image payload minus the
+ *			authentication header
+ * @image_size:		size of the image payload
+ *
+ * Authenticate the capsule signature with the public key contained
+ * in the root certificate stored as an efi environment variable
+ *
+ * Return: EFI_SUCCESS on successfull authentication or
+ *	   EFI_SECURITY_VIOLATION on authentication failure
+ */
+efi_status_t efi_capsule_authenticate(const void *capsule,
+				      efi_uintn_t capsule_size,
+				      void **image, efi_uintn_t *image_size)
+{
+	uint64_t monotonic_count;
+	struct efi_signature_store *truststore;
+	struct pkcs7_message *capsule_sig;
+	struct efi_image_regions *regs;
+	struct efi_firmware_image_authentication *auth_hdr;
+	efi_status_t status;
+
+	status = EFI_SECURITY_VIOLATION;
+	capsule_sig = NULL;
+	truststore = NULL;
+	regs = NULL;
+
+	/* Sanity checks */
+	if (capsule == NULL || capsule_size == 0)
+		goto out;
+
+	auth_hdr = (struct efi_firmware_image_authentication *)capsule;
+	if (capsule_size < sizeof(*auth_hdr))
+		goto out;
+
+	if (auth_hdr->auth_info.hdr.dwLength <=
+	    offsetof(struct win_certificate_uefi_guid, cert_data))
+		goto out;
+
+	if (guidcmp(&auth_hdr->auth_info.cert_type, &efi_guid_cert_type_pkcs7))
+		goto out;
+
+	*image = (uint8_t *)capsule + sizeof(auth_hdr->monotonic_count) +
+		auth_hdr->auth_info.hdr.dwLength;
+	*image_size = capsule_size - auth_hdr->auth_info.hdr.dwLength -
+				      sizeof(auth_hdr->monotonic_count);
+	memcpy(&monotonic_count, &auth_hdr->monotonic_count,
+	       sizeof(monotonic_count));
+
+	/* data to be digested */
+	regs = calloc(sizeof(*regs) + sizeof(struct image_region) * 2, 1);

lib/efi_loader/efi_capsule.c out: · line 334

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+	if (!regs)
+		goto out;
+
+	regs->max = 2;
+	efi_image_region_add(regs, (uint8_t *)*image,
+			     (uint8_t *)*image + *image_size, 1);
+
+	efi_image_region_add(regs, (uint8_t *)&monotonic_count,
+			     (uint8_t *)&monotonic_count + sizeof(monotonic_count),
+			     1);

Is the order of regions to be calculated correct? It seems that 'monotonic_count' precedes 'image' itself in a capsule header.

lib/efi_loader/efi_capsule.c out: · line 339

Quoted 5 lines
lib/efi_loader/efi_capsule.c +5 -0
+
+	capsule_sig = efi_parse_pkcs7_header(auth_hdr->auth_info.cert_data,
+					     auth_hdr->auth_info.hdr.dwLength
+					     - sizeof(auth_hdr->auth_info));
+	if (IS_ERR(capsule_sig)) {

As Patrick reported, ex-efi_variable_parse_signature() returns NULL on error cases, this check should be "!capsule_sig."

Thanks,
-Takahiro Akashi

Quoted 59 lines
lib/efi_loader/efi_capsule.c +34 -0
+		debug("Parsing variable's pkcs7 header failed\n");
+		capsule_sig = NULL;
+		goto out;
+	}
+
+	truststore = efi_sigstore_parse_sigdb(efi_get_truststore_name(),
+					      efi_get_truststore_vendor());
+	if (!truststore)
+		goto out;
+
+	/* verify signature */
+	if (efi_signature_verify_with_sigdb(regs, capsule_sig, truststore, NULL)) {
+		debug("Verified\n");
+	} else {
+		debug("Verifying variable's signature failed\n");
+		goto out;
+	}
+
+	status = EFI_SUCCESS;
+
+out:
+	efi_sigstore_free(truststore);
+	pkcs7_free_message(capsule_sig);
+	free(regs);
+
+	return status;
+}
+#else
+efi_status_t efi_capsule_authenticate(const void *capsule, efi_uintn_t capsule_size,
+				      void **image, efi_uintn_t *image_size)
+{
+	return EFI_UNSUPPORTED;
+}
+#endif /* CONFIG_EFI_CAPSULE_AUTHENTICATE */
 #else
 static efi_status_t efi_capsule_update_firmware(
 		struct efi_capsule_header *capsule_data)
lib/efi_loader/efi_signature.c +2 -2
index 9897f5418e..4c722e0da9 100644
@@ -23,7 +23,7 @@ const efi_guid_t efi_guid_cert_rsa2048 = EFI_CERT_RSA2048_GUID;
 const efi_guid_t efi_guid_cert_x509 = EFI_CERT_X509_GUID;
 const efi_guid_t efi_guid_cert_x509_sha256 = EFI_CERT_X509_SHA256_GUID;
 
-#ifdef CONFIG_EFI_SECURE_BOOT
+#if defined(CONFIG_EFI_SECURE_BOOT) || defined(CONFIG_EFI_CAPSULE_AUTHENTICATE)
 
 static u8 pkcs7_hdr[] = {
 	/* SEQUENCE */
@@ -871,4 +871,4 @@ err:
 
 	return NULL;
 }
-#endif /* CONFIG_EFI_SECURE_BOOT */
+#endif /* CONFIG_EFI_SECURE_BOOT || CONFIG_EFI_CAPSULE_AUTHENTICATE */
Signature · 1 line
2.17.1
#29 lore raw

PATCH 6/8 efi: capsule: Add support for uefi capsule authentication

Quoted 23 lines · Akashi Takahiro

Sughosh,

Quoted 19 lines · Sughosh Ganu

Add support for authenticating uefi capsules. Most of the signature verification functionality is shared with the uefi secure boot feature.

The root certificate containing the public key used for the signature verification is stored as an efi variable, similar to the variables used for uefi secure boot. The root certificate is stored as an efi signature list(esl) file -- this file contains the x509 certificate which is the root certificate.

---
 include/efi_api.h              |  17 +++++
 include/efi_loader.h           |   8 ++-
 lib/efi_loader/Kconfig         |  16 +++++
 lib/efi_loader/efi_capsule.c   | 126 +++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_signature.c |   4 +-
 5 files changed, 167 insertions(+), 4 deletions(-)

<snip>

Quoted 8 lines
lib/efi_loader/Kconfig +0 -0
Quoted 7 lines

index ec2976ceba..245deabbed 100644

lib/efi_loader/Kconfig +0 -0
@@ -110,6 +110,22 @@ config EFI_CAPSULE_FIT_DEVICE
      help
        Define storage device, say 1:1, for storing FIT image
 
Quoted 8 lines

lib/efi_loader/Kconfig config EFI_CAPSULE_FIT_DEVICE · line 117

Quoted 5 lines
lib/efi_loader/Kconfig +5 -0
+config EFI_CAPSULE_AUTHENTICATE
+     bool "Update Capsule authentication"
+     depends on EFI_HAVE_CAPSULE_SUPPORT
+     depends on EFI_CAPSULE_ON_DISK
+     depends on EFI_FIRMWARE_MANAGEMENT_PROTOCOL

Do we need those two configurations?

Right, I think we can just do with the EFI_CAPSULE_ON_DISK. Will change.

Quoted 20 lines
Quoted 20 lines
lib/efi_loader/Kconfig +11 -0
+     select SHA256
+     select RSA
+     select RSA_VERIFY
+     select RSA_VERIFY_WITH_PKEY
+     select X509_CERTIFICATE_PARSER
+     select PKCS7_MESSAGE_PARSER
+     default n
+     help
+       Select this option if you want to enable capsule
+       authentication
+
 config EFI_DEVICE_PATH_TO_TEXT
      bool "Device path to text protocol"
      default y
lib/efi_loader/efi_capsule.c +0 -0
index 931d363edc..a265d36ff0 100644
@@ -12,6 +12,10 @@
Quoted 9 lines

lib/efi_loader/efi_capsule.c line 16

Quoted 5 lines
lib/efi_loader/efi_capsule.c +2 -0
 #include <malloc.h>
 #include <mapmem.h>
 #include <sort.h>
+#include "../lib/crypto/pkcs7_parser.h"
+

As you might notice, the location was changed by
my recent patch.

Will check and update.

Quoted 8 lines
Quoted 8 lines
lib/efi_loader/efi_capsule.c +2 -0
+#include <crypto/pkcs7.h>
+#include <linux/err.h>
 
 const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
 static const efi_guid_t efi_guid_firmware_management_capsule_id =
@@ -245,6 +249,128 @@ out:
 
Quoted 15 lines

lib/efi_loader/efi_capsule.c out: · line 260

Quoted 11 lines
lib/efi_loader/efi_capsule.c +9 -0
      return ret;
 }
+
+#if defined(CONFIG_EFI_CAPSULE_AUTHENTICATE)
+
+const efi_guid_t efi_guid_capsule_root_cert_guid =
+     EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
+
+__weak u16 *efi_get_truststore_name(void)
+{
+     return L"CRT";

This variable is not defined by UEFI specification, isn't it? How can this variable be protected?

This is not part of the uefi specification. The uefi specification does not mandate any particular method for storing the root certificate to be used for capsule authentication. The edk2 code gets the root certificate through a pcd. I had tried using KEK variable for storing the root certificate, and had also come up with an implementation. However, the addition/deletion and update of the secure variables is very closely tied with the secure boot feature and the secure boot state of the system, which is the reason why i dropped that solution and used a separate variable, which can be defined by the vendor to store the root certificate.

Quoted 77 lines
Quoted 18 lines
lib/efi_loader/efi_capsule.c +17 -0
+}
+
+__weak const efi_guid_t *efi_get_truststore_vendor(void)
+{
+
+     return &efi_guid_capsule_root_cert_guid;
+}
+
+/**
+ * efi_capsule_authenticate() - Authenticate a uefi capsule
+ *
+ * @capsule:         Capsule file with the authentication
+ *                   header
+ * @capsule_size:    Size of the entire capsule
+ * @image:           pointer to the image payload minus the
+ *                   authentication header
+ * @image_size:              size of the image payload

lib/efi_loader/efi_capsule.c out:

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+ *
+ * Authenticate the capsule signature with the public key contained
+ * in the root certificate stored as an efi environment variable
+ *
+ * Return: EFI_SUCCESS on successfull authentication or
+ *      EFI_SECURITY_VIOLATION on authentication failure
+ */
+efi_status_t efi_capsule_authenticate(const void *capsule,
+                                   efi_uintn_t capsule_size,
+                                   void **image, efi_uintn_t

*image_size)

Quoted 16 lines
lib/efi_loader/efi_capsule.c +16 -0
+{
+     uint64_t monotonic_count;
+     struct efi_signature_store *truststore;
+     struct pkcs7_message *capsule_sig;
+     struct efi_image_regions *regs;
+     struct efi_firmware_image_authentication *auth_hdr;
+     efi_status_t status;
+
+     status = EFI_SECURITY_VIOLATION;
+     capsule_sig = NULL;
+     truststore = NULL;
+     regs = NULL;
+
+     /* Sanity checks */
+     if (capsule == NULL || capsule_size == 0)
+             goto out;

lib/efi_loader/efi_capsule.c out:

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+
+     auth_hdr = (struct efi_firmware_image_authentication *)capsule;
+     if (capsule_size < sizeof(*auth_hdr))
+             goto out;
+
+     if (auth_hdr->auth_info.hdr.dwLength <=
+         offsetof(struct win_certificate_uefi_guid, cert_data))
+             goto out;
+
+     if (guidcmp(&auth_hdr->auth_info.cert_type,

&efi_guid_cert_type_pkcs7))

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+             goto out;
+
+     *image = (uint8_t *)capsule + sizeof(auth_hdr->monotonic_count) +
+             auth_hdr->auth_info.hdr.dwLength;
+     *image_size = capsule_size - auth_hdr->auth_info.hdr.dwLength -
+                                   sizeof(auth_hdr->monotonic_count);
+     memcpy(&monotonic_count, &auth_hdr->monotonic_count,
+            sizeof(monotonic_count));
+
+     /* data to be digested */

lib/efi_loader/efi_capsule.c out:

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+     regs = calloc(sizeof(*regs) + sizeof(struct image_region) * 2, 1);
+     if (!regs)
+             goto out;
+
+     regs->max = 2;
+     efi_image_region_add(regs, (uint8_t *)*image,
+                          (uint8_t *)*image + *image_size, 1);
+
+     efi_image_region_add(regs, (uint8_t *)&monotonic_count,
+                          (uint8_t *)&monotonic_count +

sizeof(monotonic_count),

Quoted 6 lines

lib/efi_loader/efi_capsule.c out: · line 334

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+                          1);

Is the order of regions to be calculated correct? It seems that 'monotonic_count' precedes 'image' itself in a capsule header.

Does that have any impact on the hash value computed. I did not see any difference in the hash value computed due to the order in which the regions are added. But that could be because of the way the hash value gets computed at the time of building the capsule. I will check this out.

Quoted 5 lines

lib/efi_loader/efi_capsule.c out: · line 344

Quoted 4 lines
lib/efi_loader/efi_capsule.c +3 -0
+
+     capsule_sig = efi_parse_pkcs7_header(auth_hdr->auth_info.cert_data,
+

auth_hdr->auth_info.hdr.dwLength

Quoted 7 lines

lib/efi_loader/efi_capsule.c out: · line 338

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+                                          -

sizeof(auth_hdr->auth_info));

lib/efi_loader/efi_capsule.c out: · line 339

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+     if (IS_ERR(capsule_sig)) {

As Patrick reported, ex-efi_variable_parse_signature() returns NULL on error cases, this check should be "!capsule_sig."

Will change.

-sughosh

#30 lore raw

PATCH 6/8 efi: capsule: Add support for uefi capsule authentication

Quoted 46 lines · Sughosh Ganu
Quoted 23 lines · Akashi Takahiro

Sughosh,

Quoted 19 lines · Sughosh Ganu

Add support for authenticating uefi capsules. Most of the signature verification functionality is shared with the uefi secure boot feature.

The root certificate containing the public key used for the signature verification is stored as an efi variable, similar to the variables used for uefi secure boot. The root certificate is stored as an efi signature list(esl) file -- this file contains the x509 certificate which is the root certificate.

---
 include/efi_api.h              |  17 +++++
 include/efi_loader.h           |   8 ++-
 lib/efi_loader/Kconfig         |  16 +++++
 lib/efi_loader/efi_capsule.c   | 126 +++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_signature.c |   4 +-
 5 files changed, 167 insertions(+), 4 deletions(-)

<snip>

Quoted 8 lines
lib/efi_loader/Kconfig +0 -0
Quoted 7 lines

index ec2976ceba..245deabbed 100644

lib/efi_loader/Kconfig +0 -0
@@ -110,6 +110,22 @@ config EFI_CAPSULE_FIT_DEVICE
      help
        Define storage device, say 1:1, for storing FIT image
 
Quoted 8 lines

lib/efi_loader/Kconfig config EFI_CAPSULE_FIT_DEVICE · line 117

Quoted 5 lines
lib/efi_loader/Kconfig +5 -0
+config EFI_CAPSULE_AUTHENTICATE
+     bool "Update Capsule authentication"
+     depends on EFI_HAVE_CAPSULE_SUPPORT
+     depends on EFI_CAPSULE_ON_DISK
+     depends on EFI_FIRMWARE_MANAGEMENT_PROTOCOL

Do we need those two configurations?

Quoted 1 line

Right, I think we can just do with the EFI_CAPSULE_ON_DISK. Will change.

Actually I don't think we need EFI_CAPSULE_ON_DISK neither.

Quoted 58 lines
Quoted 21 lines
Quoted 21 lines
lib/efi_loader/Kconfig +11 -0
+     select SHA256
+     select RSA
+     select RSA_VERIFY
+     select RSA_VERIFY_WITH_PKEY
+     select X509_CERTIFICATE_PARSER
+     select PKCS7_MESSAGE_PARSER
+     default n
+     help
+       Select this option if you want to enable capsule
+       authentication
+
 config EFI_DEVICE_PATH_TO_TEXT
      bool "Device path to text protocol"
      default y
lib/efi_loader/efi_capsule.c +0 -0
index 931d363edc..a265d36ff0 100644
@@ -12,6 +12,10 @@
Quoted 9 lines

lib/efi_loader/efi_capsule.c line 16

Quoted 5 lines
lib/efi_loader/efi_capsule.c +2 -0
 #include <malloc.h>
 #include <mapmem.h>
 #include <sort.h>
+#include "../lib/crypto/pkcs7_parser.h"
+

As you might notice, the location was changed by
my recent patch.

Will check and update.

Quoted 8 lines
Quoted 8 lines
lib/efi_loader/efi_capsule.c +2 -0
+#include <crypto/pkcs7.h>
+#include <linux/err.h>
 
 const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
 static const efi_guid_t efi_guid_firmware_management_capsule_id =
@@ -245,6 +249,128 @@ out:
 
Quoted 15 lines

lib/efi_loader/efi_capsule.c out: · line 260

Quoted 11 lines
lib/efi_loader/efi_capsule.c +9 -0
      return ret;
 }
+
+#if defined(CONFIG_EFI_CAPSULE_AUTHENTICATE)
+
+const efi_guid_t efi_guid_capsule_root_cert_guid =
+     EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
+
+__weak u16 *efi_get_truststore_name(void)
+{
+     return L"CRT";

This variable is not defined by UEFI specification, isn't it? How can this variable be protected?

Quoted 9 lines

This is not part of the uefi specification. The uefi specification does not mandate any particular method for storing the root certificate to be used for capsule authentication. The edk2 code gets the root certificate through a pcd. I had tried using KEK variable for storing the root certificate, and had also come up with an implementation. However, the addition/deletion and update of the secure variables is very closely tied with the secure boot feature and the secure boot state of the system, which is the reason why i dropped that solution and used a separate variable, which can be defined by the vendor to store the root certificate.

My concern is that, without any protection, the value of this variable can be modified by a mal-user.
(One simple solution would be to set this variable read-only.)

Quoted 78 lines
Quoted 78 lines
Quoted 19 lines
lib/efi_loader/efi_capsule.c +17 -0
+}
+
+__weak const efi_guid_t *efi_get_truststore_vendor(void)
+{
+
+     return &efi_guid_capsule_root_cert_guid;
+}
+
+/**
+ * efi_capsule_authenticate() - Authenticate a uefi capsule
+ *
+ * @capsule:         Capsule file with the authentication
+ *                   header
+ * @capsule_size:    Size of the entire capsule
+ * @image:           pointer to the image payload minus the
+ *                   authentication header
+ * @image_size:              size of the image payload

lib/efi_loader/efi_capsule.c out:

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+ *
+ * Authenticate the capsule signature with the public key contained
+ * in the root certificate stored as an efi environment variable
+ *
+ * Return: EFI_SUCCESS on successfull authentication or
+ *      EFI_SECURITY_VIOLATION on authentication failure
+ */
+efi_status_t efi_capsule_authenticate(const void *capsule,
+                                   efi_uintn_t capsule_size,
+                                   void **image, efi_uintn_t

*image_size)

Quoted 16 lines
lib/efi_loader/efi_capsule.c +16 -0
+{
+     uint64_t monotonic_count;
+     struct efi_signature_store *truststore;
+     struct pkcs7_message *capsule_sig;
+     struct efi_image_regions *regs;
+     struct efi_firmware_image_authentication *auth_hdr;
+     efi_status_t status;
+
+     status = EFI_SECURITY_VIOLATION;
+     capsule_sig = NULL;
+     truststore = NULL;
+     regs = NULL;
+
+     /* Sanity checks */
+     if (capsule == NULL || capsule_size == 0)
+             goto out;

lib/efi_loader/efi_capsule.c out:

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+
+     auth_hdr = (struct efi_firmware_image_authentication *)capsule;
+     if (capsule_size < sizeof(*auth_hdr))
+             goto out;
+
+     if (auth_hdr->auth_info.hdr.dwLength <=
+         offsetof(struct win_certificate_uefi_guid, cert_data))
+             goto out;
+
+     if (guidcmp(&auth_hdr->auth_info.cert_type,

&efi_guid_cert_type_pkcs7))

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+             goto out;
+
+     *image = (uint8_t *)capsule + sizeof(auth_hdr->monotonic_count) +
+             auth_hdr->auth_info.hdr.dwLength;
+     *image_size = capsule_size - auth_hdr->auth_info.hdr.dwLength -
+                                   sizeof(auth_hdr->monotonic_count);
+     memcpy(&monotonic_count, &auth_hdr->monotonic_count,
+            sizeof(monotonic_count));
+
+     /* data to be digested */

lib/efi_loader/efi_capsule.c out:

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+     regs = calloc(sizeof(*regs) + sizeof(struct image_region) * 2, 1);
+     if (!regs)
+             goto out;
+
+     regs->max = 2;
+     efi_image_region_add(regs, (uint8_t *)*image,
+                          (uint8_t *)*image + *image_size, 1);
+
+     efi_image_region_add(regs, (uint8_t *)&monotonic_count,
+                          (uint8_t *)&monotonic_count +

sizeof(monotonic_count),

Quoted 8 lines
Quoted 6 lines

lib/efi_loader/efi_capsule.c out: · line 334

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+                          1);

Is the order of regions to be calculated correct? It seems that 'monotonic_count' precedes 'image' itself in a capsule header.

Does that have any impact on the hash value computed.

Not 100% sure, but if it doesn't, it cannot guarantee uniqueness of digest values.

Thanks,
-Takahiro Akashi

Quoted 22 lines

I did not see any
difference in the hash value computed due to the order in which the regions are added. But that could be because of the way the hash value gets computed at the time of building the capsule. I will check this out.

Quoted 5 lines

lib/efi_loader/efi_capsule.c out: · line 344

Quoted 4 lines
lib/efi_loader/efi_capsule.c +3 -0
+
+     capsule_sig = efi_parse_pkcs7_header(auth_hdr->auth_info.cert_data,
+

auth_hdr->auth_info.hdr.dwLength

Quoted 7 lines

lib/efi_loader/efi_capsule.c out: · line 338

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+                                          -

sizeof(auth_hdr->auth_info));

lib/efi_loader/efi_capsule.c out: · line 339

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+     if (IS_ERR(capsule_sig)) {

As Patrick reported, ex-efi_variable_parse_signature() returns NULL on error cases, this check should be "!capsule_sig."

Will change.

-sughosh

#31 lore raw

PATCH 6/8 efi: capsule: Add support for uefi capsule authentication

Quoted 49 lines · Akashi Takahiro
Quoted 23 lines · Sughosh Ganu

On Thu, 7 May 2020 at 13:49, Akashi Takahiro <[email protected]

Quoted 19 lines · wrote:

Sughosh,

Quoted 16 lines · Sughosh Ganu

Add support for authenticating uefi capsules. Most of the signature verification functionality is shared with the uefi secure boot feature.

The root certificate containing the public key used for the signature verification is stored as an efi variable, similar to the variables used for uefi secure boot. The root certificate is stored as an efi signature list(esl) file -- this file contains the x509 certificate which is the root certificate.

---
 include/efi_api.h              |  17 +++++
 include/efi_loader.h           |   8 ++-
 lib/efi_loader/Kconfig         |  16 +++++
 lib/efi_loader/efi_capsule.c   | 126

+++++++++++++++++++++++++++++++++

Quoted 24 lines
Quoted 4 lines
Quoted 3 lines
 lib/efi_loader/efi_signature.c |   4 +-
 5 files changed, 167 insertions(+), 4 deletions(-)

<snip>

Quoted 16 lines
lib/efi_loader/Kconfig +0 -0

lib/efi_loader/Kconfig config EFI_CAPSULE_FIT_DEVICE · line 117

Quoted 12 lines

index ec2976ceba..245deabbed 100644

lib/efi_loader/Kconfig +5 -0
@@ -110,6 +110,22 @@ config EFI_CAPSULE_FIT_DEVICE
      help
        Define storage device, say 1:1, for storing FIT image
 
+config EFI_CAPSULE_AUTHENTICATE
+     bool "Update Capsule authentication"
+     depends on EFI_HAVE_CAPSULE_SUPPORT
+     depends on EFI_CAPSULE_ON_DISK
+     depends on EFI_FIRMWARE_MANAGEMENT_PROTOCOL

Do we need those two configurations?

Quoted 4 lines
Quoted 1 line

Right, I think we can just do with the EFI_CAPSULE_ON_DISK. Will change.

Actually I don't think we need EFI_CAPSULE_ON_DISK neither.

We at least need EFI_HAVE_CAPSULE_SUPPORT, isn't it.

Quoted 71 lines
Quoted 18 lines
Quoted 18 lines

Review

Quoted 18 lines
lib/efi_loader/Kconfig +11 -0
+     select SHA256
+     select RSA
+     select RSA_VERIFY
+     select RSA_VERIFY_WITH_PKEY
+     select X509_CERTIFICATE_PARSER
+     select PKCS7_MESSAGE_PARSER
+     default n
+     help
+       Select this option if you want to enable capsule
+       authentication
+
 config EFI_DEVICE_PATH_TO_TEXT
      bool "Device path to text protocol"
      default y
(quoted diff) +0 -0

b/lib/efi_loader/efi_capsule.c

Quoted 41 lines
Quoted 4 lines
Quoted 4 lines

index 931d363edc..a265d36ff0 100644

lib/efi_loader/efi_capsule.c +0 -0
@@ -12,6 +12,10 @@
Quoted 9 lines

lib/efi_loader/efi_capsule.c line 16

Quoted 5 lines
lib/efi_loader/efi_capsule.c +2 -0
 #include <malloc.h>
 #include <mapmem.h>
 #include <sort.h>
+#include "../lib/crypto/pkcs7_parser.h"
+

As you might notice, the location was changed by
my recent patch.

Will check and update.

Quoted 8 lines
Quoted 8 lines
lib/efi_loader/efi_capsule.c +2 -0
+#include <crypto/pkcs7.h>
+#include <linux/err.h>
 
 const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
 static const efi_guid_t efi_guid_firmware_management_capsule_id =
@@ -245,6 +249,128 @@ out:
 
Quoted 15 lines

lib/efi_loader/efi_capsule.c out: · line 260

Quoted 11 lines
lib/efi_loader/efi_capsule.c +9 -0
      return ret;
 }
+
+#if defined(CONFIG_EFI_CAPSULE_AUTHENTICATE)
+
+const efi_guid_t efi_guid_capsule_root_cert_guid =
+     EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
+
+__weak u16 *efi_get_truststore_name(void)
+{
+     return L"CRT";

This variable is not defined by UEFI specification, isn't it? How can this variable be protected?

Quoted 1 line

This is not part of the uefi specification. The uefi specification does

not

Quoted 2 lines

mandate any particular method for storing the root certificate to be used for capsule authentication. The edk2 code gets the root certificate

through

Quoted 1 line

a pcd. I had tried using KEK variable for storing the root certificate,

and

Quoted 1 line

had also come up with an implementation. However, the addition/deletion

and

Quoted 2 lines

update of the secure variables is very closely tied with the secure boot feature and the secure boot state of the system, which is the reason why

Quoted 9 lines

i

Quoted 1 line

dropped that solution and used a separate variable, which can be defined

by

Quoted 1 line

the vendor to store the root certificate.

My concern is that, without any protection, the value of this variable can be modified by a mal-user.
(One simple solution would be to set this variable read-only.)

Yes, that is one solution. This will also be taken care of in a scenario where the platform is booted in a trusted chain, and the env is also part of the image which gets verified by the previous stage(e.g BL2) before jumping to the u-boot image. If there is any change in the u-boot image, that would result in a boot failure -- but that would need the env to be part of the u-boot image which gets verified. I will explore making this variable read-only.

Quoted 88 lines
Quoted 57 lines
Quoted 57 lines
Quoted 19 lines
lib/efi_loader/efi_capsule.c +17 -0
+}
+
+__weak const efi_guid_t *efi_get_truststore_vendor(void)
+{
+
+     return &efi_guid_capsule_root_cert_guid;
+}
+
+/**
+ * efi_capsule_authenticate() - Authenticate a uefi capsule
+ *
+ * @capsule:         Capsule file with the authentication
+ *                   header
+ * @capsule_size:    Size of the entire capsule
+ * @image:           pointer to the image payload minus the
+ *                   authentication header
+ * @image_size:              size of the image payload

lib/efi_loader/efi_capsule.c out:

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+ *
+ * Authenticate the capsule signature with the public key contained
+ * in the root certificate stored as an efi environment variable
+ *
+ * Return: EFI_SUCCESS on successfull authentication or
+ *      EFI_SECURITY_VIOLATION on authentication failure
+ */
+efi_status_t efi_capsule_authenticate(const void *capsule,
+                                   efi_uintn_t capsule_size,
+                                   void **image, efi_uintn_t

*image_size)

Quoted 16 lines
lib/efi_loader/efi_capsule.c +16 -0
+{
+     uint64_t monotonic_count;
+     struct efi_signature_store *truststore;
+     struct pkcs7_message *capsule_sig;
+     struct efi_image_regions *regs;
+     struct efi_firmware_image_authentication *auth_hdr;
+     efi_status_t status;
+
+     status = EFI_SECURITY_VIOLATION;
+     capsule_sig = NULL;
+     truststore = NULL;
+     regs = NULL;
+
+     /* Sanity checks */
+     if (capsule == NULL || capsule_size == 0)
+             goto out;

lib/efi_loader/efi_capsule.c out:

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+
+     auth_hdr = (struct efi_firmware_image_authentication *)capsule;
+     if (capsule_size < sizeof(*auth_hdr))
+             goto out;
+
+     if (auth_hdr->auth_info.hdr.dwLength <=
+         offsetof(struct win_certificate_uefi_guid, cert_data))
+             goto out;
+
+     if (guidcmp(&auth_hdr->auth_info.cert_type,

&efi_guid_cert_type_pkcs7))

Quoted 3 lines
Quoted 3 lines

lib/efi_loader/efi_capsule.c out:

Quoted 3 lines
lib/efi_loader/efi_capsule.c +3 -0
+             goto out;
+
+     *image = (uint8_t *)capsule +

sizeof(auth_hdr->monotonic_count) +

Quoted 3 lines
Quoted 3 lines

lib/efi_loader/efi_capsule.c out: · line 322

Quoted 3 lines
lib/efi_loader/efi_capsule.c +3 -0
+             auth_hdr->auth_info.hdr.dwLength;
+     *image_size = capsule_size - auth_hdr->auth_info.hdr.dwLength -
+

sizeof(auth_hdr->monotonic_count);

Quoted 5 lines
Quoted 5 lines

lib/efi_loader/efi_capsule.c out:

Quoted 5 lines
lib/efi_loader/efi_capsule.c +5 -0
+     memcpy(&monotonic_count, &auth_hdr->monotonic_count,
+            sizeof(monotonic_count));
+
+     /* data to be digested */
+     regs = calloc(sizeof(*regs) + sizeof(struct image_region) * 2,

1);

Quoted 17 lines
Quoted 16 lines

lib/efi_loader/efi_capsule.c out:

Quoted 9 lines
lib/efi_loader/efi_capsule.c +9 -0
+     if (!regs)
+             goto out;
+
+     regs->max = 2;
+     efi_image_region_add(regs, (uint8_t *)*image,
+                          (uint8_t *)*image + *image_size, 1);
+
+     efi_image_region_add(regs, (uint8_t *)&monotonic_count,
+                          (uint8_t *)&monotonic_count +

sizeof(monotonic_count),

lib/efi_loader/efi_capsule.c out: · line 334

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+                          1);

Is the order of regions to be calculated correct? It seems that 'monotonic_count' precedes 'image' itself in a capsule header.

Quoted 5 lines
Quoted 1 line

Does that have any impact on the hash value computed.

Not 100% sure, but if it doesn't, it cannot guarantee uniqueness of digest values.

Will check this.

-sughosh

Quoted 29 lines

Thanks,
-Takahiro Akashi

Quoted 2 lines

I did not see any
difference in the hash value computed due to the order in which the

regions

Quoted 7 lines

are added. But that could be because of the way the hash value gets computed at the time of building the capsule. I will check this out.

Quoted 3 lines
Quoted 3 lines
lib/efi_loader/efi_capsule.c +2 -0
+
+     capsule_sig =

efi_parse_pkcs7_header(auth_hdr->auth_info.cert_data,

Quoted 13 lines
Quoted 9 lines

lib/efi_loader/efi_capsule.c out: · line 337

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+

auth_hdr->auth_info.hdr.dwLength

lib/efi_loader/efi_capsule.c out: · line 338

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+                                          -

sizeof(auth_hdr->auth_info));

lib/efi_loader/efi_capsule.c out: · line 339

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+     if (IS_ERR(capsule_sig)) {

As Patrick reported, ex-efi_variable_parse_signature() returns NULL on error cases, this check should be "!capsule_sig."

Will change.

-sughosh

#32 lore raw

PATCH 6/8 efi: capsule: Add support for uefi capsule authentication

Quoted 52 lines · Sughosh Ganu
Quoted 49 lines · Akashi Takahiro
Quoted 23 lines · Sughosh Ganu

On Thu, 7 May 2020 at 13:49, Akashi Takahiro <[email protected]

Quoted 19 lines · wrote:

Sughosh,

Quoted 16 lines · Sughosh Ganu

Add support for authenticating uefi capsules. Most of the signature verification functionality is shared with the uefi secure boot feature.

The root certificate containing the public key used for the signature verification is stored as an efi variable, similar to the variables used for uefi secure boot. The root certificate is stored as an efi signature list(esl) file -- this file contains the x509 certificate which is the root certificate.

---
 include/efi_api.h              |  17 +++++
 include/efi_loader.h           |   8 ++-
 lib/efi_loader/Kconfig         |  16 +++++
 lib/efi_loader/efi_capsule.c   | 126

+++++++++++++++++++++++++++++++++

Quoted 24 lines
Quoted 4 lines
Quoted 3 lines
 lib/efi_loader/efi_signature.c |   4 +-
 5 files changed, 167 insertions(+), 4 deletions(-)

<snip>

Quoted 16 lines
lib/efi_loader/Kconfig +0 -0

lib/efi_loader/Kconfig config EFI_CAPSULE_FIT_DEVICE · line 117

Quoted 12 lines

index ec2976ceba..245deabbed 100644

lib/efi_loader/Kconfig +5 -0
@@ -110,6 +110,22 @@ config EFI_CAPSULE_FIT_DEVICE
      help
        Define storage device, say 1:1, for storing FIT image
 
+config EFI_CAPSULE_AUTHENTICATE
+     bool "Update Capsule authentication"
+     depends on EFI_HAVE_CAPSULE_SUPPORT
+     depends on EFI_CAPSULE_ON_DISK
+     depends on EFI_FIRMWARE_MANAGEMENT_PROTOCOL

Do we need those two configurations?

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Right, I think we can just do with the EFI_CAPSULE_ON_DISK. Will change.

Actually I don't think we need EFI_CAPSULE_ON_DISK neither.

We at least need EFI_HAVE_CAPSULE_SUPPORT, isn't it.

Ah, yes of course.

-Takahiro Akashi

Quoted 219 lines
Quoted 72 lines
Quoted 4 lines
Quoted 4 lines
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
lib/efi_loader/Kconfig +7 -0
+     select SHA256
+     select RSA
+     select RSA_VERIFY
+     select RSA_VERIFY_WITH_PKEY
+     select X509_CERTIFICATE_PARSER
+     select PKCS7_MESSAGE_PARSER
+     default n
Quoted 8 lines

Review

Quoted 8 lines
lib/efi_loader/Kconfig +4 -0
+     help
+       Select this option if you want to enable capsule
+       authentication
+
 config EFI_DEVICE_PATH_TO_TEXT
      bool "Device path to text protocol"
      default y
(quoted diff) +0 -0

b/lib/efi_loader/efi_capsule.c

Quoted 41 lines
Quoted 4 lines
Quoted 4 lines

index 931d363edc..a265d36ff0 100644

lib/efi_loader/efi_capsule.c +0 -0
@@ -12,6 +12,10 @@
Quoted 9 lines

lib/efi_loader/efi_capsule.c line 16

Quoted 5 lines
lib/efi_loader/efi_capsule.c +2 -0
 #include <malloc.h>
 #include <mapmem.h>
 #include <sort.h>
+#include "../lib/crypto/pkcs7_parser.h"
+

As you might notice, the location was changed by
my recent patch.

Will check and update.

Quoted 8 lines
Quoted 8 lines
lib/efi_loader/efi_capsule.c +2 -0
+#include <crypto/pkcs7.h>
+#include <linux/err.h>
 
 const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
 static const efi_guid_t efi_guid_firmware_management_capsule_id =
@@ -245,6 +249,128 @@ out:
 
Quoted 15 lines

lib/efi_loader/efi_capsule.c out: · line 260

Quoted 11 lines
lib/efi_loader/efi_capsule.c +9 -0
      return ret;
 }
+
+#if defined(CONFIG_EFI_CAPSULE_AUTHENTICATE)
+
+const efi_guid_t efi_guid_capsule_root_cert_guid =
+     EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
+
+__weak u16 *efi_get_truststore_name(void)
+{
+     return L"CRT";

This variable is not defined by UEFI specification, isn't it? How can this variable be protected?

Quoted 1 line

This is not part of the uefi specification. The uefi specification does

not

Quoted 2 lines

mandate any particular method for storing the root certificate to be used for capsule authentication. The edk2 code gets the root certificate

through

Quoted 1 line

a pcd. I had tried using KEK variable for storing the root certificate,

and

Quoted 1 line

had also come up with an implementation. However, the addition/deletion

and

Quoted 2 lines

update of the secure variables is very closely tied with the secure boot feature and the secure boot state of the system, which is the reason why

Quoted 9 lines

i

Quoted 1 line

dropped that solution and used a separate variable, which can be defined

by

Quoted 1 line

the vendor to store the root certificate.

My concern is that, without any protection, the value of this variable can be modified by a mal-user.
(One simple solution would be to set this variable read-only.)

Yes, that is one solution. This will also be taken care of in a scenario where the platform is booted in a trusted chain, and the env is also part of the image which gets verified by the previous stage(e.g BL2) before jumping to the u-boot image. If there is any change in the u-boot image, that would result in a boot failure -- but that would need the env to be part of the u-boot image which gets verified. I will explore making this variable read-only.

Quoted 88 lines
Quoted 57 lines
Quoted 57 lines
Quoted 19 lines
lib/efi_loader/efi_capsule.c +17 -0
+}
+
+__weak const efi_guid_t *efi_get_truststore_vendor(void)
+{
+
+     return &efi_guid_capsule_root_cert_guid;
+}
+
+/**
+ * efi_capsule_authenticate() - Authenticate a uefi capsule
+ *
+ * @capsule:         Capsule file with the authentication
+ *                   header
+ * @capsule_size:    Size of the entire capsule
+ * @image:           pointer to the image payload minus the
+ *                   authentication header
+ * @image_size:              size of the image payload

lib/efi_loader/efi_capsule.c out:

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+ *
+ * Authenticate the capsule signature with the public key contained
+ * in the root certificate stored as an efi environment variable
+ *
+ * Return: EFI_SUCCESS on successfull authentication or
+ *      EFI_SECURITY_VIOLATION on authentication failure
+ */
+efi_status_t efi_capsule_authenticate(const void *capsule,
+                                   efi_uintn_t capsule_size,
+                                   void **image, efi_uintn_t

*image_size)

Quoted 16 lines
lib/efi_loader/efi_capsule.c +16 -0
+{
+     uint64_t monotonic_count;
+     struct efi_signature_store *truststore;
+     struct pkcs7_message *capsule_sig;
+     struct efi_image_regions *regs;
+     struct efi_firmware_image_authentication *auth_hdr;
+     efi_status_t status;
+
+     status = EFI_SECURITY_VIOLATION;
+     capsule_sig = NULL;
+     truststore = NULL;
+     regs = NULL;
+
+     /* Sanity checks */
+     if (capsule == NULL || capsule_size == 0)
+             goto out;

lib/efi_loader/efi_capsule.c out:

Quoted 10 lines
lib/efi_loader/efi_capsule.c +10 -0
+
+     auth_hdr = (struct efi_firmware_image_authentication *)capsule;
+     if (capsule_size < sizeof(*auth_hdr))
+             goto out;
+
+     if (auth_hdr->auth_info.hdr.dwLength <=
+         offsetof(struct win_certificate_uefi_guid, cert_data))
+             goto out;
+
+     if (guidcmp(&auth_hdr->auth_info.cert_type,

&efi_guid_cert_type_pkcs7))

Quoted 3 lines
Quoted 3 lines

lib/efi_loader/efi_capsule.c out:

Quoted 3 lines
lib/efi_loader/efi_capsule.c +3 -0
+             goto out;
+
+     *image = (uint8_t *)capsule +

sizeof(auth_hdr->monotonic_count) +

Quoted 3 lines
Quoted 3 lines

lib/efi_loader/efi_capsule.c out: · line 322

Quoted 3 lines
lib/efi_loader/efi_capsule.c +3 -0
+             auth_hdr->auth_info.hdr.dwLength;
+     *image_size = capsule_size - auth_hdr->auth_info.hdr.dwLength -
+

sizeof(auth_hdr->monotonic_count);

Quoted 5 lines
Quoted 5 lines

lib/efi_loader/efi_capsule.c out:

Quoted 5 lines
lib/efi_loader/efi_capsule.c +5 -0
+     memcpy(&monotonic_count, &auth_hdr->monotonic_count,
+            sizeof(monotonic_count));
+
+     /* data to be digested */
+     regs = calloc(sizeof(*regs) + sizeof(struct image_region) * 2,

1);

Quoted 17 lines
Quoted 16 lines

lib/efi_loader/efi_capsule.c out:

Quoted 9 lines
lib/efi_loader/efi_capsule.c +9 -0
+     if (!regs)
+             goto out;
+
+     regs->max = 2;
+     efi_image_region_add(regs, (uint8_t *)*image,
+                          (uint8_t *)*image + *image_size, 1);
+
+     efi_image_region_add(regs, (uint8_t *)&monotonic_count,
+                          (uint8_t *)&monotonic_count +

sizeof(monotonic_count),

lib/efi_loader/efi_capsule.c out: · line 334

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+                          1);

Is the order of regions to be calculated correct? It seems that 'monotonic_count' precedes 'image' itself in a capsule header.

Quoted 5 lines
Quoted 1 line

Does that have any impact on the hash value computed.

Not 100% sure, but if it doesn't, it cannot guarantee uniqueness of digest values.

Will check this.

-sughosh

Quoted 29 lines

Thanks,
-Takahiro Akashi

Quoted 2 lines

I did not see any
difference in the hash value computed due to the order in which the

regions

Quoted 7 lines

are added. But that could be because of the way the hash value gets computed at the time of building the capsule. I will check this out.

Quoted 3 lines
Quoted 3 lines
lib/efi_loader/efi_capsule.c +2 -0
+
+     capsule_sig =

efi_parse_pkcs7_header(auth_hdr->auth_info.cert_data,

Quoted 13 lines
Quoted 9 lines

lib/efi_loader/efi_capsule.c out: · line 337

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+

auth_hdr->auth_info.hdr.dwLength

lib/efi_loader/efi_capsule.c out: · line 338

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+                                          -

sizeof(auth_hdr->auth_info));

lib/efi_loader/efi_capsule.c out: · line 339

Quoted 1 line
lib/efi_loader/efi_capsule.c +1 -0
+     if (IS_ERR(capsule_sig)) {

As Patrick reported, ex-efi_variable_parse_signature() returns NULL on error cases, this check should be "!capsule_sig."

Will change.

-sughosh

#33 lore raw

PATCH 7/8 qemu: arm64: Add support for uefi capsule authentication

In reply to Sughosh Ganu

Add support for uefi capsule authentication feature for the qemu arm64 platform. This feature is enabled by setting the environment variable "capsule_authentication_enabled".

The following configs are needed for enabling uefi capsule update and capsule authentication features on the platform.

CONFIG_EFI_CAPSULE_ON_DISK=y
CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
CONFIG_EFI_CAPSULE_AUTHENTICATE=y

---
 board/emulation/qemu-arm/qemu_efi_fmp.c | 49 +++++++++++++++++++++----
 1 file changed, 41 insertions(+), 8 deletions(-)
board/emulation/qemu-arm/qemu_efi_fmp.c +41 -8
index 9baea94e6c..b58843f8fb 100644
@@ -101,9 +101,15 @@ static efi_status_t EFIAPI qemu_arm64_fmp_get_image_info(
 	image_info[0].size = 0;
 
 	image_info[0].attributes_supported =
-		EFI_IMAGE_ATTRIBUTE_IMAGE_UPDATABLE;
+		EFI_IMAGE_ATTRIBUTE_IMAGE_UPDATABLE |
+		EFI_IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
 	image_info[0].attributes_setting = EFI_IMAGE_ATTRIBUTE_IMAGE_UPDATABLE;
 
+	/* Check if the capsule authentication is enabled */
+	if (env_get("capsule_authentication_enabled"))
+		image_info[0].attributes_setting |=
+			EFI_IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
+
 	image_info[0].lowest_supported_image_version = 1;
 	image_info[0].last_attempt_version = 0;
 	image_info[0].last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS;
@@ -142,17 +148,12 @@ static efi_status_t EFIAPI qemu_arm64_fmp_set_image(
 	long fd, ret;
 	efi_status_t status = EFI_SUCCESS;
 	char *mode = "w+b";
+	void *capsule_payload;
+	efi_uintn_t capsule_payload_size;
 
 	EFI_ENTRY("%p %d %p %ld %p %p %p\n", this, image_index, image,
 		  image_size, vendor_code, progress, abort_reason);
 
-	/*
-	 * Put a hack here to offset the size of
-	 * the FMP_PAYLOAD_HEADER that gets added
-	 * by the GenerateCapsule script in edk2.
-	 */
-	image += 0x10;
-	image_size -= 0x10;
 
 	/* Do all the sanity checks first */
 	if (!image) {
@@ -170,6 +171,38 @@ static efi_status_t EFIAPI qemu_arm64_fmp_set_image(
 		goto back;
 	}
 
+	/* Authenticate the capsule if authentication enabled */
+	if (IS_ENABLED(CONFIG_EFI_CAPSULE_AUTHENTICATE) &&
+	    env_get("capsule_authentication_enabled")) {
+		capsule_payload = NULL;
+		capsule_payload_size = 0;
+		status = efi_capsule_authenticate(image, image_size,
+						  &capsule_payload,
+						  &capsule_payload_size);
+
+		if (status == EFI_SECURITY_VIOLATION) {
+			printf("Capsule authentication check failed. Aborting update\n");
+			goto back;
+		} else if (status != EFI_SUCCESS) {
+			goto back;
+		}
+
+		debug("Capsule authentication successfull\n");
+		image = capsule_payload;
+		image_size = capsule_payload_size;
+	} else {
+		debug("Capsule authentication disabled. ");
+		debug("Updating capsule without authenticating.\n");
+	}
+
+	/*
+	 * Put a hack here to offset the size of
+	 * the FMP_PAYLOAD_HEADER that gets added
+	 * by the GenerateCapsule script in edk2.
+	 */
+	image += 0x10;
+	image_size -= 0x10;
+
 	/* Do the update */
 	fd = smh_open(UBOOT_FILE, mode);
 	if (fd == -1) {
Signature · 1 line
2.17.1
#34 lore raw

PATCH 8/8 qemu: arm64: Add documentation for capsule update

In reply to Sughosh Ganu

Add documentation highlighting the steps for using the uefi capsule update feature for updating the u-boot firmware image.

---
 doc/board/emulation/qemu-arm.rst | 112 +++++++++++++++++++++++++++++++
 1 file changed, 112 insertions(+)
doc/board/emulation/qemu-arm.rst +112 -0
index ca751d4af4..8649d593ed 100644
@@ -80,3 +80,115 @@ can be enabled with the following command line parameters:
     -drive if=none,file=disk.img,id=mydisk -device nvme,drive=mydisk,serial=foo
 
 These have been tested in QEMU 2.9.0 but should work in at least 2.5.0 as well.
+
+Enabling Uefi Capsule Update feature
+------------------------------------
+
+Support has been added for the uefi capsule update feature which
+enables updating the u-boot image using the uefi firmware management
+protocol (fmp). The capsules are not passed to the firmware through
+the UpdateCapsule runtime service. Instead, capsule-on-disk
+functionality is used for fetching the capsule from the EFI System
+Partition (ESP). Currently, support has been added for the arm64
+target booting with arm trusted firmware. The This feature is enabled
+with the following configs::
+
+    CONFIG_EFI_CAPSULE_ON_DISK=y
+    CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
+    CONFIG_CMD_EFIDEBUG=y
+
+The capsule file can be generated by using the GenerateCapsule.py
+script in edk2::
+
+    $ ./BaseTools/BinWrappers/PosixLike/GenerateCapsule -e -o \
+    <capsule_file_name> --fw-version <val> --lsv <val> --guid \
+    fb90808a-ba9a-4d42-b9a2-a7a937144aee --verbose --update-image-index \
+    <val> --verbose <u-boot.bin>
+
+
+As per the uefi specification, the capsule file needs to be placed on
+the EFI System Partition, under the EFI/UpdateCapsule/ directory. The
+EFI System Partition can be a virtio-blk-device.
+
+Before initiating the firmware update, the efi variables BootNext and
+BootXXXX need to be set. The BootXXXX variable needs to be pointing to
+the EFI System Partition which contains the capsule file. The
+BootNext and BootXXXX variables can be set using the efidebug
+command::
+
+    => efidebug boot add 0 Boot0000 virtio 0:1 <capsule_file_name>
+    => efidebug boot next 0
+
+The OsIndications efi variable needs to be set with the
+EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED flag set::
+
+    => setenv -e -nv -bs -rt OsIndications =0x04
+    => saveenv
+
+The capsule update function will be invoked on subsequent boot as part
+of the main_loop function. The updated u-boot image will be booted on
+subsequent boot.
+
+
+Enabling Capsule Authentication
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The uefi specification defines a way of authenticating the capsule to
+be updated by verifying the capsule signature. The capsule signature
+is computed and prepended to the capsule payload at the time of
+capsule generation. This signature is then verified by using the
+public key stored as part of the X509 certificate. This certificate is
+in the form of an efi signature list (esl) file, which is stored as an
+efi variable.
+
+The capsule authentication feature can be enabled through the
+following config, in addition to the configs listed above for capsule
+update::
+
+    CONFIG_EFI_CAPSULE_AUTHENTICATE=y
+
+The esl file can be generated as follows:
+
+1. Install utility commands on your host
+    * openssl
+    * efitools
+
+2. Create signing keys and certificate files on your host::
+
+        $ openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=CRT/ \
+                -keyout CRT.key -out CRT.crt -nodes -days 365
+        $ cert-to-efi-sig-list CRT.crt CRT.esl
+
+        $ openssl x509 -in CRT.crt -out CRT.cer -outform DER
+        $ openssl x509 -inform DER -in CRT.cer -outform PEM -out CRT.pub.pem
+
+        $ openssl pkcs12 -export -out CRT.pfx -inkey CRT.key -in CRT.crt
+        $ openssl pkcs12 -in CRT.pfx -nodes -out CRT.pem
+
+3. Store the esl file generated above as an efi variable::
+
+        => fatload virtio 0:1 <load_addr> EFI/CRT.esl
+        => setenv -e -nv -bs -rt -i <load_addr>,$filesize CRT
+
+        => setenv capsule_authentication_enabled 1
+        => setenv -e -nv -bs -rt OsIndication =0x04
+        => saveenv
+
+Setting the environment variable capsule_authentication_enabled
+enables the capsule authentication.
+
+4. The capsule file can be generated by using the GenerateCapsule.py
+   script in edk2::
+
+        $ ./BaseTools/BinWrappers/PosixLike/GenerateCapsule -e -o \
+	<capsule_file_name> --monotonic-count <val> --fw-version \
+	<val> --lsv <val> --guid \
+	fb90808a-ba9a-4d42-b9a2-a7a937144aee --verbose \
+	--update-image-index <val> --signer-private-cert \
+	/path/to/CRT.pem --trusted-public-cert \
+	/path/to/CRT.pub.pem --other-public-cert /path/to/CRT.pub.pem \
+	<u-boot.bin>
+
+Once the capsule has been generated, use the same instructions as
+mentioned above for placing the capsule on the EFI System Partition
+and subsequently to initiate the update.
Signature · 1 line
2.17.1
#35 lore raw

PATCH 8/8 qemu: arm64: Add documentation for capsule update

Quoted 4 lines · Sughosh Ganu

Add documentation highlighting the steps for using the uefi capsule update feature for updating the u-boot firmware image.

UEFI capsule updates should be architecture independent. I would expect that the submitted code should work for x86, ARM, and RISC-V. Why does this documentation live under the ARM emulation tree?

Best regards

Heinrich

Quoted 125 lines
---
 doc/board/emulation/qemu-arm.rst | 112 +++++++++++++++++++++++++++++++
 1 file changed, 112 insertions(+)
doc/board/emulation/qemu-arm.rst +112 -0
index ca751d4af4..8649d593ed 100644
@@ -80,3 +80,115 @@ can be enabled with the following command line parameters:
     -drive if=none,file=disk.img,id=mydisk -device nvme,drive=mydisk,serial=foo
 
 These have been tested in QEMU 2.9.0 but should work in at least 2.5.0 as well.
+
+Enabling Uefi Capsule Update feature
+------------------------------------
+
+Support has been added for the uefi capsule update feature which
+enables updating the u-boot image using the uefi firmware management
+protocol (fmp). The capsules are not passed to the firmware through
+the UpdateCapsule runtime service. Instead, capsule-on-disk
+functionality is used for fetching the capsule from the EFI System
+Partition (ESP). Currently, support has been added for the arm64
+target booting with arm trusted firmware. The This feature is enabled
+with the following configs::
+
+    CONFIG_EFI_CAPSULE_ON_DISK=y
+    CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
+    CONFIG_CMD_EFIDEBUG=y
+
+The capsule file can be generated by using the GenerateCapsule.py
+script in edk2::
+
+    $ ./BaseTools/BinWrappers/PosixLike/GenerateCapsule -e -o \
+    <capsule_file_name> --fw-version <val> --lsv <val> --guid \
+    fb90808a-ba9a-4d42-b9a2-a7a937144aee --verbose --update-image-index \
+    <val> --verbose <u-boot.bin>
+
+
+As per the uefi specification, the capsule file needs to be placed on
+the EFI System Partition, under the EFI/UpdateCapsule/ directory. The
+EFI System Partition can be a virtio-blk-device.
+
+Before initiating the firmware update, the efi variables BootNext and
+BootXXXX need to be set. The BootXXXX variable needs to be pointing to
+the EFI System Partition which contains the capsule file. The
+BootNext and BootXXXX variables can be set using the efidebug
+command::
+
+    => efidebug boot add 0 Boot0000 virtio 0:1 <capsule_file_name>
+    => efidebug boot next 0
+
+The OsIndications efi variable needs to be set with the
+EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED flag set::
+
+    => setenv -e -nv -bs -rt OsIndications =0x04
+    => saveenv
+
+The capsule update function will be invoked on subsequent boot as part
+of the main_loop function. The updated u-boot image will be booted on
+subsequent boot.
+
+
+Enabling Capsule Authentication
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The uefi specification defines a way of authenticating the capsule to
+be updated by verifying the capsule signature. The capsule signature
+is computed and prepended to the capsule payload at the time of
+capsule generation. This signature is then verified by using the
+public key stored as part of the X509 certificate. This certificate is
+in the form of an efi signature list (esl) file, which is stored as an
+efi variable.
+
+The capsule authentication feature can be enabled through the
+following config, in addition to the configs listed above for capsule
+update::
+
+    CONFIG_EFI_CAPSULE_AUTHENTICATE=y
+
+The esl file can be generated as follows:
+
+1. Install utility commands on your host
+    * openssl
+    * efitools
+
+2. Create signing keys and certificate files on your host::
+
+        $ openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=CRT/ \
+                -keyout CRT.key -out CRT.crt -nodes -days 365
+        $ cert-to-efi-sig-list CRT.crt CRT.esl
+
+        $ openssl x509 -in CRT.crt -out CRT.cer -outform DER
+        $ openssl x509 -inform DER -in CRT.cer -outform PEM -out CRT.pub.pem
+
+        $ openssl pkcs12 -export -out CRT.pfx -inkey CRT.key -in CRT.crt
+        $ openssl pkcs12 -in CRT.pfx -nodes -out CRT.pem
+
+3. Store the esl file generated above as an efi variable::
+
+        => fatload virtio 0:1 <load_addr> EFI/CRT.esl
+        => setenv -e -nv -bs -rt -i <load_addr>,$filesize CRT
+
+        => setenv capsule_authentication_enabled 1
+        => setenv -e -nv -bs -rt OsIndication =0x04
+        => saveenv
+
+Setting the environment variable capsule_authentication_enabled
+enables the capsule authentication.
+
+4. The capsule file can be generated by using the GenerateCapsule.py
+   script in edk2::
+
+        $ ./BaseTools/BinWrappers/PosixLike/GenerateCapsule -e -o \
+	<capsule_file_name> --monotonic-count <val> --fw-version \
+	<val> --lsv <val> --guid \
+	fb90808a-ba9a-4d42-b9a2-a7a937144aee --verbose \
+	--update-image-index <val> --signer-private-cert \
+	/path/to/CRT.pem --trusted-public-cert \
+	/path/to/CRT.pub.pem --other-public-cert /path/to/CRT.pub.pem \
+	<u-boot.bin>
+
+Once the capsule has been generated, use the same instructions as
+mentioned above for placing the capsule on the EFI System Partition
+and subsequently to initiate the update.
#36 lore raw

PATCH 8/8 qemu: arm64: Add documentation for capsule update

Quoted 10 lines · Heinrich Schuchardt
Quoted 4 lines · Sughosh Ganu

Add documentation highlighting the steps for using the uefi capsule update feature for updating the u-boot firmware image.

UEFI capsule updates should be architecture independent. I would expect that the submitted code should work for x86, ARM, and RISC-V. Why does this documentation live under the ARM emulation tree?

While the implementation of the core capsule update functionality is indeed architecture agnostic, this series is for implementing the routines of the firmware management protocol, which is very much platform specific -- the routines to perform the actual firmware update would be very much tied to the platform for which the firmware is being updated. So Takahiro's patch series, which adds the core capsule update changes is architecture independent, while this series is adding the routines for the firmware management protocol, which would be very much platform specific.

-sughosh

Quoted 138 lines

Best regards

Heinrich

Review

Quoted 5 lines
---
 doc/board/emulation/qemu-arm.rst | 112 +++++++++++++++++++++++++++++++
 1 file changed, 112 insertions(+)
(quoted diff) +0 -0

b/doc/board/emulation/qemu-arm.rst

doc/board/emulation/qemu-arm.rst can be enabled with the following command line

Quoted 4 lines

index ca751d4af4..8649d593ed 100644

doc/board/emulation/qemu-arm.rst +0 -0
@@ -80,3 +80,115 @@ can be enabled with the following command line

parameters:

doc/board/emulation/qemu-arm.rst can be enabled with the following command line · line 80

Quoted 1 line
doc/board/emulation/qemu-arm.rst +0 -0
     -drive if=none,file=disk.img,id=mydisk -device

nvme,drive=mydisk,serial=foo

doc/board/emulation/qemu-arm.rst can be enabled with the following command line · line 81

Quoted 2 lines
doc/board/emulation/qemu-arm.rst +0 -0
 These have been tested in QEMU 2.9.0 but should work in at least 2.5.0

as well.

Quoted 13 lines
doc/board/emulation/qemu-arm.rst +13 -0
+
+Enabling Uefi Capsule Update feature
+------------------------------------
+
+Support has been added for the uefi capsule update feature which
+enables updating the u-boot image using the uefi firmware management
+protocol (fmp). The capsules are not passed to the firmware through
+the UpdateCapsule runtime service. Instead, capsule-on-disk
+functionality is used for fetching the capsule from the EFI System
+Partition (ESP). Currently, support has been added for the arm64
+target booting with arm trusted firmware. The This feature is enabled
+with the following configs::
+

doc/board/emulation/qemu-arm.rst can be enabled with the following command line parameters:

Quoted 10 lines
doc/board/emulation/qemu-arm.rst +10 -0
+    CONFIG_EFI_CAPSULE_ON_DISK=y
+    CONFIG_EFI_FIRMWARE_MANAGEMENT_PROTOCOL=y
+    CONFIG_CMD_EFIDEBUG=y
+
+The capsule file can be generated by using the GenerateCapsule.py
+script in edk2::
+
+    $ ./BaseTools/BinWrappers/PosixLike/GenerateCapsule -e -o \
+    <capsule_file_name> --fw-version <val> --lsv <val> --guid \
+    fb90808a-ba9a-4d42-b9a2-a7a937144aee --verbose --update-image-index

\

Quoted 48 lines
doc/board/emulation/qemu-arm.rst +48 -0
+    <val> --verbose <u-boot.bin>
+
+
+As per the uefi specification, the capsule file needs to be placed on
+the EFI System Partition, under the EFI/UpdateCapsule/ directory. The
+EFI System Partition can be a virtio-blk-device.
+
+Before initiating the firmware update, the efi variables BootNext and
+BootXXXX need to be set. The BootXXXX variable needs to be pointing to
+the EFI System Partition which contains the capsule file. The
+BootNext and BootXXXX variables can be set using the efidebug
+command::
+
+    => efidebug boot add 0 Boot0000 virtio 0:1 <capsule_file_name>
+    => efidebug boot next 0
+
+The OsIndications efi variable needs to be set with the
+EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED flag set::
+
+    => setenv -e -nv -bs -rt OsIndications =0x04
+    => saveenv
+
+The capsule update function will be invoked on subsequent boot as part
+of the main_loop function. The updated u-boot image will be booted on
+subsequent boot.
+
+
+Enabling Capsule Authentication
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The uefi specification defines a way of authenticating the capsule to
+be updated by verifying the capsule signature. The capsule signature
+is computed and prepended to the capsule payload at the time of
+capsule generation. This signature is then verified by using the
+public key stored as part of the X509 certificate. This certificate is
+in the form of an efi signature list (esl) file, which is stored as an
+efi variable.
+
+The capsule authentication feature can be enabled through the
+following config, in addition to the configs listed above for capsule
+update::
+
+    CONFIG_EFI_CAPSULE_AUTHENTICATE=y
+
+The esl file can be generated as follows:
+
+1. Install utility commands on your host
+    * openssl

doc/board/emulation/qemu-arm.rst can be enabled with the following command line parameters:

Quoted 10 lines
doc/board/emulation/qemu-arm.rst +10 -0
+    * efitools
+
+2. Create signing keys and certificate files on your host::
+
+        $ openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=CRT/ \
+                -keyout CRT.key -out CRT.crt -nodes -days 365
+        $ cert-to-efi-sig-list CRT.crt CRT.esl
+
+        $ openssl x509 -in CRT.crt -out CRT.cer -outform DER
+        $ openssl x509 -inform DER -in CRT.cer -outform PEM -out

CRT.pub.pem

Quoted 32 lines
doc/board/emulation/qemu-arm.rst +31 -0
+
+        $ openssl pkcs12 -export -out CRT.pfx -inkey CRT.key -in CRT.crt
+        $ openssl pkcs12 -in CRT.pfx -nodes -out CRT.pem
+
+3. Store the esl file generated above as an efi variable::
+
+        => fatload virtio 0:1 <load_addr> EFI/CRT.esl
+        => setenv -e -nv -bs -rt -i <load_addr>,$filesize CRT
+
+        => setenv capsule_authentication_enabled 1
+        => setenv -e -nv -bs -rt OsIndication =0x04
+        => saveenv
+
+Setting the environment variable capsule_authentication_enabled
+enables the capsule authentication.
+
+4. The capsule file can be generated by using the GenerateCapsule.py
+   script in edk2::
+
+        $ ./BaseTools/BinWrappers/PosixLike/GenerateCapsule -e -o \
+     <capsule_file_name> --monotonic-count <val> --fw-version \
+     <val> --lsv <val> --guid \
+     fb90808a-ba9a-4d42-b9a2-a7a937144aee --verbose \
+     --update-image-index <val> --signer-private-cert \
+     /path/to/CRT.pem --trusted-public-cert \
+     /path/to/CRT.pub.pem --other-public-cert /path/to/CRT.pub.pem \
+     <u-boot.bin>
+
+Once the capsule has been generated, use the same instructions as
+mentioned above for placing the capsule on the EFI System Partition
+and subsequently to initiate the update.
 
#37 lore raw

PATCH 8/8 qemu: arm64: Add documentation for capsule update

Quoted 13 lines · Sughosh Ganu
Quoted 10 lines · Heinrich Schuchardt
Quoted 4 lines · Sughosh Ganu

Add documentation highlighting the steps for using the uefi capsule update feature for updating the u-boot firmware image.

UEFI capsule updates should be architecture independent. I would expect that the submitted code should work for x86, ARM, and RISC-V. Why does this documentation live under the ARM emulation tree?

Quoted 8 lines

While the implementation of the core capsule update functionality is indeed architecture agnostic, this series is for implementing the routines of the firmware management protocol, which is very much platform specific -- the routines to perform the actual firmware update would be very much tied to the platform for which the firmware is being updated. So Takahiro's patch series, which adds the core capsule update changes is architecture independent, while this series is adding the routines for the firmware management protocol, which would be very much platform specific.

Since we're talking QEMU here, how much of this can be easily dropped in to QEMU x86_64 and QEMU RISC-V? If not almost all of it, why? Can it be reworked as such?

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200430/2286b017/attachment.sig>
#38 lore raw

PATCH 8/8 qemu: arm64: Add documentation for capsule update

Quoted 26 lines · Tom Rini
Quoted 1 line · Sughosh Ganu

On Fri, 1 May 2020 at 00:07, Heinrich Schuchardt <[email protected]>

Quoted 5 lines · wrote:
Quoted 5 lines · Sughosh Ganu
Quoted 3 lines

Add documentation highlighting the steps for using the uefi capsule update feature for updating the u-boot firmware image.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

UEFI capsule updates should be architecture independent. I would expect that the submitted code should work for x86, ARM, and RISC-V. Why does this documentation live under the ARM emulation tree?

While the implementation of the core capsule update functionality is

indeed

Quoted 1 line

architecture agnostic, this series is for implementing the routines of

the

Quoted 6 lines

firmware management protocol, which is very much platform specific -- the routines to perform the actual firmware update would be very much tied to the platform for which the firmware is being updated. So Takahiro's patch series, which adds the core capsule update changes is architecture independent, while this series is adding the routines for the firmware management protocol, which would be very much platform specific.

Quoted 4 lines

Since we're talking QEMU here, how much of this can be easily dropped in to QEMU x86_64 and QEMU RISC-V? If not almost all of it, why? Can it be reworked as such?

I don't think it would be too difficult to extend it on other architectures, provided there is some mechanism to access and overwrite the u-boot binary file from the qemu target. It is currently being done using the semihosting interface for the arm architecture. I am not aware if there is an interface like semihosting for accessing the u-boot binary on the other architectures that you mentioned. Will check on this.

-sughosh

#39 lore raw

PATCH 8/8 qemu: arm64: Add documentation for capsule update

Quoted 33 lines · Sughosh Ganu
Quoted 26 lines · Tom Rini
Quoted 1 line · Sughosh Ganu

On Fri, 1 May 2020 at 00:07, Heinrich Schuchardt <[email protected]>

Quoted 5 lines · wrote:
Quoted 5 lines · Sughosh Ganu
Quoted 3 lines

Add documentation highlighting the steps for using the uefi capsule update feature for updating the u-boot firmware image.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

UEFI capsule updates should be architecture independent. I would expect that the submitted code should work for x86, ARM, and RISC-V. Why does this documentation live under the ARM emulation tree?

While the implementation of the core capsule update functionality is

indeed

Quoted 1 line

architecture agnostic, this series is for implementing the routines of

the

Quoted 6 lines

firmware management protocol, which is very much platform specific -- the routines to perform the actual firmware update would be very much tied to the platform for which the firmware is being updated. So Takahiro's patch series, which adds the core capsule update changes is architecture independent, while this series is adding the routines for the firmware management protocol, which would be very much platform specific.

Quoted 4 lines

Since we're talking QEMU here, how much of this can be easily dropped in to QEMU x86_64 and QEMU RISC-V? If not almost all of it, why? Can it be reworked as such?

Quoted 6 lines

I don't think it would be too difficult to extend it on other architectures, provided there is some mechanism to access and overwrite the u-boot binary file from the qemu target. It is currently being done using the semihosting interface for the arm architecture. I am not aware if there is an interface like semihosting for accessing the u-boot binary on the other architectures that you mentioned. Will check on this.

Obviously, another choice would be my FIT-based FMP[1] as it uses update_tftp(), more specifically dfu_tftp_write(), internally.

[1] https://lists.denx.de/pipermail/u-boot/2020-April/408767.html

Thanks,
-Takahiro Akashi

Quoted 1 line

-sughosh

#40 lore raw

PATCH 8/8 qemu: arm64: Add documentation for capsule update

Quoted 41 lines · Akashi Takahiro
Quoted 33 lines · Sughosh Ganu
Quoted 26 lines · Tom Rini
Quoted 1 line · Sughosh Ganu

On Fri, 1 May 2020 at 00:07, Heinrich Schuchardt <[email protected]>

Quoted 5 lines · wrote:
Quoted 5 lines · Sughosh Ganu
Quoted 3 lines

Add documentation highlighting the steps for using the uefi capsule update feature for updating the u-boot firmware image.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

UEFI capsule updates should be architecture independent. I would expect that the submitted code should work for x86, ARM, and RISC-V. Why does this documentation live under the ARM emulation tree?

While the implementation of the core capsule update functionality is

indeed

Quoted 1 line

architecture agnostic, this series is for implementing the routines of

the

Quoted 6 lines

firmware management protocol, which is very much platform specific -- the routines to perform the actual firmware update would be very much tied to the platform for which the firmware is being updated. So Takahiro's patch series, which adds the core capsule update changes is architecture independent, while this series is adding the routines for the firmware management protocol, which would be very much platform specific.

Quoted 4 lines

Since we're talking QEMU here, how much of this can be easily dropped in to QEMU x86_64 and QEMU RISC-V? If not almost all of it, why? Can it be reworked as such?

Quoted 6 lines

I don't think it would be too difficult to extend it on other architectures, provided there is some mechanism to access and overwrite the u-boot binary file from the qemu target. It is currently being done using the semihosting interface for the arm architecture. I am not aware if there is an interface like semihosting for accessing the u-boot binary on the other architectures that you mentioned. Will check on this.

Quoted 8 lines

Obviously, another choice would be my FIT-based FMP[1] as it uses update_tftp(), more specifically dfu_tftp_write(), internally.

[1] https://lists.denx.de/pipermail/u-boot/2020-April/408767.html

Thanks,
-Takahiro Akashi

Please, try to align. We should avoid alternative implementations were not needed. We could also have a chat on Zoom together.

Best regards

Heinrich

Quoted 3 lines
Quoted 3 lines

-sughosh