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
|
#!/usr/bin/env bash
# Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of ARM nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# This script uses the following environment variables from the variant
#
# VARIANT - build variant name
# TOP_DIR - workspace root directory
# ARM_TF_PATH - for the fip tool / output images
# UBOOT_PATH - for mkimage / output images
# TARGET_BINS_PLATS - the platforms to create binaries for
# TARGET_ARM_TF_### - the arm-tf output directory, where ### is the arm-tf plat name
# TARGET_SCP_### - the scp output directory, where ### is the scp plat name
# TARGET_UBOOT_### - the uboot output directory, where ### is the boot plat name
# TARGET_UEFI_### - the uefi output directory, where ### is the uefi plat name.
# TARGET_BINS_UIMAGE_ADDRS - the uImage load addresses
# TARGET_BINS_UINITRD_ADDRS - the uInitrd load addresses
# TARGET_BINS_HAS_ANDROID - whether we have android enabled
# TARGET_BINS_HAS_OE - whether we have OE enabled
# TARGET_BINS_HAS_DTB_RAMDISK - whether create dtbs with ramdisk chosen node
# TARGET_BINS_RAMDISK_ADDR - address in RAM that ramdisk is loaded. Required if TARGET_BINS_HAS_DTB_RAMDISK=1
# LINUX_ARCH - the architecure to build the output for (arm or arm64)
# DEVTREE_LINUX_PATH - Path to Linux tree containing DT compiler
# LINUX_IMAGE_TYPE - Image or zImage (defaults to Image if not specified)
LINUX_IMAGE_TYPE=${LINUX_IMAGE_TYPE:-Image}
populate_variant()
{
local outdir=$1
local boot_type=$2
# copy ramdisk to the variant
if [ "$TARGET_BINS_HAS_OE" = "1" ]; then
if [ "$boot_type" = "uboot" ]; then
cp ${OUTDIR}/uInitrd-oe.$TARGET_BINS_UINITRD_ADDRS $outdir/ramdisk.img
else
cp ${OUTDIR}/ramdisk.img $outdir/ramdisk.img
fi
elif [ "$TARGET_BINS_HAS_BUSYBOX" = "1" ]; then
if [ "$boot_type" = "uboot" ]; then
cp ${OUTDIR}/uInitrd-busybox.$TARGET_BINS_UINITRD_ADDRS $outdir/ramdisk.img
else
cp ${OUTDIR}/ramdisk.img $outdir/ramdisk.img
fi
elif [ "$TARGET_BINS_HAS_ANDROID" = "1" ]; then
if [ "$boot_type" = "uboot" ]; then
cp ${OUTDIR}/uInitrd-android.$TARGET_BINS_UINITRD_ADDRS $outdir/ramdisk.img
else
cp ${TOP_DIR}/ramdisk.img $outdir/ramdisk.img
fi
fi
# copy the kernel Image and *.dtb to the variant
if [ "$TARGET_BINS_UIMAGE_ADDRS" != "" ]; then
for addr in $TARGET_BINS_UIMAGE_ADDRS; do
cp ${OUTDIR}/$LINUX_PATH/$VARIANT/uImage.$addr $outdir
done
else
cp ${OUTDIR}/$LINUX_PATH/$VARIANT/$LINUX_IMAGE_TYPE $outdir
fi
for ((i=0;i<${#DEVTREE_TREES[@]};++i)); do
if [ "$TARGET_BINS_HAS_DTB_RAMDISK" = "1" ]; then
chosen="-chosen"
fi
if [ "${DEVTREE_TREES_RENAME[i]}" == "" ]; then
newname=${DEVTREE_TREES[i]}.dtb
else
newname=${DEVTREE_TREES_RENAME[i]}
fi
dts_dir=${TOP_DIR}/$LINUX_PATH/arch/${LINUX_ARCH}/boot/dts/arm/
if [ ! -e ${TOP_DIR}/$LINUX_PATH/arch/${LINUX_ARCH}/boot/dts/arm/ ]; then
dts_dir=${TOP_DIR}/$LINUX_PATH/arch/${LINUX_ARCH}/boot/dts/
fi
cp ${dts_dir}/${DEVTREE_TREES[i]}${chosen}.dtb $outdir/${newname} 2>/dev/null || :
done
}
do_build()
{
if [ "$TARGET_BINS_BUILD_ENABLED" == "1" ]; then
echo "Build"
fi
}
do_clean()
{
if [ "$TARGET_BINS_BUILD_ENABLED" == "1" ]; then
echo "clean"
fi
}
append_chosen_node()
{
# $1 = dtb name
# $2 = ramdisk file
local ramdisk_end=$(($TARGET_BINS_RAMDISK_ADDR + $(wc -c < $2)))
local DTC=$TOP_DIR/$LINUX_PATH/scripts/dtc/dtc
local tmp=linux/tmp
local devtree_path=$TOP_DIR/$LINUX_PATH/arch/arm64/boot/dts/arm
local devtree=$devtree_path/$1
if [ ! -e $devtree_path ]; then
# take into account that the DTS dir added and "arm" sub-dir between 3.10 and 4.1
devtree_path=$TOP_DIR/$LINUX_PATH/arch/arm64/boot/dts
devtree=$devtree_path/$1
fi
if [ -e ${devtree}.dtb ]; then
cp ${devtree}.dtb ${tmp}.dtb
# Decode the DTB
${DTC} -Idtb -Odts -o${tmp}.dts ${devtree}.dtb
echo "" >> ${tmp}.dts
echo "/ {" >> ${tmp}.dts
echo " chosen {" >> ${tmp}.dts
echo " linux,initrd-start = <$TARGET_BINS_RAMDISK_ADDR>;" >> ${tmp}.dts
echo " linux,initrd-end = <${ramdisk_end}>;" >> ${tmp}.dts
echo " };" >> ${tmp}.dts
echo "};" >> ${tmp}.dts
# Recode the DTB
${DTC} -Idts -Odtb -o${devtree}-chosen.dtb ${tmp}.dts
# And clean up
rm ${tmp}.dts
else
echo ""
echo ""
echo "********************************************************************************"
echo "ERROR: Missing file: ${devtree}.dtb"
echo " Continuing to process other .dtb files"
echo "********************************************************************************"
echo ""
echo ""
fi
}
do_package()
{
if [ "$TARGET_BINS_BUILD_ENABLED" == "1" ]; then
# Create uImages and uInitrds
local uboot_mkimage=${TOP_DIR}/${UBOOT_PATH}/tools/mkimage
local common_flags="-A $LINUX_ARCH -O linux -C none"
pushd ${OUTDIR}/$LINUX_PATH
for addr in $TARGET_BINS_UIMAGE_ADDRS; do
${uboot_mkimage} ${common_flags} -T kernel -n Linux -a $addr -e $addr -n "Linux" -d $LINUX_IMAGE_TYPE uImage.$addr
done
popd
pushd ${OUTDIR}
if [ "$TARGET_BINS_HAS_ANDROID" = "1" ]; then
for addr in $TARGET_BINS_UINITRD_ADDRS; do
${uboot_mkimage} ${common_flags} -T ramdisk -n ramdisk -a $addr -e $addr -n "Android ramdisk" -d ${TOP_DIR}/ramdisk.img uInitrd-android.$addr
done
fi
if [ "$TARGET_BINS_HAS_OE" = "1" ]; then
mkdir -p oe
touch oe/initrd ; echo oe/initrd | cpio -ov > ramdisk.img
for addr in $TARGET_BINS_UINITRD_ADDRS; do
${uboot_mkimage} ${common_flags} -T ramdisk -n ramdisk -a $addr -e $addr -n "Dummy ramdisk" -d ramdisk.img uInitrd-oe.$addr
done
fi
if [ "$TARGET_BINS_HAS_BUSYBOX" = "1" ]; then
mkdir -p busybox
for addr in $TARGET_BINS_UINITRD_ADDRS; do
${uboot_mkimage} ${common_flags} -T ramdisk -n ramdisk -a $addr -e $addr -n "BusyBox ramdisk" -d ${OUTDIR}/ramdisk.img uInitrd-busybox.$addr
done
fi
popd
# Add chosen node for ramdisk to dtbs
if [ "$TARGET_BINS_HAS_DTB_RAMDISK" = "1" ]; then
pushd ${OUTDIR}
for ((i=0;i<${#DEVTREE_TREES[@]};++i)); do
item=${DEVTREE_TREES[i]}
if [ "$TARGET_BINS_HAS_ANDROID" = "1" ]; then
append_chosen_node ${item} ${TOP_DIR}/ramdisk.img
fi
if [ "$TARGET_BINS_HAS_OE" = "1" ]; then
append_chosen_node ${item} ramdisk.img
fi
if [ "$TARGET_BINS_HAS_BUSYBOX" = "1" ]; then
append_chosen_node ${item} ramdisk.img
fi
done
popd
fi
echo "Packaging target binaries $VARIANT";
# Create FIPs
for target in $TARGET_BINS_PLATS; do
local tf_out="TARGET_ARM_TF_"$target
local scp_out="TARGET_SCP_"$target
local uboot_out="TARGET_UBOOT_"$target
local uefi_out="TARGET_UEFI_"$target
local bl2_fip_param="--bl2 ${OUTDIR}/${!tf_out}/tf-bl2.bin"
local bl31_fip_param="--bl31 ${OUTDIR}/${!tf_out}/tf-bl31.bin"
local bl30_fip_param=
if [ "${!scp_out}" != "" ]; then
bl30_fip_param="--bl30 ${TOP_DIR}/${!scp_out}/bl30.bin"
fi
if [ "${!uboot_out}" != "" ]; then
# remove existing fip
local outdir=${OUTDIR}/${VARIANT}/uboot
local outfile=${outdir}/fip.bin
rm -f $outfile
mkdir -p ${outdir}
if [ "$ARM_TF_BUILD_ENABLED" == "1" ]; then
$TOP_DIR/$ARM_TF_PATH/tools/fip_create/fip_create --dump \
${bl2_fip_param} \
${bl31_fip_param} \
${bl30_fip_param} \
--bl33 ${OUTDIR}/${!uboot_out}/uboot.bin \
$outfile
cp ${OUTDIR}/${!tf_out}/tf-bl1.bin $outdir/bl1.bin
else
cp ${OUTDIR}/${!uboot_out}/uboot.bin ${OUTDIR}/${VARIANT}/uboot/$UBOOT_OUTPUT_FILENAME
fi
populate_variant $outdir uboot
fi
if [ "${!uefi_out}" != "" ]; then
# remove existing fip
local outdir=${OUTDIR}/${VARIANT}/uefi
local outfile=${outdir}/fip.bin
rm -f $outfile
mkdir -p ${outdir}
if [ "$ARM_TF_BUILD_ENABLED" == "1" ]; then
$TOP_DIR/$ARM_TF_PATH/tools/fip_create/fip_create --dump \
${bl2_fip_param} \
${bl31_fip_param} \
${bl30_fip_param} \
--bl33 ${OUTDIR}/${!uefi_out}/uefi.bin \
$outfile
cp ${OUTDIR}/${!tf_out}/tf-bl1.bin $outdir/bl1.bin
else
cp ${OUTDIR}/${!uefi_out}/uefi.bin ${OUTDIR}/${VARIANT}/uefi/$UEFI_OUTPUT_FILENAME
fi
populate_variant $outdir uefi
fi
done
# clean up unwanted artifacts left in output directory
pushd ${OUTDIR}
rm -f uInitrd-* || :
rm -f ramdisk*.img || :
rm -rf linux || :
rm -rf ${TARGET_BINS_PLATS} || :
rm -rf oe || :
rm -rf busybox || :
popd
fi
}
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $DIR/framework.sh $1 $2
|