/
install_uboot_imx8.sh
executable file
·358 lines (314 loc) · 11 KB
/
install_uboot_imx8.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
349
350
351
352
353
354
355
356
357
#!/bin/sh
#################################################################################
# Copyright 2018 Technexion Ltd.
#
# Author: Richard Hu <richard.hu@technexion.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#################################################################################
DRIVE=/dev/sdX
#platform related parameters
#PLATFORM="imx8mm"
#SOC_TARGET="iMX8MM"
#SOC_DIR="iMX8M"
#DTBS="fsl-imx8mq-evk"
#DTBS="pico-imx8m"
BRANCH_VER="lf-6.1.55_2.2.0" #branch used by imx-mkimage and imx-atf under meta-imx
ATF_BRANCH_VER="lf_v2.8"
MKIMAGE_SRC_GIT_ID='c4365450fb115d87f245df2864fee1604d97c06a' #refer to 'imx-mkimage_git.inc' in Yocto
ATF_SRC_GIT_ID='08e9d4eef2262c0dd072b4325e8919e06d349e02' #refer to 'imx-atf_2.8.bb' in Yocto
DDR_FW_VER="8.21" #refer to the name of 'firmware-imx-8m_8.x.bb'
FSL_MIRROR="https://www.nxp.com/lgfiles/NMG/MAD/YOCTO"
FIRMWARE_DIR="firmware_imx8"
MKIMAGE_DIR="imx-mkimage"
MKIMAGE_TARGET="flash_hdmi_spl_uboot"
SPL_ORI="spl/u-boot-spl.bin"
UBOOT_ORI="u-boot-nodtb.bin"
IMX_BOOT="flash.bin"
TWD=`pwd`
ATF_BOOT_UART_BASE="0x30890000"
setup_platform()
{
SOC=$( echo "${DTBS}" | cut -d'-' -f1 )
if [ ${SOC} = "imx8m" ] || [ ${SOC} = "imx8mq" ] ; then
PLATFORM="imx8mq"
SOC_TARGET="iMX8M"
SOC_DIR="iMX8M"
IMX_BOOT_SEEK="33"
elif [ ${SOC} = "imx8mm" ] ; then
PLATFORM="imx8mm"
SOC_TARGET="iMX8MM"
SOC_DIR="iMX8M"
IMX_BOOT_SEEK="33"
elif [ ${SOC} = "imx8mp" ] ; then
PLATFORM="imx8mp"
SOC_TARGET="iMX8MP"
SOC_DIR="iMX8M"
IMX_BOOT_SEEK="32"
elif [ ${SOC} = "imx8mn" ] ; then
PLATFORM="imx8mn"
SOC_TARGET="iMX8MN"
SOC_DIR="iMX8M"
IMX_BOOT_SEEK="32"
elif [ ${SOC} = "imx93" ] ; then
PLATFORM="imx93"
SOC_TARGET="iMX9"
SOC_DIR="iMX9"
IMX_BOOT_SEEK="32"
MKIMAGE_TARGET="flash_singleboot"
else
printf "Targest SOC isn't supported by this script\n"
exit 1
fi
}
install_firmware()
{
cd ${TWD}
#Get and Build NXP imx-mkimage tool
if [ ! -d ${MKIMAGE_DIR} ] ; then
git clone https://github.com/nxp-imx/imx-mkimage.git -b ${BRANCH_VER} || printf "Fails to fetch imx-mkimage source code \n"
cd imx-mkimage
git checkout -b ${BRANCH_VER}_local ${MKIMAGE_SRC_GIT_ID}
fi
cd ${TWD}
#Collect required firmware files to generate bootable binary
if [ ! -d ${FIRMWARE_DIR} ] ; then
mkdir ${FIRMWARE_DIR}
fi
cd ${FIRMWARE_DIR} && FWD=`pwd`
#Get, build and copy the ARM Trusted Firmware
if [ ! -d imx-atf ] ; then
git clone https://github.com/nxp-imx/imx-atf.git -b ${ATF_BRANCH_VER} || printf "Fails to fetch ATF source code \n"
cd imx-atf
git checkout -b ${BRANCH_VER}_local ${ATF_SRC_GIT_ID}
fi
PWD=$(pwd)
[ -n "${PWD##*imx-atf}" ] && cd imx-atf
if ( git diff-index --quiet HEAD -- plat/imx/imx8mm/imx8mm_bl31_setup.c ); then
if [ -z "${DTBS##*imx8mm-axon*}" ]; then
# AXON: Change UART2 base address to UART1 and released UART4 from M4
sed -i 's/(RDC_PDAP_UART4, D1R | D1W),/(RDC_PDAP_UART4, D0R | D0W),/g' plat/imx/imx8m/imx8mm/imx8mm_bl31_setup.c
rm build/${PLATFORM}/release/bl31.bin
ATF_BOOT_UART_BASE="0x30860000"
fi
else
if [ -n "${DTBS##*imx8mm-axon*}" ]; then
git checkout plat/imx/imx8mm/imx8mm_bl31_setup.c
rm build/${PLATFORM}/release/bl31.bin
fi
fi
if [ ! -f build/${PLATFORM}/release/bl31.bin ] ; then
rm -rf build
make PLAT=${PLATFORM} IMX_BOOT_UART_BASE=${ATF_BOOT_UART_BASE} bl31 || printf "Fails to build ATF firmware \n"
fi
if [ -f build/${PLATFORM}/release/bl31.bin ] ; then
printf "Copy build/${PLATFORM}/release/bl31.bin to $MKIMAGE_DIR \n"
cp build/${PLATFORM}/release/bl31.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
else
printf "Cannot find release/bl31.bin \n"
fi
#Get and copy the DDR and HDMI firmware
cd ${FWD}
if [ ! -d firmware-imx-${DDR_FW_VER} ] ; then
wget ${FSL_MIRROR}/firmware-imx-${DDR_FW_VER}.bin && \
chmod +x firmware-imx-${DDR_FW_VER}.bin && \
./firmware-imx-${DDR_FW_VER}.bin || \
printf "Fails to fetch DDR firmware \n"
fi
if [ -d firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys ] ; then
if [ ${SOC} = "imx8mp" ] ; then
cp firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys/lpddr4_pmu_train_1d_dmem_202006.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
cp firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys/lpddr4_pmu_train_1d_imem_202006.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
cp firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys/lpddr4_pmu_train_2d_dmem_202006.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
cp firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys/lpddr4_pmu_train_2d_imem_202006.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
elif [ ${SOC} = "imx93" ] ; then
cp firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys/lpddr4_imem_1d_v202201.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
cp firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys/lpddr4_dmem_1d_v202201.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
cp firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys/lpddr4_imem_2d_v202201.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
cp firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys/lpddr4_dmem_2d_v202201.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
else
cp firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys/lpddr4_pmu_train_1d_dmem.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
cp firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys/lpddr4_pmu_train_1d_imem.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
cp firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys/lpddr4_pmu_train_2d_dmem.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
cp firmware-imx-${DDR_FW_VER}/firmware/ddr/synopsys/lpddr4_pmu_train_2d_imem.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
fi
cp firmware-imx-${DDR_FW_VER}/firmware/hdmi/cadence/signed_hdmi_imx8m.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
else
printf "Cannot find DDR firmware \n"
fi
if [ "${SOC_DIR}" = "iMX9" ] ; then
if [ ! -d firmware-sentinel-0.11 ] ; then
wget https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/firmware-sentinel-0.11.bin
chmod +x firmware-sentinel-0.11.bin
./firmware-sentinel-0.11.bin
fi
cp firmware-sentinel-0.11/mx93a1-ahab-container.img ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
fi
}
install_uboot_dtb()
{
#Copy uboot binary
cd ${TWD}
if [ "${SOC_DIR}" = "iMX9" ] ; then
cp u-boot.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
elif [ -f u-boot-nodtb.bin ] ; then
cp u-boot-nodtb.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
else
printf "Cannot find u-boot-nodtb.bin. Please build u-boot first! \n"
fi
#Copy SPL binary
cd ${TWD}
if [ -f spl/u-boot-spl.bin ] ; then
cp spl/u-boot-spl.bin ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
else
printf "Cannot find spl/u-boot-spl.bin. Please build u-boot first! \n"
fi
#Copy device tree file
cd ${TWD}
for DTB in ${DTBS}
do
if [ -f arch/arm/dts/${DTB} ] ; then
cp arch/arm/dts/${DTB} ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}
else
printf "Cannot find arch/arm/dts/${DTB} . Please build u-boot first! \n"
fi
done
}
generate_imx_boot()
{
cd ${TWD}
#Before generating the flash.bin, transfer the mkimage generated by U-Boot to iMX8M folder
if [ -f tools/mkimage ] ; then
cp tools/mkimage ${TWD}/${MKIMAGE_DIR}/${SOC_DIR}/mkimage_uboot
else
printf "Cannot find tools/mkimage. Please build u-boot first! \n"
fi
#Generate bootable binary (This binary contains SPL and u-boot.bin) for flashing
cd ${MKIMAGE_DIR}
if [ "${SOC_DIR}" = "iMX9" ] ; then
make SOC=${SOC_TARGET} REV=A1 dtbs="${DTBS}" ${MKIMAGE_TARGET} && \
printf "Make target: ${MKIMAGE_TARGET} and generate flash.bin... \n" || printf "Fails to generate flash.bin... \n"
else
make SOC=${SOC_TARGET} dtbs="${DTBS}" ${MKIMAGE_TARGET} && \
printf "Make target: ${MKIMAGE_TARGET} and generate flash.bin... \n" || printf "Fails to generate flash.bin... \n"
fi
}
flash_imx_boot()
{
cd ${TWD}
if [ ! -b $DRIVE ]; then
echo "$DRIVE doesn't exist !!!"
exit
fi
sudo umount ${DRIVE}?
sleep 0.1
sudo dd if=${TWD}/${MKIMAGE_DIR}/${SOC_DIR}/${IMX_BOOT} of=${DRIVE} bs=1k seek=${IMX_BOOT_SEEK} oflag=dsync status=progress && \
printf "Flash flash.bin... \n" || printf "Fails to flash flash.bin... \n"
}
usage()
{
echo -e "\nUsage: install_uboot_imx8mq.sh
Optional parameters: [-d disk-path] [-b DTBS_name] [-t] [-c] [-h]"
echo "
* This script is used to download required firmware files, generate and flash bootable u-boot binary
*
* [-d disk-path]: specify the disk to flash u-boot binary, e.g., /dev/sdd
* [-b dtb_name]: specify the name of dtb, which will be included in FIT image
* [-t]: target u-boot binary is without HDMI firmware
* [-c]: clean temporary directory
* [-h]: help
For example:
i.mx8MM:
* PICO-IMX8MM with PICO-PI-IMX8 baseDTBS:
./install_uboot_imx8.sh -b imx8mm-pico-pi.dtb -b imx8mm-pico-wizard.dtb -d /dev/sdX
* EDM-G-IMX8MM with WB:
./install_uboot_imx8.sh -b imx8mm-edm-g-wb.dtb -d /dev/sdX
i.mx8MQ:
* EDM-IMX8MQ with EDM-WIZARD baseDTBS:
./install_uboot_imx8.sh -b imx8mq-edm-wizard.dtb -d /dev/sdX
* PICO-IMX8MQ with PICO-PI-IMX8 baseDTBS:
./install_uboot_imx8.sh -b imx8mq-pico-pi.dtb -b imx8mq-pico-wizard.dtb -d /dev/sdX
i.mx8MP:
* AXON-IMX8MP:
./install_uboot_imx8.sh -b imx8mp-axon.dtb -d /dev/sdX
* EDM-G-IMX8MP with WB/WIZARD:
./install_uboot_imx8.sh -b imx8mp-edm-g.dtb -d /dev/sdX
* SC-IMX8MP:
./install_uboot_imx8.sh -b imx8mp-sc.dtb -d /dev/sdX
* TEK-IMX8MP:
./install_uboot_imx8.sh -b imx8mp-tek.dtb -d /dev/sdX
* TEK-IMX8MP with flexspi boot (only generate flash.bin):
./install_uboot_imx8.sh -b imx8mp-tek.dtb -f -d /dev/null
* TEP-IMX8MP:
./install_uboot_imx8.sh -b imx8mp-tep.dtb -d /dev/sdX
* TEP-IMX8MP with flexspi boot (only generate flash.bin):
./install_uboot_imx8.sh -b imx8mp-tep.dtb -f -d /dev/null
i.MX8MN:
* EDM-G-IMX8MN with WB:
./install_uboot_imx8.sh -b imx8mn-edm-g.dtb -d /dev/sdX
i.MX9:
* AXON-IMX93:
./install_uboot_imx8.sh -b imx93-axon.dtb -d /dev/sdX
"
}
print_settings()
{
echo "*************************************************************"
echo "Before run this script, please build u-boot first!
"
echo "The disk path to flash u-boot: $DRIVE"
echo "The default DTB name: ${DTBS}"
echo "Make target: ${PLATFORM}"
echo "Make target: ${MKIMAGE_TARGET}"
echo "SOC platform: ${SOC}"
echo "*************************************************************
"
}
if [ $# -eq 0 ]; then
usage
exit 1
fi
while getopts "tcfhd:b:" OPTION
do
case $OPTION in
d)
DRIVE="$OPTARG"
;;
b)
DTBS="$DTBS $OPTARG"
;;
t)
MKIMAGE_TARGET='flash_spl_uboot';
;;
f)
MKIMAGE_TARGET='flash_evk_flexspi';
;;
c)
rm -rf ${FIRMWARE_DIR} ${MKIMAGE_DIR}
echo "Clean ${FIRMWARE_DIR} ${MKIMAGE_DIR}..."
exit
;;
?|h) usage
exit
;;
esac
done
DTBS=$(echo ${DTBS} | cut -c 1-)
if [ "$(id -u)" = "0" ]; then
echo "This script can not be run as root"
exit 1
fi
#if [ ! -b $DRIVE ]
#then
# echo Target block device $DRIVE does not exist
# usage
# exit 1
#fi
setup_platform
print_settings
install_firmware
install_uboot_dtb
generate_imx_boot
flash_imx_boot