-
Notifications
You must be signed in to change notification settings - Fork 1
/
runme.sh
executable file
·584 lines (497 loc) · 17.5 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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
#!/bin/bash
### Options
: ${CROSS_COMPILE:=aarch64-linux-gnu-}
: ${CROSS_COMPILE32:=arm-linux-gnueabihf-}
: ${SOC_REVISION:=B0}
: ${IMAGE_SIZE_MiB:=1000}
: ${GATEWAY_REVISION:=1.1}
: ${SOM_REVISION:=2.1}
# optee-os secure storage on emmc rpmb
# requires protected hardware-unique-key implemetation:
# - tee_otp_get_hw_unique_key
# Implemented by optee-os imx caam driver.
: ${OPTEE_STORAGE_PRIVATE_RPMB:=true}
# optee-os secure storage with insecure real-world fs
# requires monotonic counter implementation to be secure:
# - nv_counter_get_ree_fs
# - nv_counter_incr_ree_fs_to
# Not implemented.
: ${OPTEE_STORAGE_PRIVATE_REE:=false}
### Versions
ATF_GIT_URI=https://github.com/nxp-imx/imx-atf
ATF_RELEASE=tags/lf-5.15.71-2.2.2
UBOOT_GIT_URI=https://github.com/nxp-imx/uboot-imx
UBOOT_RELEASE=tags/lf-5.15.71-2.2.2
OPTEE_OS_GIT_URI=https://github.com/nxp-imx/imx-optee-os
OPTEE_OS_RELEASE=tags/lf-5.15.71-2.2.2
MKIMAGE_GIT_URI=https://github.com/nxp-imx/imx-mkimage
MKIMAGE_RELEASE=tags/lf-5.15.71-2.2.2
SECO_HTTP_URI=https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/imx-seco-5.9.0.bin
SECO_RELEASE=5.9.0
SCFW_FILE=IMX-SCFW-PORTING-KIT-1.15.0.tar.gz
SCFW_FILE_URI="https://www.nxp.com/webapp/Download?colCode=L6.1.22_2.0.0_SCFWKIT-1.15.0&appType=license"
SCFW_RELEASE=1.15.0
LINUX_GIT_URI=https://github.com/nxp-imx/linux-imx
LINUX_RELEASE=lf-5.15.71-2.2.2
SAFSDIO_FILE=saf-sdio_RFP1.0.4.tgz
SAFSDIO_FILE_URI="NXP SAF5400 BSP v0.15 (linux-roadlink_evk2.0-v0.15.tgz:bsp/v2x-src/saf5x00)"
LLC_FILE=llc_RFP2.5.tgz
LLC_FILE_URI="NXP SAF5400 BSP v0.15 (linux-roadlink_evk2.0-v0.15.tgz:bsp/v2x-src/saf5x00)"
###
ROOTDIR=`pwd`
COMPONENTS="atf uboot optee-os mkimage seco scfw linux safsdio llc"
mkdir -p build
dlfailed=0
for i in $COMPONENTS; do
if [[ ! -d ${ROOTDIR}/build/$i ]]; then
i_sane=${i//-/_}
GIT_URI_VAR=${i_sane^^}_GIT_URI
RELEASE_VAR=${i_sane^^}_RELEASE
HTTP_URI_VAR=${i_sane^^}_HTTP_URI
FILE_VAR=${i_sane^^}_FILE
FILE_URI_VAR=${i_sane^^}_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}!"
cd "${ROOTDIR}"
rm -rf "${ROOTDIR}/build/$i"
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
# safsdio and llc are optional
if [[ $i != safsdio ]] && [[ $i != llc ]]; then
dlfailed=1
fi
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
case ${SOC_REVISION,,} in
a0)
# seco knows a0 as a1.
SECO_R=a1
;;
*)
SECO_R=${SOC_REVISION,,}
;;
esac
cd "${ROOTDIR}/build/seco"
cp -v imx-seco-${SECO_RELEASE}/firmware/seco/mx8dxl${SECO_R}-ahab-container.img "${ROOTDIR}/build/mkimage/iMX8DXL/"
cp -v imx-seco-${SECO_RELEASE}/firmware/seco/mx8dxl${SECO_R}-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-sr-som-scfw-tcm.bin"
cp -v build_mx8dxl_${SCFW_R,,}/scfw_tcm.bin "${ROOTDIR}/build/mkimage/iMX8DXL/"
mkdir -p ${ROOTDIR}/images
cp -v build_mx8dxl_${SCFW_R,,}/scfw_tcm.bin "${ROOTDIR}/images/mx8dxl-sr-som-scfw-tcm.bin"
# Build ATF
cd "${ROOTDIR}/build/atf"
make PLAT=imx8dxl clean
make -j$(nproc) CROSS_COMPILE="$CROSS_COMPILE" PLAT=imx8dxl SPD=opteed 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}:${SOM_REVISION}" in
1.0:2.0)
UBOOT_DEFAULT_FDT_FILE="imx8dxl-v2x.dtb"
;;
1.1:2.0|2.0:2.0)
UBOOT_DEFAULT_FDT_FILE="imx8dxl-v2x-v11.dtb"
;;
1.1:2.1|2.0:2.1)
UBOOT_DEFAULT_FDT_FILE="imx8dxl-v2x-v11-som-v21.dtb"
;;
*)
echo "Specified invalid combination of gateway revision \"${GATEWAY_REVISION}\" and som revision \"${SOM_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/"
cp -v spl/u-boot-spl.bin "${ROOTDIR}/build/mkimage/iMX8DXL/"
# Build optee-os
do_build_opteeos() {
local PLATFORM=imx-mx8dxlevk
local TEE_CORE_LOG_LEVEL=2
rm -rf ${ROOTDIR}/images/optee
mkdir -p ${ROOTDIR}/images/optee
# build optee devkit
cd $ROOTDIR/build/optee-os/
rm -rf out
make -j$(nproc) \
ARCH=arm \
PLATFORM=${PLATFORM} \
CROSS_COMPILE64=${CROSS_COMPILE} \
CROSS_COMPILE32=${CROSS_COMPILE32} \
CFG_ARM64_core=y \
ta_dev_kit
# TODO: build external TAs
# build optee os
cd ${ROOTDIR}/build/optee-os/
# REE_FS OPTIONS:
# - CFG_RPMB_FS:
# Enable or disable RPMB Filesystem Feature.
# - CFG_RPMB_WRITE_KEY:
# Disabled by default to avoid accidental programming of key,
# enable if optee-os shall use rpmb for secure storage.
# Only required during first use.
if [ "x$OPTEE_STORAGE_PRIVATE_REE" = "xtrue" ]; then
REE_FS="CFG_REE_FS=y"
else
REE_FS="CFG_REE_FS=n"
fi
# RPMB_FS OPTIONS:
# - CFG_RPMB_FS:
# Enable or disable RPMB Filesystem Feature.
# - CFG_RPMB_FS_DEV_ID:
# Set MMC device ID of eMMC.
# - CFG_RPMB_WRITE_KEY:
# Disabled by default to avoid accidental programming of key,
# enable if optee-os shall use rpmb for secure storage.
# Only required during first use.
if [ "x$OPTEE_STORAGE_PRIVATE_RPMB" = "xtrue" ]; then
RPMB_FS="CFG_RPMB_FS=y CFG_RPMB_FS_DEV_ID=0 CFG_RPMB_WRITE_KEY=n"
else
RPMB_FS="CFG_RPMB_FS=n"
fi
# In-Tree Early TA's
# - avb: for optee_rpmb u-boot command
IN_TREE_EARLY_TAS="avb/023f8f1a-292a-432b-8fc4-de8471358067"
# External Early TA's
EXTERNAL_EARLY_TAS=""
make -j$(nproc) \
ARCH=arm \
PLATFORM=$PLATFORM \
CROSS_COMPILE64=${CROSS_COMPILE} \
CROSS_COMPILE32=${CROSS_COMPILE32} \
CFG_ARM64_core=y \
CFG_TEE_CORE_LOG_LEVEL=$TEE_CORE_LOG_LEVEL \
$REE_FS \
$RPMB_FS \
CFG_IN_TREE_EARLY_TAS="$IN_TREE_EARLY_TAS" \
CFG_EARLY_TA=y \
EARLY_TA_PATHS="$EXTERNAL_EARLY_TAS"
cp out/arm-plat-imx/core/tee-pager_v2.bin ${ROOTDIR}/images/optee
}
echo "Building optee-os"
do_build_opteeos
# Assemble bootable image
cd "${ROOTDIR}/build/mkimage"
cp -v ${ROOTDIR}/images/optee/tee-pager_v2.bin ./iMX8DXL/tee.bin
make SOC=iMX8DXL REV=${SECO_R^^} flash_spl
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
# wipe machine-id (regenerates during first boot)
echo uninitialized > /etc/machine-id
# 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
# fix errors
s=0
e2fsck -y rootfs.e2.orig || s=$?
if [ $s -ge 4 ]; then
echo "Error: Couldn't repair generated rootfs."
rm -f rootfs.e2.orig
exit 1
fi
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}/.git ]; 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
overlay_file() {
while IFS='' read -r -a path; do
mode=`stat --printf "%a\n" "${ROOTDIR}/overlay/${path}"`
e2cp -v -G 0 -O 0 -P $mode -s "${ROOTDIR}/overlay" -d "${ROOTDIR}/build/debian/rootfs.e2:" -a $path
done
}
overlay_link() {
while IFS=' ' read -r -a args; do
if [[ ${args[0]} = /* ]]; then
# absolute links
e2ln -v "${ROOTDIR}/build/debian/rootfs.e2:${args[0]}" "${args[1]}"
else
# relative links
basedir="`dirname ${args[1]}`"
e2ln -v "${ROOTDIR}/build/debian/rootfs.e2:${basedir}/${args[0]}" "${args[1]}"
fi
done
}
find "${ROOTDIR}/overlay" -type f -printf "%P\n" | overlay_file
find "${ROOTDIR}/overlay" -type l -printf "%l %P\n" | overlay_link
# 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."