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 ${srctree}/bl31_0x*.bin 12${srctree}/arch/arm/mach-rockchip/decode_bl31.py 13 14if [ "${COMPRESSION}" == "gzip" ]; then 15 SUFFIX=".gz" 16else 17 COMPRESSION="none" 18 SUFFIX= 19fi 20 21if grep -q '^CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT=y' .config ; then 22 ALGO_PADDING=" padding = \"pss\";" 23fi 24 25function generate_uboot_node() 26{ 27 echo " uboot { 28 description = \"U-Boot(64-bit)\"; 29 data = /incbin/(\"./u-boot-nodtb.bin${SUFFIX}\"); 30 type = \"standalone\"; 31 arch = \"arm64\"; 32 os = \"U-Boot\"; 33 compression = \"${COMPRESSION}\"; 34 load = <"${UBOOT_LOAD_ADDR}">; 35 hash { 36 algo = \"sha256\"; 37 };" 38 if [ "${COMPRESSION}" == "gzip" ]; then 39 echo " digest { 40 value = /incbin/(\"./u-boot-nodtb.bin.digest\"); 41 algo = \"sha256\"; 42 };" 43 openssl dgst -sha256 -binary -out u-boot-nodtb.bin.digest u-boot-nodtb.bin 44 UBOOT_SZ=`ls -l u-boot-nodtb.bin | awk '{ print $5 }'` 45 if [ ${UBOOT_SZ} -gt 0 ]; then 46 gzip -k -f -9 ${srctree}/u-boot-nodtb.bin 47 else 48 touch ${srctree}/u-boot-nodtb.bin.gz 49 fi 50 fi 51 echo " };" 52} 53 54function generate_kfdt_node() 55{ 56 KERN_DTB=`sed -n "/CONFIG_EMBED_KERNEL_DTB_PATH=/s/CONFIG_EMBED_KERNEL_DTB_PATH=//p" .config | tr -d '"'` 57 if [ -z "${KERN_DTB}" ]; then 58 return; 59 fi 60 61 if [ -f ${srctree}/${KERN_DTB} ]; then 62 PROP_KERN_DTB=', "kern-fdt"'; 63 echo " kern-fdt { 64 description = \"${KERN_DTB}\"; 65 data = /incbin/(\"${KERN_DTB}\"); 66 type = \"flat_dt\"; 67 arch = \"${ARCH}\"; 68 compression = \"none\"; 69 hash { 70 algo = \"sha256\"; 71 }; 72 };" 73 fi 74} 75 76function generate_bl31_node() 77{ 78 NUM=1 79 for NAME in `ls -l bl31_0x*.bin | sort --key=5 -nr | awk '{ print $9 }'` 80 do 81 ATF_LOAD_ADDR=`echo ${NAME} | awk -F "_" '{ printf $2 }' | awk -F "." '{ printf $1 }'` 82 # only atf-1 support compress 83 if [ "${COMPRESSION}" == "gzip" -a ${NUM} -eq 1 ]; then 84 openssl dgst -sha256 -binary -out ${NAME}.digest ${NAME} 85 gzip -k -f -9 ${NAME} 86 87 echo " atf-${NUM} { 88 description = \"ARM Trusted Firmware\"; 89 data = /incbin/(\"./${NAME}${SUFFIX}\"); 90 type = \"firmware\"; 91 arch = \"arm64\"; 92 os = \"arm-trusted-firmware\"; 93 compression = \"${COMPRESSION}\"; 94 load = <"${ATF_LOAD_ADDR}">; 95 hash { 96 algo = \"sha256\"; 97 }; 98 digest { 99 value = /incbin/(\"./${NAME}.digest\"); 100 algo = \"sha256\"; 101 }; 102 };" 103 else 104 echo " atf-${NUM} { 105 description = \"ARM Trusted Firmware\"; 106 data = /incbin/(\"./${NAME}\"); 107 type = \"firmware\"; 108 arch = \"arm64\"; 109 os = \"arm-trusted-firmware\"; 110 compression = \"none\"; 111 load = <"${ATF_LOAD_ADDR}">; 112 hash { 113 algo = \"sha256\"; 114 }; 115 };" 116 fi 117 118 if [ ${NUM} -gt 1 ]; then 119 LOADABLE_ATF=${LOADABLE_ATF}", \"atf-${NUM}\"" 120 fi 121 NUM=`expr ${NUM} + 1` 122 done 123} 124 125function generate_bl32_node() 126{ 127 if [ -z ${TEE_LOAD_ADDR} ]; then 128 return 129 fi 130 131 echo " optee { 132 description = \"OP-TEE\"; 133 data = /incbin/(\"./tee.bin${SUFFIX}\"); 134 type = \"firmware\"; 135 arch = \"arm64\"; 136 os = \"op-tee\"; 137 compression = \"${COMPRESSION}\"; 138 load = <"0x${TEE_LOAD_ADDR}">; 139 hash { 140 algo = \"sha256\"; 141 };" 142 if [ "${COMPRESSION}" == "gzip" ]; then 143 echo " digest { 144 value = /incbin/(\"./tee.bin.digest\"); 145 algo = \"sha256\"; 146 };" 147 openssl dgst -sha256 -binary -out tee.bin.digest tee.bin 148 gzip -k -f -9 tee.bin 149 fi 150 151 LOADABLE_OPTEE=", \"optee\"" 152 echo " };" 153} 154 155function generate_mcu_node() 156{ 157 if [ -z ${MCU_LOAD_ADDR} ]; then 158 return 159 fi 160 161 echo " mcu { 162 description = \"mcu\"; 163 type = \"standalone\"; 164 arch = \"riscv\"; 165 data = /incbin/(\"./mcu.bin${SUFFIX}\"); 166 compression = \"${COMPRESSION}\"; 167 load = <0x"${MCU_LOAD_ADDR}">; 168 hash { 169 algo = \"sha256\"; 170 };" 171 if [ "${COMPRESSION}" == "gzip" ]; then 172 echo " digest { 173 value = /incbin/(\"./mcu.bin.digest\"); 174 algo = \"sha256\"; 175 };" 176 openssl dgst -sha256 -binary -out mcu.bin.digest mcu.bin 177 gzip -k -f -9 mcu.bin 178 fi 179 180 STANDALONE_SIGN=", \"standalone\"" 181 STANDALONE_MCU="standalone = \"mcu\";" 182 echo " };" 183} 184######################################################################################################## 185THIS_PLAT=`sed -n "/CONFIG_DEFAULT_DEVICE_TREE/p" .config | awk -F "=" '{ print $2 }' | tr -d '"'` 186 187cat << EOF 188/* 189 * Copyright (C) 2020 Rockchip Electronic Co.,Ltd 190 * 191 * Simple U-boot fit source file containing ATF/OP-TEE/U-Boot/dtb 192 */ 193 194/dts-v1/; 195 196/ { 197 description = "FIT Image with ATF/OP-TEE/U-Boot"; 198 #address-cells = <1>; 199 200 images { 201EOF 202 203 # generate nodes dynamically 204 generate_uboot_node 205 generate_bl31_node 206 generate_bl32_node 207 generate_mcu_node 208 generate_kfdt_node 209 210cat << EOF 211 fdt { 212 description = "U-Boot dtb"; 213 data = /incbin/("./u-boot.dtb"); 214 type = "flat_dt"; 215 arch = "${ARCH}"; 216 compression = "none"; 217 hash { 218 algo = "sha256"; 219 }; 220 }; 221 }; 222 223 configurations { 224 default = "conf"; 225 conf { 226 description = "${THIS_PLAT}"; 227 rollback-index = <0x0>; 228 firmware = "atf-1"; 229 loadables = "uboot"${LOADABLE_ATF}${LOADABLE_OPTEE}; 230 ${STANDALONE_MCU} 231 fdt = "fdt"${PROP_KERN_DTB}; 232 signature { 233 algo = "sha256,rsa2048"; 234 ${ALGO_PADDING} 235 key-name-hint = "dev"; 236 sign-images = "fdt", "firmware", "loadables"${STANDALONE_SIGN}; 237 }; 238 }; 239 }; 240}; 241EOF 242