blob: ea349e531c7db24e481fadca4f7b11f5ccd7392a [file] [log] [blame]
Robert Rostohar85056ab2021-01-25 17:01:11 +01001#!/bin/bash
2# Copyright (c) 2020, Arm Limited. All rights reserved.
3# SPDX-License-Identifier: BSD-3-Clause
4# Setup MPS2 TF-M Platform for building CMSIS-Pack
5
6# TF-M root directory
7TFM_ROOT=./trusted-firmware-m
8
9# MCUboot root directory
10MCUBOOT_ROOT=./mcuboot
11
12# Source and destination root directory
13SRC_ROOT=./trusted-firmware-m/platform/ext/target/mps2/an521
14DST_ROOT=./tf-m-platform-mps2/mps2/an521
15
16# Copy TF-M Platform files
17mkdir -p ${DST_ROOT}
18mkdir -p ${DST_ROOT}/native_drivers
19mkdir -p ${DST_ROOT}/partition
20mkdir -p ${DST_ROOT}/services/src
21cp -v ${SRC_ROOT}/boot_hal.c ${DST_ROOT}/
22cp -v ${SRC_ROOT}/plat_test.c ${DST_ROOT}/
23cp -v ${SRC_ROOT}/spm_hal.c ${DST_ROOT}/
24cp -v ${SRC_ROOT}/target_cfg.c ${DST_ROOT}/
25cp -v ${SRC_ROOT}/target_cfg.h ${DST_ROOT}/
26cp -v ${SRC_ROOT}/tfm_hal_isolation.c ${DST_ROOT}/
27cp -v ${SRC_ROOT}/tfm_peripherals_def.h ${DST_ROOT}/
28cp -v ${SRC_ROOT}/native_drivers/mpu_armv8m_drv.c ${DST_ROOT}/native_drivers/
29cp -v ${SRC_ROOT}/native_drivers/mpu_armv8m_drv.h ${DST_ROOT}/native_drivers/
30cp -v ${SRC_ROOT}/partition/flash_layout.h ${DST_ROOT}/partition/
31cp -v ${SRC_ROOT}/partition/region_defs.h ${DST_ROOT}/partition/
32cp -v ${SRC_ROOT}/services/src/tfm_platform_system.c ${DST_ROOT}/services/src/
33
34# Copy TF-M Platform device files (temporary directory before patching)
35mkdir -p ${DST_ROOT}/device
36mkdir -p ${DST_ROOT}/device/bl2
37mkdir -p ${DST_ROOT}/device/secure
38mkdir -p ${DST_ROOT}/device/non_secure
39cp -v ${SRC_ROOT}/cmsis_driver_config.h ${DST_ROOT}/device/
40cp -v ${SRC_ROOT}/device_cfg.h ${DST_ROOT}/device/
41cp -v ${SRC_ROOT}/RTE_Device.h ${DST_ROOT}/device/
42cp -v ${SRC_ROOT}/armclang/startup_cmsdk_mps2_an521_bl2.s ${DST_ROOT}/device/bl2/
43cp -v ${SRC_ROOT}/armclang/startup_cmsdk_mps2_an521_s.s ${DST_ROOT}/device/secure/
44cp -v ${SRC_ROOT}/armclang/startup_cmsdk_mps2_an521_ns.s ${DST_ROOT}/device/non_secure/
45cp -v ${SRC_ROOT}/armclang/mps2_an521_bl2.sct ${DST_ROOT}/device/bl2/
46cp -v ${SRC_ROOT}/armclang/mps2_an521_ns.sct ${DST_ROOT}/device/non_secure/
47cp -v ${SRC_ROOT}/cmsis_core/cmsis.h ${DST_ROOT}/device/
48cp -v ${SRC_ROOT}/cmsis_core/cmsis_cpu.h ${DST_ROOT}/device/
49cp -v ${SRC_ROOT}/cmsis_core/mps2_an521.h ${DST_ROOT}/device/
50cp -v ${SRC_ROOT}/cmsis_core/platform_irq.h ${DST_ROOT}/device/
51cp -v ${SRC_ROOT}/cmsis_core/platform_regs.h ${DST_ROOT}/device/
52cp -v ${SRC_ROOT}/cmsis_core/system_cmsdk_mps2_an521.c ${DST_ROOT}/device/
53cp -v ${SRC_ROOT}/cmsis_core/system_cmsdk_mps2_an521.h ${DST_ROOT}/device/
54cp -v ${SRC_ROOT}/retarget/platform_retarget.h ${DST_ROOT}/device/
55cp -v ${SRC_ROOT}/retarget/platform_retarget_dev.c ${DST_ROOT}/device/
56cp -v ${SRC_ROOT}/retarget/platform_retarget_dev.h ${DST_ROOT}/device/
57cp -v ${SRC_ROOT}/retarget/platform_retarget_pins.h ${DST_ROOT}/device/
58cp -v ${DST_ROOT}/target_cfg.h ${DST_ROOT}/device/
59cp -v ${DST_ROOT}/target_cfg.c ${DST_ROOT}/device/secure/
60cp -v ${DST_ROOT}/spm_hal.c ${DST_ROOT}/device/secure/
61cp -v ${DST_ROOT}/tfm_peripherals_def.h ${DST_ROOT}/device/secure/
62
63# Apply patches
64cd tf-m-platform-mps2
65for f in ../tf-m-platform-mps2_patch/*.patch
66 do
67 git apply -v $f
68done
69cd ..
70
71# Update TF-M Platform files (after patching)
72cp -vf ${DST_ROOT}/device/target_cfg.h ${DST_ROOT}/
73cp -vf ${DST_ROOT}/device/secure/target_cfg.c ${DST_ROOT}/
74cp -vf ${DST_ROOT}/device/secure/spm_hal.c ${DST_ROOT}/
75cp -vf ${DST_ROOT}/device/secure/tfm_peripherals_def.h ${DST_ROOT}/
76
77# Destination path for projects (bl2+secure)
78DST_PATH="
79 ${DST_ROOT}/project/fvp/tfm_bl/bl2
80 ${DST_ROOT}/project/fvp/tfm_bl/tfm_s
81 ${DST_ROOT}/project/fvp/tfm/tfm_s
82 ${DST_ROOT}/test/fvp/ipc_l1/tfm_s
83 ${DST_ROOT}/test/fvp/ipc_l2/tfm_s
84 ${DST_ROOT}/test/fvp/ipc_l3/tfm_s
85 ${DST_ROOT}/test/fvp/sfn/tfm_s
86"
87
88# Copy TF-M Platform native drivers
89FILE_LIST="
90 arm_uart_drv.c
91 arm_uart_drv.h
92 mpc_sie200_drv.c
93 mpc_sie200_drv.h
94 ppc_sse200_drv.c
95 ppc_sse200_drv.h
96"
97SUB_DIR=native_drivers
98for d in ${DST_PATH}
99do
100 mkdir -p $d/${SUB_DIR}
101 for f in ${FILE_LIST}
102 do
103 cp -v ${SRC_ROOT}/${SUB_DIR}/$f $d/${SUB_DIR}/
104 done
105done
106
107FILE_LIST="
108 timer_cmsdk.c
109 timer_cmsdk.h
110"
111SUB_DIR=native_drivers/timer_cmsdk
112for d in ${DST_PATH}
113do
114 mkdir -p $d/${SUB_DIR}
115 for f in ${FILE_LIST}
116 do
117 cp -v ${SRC_ROOT}/${SUB_DIR}/$f $d/${SUB_DIR}/
118 done
119done
120
121# Copy TF-M Platform CMSIS drivers
122FILE_LIST="
123 Driver_Flash.c
124 Driver_MPC.c
125 Driver_PPC.c
126 Driver_USART.c
127"
128SUB_DIR=cmsis_drivers
129for d in ${DST_PATH}
130do
131 mkdir -p $d/${SUB_DIR}
132 for f in ${FILE_LIST}
133 do
134 cp -v ${SRC_ROOT}/${SUB_DIR}/$f $d/${SUB_DIR}/
135 done
136done
137
138FILE_LIST="
139 Driver_MPC.h
140 Driver_PPC.h
141"
142SRC_DIR=../../../driver
143DST_DIR=cmsis_drivers
144for d in ${DST_PATH}
145do
146 mkdir -p $d/${DST_DIR}
147 for f in ${FILE_LIST}
148 do
149 cp -v ${SRC_ROOT}/${SRC_DIR}/$f $d/${DST_DIR}/
150 done
151done
152
153# Destination directory for device files
154DST_DIR=RTE/Device/SMM-SSE-200
155
156# Destination path for projects (bl2+secure+non_secure)
157DST_PATH="
158 ${DST_ROOT}/project/fvp/tfm_bl/bl2
159 ${DST_ROOT}/project/fvp/tfm_bl/tfm_s
160 ${DST_ROOT}/project/fvp/tfm_bl/tfm_ns
161 ${DST_ROOT}/project/fvp/tfm/tfm_s
162 ${DST_ROOT}/project/fvp/tfm/tfm_ns
163 ${DST_ROOT}/test/fvp/ipc_l1/tfm_s
164 ${DST_ROOT}/test/fvp/ipc_l1/tfm_ns
165 ${DST_ROOT}/test/fvp/ipc_l2/tfm_s
166 ${DST_ROOT}/test/fvp/ipc_l2/tfm_ns
167 ${DST_ROOT}/test/fvp/ipc_l3/tfm_s
168 ${DST_ROOT}/test/fvp/ipc_l3/tfm_ns
169 ${DST_ROOT}/test/fvp/sfn/tfm_s
170 ${DST_ROOT}/test/fvp/sfn/tfm_ns
171"
172
173# Copy device files (bl2+secure+non_secure)
174for d in ${DST_PATH}
175do
176 mkdir -p $d/${DST_DIR}
177 cp -v ${DST_ROOT}/device/*.* $d/${DST_DIR}/
178done
179
180# Destination path for projects (bl2)
181DST_PATH="
182 ${DST_ROOT}/project/fvp/tfm_bl/bl2
183"
184
185# Copy device files (bl2)
186for d in ${DST_PATH}
187do
188 mkdir -p $d/${DST_DIR}
189 cp -v ${DST_ROOT}/device/bl2/*.* $d/${DST_DIR}/
190done
191
192# Copy TF-M specific files (bl2)
193for d in ${DST_PATH}
194do
195 mkdir -p $d/RTE/TFM
196 cp -v ${TFM_ROOT}/bl2/ext/mcuboot/config/mcuboot-mbedtls-cfg.h $d/RTE/TFM/
Robert Rostoharc25fc5f2021-02-18 14:59:06 +0100197 sed -b -i '/#define __MCUBOOT_MBEDTLS_CFG__/a\\r\n#include "bl2_config.h"\r' $d/RTE/TFM/mcuboot-mbedtls-cfg.h
Robert Rostohar85056ab2021-01-25 17:01:11 +0100198 mkdir -p $d/RTE/TFM_Platform/SMM-SSE-200
199 cp -v ${DST_ROOT}/boot_hal.c $d/RTE/TFM_Platform/SMM-SSE-200/
200 cp -v ${DST_ROOT}/partition/flash_layout.h $d/RTE/TFM_Platform/SMM-SSE-200/
201 cp -v ${DST_ROOT}/partition/region_defs.h $d/RTE/TFM_Platform/SMM-SSE-200/
202done
203
204# Destination path for projects (secure)
205DST_PATH="
206 ${DST_ROOT}/project/fvp/tfm_bl/tfm_s
207 ${DST_ROOT}/project/fvp/tfm/tfm_s
208 ${DST_ROOT}/test/fvp/ipc_l1/tfm_s
209 ${DST_ROOT}/test/fvp/ipc_l2/tfm_s
210 ${DST_ROOT}/test/fvp/ipc_l3/tfm_s
211 ${DST_ROOT}/test/fvp/sfn/tfm_s
212"
213
214# Copy device files (secure)
215for d in ${DST_PATH}
216do
217 mkdir -p $d/${DST_DIR}
218 cp -v ${DST_ROOT}/device/secure/*.* $d/${DST_DIR}/
219done
220
221# Copy TF-M specific files (secure)
222for d in ${DST_PATH}
223do
224 mkdir -p $d/RTE/TFM
225 cp -v ${TFM_ROOT}/platform/ext/common/armclang/tfm_common_s.sct $d/RTE/TFM/
226 cp -v ${TFM_ROOT}/platform/ext/common/armclang/tfm_isolation_l3.sct $d/RTE/TFM/
227 cp -v ${TFM_ROOT}/lib/ext/mbedcrypto/mbedcrypto_config/tfm_mbedcrypto_config.h $d/RTE/TFM/
228 mkdir -p $d/RTE/TFM_Platform
229 cp -v ${TFM_ROOT}/platform/ext/common/template/attest_hal.c $d/RTE/TFM_Platform/
230 mkdir -p $d/RTE/TFM_Platform/SMM-SSE-200
231 cp -v ${DST_ROOT}/partition/flash_layout.h $d/RTE/TFM_Platform/SMM-SSE-200/
232 cp -v ${DST_ROOT}/partition/region_defs.h $d/RTE/TFM_Platform/SMM-SSE-200/
233 cp -v ${DST_ROOT}/services/src/tfm_platform_system.c $d/RTE/TFM_Platform/SMM-SSE-200/
234done
235
236# Destination path for projects (non_secure)
237DST_PATH="
238 ${DST_ROOT}/project/fvp/tfm_bl/tfm_ns
239 ${DST_ROOT}/project/fvp/tfm/tfm_ns
240 ${DST_ROOT}/test/fvp/ipc_l1/tfm_ns
241 ${DST_ROOT}/test/fvp/ipc_l2/tfm_ns
242 ${DST_ROOT}/test/fvp/ipc_l3/tfm_ns
243 ${DST_ROOT}/test/fvp/sfn/tfm_ns
244"
245
246# Copy device files (non_secure)
247for d in ${DST_PATH}
248do
249 mkdir -p $d/${DST_DIR}
250 cp -v ${DST_ROOT}/device/non_secure/* $d/${DST_DIR}/
251done
252
253# Adjust memory map of non-secure project when using bootloader
254pushd ${DST_ROOT}/project/fvp/tfm_bl/tfm_ns/${DST_DIR}
Robert Rostoharc25fc5f2021-02-18 14:59:06 +0100255sed -b -i 's/NS_CODE_START (0x00100000)/NS_CODE_START (0x00100400)/' mps2_an521_ns.sct
256sed -b -i 's/NS_CODE_SIZE (0x00080000)/NS_CODE_SIZE (0x0007F800)/' mps2_an521_ns.sct
Robert Rostohar85056ab2021-01-25 17:01:11 +0100257popd
258
259# Remove temporary device files
260rm -r ${DST_ROOT}/device
261
262# Copy root and encryption keys
263cp -v ${TFM_ROOT}/bl2/ext/mcuboot/root-RSA-3072.pem ${DST_ROOT}/project/fvp/tfm_bl/tfm_s/
264cp -v ${TFM_ROOT}/bl2/ext/mcuboot/root-RSA-3072_1.pem ${DST_ROOT}/project/fvp/tfm_bl/tfm_ns/
265cp -v ${MCUBOOT_ROOT}/enc-rsa2048-pub.pem ${DST_ROOT}/project/fvp/tfm_bl/tfm_s/
266cp -v ${MCUBOOT_ROOT}/enc-rsa2048-pub.pem ${DST_ROOT}/project/fvp/tfm_bl/tfm_ns/
267
268# Copy pack addon files
269cp -vr ./tf-m-platform-mps2_addon/* ./tf-m-platform-mps2/