blob: 1e0797b069e4663f280cbe9b790fee94ab325aae [file] [log] [blame]
Antonio Nino Diaz1451f612018-11-30 10:51:26 +00001#!/bin/bash
2
3#
Olivier Deprez6baf5b82021-05-14 19:04:40 +02004# Copyright (c) 2018-2022, Arm Limited. All rights reserved.
Antonio Nino Diaz1451f612018-11-30 10:51:26 +00005#
6# SPDX-License-Identifier: BSD-3-Clause
7#
8
9# Generate a DTB file from a base DTS file and the MAP file generated during the
10# compilation of a Secure Partition.
11
12# $1 = image_name (lowercase)
13# $2 = path/to/file.dts
14# $3 = build/$PLAT/$BUILD_TYPE/
Olivier Deprez6baf5b82021-05-14 19:04:40 +020015# $4 = path to store the dtb generated by this script
Antonio Nino Diaz1451f612018-11-30 10:51:26 +000016
17ORIGINAL_DTS=$2
18MAPFILE="$3/$1/$1.map"
19EXTRA_DTS="$3/$1/$1_extra.dts"
20COMBINED_DTS="$3/$1/$1_combined.dts"
21PREPROCESSED_DTS="$3/$1/$1_preprocessed.dts"
Olivier Deprez6baf5b82021-05-14 19:04:40 +020022GENERATED_DTB=$4
Antonio Nino Diaz1451f612018-11-30 10:51:26 +000023
24# Look for the start and end of the sections that are only known in the elf file
25# after compiling the partition.
26
27TEXT_START=$(grep __TEXT_START__ $MAPFILE | awk {'print $1'})
28TEXT_END=$(grep __TEXT_END__ $MAPFILE | awk {'print $1'})
29
30RODATA_START=$(grep __RODATA_START__ $MAPFILE | awk {'print $1'})
31RODATA_END=$(grep __RODATA_END__ $MAPFILE | awk {'print $1'})
32
33DATA_START=$(grep __DATA_START__ $MAPFILE | awk {'print $1'})
34DATA_END=$(grep __DATA_END__ $MAPFILE | awk {'print $1'})
35
36BSS_START=$(grep __BSS_START__ $MAPFILE | awk {'print $1'})
37BSS_END=$(grep __BSS_END__ $MAPFILE | awk {'print $1'})
38
39# Inject new sections to the base DTS
40
Olivier Deprez48e6d262020-03-13 18:04:17 +010041# Memory region generation discarded
Antonio Nino Diaz1451f612018-11-30 10:51:26 +000042
Olivier Deprez48e6d262020-03-13 18:04:17 +010043cat "$ORIGINAL_DTS" > "$COMBINED_DTS"
Antonio Nino Diaz1451f612018-11-30 10:51:26 +000044
45INCLUDES="-I spm/cactus
46 -I spm/ivy
Antonio Nino Diaz1451f612018-11-30 10:51:26 +000047 -I spm/include
48 -I include/lib"
49
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -060050cpp -x c -P -o "$PREPROCESSED_DTS" "$COMBINED_DTS" ${INCLUDES}
Antonio Nino Diaz1451f612018-11-30 10:51:26 +000051dtc -I dts -O dtb "$PREPROCESSED_DTS" > "$GENERATED_DTB"