1#!/usr/bin/env bash - 2#****************************************************************************** 3# * @attention 4# * 5# * <h2><center>© Copyright (c) 2019 STMicroelectronics. 6# * All rights reserved.</center></h2> 7# * 8# * This software component is licensed by ST under BSD 3-Clause license, 9# * the "License"; You may not use this file except in compliance with the 10# * License. You may obtain a copy of the License at: 11# * opensource.org/licenses/BSD-3-Clause 12# * 13# ****************************************************************************** 14 15echo "TFM BIN2HEX started" 16disk=d 17if [ $# -eq 1 ]; then 18disk="$1" 19fi 20disk_option="/"$disk 21 22# Absolute path to this script 23SCRIPT=$(readlink -f $0) 24# Absolute path this script 25SCRIPTPATH=`dirname $SCRIPT` 26BINPATH="$SCRIPTPATH/bin" 27 28 29echo "Write TFM_Appli Secure" 30# part ot be updated according to flash_layout.h 31slot0= 32slot1= 33boot= 34unused= 35#since drag an drop is not supporting flash secure alias, address is conververted to non secure flash alias 36let image_s=$slot0-0x4000000 37image_s=`printf 0x%x $image_s` 38let image_ns=$slot1-0x4000000 39image_ns=`printf 0x%x $image_ns` 40let bl2=$boot-0x4000000 41bl2=`printf 0x%x $bl2` 42printf "disk "$disk_option", hex addresses: "$bl2", "$image_s", "$image_ns 43python scripts/bin2hex.py --offset=$image_s $BINPATH/tfm_s_signed.bin $BINPATH/tfm_s_signed.hex 44python scripts/bin2hex.py --offset=$image_ns $BINPATH/tfm_ns_signed.bin $BINPATH/tfm_ns_signed.hex 45python scripts/bin2hex.py --offset=$bl2 $BINPATH/bl2.bin $BINPATH/bl2.hex 46if [ ! -f $disk_option/DETAILS.TXT ]; then 47 echo "disk not present" 48 exit 1 49fi 50# cleaning 1st bank is ok for now. 51echo "Cleaning 1st bank" 52#create a file with 0 to clean up internal 1st bank : NVM, ITS and PS area 53# must be clean 54dd if=/dev/zero of=$BINPATH/clean.bin bs=1K count=256 55python scripts/bin2hex.py --offset=0x8000000 $BINPATH/clean.bin $BINPATH/clean.hex 56cp $BINPATH/clean.hex $disk_option 57while [ -f $disk_option/clean.hex ]; 58do 59 sleep 0.1 60done 61sleep 5 62while [ ! -f $disk_option/DETAILS.TXT ] 63do 64 sleep 0.1 65done 66if [ -f $disk_option/failed.txt ]; then 67 echo " tfm_s_signed.hex not written" 68 cat $disk-option/failed.txt 69 exit 1 70fi 71#write secure image 72echo "Write Secure Image" 73cp $BINPATH/tfm_s_signed.hex $disk_option 74while [ -f $disk_option/tfm_s_signed.hex ]; 75do 76 sleep 0.1 77done 78sleep 5 79while [ ! -f $disk_option/DETAILS.TXT ] 80do 81 sleep 0.1 82done 83if [ -f $disk_option/failed.txt ]; then 84 echo " tfm_s_signed.hex not written" 85 cat $disk-option/failed.txt 86 exit 1 87fi 88#write non secure image 89echo "Write non secure image" 90cp $BINPATH/tfm_ns_signed.hex $disk_option 91while [ -f $disk_option/tfm_ns_signed.hex ]; 92do 93 sleep 0.1 94done 95sleep 5 96while [ ! -f $disk_option/DETAILS.TXT ] 97do 98 sleep 0.1 99done 100if [ -f $disk_option/failed.txt ]; then 101 echo "tfm_ns_signed.hex not written" 102 cat $disk_option/failed.txt 103 exit 1 104fi 105#write bl2 image 106echo "Write bl2 Image" 107cp $BINPATH/bl2.hex $disk_option 108while [ -f $disk_option/tfm_ns_signed.hex ]; 109do 110 sleep 0.1 111done 112sleep 5 113while [ ! -f $disk_option/DETAILS.TXT ] 114do 115 sleep 0.1 116done 117if [ -f $disk_option/failed.txt ]; then 118 echo "bl2.hex not written" 119 cat $disk_option/failed.txt 120 exit 1 121fi 122