Re: [PATCH v2 5/8] tools: mkeficapsule: Add support for parsing capsule params from config file

2023-07-17 Thread Michal Simek




On 7/15/23 14:30, Sughosh Ganu wrote:

On Fri, 14 Jul 2023 at 16:14, Michal Simek  wrote:




On 6/24/23 15:41, Sughosh Ganu wrote:

Add support for specifying the parameters needed for capsule
generation through a config file, instead of passing them through
command-line. Parameters for more than a single capsule file can be
specified, resulting in generation of multiple capsules through a
single invocation of the command.

This path is to be used for generating capsules through a make target,
with the parameters being parsed from the config file.



Can you please also add support for adding comment to config file?
Pretty much just ignore lines which starts with /* or so.


Comments are currently supported with the '#' character, so that lines
starting with # are considered as comments.


Good thanks.
M


Re: [PATCH v2 5/8] tools: mkeficapsule: Add support for parsing capsule params from config file

2023-07-15 Thread Sughosh Ganu
On Fri, 14 Jul 2023 at 16:14, Michal Simek  wrote:
>
>
>
> On 6/24/23 15:41, Sughosh Ganu wrote:
> > Add support for specifying the parameters needed for capsule
> > generation through a config file, instead of passing them through
> > command-line. Parameters for more than a single capsule file can be
> > specified, resulting in generation of multiple capsules through a
> > single invocation of the command.
> >
> > This path is to be used for generating capsules through a make target,
> > with the parameters being parsed from the config file.
> >
>
> Can you please also add support for adding comment to config file?
> Pretty much just ignore lines which starts with /* or so.

Comments are currently supported with the '#' character, so that lines
starting with # are considered as comments.

-sughosh


Re: [PATCH v2 5/8] tools: mkeficapsule: Add support for parsing capsule params from config file

2023-07-14 Thread Michal Simek




On 6/24/23 15:41, Sughosh Ganu wrote:

Add support for specifying the parameters needed for capsule
generation through a config file, instead of passing them through
command-line. Parameters for more than a single capsule file can be
specified, resulting in generation of multiple capsules through a
single invocation of the command.

This path is to be used for generating capsules through a make target,
with the parameters being parsed from the config file.



Can you please also add support for adding comment to config file?
Pretty much just ignore lines which starts with /* or so.

Thanks,
Michal



[PATCH v2 5/8] tools: mkeficapsule: Add support for parsing capsule params from config file

2023-06-24 Thread Sughosh Ganu
Add support for specifying the parameters needed for capsule
generation through a config file, instead of passing them through
command-line. Parameters for more than a single capsule file can be
specified, resulting in generation of multiple capsules through a
single invocation of the command.

This path is to be used for generating capsules through a make target,
with the parameters being parsed from the config file.

Signed-off-by: Sughosh Ganu 
---
Changes since V1:
* Add a cfg-file parameter to pass the config file to the mkeficapsule
  tool. This results in generation of the same tool image irrespective
  of using command-line parameters or config file.

 tools/Kconfig  |   9 +
 tools/Makefile |   1 +
 tools/eficapsule.h | 110 
 tools/mkeficapsule.c   |  84 +
 tools/mkeficapsule_parse.c | 345 +
 5 files changed, 519 insertions(+), 30 deletions(-)
 create mode 100644 tools/mkeficapsule_parse.c

diff --git a/tools/Kconfig b/tools/Kconfig
index 539708f277..95f27b7c45 100644
--- a/tools/Kconfig
+++ b/tools/Kconfig
@@ -98,6 +98,15 @@ config TOOLS_MKEFICAPSULE
  optionally sign that file. If you want to enable UEFI capsule
  update feature on your target, you certainly need this.
 
+config EFI_CAPSULE_CFG_FILE
+   string "Path to the EFI Capsule Config File"
+   default ""
+   help
+ Path to the EFI capsule config file which provides the
+ parameters needed to build capsule(s). Parameters can be
+ provided for multiple payloads resulting in corresponding
+ capsule images being generated.
+
 menuconfig FSPI_CONF_HEADER
bool "FlexSPI Header Configuration"
help
diff --git a/tools/Makefile b/tools/Makefile
index a5558eeb4d..833d8292e3 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -250,6 +250,7 @@ HOSTLDLIBS_mkeficapsule += \
 HOSTLDLIBS_mkeficapsule += \
$(shell pkg-config --libs uuid 2> /dev/null || echo "-luuid")
 hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule
+mkeficapsule-objs := mkeficapsule.o mkeficapsule_parse.o
 
 # We build some files with extra pedantic flags to try to minimize things
 # that won't build on some weird host compiler -- though there are lots of
diff --git a/tools/eficapsule.h b/tools/eficapsule.h
index 072a4b5598..42e66c6d6a 100644
--- a/tools/eficapsule.h
+++ b/tools/eficapsule.h
@@ -52,6 +52,38 @@ typedef struct {
 /* flags */
 #define CAPSULE_FLAGS_PERSIST_ACROSS_RESET  0x0001
 
+enum capsule_type {
+   CAPSULE_NORMAL_BLOB = 0,
+   CAPSULE_ACCEPT,
+   CAPSULE_REVERT,
+};
+
+/**
+ * struct efi_capsule_params - Capsule parameters
+ * @image_guid: Guid value of the payload input image
+ * @image_index: Image index value
+ * @hardware_instance: Hardware instance to be used for the image
+ * @monotonic_count: Monotonic count value to be used for signed capsule
+ * @privkey_file: Path to private key used in capsule signing
+ * @cert_file: Path to public key certificate used in capsule signing
+ * @input_file: Path to payload input image
+ * @capsule_file: Path to the output capsule file
+ * @oemflags: Oemflags to be populated in the capsule header
+ * @capsule: Capsule Type, normal or accept or revert
+ */
+struct efi_capsule_params {
+   efi_guid_t *image_guid;
+   unsigned long image_index;
+   unsigned long hardware_instance;
+   uint64_t monotonic_count;
+   char *privkey_file;
+   char *cert_file;
+   char *input_file;
+   char *capsule_file;
+   unsigned long oemflags;
+   enum capsule_type capsule;
+};
+
 struct efi_capsule_header {
efi_guid_t capsule_guid;
uint32_t header_size;
@@ -113,4 +145,82 @@ struct efi_firmware_image_authentication {
struct win_certificate_uefi_guid auth_info;
 } __packed;
 
+/**
+ * capsule_with_cfg_file() - Generate capsule from config file
+ * @cfg_file: Path to the config file
+ *
+ * Parse the capsule parameters from the config file and use the
+ * parameters for generating one or more capsules.
+ *
+ * Return: None
+ *
+ */
+void capsule_with_cfg_file(const char *cfg_file);
+
+/**
+ * convert_uuid_to_guid() - convert UUID to GUID
+ * @buf:   UUID binary
+ *
+ * UUID and GUID have the same data structure, but their binary
+ * formats are different due to the endianness. See lib/uuid.c.
+ * Since uuid_parse() can handle only UUID, this function must
+ * be called to get correct data for GUID when parsing a string.
+ *
+ * The correct data will be returned in @buf.
+ */
+void convert_uuid_to_guid(unsigned char *buf);
+
+/**
+ * create_empty_capsule() - Generate an empty capsule
+ * @path: Path to the empty capsule file to be generated
+ * @guid: Guid value of the image for which empty capsule is generated
+ * @fw_accept: Flag to specify whether to generate accept or revert capsule
+ *
+ * Generate an empty capsule, either an accept or a revert capsule to be
+ * used to flag