All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 02/14] mkimage: Automatically expand FDT in more cases
Date: Thu, 12 Jun 2014 07:24:42 -0600	[thread overview]
Message-ID: <1402579494-29389-3-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1402579494-29389-1-git-send-email-sjg@chromium.org>

The original code did not cover every case and there was a missing negative
sign in one case. Expand the coverage and fix the bug.

Signed-off-by: Simon Glass <sjg@chromium.org>
mkimage: Automatically make space in FDT when full

When adding hashes or signatures, the target FDT may be full. Detect this
and automatically try again after making 1KB of space.

---

Changes in v2:
- Add update patch to correct and expand -ENOSPC error handling

 lib/rsa/rsa-sign.c | 27 ++++++++++++++++++---------
 tools/image-host.c |  4 +++-
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c
index 48f3197..83f5e87 100644
--- a/lib/rsa/rsa-sign.c
+++ b/lib/rsa/rsa-sign.c
@@ -405,11 +405,15 @@ int rsa_add_verify_data(struct image_sign_info *info, void *keydest)
 	if (parent == -FDT_ERR_NOTFOUND) {
 		parent = fdt_add_subnode(keydest, 0, FIT_SIG_NODENAME);
 		if (parent < 0) {
-			fprintf(stderr, "Couldn't create signature node: %s\n",
-				fdt_strerror(parent));
-			return -EINVAL;
+			ret = parent;
+			if (ret != -FDT_ERR_NOSPACE) {
+				fprintf(stderr, "Couldn't create signature node: %s\n",
+					fdt_strerror(parent));
+			}
 		}
 	}
+	if (ret)
+		goto done;
 
 	/* Either create or overwrite the named key node */
 	snprintf(name, sizeof(name), "key-%s", info->keyname);
@@ -417,18 +421,22 @@ int rsa_add_verify_data(struct image_sign_info *info, void *keydest)
 	if (node == -FDT_ERR_NOTFOUND) {
 		node = fdt_add_subnode(keydest, parent, name);
 		if (node < 0) {
-			fprintf(stderr, "Could not create key subnode: %s\n",
-				fdt_strerror(node));
-			return -EINVAL;
+			ret = node;
+			if (ret != -FDT_ERR_NOSPACE) {
+				fprintf(stderr, "Could not create key subnode: %s\n",
+					fdt_strerror(node));
+			}
 		}
 	} else if (node < 0) {
 		fprintf(stderr, "Cannot select keys parent: %s\n",
 			fdt_strerror(node));
-		return -ENOSPC;
+		ret = node;
 	}
 
-	ret = fdt_setprop_string(keydest, node, "key-name-hint",
+	if (!ret) {
+		ret = fdt_setprop_string(keydest, node, "key-name-hint",
 				 info->keyname);
+	}
 	if (!ret)
 		ret = fdt_setprop_u32(keydest, node, "rsa,num-bits", bits);
 	if (!ret)
@@ -449,10 +457,11 @@ int rsa_add_verify_data(struct image_sign_info *info, void *keydest)
 		ret = fdt_setprop_string(keydest, node, "required",
 					 info->require_keys);
 	}
+done:
 	BN_free(modulus);
 	BN_free(r_squared);
 	if (ret)
-		return ret == FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
+		return ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
 
 	return 0;
 }
diff --git a/tools/image-host.c b/tools/image-host.c
index 2be5e80..faeef66 100644
--- a/tools/image-host.c
+++ b/tools/image-host.c
@@ -609,11 +609,13 @@ static int fit_config_process_sig(const char *keydir, void *keydest,
 	/* Write the public key into the supplied FDT file */
 	if (keydest) {
 		ret = info.algo->add_verify_data(&info, keydest);
+		if (ret == -ENOSPC)
+			return -ENOSPC;
 		if (ret) {
 			printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
 			       node_name, conf_name);
-			return ret == FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
 		}
+		return ret;
 	}
 
 	return 0;
-- 
2.0.0.526.g5318336

  parent reply	other threads:[~2014-06-12 13:24 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-12 13:24 [U-Boot] [PATCH v2 0/14] Enhance fit_check_sign add beaglebone black vboot docs Simon Glass
2014-06-12 13:24 ` [U-Boot] [PATCH v2 01/14] hash: Use uint8_t in preference to u8 Simon Glass
2014-06-19 15:21   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-12 13:24 ` Simon Glass [this message]
2014-06-19 15:21   ` [U-Boot] [U-Boot, v2, 02/14] mkimage: Automatically expand FDT in more cases Tom Rini
2014-06-12 13:24 ` [U-Boot] [PATCH v2 03/14] fdt: Rename the DEV_TREE_BIN Makefile flag to to EXT_DTB Simon Glass
2014-06-19 15:21   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-12 13:24 ` [U-Boot] [PATCH v2 04/14] tools: Check arguments in fit_check_sign/fit_info Simon Glass
2014-06-19 15:21   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-12 13:24 ` [U-Boot] [PATCH v2 05/14] Reverse the meaning of the fit_config_verify() return code Simon Glass
2014-06-19 15:21   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-12 13:24 ` [U-Boot] [PATCH v2 06/14] bootm: Split out code from cmd_bootm.c Simon Glass
2014-06-19 15:23   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-19 15:31     ` Tom Rini
2014-06-19 23:27       ` Simon Glass
2014-06-20 14:57         ` Tom Rini
2014-06-19 15:24   ` [U-Boot] [PATCH v2 " Tom Rini
2014-06-12 13:24 ` [U-Boot] [PATCH v2 07/14] image: Remove the fit_load_image() property parameter Simon Glass
2014-06-19 15:21   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-12 13:24 ` [U-Boot] [PATCH v2 08/14] bootm: Support android boot on sandbox Simon Glass
2014-06-19 15:21   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-12 13:24 ` [U-Boot] [PATCH v2 09/14] Fix small 'case' typo in image-fit.c Simon Glass
2014-06-19 15:21   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-12 13:24 ` [U-Boot] [PATCH v2 10/14] Avoid including config.h in command.h Simon Glass
2014-06-19 15:22   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-12 13:24 ` [U-Boot] [PATCH v2 11/14] Allow compiling common/bootm.c on with HOSTCC Simon Glass
2014-06-19 15:22   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-12 13:24 ` [U-Boot] [PATCH v2 12/14] bootm: Move decompression code into its own function Simon Glass
2014-06-19 15:22   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-12 13:24 ` [U-Boot] [PATCH v2 13/14] Enhance fit_check_sign to check all images Simon Glass
2014-06-19 15:23   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-12 13:24 ` [U-Boot] [PATCH v2 14/14] Add documentation for verified boot on Beaglebone Black Simon Glass
2014-06-19 15:22   ` [U-Boot] [U-Boot, v2, " Tom Rini
2014-06-19 12:48 ` [U-Boot] [PATCH] am335x_evm: Only enable OF_CONTROL/OF_SEPARATE on VBOOT for now Tom Rini
2014-06-19 15:23   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1402579494-29389-3-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.