-
Notifications
You must be signed in to change notification settings - Fork 56
/
make_var_mx6ul_dart_debian.sh
executable file
·1124 lines (895 loc) · 28.8 KB
/
make_var_mx6ul_dart_debian.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
# It is designed to build Debian linux for Variscite imx6ul-dart module
# script tested in OS debian (jessie)
# prepare host OS system:
# sudo apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx
# sudo apt-get install lvm2 dosfstools gpart binutils git lib32ncurses5-dev python-m2crypto
# sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat libsdl1.2-dev
# sudo apt-get install autoconf libtool libglib2.0-dev libarchive-dev
# sudo apt-get install python-git xterm sed cvs subversion coreutils texi2html
# sudo apt-get install docbook-utils python-pysqlite2 help2man make gcc g++ desktop-file-utils libgl1-mesa-dev
# sudo apt-get install libglu1-mesa-dev mercurial automake groff curl lzop asciidoc u-boot-tools mtd-utils
#
# -e Exit immediately if a command exits with a non-zero status.
set -e
SCRIPT_NAME=${0##*/}
readonly SCRIPT_VERSION="0.4"
#### Exports Variables ####
#### global variables ####
readonly ABSOLUTE_FILENAME=`readlink -e "$0"`
readonly ABSOLUTE_DIRECTORY=`dirname ${ABSOLUTE_FILENAME}`
readonly SCRIPT_POINT=${ABSOLUTE_DIRECTORY}
readonly SCRIPT_START_DATE=`date +%Y%m%d`
# default mirror
readonly DEF_DEBIAN_MIRROR="http://archive.debian.org/debian"
readonly DEB_RELEASE="jessie"
readonly DEF_ROOTFS_TARBAR_NAME="rootfs.tar.bz2"
## base paths
readonly DEF_BUILDENV="${ABSOLUTE_DIRECTORY}"
readonly DEF_SRC_DIR="${DEF_BUILDENV}/src"
readonly G_ROOTFS_DIR="${DEF_BUILDENV}/rootfs"
readonly G_TMP_DIR="${DEF_BUILDENV}/tmp"
readonly G_TOOLS_PATH="${DEF_BUILDENV}/toolchain"
readonly G_VARISCITE_PATH="${DEF_BUILDENV}/variscite"
## LINUX kernel: git, config, paths and etc
#git clone https://github.com/varigit/linux-2.6-imx.git -b imx_3.14.52_1.1.0_ga-var01 kernel
readonly G_LINUX_KERNEL_SRC_DIR="${DEF_SRC_DIR}/kernel"
readonly G_LINUX_KERNEL_GIT="https://github.com/varigit/linux-2.6-imx.git"
readonly G_LINUX_KERNEL_BRANCH="imx_3.14.52_1.1.0_ga-var01"
readonly G_LINUX_KERNEL_DEF_CONFIG='imx6ul-var-dart_defconfig'
readonly G_LINUX_DTB='imx6ul-var-dart-emmc_wifi.dtb imx6ul-var-dart-nand_wifi.dtb imx6ul-var-dart-sd_emmc.dtb imx6ul-var-dart-sd_nand.dtb'
## uboot
readonly G_UBOOT_SRC_DIR="${DEF_SRC_DIR}/uboot"
readonly G_UBOOT_GIT="https://github.com/varigit/uboot-imx.git"
readonly G_UBOOT_BRANCH="imx_v2015.10_dart_6ul_var1"
readonly G_UBOOT_DEF_CONFIG_MMC='mx6ul_var_dart_mmc_defconfig'
readonly G_UBOOT_DEF_CONFIG_NAND='mx6ul_var_dart_nand_defconfig'
readonly G_UBOOT_NAME_FOR_EMMC='u-boot.img.mmc'
readonly G_SPL_NAME_FOR_EMMC='SPL.mmc'
readonly G_UBOOT_NAME_FOR_NAND='u-boot.img.nand'
readonly G_SPL_NAME_FOR_NAND='SPL.nand'
## ext-firmware ##
readonly G_BCM_FW_SRC_DIR="${DEF_SRC_DIR}/bcmfw"
readonly G_BCM_FW_GIT="https://github.com/varigit/bcm_4343w_fw.git"
readonly G_BCM_FW_GIT_BRANCH="master"
## ubi
readonly G_UBI_FILE_NAME='rootfs.ubi.img'
## CROSS_COMPILER config and paths
readonly G_CROSS_COMPILEER_PATH="${G_TOOLS_PATH}/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf/bin"
#readonly G_CROSS_COMPILEER_PREFFIX="arm-none-eabi-"
readonly G_CROSS_COMPILEER_PREFFIX="arm-linux-gnueabihf-"
readonly G_CROSS_COMPILEER_JOPTION="-j 4"
readonly G_EXT_CROSS_COMPILER_NAME='gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf.tar.xz'
readonly G_EXT_CROSS_COMPILER_LINK="http://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-linux-gnueabihf/${G_EXT_CROSS_COMPILER_NAME}"
############## user rootfs packages ##########
readonly G_USER_PACKAGES=""
#### Input params #####
PARAM_DEB_LOCAL_MIRROR="${DEF_DEBIAN_MIRROR}"
PARAM_OUTPUT_DIR="${DEF_BUILDENV}/output"
PARAM_DEBUG="0"
PARAM_CMD="all"
PARAM_BLOCK_DEVICE="na"
### usage ###
function usage() {
echo "This program version ${SCRIPT_VERSION}"
echo " Used for make debian(${DEB_RELEASE}) image for \"imx6ul-var-dart\" board"
echo " and create booted sdcard"
echo ""
echo "Usage:"
echo " ./${SCRIPT_NAME} options"
echo ""
echo "Options:"
echo " -h|--help -- print this help"
echo " -c|--cmd <command>"
echo " Supported commands:"
echo " deploy -- prepare environment for all commands"
echo " all -- build or rebuild kernel/bootloader/rootfs"
echo " bootloader -- build or rebuild bootloader (u-boot+SPL)"
echo " kernel -- build or rebuild linux kernel for this board"
echo " modules -- build or rebuild linux kernel modules and install in rootfs directory for this board"
echo " rootfs -- build or rebuild debian rootfs filesystem (includes: make debian apks, make and install kernel moduled,"
echo " make and install extern modules (wifi/bt), create rootfs.ubi.img and rootfs.tar.bz2)"
echo " rubi -- generate or regenerate rootfs.ubi.img image from rootfs folder "
echo " rtar -- generate or regenerate rootfs.tar.bz2 image from rootfs folder "
echo " clean -- clean all build artifacts (not delete sources code and resulted images (output folder))"
echo " sdcard -- create bootting sdcard for this device"
echo " -o|--output -- custom select output directory (default: \"${PARAM_OUTPUT_DIR}\")"
echo " -d|--dev -- select sdcard device (exmple: -d /dev/sde)"
echo " --debug -- enable debug mode for this script"
echo "Examples of use:"
echo " make only linux kernel for board: sudo ./${SCRIPT_NAME} --cmd kernel"
echo " make only rootfs for board: sudo ./${SCRIPT_NAME} --cmd rootfs"
echo " create boot sdcard: sudo ./${SCRIPT_NAME} --cmd sdcard --dev /dev/sdX"
echo " deploy and build: ./${SCRIPT_NAME} --cmd deploy && sudo ./${SCRIPT_NAME} --cmd all"
echo ""
}
###### parse input arguments ##
readonly SHORTOPTS="c:o:d:h"
readonly LONGOPTS="cmd:,output:,dev:,help,debug"
ARGS=$(getopt -s bash --options ${SHORTOPTS} \
--longoptions ${LONGOPTS} --name ${SCRIPT_NAME} -- "$@" )
eval set -- "$ARGS"
while true; do
case $1 in
-c|--cmd ) # script command
shift
PARAM_CMD="$1";
;;
-o|--output ) # select output dir
shift
PARAM_OUTPUT_DIR="$1";
;;
-d|--dev ) # block device (for create sdcard)
shift
[ -e ${1} ] && {
PARAM_BLOCK_DEVICE=${1};
};
;;
--debug ) # enable debug
PARAM_DEBUG=1;
;;
-h|--help ) # get help
usage
exit 0;
;;
-- )
shift
break
;;
* )
shift
break
;;
esac
shift
done
## enable tarce options in debug mode
[ "${PARAM_DEBUG}" = "1" ] && {
echo "Debug mode enabled!"
set -x
};
## declarate dinamic variables ##
readonly G_ROOTFS_TARBAR_PATH="${PARAM_OUTPUT_DIR}/${DEF_ROOTFS_TARBAR_NAME}"
###### local functions ######
### printing functions ###
# print error message
# $1 - printing string
function pr_error() {
echo "E: $1"
}
# print warning message
# $1 - printing string
function pr_warning() {
echo "W: $1"
}
# print info message
# $1 - printing string
function pr_info() {
echo "I: $1"
}
# print debug message
# $1 - printing string
function pr_debug() {
echo "D: $1"
}
### work functions ###
# get sources from git repository
# $1 - git repository
# $2 - branch name
# $3 - output dir
function get_git_src() {
# clone src code
git clone -b ${2} ${1} ${3}
return $?
}
function make_prepare() {
## create src dirs
# mkdir -p ${G_WILINK8_SRC_DIR} && :;
mkdir -p ${G_BCM_FW_SRC_DIR} && :;
mkdir -p ${G_LINUX_KERNEL_SRC_DIR} && :;
mkdir -p ${G_UBOOT_SRC_DIR} && :;
mkdir -p ${G_TOOLS_PATH} && :;
## mkdir -p ${G_CROSS_COMPILEER_PATH} && :;
## create rootfs dir
mkdir -p ${G_ROOTFS_DIR} && :;
## create out dir
mkdir -p ${PARAM_OUTPUT_DIR} && :;
## create tmp dir
mkdir -p ${G_TMP_DIR} && :;
}
# function generate rootfs in input dir
# $1 - rootfs base dir
function make_debian_rootfs() {
local ROOTFS_BASE=$1
pr_info "Make debian(${DEB_RELEASE}) rootfs start..."
# umount previus mounts (if fail)
umount -l -f ${ROOTFS_BASE}/proc && :;
umount -l -f ${ROOTFS_BASE}/sys && :;
## clear rootfs dir
rm -rf ${ROOTFS_BASE}/* && :;
pr_info "rootfs: debootstrap"
debootstrap --verbose --foreign --arch armhf ${DEB_RELEASE} ${ROOTFS_BASE}/ ${PARAM_DEB_LOCAL_MIRROR}
## prepare qemu
pr_info "rootfs: debootstrap in rootfs (second-stage)"
cp /usr/bin/qemu-arm-static usr/bin/
LANG=C chroot $ROOTFS_BASE /debootstrap/debootstrap --second-stage
# delete unused folder
LANG=C chroot $ROOTFS_BASE rm -rf ${ROOTFS_BASE}/debootstrap
pr_info "rootfs: generate default configs"
mkdir -p ${ROOTFS_BASE}/etc/sudoers.d/
echo "user ALL=(root) /usr/bin/apt-get, /usr/bin/dpkg, /usr/bin/vi, /sbin/reboot" > ${ROOTFS_BASE}/etc/sudoers.d/user
chmod 0440 ${ROOTFS_BASE}/etc/sudoers.d/user
echo "deb $PARAM_DEB_LOCAL_MIRROR ${DEB_RELEASE} main contrib non-free
" > etc/apt/sources.list
echo "
# /dev/mmcblk0p1 /boot vfat defaults 0 0
" > etc/fstab
echo "imx6ul-var-dart" > etc/hostname
echo "auto lo
iface lo inet loopback
" > etc/network/interfaces
echo "
locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8
locales locales/default_environment_locale select en_US.UTF-8
console-common console-data/keymap/policy select Select keymap from full list
keyboard-configuration keyboard-configuration/variant select 'English (US)'
openssh-server openssh-server/permit-root-login select true
slim shared/default-x-display-manager select slim
" > debconf.set
pr_info "rootfs: prepare install packages in rootfs"
## apt-get install without starting
cat > ${ROOTFS_BASE}/usr/sbin/policy-rc.d << EOF
# !/bin/sh
exit 101
EOF
chmod +x ${ROOTFS_BASE}/usr/sbin/policy-rc.d
## third packages stage
cat > third-stage << EOF
#!/bin/bash
# apply debconfig options
debconf-set-selections /debconf.set
rm -f /debconf.set
function protected_install() {
local _name=\${1}
local repeated_cnt=5;
local RET_CODE=1;
for (( c=0; c<\${repeated_cnt}; c++ ))
do
apt-get install -y \${_name} && {
RET_CODE=0;
break;
};
echo ""
echo "###########################"
echo "## Fix missing packeges ###"
echo "###########################"
echo ""
sleep 2;
done
return \${RET_CODE}
}
# update packages and install base
apt-get update || apt-get update
protected_install locales
protected_install ntp
protected_install openssh-server
protected_install nfs-common
# packages required when flashing emmc
protected_install dosfstools
protected_install bzip2
# fix config for sshd (added user login for password)
sed -i -e 's/\PermitRootLogin.*/PermitRootLogin\tyes/g' /etc/ssh/sshd_config
# enable graphical desktop
protected_install Xorg
protected_install xfce4
protected_install xfce4-goodies
protected_install slim
# sound mixer & volune
protected_install xfce4-mixer
protected_install xfce4-volumed
# network manager
protected_install network-manager-gnome
## fix slim config (added autologin x_user) ##
sed -i -e 's/\#auto_login.*/auto_login\tyes/g' /etc/slim.conf
sed -i -e 's/\#default_user.*/default_user\tx_user/g' /etc/slim.conf
# added alsa & alsa utilites
protected_install alsa-base
protected_install alsa-utils
# protected_install gstreamer0.10-plugins-good
protected_install gstreamer0.10-alsa
# added i2c tools
protected_install i2c-tools
# added usb tools
protected_install usbutils
# added net tools
protected_install iperf
#media
protected_install audacious
# protected_install parole
# wifi
protected_install wpasupplicant
# mtd
protected_install mtd-utils
# bluetooth
protected_install bluetooth
protected_install bluez
protected_install bluez-obexd
protected_install bluez-tools
protected_install libbluetooth3
# wifi support packages
protected_install hostapd
protected_install udhcpd
# can support
protected_install can-utils
# psmisc utils (killall and etc)
protected_install psmisc
# nano
protected_install nano
# delete unused packages ##
apt-get -y remove xscreensaver
apt-get -y remove xserver-xorg-video-ati
apt-get -y remove xserver-xorg-video-r128
apt-get -y remove xserver-xorg-video-radeon
apt-get -y remove xserver-xorg-video-mach64
apt-get -y remove manpages
apt-get -y remove gstreamer0.10-x
apt-get -y remove hddtemp
apt-get -y autoremove
# create users and set password
useradd -m -G audio -s /bin/bash user
useradd -m -G audio -s /bin/bash x_user
echo "user:user" | chpasswd
echo "root:root" | chpasswd
passwd -d x_user
# sado kill
rm -f third-stage
EOF
pr_info "rootfs: install selected debian packages (third-stage)"
chmod +x third-stage
LANG=C chroot ${ROOTFS_BASE} /third-stage
## fourth-stage ##
### install vvariscite-bluetooth init script
install -m 0755 ${G_VARISCITE_PATH}/brcm_patchram_plus ${ROOTFS_BASE}/usr/bin/
install -m 0755 ${G_VARISCITE_PATH}/variscite-bluetooth ${ROOTFS_BASE}/etc/init.d/
LANG=C chroot ${ROOTFS_BASE} update-rc.d variscite-bluetooth defaults
LANG=C chroot ${ROOTFS_BASE} update-rc.d variscite-bluetooth enable 2 3 4 5
## end packages stage ##
[ "${G_USER_PACKAGES}" != "" ] && {
pr_info "rootfs: install user defined packages (user-stage)"
pr_info "rootfs: G_USER_PACKAGES \"${G_USER_PACKAGES}\" "
echo "#!/bin/bash
# update packages
apt-get update
# install all user packages
apt-get -y install ${G_USER_PACKAGES}
rm -f user-stage
" > user-stage
chmod +x user-stage
LANG=C chroot ${ROOTFS_BASE} /user-stage
};
## binaries rootfs patching ##
install -m 0755 ${G_VARISCITE_PATH}/issue ${ROOTFS_BASE}/etc/
install -m 0755 ${G_VARISCITE_PATH}/issue.net ${ROOTFS_BASE}/etc/
install -m 0755 ${G_VARISCITE_PATH}/hostapd.conf ${ROOTFS_BASE}/etc/
## added alsa default configs ##
install -m 0666 ${G_VARISCITE_PATH}/asound.state ${ROOTFS_BASE}/var/lib/alsa/
install -m 0666 ${G_VARISCITE_PATH}/asound.conf ${ROOTFS_BASE}/etc/
## Revert regular booting
rm -f ${ROOTFS_BASE}/usr/sbin/policy-rc.d
# added mirror to source list
echo "deb ${DEF_DEBIAN_MIRROR} ${DEB_RELEASE} main contrib non-free
" > etc/apt/sources.list
pr_info "rootfs: clean"
## clenup command
echo "#!/bin/bash
apt-get clean
rm -f cleanup
" > cleanup
# clean all packages
chmod +x cleanup
LANG=C chroot ${ROOTFS_BASE} /cleanup
return 0;
}
# make tarbar arx from footfs
# $1 -- packet folder
# $2 -- output arx full name
function make_tarbar() {
cd $1
pr_info "make tarbar arx from folder ${1}"
pr_info "Remove old arx $2"
rm $2 > /dev/null 2>&1 && :;
pr_info "Create $2"
tar jcf $2 .
success=$?
[ $success -eq 0 ] || {
# fail
rm $2 > /dev/null 2>&1 && :;
};
cd -
}
# make linux kernel modules
# $1 -- cross compiller prefix
# $2 -- linux defconfig file
# $3 -- linux dtb files
# $4 -- linux dirname
# $5 -- out patch
function make_kernel() {
pr_info "make kernel .config"
make ARCH=arm CROSS_COMPILE=${1} ${G_CROSS_COMPILEER_JOPTION} -C ${4}/ ${2}
pr_info "make kernal"
make CROSS_COMPILE=${1} ARCH=arm ${G_CROSS_COMPILEER_JOPTION} -C ${4}/ zImage
pr_info "make ${3} file"
make CROSS_COMPILE=${1} ARCH=arm ${G_CROSS_COMPILEER_JOPTION} -C ${4} ${3}
pr_info "Copy kernel and dtb files to output dir: ${5}"
cp ${4}/arch/arm/boot/zImage ${5}/;
cp ${4}/arch/arm/boot/dts/*.dtb ${5}/;
return 0;
}
# clean kernel
# $1 -- linux dir path
function clean_kernel() {
pr_info "Clean linux kernel"
make ARCH=arm -C ${1}/ mrproper
return 0;
}
# make linux kernel modules
# $1 -- cross compiller prefix
# $2 -- linux defconfig file
# $3 -- linux dirname
# $4 -- out modules patch
function make_kernel_modules() {
pr_info "make kernel .config"
make ARCH=arm CROSS_COMPILE=${1} ${G_CROSS_COMPILEER_JOPTION} -C ${3}/ ${2}
pr_info "Compiling Linux kernel modules"
make ARCH=arm CROSS_COMPILE=${1} ${G_CROSS_COMPILEER_JOPTION} -C ${3}/ modules
pr_info "Installing Linux kernel modules to ${4}"
make CROSS_COMPILE=${1} ARCH=arm INSTALL_MOD_PATH=${4}/ ${G_CROSS_COMPILEER_JOPTION} -C ${3}/ modules_install
return 0;
}
# make uboot
# $1 uboot path
# $2 outputdir
function make_uboot() {
### make emmc uboot ###
pr_info "Make SPL & u-boot: ${G_UBOOT_DEF_CONFIG_MMC}"
# clean work directory
make ARCH=arm -C ${1} CROSS_COMPILE=${G_CROSS_COMPILEER_PATH}/${G_CROSS_COMPILEER_PREFFIX} ${G_CROSS_COMPILEER_JOPTION} mrproper
# make uboot config for mmc
make ARCH=arm -C ${1} CROSS_COMPILE=${G_CROSS_COMPILEER_PATH}/${G_CROSS_COMPILEER_PREFFIX} ${G_CROSS_COMPILEER_JOPTION} ${G_UBOOT_DEF_CONFIG_MMC}
# make uboot
make ARCH=arm -C ${1} CROSS_COMPILE=${G_CROSS_COMPILEER_PATH}/${G_CROSS_COMPILEER_PREFFIX} ${G_CROSS_COMPILEER_JOPTION}
# copy images
cp ${1}/SPL ${2}/${G_SPL_NAME_FOR_EMMC}
cp ${1}/u-boot.img ${2}/${G_UBOOT_NAME_FOR_EMMC}
### make nand uboot ###
pr_info "Make SPL & u-boot: ${G_UBOOT_DEF_CONFIG_NAND}"
# clean work directory
make ARCH=arm -C ${1} CROSS_COMPILE=${G_CROSS_COMPILEER_PATH}/${G_CROSS_COMPILEER_PREFFIX} ${G_CROSS_COMPILEER_JOPTION} mrproper
# make uboot config for nand
make ARCH=arm -C ${1} CROSS_COMPILE=${G_CROSS_COMPILEER_PATH}/${G_CROSS_COMPILEER_PREFFIX} ${G_CROSS_COMPILEER_JOPTION} ${G_UBOOT_DEF_CONFIG_NAND}
# make uboot
make ARCH=arm -C ${1} CROSS_COMPILE=${G_CROSS_COMPILEER_PATH}/${G_CROSS_COMPILEER_PREFFIX} ${G_CROSS_COMPILEER_JOPTION}
# copy images
cp ${1}/SPL ${2}/${G_SPL_NAME_FOR_NAND}
cp ${1}/u-boot.img ${2}/${G_UBOOT_NAME_FOR_NAND}
return 0;
}
# clean uboot
# $1 -- u-boot dir path
function clean_uboot() {
pr_info "Clean uboot"
make ARCH=arm -C ${1}/ mrproper
return 0;
}
# make *.ubi image from rootfs
# params:
# $1 -- path to rootfs dir
# $2 -- tmp dir
# $3 -- output dir
# $4 -- ubi file name
function make_ubi() {
readonly local _rootfs=${1};
readonly local _tmp=${2};
readonly local _output=${3};
readonly local _ubi_file_name=${4};
readonly local UBI_CFG="${_tmp}/ubi.cfg"
readonly local UBIFS_IMG="${_tmp}/rootfs.ubifs"
readonly local UBI_IMG="${_output}/${_ubi_file_name}"
# gnerate ubifs file
pr_info "Generate ubi config file: ${UBI_CFG}"
cat > ${UBI_CFG} << EOF
[ubifs]
mode=ubi
image=${UBIFS_IMG}
vol_id=0
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize
EOF
# delete previus images
rm -f ${UBI_IMG} && :;
rm -f ${UBIFS_IMG} && :;
pr_info "Creating $UBIFS_IMG image"
mkfs.ubifs -x zlib -m 2048 -e 124KiB -c 3965 -r ${_rootfs} $UBIFS_IMG
pr_info "Creating $UBI_IMG image"
ubinize -o ${UBI_IMG} -m 2048 -p 128KiB -s 2048 -O 2048 ${UBI_CFG}
# delete unused file
rm -f ${UBIFS_IMG} && :;
rm -f ${UBI_CFG} && :;
return 0;
}
# make sdcard for device
# $1 -- block device
# $2 -- output images dir
function make_sdcard() {
readonly local LPARAM_BLOCK_DEVICE=${1}
readonly local LPARAM_OUTPUT_DIR=${2}
readonly local P1_MOUNT_DIR="${G_TMP_DIR}/p1"
readonly local P2_MOUNT_DIR="${G_TMP_DIR}/p2"
readonly local DEBIAN_IMAGES_TO_ROOTFS_POINT="opt/images/Debian"
readonly local BOOTLOAD_RESERVE=4
readonly local BOOT_ROM_SIZE=8
readonly local SPARE_SIZE=0
make_prepare;
[ "${LPARAM_BLOCK_DEVICE}" = "na" ] && {
pr_warning "No valid block device: ${LPARAM_BLOCK_DEVICE}"
return 1;
};
local part=""
if [ `echo ${LPARAM_BLOCK_DEVICE} | grep -c mmcblk` -ne 0 ]; then
part="p"
fi
pr_info "Device: ${LPARAM_BLOCK_DEVICE}"
pr_info "================================================"
read -p "Press Enter to continue"
for ((i=0; i<10; i++))
do
if [ `mount | grep -c ${LPARAM_BLOCK_DEVICE}${part}$i` -ne 0 ]; then
umount ${LPARAM_BLOCK_DEVICE}${part}$i
fi
done
# Call sfdisk to get total card size
local TOTAL_SIZE=`sfdisk -s ${LPARAM_BLOCK_DEVICE}`
local TOTAL_SIZE=`expr ${TOTAL_SIZE} / 1024`
local ROOTFS_SIZE=`expr ${TOTAL_SIZE} - ${BOOTLOAD_RESERVE_SIZE} - ${BOOT_ROM_SIZE} - ${SPARE_SIZE}`
function format_sdcard
{
pr_info "Formating SDCARD partitions"
mkfs.vfat ${LPARAM_BLOCK_DEVICE}${part}1 -n BOOT-VARSOM
mkfs.ext4 ${LPARAM_BLOCK_DEVICE}${part}2 -L rootfs
}
function flash_u-boot
{
pr_info "Flashing U-Boot"
dd if=${LPARAM_OUTPUT_DIR}/${G_SPL_NAME_FOR_EMMC} of=${LPARAM_BLOCK_DEVICE} bs=1K seek=1; sync
dd if=${LPARAM_OUTPUT_DIR}/${G_UBOOT_NAME_FOR_EMMC} of=${LPARAM_BLOCK_DEVICE} bs=1K seek=69; sync
}
function flash_sdcard
{
pr_info "Flashing \"BOOT-VARSOM\" partition"
cp ${LPARAM_OUTPUT_DIR}/*.dtb ${P1_MOUNT_DIR}/
cp ${LPARAM_OUTPUT_DIR}/zImage ${P1_MOUNT_DIR}/zImage
sync
pr_info "Flashing \"rootfs\" partition"
tar -xjf ${LPARAM_OUTPUT_DIR}/${DEF_ROOTFS_TARBAR_NAME} -C ${P2_MOUNT_DIR}/
}
function copy_debian_images
{
mkdir -p ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}
pr_info "Copying Debian images to /${DEBIAN_IMAGES_TO_ROOTFS_POINT}"
cp ${LPARAM_OUTPUT_DIR}/zImage ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/
cp ${LPARAM_OUTPUT_DIR}/${DEF_ROOTFS_TARBAR_NAME} ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/${DEF_ROOTFS_TARBAR_NAME}
cp ${LPARAM_OUTPUT_DIR}/${G_UBI_FILE_NAME} ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/${G_UBI_FILE_NAME}
cp ${LPARAM_OUTPUT_DIR}/*.dtb ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/
pr_info "Copying NAND U-Boot to /${DEBIAN_IMAGES_TO_ROOTFS_POINT}"
cp ${LPARAM_OUTPUT_DIR}/${G_SPL_NAME_FOR_NAND} ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/
cp ${LPARAM_OUTPUT_DIR}/${G_UBOOT_NAME_FOR_NAND} ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/
pr_info "Copying MMC U-Boot to /${DEBIAN_IMAGES_TO_ROOTFS_POINT}"
cp ${LPARAM_OUTPUT_DIR}/${G_SPL_NAME_FOR_EMMC} ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/
cp ${LPARAM_OUTPUT_DIR}/${G_UBOOT_NAME_FOR_EMMC} ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/
return 0;
}
function copy_scripts
{
pr_info "Copying scripts to /${DEBIAN_IMAGES_TO_ROOTFS_POINT}"
cp ${G_VARISCITE_PATH}/debian-emmc.sh ${P2_MOUNT_DIR}/usr/sbin/
cp ${G_VARISCITE_PATH}/debian-nand.sh ${P2_MOUNT_DIR}/usr/sbin/
cp ${G_VARISCITE_PATH}/kobs-ng ${P2_MOUNT_DIR}/usr/sbin/
# added exec options
chmod +x ${P2_MOUNT_DIR}/usr/sbin/debian-emmc.sh ${P2_MOUNT_DIR}/usr/sbin/debian-nand.sh ${P2_MOUNT_DIR}/usr/sbin/kobs-ng
}
function ceildiv
{
local num=$1
local div=$2
echo $(( (num + div - 1) / div ))
}
# Delete the partitions
for ((i=0; i<10; i++))
do
if [ `ls ${LPARAM_BLOCK_DEVICE}${part}$i 2> /dev/null | grep -c ${LPARAM_BLOCK_DEVICE}${part}$i` -ne 0 ]; then
dd if=/dev/zero of=${LPARAM_BLOCK_DEVICE}${part}$i bs=512 count=1024
fi
done
sync
((echo d; echo 1; echo d; echo 2; echo d; echo 3; echo d; echo w) | fdisk ${LPARAM_BLOCK_DEVICE} &> /dev/null) || true
sync
dd if=/dev/zero of=${LPARAM_BLOCK_DEVICE} bs=1024 count=4096
sleep 2; sync;
pr_info "Creating new partitions"
# Create a new partition table
fdisk ${LPARAM_BLOCK_DEVICE} <<EOF
n
p
1
8192
24575
t
c
n
p
2
24576
p
w
EOF
sleep 2; sync;
# Get total card size
total_size=`sfdisk -s ${LPARAM_BLOCK_DEVICE}`
total_size=`expr ${total_size} / 1024`
boot_rom_sizeb=`expr ${BOOT_ROM_SIZE} + ${BOOTLOAD_RESERVE}`
rootfs_size=`expr ${total_size} - ${boot_rom_sizeb} - ${SPARE_SIZE}`
pr_info "ROOT SIZE=${rootfs_size} TOTAl SIZE=${total_size} BOOTROM SIZE=${boot_rom_sizeb}"
sleep 2; sync;
# Format the partitions
format_sdcard
sleep 2; sync;
flash_u-boot
sleep 2; sync;
# Mount the partitions
mkdir -p ${P1_MOUNT_DIR}
mkdir -p ${P2_MOUNT_DIR}
sync
mount ${LPARAM_BLOCK_DEVICE}${part}1 ${P1_MOUNT_DIR}
mount ${LPARAM_BLOCK_DEVICE}${part}2 ${P2_MOUNT_DIR}
sleep 2; sync;
flash_sdcard
copy_debian_images
copy_scripts
pr_info "Sync sdcard..."
sync
umount ${P1_MOUNT_DIR}
umount ${P2_MOUNT_DIR}
rm -rf ${P1_MOUNT_DIR}
rm -rf ${P2_MOUNT_DIR}
pr_info "Done make sdcard!"
return 0;
}
# make firmware for wl bcm module
# $1 -- bcm git directory
# $2 -- rootfs output dir
function make_bcm_fw() {
pr_info "Make and install bcmhd configs and firmwares"
install -d ${2}/lib/firmware/bcm
install -m 0755 ${1}/bcmdhd.cal ${2}/lib/firmware/bcm/bcmdhd.cal
install -m 0755 ${1}/bcm43430a1.hcd ${2}/lib/firmware/bcm/bcm43430a1.hcd
install -m 0755 ${1}/fw_bcmdhd.bin ${2}/lib/firmware/bcm/fw_bcmdhd.bin
install -m 0755 ${1}/fw_bcmdhd_mfgtest.bin ${2}/lib/firmware/bcm/fw_bcmdhd_mfgtest.bin
install -m 0755 ${1}/fw_bcmdhd_apsta.bin ${2}/lib/firmware/bcm/fw_bcmdhd_apsta.bin
install -m 0755 ${1}/LICENCE.broadcom_bcm4343w ${2}/lib/firmware/bcm/
install -m 0755 ${1}/wl ${2}/usr/sbin/wl
return 0;
}
#################### commands ################
function cmd_make_deploy() {
make_prepare;
# get bcm firmware repository
(( `ls ${G_BCM_FW_SRC_DIR} | wc -l` == 0 )) && {
pr_info "Get bcmhd firmware repository";
get_git_src ${G_BCM_FW_GIT} ${G_BCM_FW_GIT_BRANCH} ${G_BCM_FW_SRC_DIR}
};
# get kernel repository
(( `ls ${G_LINUX_KERNEL_SRC_DIR} | wc -l` == 0 )) && {
pr_info "Get kernel repository";
get_git_src ${G_LINUX_KERNEL_GIT} ${G_LINUX_KERNEL_BRANCH} ${G_LINUX_KERNEL_SRC_DIR};
};
# get uboot repository
(( `ls ${G_UBOOT_SRC_DIR} | wc -l` == 0 )) && {
pr_info "Get uboot repository";
get_git_src ${G_UBOOT_GIT} ${G_UBOOT_BRANCH} ${G_UBOOT_SRC_DIR}
};
# get linaro toolchain
(( `ls ${G_CROSS_COMPILEER_PATH} | wc -l` == 0 )) && {
pr_info "Get and unpack cross compiler";
wget -c ${G_EXT_CROSS_COMPILER_LINK} -O ${G_TMP_DIR}/${G_EXT_CROSS_COMPILER_NAME}
tar -xJf ${G_TMP_DIR}/${G_EXT_CROSS_COMPILER_NAME} -C ${G_TOOLS_PATH}/
rm -rf ${G_TMP_DIR}/${G_EXT_CROSS_COMPILER_NAME} && :;
};
return 0;
}
function cmd_make_rootfs() {
make_prepare;
## make debian rootfs
cd ${G_ROOTFS_DIR}
make_debian_rootfs ${G_ROOTFS_DIR} || {
pr_error "Failed #$? in function make_debian_rootfs"
cd -;
return 1;
}
cd -
## make and apply modules in rootfs
make_kernel_modules ${G_CROSS_COMPILEER_PATH}/${G_CROSS_COMPILEER_PREFFIX} ${G_LINUX_KERNEL_DEF_CONFIG} ${G_LINUX_KERNEL_SRC_DIR} ${G_ROOTFS_DIR} || {
pr_error "Failed #$? in function make_kernel_modules"
return 2;
}
## make bcm firmwares
make_bcm_fw ${G_BCM_FW_SRC_DIR} ${G_ROOTFS_DIR} || {
pr_error "Failed #$? in function make_tarbar"
return 4;
};
## pack rootfs
make_tarbar ${G_ROOTFS_DIR} ${G_ROOTFS_TARBAR_PATH} || {
pr_error "Failed #$? in function make_tarbar"
return 4;
}
## pack to ubi
make_ubi ${G_ROOTFS_DIR} ${G_TMP_DIR} ${PARAM_OUTPUT_DIR} ${G_UBI_FILE_NAME} || {
pr_error "Failed #$? in function make_ubi"
return 5;
};
return 0;
}
function cmd_make_uboot() {
make_prepare;
make_uboot ${G_UBOOT_SRC_DIR} ${PARAM_OUTPUT_DIR} || {
pr_error "Failed #$? in function make_uboot"
return 1;
};
return 0;
}
function cmd_make_kernel() {
make_prepare;
make_kernel ${G_CROSS_COMPILEER_PATH}/${G_CROSS_COMPILEER_PREFFIX} ${G_LINUX_KERNEL_DEF_CONFIG} "${G_LINUX_DTB}" ${G_LINUX_KERNEL_SRC_DIR} ${PARAM_OUTPUT_DIR} || {
pr_error "Failed #$? in function make_kernel"
return 1;
};
return 0;
}
function cmd_make_kmodules() {
make_prepare;
rm -rf ${G_ROOTFS_DIR}/lib/modules/* || {
pr_error "Failed #$? prepare modules dir"
return 1;
};
make_kernel_modules ${G_CROSS_COMPILEER_PATH}/${G_CROSS_COMPILEER_PREFFIX} ${G_LINUX_KERNEL_DEF_CONFIG} ${G_LINUX_KERNEL_SRC_DIR} ${G_ROOTFS_DIR} || {
pr_error "Failed #$? in function make_kmodules"
return 2;
};
return 0;
}
function cmd_make_rfs_ubi() {
make_prepare;
make_ubi ${G_ROOTFS_DIR} ${G_TMP_DIR} ${PARAM_OUTPUT_DIR} ${G_UBI_FILE_NAME} || {
pr_error "Failed #$? in function make_ubi"
return 1;
};
return 0;
}
function cmd_make_rfs_tar() {
make_prepare;
## pack rootfs
make_tarbar ${G_ROOTFS_DIR} ${G_ROOTFS_TARBAR_PATH} || {
pr_error "Failed #$? in function make_tarbar"
return 1;
}
return 0;
}
function cmd_make_sdcard() {
make_prepare;
make_sdcard ${PARAM_BLOCK_DEVICE} ${PARAM_OUTPUT_DIR} || {