blob: 6b426c854c20b8ea817873352e7e017935913e9a [file] [log] [blame]
Jan Kiszka15bb43b2023-02-28 19:19:17 +01001#!/bin/sh
2
3if [ -z "$1" ]; then
4 echo "Usage: $0 KEY"
5 exit 1
6fi
7
8TEMP_X509=$(mktemp XXXXXXXX.temp)
9
10REVISION=${2:-0}
11SHA_VAL=$(openssl dgst -sha512 -hex tispl.bin | sed -e "s/^.*= //g")
12BIN_SIZE=$(stat -c %s tispl.bin)
13
14cat <<EOF >$TEMP_X509
15[ req ]
16distinguished_name = req_distinguished_name
17x509_extensions = v3_ca
18prompt = no
19dirstring_type = nobmp
20
21[ req_distinguished_name ]
22CN = IOT2050 Firmware Signature
23
24[ v3_ca ]
25basicConstraints = CA:true
261.3.6.1.4.1.294.1.3 = ASN1:SEQUENCE:swrv
271.3.6.1.4.1.294.1.34 = ASN1:SEQUENCE:sysfw_image_integrity
28
29[ swrv ]
30swrv = INTEGER:$REVISION
31
32[ sysfw_image_integrity ]
33shaType = OID:2.16.840.1.101.3.4.2.3
34shaValue = FORMAT:HEX,OCT:$SHA_VAL
35imageSize = INTEGER:$BIN_SIZE
36EOF
37
38CERT_X509=$(mktemp XXXXXXXX.crt)
39
40openssl req -new -x509 -key $1 -nodes -outform DER -out $CERT_X509 -config $TEMP_X509 -sha512
41cat $CERT_X509 tispl.bin > tispl.bin_signed
Jan Kiszkab2d24f92023-07-27 06:34:54 +020042source/tools/binman/binman replace -i flash-pg1.bin -f tispl.bin_signed fit@180000
43source/tools/binman/binman replace -i flash-pg2.bin -f tispl.bin_signed fit@180000
Jan Kiszka15bb43b2023-02-28 19:19:17 +010044
45rm $TEMP_X509 $CERT_X509
46
Jan Kiszkab2d24f92023-07-27 06:34:54 +020047source/tools/binman/binman sign -i flash-pg1.bin -k $1 -a sha256,rsa4096 fit@380000
48source/tools/binman/binman sign -i flash-pg2.bin -k $1 -a sha256,rsa4096 fit@380000