diff mbox series

[v4,01/11] Revert "Revert "mkeficapsule: Remove dtb related options""

Message ID 20211007062340.72207-2-takahiro.akashi@linaro.org
State New
Headers show
Series efi_loader: capsule: improve capsule authentication support | expand

Commit Message

AKASHI Takahiro Oct. 7, 2021, 6:23 a.m. UTC
This reverts commit d428e81266a59974ade74c1ba019af39f23304ab.
We have agreed with removing dtb-related stuff from mkeficapsule
command even if the commit 47a25e81d35c ("Revert "efi_capsule: Move
signature from DTB to .rodata"") was applied.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

---
 tools/mkeficapsule.c | 229 ++-----------------------------------------
 1 file changed, 7 insertions(+), 222 deletions(-)

-- 
2.33.0

Comments

Simon Glass Oct. 8, 2021, 3:38 p.m. UTC | #1
Hi Takahiro,

On Thu, 7 Oct 2021 at 00:24, AKASHI Takahiro <takahiro.akashi@linaro.org> wrote:
>

> This reverts commit d428e81266a59974ade74c1ba019af39f23304ab.

> We have agreed with removing dtb-related stuff from mkeficapsule

> command even if the commit 47a25e81d35c ("Revert "efi_capsule: Move

> signature from DTB to .rodata"") was applied.


Can you please explain why this is being removed? How is the public
key to be communicated?

Please can you also copy me on future related patches? (thank for you
for the private email alerting me)

What does "We have agreed" mean?

>

> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

> ---

>  tools/mkeficapsule.c | 229 ++-----------------------------------------

>  1 file changed, 7 insertions(+), 222 deletions(-)

>


Regards,
Simon
Ilias Apalodimas Oct. 8, 2021, 7:11 p.m. UTC | #2
Hi Simon, 

On Fri, Oct 08, 2021 at 09:38:11AM -0600, Simon Glass wrote:
> Hi Takahiro,

> 

> On Thu, 7 Oct 2021 at 00:24, AKASHI Takahiro <takahiro.akashi@linaro.org> wrote:

> >

> > This reverts commit d428e81266a59974ade74c1ba019af39f23304ab.

> > We have agreed with removing dtb-related stuff from mkeficapsule

> > command even if the commit 47a25e81d35c ("Revert "efi_capsule: Move

> > signature from DTB to .rodata"") was applied.

> 

> Can you please explain why this is being removed? How is the public

> key to be communicated?


Via the script that Akashi-san is adding in this patch series.

> 

> Please can you also copy me on future related patches? (thank for you

> for the private email alerting me)

> 

> What does "We have agreed" mean?


This has nothing to do with the public key.  This is only changing the tool
we used to include the key in the DTB.  It is the same patch I mentioned you 
should never have reverted in the first place on your pull request,  but since
that happened very late in the release cycle we said we would re-apply it after
the release.

> 

> >

> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

> > ---

> >  tools/mkeficapsule.c | 229 ++-----------------------------------------

> >  1 file changed, 7 insertions(+), 222 deletions(-)

> >

> 

> Regards,

> Simon


It was my patch to begin with so I am not really sure my reviewed tag has
any value, but FWIW

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
AKASHI Takahiro Oct. 11, 2021, 12:29 a.m. UTC | #3
On Fri, Oct 08, 2021 at 10:11:59PM +0300, Ilias Apalodimas wrote:
> Hi Simon, 

> 

> On Fri, Oct 08, 2021 at 09:38:11AM -0600, Simon Glass wrote:

> > Hi Takahiro,

> > 

> > On Thu, 7 Oct 2021 at 00:24, AKASHI Takahiro <takahiro.akashi@linaro.org> wrote:

> > >

> > > This reverts commit d428e81266a59974ade74c1ba019af39f23304ab.

> > > We have agreed with removing dtb-related stuff from mkeficapsule

> > > command even if the commit 47a25e81d35c ("Revert "efi_capsule: Move

> > > signature from DTB to .rodata"") was applied.

> > 

> > Can you please explain why this is being removed? How is the public

> > key to be communicated?

> 

> Via the script that Akashi-san is adding in this patch series.


Yeah, please see my patch#4 for fdtsig.sh.
The reason why I think we should remove the feature from mkeficapsule
command is partly because we can do the same task by using *existing*
fdt tools and partly because having two totally-independent functionality
(one for a capsule binary and one for fdt) in a single tool seems confusing.

> > 

> > Please can you also copy me on future related patches? (thank for you

> > for the private email alerting me)

> > 

> > What does "We have agreed" mean?

> 

> This has nothing to do with the public key.  This is only changing the tool

> we used to include the key in the DTB.  It is the same patch I mentioned you 

> should never have reverted in the first place on your pull request,  but since

> that happened very late in the release cycle we said we would re-apply it after

> the release.


Indeed.

-Takahiro Akashi


> > 

> > >

> > > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

> > > ---

> > >  tools/mkeficapsule.c | 229 ++-----------------------------------------

> > >  1 file changed, 7 insertions(+), 222 deletions(-)

> > >

> > 

> > Regards,

> > Simon

> 

> It was my patch to begin with so I am not really sure my reviewed tag has

> any value, but FWIW

> 

> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Simon Glass Oct. 11, 2021, 2:54 p.m. UTC | #4
Hi Takahiro, Ilias,

On Sun, 10 Oct 2021 at 18:29, AKASHI Takahiro
<takahiro.akashi@linaro.org> wrote:
>

> On Fri, Oct 08, 2021 at 10:11:59PM +0300, Ilias Apalodimas wrote:

> > Hi Simon,

> >

> > On Fri, Oct 08, 2021 at 09:38:11AM -0600, Simon Glass wrote:

> > > Hi Takahiro,

> > >

> > > On Thu, 7 Oct 2021 at 00:24, AKASHI Takahiro <takahiro.akashi@linaro.org> wrote:

> > > >

> > > > This reverts commit d428e81266a59974ade74c1ba019af39f23304ab.

> > > > We have agreed with removing dtb-related stuff from mkeficapsule

> > > > command even if the commit 47a25e81d35c ("Revert "efi_capsule: Move

> > > > signature from DTB to .rodata"") was applied.

> > >

> > > Can you please explain why this is being removed? How is the public

> > > key to be communicated?

> >

> > Via the script that Akashi-san is adding in this patch series.

>

> Yeah, please see my patch#4 for fdtsig.sh.


OK I see. I don't think I was copied on that. I replied on the patch.

Is there a tree somewhere with all the patches and docs so I can take a look?

Regards,
Simon



> The reason why I think we should remove the feature from mkeficapsule

> command is partly because we can do the same task by using *existing*

> fdt tools and partly because having two totally-independent functionality

> (one for a capsule binary and one for fdt) in a single tool seems confusing.

>

> > >

> > > Please can you also copy me on future related patches? (thank for you

> > > for the private email alerting me)

> > >

> > > What does "We have agreed" mean?

> >

> > This has nothing to do with the public key.  This is only changing the tool

> > we used to include the key in the DTB.  It is the same patch I mentioned you

> > should never have reverted in the first place on your pull request,  but since

> > that happened very late in the release cycle we said we would re-apply it after

> > the release.

>

> Indeed.

>

> -Takahiro Akashi

>

>

> > >

> > > >

> > > > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

> > > > ---

> > > >  tools/mkeficapsule.c | 229 ++-----------------------------------------

> > > >  1 file changed, 7 insertions(+), 222 deletions(-)

> > > >

> > >

> > > Regards,

> > > Simon

> >

> > It was my patch to begin with so I am not really sure my reviewed tag has

> > any value, but FWIW

> >

> > Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
AKASHI Takahiro Oct. 12, 2021, 1:15 a.m. UTC | #5
Simon,

On Mon, Oct 11, 2021 at 08:54:10AM -0600, Simon Glass wrote:
> Hi Takahiro, Ilias,

> 

> On Sun, 10 Oct 2021 at 18:29, AKASHI Takahiro

> <takahiro.akashi@linaro.org> wrote:

> >

> > On Fri, Oct 08, 2021 at 10:11:59PM +0300, Ilias Apalodimas wrote:

> > > Hi Simon,

> > >

> > > On Fri, Oct 08, 2021 at 09:38:11AM -0600, Simon Glass wrote:

> > > > Hi Takahiro,

> > > >

> > > > On Thu, 7 Oct 2021 at 00:24, AKASHI Takahiro <takahiro.akashi@linaro.org> wrote:

> > > > >

> > > > > This reverts commit d428e81266a59974ade74c1ba019af39f23304ab.

> > > > > We have agreed with removing dtb-related stuff from mkeficapsule

> > > > > command even if the commit 47a25e81d35c ("Revert "efi_capsule: Move

> > > > > signature from DTB to .rodata"") was applied.

> > > >

> > > > Can you please explain why this is being removed? How is the public

> > > > key to be communicated?

> > >

> > > Via the script that Akashi-san is adding in this patch series.

> >

> > Yeah, please see my patch#4 for fdtsig.sh.

> 

> OK I see. I don't think I was copied on that. I replied on the patch.


In my initial submission, there were some accidentally-duplicated patches
that would have caused some confusion.

> Is there a tree somewhere with all the patches and docs so I can take a look?


Please take a look at:
https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/dm_disk

-Takahiro Akashi


> Regards,

> Simon

> 

> 

> 

> > The reason why I think we should remove the feature from mkeficapsule

> > command is partly because we can do the same task by using *existing*

> > fdt tools and partly because having two totally-independent functionality

> > (one for a capsule binary and one for fdt) in a single tool seems confusing.

> >

> > > >

> > > > Please can you also copy me on future related patches? (thank for you

> > > > for the private email alerting me)

> > > >

> > > > What does "We have agreed" mean?

> > >

> > > This has nothing to do with the public key.  This is only changing the tool

> > > we used to include the key in the DTB.  It is the same patch I mentioned you

> > > should never have reverted in the first place on your pull request,  but since

> > > that happened very late in the release cycle we said we would re-apply it after

> > > the release.

> >

> > Indeed.

> >

> > -Takahiro Akashi

> >

> >

> > > >

> > > > >

> > > > > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

> > > > > ---

> > > > >  tools/mkeficapsule.c | 229 ++-----------------------------------------

> > > > >  1 file changed, 7 insertions(+), 222 deletions(-)

> > > > >

> > > >

> > > > Regards,

> > > > Simon

> > >

> > > It was my patch to begin with so I am not really sure my reviewed tag has

> > > any value, but FWIW

> > >

> > > Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
diff mbox series

Patch

diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c
index de0a62898886..4995ba4e0c2a 100644
--- a/tools/mkeficapsule.c
+++ b/tools/mkeficapsule.c
@@ -4,22 +4,17 @@ 
  *		Author: AKASHI Takahiro
  */
 
-#include <errno.h>
 #include <getopt.h>
 #include <malloc.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <linux/types.h>
 
-#include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include "fdt_host.h"
-
 typedef __u8 u8;
 typedef __u16 u16;
 typedef __u32 u32;
@@ -29,9 +24,6 @@  typedef __s32 s32;
 
 #define aligned_u64 __aligned_u64
 
-#define SIGNATURE_NODENAME	"signature"
-#define OVERLAY_NODENAME	"__overlay__"
-
 #ifndef __packed
 #define __packed __attribute__((packed))
 #endif
@@ -52,9 +44,6 @@  static struct option options[] = {
 	{"raw", required_argument, NULL, 'r'},
 	{"index", required_argument, NULL, 'i'},
 	{"instance", required_argument, NULL, 'I'},
-	{"dtb", required_argument, NULL, 'D'},
-	{"public key", required_argument, NULL, 'K'},
-	{"overlay", no_argument, NULL, 'O'},
 	{"help", no_argument, NULL, 'h'},
 	{NULL, 0, NULL, 0},
 };
@@ -68,187 +57,10 @@  static void print_usage(void)
 	       "\t-r, --raw <raw image>       new raw image file\n"
 	       "\t-i, --index <index>         update image index\n"
 	       "\t-I, --instance <instance>   update hardware instance\n"
-	       "\t-K, --public-key <key file> public key esl file\n"
-	       "\t-D, --dtb <dtb file>        dtb file\n"
-	       "\t-O, --overlay               the dtb file is an overlay\n"
 	       "\t-h, --help                  print a help message\n",
 	       tool_name);
 }
 
-static int fdt_add_pub_key_data(void *sptr, void *dptr, size_t key_size,
-				bool overlay)
-{
-	int parent;
-	int ov_node;
-	int frag_node;
-	int ret = 0;
-
-	if (overlay) {
-		/*
-		 * The signature would be stored in the
-		 * first fragment node of the overlay
-		 */
-		frag_node = fdt_first_subnode(dptr, 0);
-		if (frag_node == -FDT_ERR_NOTFOUND) {
-			fprintf(stderr,
-				"Couldn't find the fragment node: %s\n",
-				fdt_strerror(frag_node));
-			goto done;
-		}
-
-		ov_node = fdt_subnode_offset(dptr, frag_node, OVERLAY_NODENAME);
-		if (ov_node == -FDT_ERR_NOTFOUND) {
-			fprintf(stderr,
-				"Couldn't find the __overlay__ node: %s\n",
-				fdt_strerror(ov_node));
-			goto done;
-		}
-	} else {
-		ov_node = 0;
-	}
-
-	parent = fdt_subnode_offset(dptr, ov_node, SIGNATURE_NODENAME);
-	if (parent == -FDT_ERR_NOTFOUND) {
-		parent = fdt_add_subnode(dptr, ov_node, SIGNATURE_NODENAME);
-		if (parent < 0) {
-			ret = parent;
-			if (ret != -FDT_ERR_NOSPACE) {
-				fprintf(stderr,
-					"Couldn't create signature node: %s\n",
-					fdt_strerror(parent));
-			}
-		}
-	}
-	if (ret)
-		goto done;
-
-	/* Write the key to the FDT node */
-	ret = fdt_setprop(dptr, parent, "capsule-key",
-			  sptr, key_size);
-
-done:
-	if (ret)
-		ret = ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
-
-	return ret;
-}
-
-static int add_public_key(const char *pkey_file, const char *dtb_file,
-			  bool overlay)
-{
-	int ret;
-	int srcfd = -1;
-	int destfd = -1;
-	void *sptr = NULL;
-	void *dptr = NULL;
-	off_t src_size;
-	struct stat pub_key;
-	struct stat dtb;
-
-	/* Find out the size of the public key */
-	srcfd = open(pkey_file, O_RDONLY);
-	if (srcfd == -1) {
-		fprintf(stderr, "%s: Can't open %s: %s\n",
-			__func__, pkey_file, strerror(errno));
-		ret = -1;
-		goto err;
-	}
-
-	ret = fstat(srcfd, &pub_key);
-	if (ret == -1) {
-		fprintf(stderr, "%s: Can't stat %s: %s\n",
-			__func__, pkey_file, strerror(errno));
-		ret = -1;
-		goto err;
-	}
-
-	src_size = pub_key.st_size;
-
-	/* mmap the public key esl file */
-	sptr = mmap(0, src_size, PROT_READ, MAP_SHARED, srcfd, 0);
-	if (sptr == MAP_FAILED) {
-		fprintf(stderr, "%s: Failed to mmap %s:%s\n",
-			__func__, pkey_file, strerror(errno));
-		ret = -1;
-		goto err;
-	}
-
-	/* Open the dest FDT */
-	destfd = open(dtb_file, O_RDWR);
-	if (destfd == -1) {
-		fprintf(stderr, "%s: Can't open %s: %s\n",
-			__func__, dtb_file, strerror(errno));
-		ret = -1;
-		goto err;
-	}
-
-	ret = fstat(destfd, &dtb);
-	if (ret == -1) {
-		fprintf(stderr, "%s: Can't stat %s: %s\n",
-			__func__, dtb_file, strerror(errno));
-		goto err;
-	}
-
-	dtb.st_size += src_size + 0x30;
-	if (ftruncate(destfd, dtb.st_size)) {
-		fprintf(stderr, "%s: Can't expand %s: %s\n",
-			__func__, dtb_file, strerror(errno));
-		ret = -1;
-		goto err;
-	}
-
-	errno = 0;
-	/* mmap the dtb file */
-	dptr = mmap(0, dtb.st_size, PROT_READ | PROT_WRITE, MAP_SHARED,
-		    destfd, 0);
-	if (dptr == MAP_FAILED) {
-		fprintf(stderr, "%s: Failed to mmap %s:%s\n",
-			__func__, dtb_file, strerror(errno));
-		ret = -1;
-		goto err;
-	}
-
-	if (fdt_check_header(dptr)) {
-		fprintf(stderr, "%s: Invalid FDT header\n", __func__);
-		ret = -1;
-		goto err;
-	}
-
-	ret = fdt_open_into(dptr, dptr, dtb.st_size);
-	if (ret) {
-		fprintf(stderr, "%s: Cannot expand FDT: %s\n",
-			__func__, fdt_strerror(ret));
-		ret = -1;
-		goto err;
-	}
-
-	/* Copy the esl file to the expanded FDT */
-	ret = fdt_add_pub_key_data(sptr, dptr, src_size, overlay);
-	if (ret < 0) {
-		fprintf(stderr, "%s: Unable to add public key to the FDT\n",
-			__func__);
-		ret = -1;
-		goto err;
-	}
-
-	ret = 0;
-
-err:
-	if (sptr)
-		munmap(sptr, src_size);
-
-	if (dptr)
-		munmap(dptr, dtb.st_size);
-
-	if (srcfd != -1)
-		close(srcfd);
-
-	if (destfd != -1)
-		close(destfd);
-
-	return ret;
-}
-
 static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
 			unsigned long index, unsigned long instance)
 {
@@ -366,22 +178,16 @@  err_1:
 int main(int argc, char **argv)
 {
 	char *file;
-	char *pkey_file;
-	char *dtb_file;
 	efi_guid_t *guid;
 	unsigned long index, instance;
 	int c, idx;
-	int ret;
-	bool overlay = false;
 
 	file = NULL;
-	pkey_file = NULL;
-	dtb_file = NULL;
 	guid = NULL;
 	index = 0;
 	instance = 0;
 	for (;;) {
-		c = getopt_long(argc, argv, "f:r:i:I:v:D:K:Oh", options, &idx);
+		c = getopt_long(argc, argv, "f:r:i:I:v:h", options, &idx);
 		if (c == -1)
 			break;
 
@@ -408,43 +214,22 @@  int main(int argc, char **argv)
 		case 'I':
 			instance = strtoul(optarg, NULL, 0);
 			break;
-		case 'K':
-			if (pkey_file) {
-				printf("Public Key already specified\n");
-				return -1;
-			}
-			pkey_file = optarg;
-			break;
-		case 'D':
-			if (dtb_file) {
-				printf("DTB file already specified\n");
-				return -1;
-			}
-			dtb_file = optarg;
-			break;
-		case 'O':
-			overlay = true;
-			break;
 		case 'h':
 			print_usage();
 			return 0;
 		}
 	}
 
-	/* need a fit image file or raw image file */
-	if (!file && !pkey_file && !dtb_file) {
+	/* need an output file */
+	if (argc != optind + 1) {
 		print_usage();
 		exit(EXIT_FAILURE);
 	}
 
-	if (pkey_file && dtb_file) {
-		ret = add_public_key(pkey_file, dtb_file, overlay);
-		if (ret == -1) {
-			printf("Adding public key to the dtb failed\n");
-			exit(EXIT_FAILURE);
-		} else {
-			exit(EXIT_SUCCESS);
-		}
+	/* need a fit image file or raw image file */
+	if (!file) {
+		print_usage();
+		exit(EXIT_SUCCESS);
 	}
 
 	if (create_fwbin(argv[optind], file, guid, index, instance)