aboutsummaryrefslogtreecommitdiff
path: root/script/setup_fvp_optee.sh
blob: 71f27399b2640afd93b929e5f2308cb2e8668ade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
#!/bin/bash
################################################################################
# EDIT so these match your credentials                                         #
################################################################################
DEV_PATH=$HOME/devel/fvp_optee_benchmark
SRC_FVP=

# You only need to set these variables if you have access to the OPTEE_TEST
# (requires a Linaro account and access to the git called optee_test.git)
LINARO_USERNAME=firstname.lastname # Should _NOT_ contain @linaro.org.
HAVE_ACCESS_TO_OPTEE_TEST=
################################################################################
# Don't touch anything below this comment                                      #
################################################################################
mkdir -p $DEV_PATH

DST_FVP=$DEV_PATH/Foundation_Platformpkg
if [ ! -n "$SRC_FVP" ]; then
	echo "FVP must be downloaded first, please go to: "
	echo "  http://www.arm.com/products/tools/models/fast-models/foundation-model.php"
	echo "When done, install it on this path:"
	echo "  $DST_FVP"
	echo "Then open this script (`basename $0`) and change the line from saying:"
	echo "  SRC_FVP=     to      SRC_FVP=1"
	exit
fi

# Until something official ARM-TF supports loading a partitioned OP-TEE
# SRC_ARM_TF=https://github.com/ARM-software/arm-trusted-firmware.git
SRC_ARM_TF=https://github.com/jenswi-linaro/arm-trusted-firmware.git
DST_ARM_TF=$DEV_PATH/arm-trusted-firmware
STABLE_ARM_TF_COMMIT=db4b9efe59b4f76e9680836a443158fde0f12e40

SRC_KERNEL=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
DST_KERNEL=$DEV_PATH/linux
STABLE_KERNEL_COMMIT=v3.18-rc1

SRC_OPTEE_OS=https://github.com/kong1191/optee_os.git
DST_OPTEE_OS=$DEV_PATH/optee_os

SRC_OPTEE_CLIENT=https://github.com/OP-TEE/optee_client.git
DST_OPTEE_CLIENT=$DEV_PATH/optee_client
STABLE_CLIENT_COMMIT=2893f86b0925bc6be358a6913a07773b2b909ee3

SRC_OPTEE_LK=https://github.com/kong1191/optee_linuxdriver.git
DST_OPTEE_LK=$DEV_PATH/optee_linuxdriver

SRC_OPTEE_TEST=ssh://$LINARO_USERNAME@linaro-private.git.linaro.org/srv/linaro-private.git.linaro.org/swg/optee_test.git
DST_OPTEE_TEST=$DEV_PATH/optee_test
STABLE_OPTEE_TEST_COMMIT=774cc3c10954eba316d56f48112652eff05f33a0

SRC_GEN_ROOTFS=https://github.com/jbech-linaro/gen_rootfs.git
DST_GEN_ROOTFS=$DEV_PATH/gen_rootfs
STABLE_GEN_ROOTFS_COMMIT=e4633eb4e5d170021f45bbdfca9c65e3b41c866b

SRC_OPTEE_BENCHMARK=https://github.com/kong1191/optee_benchmark.git
DST_OPTEE_BENCHMARK=$DEV_PATH/optee_benchmark

SRC_EDK2=https://github.com/tianocore/edk2.git
DST_EDK2=$DEV_PATH/edk2
STABLE_EDK2_COMMIT=8c83d0c0b9bd102cd905c83b2644a543e9711815

AARCH64_NONE_GCC=aarch64-none-elf
AARCH64_NONE_GCC_VERSION=gcc-linaro-aarch64-none-elf-4.9-2014.07_linux
SRC_AARCH64_NONE_GCC=http://releases.linaro.org/14.07/components/toolchain/binaries/${AARCH64_NONE_GCC_VERSION}.tar.xz
DST_AARCH64_NONE_GCC=$DEV_PATH/toolchains/$AARCH64_NONE_GCC

AARCH64_GCC=aarch64
AARCH64_GCC_VERSION=gcc-linaro-aarch64-linux-gnu-4.9-2014.08_linux
SRC_AARCH64_GCC=http://releases.linaro.org/14.08/components/toolchain/binaries/${AARCH64_GCC_VERSION}.tar.xz
DST_AARCH64_GCC=$DEV_PATH/toolchains/$AARCH64_GCC

AARCH32_GCC=aarch32
AARCH32_GCC_VERSION=gcc-linaro-arm-linux-gnueabihf-4.9-2014.08_linux
SRC_AARCH32_GCC=http://releases.linaro.org/14.08/components/toolchain/binaries/${AARCH32_GCC_VERSION}.tar.xz
DST_AARCH32_GCC=$DEV_PATH/toolchains/$AARCH32_GCC

################################################################################
# Cloning all needed repositories                                              #
################################################################################
if [ ! -d "$DST_OPTEE_BENCHMARK" ]; then
	git clone $SRC_OPTEE_BENCHMARK $DST_OPTEE_BENCHMARK
else
	echo " `basename $DST_OPTEE_BENCHMARK` already exist, not cloning"
fi

cd $DEV_PATH
if [ ! -d "$DST_ARM_TF" ]; then
	git clone $SRC_ARM_TF && cd $DST_ARM_TF && git reset --hard $STABLE_ARM_TF_COMMIT
else
	echo " `basename $DST_ARM_TF` already exist, not cloning"
fi

cd $DEV_PATH
if [ ! -d "$DST_KERNEL" ]; then
	git clone $SRC_KERNEL && cd $DST_KERNEL && git reset --hard $STABLE_KERNEL_COMMIT
else
	echo " `basename $DST_KERNEL` already exist, not cloning"
fi

cd $DEV_PATH
if [ ! -d "$DST_OPTEE_OS" ]; then
	git clone $SRC_OPTEE_OS
else
	echo " `basename $DST_OPTEE_OS` already exist, not cloning"
fi

cd $DEV_PATH
if [ ! -d "$DST_OPTEE_CLIENT" ]; then
	git clone $SRC_OPTEE_CLIENT && cd $DST_OPTEE_CLIENT && git reset --hard $STABLE_CLIENT_COMMIT
else
	echo " `basename $DST_OPTEE_CLIENT` already exist, not cloning"
fi

cd $DEV_PATH
if [ ! -d "$DST_OPTEE_LK" ]; then
	git clone $SRC_OPTEE_LK
else
	echo " `basename $DST_OPTEE_LK` already exist, not cloning"
fi

cd $DEV_PATH
if [ ! -d "$DST_OPTEE_TEST" ] && [ -n "$HAVE_ACCESS_TO_OPTEE_TEST" ]; then
	git clone $SRC_OPTEE_TEST && cd $DST_OPTEE_TEST && git reset --hard $STABLE_OPTEE_TEST_COMMIT
else
	echo " `basename $DST_OPTEE_TEST` already exist (or no access), not cloning"
fi

cd $DEV_PATH
if [ ! -d "$DST_GEN_ROOTFS" ]; then
	git clone $SRC_GEN_ROOTFS && cd $DST_GEN_ROOTFS && git reset --hard $STABLE_GEN_ROOTFS_COMMIT
else
	echo " `basename $DST_GEN_ROOTFS` already exist, not cloning"
fi

cd $DEV_PATH
if [ ! -d "$DST_EDK2" ]; then
	git clone -n $SRC_EDK2 && cd $DST_EDK2 && git reset --hard $STABLE_EDK2_COMMIT
else
	echo " `basename $DST_EDK2` already exist, not cloning"
fi

################################################################################
# Download and install the needed toolchains                                   #
################################################################################
mkdir -p $DEV_PATH/toolchains
cd $DEV_PATH/toolchains

if [ ! -f "${AARCH64_NONE_GCC_VERSION}.tar.xz" ]; then
	wget $SRC_AARCH64_NONE_GCC
fi
if [ ! -d "$DST_AARCH64_NONE_GCC" ]; then
	echo "Untar $AARCH64_NONE_GCC_VERSION ..."
	tar xf ${AARCH64_NONE_GCC_VERSION}.tar.xz && mv $AARCH64_NONE_GCC_VERSION $DST_AARCH64_NONE_GCC
fi


if [ ! -f "${AARCH64_GCC_VERSION}.tar.xz" ]; then
	wget $SRC_AARCH64_GCC
fi
if [ ! -d "$DST_AARCH64_GCC" ]; then
	echo "Untar $AARCH64_GCC_VERSION ..."
	tar xf ${AARCH64_GCC_VERSION}.tar.xz && mv $AARCH64_GCC_VERSION $DST_AARCH64_GCC
fi

if [ ! -f "${AARCH32_GCC_VERSION}.tar.xz" ]; then
	wget $SRC_AARCH32_GCC
fi
if [ ! -d "$DST_AARCH32_GCC" ]; then
	echo "Untar $AARCH32_GCC_VERSION ..."
	tar xf ${AARCH32_GCC_VERSION}.tar.xz && mv $AARCH32_GCC_VERSION $DST_AARCH32_GCC
fi

################################################################################
# Generate the build script for Linux kernel                                   #
################################################################################
cd $DEV_PATH
cat > $DEV_PATH/build_linux.sh << EOF
#/bin/bash
export PATH=$DST_AARCH64_NONE_GCC/bin:\$PATH
export CROSS_COMPILE=$DST_AARCH64_NONE_GCC/bin/aarch64-none-elf-
cd $DST_KERNEL

if [ ! -f ".config" ]; then
	make ARCH=arm64 defconfig
fi

make -j\`getconf _NPROCESSORS_ONLN\` LOCALVERSION= ARCH=arm64 \$@
EOF

chmod 711 $DEV_PATH/build_linux.sh
# We must also build it since we need gen_init_cpio during the setup
$DEV_PATH/build_linux.sh

# Save kernel version for later use
export KERNEL_VERSION=`cd $DST_KERNEL && make kernelversion`

################################################################################
# Generate the filesystem using gen_init_cpio                                  #
################################################################################
cd $DST_GEN_ROOTFS
export CC_DIR=$DST_AARCH64_GCC

# Set path to gen_init_cpio
export PATH=$DST_KERNEL/usr:$PATH

if [ ! -f "$DST_GEN_ROOTFS/filelist-tee.txt" ]; then
	echo "Generting the file system"
	./generate-cpio-rootfs.sh fvp-aarch64
fi

cp $DST_GEN_ROOTFS/filelist-final.txt $DST_GEN_ROOTFS/filelist-tee.txt

# Remove last line about fbtest in the filelist
head -n -1 $DST_GEN_ROOTFS/filelist-tee.txt > temp.txt ; mv temp.txt $DST_GEN_ROOTFS/filelist-tee.txt

cat >> $DST_GEN_ROOTFS/filelist-tee.txt << EOF
# OP-TEE device
dir /lib/modules 755 0 0
dir /lib/modules/$KERNEL_VERSION 755 0 0
file /lib/modules/$KERNEL_VERSION/optee.ko $DST_OPTEE_LK/optee.ko 755 0 0

# OP-TEE Client
file /bin/tee-supplicant $DST_OPTEE_CLIENT/out/export/bin/tee-supplicant 755 0 0
dir /lib/aarch64-linux-gnu 755 0 0
file /lib/aarch64-linux-gnu/libteec.so.1.0 $DST_OPTEE_CLIENT/out/export/lib/libteec.so.1.0 755 0 0
slink /lib/aarch64-linux-gnu/libteec.so.1 libteec.so.1.0 755 0 0
slink /lib/aarch64-linux-gnu/libteec.so libteec.so.1 755 0 0

# Secure storage dig
dir /data 755 0 0
dir /data/tee 755 0 0

# TAs
dir /lib/teetz 755 0 0

file /lib/teetz/99e937a0-8f3e-11e4-8b8f0002a5d5c51b.ta $DST_OPTEE_BENCHMARK/ta/out-client-aarch64/99e937a0-8f3e-11e4-8b8f0002a5d5c51b.ta 444 0 0

file /bin/simple_client $DST_OPTEE_BENCHMARK/host/simple_client 755 0 0
EOF

if [ -n "$HAVE_ACCESS_TO_OPTEE_TEST" ]; then
cat >> $DST_GEN_ROOTFS/filelist-tee.txt << EOF
# Trusted Applications
file /lib/teetz/d17f73a0-36ef-11e1-984a0002a5d5c51b.ta $DEV_PATH/out/utest/user_ta/armv7/rpc_test/d17f73a0-36ef-11e1-984a0002a5d5c51b.ta 444 0 0
file /lib/teetz/cb3e5ba0-adf1-11e0-998b0002a5d5c51b.ta $DEV_PATH/out/utest/user_ta/armv7/crypt/cb3e5ba0-adf1-11e0-998b0002a5d5c51b.ta 444 0 0
file /lib/teetz/b689f2a7-8adf-477a-9f9932e90c0ad0a2.ta $DEV_PATH/out/utest/user_ta/armv7/storage/b689f2a7-8adf-477a-9f9932e90c0ad0a2.ta 444 0 0
file /lib/teetz/5b9e0e40-2636-11e1-ad9e0002a5d5c51b.ta $DEV_PATH/out/utest/user_ta/armv7/os_test/5b9e0e40-2636-11e1-ad9e0002a5d5c51b.ta 444 0 0
file /lib/teetz/c3f6e2c0-3548-11e1-b86c0800200c9a66.ta $DEV_PATH/out/utest/user_ta/armv7/create_fail_test/c3f6e2c0-3548-11e1-b86c0800200c9a66.ta 444 0 0
file /lib/teetz/e6a33ed4-562b-463a-bb7eff5e15a493c8.ta $DEV_PATH/out/utest/user_ta/armv7/sims/e6a33ed4-562b-463a-bb7eff5e15a493c8.ta 444 0 0

# OP-TEE Tests
file /bin/xtest $DEV_PATH/out/utest/host/xtest/bin/xtest 755 0 0
EOF

fi

################################################################################
# Generate build_optee_os.sh for building optee_os                             #
################################################################################
cd $DEV_PATH
cat > $DEV_PATH/build_optee_os.sh << EOF
#/bin/bash
export PATH=$DST_AARCH32_GCC/bin:\$PATH
export CROSS_COMPILE=arm-linux-gnueabihf-
export PLATFORM=vexpress
export PLATFORM_FLAVOR=fvp
export O=$DST_OPTEE_OS/out-os-fvp
export CFG_TEE_CORE_LOG_LEVEL=4
export CFG_TEE_TRACE_PERFORMANCE=y
#export DEBUG=1

cd $DST_OPTEE_OS
make -j\`getconf _NPROCESSORS_ONLN\` \$@
EOF

chmod 711 $DEV_PATH/build_optee_os.sh
$DEV_PATH/build_optee_os.sh

################################################################################
# Generate build_uefi.sh for Tianocore EDK2                                    #
################################################################################
# First some configuration according to the ARM-Trusted-Firmware page:
# https://github.com/ARM-software/arm-trusted-firmware/blob/master/docs/user-guide.md#obtaining-edk2
cd $DST_EDK2
git remote add -f --tags arm-software https://github.com/ARM-software/edk2.git
git checkout --detach v1.2

cd $DEV_PATH
cat > $DEV_PATH/build_uefi.sh << EOF
#/bin/bash
export GCC49_AARCH64_PREFIX=$DST_AARCH64_NONE_GCC/bin/aarch64-none-elf-

cd $DST_EDK2
. edksetup.sh

# Build the EDK host tools
make -C BaseTools clean
make -C BaseTools

make -f ArmPlatformPkg/Scripts/Makefile EDK2_ARCH=AARCH64 \\
	EDK2_DSC=ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-FVP-AArch64.dsc \\
	EDK2_TOOLCHAIN=GCC49 EDK2_BUILD=RELEASE \\
	EDK2_MACROS="-n 6 -D ARM_FOUNDATION_FVP=1" \$@
EOF

chmod 711 $DEV_PATH/build_uefi.sh
$DEV_PATH/build_uefi.sh

################################################################################
# Generate build_arm_tf_opteed.sh for building ARM TF and opteed               #
################################################################################
cd $DEV_PATH

cat > $DEV_PATH/build_arm_tf_opteed.sh << EOF
#!/bin/bash
export PATH=$DST_AARCH64_NONE_GCC/bin:\$PATH
export CROSS_COMPILE=$DST_AARCH64_NONE_GCC/bin/aarch64-none-elf-
export CFLAGS='-O0 -gdwarf-2'
export DEBUG=1
export BL32=$DST_OPTEE_OS/out-os-fvp/core/tee.bin
export BL33=$DST_EDK2/Build/ArmVExpress-FVP-AArch64/RELEASE_GCC49/FV/FVP_AARCH64_EFI.fd

cd $DST_ARM_TF
make -j\`getconf _NPROCESSORS_ONLN\`   \\
	DEBUG=                        \\
	FVP_TSP_RAM_LOCATION=tdram     \\
	FVP_SHARED_DATA_LOCATION=tdram \\
	PLAT=fvp                       \\
	SPD=opteed                     \\
	\$@
EOF

chmod 711 $DEV_PATH/build_arm_tf_opteed.sh
$DEV_PATH/build_arm_tf_opteed.sh all fip

################################################################################
# Generate build_optee_client.sh for building optee_client                     #
################################################################################
cd $DEV_PATH

cat > $DEV_PATH/build_optee_client.sh << EOF
#!/bin/bash
export PATH=$DST_AARCH64_GCC/bin:\$PATH

cd $DST_OPTEE_CLIENT
make -j\`getconf _NPROCESSORS_ONLN\` O=out CROSS_COMPILE=aarch64-linux-gnu- \$@
EOF

chmod 711 $DEV_PATH/build_optee_client.sh
$DEV_PATH/build_optee_client.sh

if [ -n "$HAVE_ACCESS_TO_OPTEE_TEST" ]; then
################################################################################
# Generate build_optee_tests.sh                                                #
################################################################################
cd $DEV_PATH

cat > $DEV_PATH/build_optee_tests.sh << EOF
#!/bin/bash
cd $DST_OPTEE_TEST
export CFG_DEV_PATH=$DEV_PATH
export CFG_ROOTFS_DIR=\$CFG_DEV_PATH/out

export PATH=\$CFG_DEV_PATH/toolchains/aarch64/bin:\$PATH
export PATH=\$CFG_DEV_PATH/toolchains/aarch32/bin:\$PATH

make $@
EOF

chmod 711 $DEV_PATH/build_optee_tests.sh
$DEV_PATH/build_optee_tests.sh
fi

################################################################################
# Generate build_optee_linuxkernel.sh                                          #
################################################################################
cd $DEV_PATH

cat > $DEV_PATH/build_optee_linuxkernel.sh << EOF
#!/bin/bash
export PATH=$DST_AARCH64_GCC/bin:\$PATH

cd $DST_KERNEL
make CONFIG_TEE_TRACE_PERFORMANCE=y V=0 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- LOCALVERSION= M=$DST_OPTEE_LK modules \$@
EOF

chmod 711 $DEV_PATH/build_optee_linuxkernel.sh
$DEV_PATH/build_optee_linuxkernel.sh

################################################################################
# Generate the files system using gen_init_cpio part 2 - update_rootfs.sh      #
################################################################################
cd $DEV_PATH
cat > $DEV_PATH/update_rootfs.sh << EOF
#!/bin/bash
export PATH=$DST_KERNEL/usr:\$PATH

cd $DST_GEN_ROOTFS
gen_init_cpio $DST_GEN_ROOTFS/filelist-tee.txt | gzip > $DST_FVP/filesystem.cpio.gz
EOF

chmod 711 $DEV_PATH/update_rootfs.sh
$DEV_PATH/update_rootfs.sh

################################################################################
# Generate optee_benchmark/build_app.sh                                        #
################################################################################
cd $DST_OPTEE_BENCHMARK
cat > $DST_OPTEE_BENCHMARK/build_app.sh << EOF
#!/bin/bash
DEVEL_PATH=$DEV_PATH
export PATH=\$DEVEL_PATH/toolchains/aarch64/bin:\$PATH
export PATH=\$DEVEL_PATH/toolchains/aarch32/bin:\$PATH

export TA_DEV_KIT_DIR=\$DEVEL_PATH/optee_os/out-os-fvp/export-user_ta
export TEEC_EXPORT=\$DEVEL_PATH/optee_client/out/export

cd \$DEVEL_PATH/optee_benchmark
make O=./out-client-aarch64 \\
     HOST_CROSS_COMPILE=aarch64-linux-gnu- \\
     TA_CROSS_COMPILE=arm-linux-gnueabihf- \\
     \$@
                
EOF

chmod 711 $DST_OPTEE_BENCHMARK/build_app.sh
$DST_OPTEE_BENCHMARK/build_app.sh

################################################################################
# Generate build_device_tree_files.sh                                          #
################################################################################
cd $DEV_PATH

cat > $DEV_PATH/build_device_tree_files.sh << EOF
#!/bin/bash

cd $DST_OPTEE_LK/fdts
$DST_KERNEL/scripts/dtc/dtc -O dtb -o fvp-foundation-gicv2-psci.dtb -b 0 -i . fvp-foundation-gicv2-psci.dts
EOF

chmod 711 $DEV_PATH/build_device_tree_files.sh
$DEV_PATH/build_device_tree_files.sh

################################################################################
# Generate run_foundation.sh                                                   #
################################################################################
cd $DST_FVP
ln -sf $DST_KERNEL/arch/arm64/boot/Image .
ln -sf $DST_OPTEE_LK/fdts/fvp-foundation-gicv2-psci.dtb fdt.dtb

cd $DEV_PATH
cat > $DEV_PATH/run_foundation.sh << EOF
#!/bin/bash
BL1=$DST_ARM_TF/build/fvp/debug/bl1.bin
FIP=$DST_ARM_TF/build/fvp/debug/fip.bin

cd $DST_FVP
$DST_FVP/models/Linux64_GCC-4.1/Foundation_Platform \\
        --cores=4                             \\
        --no-secure-memory                    \\
        --visualization                       \\
        --gicv3                               \\
        --data="\${BL1}"@0x0                  \\
        --data="\${FIP}"@0x8000000
EOF

chmod 711 $DEV_PATH/run_foundation.sh

################################################################################
# Generate build_secure.sh                                                     #
################################################################################
cd $DEV_PATH

cat > $DEV_PATH/build_secure.sh << EOF
#!/bin/bash
cd $DEV_PATH
./build_optee_os.sh && ./build_arm_tf_opteed.sh all fip

EOF

chmod 711 $DEV_PATH/build_secure.sh

################################################################################
# Generate build_normal.sh                                                     #
################################################################################
cd $DEV_PATH

cat > $DEV_PATH/build_normal.sh << EOF
#!/bin/bash
cd $DEV_PATH
./build_optee_client.sh
if [ -f "build_optee_tests.sh" ]; then
	./build_optee_tests.sh
fi
./build_optee_linuxkernel.sh
./update_rootfs.sh
./build_linux.sh
./build_device_tree_files.sh
EOF

chmod 711 $DEV_PATH/build_normal.sh

echo "OP-TEE and FVP setup completed."
if [ ! -n "$HAVE_ACCESS_TO_OPTEE_TEST" ]; then
	echo "LINARO_USERNAME and HAVE_ACCESS_TO_OPTEE_TEST wasn't updated, therefore no tests"
	echo "has been included."
fi

################################################################################
# Generate clean_gits.sh script                                                #
################################################################################
cd $DEV_PATH
cat > $DEV_PATH/clean_gits.sh << EOF
#!/bin/bash
CLEAN_CMD="git clean -xdf"
CLEAN_CMD2="git reset --hard"

echo "This will clean all gits using \$CLEAN_CMD && \$CLEAN_CMD2,"
echo "if this was not your intention, then press CTRL+C immediately!"
read -t 10

cd $DST_ARM_TF && \$CLEAN_CMD && \$CLEAN_CMD2 && echo -e "$DST_ARM_TF clean!\n"
cd $DST_KERNEL && \$CLEAN_CMD && \$CLEAN_CMD2 && echo -e"$DST_KERNEL clean!\n"
cd $DST_OPTEE_OS && \$CLEAN_CMD && \$CLEAN_CMD2 && echo -e "$DST_OPTEE_OS clean!\n"
cd $DST_OPTEE_CLIENT && \$CLEAN_CMD && \$CLEAN_CMD2 && echo -e "$DST_OPTEE_CLIENT clean!\n"
cd $DST_OPTEE_LK && \$CLEAN_CMD && \$CLEAN_CMD2 && echo -e "$DST_OPTEE_LK clean!\n"
if [ -d "$DST_OPTEE_TEST" ]; then
	cd $DST_OPTEE_TEST && \$CLEAN_CMD && \$CLEAN_CMD2 && echo -e "$DST_OPTEE_TEST clean!\n"
	rm -rf $DEV_PATH/out
fi
cd $DST_GEN_ROOTFS && \$CLEAN_CMD && \$CLEAN_CMD2 && echo -e "$DST_GEN_ROOTFS clean!\n"
cd $DST_EDK2 && \$CLEAN_CMD && \$CLEAN_CMD2 && echo -e "$DST_EDK2 clean!\n"
EOF

chmod 711 $DEV_PATH/clean_gits.sh