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