forked from SolidRun/imx8dxl_build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runme.sh
executable file
·438 lines (365 loc) · 13.4 KB
/
runme.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
#!/bin/bash
### Options
: ${CROSS_COMPILE:=aarch64-linux-gnu-}
: ${SOC_REVISION:=A0}
: ${IMAGE_SIZE_MiB:=1000}
: ${GATEWAY_REVISION:=1.1}
### Versions
ATF_GIT_URI=https://github.com/nxp-imx/imx-atf
ATF_RELEASE=tags/lf-5.15.52-2.1.0
UBOOT_GIT_URI=https://github.com/nxp-imx/uboot-imx
UBOOT_RELEASE=tags/lf-5.15.52-2.1.0
MKIMAGE_GIT_URI=https://github.com/nxp-imx/imx-mkimage
MKIMAGE_RELEASE=tags/lf-5.15.52-2.1.0
SECO_HTTP_URI=https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/imx-seco-5.8.7.1.bin
SECO_RELEASE=5.8.7.1
SCFW_FILE=L5.15.52_2.1.0_SCFWKIT-1.14.0.tar.gz
SCFW_FILE_URI="https://www.nxp.com/webapp/Download?colCode=L5.15.52_2.1.0_SCFWKIT-1.14.0&appType=license"
SCFW_RELEASE=1.14.0
LINUX_GIT_URI=https://github.com/nxp-imx/linux-imx
LINUX_RELEASE=lf-5.15.52-2.1.0
SAFSDIO_FILE=saf-sdio_RFP1.0.4.tgz
SAFSDIO_FILE_URI="Roadlink BSP v0.15"
LLC_FILE=llc_RFP2.5.tgz
LLC_FILE_URI="Roadlink BSP v0.15"
###
ROOTDIR=`pwd`
COMPONENTS="atf uboot mkimage seco scfw linux safsdio llc"
mkdir -p build
dlfailed=0
for i in $COMPONENTS; do
if [[ ! -d ${ROOTDIR}/build/$i ]]; then
GIT_URI_VAR=${i^^}_GIT_URI
RELEASE_VAR=${i^^}_RELEASE
HTTP_URI_VAR=${i^^}_HTTP_URI
FILE_VAR=${i^^}_FILE
FILE_URI_VAR=${i^^}_FILE_URI
if [[ -n ${!GIT_URI_VAR} ]]; then
echo "Fetching $i from Git ..."
git clone "${!GIT_URI_VAR}" "${ROOTDIR}/build/$i"
if [ $? -ne 0 ]; then
echo "Warning: Failed to fetch $i!"
dlfailed=1
continue
elif [[ -n ${!RELEASE_VAR} ]]; then
cd "${ROOTDIR}/build/$i"
git checkout "${!RELEASE_VAR}"
if [ $? -ne 0 ]; then
echo "Warning: Failed to checkout $i release ${!RELEASE_VAR}!"
dlfailed=1
continue
fi
fi
fi
if [[ -n ${!HTTP_URI_VAR} ]]; then
mkdir "${ROOTDIR}/build/$i"
cd "${ROOTDIR}/build/$i"
wget "${!HTTP_URI_VAR}"
if [ $? -ne 0 ]; then
echo "Warning: Failed to fetch $i!"
cd "${ROOTDIR}"
rm -rf "${ROOTDIR}/build/$i"
dlfailed=1
continue
fi
fi
if [[ -n ${!FILE_VAR} ]]; then
if [[ -f ${ROOTDIR}/${!FILE_VAR} ]]; then
if [[ ${!FILE_VAR} =~ \.tgz$ ]]; then
tar -C "${ROOTDIR}/build" -xf "${ROOTDIR}/${!FILE_VAR}"
if [ $? -ne 0 ]; then
echo "Error: Failed to unpack \"${!FILE_VAR}\"!"
fi
if [[ $i == safsdio ]]; then
mv "${ROOTDIR}/build/saf-sdio" "${ROOTDIR}/build/safsdio"
fi
else
mkdir "${ROOTDIR}/build/$i"
cp -v "${ROOTDIR}/${!FILE_VAR}" "${ROOTDIR}/build/$i/"
fi
else
echo "Warning: Missing file ${!FILE_VAR}! Please download manually and place it next to this script."
if [[ -n ${!FILE_URI_VAR} ]]; then
echo "${!FILE_URI_VAR}"
fi
dlfailed=1
continue
fi
fi
# post-download processing
cd "${ROOTDIR}/build/$i/"
# scfw porting kit is multi-wrapped :(
if [[ $i == scfw ]]; then
tar --wildcards --strip-components=2 -xvf $SCFW_FILE "*.bin"
if [ $? -ne 0 ]; then
echo "Warning: Failed to extract scfw porting kit layer 1!"
dlfailed=1
cd "${ROOTDIR}"
rm -rf "${ROOTDIR}/build/$i"
continue
fi
fi
# unpack NXP PKGs
for NXPPKG in `ls *.bin 2>/dev/null`; do
chmod +x $NXPPKG
./$NXPPKG --auto-accept
if [ $? -ne 0 ]; then
echo "Warning: Failed to extract $NXPPKG!"
dlfailed=1
cd "${ROOTDIR}"
rm -rf "${ROOTDIR}/build/$i"
continue
fi
done
# scfw porting kit is multi-wrapped :(
if [[ $i == scfw ]]; then
find imx-scfw-porting-kit-${SCFW_RELEASE} -iname "scfw_export_mx8*.gz" -exec tar --strip-components 1 --one-top-level=scfw_export_mx8 -xzf {} \;
if [ $? -ne 0 ] || [[ ! -d scfw_export_mx8 ]]; then
echo "Warning: Failed to extract scfw porting kit layer 3!"
dlfailed=1
cd "${ROOTDIR}"
rm -rf "${ROOTDIR}/build/$i"
continue
fi
fi
if [[ -d ${ROOTDIR}/patches/$i ]]; then
for patch in "${ROOTDIR}/patches/$i"/*; do
echo "Applying $patch ..."
test -e .git && git am "$patch"
test -e .git || patch -p1 < $patch
if [ $? -ne 0 ]; then
echo "Warning: Failed to apply $patch!"
dlfailed=1
break
fi
done
fi
fi
done
# Particular tools
mkdir -p "${ROOTDIR}/tools"
cd "${ROOTDIR}/tools"
if [ ! -e gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2 ]; then
wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/8-2018q4/gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2
if [ $? -ne 0 ]; then
dlfailed=1
fi
fi
if [ ! -d gcc-arm-none-eabi-8-2018-q4-major ] && [ -f gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2 ]; then
tar -xf gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2
if [ $? -ne 0 ]; then
echo "Warning: Failed to unpack arm embedded cross toolchain!"
dlfailed=1
fi
fi
if [ $dlfailed -ne 0 ]; then
echo "Some downloads failed, aborting build."
exit 1
fi
### Compile
set -eu
set -o pipefail
# Copy SECO FW
cd "${ROOTDIR}/build/seco"
cp -v imx-seco-${SECO_RELEASE}/firmware/seco/mx8dxl${SOC_REVISION,,}-ahab-container.img "${ROOTDIR}/build/mkimage/iMX8DXL/"
cp -v imx-seco-${SECO_RELEASE}/firmware/seco/mx8dxl${SOC_REVISION,,}-ahab-container.img "${ROOTDIR}/build/uboot/ahab-container.img"
# Build SCFW
case ${SOC_REVISION,,} in
b0)
# B0 currently has no specific SCU Firmware variant, reuse A0.
SCFW_R=A0
;;
*)
SCFW_R=${SOC_REVISION^^}
;;
esac
cd "${ROOTDIR}/build/scfw/scfw_export_mx8"
make TOOLS="${ROOTDIR}/tools" R=${SCFW_R^^} B=evk D=0 M=0 dxl
cp -v build_mx8dxl_${SCFW_R,,}/scfw_tcm.bin "${ROOTDIR}/build/uboot/mx8dxl-evk-scfw-tcm.bin"
cp -v build_mx8dxl_${SCFW_R,,}/scfw_tcm.bin "${ROOTDIR}/build/mkimage/iMX8DXL/"
# Build ATF
cd "${ROOTDIR}/build/atf"
make -j$(nproc) CROSS_COMPILE="$CROSS_COMPILE" PLAT=imx8dxl bl31
cp -v build/imx8dxl/release/bl31.bin "${ROOTDIR}/build/mkimage/iMX8DXL/"
# Build u-boot
cd "${ROOTDIR}/build/uboot"
make CROSS_COMPILE="$CROSS_COMPILE" imx8dxl_v2x_defconfig
case ${GATEWAY_REVISION} in
1.0)
UBOOT_DEFAULT_FDT_FILE="imx8dxl-v2x.dtb"
;;
1.1|2.0)
UBOOT_DEFAULT_FDT_FILE="imx8dxl-v2x-v11.dtb"
;;
*)
echo "Specified invalid gateway revision \"${GATEWAY_REVISION}\"!"
exit 1
;;
esac
printf "CONFIG_DEFAULT_FDT_FILE=\"%s\"\n" "${UBOOT_DEFAULT_FDT_FILE}" >> .config
make -j$(nproc) CROSS_COMPILE="$CROSS_COMPILE"
cp -v u-boot.bin "${ROOTDIR}/build/mkimage/iMX8DXL/"
# Assemble bootable image
cd "${ROOTDIR}/build/mkimage"
make SOC=iMX8DXL REV=${SOC_REVISION^^} flash
mkdir -p ${ROOTDIR}/images
cp -v "${ROOTDIR}/build/mkimage/iMX8DXL/flash.bin" "${ROOTDIR}/images/uboot.bin"
echo "Finished compiling bootloader image."
# Build Linux
mkdir -p "${ROOTDIR}/build/linux-build"
cd "${ROOTDIR}/build/linux"
find "${ROOTDIR}/configs/linux" -type f | sort | xargs ./scripts/kconfig/merge_config.sh -O "${ROOTDIR}/build/linux-build" -m arch/arm64/configs/imx_v8_defconfig /dev/null
make -C "${ROOTDIR}/build/linux" O="${ROOTDIR}/build/linux-build" ARCH=arm64 CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig
cd "${ROOTDIR}/build/linux-build"
#make ARCH=arm64 CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
make ARCH=arm64 CROSS_COMPILE="${CROSS_COMPILE}" savedefconfig
make -j$(nproc) ARCH=arm64 CROSS_COMPILE="${CROSS_COMPILE}" dtbs Image modules
rm -rf "${ROOTDIR}/images/linux"
mkdir -p "${ROOTDIR}/images/linux/boot/extlinux"
cp -v arch/arm64/boot/dts/freescale/imx8dxl*.dtb "${ROOTDIR}/images/linux/boot/"
cp -v arch/arm64/boot/Image "${ROOTDIR}/images/linux/boot/"
cp -v System.map "${ROOTDIR}/images/linux/boot/"
cp -v .config "${ROOTDIR}/images/linux/boot/config"
make ARCH=arm64 CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH="${ROOTDIR}/images/linux/usr" modules_install
KRELEASE=`make kernelrelease`
cat > "${ROOTDIR}/images/linux/boot/extlinux/extlinux.conf" << EOF
label linux
linux ../Image
fdtdir ..
append root=/dev/mmcblk0p1 ro rootwait net.ifnames=0
EOF
# Build external Linux Headers package for compiling modules
cd "${ROOTDIR}/build/linux"
rm -rf "${ROOTDIR}/images/linux-headers"
mkdir -p ${ROOTDIR}/images/linux-headers
tempfile=$(mktemp)
find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > $tempfile
find arch/arm64/include include scripts -type f >> $tempfile
tar -c -f - -T $tempfile | tar -C "${ROOTDIR}/images/linux-headers" -xf -
cd "${ROOTDIR}/build/linux-build"
find arch/arm64/include .config Module.symvers include scripts -type f > $tempfile
tar -c -f - -T $tempfile | tar -C "${ROOTDIR}/images/linux-headers" -xf -
rm -f $tempfile
unset tempfile
cd "${ROOTDIR}/images/linux-headers"
tar cpf "${ROOTDIR}/images/linux-headers.tar" *
# Build SAF5x00 SDIO Driver
if [[ -d ${ROOTDIR}/build/safsdio ]]; then
cd "${ROOTDIR}/build/safsdio"
make -C "${ROOTDIR}/build/linux-build" CROSS_COMPILE="$CROSS_COMPILE" ARCH=arm64 M="$PWD" modules
install -v -m644 -D saf_sdio.ko "${ROOTDIR}/images/linux/usr/lib/modules/${KRELEASE}/kernel/v2x/saf_sdio.ko"
install -v -m644 -D include/saf_sdio.h "${ROOTDIR}/images/linux/usr/include/linux/saf_sdio.h"
fi
# Build SAF5x00 LLC Driver
if [[ -d ${ROOTDIR}/build/llc ]]; then
cd "${ROOTDIR}/build/llc/kernel/drivers/cohda/llc"
make -C "${ROOTDIR}/build/linux-build" CROSS_COMPILE="$CROSS_COMPILE" ARCH=arm64 M=$PWD BOARD=SRIMX8DXLSOM LLC_DEV_CNT=1 modules
install -v -m644 -D cw-llc.ko "${ROOTDIR}/images/linux/usr/lib/modules/${KRELEASE}/kernel/v2x/cw-llc.ko"
fi
# regenerate modules dependencies
depmod -b "${ROOTDIR}/images/linux/usr" -F "${ROOTDIR}/build/linux-build/System.map" ${KRELEASE}
# Generate a Debian rootfs
mkdir -p "${ROOTDIR}/build/debian"
cd "${ROOTDIR}/build/debian"
if [ ! -f rootfs.e2.orig ] || [[ ${ROOTDIR}/${BASH_SOURCE[0]} -nt rootfs.e2.orig ]]; then
rm -f rootfs.e2.orig
# bootstrap a first-stage rootfs
rm -rf stage1
fakeroot debootstrap --variant=minbase \
--arch=arm64 --components=main,contrib,non-free \
--foreign \
--include=apt-transport-https,bluez,busybox,ca-certificates,can-utils,command-not-found,chrony,curl,e2fsprogs,ethtool,fdisk,gpiod,gpsd,gpsd-tools,haveged,i2c-tools,ifupdown,iputils-ping,isc-dhcp-client,iw,initramfs-tools,libiio-utils,libnss-resolve,libpcap0.8,lm-sensors,locales,nano,net-tools,ntpdate,openssh-server,psmisc,python3-gps,python3-serial,rfkill,sudo,systemd-sysv,tio,usbutils,wget,wpasupplicant,xterm,xz-utils \
bullseye \
stage1 \
https://deb.debian.org/debian
# prepare init-script for second stage inside VM
cat > stage1/stage2.sh << EOF
#!/bin/sh
# run second-stage bootstrap
/debootstrap/debootstrap --second-stage
# mount pseudo-filesystems
mount -vt proc proc /proc
mount -vt sysfs sysfs /sys
# configure dns
cat /proc/net/pnp > /etc/resolv.conf
# set empty root password
passwd -d root
# update command-not-found db
apt-file update
update-command-not-found
# enable optional system services
systemctl enable gpsd
# populate fstab
printf "/dev/root / ext4 defaults 0 1\\n" > /etc/fstab
# enable systemd-networkd and re-configure DNS
systemctl enable systemd-networkd
systemctl enable systemd-resolved
ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
# delete self
rm -f /stage2.sh
# flush disk
sync
# power-off
reboot -f
EOF
chmod +x stage1/stage2.sh
# create empty partition image
dd if=/dev/zero of=rootfs.e2.orig bs=1 count=0 seek=${IMAGE_SIZE_MiB}M
# create filesystem from first stage
mkfs.ext2 -L rootfs -E root_owner=0:0 -d stage1 rootfs.e2.orig
# bootstrap second stage within qemu
qemu-system-aarch64 \
-m 1G \
-M virt \
-cpu cortex-a57 \
-smp 1 \
-netdev user,id=eth0 \
-device virtio-net-device,netdev=eth0 \
-drive file=rootfs.e2.orig,if=none,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-nographic \
-no-reboot \
-kernel "${ROOTDIR}/images/linux/boot/Image" \
-append "console=ttyAMA0 root=/dev/vda rootfstype=ext2 ip=dhcp rw init=/stage2.sh" \
:
# convert to ext4
tune2fs -O extents,uninit_bg,dir_index,has_journal rootfs.e2.orig
fi;
# Prepare final rootfs
cp rootfs.e2.orig rootfs.e2
# Add os-version to rootfs
gen_os_version() {
local TIMESTAMP
local IMAGE_SOURCE_COMMIT
IMAGE_BUILD_DATE="$(date +%Y%m%d)"
IMAGE_SOURCE_COMMIT="unknown"
if [ -d ${ROOTDIR} ]; then
IMAGE_SOURCE_COMMIT="$(git -C ${ROOTDIR} rev-parse --short HEAD)"
fi
printf "PRETTY_NAME=\"%s\"\n" "Debian GNU/Linux 11 (bullseye) SolidRun Fork for i.MX8DXL"
printf "NAME=\"%s\"\n" "Debian GNU/Linux (SolidRun)"
printf "VERSION_ID=\"%s\"\n" "11"
printf "VERSION=\"%s\"\n" "11 (bullseye)"
printf "VERSION_CODENAME=%s\n" "bullseye"
printf "ID=%s\n" "debian"
printf "HOME_URL=\"%s\"\n" "https://www.solid-run.com/"
printf "SUPPORT_URL=\"%s\"\n" "https://www.solid-run.com/contact-us/#technical-support"
printf "BUG_REPORT_URL=\"%s\"\n" "https://www.solid-run.com/contact-us/#technical-support"
printf "IMAGE_BUILD_DATE=\"%s\"\n" "${IMAGE_BUILD_DATE}"
printf "IMAGE_SOURCE_COMMIT=\"%s\"\n" "${IMAGE_SOURCE_COMMIT}"
}
gen_os_version > "${ROOTDIR}/build/os-version"
e2cp -G 0 -O 0 -P 644 "${ROOTDIR}/build/os-version" -d "${ROOTDIR}/build/debian/rootfs.e2:/etc"
# Add kernel to rootfs
find "${ROOTDIR}/images/linux" -type f -printf "%P\n" | e2cp -G 0 -O 0 -P 644 -s "${ROOTDIR}/images/linux" -d "${ROOTDIR}/build/debian/rootfs.e2:" -a
# package kernel individually
rm -f "${ROOTDIR}/images/linux/linux.tar*"
cd "${ROOTDIR}/images/linux"; tar -c --owner=root:0 -f "${ROOTDIR}/images/linux.tar" *; cd "${ROOTDIR}"
# Add overlay to rootfs
find "${ROOTDIR}/overlay" -type f -printf "%P\n" | e2cp -G 0 -O 0 -s "${ROOTDIR}/overlay" -d "${ROOTDIR}/build/debian/rootfs.e2:" -a
# assemble final disk image
rm -f "${ROOTDIR}/images/emmc.img"
dd if=/dev/zero of="${ROOTDIR}/images/emmc.img" bs=1 count=0 seek=$(($IMAGE_SIZE_MiB + 24))M
printf "o\nn\np\n1\n49152\n\na\nw\n" | fdisk "${ROOTDIR}/images/emmc.img"
dd of="${ROOTDIR}/images/emmc.img" if="${ROOTDIR}/build/debian/rootfs.e2" ibs=1M seek=24 obs=1M
echo "Finished generating disk image."