mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH v2 01/33] scripts/k3img: make more flexible
Date: Thu, 05 Jun 2025 14:42:26 +0200	[thread overview]
Message-ID: <20250605-arm-k3-am62l-v2-1-53257d4b2dd2@pengutronix.de> (raw)
In-Reply-To: <20250605-arm-k3-am62l-v2-0-53257d4b2dd2@pengutronix.de>

We had a template for the certificate in which each component has a
certain name and the file to use for each component was specified using
different options (--sysfw, --sysfwdata, --dmdata, --sbl and
--innerdata). All components have the same format and the name doesn't
matter. Instead of supporting different options just take a list of
components as input of the tool. Each component can be specified like:

filename:compType:bootCore:compOpts:destAddr

This not only makes the tool easier to follow, but also lets us specify
the compType, bootCore and compOpts options which need different values
for different SoCs.

While at it add support for the --help option.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 images/Makefile.k3 |  12 ++--
 scripts/k3img      | 182 ++++++++++++++++++++---------------------------------
 2 files changed, 77 insertions(+), 117 deletions(-)

diff --git a/images/Makefile.k3 b/images/Makefile.k3
index d9b0af8d67b49569283d35ce0ec1792897654c57..c03ce7acc3152bacfcd7c3c8bf953c2214aaa42a 100644
--- a/images/Makefile.k3
+++ b/images/Makefile.k3
@@ -63,12 +63,16 @@ endif
 quiet_cmd_k3_image = K3IMG   $@
       cmd_k3_image = \
 		if [ -n "$(INNERDATA_$(@F))" ]; then				\
-			inner="--innerdata $(INNERDATA_$(@F))";			\
+			inner="$(INNERDATA_$(@F)):3:0:0:00000000";		\
 		fi;								\
 										\
-		$(srctree)/scripts/k3img --sysfw $(SYSFW_$(@F))			\
-		--sysfwdata $(SYSFWDATA_$(@F)) --dmdata $(DMDATA_$(@F))		\
-		--key $(KEY_$(@F)) $$inner --sbl $< --out $@
+		$(srctree)/scripts/k3img					\
+			$<:1:16:0:43c00000					\
+			$(SYSFW_$(@F)):2:0:0:00040000				\
+			$(SYSFWDATA_$(@F)):18:0:0:00067000			\
+			$$inner							\
+			$(DMDATA_$(@F)):17:16:0:43c3a800			\
+			--key $(KEY_$(@F)) --out $@
 
 $(obj)/%.k3img: $(obj)/% scripts/k3img FORCE
 	$(call if_changed,k3_image)
diff --git a/scripts/k3img b/scripts/k3img
index a514852fcdf6369c33b1e291b59c121badc6f4bd..1f2a34e1c4842171488f2d02a4c5722e4e3f94c2 100755
--- a/scripts/k3img
+++ b/scripts/k3img
@@ -2,7 +2,9 @@
 
 set -e
 
-TEMP=$(getopt -o '' --long 'sysfw:,sysfwdata:,dmdata:,out:,sbl:,key:,innerdata:' -n 'k3img' -- "$@")
+bootcore_opts=0
+
+TEMP=$(getopt -o '' --long 'out:,key:,help' -n 'k3img' -- "$@")
 
 if [ $? -ne 0 ]; then
 	echo 'Terminating...' >&2
@@ -13,47 +15,38 @@ fi
 eval set -- "$TEMP"
 unset TEMP
 
+usage() {
+cat <<EndOfHereDocument
+Generate certificate images suitable for booting TI K3 SoCs.
+
+usage: $0 [OPTION]... [COMPONENT]...
+  --out <FILE>		write output image to <FILE>
+  --key <KEYFILE>	signing key
+  --help		this help
+
+Components have the form:
+
+filename:compType:bootCore:compOpts:destAddr
+
+For the meaning of compType, bootCore and compOpts see the Reference Manual
+EndOfHereDocument
+}
+
 while true; do
         case "$1" in
-        '--sysfw')
-		sysfw="$2"
-		shift 2
-		continue
-	;;
-        '--sysfwdata')
-		sysfwdata="$2"
-		shift 2
-		continue
-	;;
-        '--sysfw')
-		sysfw="$2"
-		shift 2
-		continue
-	;;
-        '--dmdata')
-		dmdata="$2"
-		shift 2
-		continue
-	;;
 	'--out')
 		out="$2"
 		shift 2
 		continue
 	;;
-	'--sbl')
-		sbl="$2"
-		shift 2
-		continue
-	;;
 	'--key')
 		key="$2"
 		shift 2
 		continue
 	;;
-	'--innerdata')
-		innerdata="$2"
-		shift 2
-		continue
+	'--help')
+		usage
+		exit 0
 	;;
 	'--')
 		shift
@@ -66,46 +59,57 @@ while true; do
 	esac
 done
 
-shasbl=$(sha512sum $sbl | sed 's/ .*//')
-shasysfw=$(sha512sum $sysfw | sed 's/ .*//')
-shasysfwdata=$(sha512sum $sysfwdata | sed 's/ .*//')
-shadmdata=$(sha512sum $dmdata | sed 's/ .*//')
+total=0
+num_comp=0
 
-sblsize=$(stat -c%s $sbl)
-sysfwsize=$(stat -c%s $sysfw)
-sysfwdatasize=$(stat -c%s $sysfwdata)
-dmdatasize=$(stat -c%s $dmdata)
-
-total=$(($sblsize + $sysfwsize + $sysfwdatasize + $dmdatasize))
-
-TMPDIR="$(mktemp -d)"
 trap 'rm -rf -- "$TMPDIR"' EXIT
+TMPDIR="$(mktemp -d)"
 
-certcfg=${TMPDIR}/certcfg
-cert=${TMPDIR}/cert
+components=${TMPDIR}/components
+ext_boot_info=${TMPDIR}/ext_boot_info
+data=${TMPDIR}/data
+
+for i in $*; do
+	filename=$(echo "$i" | cut -d ":" -f 1)
+	compType=$(echo "$i" | cut -d ":" -f 2)
+	bootCore=$(echo "$i" | cut -d ":" -f 3)
+	compOpts=$(echo "$i" | cut -d ":" -f 4)
+	destAddr=$(echo "$i" | cut -d ":" -f 5)
 
-num_comp=4
+	sha=$(sha512sum $filename | sed 's/ .*//')
+	size=$(stat -c%s $filename)
 
-if [ -n "${innerdata}" ]; then
-	shainnerdata=$(sha512sum $innerdata | sed 's/ .*//')
-	innerdatasize=$(stat -c%s $innerdata)
+	total=$((total + size))
+	num_comp=$((num_comp + 1))
 
-	innercert=$(cat <<EOF
-[sysfw_inner_cert]
-compType = INTEGER:3
-bootCore = INTEGER:0
-compOpts = INTEGER:0
-destAddr = FORMAT:HEX,OCT:00000000
-compSize = INTEGER:$innerdatasize
+	cat >> $components <<EndOfHereDocument
+[comp$num_comp]
+compType = INTEGER:$compType
+bootCore = INTEGER:$bootCore
+compOpts = INTEGER:$compOpts
+destAddr = FORMAT:HEX,OCT:$destAddr
+compSize = INTEGER:$size
 shaType  = OID:2.16.840.1.101.3.4.2.3
-shaValue = FORMAT:HEX,OCT:$shainnerdata
-EOF
-)
+shaValue = FORMAT:HEX,OCT:$sha
 
-	num_comp=$((num_comp + 1))
-	total=$((total + innerdatasize))
-	sysfw_inner_cert="sysfw_inner_cert=SEQUENCE:sysfw_inner_cert"
-fi
+EndOfHereDocument
+
+	echo "comp$num_comp = SEQUENCE:comp$num_comp" >> $ext_boot_info
+	cat $filename >> $data
+done
+
+echo >> $ext_boot_info
+
+cat >> $components <<EndOfHereDocument
+[ debug ]
+debugUID = FORMAT:HEX,OCT:0000000000000000000000000000000000000000000000000000000000000000
+debugType = INTEGER:4
+coreDbgEn = INTEGER:0
+coreDbgSecEn = INTEGER:0
+EndOfHereDocument
+
+certcfg=${TMPDIR}/certcfg
+cert=${TMPDIR}/cert
 
 cat > $certcfg <<EndOfHereDocument
 [ req ]
@@ -135,58 +139,10 @@ swrv=INTEGER:1
 [ext_boot_info]
 extImgSize=INTEGER:$total
 numComp=INTEGER:$num_comp
-sbl=SEQUENCE:sbl
-sysfw=SEQUENCE:sysfw
-sysfw_data=SEQUENCE:sysfw_data
-$sysfw_inner_cert
-dm_data=SEQUENCE:dm_data
-
-[sbl]
-compType = INTEGER:1
-bootCore = INTEGER:16
-compOpts = INTEGER:0
-destAddr = FORMAT:HEX,OCT:43c00000
-compSize = INTEGER:$sblsize
-shaType  = OID:2.16.840.1.101.3.4.2.3
-shaValue = FORMAT:HEX,OCT:$shasbl
-
-[sysfw]
-compType = INTEGER:2
-bootCore = INTEGER:0
-compOpts = INTEGER:0
-destAddr = FORMAT:HEX,OCT:00040000
-compSize = INTEGER:$sysfwsize
-shaType  = OID:2.16.840.1.101.3.4.2.3
-shaValue = FORMAT:HEX,OCT:$shasysfw
-
-[sysfw_data]
-compType = INTEGER:18
-bootCore = INTEGER:0
-compOpts = INTEGER:0
-destAddr = FORMAT:HEX,OCT:00067000
-compSize = INTEGER:$sysfwdatasize
-shaType  = OID:2.16.840.1.101.3.4.2.3
-shaValue = FORMAT:HEX,OCT:$shasysfwdata
-
-[ debug ]
-debugUID = FORMAT:HEX,OCT:0000000000000000000000000000000000000000000000000000000000000000
-debugType = INTEGER:4
-coreDbgEn = INTEGER:0
-coreDbgSecEn = INTEGER:0
-
-$innercert
-
-[dm_data]
-compType = INTEGER:17
-bootCore = INTEGER:16
-compOpts = INTEGER:0
-destAddr = FORMAT:HEX,OCT:43c3a800
-compSize = INTEGER:$dmdatasize
-shaType  = OID:2.16.840.1.101.3.4.2.3
-shaValue = FORMAT:HEX,OCT:$shadmdata
-
 EndOfHereDocument
 
+cat $ext_boot_info $components >> $certcfg
+
 openssl req -new -x509 -key $key -nodes -outform DER -out $cert -config $certcfg -sha512
 
-cat $cert $sbl $sysfw $sysfwdata $innerdata $dmdata > $out
+cat $cert $data > $out

-- 
2.39.5




  reply	other threads:[~2025-06-05 12:45 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-05 12:42 [PATCH v2 00/33] ARM: K3: add support for AM62L Sascha Hauer
2025-06-05 12:42 ` Sascha Hauer [this message]
2025-06-05 12:42 ` [PATCH v2 02/33] images: K3: rename %.k3img target to %.k3_am62x_img Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 03/33] ARM: K3: prepare support for other SoCs Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 04/33] ARM: dts: add k3-am62l dts(i) files Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 05/33] ARM: dts: am62l: Fix assigned-clock-parents Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 06/33] ARM: K3: add am62lx base support Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 07/33] ARM: Makefile: descend into mach-* for cleaning Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 08/33] ARM: k3: rename yaml files from am625 to am62x Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 09/33] firmware: add ti-linux-firmware submodule Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 10/33] scripts/ti-board-config.py: fix length Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 11/33] ARM: k3: add yaml files for AM62l Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 12/33] k3: ringacc: pass ringrt address in struct k3_ringacc_init_data Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 13/33] drivers: soc: ti: k3-ringacc: handle absence of tisci Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 14/33] drivers: soc: ti: k3-ringacc: fix k3_ringacc_ring_reset_sci Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 15/33] dma: ti: k3-psil: Add PSIL data for AM62L Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 16/33] dma: ti: k3-udma: Refactor common bits for AM62L support Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 17/33] dma: ti: k3-udma-common: Update common code for AM62L DMAs Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 18/33] dma: ti: k3-udma-am62l: Add AM62L support DMA drivers Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 19/33] ARM: dts: am62l: Add ethernet ports Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 20/33] ARM: dts: am62l evm: " Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 21/33] ARM: k3: am62l: add barebox specific am62l.dtsi Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 22/33] net: davinci_mdio: Use fallback clock rate Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 23/33] firmware: arm_scmi: Add support for clock parents Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 24/33] clk: add struct clk_parent_data Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 25/33] clk: arm_scmi: implement clock parent setting Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 26/33] ARM: dts: am62l3-evm: add MMC aliases Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 27/33] dma: ti: k3-udma: limit asel to am625 Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 28/33] gpio: increase ARCH_NR_GPIOS to 512 Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 29/33] ARM: dts: k3-am62l: reserve memory for TF-A and OP-TEE Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 30/33] ARM: k3: add AM62l3 EVM board support Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 31/33] ARM: K3: am62l: add serial aliases Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 32/33] Documentation: boards: k3: split generic and am62x specific documentation Sascha Hauer
2025-06-05 12:42 ` [PATCH v2 33/33] Documentation: boards: k3: add AM62lx documentation Sascha Hauer

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=20250605-arm-k3-am62l-v2-1-53257d4b2dd2@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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