xref: /rk3399_rockchip-uboot/arch/arm/mach-rockchip/make_fit_optee.sh (revision e091b6c996a68a6a0faa2bd3ffdd90b3ba5f44ce)
1#!/bin/bash
2#
3# Copyright (C) 2020 Rockchip Electronics Co., Ltd
4#
5# SPDX-License-Identifier:     GPL-2.0+
6#
7
8# Process args and auto set variables
9source ./${srctree}/arch/arm/mach-rockchip/make_fit_args.sh
10
11rm -f ${srctree}/*.digest ${srctree}/*.bin.gz
12
13if [ "${COMPRESSION}" == "gzip" ]; then
14	SUFFIX=".gz"
15else
16	COMPRESSION="none"
17	SUFFIX=
18fi
19
20# digest
21if [ "${COMPRESSION}" == "gzip" ]; then
22	openssl dgst -sha256 -binary -out ${srctree}/u-boot-nodtb.digest ${srctree}/u-boot-nodtb.bin
23	openssl dgst -sha256 -binary -out ${srctree}/tee.digest ${srctree}/tee.bin
24	gzip -k -f -9 ${srctree}/tee.bin
25	UBOOT_SZ=`ls -l u-boot-nodtb.bin | awk '{ print $5 }'`
26	if [ ${UBOOT_SZ} -gt 0 ]; then
27		gzip -k -f -9 ${srctree}/u-boot-nodtb.bin
28	else
29		touch ${srctree}/u-boot-nodtb.bin.gz
30	fi
31	if [ ! -z "${MCU_LOAD_ADDR}" ]; then
32		openssl dgst -sha256 -binary -out ${srctree}/mcu.digest ${srctree}/mcu.bin
33		gzip -k -f -9 ${srctree}/mcu.bin
34	fi
35
36	UBOOT_DIGEST="			digest {
37				value = /incbin/(\"./u-boot-nodtb.digest\");
38				algo = \"sha256\";
39			};"
40	TEE_DIGEST="			digest {
41				value = /incbin/(\"./tee.digest\");
42				algo = \"sha256\";
43			};"
44	MCU_DIGEST="			digest {
45				value = /incbin/(\"./mcu.digest\");
46				algo = \"sha256\";
47			};"
48fi
49
50# mcu
51if [ ! -z "${MCU_LOAD_ADDR}" ]; then
52	MCU_NODE="		mcu {
53			description = \"mcu\";
54			type = \"standalone\";
55			arch = \"riscv\";
56			data = /incbin/(\"./mcu.bin${SUFFIX}\");
57			compression = \"${COMPRESSION}\";
58			load = <0x"${MCU_LOAD_ADDR}">;
59			hash {
60				algo = \"sha256\";
61			};
62${MCU_DIGEST}
63		};"
64	MCU_STANDALONE="			standalone = \"mcu\";"
65	SIGN_IMAGES="			        sign-images = \"fdt\", \"firmware\", \"loadables\", \"standalone\";"
66else
67	SIGN_IMAGES="			        sign-images = \"fdt\", \"firmware\", \"loadables\";"
68fi
69
70KERN_DTB=`sed -n "/CONFIG_EMBED_KERNEL_DTB_PATH=/s/CONFIG_EMBED_KERNEL_DTB_PATH=//p" .config | tr -d '"'`
71if [ -z "${KERN_DTB}" ]; then
72	return;
73fi
74if [ -f ${srctree}/${KERN_DTB} ]; then
75	PROP_KERN_DTB=', "kern-fdt"';
76	KFDT_NODE="		kern-fdt {
77			description = \"${KERN_DTB}\";
78			data = /incbin/(\"${KERN_DTB}\");
79			type = \"flat_dt\";
80			arch = \"${ARCH}\";
81			compression = \"none\";
82			hash {
83				algo = \"sha256\";
84			};
85		};"
86fi
87########################################################################################################
88THIS_PLAT=`sed -n "/CONFIG_DEFAULT_DEVICE_TREE/p" .config | awk -F "=" '{ print $2 }' | tr -d '"'`
89
90cat << EOF
91/*
92 * Copyright (C) 2020 Rockchip Electronic Co.,Ltd
93 *
94 * Simple U-boot fit source file containing U-Boot, dtb and optee
95 */
96
97/dts-v1/;
98
99/ {
100	description = "FIT Image with U-Boot/OP-TEE/MCU";
101	#address-cells = <1>;
102
103	images {
104		uboot {
105			description = "U-Boot (32-bit)";
106			data = /incbin/("./u-boot-nodtb.bin${SUFFIX}");
107			type = "standalone";
108			arch = "arm";
109			os = "U-Boot";
110			compression = "${COMPRESSION}";
111			load = <${UBOOT_LOAD_ADDR}>;
112			hash {
113				algo = "sha256";
114			};
115EOF
116echo "${UBOOT_DIGEST}"
117cat << EOF
118		};
119		optee {
120			description = "OP-TEE";
121			data = /incbin/("./tee.bin${SUFFIX}");
122			type = "firmware";
123			arch = "arm";
124			os = "op-tee";
125			compression = "${COMPRESSION}";
126			load = <0x${TEE_LOAD_ADDR}>;
127			entry = <0x${TEE_LOAD_ADDR}>;
128			hash {
129				algo = "sha256";
130			};
131EOF
132echo "${TEE_DIGEST}"
133cat << EOF
134		};
135		fdt {
136			description = "U-Boot dtb";
137			data = /incbin/("./u-boot.dtb");
138			type = "flat_dt";
139			arch = "${ARCH}";
140			compression = "none";
141			hash {
142				algo = "sha256";
143			};
144		};
145EOF
146echo "${KFDT_NODE}"
147echo "${MCU_NODE}"
148cat  << EOF
149	};
150
151	configurations {
152		default = "conf";
153		conf {
154			description = "${THIS_PLAT}";
155			rollback-index = <0x0>;
156			firmware = "optee";
157			loadables = "uboot";
158			fdt = "fdt"${PROP_KERN_DTB};
159EOF
160echo "${MCU_STANDALONE}"
161cat  << EOF
162			signature {
163				algo = "sha256,rsa2048";
164				padding = "pss";
165				key-name-hint = "dev";
166EOF
167echo "${SIGN_IMAGES}"
168cat  << EOF
169			};
170		};
171	};
172};
173EOF
174