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