forked from RobertCNelson/netinstall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmk_mmc.sh
executable file
·1668 lines (1409 loc) · 47.9 KB
/
mk_mmc.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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash -e
#
# Copyright (c) 2009-2017 Robert Nelson <robertcnelson@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# Latest can be found at:
# http://github.com/RobertCNelson/netinstall/blob/master/mk_mmc.sh
#REQUIREMENTS:
#uEnv.txt bootscript support
MIRROR="https://rcn-ee.com/repos"
BOOT_LABEL="BOOT"
PARTITION_PREFIX=""
unset USE_BETA_BOOTLOADER
unset USE_LOCAL_BOOT
unset LOCAL_BOOTLOADER
unset ADDON
unset FIRMWARE
unset KERNEL_DEB
GIT_VERSION=$(git rev-parse --short HEAD)
DIST=stretch
ARCH=armhf
DISTARCH="${DIST}-${ARCH}"
deb_distribution="debian"
preseed_file_name=""
DIR="$PWD"
TEMPDIR=$(mktemp -d)
is_element_of () {
testelt=$1
for validelt in $2 ; do
[ "$testelt" = "$validelt" ] && return 0
done
return 1
}
check_root () {
if ! [ "$(id -u)" = 0 ] ; then
echo "$0 must be run as sudo user or root"
exit 1
fi
}
check_for_command () {
if ! which "$1" > /dev/null ; then
echo -n "You're missing command $1"
NEEDS_COMMAND=1
if [ -n "$2" ] ; then
echo -n " (consider installing package $2)"
fi
echo
fi
}
detect_software () {
unset NEEDS_COMMAND
check_for_command mkfs.vfat dosfstools
check_for_command wget wget
check_for_command dpkg dpkg
check_for_command partprobe parted
check_for_command patch patch
check_for_command mkimage u-boot-tools
if [ "${NEEDS_COMMAND}" ] ; then
echo ""
echo "Your system is missing some dependencies"
echo "Ubuntu/Debian: sudo apt-get install wget dosfstools u-boot-tools parted"
echo "Fedora: as root: yum install wget dosfstools dpkg patch uboot-tools parted"
echo "Gentoo: emerge wget dosfstools dpkg u-boot-tools parted"
echo ""
exit
fi
unset test_sfdisk
test_sfdisk=$(LC_ALL=C sfdisk -v 2>/dev/null | grep 2.17.2 | awk '{print $1}')
if [ "x${test_sdfdisk}" = "xsfdisk" ] ; then
echo ""
echo "Detected known broken sfdisk:"
echo "See: https://github.com/RobertCNelson/netinstall/issues/20"
echo ""
exit
fi
unset wget_version
wget_version=$(LC_ALL=C wget --version | grep "GNU Wget" | awk '{print $3}' | awk -F '.' '{print $2}' || true)
case "${wget_version}" in
12|13)
#wget before 1.14 in debian does not support sni
echo "wget: [$(LC_ALL=C wget --version | grep \"GNU Wget\" | awk '{print $3}' || true)]"
echo "wget: [this version of wget does not support sni, using --no-check-certificate]"
echo "wget: [http://en.wikipedia.org/wiki/Server_Name_Indication]"
dl="wget --no-check-certificate"
;;
*)
dl="wget"
;;
esac
dl_continue="${dl} -c"
dl_quiet="${dl} --no-verbose"
}
local_bootloader () {
echo ""
echo "Using Locally Stored Device Bootloader"
echo "-----------------------------"
mkdir -p "${TEMPDIR}/dl/"
if [ "${spl_name}" ] ; then
cp "${LOCAL_SPL}" "${TEMPDIR}/dl/"
SPL=${LOCAL_SPL##*/}
echo "SPL Bootloader: ${SPL}"
fi
if [ "${boot_name}" ] ; then
cp "${LOCAL_BOOTLOADER}" "${TEMPDIR}/dl/"
UBOOT=${LOCAL_BOOTLOADER##*/}
echo "UBOOT Bootloader: ${UBOOT}"
fi
}
dl_bootloader () {
echo ""
echo "Downloading Device's Bootloader"
echo "-----------------------------"
minimal_boot="1"
mkdir -p "${TEMPDIR}/dl/${DISTARCH}"
mkdir -p "${DIR}/dl/${DISTARCH}"
${dl_quiet} --directory-prefix="${TEMPDIR}/dl/" "${conf_bl_http}/${conf_bl_listfile}"
if [ ! -f "${TEMPDIR}/dl/${conf_bl_listfile}" ] ; then
echo "error: can't connect to rcn-ee.net, retry in a few minutes..."
exit
fi
boot_version=$(cat "${TEMPDIR}/dl/${conf_bl_listfile}" | grep "VERSION:" | awk -F":" '{print $2}')
if [ "x${boot_version}" != "x${minimal_boot}" ] ; then
echo "Error: This script is out of date and unsupported..."
echo "Please Visit: https://github.com/RobertCNelson to find updates..."
exit
fi
if [ "${USE_BETA_BOOTLOADER}" ] ; then
ABI="ABX2"
else
ABI="ABI2"
fi
if [ "${spl_name}" ] ; then
SPL=$(cat "${TEMPDIR}/dl/${conf_bl_listfile}" | grep "${ABI}:${conf_board}:SPL" | awk '{print $2}')
${dl_quiet} --directory-prefix="${TEMPDIR}/dl/" "${SPL}"
SPL=${SPL##*/}
echo "SPL Bootloader: ${SPL}"
else
unset SPL
fi
if [ "${boot_name}" ] ; then
UBOOT=$(cat "${TEMPDIR}/dl/${conf_bl_listfile}" | grep "${ABI}:${conf_board}:BOOT" | awk '{print $2}')
${dl} --directory-prefix="${TEMPDIR}/dl/" "${UBOOT}"
UBOOT=${UBOOT##*/}
echo "UBOOT Bootloader: ${UBOOT}"
else
unset UBOOT
fi
}
dl_kernel_image () {
echo ""
echo "Downloading Device's Kernel Image"
echo "-----------------------------"
if [ "x${cmd_kernel_override}" = "xenable" ] ; then
unset kernel_selected
if [ "x${cmd_LTS41_KERNEL}" = "xenable" ] ; then
kernel_repo="LTS41"
kernel_selected="true"
fi
if [ "x${cmd_LTS44_KERNEL}" = "xenable" ] ; then
kernel_repo="LTS44"
kernel_selected="true"
fi
if [ "x${cmd_LTS49_KERNEL}" = "xenable" ] ; then
kernel_repo="LTS49"
kernel_selected="true"
fi
if [ "x${cmd_STABLE_KERNEL}" = "xenable" ] && [ "x${kernel_selected}" = "x" ] ; then
kernel_repo="STABLE"
kernel_selected="true"
fi
if [ "x${cmd_TESTING_KERNEL}" = "xenable" ] && [ "x${kernel_selected}" = "x" ] ; then
kernel_repo="TESTING"
kernel_selected="true"
fi
if [ "x${cmd_EXPERIMENTAL_KERNEL}" = "xenable" ] && [ "x${kernel_selected}" = "x" ] ; then
kernel_repo="EXPERIMENTAL"
kernel_selected="true"
fi
fi
if [ ! "${KERNEL_DEB}" ] ; then
${dl_quiet} --directory-prefix="${TEMPDIR}/dl/" "${MIRROR}/latest/${DISTARCH}/LATEST-${kernel_subarch}"
echo "-----------------------------"
echo "Kernel Options:"
cat "${TEMPDIR}/dl/LATEST-${kernel_subarch}"
echo "-----------------------------"
#echo "LTS41: --use-lts-4_1-kernel"
echo "LTS44: --use-lts-4_4-kernel"
echo "LTS49: --use-lts-4_9-kernel"
echo "STABLE: --use-stable-kernel"
echo "TESTING: --use-testing-kernel"
echo "EXPERIMENTAL: --use-experimental-kernel"
echo "-----------------------------"
FTP_DIR=$(cat "${TEMPDIR}/dl/LATEST-${kernel_subarch}" | grep "ABI:1 ${kernel_repo}" | awk '{print $3}')
uname_r="${FTP_DIR}"
ACTUAL_DEB_FILE=linux-image-${uname_r}_1${DIST}_${ARCH}.deb
${dl_continue} --directory-prefix="${DIR}/dl/${DISTARCH}" "${MIRROR}/${deb_distribution}/pool/main/l/linux-upstream/${ACTUAL_DEB_FILE}"
else
KERNEL=${external_deb_file}
#Remove all "\" from file name.
ACTUAL_DEB_FILE=$(echo "${external_deb_file}" | sed 's!.*/!!' | grep linux-image)
if [ -f "${DIR}/dl/${DISTARCH}/${ACTUAL_DEB_FILE}" ] ; then
rm -rf "${DIR}/dl/${DISTARCH}/${ACTUAL_DEB_FILE}" || true
fi
cp -v "${external_deb_file}" "${DIR}/dl/${DISTARCH}/"
fi
echo "Using Kernel: ${ACTUAL_DEB_FILE}"
}
remove_uboot_wrapper () {
echo "Note: NetInstall has u-boot header, removing..."
echo "-----------------------------"
dd if="${DIR}/dl/${DISTARCH}/${NETINSTALL}" bs=64 skip=1 of="${DIR}/dl/${DISTARCH}/initrd.gz"
echo "-----------------------------"
NETINSTALL="initrd.gz"
unset UBOOTWRAPPER
}
actually_dl_netinstall () {
${dl} --directory-prefix="${DIR}/dl/${DISTARCH}" "${HTTP_IMAGE}/${DIST}/main/installer-${ARCH}/${NETIMAGE}/images/${BASE_IMAGE}/${NETINSTALL}"
MD5SUM=$(md5sum "${DIR}/dl/${DISTARCH}/${NETINSTALL}" | awk '{print $1}')
if [ "${UBOOTWRAPPER}" ] ; then
remove_uboot_wrapper
fi
}
check_dl_netinstall () {
MD5SUM=$(md5sum "${DIR}/dl/${DISTARCH}/${NETINSTALL}" | awk '{print $1}')
if [ "x${TEST_MD5SUM}" != "x${MD5SUM}" ] ; then
echo "Note: NetInstall md5sum has changed: ${MD5SUM}"
echo "-----------------------------"
rm -f "${DIR}/dl/${DISTARCH}/${NETINSTALL}" || true
actually_dl_netinstall
else
if [ "${UBOOTWRAPPER}" ] ; then
remove_uboot_wrapper
fi
fi
}
dl_netinstall_image () {
echo ""
echo "Downloading NetInstall Image"
echo "-----------------------------"
##FIXME: "network-console" support...
debian_boot="netboot"
. "${DIR}/lib/distro.conf"
if [ -f "${DIR}/dl/${DISTARCH}/${NETINSTALL}" ] ; then
check_dl_netinstall
else
actually_dl_netinstall
fi
echo "md5sum of NetInstall: ${MD5SUM}"
}
boot_uenv_txt_template () {
#Start with a blank state:
echo "#Normal Boot" > "${TEMPDIR}/bootscripts/normal.cmd"
echo "#Debian Installer only Boot" > "${TEMPDIR}/bootscripts/netinstall.cmd"
drm_device_identifier=${drm_device_identifier:-"HDMI-A-1"}
uboot_fdt_variable_name=${uboot_fdt_variable_name:-"fdtfile"}
conf_bootcmd=${conf_bootcmd:-"bootz"}
kernel=${kernel:-"/boot/vmlinuz-current"}
initrd=${initrd:-"/boot/initrd.img-current"}
if [ "x${di_serial_mode}" = "xenable" ] ; then
xyz_message="echo; echo Installer for [${DISTARCH}] is using the Serial Interface; echo;"
else
xyz_message="echo; echo Installer for [${DISTARCH}] is using the Video Interface; echo Use [--serial-mode] to force Installing over the Serial Interface; echo;"
fi
cat >> "${TEMPDIR}/bootscripts/normal.cmd" <<-__EOF__
#fdtfile=${dtb}
##Video: [ls /sys/class/drm/]
##Docs: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/fb/modedb.txt
##Uncomment to override:
#kms_force_mode=video=${drm_device_identifier}:1024x768@60e
console=SERIAL_CONSOLE
mmcroot=FINAL_PART ro
mmcrootfstype=FINAL_FSTYPE rootwait fixrtc
loadximage=${conf_fileload} mmc \${bootpart} ${conf_loadaddr} ${kernel}
loadxfdt=${conf_fileload} mmc \${bootpart} ${conf_fdtaddr} /boot/dtbs/current/\${fdtfile}
loadxrd=${conf_fileload} mmc \${bootpart} ${conf_initrdaddr} ${initrd}; setenv initrd_size \${filesize}
loadall=run loadximage; run loadxfdt; run loadxrd;
optargs=VIDEO_CONSOLE
mmcargs=setenv bootargs console=\${console} \${optargs} \${kms_force_mode} root=\${mmcroot} rootfstype=\${mmcrootfstype}
uenvcmd=run loadall; run mmcargs; ${conf_bootcmd} ${conf_loadaddr} ${conf_initrdaddr}:\${initrd_size} ${conf_fdtaddr}
__EOF__
cat >> "${TEMPDIR}/bootscripts/netinstall.cmd" <<-__EOF__
#fdtfile=${dtb}
##Video: [ls /sys/class/drm/]
##Docs: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/fb/modedb.txt
##Uncomment to override:
#kms_force_mode=video=${drm_device_identifier}:1024x768@60e
console=DICONSOLE
mmcroot=/dev/ram0 rw
loadximage=${conf_fileload} mmc \${bootpart} ${conf_loadaddr} ${kernel}
loadxfdt=${conf_fileload} mmc \${bootpart} ${conf_fdtaddr} /boot/dtbs/current/\${fdtfile}
loadxrd=${conf_fileload} mmc \${bootpart} ${conf_initrdaddr} ${initrd}; setenv initrd_size \${filesize}
loadall=run loadximage; run loadxfdt; run loadxrd;
xyz_message=${xyz_message}
optargs=${conf_optargs}
mmcargs=setenv bootargs console=\${console} \${optargs} \${kms_force_mode} root=\${mmcroot}
uenvcmd=run xyz_message; run loadall; run mmcargs; ${conf_bootcmd} ${conf_loadaddr} ${conf_initrdaddr}:\${initrd_size} ${conf_fdtaddr}
__EOF__
if [ ! "${uboot_fdt_auto_detection}" ] ; then
sed -i -e 's:#fdtfile:fdtfile:g' "${TEMPDIR}"/bootscripts/*.cmd
fi
if [ "${uboot_fdt_variable_name}" ] ; then
sed -i -e 's:fdtfile:'$uboot_fdt_variable_name':g' "${TEMPDIR}"/bootscripts/*.cmd
fi
if [ "x${drm_read_edid_broken}" = "xenable" ] ; then
sed -i -e 's:#kms_force_mode:kms_force_mode:g' "${TEMPDIR}"/bootscripts/*.cmd
fi
if [ "x${di_serial_mode}" = "xenable" ] ; then
sed -i -e 's:optargs=VIDEO_CONSOLE::g' "${TEMPDIR}/bootscripts/normal.cmd"
fi
}
tweak_boot_scripts () {
unset KMS_OVERRIDE
ALL="*.cmd"
NET="netinstall.cmd"
FINAL="normal.cmd"
#Set the Serial Console
sed -i -e 's:SERIAL_CONSOLE:'$SERIAL_CONSOLE':g' "${TEMPDIR}"/bootscripts/${ALL}
if [ "x${di_kms_mode}" = "xenable" ] && [ ! "x${di_serial_mode}" = "xenable" ] ; then
#optargs=VIDEO_CONSOLE
sed -i -e 's:VIDEO_CONSOLE:console=tty0:g' "${TEMPDIR}"/bootscripts/${ALL}
#Debian Installer console
sed -i -e 's:DICONSOLE:tty0:g' "${TEMPDIR}/bootscripts/${NET}"
fi
if [ "x${di_serial_mode}" = "xenable" ] ; then
echo "NetInstall: Setting up to use Serial Port: [${SERIAL}]"
#In pure serial mode, remove all traces of VIDEO
sed -i -e 's:VIDEO_DISPLAY ::g' "${TEMPDIR}/bootscripts/${NET}"
#Debian Installer console
sed -i -e 's:DICONSOLE:'$SERIAL_CONSOLE':g' "${TEMPDIR}/bootscripts/${NET}"
sed -i -e 's:kms_force_mode=:#kms_force_mode=:g' "${TEMPDIR}/bootscripts/${NET}"
#Unlike the debian-installer, normal boot will boot fine with the display enabled...
if [ "x${di_kms_mode}" = "xenable" ] ; then
#optargs=VIDEO_CONSOLE
sed -i -e 's:VIDEO_CONSOLE:console=tty0:g' "${TEMPDIR}/bootscripts/${FINAL}"
fi
fi
}
setup_bootscripts () {
mkdir -p "${TEMPDIR}/bootscripts/"
boot_uenv_txt_template
tweak_boot_scripts
}
extract_base_initrd () {
echo "NetInstall: Extracting Base ${NETINSTALL}"
cd "${TEMPDIR}/initrd-tree" || exit
zcat "${DIR}/dl/${DISTARCH}/${NETINSTALL}" | cpio -i -d
dpkg -x "${DIR}/dl/${DISTARCH}/${ACTUAL_DEB_FILE}" "${TEMPDIR}/initrd-tree"
cd "${DIR}/" || exit
}
git_failure () {
echo "Unable to pull/clone git tree"
exit
}
dl_linux_firmware () {
echo ""
echo "Clone/Pulling linux-firmware.git"
echo "-----------------------------"
if [ ! -f "${DIR}/dl/linux-firmware/.git/config" ] ; then
cd "${DIR}/dl/" || exit
if [ -d "${DIR}/dl/linux-firmware/" ] ; then
rm -rf "${DIR}/dl/linux-firmware/" || true
fi
git clone git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git || git_failure
else
cd "${DIR}/dl/linux-firmware" || exit
git pull || git_failure
fi
cd "${DIR}/" || exit
}
dl_device_firmware () {
mkdir -p "${TEMPDIR}/firmware/"
DL_WGET="${dl_quiet} --directory-prefix=${TEMPDIR}/firmware/"
if [ "${need_ti_connectivity_firmware}" ] ; then
dl_linux_firmware
echo "-----------------------------"
echo "Adding Firmware for onboard WiFi/Bluetooth module"
cp -rv "${DIR}/dl/linux-firmware/ti-connectivity" "${TEMPDIR}/firmware/"
echo "-----------------------------"
fi
if [ "x${conf_board}" = "xwandboard" ] ; then
dl_linux_firmware
echo "-----------------------------"
echo "Adding Firmware for onboard WiFi/Bluetooth module"
echo "-----------------------------"
mkdir -p "${TEMPDIR}/firmware/brcm/"
if [ -f "${DIR}/dl/linux-firmware/brcm/brcmfmac4329-sdio.bin" ] ; then
cp -v "${DIR}/dl/linux-firmware/brcm/brcmfmac4329-sdio.bin" "${TEMPDIR}/firmware/brcm/brcmfmac4329-sdio.bin"
fi
if [ -f "${DIR}/dl/linux-firmware/brcm/brcmfmac4330-sdio.bin" ] ; then
cp -v "${DIR}/dl/linux-firmware/brcm/brcmfmac4330-sdio.bin" "${TEMPDIR}/firmware/brcm/brcmfmac4330-sdio.bin"
fi
wget_brcm="${dl_quiet} --directory-prefix=${TEMPDIR}/firmware/brcm/"
http_brcm="https://rcn-ee.com/repos/git/meta-fsl-arm-extra/recipes-bsp/broadcom-nvram-config/files/wandboard"
${wget_brcm} "${http_brcm}/brcmfmac4329-sdio.txt"
${wget_brcm} "${http_brcm}/brcmfmac4330-sdio.txt"
fi
if [ "x${conf_board}" = "xudoo" ] ; then
dl_linux_firmware
echo "-----------------------------"
echo "Adding Firmware for onboard WiFi/Bluetooth module"
echo "-----------------------------"
mkdir -p "${TEMPDIR}/firmware/"
if [ -f "${DIR}/dl/linux-firmware/rt2870.bin" ] ; then
cp -v "${DIR}/dl/linux-firmware/rt2870.bin" "${TEMPDIR}/firmware/rt2870.bin"
echo "-----------------------------"
fi
fi
case "${dtb}" in
tegra124-jetson-tk1.dtb)
dl_linux_firmware
echo "-----------------------------"
echo "Adding NVIDIA firmware:"
cp -rv "${DIR}/dl/linux-firmware/nvidia" "${TEMPDIR}/firmware/"
mkdir -p "${TEMPDIR}/firmware/rtl_nic/"
cp -v "${DIR}/dl/linux-firmware/rtl_nic/rtl8168g-2.fw" "${TEMPDIR}/firmware/rtl_nic"
echo "-----------------------------"
;;
esac
}
initrd_add_firmware () {
DL_WGET="${dl_quiet} --directory-prefix=${TEMPDIR}/firmware/"
echo ""
echo "NetInstall: Adding Firmware"
echo "-----------------------------"
echo "Adding: Firmware from linux-firmware.git"
echo "-----------------------------"
dl_linux_firmware
#Atheros:
cp "${DIR}"/dl/linux-firmware/ath3k-1.fw "${TEMPDIR}/initrd-tree/lib/firmware/"
cp -r "${DIR}/dl/linux-firmware/ar3k/" "${TEMPDIR}/initrd-tree/lib/firmware/"
cp "${DIR}/dl/linux-firmware/carl9170-1.fw" "${TEMPDIR}/initrd-tree/lib/firmware/"
cp "${DIR}/dl/linux-firmware/htc_9271.fw" "${TEMPDIR}/initrd-tree/lib/firmware/"
#Libertas
cp -r "${DIR}/dl/linux-firmware/libertas/" "${TEMPDIR}/initrd-tree/lib/firmware/"
#Ralink
cp -r "${DIR}"/dl/linux-firmware/rt*.bin "${TEMPDIR}/initrd-tree/lib/firmware/"
#Realtek
cp -r "${DIR}/dl/linux-firmware/rtlwifi/" "${TEMPDIR}/initrd-tree/lib/firmware/"
echo "-----------------------------"
}
initrd_cleanup () {
echo "NetInstall: Removing Optional Stuff to Save RAM Space"
echo "NetInstall: Original size [$(du -ch ${TEMPDIR}/initrd-tree/ | grep total)]"
#Cleanup some of the extra space..
rm -f "${TEMPDIR}"/initrd-tree/boot/*-${KERNEL} || true
rm -rf "${TEMPDIR}"/initrd-tree/lib/modules/*-versatile/ || true
rm -rf "${TEMPDIR}"/initrd-tree/lib/modules/*-omap || true
rm -rf "${TEMPDIR}"/initrd-tree/lib/modules/*-mx5 || true
rm -rf "${TEMPDIR}"/initrd-tree/lib/modules/*-generic || true
rm -rf "${TEMPDIR}"/initrd-tree/lib/firmware/*-versatile/ || true
#jessie:
rm -rf "${TEMPDIR}"/initrd-tree/lib/modules/*-armmp || true
echo "NetInstall: Final size [$(du -ch ${TEMPDIR}/initrd-tree/ | grep total)]"
}
neuter_flash_kernel () {
cp -v "${DIR}/lib/flash_kernel/rcn-ee.db" "${TEMPDIR}/initrd-tree/etc/rcn-ee.db"
cat > "${TEMPDIR}/initrd-tree/usr/lib/post-base-installer.d/06neuter_flash_kernel" <<-__EOF__
#!/bin/sh -ex
#BusyBox: http://linux.die.net/man/1/busybox
apt-install linux-base || true
#work around: https://anonscm.debian.org/cgit/d-i/flash-kernel.git/commit/functions?id=808a0457400a1b301f2f61a4939e4a6f777a1beb
apt-install initramfs-tools || true
mkdir -p /target/lib/modules/\$(uname -r)/
cp -rf /lib/modules/\$(uname -r)/ /target/lib/modules/\$(uname -r)/
#ubuntu:
#Nov 20 23:19:20 in-target: flash-kernel: installing version 4.4.33-armv7-x13
#Nov 20 23:19:21 in-target: find: ��‘/lib/firmware/4.4.33-armv7-x13/device-tree/��’
#Nov 20 23:19:21 in-target: : No such file or directory
#Nov 20 23:19:21 flash-kernel-installer: error: flash-kernel failed
#Nov 20 23:19:21 main-menu[897]: WARNING **: Configuring 'flash-kernel-installer' failed with error code 1
#Nov 20 23:19:21 main-menu[897]: WARNING **: Menu item 'flash-kernel-installer' failed.
mkdir -p /target/lib/firmware/\$(uname -r)/device-tree/
cp -rf /boot/dtbs/\$(uname -r)/*.dtb /target/lib/firmware/\$(uname -r)/device-tree/
chroot /target /bin/bash usr/sbin/update-initramfs -ck \$(uname -r)
if [ -f /target/usr/share/flash-kernel/db/all.db ] ; then
rm /target/usr/share/flash-kernel/db/all.db || true
fi
mkdir -p /target/usr/share/flash-kernel/db/ || true
cp /etc/rcn-ee.db /target/usr/share/flash-kernel/db/rcn-ee.db
if [ -f /target/etc/initramfs/post-update.d/flash-kernel ] ; then
rm /target/etc/initramfs/post-update.d/flash-kernel || true
fi
if [ -f /target/etc/kernel/postinst.d/zz-flash-kernel ] ; then
rm /target/etc/kernel/postinst.d/zz-flash-kernel || true
fi
if [ -f /target/etc/kernel/postrm.d/zz-flash-kernel ] ; then
rm /target/etc/kernel/postrm.d/zz-flash-kernel || true
fi
mkdir -p /target/etc/dpkg/dpkg.cfg.d/ || true
echo "# neuter flash-kernel" > /target/etc/dpkg/dpkg.cfg.d/01_noflash_kernel
echo "path-exclude=/usr/share/flash-kernel/db/all.db" >> /target/etc/dpkg/dpkg.cfg.d/01_noflash_kernel
echo "path-exclude=/etc/initramfs/post-update.d/flash-kernel" >> /target/etc/dpkg/dpkg.cfg.d/01_noflash_kernel
echo "path-exclude=/etc/kernel/postinst.d/zz-flash-kernel" >> /target/etc/dpkg/dpkg.cfg.d/01_noflash_kernel
echo "path-exclude=/etc/kernel/postrm.d/zz-flash-kernel" >> /target/etc/dpkg/dpkg.cfg.d/01_noflash_kernel
echo "" >> /target/etc/dpkg/dpkg.cfg.d/01_noflash_kernel
__EOF__
chmod a+x "${TEMPDIR}/initrd-tree/usr/lib/post-base-installer.d/06neuter_flash_kernel"
}
finish_installing_device () {
cat > "${TEMPDIR}/initrd-tree/usr/lib/finish-install.d/08rcn-ee-finish-installing-device" <<-__EOF__
#!/bin/sh -e
cp /usr/bin/finish-install.sh /target/usr/bin/finish-install.sh
chmod a+x /target/usr/bin/finish-install.sh
mkdir -p /target/boot/uboot || true
#Some devices may have mmc cards in both slots...
unset got_boot_drive
if [ ! \${got_boot_drive} ] ; then
if [ -b /dev/mmcblk0p1 ] ; then
mount /dev/mmcblk0p1 /target/boot/uboot
if [ -f /target/boot/uboot/SOC.sh ] ; then
got_boot_drive=1
echo "/dev/mmcblk0" > /target/boot/uboot/bootdrive
else
umount /target/boot/uboot
fi
fi
fi
if [ ! \${got_boot_drive} ] ; then
if [ -b /dev/mmcblk1p1 ] ; then
mount /dev/mmcblk1p1 /target/boot/uboot
if [ -f /target/boot/uboot/SOC.sh ] ; then
got_boot_drive=1
echo "/dev/mmcblk1" > /target/boot/uboot/bootdrive
else
umount /target/boot/uboot
fi
fi
fi
if [ ! \${got_boot_drive} ] ; then
if [ -b /dev/mmcblk2p1 ] ; then
mount /dev/mmcblk2p1 /target/boot/uboot
if [ -f /target/boot/uboot/SOC.sh ] ; then
got_boot_drive=1
echo "/dev/mmcblk2" > /target/boot/uboot/bootdrive
else
umount /target/boot/uboot
fi
fi
fi
if [ -d /lib/firmware/ ] ; then
cp -rf /lib/firmware/ /target/lib/ || true
fi
mount -o bind /sys /target/sys
#Needed by finish-install.sh to determine root file system location
cat /proc/mounts > /target/boot/uboot/mounts
mkdir -p /target/etc/hwpack/
cp /etc/hwpack/SOC.sh /target/etc/hwpack/
cp /etc/hwpack/SOC.sh /target/boot/
chroot /target /bin/bash /usr/bin/finish-install.sh
cp /zz-uenv_txt /target/etc/kernel/postinst.d/
chmod +x /target/etc/kernel/postinst.d/zz-uenv_txt
rm -f /target/mounts || true
cat /proc/mounts > /target/boot/uboot/backup/proc_mounts
cat /var/log/syslog > /target/boot/uboot/backup/syslog.log
umount /target/sys
sync
umount /target/boot/uboot
rm -rf /target/usr/bin/finish-install.sh || true
__EOF__
chmod a+x "${TEMPDIR}/initrd-tree/usr/lib/finish-install.d/08rcn-ee-finish-installing-device"
}
setup_parition_recipe () {
#This (so far) has been leaving the first Partition Alone...
if [ "x${no_swap}" = "xenabled" ] ; then
cat > "${TEMPDIR}/initrd-tree/partition_recipe" <<-__EOF__
500 1000 -1 ext4
method{ format } format{ }
use_filesystem{ } filesystem{ ext4 }
mountpoint{ / } label{ rootfs }
options/noatime{ noatime } .
__EOF__
else
if [ ! "${conf_swapsize_mb}" ] ; then
conf_swapsize_mb=1024
fi
cat > "${TEMPDIR}/initrd-tree/partition_recipe" <<-__EOF__
500 1000 -1 ext4
method{ format } format{ }
use_filesystem{ } filesystem{ ext4 }
mountpoint{ / } label{ rootfs }
options/noatime{ noatime } .
128 1200 ${conf_swapsize_mb} linux-swap
method{ swap }
format{ } .
__EOF__
fi
}
initrd_preseed_settings () {
echo "NetInstall: Adding Distro Tweaks and Preseed Configuration"
cd "${TEMPDIR}/initrd-tree/" || exit
cp -v "${DIR}/lib/${deb_distribution}-finish.sh" "${TEMPDIR}/initrd-tree/usr/bin/finish-install.sh"
if [ "x${conf_smart_uboot}" = "xenable" ] ; then
sed -i -e 's:smart_DISABLED:enable:g' "${TEMPDIR}/initrd-tree/usr/bin/finish-install.sh"
fi
neuter_flash_kernel
finish_installing_device
setup_parition_recipe
cp -v "${DIR}/lib/shared/zz-uenv_txt" "${TEMPDIR}/initrd-tree/zz-uenv_txt"
if [ "${preseed_file_name}" != "" ]; then
echo "using preseed ${preseed_file_name}!"
cp -v "${DIR}/lib/${preseed_file_name}" "${TEMPDIR}/initrd-tree/preseed.cfg"
else
echo "using preseed ${DIST}-preseed.cfg!"
cp -v "${DIR}/lib/${DIST}-preseed.cfg" "${TEMPDIR}/initrd-tree/preseed.cfg"
fi
if [ ! "x${deb_not_in_repo}" = "xenable" ] ; then
#repos.rcn-ee.com: add linux-image-${uname -r}
sed -i -e 's:rcn-ee-archive-keyring:rcn-ee-archive-keyring linux-image-'$uname_r':g' "${TEMPDIR}/initrd-tree/preseed.cfg"
cat "${TEMPDIR}/initrd-tree/preseed.cfg" | grep linux-image
fi
if [ ! "x${conf_smart_uboot}" = "xenable" ] ; then
sed -i -e 's:rcn-ee-archive-keyring:rcn-ee-archive-keyring u-boot-tools:g' "${TEMPDIR}/initrd-tree/preseed.cfg"
fi
cd "${DIR}/" || true
}
extract_zimage () {
echo "NetInstall: Extracting Kernel Boot Image"
dpkg -x "${DIR}/dl/${DISTARCH}/${ACTUAL_DEB_FILE}" "${TEMPDIR}/kernel"
#ubuntu, copy dtb's...
cp -r "${TEMPDIR}/kernel/boot/dtbs/" "${TEMPDIR}"/initrd-tree/boot/ || true
}
generate_soc () {
echo "#!/bin/sh" > "${wfile}"
echo "format=1.0" >> "${wfile}"
echo "" >> "${wfile}"
if [ ! "x${conf_bootloader_in_flash}" = "xenable" ] ; then
echo "board=${conf_board}" >> "${wfile}"
echo "" >> "${wfile}"
echo "bootloader_location=${bootloader_location}" >> "${wfile}"
echo "" >> "${wfile}"
echo "dd_spl_uboot_count=${dd_spl_uboot_count}" >> "${wfile}"
echo "dd_spl_uboot_seek=${dd_spl_uboot_seek}" >> "${wfile}"
echo "dd_spl_uboot_conf=${dd_spl_uboot_conf}" >> "${wfile}"
echo "dd_spl_uboot_bs=${dd_spl_uboot_bs}" >> "${wfile}"
echo "dd_spl_uboot_backup=${dd_spl_uboot_backup}" >> "${wfile}"
echo "" >> "${wfile}"
echo "dd_uboot_count=${dd_uboot_count}" >> "${wfile}"
echo "dd_uboot_seek=${dd_uboot_seek}" >> "${wfile}"
echo "dd_uboot_conf=${dd_uboot_conf}" >> "${wfile}"
echo "dd_uboot_bs=${dd_uboot_bs}" >> "${wfile}"
echo "dd_uboot_backup=${dd_uboot_backup}" >> "${wfile}"
else
if [ ! "x${conf_smart_uboot}" = "xenable" ] ; then
echo "uboot_CONFIG_CMD_BOOTZ=${uboot_CONFIG_CMD_BOOTZ}" >> "${wfile}"
echo "uboot_CONFIG_SUPPORT_RAW_INITRD=${uboot_CONFIG_SUPPORT_RAW_INITRD}" >> "${wfile}"
echo "uboot_CONFIG_CMD_FS_GENERIC=${uboot_CONFIG_CMD_FS_GENERIC}" >> "${wfile}"
echo "zreladdr=${conf_zreladdr}" >> "${wfile}"
fi
fi
echo "" >> "${wfile}"
echo "boot_fstype=${conf_boot_fstype}" >> "${wfile}"
echo "" >> "${wfile}"
echo "#Kernel" >> "${wfile}"
echo "dtb=${dtb}" >> "${wfile}"
echo "serial_tty=${SERIAL}" >> "${wfile}"
echo "usbnet_mem=${usbnet_mem}" >> "${wfile}"
if [ ! "x${di_serial_mode}" = "xenable" ] ; then
echo "optargs=console=tty0" >> "${wfile}"
if [ "x${drm_read_edid_broken}" = "xenable" ] ; then
echo "video=${drm_device_identifier}:1024x768@60e" >> "${wfile}"
fi
fi
echo "" >> "${wfile}"
}
initrd_device_settings () {
echo "NetInstall: Adding Device Tweaks"
#work around for the kevent smsc95xx issue
touch "${TEMPDIR}/initrd-tree/etc/sysctl.conf"
if [ "${usbnet_mem}" ] ; then
echo "vm.min_free_kbytes = ${usbnet_mem}" >> "${TEMPDIR}/initrd-tree/etc/sysctl.conf"
fi
mkdir -p "${TEMPDIR}/initrd-tree/etc/hwpack/"
wfile="${TEMPDIR}/initrd-tree/etc/hwpack/SOC.sh"
generate_soc
}
recompress_initrd () {
echo "NetInstall: Compressing initrd image"
cd "${TEMPDIR}/initrd-tree/" || exit
find . | cpio -o -H newc | gzip -9 > "${TEMPDIR}/initrd.mod.gz"
cd "${DIR}/" || exit
}
create_custom_netinstall_image () {
echo ""
echo "NetInstall: Creating Custom Image"
echo "-----------------------------"
mkdir -p "${TEMPDIR}/kernel"
mkdir -p "${TEMPDIR}/initrd-tree/lib/firmware/"
mkdir -p "${TEMPDIR}/initrd-tree/fixes"
extract_base_initrd
#Copy Device Firmware
cp -r "${TEMPDIR}/firmware/" "${TEMPDIR}/initrd-tree/lib/"
if [ "${FIRMWARE}" ] ; then
initrd_add_firmware
fi
initrd_cleanup
initrd_preseed_settings
extract_zimage
initrd_device_settings
recompress_initrd
}
drive_error_ro () {
echo "-----------------------------"
echo "Error: for some reason your SD card is not writable..."
echo "Check: is the write protect lever set the locked position?"
echo "Check: do you have another SD card reader?"
echo "-----------------------------"
echo "Script gave up..."
exit
}
unmount_all_drive_partitions () {
echo ""
echo "Unmounting Partitions"
echo "-----------------------------"
NUM_MOUNTS=$(mount | grep -v none | grep "${media}" | wc -l)
## for (i=1;i<=${NUM_MOUNTS};i++)
for ((i=1;i<=${NUM_MOUNTS};i++))
do
DRIVE=$(mount | grep -v none | grep "${media}" | tail -1 | awk '{print $1}')
umount ${DRIVE} >/dev/null 2>&1 || true
done
echo "Zeroing out Partition Table"
echo "-----------------------------"
dd if=/dev/zero of=${media} bs=1M count=50 || drive_error_ro
sync
dd if=${media} of=/dev/null bs=1M count=50
sync
}
sfdisk_partition_layout () {
sfdisk_options="--force --Linux --in-order --unit M"
test_sfdisk=$(LC_ALL=C sfdisk --help | grep -m 1 -e "--in-order" || true)
if [ "x${test_sfdisk}" = "x" ] ; then
echo "sfdisk: 2.26.x or greater"
sfdisk_options="--force"
conf_boot_startmb="${conf_boot_startmb}M"
conf_boot_endmb="${conf_boot_endmb}M"
fi
LC_ALL=C sfdisk ${sfdisk_options} "${media}" <<-__EOF__
${conf_boot_startmb},${conf_boot_endmb},${sfdisk_fstype},*
__EOF__
sync
}
dd_uboot_boot () {
unset dd_uboot
if [ ! "x${dd_uboot_count}" = "x" ] ; then
dd_uboot="${dd_uboot}count=${dd_uboot_count} "
fi
if [ ! "x${dd_uboot_seek}" = "x" ] ; then
dd_uboot="${dd_uboot}seek=${dd_uboot_seek} "
fi
if [ ! "x${dd_uboot_conf}" = "x" ] ; then
dd_uboot="${dd_uboot}conv=${dd_uboot_conf} "
fi
if [ ! "x${dd_uboot_bs}" = "x" ] ; then
dd_uboot="${dd_uboot}bs=${dd_uboot_bs}"
fi
echo "${uboot_name}: dd if=${uboot_name} of=${media} ${dd_uboot}"
echo "-----------------------------"
dd if="${TEMPDIR}/dl/${UBOOT}" of=${media} ${dd_uboot}
echo "-----------------------------"
}
dd_spl_uboot_boot () {
unset dd_spl_uboot
if [ ! "x${dd_spl_uboot_count}" = "x" ] ; then
dd_spl_uboot="${dd_spl_uboot}count=${dd_spl_uboot_count} "
fi
if [ ! "x${dd_spl_uboot_seek}" = "x" ] ; then
dd_spl_uboot="${dd_spl_uboot}seek=${dd_spl_uboot_seek} "
fi
if [ ! "x${dd_spl_uboot_conf}" = "x" ] ; then
dd_spl_uboot="${dd_spl_uboot}conv=${dd_spl_uboot_conf} "
fi
if [ ! "x${dd_spl_uboot_bs}" = "x" ] ; then
dd_spl_uboot="${dd_spl_uboot}bs=${dd_spl_uboot_bs}"
fi
echo "${spl_uboot_name}: dd if=${spl_uboot_name} of=${media} ${dd_spl_uboot}"
echo "-----------------------------"
dd if="${TEMPDIR}/dl/${SPL}" of=${media} ${dd_spl_uboot}
echo "-----------------------------"
}
format_partition_error () {
echo "LC_ALL=C ${mkfs} ${mkfs_partition} ${mkfs_label}"
echo "Failure: formating partition"
exit
}
format_partition () {
echo "Formating with: [${mkfs} ${mkfs_partition} ${mkfs_label}]"
echo "-----------------------------"
LC_ALL=C ${mkfs} ${mkfs_partition} ${mkfs_label} || format_partition_error
sync
}
format_boot_partition () {
mkfs_partition="${media_prefix}${media_boot_partition}"
if [ "x${conf_boot_fstype}" = "xfat" ] ; then
mount_partition_format="vfat"
mkfs="mkfs.vfat -F 16"
mkfs_label="-n ${BOOT_LABEL}"
else
mount_partition_format="${conf_boot_fstype}"
mkfs="mkfs.${conf_boot_fstype}"
mkfs_label="-L ${BOOT_LABEL}"
fi
format_partition
}
create_partitions () {
unset bootloader_installed