blob: efcc67edd3c5b343bc6b7ad3b353ca534ee44dba [file] [log] [blame]
Antonio Nino Diaz1451f612018-11-30 10:51:26 +00001#!/bin/bash
2
3#
4# Copyright (c) 2018, Arm Limited. All rights reserved.
5#
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/
15
16ORIGINAL_DTS=$2
17MAPFILE="$3/$1/$1.map"
18EXTRA_DTS="$3/$1/$1_extra.dts"
19COMBINED_DTS="$3/$1/$1_combined.dts"
20PREPROCESSED_DTS="$3/$1/$1_preprocessed.dts"
21GENERATED_DTB="$3/$1.dtb"
22
23# Look for the start and end of the sections that are only known in the elf file
24# after compiling the partition.
25
26TEXT_START=$(grep __TEXT_START__ $MAPFILE | awk {'print $1'})
27TEXT_END=$(grep __TEXT_END__ $MAPFILE | awk {'print $1'})
28
29RODATA_START=$(grep __RODATA_START__ $MAPFILE | awk {'print $1'})
30RODATA_END=$(grep __RODATA_END__ $MAPFILE | awk {'print $1'})
31
32DATA_START=$(grep __DATA_START__ $MAPFILE | awk {'print $1'})
33DATA_END=$(grep __DATA_END__ $MAPFILE | awk {'print $1'})
34
35BSS_START=$(grep __BSS_START__ $MAPFILE | awk {'print $1'})
36BSS_END=$(grep __BSS_END__ $MAPFILE | awk {'print $1'})
37
38# Inject new sections to the base DTS
39
40echo "\
41/ {
42 memory_regions {
43 text {
44 str = \"Text\";
45 base = <0x0 ${TEXT_START}ULL>;
46 size = <0x0 (${TEXT_END}ULL - ${TEXT_START}ULL)>;
47 attr = <RD_MEM_NORMAL_CODE>;
48 };
49 rodata {
50 str = \"RO Data\";
51 base = <0x0 (${RODATA_START}ULL)>;
52 size = <0x0 (${RODATA_END}ULL - ${RODATA_START}ULL)>;
53 attr = <RD_MEM_NORMAL_RODATA>;
54 };
55 rwdata {
56 str = \"Data\";
57 base = <0x0 ${DATA_START}ULL>;
58 size = <0x0 (${DATA_END}ULL - ${DATA_START}ULL)>;
59 attr = <RD_MEM_NORMAL_DATA>;
60 };
61 bss {
62 str = \"BSS\";
63 base = <0x0 ${BSS_START}ULL>;
64 size = <0x0 (${BSS_END}ULL - ${BSS_START}ULL)>;
65 attr = <RD_MEM_NORMAL_BSS>;
66 };
67 };
68};" > "$EXTRA_DTS"
69
70cat "$ORIGINAL_DTS" "$EXTRA_DTS" > "$COMBINED_DTS"
71
72INCLUDES="-I spm/cactus
73 -I spm/ivy
74 -I spm/include
75 -I include/lib"
76
77cpp -x c -P -o "$PREPROCESSED_DTS" "$COMBINED_DTS" ${INCLUDES} -DAARCH64
78dtc -I dts -O dtb "$PREPROCESSED_DTS" > "$GENERATED_DTB"