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