xref: /rk3399_rockchip-uboot/arch/arm/mach-rockchip/make_fit_optee.sh (revision 2a7051be6cb4eddfbb7c8a7288750ec77adc42f3)
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
70if [ -f ${srctree}/dts/kern.dtb ]; then
71	KFDT_NODE="		kernel-fdt {
72			description = \"Kernel dtb\";
73			data = /incbin/(\"./dts/kern.dtb\");
74			type = \"flat_dt\";
75			arch = \"${ARCH}\";
76			compression = \"none\";
77			hash {
78				algo = \"sha256\";
79			};
80		};"
81fi
82########################################################################################################
83THIS_PLAT=`sed -n "/CONFIG_DEFAULT_DEVICE_TREE/p" .config | awk -F "=" '{ print $2 }' | tr -d '"'`
84
85cat << EOF
86/*
87 * Copyright (C) 2020 Rockchip Electronic Co.,Ltd
88 *
89 * Simple U-boot fit source file containing U-Boot, dtb and optee
90 */
91
92/dts-v1/;
93
94/ {
95	description = "FIT Image with U-Boot/OP-TEE/MCU";
96	#address-cells = <1>;
97
98	images {
99		uboot {
100			description = "U-Boot (32-bit)";
101			data = /incbin/("./u-boot-nodtb.bin${SUFFIX}");
102			type = "standalone";
103			arch = "arm";
104			os = "U-Boot";
105			compression = "${COMPRESSION}";
106			load = <${UBOOT_LOAD_ADDR}>;
107			hash {
108				algo = "sha256";
109			};
110EOF
111echo "${UBOOT_DIGEST}"
112cat << EOF
113		};
114		optee {
115			description = "OP-TEE";
116			data = /incbin/("./tee.bin${SUFFIX}");
117			type = "firmware";
118			arch = "arm";
119			os = "op-tee";
120			compression = "${COMPRESSION}";
121			load = <0x${TEE_LOAD_ADDR}>;
122			entry = <0x${TEE_LOAD_ADDR}>;
123			hash {
124				algo = "sha256";
125			};
126EOF
127echo "${TEE_DIGEST}"
128cat << EOF
129		};
130		fdt {
131			description = "U-Boot dtb";
132			data = /incbin/("./u-boot.dtb");
133			type = "flat_dt";
134			arch = "${ARCH}";
135			compression = "none";
136			hash {
137				algo = "sha256";
138			};
139		};
140EOF
141echo "${KFDT_NODE}"
142echo "${MCU_NODE}"
143cat  << EOF
144	};
145
146	configurations {
147		default = "conf";
148		conf {
149			description = "${THIS_PLAT}";
150			rollback-index = <0x0>;
151			firmware = "optee";
152			loadables = "uboot";
153			fdt = "fdt";
154EOF
155echo "${MCU_STANDALONE}"
156cat  << EOF
157			signature {
158				algo = "sha256,rsa2048";
159				padding = "pss";
160				key-name-hint = "dev";
161EOF
162echo "${SIGN_IMAGES}"
163cat  << EOF
164			};
165		};
166	};
167};
168EOF
169