forked from ariaboard-com/rockchip_rk3568_linux_sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkfirmware.sh
executable file
·348 lines (316 loc) · 8.53 KB
/
mkfirmware.sh
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
#!/bin/bash
set -e
SCRIPT_DIR=$(dirname $(realpath $BASH_SOURCE))
TOP_DIR=$(realpath $SCRIPT_DIR/../../..)
cd $TOP_DIR
function unset_board_config_all()
{
local tmp_file=`mktemp`
grep -o "^export.*RK_.*=" `find $TOP_DIR/device/rockchip -name "Board*.mk" -type f` -h | sort | uniq > $tmp_file
source $tmp_file
rm -f $tmp_file
}
unset_board_config_all
source $TOP_DIR/device/rockchip/.BoardConfig.mk
ROCKDEV=$TOP_DIR/rockdev
PARAMETER=$TOP_DIR/device/rockchip/$RK_TARGET_PRODUCT/$RK_PARAMETER
if [ "${RK_OEM_DIR}x" != "x" ];then
OEM_DIR=$TOP_DIR/device/rockchip/oem/$RK_OEM_DIR
else
OEM_DIR=
fi
USER_DATA_DIR=$TOP_DIR/device/rockchip/userdata/$RK_USERDATA_DIR
MISC_IMG=$TOP_DIR/device/rockchip/rockimg/$RK_MISC
ROOTFS_IMG=$TOP_DIR/$RK_ROOTFS_IMG
ROOTFS_IMG_SOURCE=$TOP_DIR/buildroot/output/$RK_CFG_BUILDROOT/images/rootfs.$RK_ROOTFS_TYPE
RAMBOOT_IMG=$TOP_DIR/buildroot/output/$RK_CFG_RAMBOOT/images/ramboot.img
if [ -n "${RK_CFG_RECOVERY}" ]; then
RECOVERY_IMG=$TOP_DIR/buildroot/output/$RK_CFG_RECOVERY/images/recovery.img
else
RECOVERY_IMG=$ROCKDEV/recovery.img
fi
IDBLOADER_IMG=$TOP_DIR/u-boot/idbloader.img
if which fakeroot; then
FAKEROOT_TOOL="`which fakeroot`"
else
echo -e "Install fakeroot First."
echo -e " sudo apt-get install fakeroot"
exit -1
fi
OEM_FAKEROOT_SCRIPT=$ROCKDEV/oem.fs
USERDATA_FAKEROOT_SCRIPT=$ROCKDEV/userdata.fs
TRUST_IMG=$TOP_DIR/u-boot/trust.img
UBOOT_IMG=$TOP_DIR/u-boot/uboot.img
BOOT_IMG=$TOP_DIR/kernel/$RK_BOOT_IMG
LOADER=$TOP_DIR/u-boot/*_loader_v*.bin
SPL=$TOP_DIR/u-boot/*_loader_spl.bin
#SPINOR_LOADER=$TOP_DIR/u-boot/*_loader_spinor_v*.bin
MKIMAGE=$SCRIPT_DIR/mk-image.sh
mkdir -p $ROCKDEV
# Require buildroot host tools to do image packing.
#Move to mk-image.sh, for ubuntu and debian os not need
#if [ ! -d "$TARGET_OUTPUT_DIR" ]; then
# echo "Source buildroot/build/envsetup.sh"
#fi
# NOT support the grow partition
get_partition_size() {
echo $PARAMETER
PARTITIONS_PREFIX=`echo -n "CMDLINE: mtdparts=rk29xxnand:"`
while read line
do
if [[ $line =~ $PARTITIONS_PREFIX ]]
then
partitions=`echo $line | sed "s/$PARTITIONS_PREFIX//g"`
echo $partitions
break
fi
done < $PARAMETER
if [ -z $partitions ]
then
echo -e "\e[31m $PARAMETER parse no find string \"$PARTITIONS_PREFIX\" or The last line is not empty or other reason\e[0m"
return
fi
PART_NAME_NEED_TO_CHECK=""
IFS=,
for part in $partitions;
do
part_size=`echo $part | cut -d '@' -f1`
part_name=`echo $part | cut -d '(' -f2|cut -d ')' -f1`
[[ $part_size =~ "-" ]] && continue
part_size=$(($part_size))
part_size_bytes=$[$part_size*512]
case $part_name in
uboot|uboot_[ab])
uboot_part_size_bytes=$part_size_bytes
PART_NAME_NEED_TO_CHECK="$PART_NAME_NEED_TO_CHECK:$part_name"
;;
boot|boot_[ab])
boot_part_size_bytes=$part_size_bytes
PART_NAME_NEED_TO_CHECK="$PART_NAME_NEED_TO_CHECK:$part_name"
;;
recovery)
recovery_part_size_bytes=$part_size_bytes
PART_NAME_NEED_TO_CHECK="$PART_NAME_NEED_TO_CHECK:$part_name"
;;
rootfs|system_[ab])
rootfs_part_size_bytes=$part_size_bytes
PART_NAME_NEED_TO_CHECK="$PART_NAME_NEED_TO_CHECK:$part_name"
;;
oem)
oem_part_size_bytes=$part_size_bytes
PART_NAME_NEED_TO_CHECK="$PART_NAME_NEED_TO_CHECK:$part_name"
;;
esac
done
}
check_partition_size() {
while true
do
part_name=${PART_NAME_NEED_TO_CHECK##*:}
case $part_name in
uboot|uboot_[ab])
if [ $uboot_part_size_bytes -lt `du -b $UBOOT_IMG | awk '{print $1}'` ]
then
echo -e "\e[31m error: uboot image size exceed parameter! \e[0m"
return -1
fi
;;
boot|boot_[ab])
if [ $boot_part_size_bytes -lt `du -b $BOOT_IMG | awk '{print $1}'` ]
then
echo -e "\e[31m error: boot image size exceed parameter! \e[0m"
return -1
fi
;;
recovery)
if [ -f $RECOVERY_IMG ]
then
if [ $recovery_part_size_bytes -lt `du -b $RECOVERY_IMG | awk '{print $1}'` ]
then
echo -e "\e[31m error: recovery image size exceed parameter! \e[0m"
return -1
fi
fi
;;
rootfs|system_[ab])
if [ -f $ROOTFS_IMG ]
then
echo "mkupdate.sh will resize the rootfs partition."
fi
;;
esac
PART_NAME_NEED_TO_CHECK=${PART_NAME_NEED_TO_CHECK%:*}
if [ -z "$PART_NAME_NEED_TO_CHECK" ]; then
break
fi
done
}
if [ $RK_ROOTFS_IMG ]
then
if [ -f $ROOTFS_IMG_SOURCE ];then
ln -rsf $ROOTFS_IMG_SOURCE $ROOTFS_IMG
fi
if [ -f $ROOTFS_IMG ]
then
echo -n "create rootfs.img..."
ln -rsf $ROOTFS_IMG $ROCKDEV/rootfs.img
echo "done."
else
echo "warning: $ROOTFS_IMG not found!"
echo -e "\nplease set correct \e[31m RK_ROOTFS_IMG \e[0m in \e[31m device/rockchip/.BoardConfig.mk \e[0m\n"
fi
fi
if [ -f $PARAMETER ]
then
echo -n "create parameter..."
ln -rsf $PARAMETER $ROCKDEV/parameter.txt
echo "done."
else
echo -e "\e[31m error: $PARAMETER not found! \e[0m"
exit -1
fi
get_partition_size
if [ $RK_CFG_RECOVERY ]
then
if [ -f $RECOVERY_IMG ]
then
echo -n "create recovery.img..."
ln -rsf $RECOVERY_IMG $ROCKDEV/recovery.img
echo "done."
else
echo "warning: $RECOVERY_IMG not found!"
fi
fi
if [ $RK_MISC ]
then
if [ -f $MISC_IMG ]
then
echo -n "create misc.img..."
ln -rsf $MISC_IMG $ROCKDEV/misc.img
echo "done."
else
echo "warning: $MISC_IMG not found!"
fi
fi
if [ "${RK_OEM_BUILDIN_BUILDROOT}x" != "YESx" ]
then
if [ -d "$OEM_DIR" ]
then
echo "#!/bin/sh" > $OEM_FAKEROOT_SCRIPT
echo "set -e" >> $OEM_FAKEROOT_SCRIPT
if [ -d $OEM_DIR/www ]; then
echo "chown -R www-data:www-data $OEM_DIR/www" >> $OEM_FAKEROOT_SCRIPT
fi
if [ "$RK_OEM_FS_TYPE" = "ubi" ]; then
echo "$MKIMAGE $OEM_DIR $ROCKDEV/oem.img $RK_OEM_FS_TYPE ${RK_OEM_PARTITION_SIZE:-$oem_part_size_bytes} oem $RK_UBI_PAGE_SIZE $RK_UBI_BLOCK_SIZE" >> $OEM_FAKEROOT_SCRIPT
else
echo "$MKIMAGE $OEM_DIR $ROCKDEV/oem.img $RK_OEM_FS_TYPE" >> $OEM_FAKEROOT_SCRIPT
fi
chmod a+x $OEM_FAKEROOT_SCRIPT
$FAKEROOT_TOOL -- $OEM_FAKEROOT_SCRIPT
rm -f $OEM_FAKEROOT_SCRIPT
else
echo "warning: $OEM_DIR not found!"
fi
else
if [ -f "$TOP_DIR/buildroot/output/$RK_CFG_BUILDROOT/images/oem.img" ]; then
ln -sfr $TOP_DIR/buildroot/output/$RK_CFG_BUILDROOT/images/oem.img $ROCKDEV/oem.img
fi
fi
if [ $RK_USERDATA_DIR ]
then
if [ -d "$USER_DATA_DIR" ]
then
echo "#!/bin/sh" > $USERDATA_FAKEROOT_SCRIPT
echo "set -e" >> $USERDATA_FAKEROOT_SCRIPT
echo "$MKIMAGE $USER_DATA_DIR $ROCKDEV/userdata.img $RK_USERDATA_FS_TYPE" >> $USERDATA_FAKEROOT_SCRIPT
chmod a+x $USERDATA_FAKEROOT_SCRIPT
$FAKEROOT_TOOL -- $USERDATA_FAKEROOT_SCRIPT
rm -f $USERDATA_FAKEROOT_SCRIPT
else
echo "warning: $USER_DATA_DIR not found!"
fi
fi
if [ -f $UBOOT_IMG ]
then
echo -n "create uboot.img..."
ln -rsf $UBOOT_IMG $ROCKDEV/uboot.img
echo "done."
else
echo -e "\e[31m error: $UBOOT_IMG not found! \e[0m"
fi
if [ -f $IDBLOADER_IMG ]
then
echo -n "create idbloader.img..."
ln -s -f $IDBLOADER_IMG $ROCKDEV/idbloader.img
echo "done."
fi
if [ "$RK_UBOOT_FORMAT_TYPE" = "fit" ]; then
rm -f $ROCKDEV/trust.img
echo "uboot fotmat type is fit, so ignore trust.img..."
else
if [ -f $TRUST_IMG ]
then
echo -n "create trust.img..."
ln -rsf $TRUST_IMG $ROCKDEV/trust.img
echo "done."
else
echo -e "\e[31m error: $TRUST_IMG not found! \e[0m"
fi
fi
if [ -f $LOADER ]
then
echo -n "create loader..."
ln -rsf $LOADER $ROCKDEV/MiniLoaderAll.bin
echo "done."
elif [ -f $SPL ]
then
echo -n "create spl..."
ln -rsf $SPL $ROCKDEV/MiniLoaderAll.bin
echo "done."
else
echo -e "\e[31m error: $LOADER not found,or there are multiple loaders! \e[0m"
rm $LOADER || true
fi
#if [ -f $SPINOR_LOADER ]
#then
# echo -n "create spinor loader..."
# ln -rsf $SPINOR_LOADER $ROCKDEV/MiniLoaderAll_SpiNor.bin
# echo "done."
#else
# rm $SPINOR_LOADER_PATH 2>/dev/null
#fi
if [ $RK_BOOT_IMG ]
then
if [ -f $BOOT_IMG ]
then
echo -n "create boot.img..."
ln -rsf $BOOT_IMG $ROCKDEV/boot.img
echo "done."
else
echo "warning: $BOOT_IMG not found!"
fi
fi
if [ $RK_CFG_RAMBOOT ]
then
if [ -f $RAMBOOT_IMG ]
then
echo -n "create boot.img..."
ln -rsf $RAMBOOT_IMG $ROCKDEV/boot.img
echo "done."
else
echo "warning: $RAMBOOT_IMG not found!"
fi
fi
if [ "$RK_RAMDISK_SECURITY_BOOTUP" = "true" ];then
if [ -f $TOP_DIR/u-boot/boot.img ]
then
echo -n "Enable ramdisk security bootup, create boot.img..."
ln -rsf $TOP_DIR/u-boot/boot.img $ROCKDEV/boot.img
echo "done."
else
echo "warning: $TOP_DIR/u-boot/boot.img not found!"
fi
fi
check_partition_size
echo -e "\e[36m Image: image in rockdev is ready \e[0m"