public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Chia-Wei Wang <chiawei_wang@aspeedtech.com>
To: <trini@konsulko.com>, <sjg@chromium.org>, <bob.wolff68@gmail.com>,
	<u-boot@lists.denx.de>
Subject: [PATCH v2 2/4] lib: ecdsa: Create device tree node automatically
Date: Fri, 27 Sep 2024 11:07:24 +0800	[thread overview]
Message-ID: <20240927030726.2211297-3-chiawei_wang@aspeedtech.com> (raw)
In-Reply-To: <20240927030726.2211297-1-chiawei_wang@aspeedtech.com>

Both the signature and the public key are stored as DTS nodes
in the FIT image and SPL/U-Boot DTBs.

Like the RSA signing & verification do, this patch either creates
the nodes or overwirte the content automatically.

Signed-off-by: Chia-Wei Wang <chiawei_wang@aspeedtech.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 lib/ecdsa/ecdsa-libcrypto.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/lib/ecdsa/ecdsa-libcrypto.c b/lib/ecdsa/ecdsa-libcrypto.c
index 5fa9be10b4b..774cc946c7b 100644
--- a/lib/ecdsa/ecdsa-libcrypto.c
+++ b/lib/ecdsa/ecdsa-libcrypto.c
@@ -281,15 +281,26 @@ static int do_add(struct signer *ctx, void *fdt, const char *key_node_name)
 	BIGNUM *x, *y;
 
 	signature_node = fdt_subnode_offset(fdt, 0, FIT_SIG_NODENAME);
-	if (signature_node < 0) {
-		fprintf(stderr, "Could not find 'signature node: %s\n",
-			fdt_strerror(signature_node));
-		return signature_node;
+	if (signature_node == -FDT_ERR_NOTFOUND) {
+		signature_node = fdt_add_subnode(fdt, 0, FIT_SIG_NODENAME);
+		if (signature_node < 0) {
+			fprintf(stderr, "Could not add 'signature' node: %s\n",
+				fdt_strerror(signature_node));
+			return signature_node;
+		}
 	}
 
-	key_node = fdt_add_subnode(fdt, signature_node, key_node_name);
-	if (key_node < 0) {
-		fprintf(stderr, "Could not create '%s' node: %s\n",
+	/* Either create or overwrite the named key node */
+	key_node = fdt_subnode_offset(fdt, signature_node, key_node_name);
+	if (key_node == -FDT_ERR_NOTFOUND) {
+		key_node = fdt_add_subnode(fdt, signature_node, key_node_name);
+		if (key_node < 0) {
+			fprintf(stderr, "Could not create '%s' node: %s\n",
+				key_node_name, fdt_strerror(key_node));
+			return key_node;
+		}
+	} else if (key_node < 0) {
+		fprintf(stderr, "cannot select '%s' node: %s\n",
 			key_node_name, fdt_strerror(key_node));
 		return key_node;
 	}
-- 
2.25.1


  parent reply	other threads:[~2024-09-27  3:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-27  3:07 [PATCH v2 0/4] aspeed: ast2700: Add Caliptra ECDSA driver Chia-Wei Wang
2024-09-27  3:07 ` [PATCH v2 1/4] lib: ecdsa: Add ECDSA384 support Chia-Wei Wang
2024-09-27  3:07 ` Chia-Wei Wang [this message]
2024-09-27  3:07 ` [PATCH v2 3/4] image-fit-sig: Remove padding check Chia-Wei Wang
2024-09-27  3:07 ` [PATCH v2 4/4] drivers/crypto: aspeed: Add Caliptra ECDSA384 support Chia-Wei Wang
2024-10-11 17:34 ` [PATCH v2 0/4] aspeed: ast2700: Add Caliptra ECDSA driver Tom Rini
2024-10-14  2:07   ` ChiaWei Wang

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=20240927030726.2211297-3-chiawei_wang@aspeedtech.com \
    --to=chiawei_wang@aspeedtech.com \
    --cc=bob.wolff68@gmail.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox