Commit 4a4f371228f9d9edb92c75d9db64824c67d96fdc

Authored by Eric Lee
1 parent 63b346e1e6

rewrite u-boot LPDDR4 timing parameters

Showing 1 changed file with 1 additions and 1 deletions Inline Diff

make_smarc_mx8m_debian.sh
1 #!/bin/bash 1 #!/bin/bash
2 # It is designed to build Debian linux for Embedian SMARC-imx8m modules 2 # It is designed to build Debian linux for Embedian SMARC-imx8m modules
3 # prepare host OS system: 3 # prepare host OS system:
4 # sudo apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx 4 # sudo apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx
5 # sudo apt-get install lvm2 dosfstools gpart binutils git lib32ncurses5-dev python-m2crypto 5 # sudo apt-get install lvm2 dosfstools gpart binutils git lib32ncurses5-dev python-m2crypto
6 # sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat libsdl1.2-dev 6 # sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat libsdl1.2-dev
7 # sudo apt-get install autoconf libtool libglib2.0-dev libarchive-dev 7 # sudo apt-get install autoconf libtool libglib2.0-dev libarchive-dev
8 # sudo apt-get install python-git xterm sed cvs subversion coreutils texi2html 8 # sudo apt-get install python-git xterm sed cvs subversion coreutils texi2html
9 # sudo apt-get install docbook-utils python-pysqlite2 help2man make gcc g++ desktop-file-utils libgl1-mesa-dev 9 # sudo apt-get install docbook-utils python-pysqlite2 help2man make gcc g++ desktop-file-utils libgl1-mesa-dev
10 # sudo apt-get install libglu1-mesa-dev mercurial automake groff curl lzop asciidoc u-boot-tools mtd-utils 10 # sudo apt-get install libglu1-mesa-dev mercurial automake groff curl lzop asciidoc u-boot-tools mtd-utils
11 # 11 #
12 12
13 # -e Exit immediately if a command exits with a non-zero status. 13 # -e Exit immediately if a command exits with a non-zero status.
14 set -e 14 set -e
15 15
16 SCRIPT_NAME=${0##*/} 16 SCRIPT_NAME=${0##*/}
17 readonly SCRIPT_VERSION="0.5" 17 readonly SCRIPT_VERSION="0.5"
18 18
19 19
20 #### Exports Variables #### 20 #### Exports Variables ####
21 #### global variables #### 21 #### global variables ####
22 readonly ABSOLUTE_FILENAME=`readlink -e "$0"` 22 readonly ABSOLUTE_FILENAME=`readlink -e "$0"`
23 readonly ABSOLUTE_DIRECTORY=`dirname ${ABSOLUTE_FILENAME}` 23 readonly ABSOLUTE_DIRECTORY=`dirname ${ABSOLUTE_FILENAME}`
24 readonly SCRIPT_POINT=${ABSOLUTE_DIRECTORY} 24 readonly SCRIPT_POINT=${ABSOLUTE_DIRECTORY}
25 readonly SCRIPT_START_DATE=`date +%Y%m%d` 25 readonly SCRIPT_START_DATE=`date +%Y%m%d`
26 readonly LOOP_MAJOR=7 26 readonly LOOP_MAJOR=7
27 27
28 # default mirror 28 # default mirror
29 readonly DEF_DEBIAN_MIRROR="http://httpredir.debian.org/debian" 29 readonly DEF_DEBIAN_MIRROR="http://httpredir.debian.org/debian"
30 readonly DEB_RELEASE="stretch" 30 readonly DEB_RELEASE="stretch"
31 readonly DEF_ROOTFS_TARBAR_NAME="rootfs.tar.gz" 31 readonly DEF_ROOTFS_TARBAR_NAME="rootfs.tar.gz"
32 32
33 ## display 33 ## display
34 readonly DISPLAY="-hdmi" 34 readonly DISPLAY="-hdmi"
35 35
36 ## base paths 36 ## base paths
37 readonly DEF_BUILDENV="${ABSOLUTE_DIRECTORY}" 37 readonly DEF_BUILDENV="${ABSOLUTE_DIRECTORY}"
38 readonly DEF_SRC_DIR="${DEF_BUILDENV}/src" 38 readonly DEF_SRC_DIR="${DEF_BUILDENV}/src"
39 readonly G_ROOTFS_DIR="${DEF_BUILDENV}/rootfs" 39 readonly G_ROOTFS_DIR="${DEF_BUILDENV}/rootfs"
40 readonly G_TMP_DIR="${DEF_BUILDENV}/tmp" 40 readonly G_TMP_DIR="${DEF_BUILDENV}/tmp"
41 readonly G_TOOLS_PATH="${DEF_BUILDENV}/toolchain" 41 readonly G_TOOLS_PATH="${DEF_BUILDENV}/toolchain"
42 readonly G_EMBEDIAN_PATH="${DEF_BUILDENV}/embedian" 42 readonly G_EMBEDIAN_PATH="${DEF_BUILDENV}/embedian"
43 43
44 ## LINUX kernel: git, config, paths and etc 44 ## LINUX kernel: git, config, paths and etc
45 readonly G_LINUX_KERNEL_SRC_DIR="${DEF_SRC_DIR}/kernel" 45 readonly G_LINUX_KERNEL_SRC_DIR="${DEF_SRC_DIR}/kernel"
46 readonly G_LINUX_KERNEL_GIT="git@git.embedian.com:developer/smarc-fsl-linux-kernel.git" 46 readonly G_LINUX_KERNEL_GIT="git@git.embedian.com:developer/smarc-fsl-linux-kernel.git"
47 readonly G_LINUX_KERNEL_BRANCH="smarc_8m_imx_4.14.78_1.0.0_ga" 47 readonly G_LINUX_KERNEL_BRANCH="smarc_8m_imx_4.14.78_1.0.0_ga"
48 readonly G_LINUX_KERNEL_REV="4544004fd5f97dece58e27f3ade5c7f47feaea23" 48 readonly G_LINUX_KERNEL_REV="4544004fd5f97dece58e27f3ade5c7f47feaea23"
49 readonly G_LINUX_KERNEL_DEF_CONFIG='smarcimx8m_defconfig' 49 readonly G_LINUX_KERNEL_DEF_CONFIG='smarcimx8m_defconfig'
50 readonly G_LINUX_DTB='embedian/fsl-smarcimx8mq.dtb embedian/fsl-smarcimx8mq-dcss-lvds.dtb embedian/fsl-smarcimx8mq-hdmi.dtb embedian/fsl-smarcimx8mq-lcdif-lvds.dtb embedian/fsl-smarcimx8mq-dual-display.dtb embedian/fsl-smarcimx8mq-dp.dtb embedian/fsl-smarcimx8mq-edp.dtb' 50 readonly G_LINUX_DTB='embedian/fsl-smarcimx8mq.dtb embedian/fsl-smarcimx8mq-dcss-lvds.dtb embedian/fsl-smarcimx8mq-hdmi.dtb embedian/fsl-smarcimx8mq-lcdif-lvds.dtb embedian/fsl-smarcimx8mq-dual-display.dtb embedian/fsl-smarcimx8mq-dp.dtb embedian/fsl-smarcimx8mq-edp.dtb'
51 51
52 ## uboot 52 ## uboot
53 readonly G_UBOOT_SRC_DIR="${DEF_SRC_DIR}/uboot" 53 readonly G_UBOOT_SRC_DIR="${DEF_SRC_DIR}/uboot"
54 readonly G_UBOOT_GIT="git@git.embedian.com:developer/smarc-t335x-uboot.git" 54 readonly G_UBOOT_GIT="git@git.embedian.com:developer/smarc-t335x-uboot.git"
55 readonly G_UBOOT_BRANCH="smarc-imx_v2018.03_4.14.78_1.0.0_ga" 55 readonly G_UBOOT_BRANCH="smarc-imx_v2018.03_4.14.78_1.0.0_ga"
56 readonly G_UBOOT_REV="2da97eda457ceb70d01065a8f7417a657557f8c0" 56 readonly G_UBOOT_REV="f93b98812f1964ddb0cf6943b8aeb2db52d9ca89"
57 readonly G_UBOOT_DEF_CONFIG='smarcimx8mq_2g_ser3_defconfig' 57 readonly G_UBOOT_DEF_CONFIG='smarcimx8mq_2g_ser3_defconfig'
58 readonly G_UBOOT_NAME='imx-boot-sd.bin' 58 readonly G_UBOOT_NAME='imx-boot-sd.bin'
59 59
60 ## CROSS_COMPILER config and paths 60 ## CROSS_COMPILER config and paths
61 readonly G_CROSS_COMPILER_NAME="gcc-linaro-6.4.1-2017.11-x86_64_aarch64-linux-gnu" 61 readonly G_CROSS_COMPILER_NAME="gcc-linaro-6.4.1-2017.11-x86_64_aarch64-linux-gnu"
62 readonly G_CROSS_COMPILER_ARCHIVE="${G_CROSS_COMPILER_NAME}.tar.xz" 62 readonly G_CROSS_COMPILER_ARCHIVE="${G_CROSS_COMPILER_NAME}.tar.xz"
63 readonly G_CROSS_COMPILER_PATH="${G_TOOLS_PATH}/${G_CROSS_COMPILER_NAME}/bin" 63 readonly G_CROSS_COMPILER_PATH="${G_TOOLS_PATH}/${G_CROSS_COMPILER_NAME}/bin"
64 readonly G_CROSS_COMPILER_PREFIX="aarch64-linux-gnu-" 64 readonly G_CROSS_COMPILER_PREFIX="aarch64-linux-gnu-"
65 readonly G_CROSS_COMPILER_JOPTION="-j 4" 65 readonly G_CROSS_COMPILER_JOPTION="-j 4"
66 readonly G_EXT_CROSS_COMPILER_LINK="http://releases.linaro.org/components/toolchain/binaries/6.4-2017.11/aarch64-linux-gnu/${G_CROSS_COMPILER_ARCHIVE}" 66 readonly G_EXT_CROSS_COMPILER_LINK="http://releases.linaro.org/components/toolchain/binaries/6.4-2017.11/aarch64-linux-gnu/${G_CROSS_COMPILER_ARCHIVE}"
67 67
68 ############## user rootfs packages ########## 68 ############## user rootfs packages ##########
69 readonly G_USER_PACKAGES="" 69 readonly G_USER_PACKAGES=""
70 70
71 export LC_ALL=C 71 export LC_ALL=C
72 72
73 SOM="smarc-imx8m" 73 SOM="smarc-imx8m"
74 74
75 #### Input params ##### 75 #### Input params #####
76 PARAM_DEB_LOCAL_MIRROR="${DEF_DEBIAN_MIRROR}" 76 PARAM_DEB_LOCAL_MIRROR="${DEF_DEBIAN_MIRROR}"
77 PARAM_OUTPUT_DIR="${DEF_BUILDENV}/output" 77 PARAM_OUTPUT_DIR="${DEF_BUILDENV}/output"
78 PARAM_DEBUG="0" 78 PARAM_DEBUG="0"
79 PARAM_CMD="all" 79 PARAM_CMD="all"
80 PARAM_BLOCK_DEVICE="na" 80 PARAM_BLOCK_DEVICE="na"
81 81
82 82
83 ### usage ### 83 ### usage ###
84 function usage() { 84 function usage() {
85 echo "This program version ${SCRIPT_VERSION}" 85 echo "This program version ${SCRIPT_VERSION}"
86 echo " Used for make debian(${DEB_RELEASE}) image for \"smarc-imx8m\" board" 86 echo " Used for make debian(${DEB_RELEASE}) image for \"smarc-imx8m\" board"
87 echo " and create booted sdcard" 87 echo " and create booted sdcard"
88 echo "" 88 echo ""
89 echo "Usage:" 89 echo "Usage:"
90 echo " ./${SCRIPT_NAME} options" 90 echo " ./${SCRIPT_NAME} options"
91 echo "" 91 echo ""
92 echo "Options:" 92 echo "Options:"
93 echo " -h|--help -- print this help" 93 echo " -h|--help -- print this help"
94 echo " -c|--cmd <command>" 94 echo " -c|--cmd <command>"
95 echo " Supported commands:" 95 echo " Supported commands:"
96 echo " deploy -- prepare environment for all commands" 96 echo " deploy -- prepare environment for all commands"
97 echo " all -- build or rebuild kernel/bootloader/rootfs" 97 echo " all -- build or rebuild kernel/bootloader/rootfs"
98 echo " bootloader -- build or rebuild bootloader (u-boot+SPL)" 98 echo " bootloader -- build or rebuild bootloader (u-boot+SPL)"
99 echo " kernel -- build or rebuild linux kernel for this board" 99 echo " kernel -- build or rebuild linux kernel for this board"
100 echo " modules -- build or rebuild linux kernel modules and install in rootfs directory for this board" 100 echo " modules -- build or rebuild linux kernel modules and install in rootfs directory for this board"
101 echo " rootfs -- build or rebuild debian rootfs filesystem (includes: make debian apks, make and install kernel moduled," 101 echo " rootfs -- build or rebuild debian rootfs filesystem (includes: make debian apks, make and install kernel moduled,"
102 echo " make and install extern modules (wifi/bt), create rootfs.tar.gz)" 102 echo " make and install extern modules (wifi/bt), create rootfs.tar.gz)"
103 echo " rtar -- generate or regenerate rootfs.tar.gz image from rootfs folder " 103 echo " rtar -- generate or regenerate rootfs.tar.gz image from rootfs folder "
104 echo " clean -- clean all build artifacts (not delete sources code and resulted images (output folder))" 104 echo " clean -- clean all build artifacts (not delete sources code and resulted images (output folder))"
105 echo " sdcard -- create bootting sdcard for this device" 105 echo " sdcard -- create bootting sdcard for this device"
106 echo " -o|--output -- custom select output directory (default: \"${PARAM_OUTPUT_DIR}\")" 106 echo " -o|--output -- custom select output directory (default: \"${PARAM_OUTPUT_DIR}\")"
107 echo " -d|--dev -- select sdcard device (exmple: -d /dev/sde)" 107 echo " -d|--dev -- select sdcard device (exmple: -d /dev/sde)"
108 echo " --debug -- enable debug mode for this script" 108 echo " --debug -- enable debug mode for this script"
109 echo "Examples of use:" 109 echo "Examples of use:"
110 echo " make only linux kernel for board: sudo ./${SCRIPT_NAME} --cmd kernel" 110 echo " make only linux kernel for board: sudo ./${SCRIPT_NAME} --cmd kernel"
111 echo " make only rootfs for board: sudo ./${SCRIPT_NAME} --cmd rootfs" 111 echo " make only rootfs for board: sudo ./${SCRIPT_NAME} --cmd rootfs"
112 echo " create boot sdcard: sudo ./${SCRIPT_NAME} --cmd sdcard --dev /dev/sdX" 112 echo " create boot sdcard: sudo ./${SCRIPT_NAME} --cmd sdcard --dev /dev/sdX"
113 echo " deploy and build: ./${SCRIPT_NAME} --cmd deploy && sudo ./${SCRIPT_NAME} --cmd all" 113 echo " deploy and build: ./${SCRIPT_NAME} --cmd deploy && sudo ./${SCRIPT_NAME} --cmd all"
114 echo "" 114 echo ""
115 } 115 }
116 116
117 ###### parse input arguments ## 117 ###### parse input arguments ##
118 readonly SHORTOPTS="c:o:d:s:h" 118 readonly SHORTOPTS="c:o:d:s:h"
119 readonly LONGOPTS="cmd:,output:,dev:,som:,help,debug" 119 readonly LONGOPTS="cmd:,output:,dev:,som:,help,debug"
120 120
121 ARGS=$(getopt -s bash --options ${SHORTOPTS} \ 121 ARGS=$(getopt -s bash --options ${SHORTOPTS} \
122 --longoptions ${LONGOPTS} --name ${SCRIPT_NAME} -- "$@" ) 122 --longoptions ${LONGOPTS} --name ${SCRIPT_NAME} -- "$@" )
123 123
124 eval set -- "$ARGS" 124 eval set -- "$ARGS"
125 125
126 while true; do 126 while true; do
127 case $1 in 127 case $1 in
128 -c|--cmd ) # script command 128 -c|--cmd ) # script command
129 shift 129 shift
130 PARAM_CMD="$1"; 130 PARAM_CMD="$1";
131 ;; 131 ;;
132 -o|--output ) # select output dir 132 -o|--output ) # select output dir
133 shift 133 shift
134 PARAM_OUTPUT_DIR="$1"; 134 PARAM_OUTPUT_DIR="$1";
135 ;; 135 ;;
136 -d|--dev ) # block device (for create sdcard) 136 -d|--dev ) # block device (for create sdcard)
137 shift 137 shift
138 [ -e ${1} ] && { 138 [ -e ${1} ] && {
139 PARAM_BLOCK_DEVICE=${1}; 139 PARAM_BLOCK_DEVICE=${1};
140 }; 140 };
141 ;; 141 ;;
142 --debug ) # enable debug 142 --debug ) # enable debug
143 PARAM_DEBUG=1; 143 PARAM_DEBUG=1;
144 ;; 144 ;;
145 -h|--help ) # get help 145 -h|--help ) # get help
146 usage 146 usage
147 exit 0; 147 exit 0;
148 ;; 148 ;;
149 -s|--som ) # target SOM 149 -s|--som ) # target SOM
150 shift 150 shift
151 SOM="$1"; 151 SOM="$1";
152 ;; 152 ;;
153 -- ) 153 -- )
154 shift 154 shift
155 break 155 break
156 ;; 156 ;;
157 * ) 157 * )
158 shift 158 shift
159 break 159 break
160 ;; 160 ;;
161 esac 161 esac
162 shift 162 shift
163 done 163 done
164 164
165 ## enable tarce options in debug mode 165 ## enable tarce options in debug mode
166 [ "${PARAM_DEBUG}" = "1" ] && { 166 [ "${PARAM_DEBUG}" = "1" ] && {
167 echo "Debug mode enabled!" 167 echo "Debug mode enabled!"
168 set -x 168 set -x
169 }; 169 };
170 170
171 if [ "${SOM}" = "smarc-imx8m" ]; then 171 if [ "${SOM}" = "smarc-imx8m" ]; then
172 IMXGSTPLG="imx-gst1.0-plugin-mx8mq" 172 IMXGSTPLG="imx-gst1.0-plugin-mx8mq"
173 else 173 else
174 echo "Unknown target SOM ${SOM}" 174 echo "Unknown target SOM ${SOM}"
175 exit 1 175 exit 1
176 fi 176 fi
177 177
178 if [ -d ${G_EMBEDIAN_PATH}/${SOM} ]; then 178 if [ -d ${G_EMBEDIAN_PATH}/${SOM} ]; then
179 echo "Building Debian for SOM ${SOM}" 179 echo "Building Debian for SOM ${SOM}"
180 else 180 else
181 echo "Missing custom files for SOM ${SOM}" 181 echo "Missing custom files for SOM ${SOM}"
182 exit 1 182 exit 1
183 fi 183 fi
184 184
185 ## declarate dinamic variables ## 185 ## declarate dinamic variables ##
186 readonly G_ROOTFS_TARBAR_PATH="${PARAM_OUTPUT_DIR}/${DEF_ROOTFS_TARBAR_NAME}" 186 readonly G_ROOTFS_TARBAR_PATH="${PARAM_OUTPUT_DIR}/${DEF_ROOTFS_TARBAR_NAME}"
187 187
188 ###### local functions ###### 188 ###### local functions ######
189 189
190 ### printing functions ### 190 ### printing functions ###
191 191
192 # print error message 192 # print error message
193 # $1 - printing string 193 # $1 - printing string
194 function pr_error() { 194 function pr_error() {
195 echo "E: $1" 195 echo "E: $1"
196 } 196 }
197 197
198 # print warning message 198 # print warning message
199 # $1 - printing string 199 # $1 - printing string
200 function pr_warning() { 200 function pr_warning() {
201 echo "W: $1" 201 echo "W: $1"
202 } 202 }
203 203
204 # print info message 204 # print info message
205 # $1 - printing string 205 # $1 - printing string
206 function pr_info() { 206 function pr_info() {
207 echo "I: $1" 207 echo "I: $1"
208 } 208 }
209 209
210 # print debug message 210 # print debug message
211 # $1 - printing string 211 # $1 - printing string
212 function pr_debug() { 212 function pr_debug() {
213 echo "D: $1" 213 echo "D: $1"
214 } 214 }
215 215
216 ### work functions ### 216 ### work functions ###
217 217
218 # get sources from git repository 218 # get sources from git repository
219 # $1 - git repository 219 # $1 - git repository
220 # $2 - branch name 220 # $2 - branch name
221 # $3 - output dir 221 # $3 - output dir
222 # $4 - commit id 222 # $4 - commit id
223 function get_git_src() { 223 function get_git_src() {
224 # clone src code 224 # clone src code
225 git clone ${1} -b ${2} ${3} 225 git clone ${1} -b ${2} ${3}
226 cd ${3} 226 cd ${3}
227 git reset --hard ${4} 227 git reset --hard ${4}
228 RET=$? 228 RET=$?
229 cd - 229 cd -
230 return $RET 230 return $RET
231 } 231 }
232 232
233 # get remote file 233 # get remote file
234 # $1 - remote file 234 # $1 - remote file
235 # $2 - local file 235 # $2 - local file
236 function get_remote_file() { 236 function get_remote_file() {
237 # download remote file 237 # download remote file
238 wget -c ${1} -O ${2} 238 wget -c ${1} -O ${2}
239 return $? 239 return $?
240 } 240 }
241 241
242 function make_prepare() { 242 function make_prepare() {
243 ## create src dir 243 ## create src dir
244 mkdir -p ${DEF_SRC_DIR} && :; 244 mkdir -p ${DEF_SRC_DIR} && :;
245 245
246 ## create toolchain dir 246 ## create toolchain dir
247 mkdir -p ${G_TOOLS_PATH} && :; 247 mkdir -p ${G_TOOLS_PATH} && :;
248 248
249 ## create rootfs dir 249 ## create rootfs dir
250 mkdir -p ${G_ROOTFS_DIR} && :; 250 mkdir -p ${G_ROOTFS_DIR} && :;
251 251
252 ## create out dir 252 ## create out dir
253 mkdir -p ${PARAM_OUTPUT_DIR} && :; 253 mkdir -p ${PARAM_OUTPUT_DIR} && :;
254 254
255 ## create tmp dir 255 ## create tmp dir
256 mkdir -p ${G_TMP_DIR} && :; 256 mkdir -p ${G_TMP_DIR} && :;
257 } 257 }
258 258
259 # function generate rootfs in input dir 259 # function generate rootfs in input dir
260 # $1 - rootfs base dir 260 # $1 - rootfs base dir
261 function make_debian_rootfs() { 261 function make_debian_rootfs() {
262 local ROOTFS_BASE=$1 262 local ROOTFS_BASE=$1
263 263
264 pr_info "Make debian(${DEB_RELEASE}) rootfs start..." 264 pr_info "Make debian(${DEB_RELEASE}) rootfs start..."
265 265
266 ## umount previus mounts (if fail) 266 ## umount previus mounts (if fail)
267 umount ${ROOTFS_BASE}/{sys,proc,dev/pts,dev} 2>/dev/null && :; 267 umount ${ROOTFS_BASE}/{sys,proc,dev/pts,dev} 2>/dev/null && :;
268 268
269 ## clear rootfs dir 269 ## clear rootfs dir
270 rm -rf ${ROOTFS_BASE}/* && :; 270 rm -rf ${ROOTFS_BASE}/* && :;
271 271
272 pr_info "rootfs: debootstrap" 272 pr_info "rootfs: debootstrap"
273 debootstrap --verbose --foreign --arch arm64 ${DEB_RELEASE} ${ROOTFS_BASE}/ ${PARAM_DEB_LOCAL_MIRROR} 273 debootstrap --verbose --foreign --arch arm64 ${DEB_RELEASE} ${ROOTFS_BASE}/ ${PARAM_DEB_LOCAL_MIRROR}
274 274
275 ## prepare qemu 275 ## prepare qemu
276 pr_info "rootfs: debootstrap in rootfs (second-stage)" 276 pr_info "rootfs: debootstrap in rootfs (second-stage)"
277 cp /usr/bin/qemu-aarch64-static ${ROOTFS_BASE}/usr/bin/ 277 cp /usr/bin/qemu-aarch64-static ${ROOTFS_BASE}/usr/bin/
278 mount -o bind /proc ${ROOTFS_BASE}/proc 278 mount -o bind /proc ${ROOTFS_BASE}/proc
279 mount -o bind /dev ${ROOTFS_BASE}/dev 279 mount -o bind /dev ${ROOTFS_BASE}/dev
280 mount -o bind /dev/pts ${ROOTFS_BASE}/dev/pts 280 mount -o bind /dev/pts ${ROOTFS_BASE}/dev/pts
281 mount -o bind /sys ${ROOTFS_BASE}/sys 281 mount -o bind /sys ${ROOTFS_BASE}/sys
282 chroot $ROOTFS_BASE /debootstrap/debootstrap --second-stage 282 chroot $ROOTFS_BASE /debootstrap/debootstrap --second-stage
283 283
284 # delete unused folder 284 # delete unused folder
285 chroot $ROOTFS_BASE rm -rf ${ROOTFS_BASE}/debootstrap 285 chroot $ROOTFS_BASE rm -rf ${ROOTFS_BASE}/debootstrap
286 286
287 pr_info "rootfs: generate default configs" 287 pr_info "rootfs: generate default configs"
288 mkdir -p ${ROOTFS_BASE}/etc/sudoers.d/ 288 mkdir -p ${ROOTFS_BASE}/etc/sudoers.d/
289 echo "user ALL=(root) /usr/bin/apt-get, /usr/bin/dpkg, /usr/bin/vi, /sbin/reboot" > ${ROOTFS_BASE}/etc/sudoers.d/user 289 echo "user ALL=(root) /usr/bin/apt-get, /usr/bin/dpkg, /usr/bin/vi, /sbin/reboot" > ${ROOTFS_BASE}/etc/sudoers.d/user
290 chmod 0440 ${ROOTFS_BASE}/etc/sudoers.d/user 290 chmod 0440 ${ROOTFS_BASE}/etc/sudoers.d/user
291 291
292 mkdir -p ${ROOTFS_BASE}/srv/local-apt-repository 292 mkdir -p ${ROOTFS_BASE}/srv/local-apt-repository
293 cp -r ${G_EMBEDIAN_PATH}/deb/* ${ROOTFS_BASE}/srv/local-apt-repository 293 cp -r ${G_EMBEDIAN_PATH}/deb/* ${ROOTFS_BASE}/srv/local-apt-repository
294 294
295 ## added mirror to source list 295 ## added mirror to source list
296 echo "deb ${DEF_DEBIAN_MIRROR} ${DEB_RELEASE} main contrib non-free 296 echo "deb ${DEF_DEBIAN_MIRROR} ${DEB_RELEASE} main contrib non-free
297 deb-src ${DEF_DEBIAN_MIRROR} ${DEB_RELEASE} main contrib non-free 297 deb-src ${DEF_DEBIAN_MIRROR} ${DEB_RELEASE} main contrib non-free
298 deb ${DEF_DEBIAN_MIRROR} ${DEB_RELEASE}-backports main contrib non-free 298 deb ${DEF_DEBIAN_MIRROR} ${DEB_RELEASE}-backports main contrib non-free
299 deb-src ${DEF_DEBIAN_MIRROR} ${DEB_RELEASE}-backports main contrib non-free 299 deb-src ${DEF_DEBIAN_MIRROR} ${DEB_RELEASE}-backports main contrib non-free
300 " > etc/apt/sources.list 300 " > etc/apt/sources.list
301 301
302 ## raise backports priority 302 ## raise backports priority
303 echo "Package: * 303 echo "Package: *
304 Pin: release n=${DEB_RELEASE}-backports 304 Pin: release n=${DEB_RELEASE}-backports
305 Pin-Priority: 500 305 Pin-Priority: 500
306 " > etc/apt/preferences.d/backports 306 " > etc/apt/preferences.d/backports
307 307
308 ## maximize local repo priority 308 ## maximize local repo priority
309 echo "Package: * 309 echo "Package: *
310 Pin: origin "" 310 Pin: origin ""
311 Pin-Priority: 1000 311 Pin-Priority: 1000
312 " > etc/apt/preferences.d/local 312 " > etc/apt/preferences.d/local
313 313
314 echo " 314 echo "
315 # /dev/mmcblk0p1 /boot vfat defaults 0 0 315 # /dev/mmcblk0p1 /boot vfat defaults 0 0
316 " > etc/fstab 316 " > etc/fstab
317 317
318 echo "smarc-imx8m" > etc/hostname 318 echo "smarc-imx8m" > etc/hostname
319 319
320 echo "auto lo 320 echo "auto lo
321 iface lo inet loopback 321 iface lo inet loopback
322 " > etc/network/interfaces 322 " > etc/network/interfaces
323 323
324 echo " 324 echo "
325 locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8 325 locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8
326 locales locales/default_environment_locale select en_US.UTF-8 326 locales locales/default_environment_locale select en_US.UTF-8
327 console-common console-data/keymap/policy select Select keymap from full list 327 console-common console-data/keymap/policy select Select keymap from full list
328 keyboard-configuration keyboard-configuration/variant select 'English (US)' 328 keyboard-configuration keyboard-configuration/variant select 'English (US)'
329 openssh-server openssh-server/permit-root-login select true 329 openssh-server openssh-server/permit-root-login select true
330 " > debconf.set 330 " > debconf.set
331 331
332 pr_info "rootfs: prepare install packages in rootfs" 332 pr_info "rootfs: prepare install packages in rootfs"
333 ## apt-get install without starting 333 ## apt-get install without starting
334 cat > ${ROOTFS_BASE}/usr/sbin/policy-rc.d << EOF 334 cat > ${ROOTFS_BASE}/usr/sbin/policy-rc.d << EOF
335 #!/bin/sh 335 #!/bin/sh
336 exit 101 336 exit 101
337 EOF 337 EOF
338 338
339 chmod +x ${ROOTFS_BASE}/usr/sbin/policy-rc.d 339 chmod +x ${ROOTFS_BASE}/usr/sbin/policy-rc.d
340 340
341 ## third packages stage 341 ## third packages stage
342 cat > third-stage << EOF 342 cat > third-stage << EOF
343 #!/bin/bash 343 #!/bin/bash
344 # apply debconfig options 344 # apply debconfig options
345 debconf-set-selections /debconf.set 345 debconf-set-selections /debconf.set
346 rm -f /debconf.set 346 rm -f /debconf.set
347 347
348 348
349 function protected_install() { 349 function protected_install() {
350 local _name=\${1} 350 local _name=\${1}
351 local repeated_cnt=5; 351 local repeated_cnt=5;
352 local RET_CODE=1; 352 local RET_CODE=1;
353 353
354 echo Installing \${_name} 354 echo Installing \${_name}
355 for (( c=0; c<\${repeated_cnt}; c++ )) 355 for (( c=0; c<\${repeated_cnt}; c++ ))
356 do 356 do
357 apt install -y \${_name} && { 357 apt install -y \${_name} && {
358 RET_CODE=0; 358 RET_CODE=0;
359 break; 359 break;
360 }; 360 };
361 361
362 echo "" 362 echo ""
363 echo "###########################" 363 echo "###########################"
364 echo "## Fix missing packages ###" 364 echo "## Fix missing packages ###"
365 echo "###########################" 365 echo "###########################"
366 echo "" 366 echo ""
367 367
368 sleep 2; 368 sleep 2;
369 369
370 apt --fix-broken install -y && { 370 apt --fix-broken install -y && {
371 RET_CODE=0; 371 RET_CODE=0;
372 break; 372 break;
373 }; 373 };
374 done 374 done
375 375
376 return \${RET_CODE} 376 return \${RET_CODE}
377 } 377 }
378 378
379 # update packages and install base 379 # update packages and install base
380 apt-get update || apt-get upgrade 380 apt-get update || apt-get upgrade
381 381
382 # local-apt-repository support 382 # local-apt-repository support
383 protected_install local-apt-repository 383 protected_install local-apt-repository
384 384
385 # update packages and install base 385 # update packages and install base
386 apt-get update || apt-get upgrade 386 apt-get update || apt-get upgrade
387 387
388 protected_install locales 388 protected_install locales
389 protected_install ntp 389 protected_install ntp
390 protected_install openssh-server 390 protected_install openssh-server
391 protected_install nfs-common 391 protected_install nfs-common
392 392
393 # packages required when flashing emmc 393 # packages required when flashing emmc
394 protected_install dosfstools 394 protected_install dosfstools
395 395
396 # fix config for sshd (permit root login) 396 # fix config for sshd (permit root login)
397 sed -i -e 's/#PermitRootLogin.*/PermitRootLogin\tyes/g' /etc/ssh/sshd_config 397 sed -i -e 's/#PermitRootLogin.*/PermitRootLogin\tyes/g' /etc/ssh/sshd_config
398 398
399 # net-tools (ifconfig, etc.) 399 # net-tools (ifconfig, etc.)
400 protected_install net-tools 400 protected_install net-tools
401 protected_install network-manager 401 protected_install network-manager
402 402
403 # sdma package 403 # sdma package
404 protected_install imx-firmware-sdma 404 protected_install imx-firmware-sdma
405 405
406 # graphical packages 406 # graphical packages
407 protected_install libdrm-vivante1 407 protected_install libdrm-vivante1
408 protected_install imx-gpu-viv-core 408 protected_install imx-gpu-viv-core
409 protected_install weston 409 protected_install weston
410 410
411 # added alsa & gstreamer 411 # added alsa & gstreamer
412 protected_install alsa-utils 412 protected_install alsa-utils
413 protected_install gstreamer1.0-alsa 413 protected_install gstreamer1.0-alsa
414 protected_install gstreamer1.0-plugins-bad 414 protected_install gstreamer1.0-plugins-bad
415 protected_install gstreamer1.0-plugins-base 415 protected_install gstreamer1.0-plugins-base
416 protected_install gstreamer1.0-plugins-base-apps 416 protected_install gstreamer1.0-plugins-base-apps
417 protected_install gstreamer1.0-plugins-ugly 417 protected_install gstreamer1.0-plugins-ugly
418 protected_install gstreamer1.0-plugins-good 418 protected_install gstreamer1.0-plugins-good
419 protected_install gstreamer1.0-tools 419 protected_install gstreamer1.0-tools
420 protected_install ${IMXGSTPLG} 420 protected_install ${IMXGSTPLG}
421 421
422 # added i2c tools 422 # added i2c tools
423 protected_install i2c-tools 423 protected_install i2c-tools
424 424
425 # added usb tools 425 # added usb tools
426 protected_install usbutils 426 protected_install usbutils
427 427
428 # added net tools 428 # added net tools
429 protected_install iperf 429 protected_install iperf
430 430
431 # mtd 431 # mtd
432 protected_install mtd-utils 432 protected_install mtd-utils
433 433
434 # bluetooth 434 # bluetooth
435 protected_install bluetooth 435 protected_install bluetooth
436 protected_install bluez-obexd 436 protected_install bluez-obexd
437 protected_install bluez-tools 437 protected_install bluez-tools
438 protected_install blueman 438 protected_install blueman
439 protected_install gconf2 439 protected_install gconf2
440 440
441 # wifi support packages 441 # wifi support packages
442 #protected_install hostapd 442 #protected_install hostapd
443 protected_install udhcpd 443 protected_install udhcpd
444 444
445 # can support 445 # can support
446 protected_install can-utils 446 protected_install can-utils
447 447
448 apt-get -y autoremove 448 apt-get -y autoremove
449 449
450 # create users and set password 450 # create users and set password
451 useradd -m -G audio -s /bin/bash user 451 useradd -m -G audio -s /bin/bash user
452 usermod -a -G video user 452 usermod -a -G video user
453 echo "user:user" | chpasswd 453 echo "user:user" | chpasswd
454 echo "root:root" | chpasswd 454 echo "root:root" | chpasswd
455 455
456 # sado kill 456 # sado kill
457 rm -f third-stage 457 rm -f third-stage
458 EOF 458 EOF
459 459
460 pr_info "rootfs: install selected debian packages (third-stage)" 460 pr_info "rootfs: install selected debian packages (third-stage)"
461 chmod +x third-stage 461 chmod +x third-stage
462 chroot ${ROOTFS_BASE} /third-stage 462 chroot ${ROOTFS_BASE} /third-stage
463 463
464 ### install weston service 464 ### install weston service
465 install -d -m 0755 ${ROOTFS_BASE}/etc/xdg/weston 465 install -d -m 0755 ${ROOTFS_BASE}/etc/xdg/weston
466 install -m 0644 ${G_EMBEDIAN_PATH}/${SOM}/weston.ini ${ROOTFS_BASE}/etc/xdg/weston 466 install -m 0644 ${G_EMBEDIAN_PATH}/${SOM}/weston.ini ${ROOTFS_BASE}/etc/xdg/weston
467 install -m 0755 ${G_EMBEDIAN_PATH}/${SOM}/weston.config ${ROOTFS_BASE}/etc/default/weston 467 install -m 0755 ${G_EMBEDIAN_PATH}/${SOM}/weston.config ${ROOTFS_BASE}/etc/default/weston
468 install -m 0755 ${G_EMBEDIAN_PATH}/weston-start ${ROOTFS_BASE}/usr/bin/weston-start 468 install -m 0755 ${G_EMBEDIAN_PATH}/weston-start ${ROOTFS_BASE}/usr/bin/weston-start
469 install -m 0755 ${G_EMBEDIAN_PATH}/weston.profile ${ROOTFS_BASE}/etc/profile.d/weston.sh 469 install -m 0755 ${G_EMBEDIAN_PATH}/weston.profile ${ROOTFS_BASE}/etc/profile.d/weston.sh
470 install -m 0644 ${G_EMBEDIAN_PATH}/weston.service ${ROOTFS_BASE}/lib/systemd/system 470 install -m 0644 ${G_EMBEDIAN_PATH}/weston.service ${ROOTFS_BASE}/lib/systemd/system
471 ln -s /lib/systemd/system/weston.service \ 471 ln -s /lib/systemd/system/weston.service \
472 ${ROOTFS_BASE}/etc/systemd/system/multi-user.target.wants/weston.service 472 ${ROOTFS_BASE}/etc/systemd/system/multi-user.target.wants/weston.service
473 473
474 ## end packages stage ## 474 ## end packages stage ##
475 [ "${G_USER_PACKAGES}" != "" ] && { 475 [ "${G_USER_PACKAGES}" != "" ] && {
476 476
477 pr_info "rootfs: install user defined packages (user-stage)" 477 pr_info "rootfs: install user defined packages (user-stage)"
478 pr_info "rootfs: G_USER_PACKAGES \"${G_USER_PACKAGES}\" " 478 pr_info "rootfs: G_USER_PACKAGES \"${G_USER_PACKAGES}\" "
479 479
480 echo "#!/bin/bash 480 echo "#!/bin/bash
481 # update packages 481 # update packages
482 apt-get update 482 apt-get update
483 apt-get upgrade 483 apt-get upgrade
484 484
485 # install all user packages 485 # install all user packages
486 apt-get -y install ${G_USER_PACKAGES} 486 apt-get -y install ${G_USER_PACKAGES}
487 487
488 rm -f user-stage 488 rm -f user-stage
489 " > user-stage 489 " > user-stage
490 490
491 chmod +x user-stage 491 chmod +x user-stage
492 chroot ${ROOTFS_BASE} /user-stage 492 chroot ${ROOTFS_BASE} /user-stage
493 493
494 }; 494 };
495 495
496 ## binaries rootfs patching ## 496 ## binaries rootfs patching ##
497 install -m 0644 ${G_EMBEDIAN_PATH}/issue ${ROOTFS_BASE}/etc/ 497 install -m 0644 ${G_EMBEDIAN_PATH}/issue ${ROOTFS_BASE}/etc/
498 install -m 0644 ${G_EMBEDIAN_PATH}/issue.net ${ROOTFS_BASE}/etc/ 498 install -m 0644 ${G_EMBEDIAN_PATH}/issue.net ${ROOTFS_BASE}/etc/
499 install -m 0755 ${G_EMBEDIAN_PATH}/rc.local ${ROOTFS_BASE}/etc/ 499 install -m 0755 ${G_EMBEDIAN_PATH}/rc.local ${ROOTFS_BASE}/etc/
500 install -m 0644 ${G_EMBEDIAN_PATH}/splash.bmp ${ROOTFS_BASE}/boot/ 500 install -m 0644 ${G_EMBEDIAN_PATH}/splash.bmp ${ROOTFS_BASE}/boot/
501 cp ${PARAM_OUTPUT_DIR}/Image ${ROOTFS_BASE}/boot 501 cp ${PARAM_OUTPUT_DIR}/Image ${ROOTFS_BASE}/boot
502 cp ${PARAM_OUTPUT_DIR}/*.dtb ${ROOTFS_BASE}/boot 502 cp ${PARAM_OUTPUT_DIR}/*.dtb ${ROOTFS_BASE}/boot
503 ln -sf fsl-smarcimx8mq${DISPLAY}.dtb ${ROOTFS_BASE}/boot/fsl-smarcimx8mq.dtb 503 ln -sf fsl-smarcimx8mq${DISPLAY}.dtb ${ROOTFS_BASE}/boot/fsl-smarcimx8mq.dtb
504 504
505 mkdir -p ${ROOTFS_BASE}/usr/share/images/desktop-base/ 505 mkdir -p ${ROOTFS_BASE}/usr/share/images/desktop-base/
506 install -m 0644 ${G_EMBEDIAN_PATH}/wallpaper.png \ 506 install -m 0644 ${G_EMBEDIAN_PATH}/wallpaper.png \
507 ${ROOTFS_BASE}/usr/share/images/desktop-base/default 507 ${ROOTFS_BASE}/usr/share/images/desktop-base/default
508 508
509 ## added alsa default configs ## 509 ## added alsa default configs ##
510 install -m 0644 ${G_EMBEDIAN_PATH}/asound.state ${ROOTFS_BASE}/var/lib/alsa/ 510 install -m 0644 ${G_EMBEDIAN_PATH}/asound.state ${ROOTFS_BASE}/var/lib/alsa/
511 install -m 0644 ${G_EMBEDIAN_PATH}/asound.conf ${ROOTFS_BASE}/etc/ 511 install -m 0644 ${G_EMBEDIAN_PATH}/asound.conf ${ROOTFS_BASE}/etc/
512 512
513 ## Revert regular booting 513 ## Revert regular booting
514 rm -f ${ROOTFS_BASE}/usr/sbin/policy-rc.d 514 rm -f ${ROOTFS_BASE}/usr/sbin/policy-rc.d
515 515
516 ## install kernel modules in rootfs 516 ## install kernel modules in rootfs
517 install_kernel_modules ${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_LINUX_KERNEL_DEF_CONFIG} ${G_LINUX_KERNEL_SRC_DIR} ${ROOTFS_BASE} || { 517 install_kernel_modules ${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_LINUX_KERNEL_DEF_CONFIG} ${G_LINUX_KERNEL_SRC_DIR} ${ROOTFS_BASE} || {
518 pr_error "Failed #$? in function install_kernel_modules" 518 pr_error "Failed #$? in function install_kernel_modules"
519 return 2; 519 return 2;
520 } 520 }
521 521
522 ## copy all kernel headers for development 522 ## copy all kernel headers for development
523 mkdir -p ${ROOTFS_BASE}/usr/local/src/linux-imx/drivers/staging/android/uapi 523 mkdir -p ${ROOTFS_BASE}/usr/local/src/linux-imx/drivers/staging/android/uapi
524 cp ${G_LINUX_KERNEL_SRC_DIR}/drivers/staging/android/uapi/* ${ROOTFS_BASE}/usr/local/src/linux-imx/drivers/staging/android/uapi 524 cp ${G_LINUX_KERNEL_SRC_DIR}/drivers/staging/android/uapi/* ${ROOTFS_BASE}/usr/local/src/linux-imx/drivers/staging/android/uapi
525 cp -r ${G_LINUX_KERNEL_SRC_DIR}/include ${ROOTFS_BASE}/usr/local/src/linux-imx/ 525 cp -r ${G_LINUX_KERNEL_SRC_DIR}/include ${ROOTFS_BASE}/usr/local/src/linux-imx/
526 526
527 ## copy custom files 527 ## copy custom files
528 cp ${G_EMBEDIAN_PATH}/10-imx.rules ${ROOTFS_BASE}/etc/udev/rules.d 528 cp ${G_EMBEDIAN_PATH}/10-imx.rules ${ROOTFS_BASE}/etc/udev/rules.d
529 cp ${G_EMBEDIAN_PATH}/${SOM}/*.rules ${ROOTFS_BASE}/etc/udev/rules.d 529 cp ${G_EMBEDIAN_PATH}/${SOM}/*.rules ${ROOTFS_BASE}/etc/udev/rules.d
530 530
531 531
532 ## clenup command 532 ## clenup command
533 echo "#!/bin/bash 533 echo "#!/bin/bash
534 apt-get clean 534 apt-get clean
535 rm -f cleanup 535 rm -f cleanup
536 " > cleanup 536 " > cleanup
537 537
538 # clean all packages 538 # clean all packages
539 pr_info "rootfs: clean" 539 pr_info "rootfs: clean"
540 chmod +x cleanup 540 chmod +x cleanup
541 chroot ${ROOTFS_BASE} /cleanup 541 chroot ${ROOTFS_BASE} /cleanup
542 umount ${ROOTFS_BASE}/{sys,proc,dev/pts,dev} 542 umount ${ROOTFS_BASE}/{sys,proc,dev/pts,dev}
543 543
544 ## kill latest dbus-daemon instance due to qemu-aarch64-static 544 ## kill latest dbus-daemon instance due to qemu-aarch64-static
545 QEMU_PROC_ID=$(ps axf | grep dbus-daemon | grep qemu-aarch64-static | awk '{print $1}') 545 QEMU_PROC_ID=$(ps axf | grep dbus-daemon | grep qemu-aarch64-static | awk '{print $1}')
546 if [ -n "$QEMU_PROC_ID" ] 546 if [ -n "$QEMU_PROC_ID" ]
547 then 547 then
548 kill -9 $QEMU_PROC_ID 548 kill -9 $QEMU_PROC_ID
549 fi 549 fi
550 550
551 rm ${ROOTFS_BASE}/usr/bin/qemu-aarch64-static 551 rm ${ROOTFS_BASE}/usr/bin/qemu-aarch64-static
552 552
553 return 0; 553 return 0;
554 } 554 }
555 555
556 # make tarbar arx from footfs 556 # make tarbar arx from footfs
557 # $1 -- packet folder 557 # $1 -- packet folder
558 # $2 -- output arx full name 558 # $2 -- output arx full name
559 function make_tarbar() { 559 function make_tarbar() {
560 cd $1 560 cd $1
561 561
562 chown root:root . 562 chown root:root .
563 pr_info "make tarbar arx from folder ${1}" 563 pr_info "make tarbar arx from folder ${1}"
564 pr_info "Remove old arx $2" 564 pr_info "Remove old arx $2"
565 rm $2 > /dev/null 2>&1 && :; 565 rm $2 > /dev/null 2>&1 && :;
566 566
567 pr_info "Create $2" 567 pr_info "Create $2"
568 568
569 tar czf $2 . 569 tar czf $2 .
570 success=$? 570 success=$?
571 [ $success -eq 0 ] || { 571 [ $success -eq 0 ] || {
572 # fail 572 # fail
573 rm $2 > /dev/null 2>&1 && :; 573 rm $2 > /dev/null 2>&1 && :;
574 }; 574 };
575 575
576 cd - 576 cd -
577 } 577 }
578 578
579 # make linux kernel modules 579 # make linux kernel modules
580 # $1 -- cross compiler prefix 580 # $1 -- cross compiler prefix
581 # $2 -- linux defconfig file 581 # $2 -- linux defconfig file
582 # $3 -- linux dtb files 582 # $3 -- linux dtb files
583 # $4 -- linux dirname 583 # $4 -- linux dirname
584 # $5 -- out path 584 # $5 -- out path
585 function make_kernel() { 585 function make_kernel() {
586 pr_info "make kernel .config" 586 pr_info "make kernel .config"
587 make ARCH=arm64 CROSS_COMPILE=${1} ${G_CROSS_COMPILER_JOPTION} -C ${4}/ ${2} 587 make ARCH=arm64 CROSS_COMPILE=${1} ${G_CROSS_COMPILER_JOPTION} -C ${4}/ ${2}
588 588
589 pr_info "make kernel" 589 pr_info "make kernel"
590 make CROSS_COMPILE=${1} ARCH=arm64 ${G_CROSS_COMPILER_JOPTION} -C ${4}/ Image 590 make CROSS_COMPILE=${1} ARCH=arm64 ${G_CROSS_COMPILER_JOPTION} -C ${4}/ Image
591 591
592 pr_info "make ${3}" 592 pr_info "make ${3}"
593 make CROSS_COMPILE=${1} ARCH=arm64 ${G_CROSS_COMPILER_JOPTION} -C ${4} ${3} 593 make CROSS_COMPILE=${1} ARCH=arm64 ${G_CROSS_COMPILER_JOPTION} -C ${4} ${3}
594 594
595 pr_info "Copy kernel and dtb files to output dir: ${5}" 595 pr_info "Copy kernel and dtb files to output dir: ${5}"
596 cp ${4}/arch/arm64/boot/Image ${5}/; 596 cp ${4}/arch/arm64/boot/Image ${5}/;
597 cp ${4}/arch/arm64/boot/dts/embedian/*.dtb ${5}/; 597 cp ${4}/arch/arm64/boot/dts/embedian/*.dtb ${5}/;
598 598
599 return 0; 599 return 0;
600 } 600 }
601 601
602 # clean kernel 602 # clean kernel
603 # $1 -- linux dir path 603 # $1 -- linux dir path
604 function clean_kernel() { 604 function clean_kernel() {
605 pr_info "Clean linux kernel" 605 pr_info "Clean linux kernel"
606 606
607 make ARCH=arm64 -C ${1}/ mrproper 607 make ARCH=arm64 -C ${1}/ mrproper
608 608
609 return 0; 609 return 0;
610 } 610 }
611 611
612 # make linux kernel modules 612 # make linux kernel modules
613 # $1 -- cross compiler prefix 613 # $1 -- cross compiler prefix
614 # $2 -- linux defconfig file 614 # $2 -- linux defconfig file
615 # $3 -- linux dirname 615 # $3 -- linux dirname
616 # $4 -- out modules path 616 # $4 -- out modules path
617 function make_kernel_modules() { 617 function make_kernel_modules() {
618 pr_info "make kernel defconfig" 618 pr_info "make kernel defconfig"
619 make ARCH=arm64 CROSS_COMPILE=${1} ${G_CROSS_COMPILER_JOPTION} -C ${3} ${2} 619 make ARCH=arm64 CROSS_COMPILE=${1} ${G_CROSS_COMPILER_JOPTION} -C ${3} ${2}
620 620
621 pr_info "Compiling kernel modules" 621 pr_info "Compiling kernel modules"
622 make ARCH=arm64 CROSS_COMPILE=${1} ${G_CROSS_COMPILER_JOPTION} -C ${3} modules 622 make ARCH=arm64 CROSS_COMPILE=${1} ${G_CROSS_COMPILER_JOPTION} -C ${3} modules
623 } 623 }
624 624
625 # install linux kernel modules 625 # install linux kernel modules
626 # $1 -- cross compiler prefix 626 # $1 -- cross compiler prefix
627 # $2 -- linux defconfig file 627 # $2 -- linux defconfig file
628 # $3 -- linux dirname 628 # $3 -- linux dirname
629 # $4 -- out modules path 629 # $4 -- out modules path
630 function install_kernel_modules() { 630 function install_kernel_modules() {
631 pr_info "Installing kernel headers to ${4}" 631 pr_info "Installing kernel headers to ${4}"
632 make ARCH=arm64 CROSS_COMPILE=${1} ${G_CROSS_COMPILER_JOPTION} -C ${3} INSTALL_HDR_PATH=${4}/usr/local headers_install 632 make ARCH=arm64 CROSS_COMPILE=${1} ${G_CROSS_COMPILER_JOPTION} -C ${3} INSTALL_HDR_PATH=${4}/usr/local headers_install
633 633
634 pr_info "Installing kernel modules to ${4}" 634 pr_info "Installing kernel modules to ${4}"
635 make ARCH=arm64 CROSS_COMPILE=${1} ${G_CROSS_COMPILER_JOPTION} -C ${3} INSTALL_MOD_PATH=${4} modules_install 635 make ARCH=arm64 CROSS_COMPILE=${1} ${G_CROSS_COMPILER_JOPTION} -C ${3} INSTALL_MOD_PATH=${4} modules_install
636 636
637 return 0; 637 return 0;
638 } 638 }
639 639
640 # make uboot 640 # make uboot
641 # $1 uboot path 641 # $1 uboot path
642 # $2 outputdir 642 # $2 outputdir
643 function make_uboot() { 643 function make_uboot() {
644 ### make emmc uboot ### 644 ### make emmc uboot ###
645 pr_info "Make SPL & u-boot: ${G_UBOOT_DEF_CONFIG}" 645 pr_info "Make SPL & u-boot: ${G_UBOOT_DEF_CONFIG}"
646 # clean work directory 646 # clean work directory
647 make ARCH=arm64 -C ${1} CROSS_COMPILE=${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_CROSS_COMPILER_JOPTION} mrproper 647 make ARCH=arm64 -C ${1} CROSS_COMPILE=${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_CROSS_COMPILER_JOPTION} mrproper
648 648
649 # make uboot config for mmc 649 # make uboot config for mmc
650 make ARCH=arm64 -C ${1} CROSS_COMPILE=${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_CROSS_COMPILER_JOPTION} ${G_UBOOT_DEF_CONFIG} 650 make ARCH=arm64 -C ${1} CROSS_COMPILE=${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_CROSS_COMPILER_JOPTION} ${G_UBOOT_DEF_CONFIG}
651 651
652 # make uboot 652 # make uboot
653 make -C ${1} CROSS_COMPILE=${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_CROSS_COMPILER_JOPTION} 653 make -C ${1} CROSS_COMPILE=${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_CROSS_COMPILER_JOPTION}
654 654
655 if [ "${SOM}" = "smarc-imx8m" ]; then 655 if [ "${SOM}" = "smarc-imx8m" ]; then
656 HDMI=yes 656 HDMI=yes
657 UBOOT_DTB="fsl-smarcimx8mq.dtb" 657 UBOOT_DTB="fsl-smarcimx8mq.dtb"
658 fi 658 fi
659 659
660 # Copy u-boot, SPL and DTB 660 # Copy u-boot, SPL and DTB
661 cd ${G_EMBEDIAN_PATH}/${SOM}/imx-mkimage 661 cd ${G_EMBEDIAN_PATH}/${SOM}/imx-mkimage
662 rm -f iMX8M/u-boot* iMX8M/*.dtb 662 rm -f iMX8M/u-boot* iMX8M/*.dtb
663 cp ${1}/u-boot.bin ${1}/u-boot-nodtb.bin ${1}/spl/u-boot-spl.bin ${1}/arch/arm/dts/${UBOOT_DTB} iMX8M/ 663 cp ${1}/u-boot.bin ${1}/u-boot-nodtb.bin ${1}/spl/u-boot-spl.bin ${1}/arch/arm/dts/${UBOOT_DTB} iMX8M/
664 664
665 # Build final image 665 # Build final image
666 if [ "${HDMI}" = "yes" ]; then 666 if [ "${HDMI}" = "yes" ]; then
667 make CROSS_COMPILE=${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_CROSS_COMPILER_JOPTION} SOC=iMX8M flash_hdmi_spl_uboot 667 make CROSS_COMPILE=${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_CROSS_COMPILER_JOPTION} SOC=iMX8M flash_hdmi_spl_uboot
668 else 668 else
669 make CROSS_COMPILE=${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_CROSS_COMPILER_JOPTION} SOC=iMX8M flash_spl_uboot 669 make CROSS_COMPILE=${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_CROSS_COMPILER_JOPTION} SOC=iMX8M flash_spl_uboot
670 fi 670 fi
671 671
672 # copy images 672 # copy images
673 cp iMX8M/flash.bin ${2}/${G_UBOOT_NAME} 673 cp iMX8M/flash.bin ${2}/${G_UBOOT_NAME}
674 674
675 return 0; 675 return 0;
676 } 676 }
677 677
678 # clean uboot 678 # clean uboot
679 # $1 -- u-boot dir path 679 # $1 -- u-boot dir path
680 function clean_uboot() { 680 function clean_uboot() {
681 pr_info "Clean uboot" 681 pr_info "Clean uboot"
682 682
683 make ARCH=arm64 -C ${1}/ mrproper 683 make ARCH=arm64 -C ${1}/ mrproper
684 684
685 return 0; 685 return 0;
686 } 686 }
687 687
688 # make sdcard for device 688 # make sdcard for device
689 # $1 -- block device 689 # $1 -- block device
690 function check_sdcard() 690 function check_sdcard()
691 { 691 {
692 # Check that parameter is a valid block device 692 # Check that parameter is a valid block device
693 if [ ! -b "$1" ]; then 693 if [ ! -b "$1" ]; then
694 pr_error "$1 is not a valid block device, exiting" 694 pr_error "$1 is not a valid block device, exiting"
695 return 1 695 return 1
696 fi 696 fi
697 697
698 local dev=$(basename $1) 698 local dev=$(basename $1)
699 699
700 # Check that /sys/block/$dev exists 700 # Check that /sys/block/$dev exists
701 if [ ! -d /sys/block/$dev ]; then 701 if [ ! -d /sys/block/$dev ]; then
702 pr_error "Directory /sys/block/${dev} missing, exiting" 702 pr_error "Directory /sys/block/${dev} missing, exiting"
703 return 1 703 return 1
704 fi 704 fi
705 705
706 # Get device parameters 706 # Get device parameters
707 local removable=$(cat /sys/block/${dev}/removable) 707 local removable=$(cat /sys/block/${dev}/removable)
708 local block_size=$(cat /sys/class/block/${dev}/queue/physical_block_size) 708 local block_size=$(cat /sys/class/block/${dev}/queue/physical_block_size)
709 local size_bytes=$((${block_size}*$(cat /sys/class/block/${dev}/size))) 709 local size_bytes=$((${block_size}*$(cat /sys/class/block/${dev}/size)))
710 local size_gib=$(bc <<< "scale=1; ${size_bytes}/(1024*1024*1024)") 710 local size_gib=$(bc <<< "scale=1; ${size_bytes}/(1024*1024*1024)")
711 711
712 # non removable SD card readers require additional check 712 # non removable SD card readers require additional check
713 if [ "${removable}" != "1" ]; then 713 if [ "${removable}" != "1" ]; then
714 local drive=$(udisksctl info -b /dev/${dev}|grep "Drive:"|cut -d"'" -f 2) 714 local drive=$(udisksctl info -b /dev/${dev}|grep "Drive:"|cut -d"'" -f 2)
715 local mediaremovable=$(gdbus call --system --dest org.freedesktop.UDisks2 --object-path ${drive} --method org.freedesktop.DBus.Properties.Get org.freedesktop.UDisks2.Drive MediaRemovable) 715 local mediaremovable=$(gdbus call --system --dest org.freedesktop.UDisks2 --object-path ${drive} --method org.freedesktop.DBus.Properties.Get org.freedesktop.UDisks2.Drive MediaRemovable)
716 if [[ "${mediaremovable}" = *"true"* ]]; then 716 if [[ "${mediaremovable}" = *"true"* ]]; then
717 removable=1 717 removable=1
718 fi 718 fi
719 fi 719 fi
720 720
721 # Check that device is either removable or loop 721 # Check that device is either removable or loop
722 if [ "$removable" != "1" -a $(stat -c '%t' /dev/$dev) != ${LOOP_MAJOR} ]; then 722 if [ "$removable" != "1" -a $(stat -c '%t' /dev/$dev) != ${LOOP_MAJOR} ]; then
723 pr_error "$1 is not a removable device, exiting" 723 pr_error "$1 is not a removable device, exiting"
724 return 1 724 return 1
725 fi 725 fi
726 726
727 # Check that device is attached 727 # Check that device is attached
728 if [ ${size_bytes} -eq 0 ]; then 728 if [ ${size_bytes} -eq 0 ]; then
729 pr_error "$1 is not attached, exiting" 729 pr_error "$1 is not attached, exiting"
730 return 1 730 return 1
731 fi 731 fi
732 732
733 pr_info "Device: ${LPARAM_BLOCK_DEVICE}, ${size_gib}GiB" 733 pr_info "Device: ${LPARAM_BLOCK_DEVICE}, ${size_gib}GiB"
734 pr_info "================================================" 734 pr_info "================================================"
735 read -p "Press Enter to continue" 735 read -p "Press Enter to continue"
736 736
737 return 0 737 return 0
738 } 738 }
739 739
740 # make sdcard for device 740 # make sdcard for device
741 # $1 -- block device 741 # $1 -- block device
742 # $2 -- output images dir 742 # $2 -- output images dir
743 function make_sdcard() { 743 function make_sdcard() {
744 readonly local LPARAM_BLOCK_DEVICE=${1} 744 readonly local LPARAM_BLOCK_DEVICE=${1}
745 readonly local LPARAM_OUTPUT_DIR=${2} 745 readonly local LPARAM_OUTPUT_DIR=${2}
746 readonly local P1_MOUNT_DIR="${G_TMP_DIR}/p1" 746 readonly local P1_MOUNT_DIR="${G_TMP_DIR}/p1"
747 readonly local P2_MOUNT_DIR="${G_TMP_DIR}/p2" 747 readonly local P2_MOUNT_DIR="${G_TMP_DIR}/p2"
748 readonly local DEBIAN_IMAGES_TO_ROOTFS_POINT="opt/images/Debian" 748 readonly local DEBIAN_IMAGES_TO_ROOTFS_POINT="opt/images/Debian"
749 749
750 readonly local BOOTLOAD_RESERVE_SIZE=2 750 readonly local BOOTLOAD_RESERVE_SIZE=2
751 readonly local PART1_SIZE=48 751 readonly local PART1_SIZE=48
752 readonly local BOOTPART=1 752 readonly local BOOTPART=1
753 readonly local ROOTFSPART=2 753 readonly local ROOTFSPART=2
754 readonly local SPARE_SIZE=4 754 readonly local SPARE_SIZE=4
755 755
756 [ "${LPARAM_BLOCK_DEVICE}" = "na" ] && { 756 [ "${LPARAM_BLOCK_DEVICE}" = "na" ] && {
757 pr_warning "No valid block device: ${LPARAM_BLOCK_DEVICE}" 757 pr_warning "No valid block device: ${LPARAM_BLOCK_DEVICE}"
758 return 1; 758 return 1;
759 }; 759 };
760 760
761 local part="" 761 local part=""
762 if [ `echo ${LPARAM_BLOCK_DEVICE} | grep -c mmcblk` -ne 0 ]; then 762 if [ `echo ${LPARAM_BLOCK_DEVICE} | grep -c mmcblk` -ne 0 ]; then
763 part="p" 763 part="p"
764 fi 764 fi
765 765
766 # Check that we're using a valid device 766 # Check that we're using a valid device
767 if ! check_sdcard ${LPARAM_BLOCK_DEVICE}; then 767 if ! check_sdcard ${LPARAM_BLOCK_DEVICE}; then
768 return 1 768 return 1
769 fi 769 fi
770 770
771 for ((i=0; i<10; i++)) 771 for ((i=0; i<10; i++))
772 do 772 do
773 if [ `mount | grep -c ${LPARAM_BLOCK_DEVICE}${part}$i` -ne 0 ]; then 773 if [ `mount | grep -c ${LPARAM_BLOCK_DEVICE}${part}$i` -ne 0 ]; then
774 umount ${LPARAM_BLOCK_DEVICE}${part}$i 774 umount ${LPARAM_BLOCK_DEVICE}${part}$i
775 fi 775 fi
776 done 776 done
777 777
778 function format_sdcard 778 function format_sdcard
779 { 779 {
780 pr_info "Formating SDCARD partitions" 780 pr_info "Formating SDCARD partitions"
781 mkfs.vfat -F 16 ${LPARAM_BLOCK_DEVICE}${part}1 -n boot 781 mkfs.vfat -F 16 ${LPARAM_BLOCK_DEVICE}${part}1 -n boot
782 mkfs.ext4 ${LPARAM_BLOCK_DEVICE}${part}2 -L rootfs 782 mkfs.ext4 ${LPARAM_BLOCK_DEVICE}${part}2 -L rootfs
783 } 783 }
784 784
785 function flash_u-boot 785 function flash_u-boot
786 { 786 {
787 pr_info "Flashing U-Boot" 787 pr_info "Flashing U-Boot"
788 dd if=${LPARAM_OUTPUT_DIR}/${G_UBOOT_NAME} of=${LPARAM_BLOCK_DEVICE} bs=1K seek=33; sync 788 dd if=${LPARAM_OUTPUT_DIR}/${G_UBOOT_NAME} of=${LPARAM_BLOCK_DEVICE} bs=1K seek=33; sync
789 } 789 }
790 790
791 function flash_sdcard 791 function flash_sdcard
792 { 792 {
793 pr_info "Flashing \"Image, device tree and rootfs\" partition" 793 pr_info "Flashing \"Image, device tree and rootfs\" partition"
794 cp -v ${LPARAM_OUTPUT_DIR}/Image ${P1_MOUNT_DIR}/ 794 cp -v ${LPARAM_OUTPUT_DIR}/Image ${P1_MOUNT_DIR}/
795 mkdir -p ${P1_MOUNT_DIR}/dtbs/ 795 mkdir -p ${P1_MOUNT_DIR}/dtbs/
796 cp -v ${LPARAM_OUTPUT_DIR}/fsl-smarcimx8mq${DISPLAY}.dtb ${P1_MOUNT_DIR}/dtbs/fsl-smarcimx8mq.dtb 796 cp -v ${LPARAM_OUTPUT_DIR}/fsl-smarcimx8mq${DISPLAY}.dtb ${P1_MOUNT_DIR}/dtbs/fsl-smarcimx8mq.dtb
797 cp -v ${G_EMBEDIAN_PATH}/uEnv.txt ${P1_MOUNT_DIR}/ 797 cp -v ${G_EMBEDIAN_PATH}/uEnv.txt ${P1_MOUNT_DIR}/
798 tar -xpf ${LPARAM_OUTPUT_DIR}/${DEF_ROOTFS_TARBAR_NAME} -C ${P2_MOUNT_DIR}/ 798 tar -xpf ${LPARAM_OUTPUT_DIR}/${DEF_ROOTFS_TARBAR_NAME} -C ${P2_MOUNT_DIR}/
799 } 799 }
800 800
801 function copy_debian_images 801 function copy_debian_images
802 { 802 {
803 mkdir -p ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT} 803 mkdir -p ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}
804 804
805 pr_info "Copying Debian images to /${DEBIAN_IMAGES_TO_ROOTFS_POINT}" 805 pr_info "Copying Debian images to /${DEBIAN_IMAGES_TO_ROOTFS_POINT}"
806 cp ${LPARAM_OUTPUT_DIR}/${DEF_ROOTFS_TARBAR_NAME} ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/${DEF_ROOTFS_TARBAR_NAME} 806 cp ${LPARAM_OUTPUT_DIR}/${DEF_ROOTFS_TARBAR_NAME} ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/${DEF_ROOTFS_TARBAR_NAME}
807 807
808 pr_info "Copying U-Boot to /${DEBIAN_IMAGES_TO_ROOTFS_POINT}" 808 pr_info "Copying U-Boot to /${DEBIAN_IMAGES_TO_ROOTFS_POINT}"
809 cp ${LPARAM_OUTPUT_DIR}/${G_UBOOT_NAME} ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/ 809 cp ${LPARAM_OUTPUT_DIR}/${G_UBOOT_NAME} ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/
810 810
811 pr_info "Copying Image and device tree files to /${DEBIAN_IMAGES_TO_ROOTFS_POINT}" 811 pr_info "Copying Image and device tree files to /${DEBIAN_IMAGES_TO_ROOTFS_POINT}"
812 cp ${LPARAM_OUTPUT_DIR}/Image ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/ 812 cp ${LPARAM_OUTPUT_DIR}/Image ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/
813 cp ${LPARAM_OUTPUT_DIR}/*.dtb ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/ 813 cp ${LPARAM_OUTPUT_DIR}/*.dtb ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/
814 cp ${G_EMBEDIAN_PATH}/uEnv_emmc.txt ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/uEnv.txt 814 cp ${G_EMBEDIAN_PATH}/uEnv_emmc.txt ${P2_MOUNT_DIR}/${DEBIAN_IMAGES_TO_ROOTFS_POINT}/uEnv.txt
815 815
816 return 0; 816 return 0;
817 } 817 }
818 818
819 function copy_scripts 819 function copy_scripts
820 { 820 {
821 pr_info "Copying scripts to /${DEBIAN_IMAGES_TO_ROOTFS_POINT}" 821 pr_info "Copying scripts to /${DEBIAN_IMAGES_TO_ROOTFS_POINT}"
822 cp ${G_EMBEDIAN_PATH}/debian-emmc.sh ${P2_MOUNT_DIR}/usr/sbin/ 822 cp ${G_EMBEDIAN_PATH}/debian-emmc.sh ${P2_MOUNT_DIR}/usr/sbin/
823 } 823 }
824 824
825 function ceildiv 825 function ceildiv
826 { 826 {
827 local num=$1 827 local num=$1
828 local div=$2 828 local div=$2
829 echo $(( (num + div - 1) / div )) 829 echo $(( (num + div - 1) / div ))
830 } 830 }
831 831
832 # Delete the partitions 832 # Delete the partitions
833 for ((i=0; i<10; i++)) 833 for ((i=0; i<10; i++))
834 do 834 do
835 if [ `ls ${LPARAM_BLOCK_DEVICE}${part}$i 2> /dev/null | grep -c ${LPARAM_BLOCK_DEVICE}${part}$i` -ne 0 ]; then 835 if [ `ls ${LPARAM_BLOCK_DEVICE}${part}$i 2> /dev/null | grep -c ${LPARAM_BLOCK_DEVICE}${part}$i` -ne 0 ]; then
836 dd if=/dev/zero of=${LPARAM_BLOCK_DEVICE}${part}$i bs=512 count=1024 836 dd if=/dev/zero of=${LPARAM_BLOCK_DEVICE}${part}$i bs=512 count=1024
837 fi 837 fi
838 done 838 done
839 sync 839 sync
840 840
841 ((echo d; echo 1; echo d; echo 2; echo d; echo 3; echo d; echo w) | fdisk ${LPARAM_BLOCK_DEVICE} &> /dev/null) || true 841 ((echo d; echo 1; echo d; echo 2; echo d; echo 3; echo d; echo w) | fdisk ${LPARAM_BLOCK_DEVICE} &> /dev/null) || true
842 sync 842 sync
843 843
844 dd if=/dev/zero of=${LPARAM_BLOCK_DEVICE} bs=1024 count=4096 844 dd if=/dev/zero of=${LPARAM_BLOCK_DEVICE} bs=1024 count=4096
845 sleep 2; sync; 845 sleep 2; sync;
846 846
847 pr_info "Creating new partitions" 847 pr_info "Creating new partitions"
848 848
849 # Create a new partition table 849 # Create a new partition table
850 850
851 # Get total card size 851 # Get total card size
852 TOTAL_SIZE=`fdisk -s ${LPARAM_BLOCK_DEVICE}` 852 TOTAL_SIZE=`fdisk -s ${LPARAM_BLOCK_DEVICE}`
853 TOTAL_SIZE=`expr ${TOTAL_SIZE} / 1024` 853 TOTAL_SIZE=`expr ${TOTAL_SIZE} / 1024`
854 ROOTFS_SIZE=`expr ${TOTAL_SIZE} - ${BOOTLOAD_RESERVE_SIZE} - ${PART1_SIZE} - ${SPARE_SIZE}` 854 ROOTFS_SIZE=`expr ${TOTAL_SIZE} - ${BOOTLOAD_RESERVE_SIZE} - ${PART1_SIZE} - ${SPARE_SIZE}`
855 855
856 pr_info "ROOT SIZE=${ROOTFS_SIZE} TOTAl SIZE=${TOTAL_SIZE}" 856 pr_info "ROOT SIZE=${ROOTFS_SIZE} TOTAl SIZE=${TOTAL_SIZE}"
857 857
858 BLOCK=`echo ${LPARAM_BLOCK_DEVICE} | cut -d "/" -f 3` 858 BLOCK=`echo ${LPARAM_BLOCK_DEVICE} | cut -d "/" -f 3`
859 SECT_SIZE_BYTES=`cat /sys/block/${BLOCK}/queue/physical_block_size` 859 SECT_SIZE_BYTES=`cat /sys/block/${BLOCK}/queue/physical_block_size`
860 860
861 BOOTLOAD_RESERVE_SIZE_BYTES=$((BOOTLOAD_RESERVE_SIZE * 1024 * 1024)) 861 BOOTLOAD_RESERVE_SIZE_BYTES=$((BOOTLOAD_RESERVE_SIZE * 1024 * 1024))
862 PART1_SIZE_BYTES=$((PART1_SIZE * 1024 * 1024)) 862 PART1_SIZE_BYTES=$((PART1_SIZE * 1024 * 1024))
863 PART1_END_BYTES=`expr ${BOOTLOAD_RESERVE_SIZE_BYTES} + ${PART1_SIZE_BYTES}` 863 PART1_END_BYTES=`expr ${BOOTLOAD_RESERVE_SIZE_BYTES} + ${PART1_SIZE_BYTES}`
864 ROOTFS_SIZE_BYTES=$((ROOTFS_SIZE * 1024 * 1024)) 864 ROOTFS_SIZE_BYTES=$((ROOTFS_SIZE * 1024 * 1024))
865 865
866 PART1_FIRST_SECT=`ceildiv ${BOOTLOAD_RESERVE_SIZE_BYTES} ${SECT_SIZE_BYTES}` 866 PART1_FIRST_SECT=`ceildiv ${BOOTLOAD_RESERVE_SIZE_BYTES} ${SECT_SIZE_BYTES}`
867 PART1_END_SECT=`ceildiv ${PART1_END_BYTES} ${SECT_SIZE_BYTES}` 867 PART1_END_SECT=`ceildiv ${PART1_END_BYTES} ${SECT_SIZE_BYTES}`
868 PART2_FIRST_SECT=`expr ${PART1_END_SECT} + 1 ` 868 PART2_FIRST_SECT=`expr ${PART1_END_SECT} + 1 `
869 869
870 (echo n; echo p; echo $BOOTPART; echo $PART1_FIRST_SECT; \ 870 (echo n; echo p; echo $BOOTPART; echo $PART1_FIRST_SECT; \
871 echo $PART1_END_SECT; echo n; echo p; echo $ROOTFSPART; \ 871 echo $PART1_END_SECT; echo n; echo p; echo $ROOTFSPART; \
872 echo $PART2_FIRST_SECT; echo; echo p; echo w) | fdisk -u ${LPARAM_BLOCK_DEVICE} > /dev/null 872 echo $PART2_FIRST_SECT; echo; echo p; echo w) | fdisk -u ${LPARAM_BLOCK_DEVICE} > /dev/null
873 873
874 sleep 2; sync; 874 sleep 2; sync;
875 fdisk -l ${LPARAM_BLOCK_DEVICE} 875 fdisk -l ${LPARAM_BLOCK_DEVICE}
876 876
877 sleep 2; sync; 877 sleep 2; sync;
878 878
879 # Format the partitions 879 # Format the partitions
880 format_sdcard 880 format_sdcard
881 sleep 2; sync; 881 sleep 2; sync;
882 882
883 flash_u-boot 883 flash_u-boot
884 sleep 2; sync; 884 sleep 2; sync;
885 885
886 # Mount the partitions 886 # Mount the partitions
887 mkdir -p ${P1_MOUNT_DIR} 887 mkdir -p ${P1_MOUNT_DIR}
888 mkdir -p ${P2_MOUNT_DIR} 888 mkdir -p ${P2_MOUNT_DIR}
889 sync 889 sync
890 890
891 mount ${LPARAM_BLOCK_DEVICE}${part}1 ${P1_MOUNT_DIR} 891 mount ${LPARAM_BLOCK_DEVICE}${part}1 ${P1_MOUNT_DIR}
892 mount ${LPARAM_BLOCK_DEVICE}${part}2 ${P2_MOUNT_DIR} 892 mount ${LPARAM_BLOCK_DEVICE}${part}2 ${P2_MOUNT_DIR}
893 sleep 2; sync; 893 sleep 2; sync;
894 894
895 flash_sdcard 895 flash_sdcard
896 copy_debian_images 896 copy_debian_images
897 copy_scripts 897 copy_scripts
898 898
899 pr_info "Sync sdcard..." 899 pr_info "Sync sdcard..."
900 sync 900 sync
901 umount ${P1_MOUNT_DIR} 901 umount ${P1_MOUNT_DIR}
902 umount ${P2_MOUNT_DIR} 902 umount ${P2_MOUNT_DIR}
903 903
904 rm -rf ${P1_MOUNT_DIR} 904 rm -rf ${P1_MOUNT_DIR}
905 rm -rf ${P2_MOUNT_DIR} 905 rm -rf ${P2_MOUNT_DIR}
906 906
907 pr_info "Done make sdcard!" 907 pr_info "Done make sdcard!"
908 908
909 return 0; 909 return 0;
910 } 910 }
911 911
912 #################### commands ################ 912 #################### commands ################
913 913
914 function cmd_make_deploy() { 914 function cmd_make_deploy() {
915 make_prepare; 915 make_prepare;
916 916
917 # get linaro toolchain 917 # get linaro toolchain
918 (( `ls ${G_CROSS_COMPILER_PATH} 2>/dev/null | wc -l` == 0 )) && { 918 (( `ls ${G_CROSS_COMPILER_PATH} 2>/dev/null | wc -l` == 0 )) && {
919 pr_info "Get and unpack cross compiler"; 919 pr_info "Get and unpack cross compiler";
920 get_remote_file ${G_EXT_CROSS_COMPILER_LINK} ${DEF_SRC_DIR}/${G_CROSS_COMPILER_ARCHIVE} 920 get_remote_file ${G_EXT_CROSS_COMPILER_LINK} ${DEF_SRC_DIR}/${G_CROSS_COMPILER_ARCHIVE}
921 tar -xJf ${DEF_SRC_DIR}/${G_CROSS_COMPILER_ARCHIVE} -C ${G_TOOLS_PATH}/ 921 tar -xJf ${DEF_SRC_DIR}/${G_CROSS_COMPILER_ARCHIVE} -C ${G_TOOLS_PATH}/
922 }; 922 };
923 923
924 # get uboot repository 924 # get uboot repository
925 (( `ls ${G_UBOOT_SRC_DIR} 2>/dev/null | wc -l` == 0 )) && { 925 (( `ls ${G_UBOOT_SRC_DIR} 2>/dev/null | wc -l` == 0 )) && {
926 pr_info "Get uboot repository"; 926 pr_info "Get uboot repository";
927 get_git_src ${G_UBOOT_GIT} ${G_UBOOT_BRANCH} ${G_UBOOT_SRC_DIR} ${G_UBOOT_REV} 927 get_git_src ${G_UBOOT_GIT} ${G_UBOOT_BRANCH} ${G_UBOOT_SRC_DIR} ${G_UBOOT_REV}
928 }; 928 };
929 929
930 # get kernel repository 930 # get kernel repository
931 (( `ls ${G_LINUX_KERNEL_SRC_DIR} 2>/dev/null | wc -l` == 0 )) && { 931 (( `ls ${G_LINUX_KERNEL_SRC_DIR} 2>/dev/null | wc -l` == 0 )) && {
932 pr_info "Get kernel repository"; 932 pr_info "Get kernel repository";
933 get_git_src ${G_LINUX_KERNEL_GIT} ${G_LINUX_KERNEL_BRANCH} ${G_LINUX_KERNEL_SRC_DIR} ${G_LINUX_KERNEL_REV} 933 get_git_src ${G_LINUX_KERNEL_GIT} ${G_LINUX_KERNEL_BRANCH} ${G_LINUX_KERNEL_SRC_DIR} ${G_LINUX_KERNEL_REV}
934 cd ${G_LINUX_KERNEL_SRC_DIR} 934 cd ${G_LINUX_KERNEL_SRC_DIR}
935 git am < ${G_EMBEDIAN_PATH}/patches/kernel/0001-vivante-gpu-revert-to-6.2.4.p1-driver.patch 935 git am < ${G_EMBEDIAN_PATH}/patches/kernel/0001-vivante-gpu-revert-to-6.2.4.p1-driver.patch
936 git am < ${G_EMBEDIAN_PATH}/patches/kernel/0001-smarc-imx8m-compile-imx-sdma-driver-as-module.patch 936 git am < ${G_EMBEDIAN_PATH}/patches/kernel/0001-smarc-imx8m-compile-imx-sdma-driver-as-module.patch
937 cd - 937 cd -
938 }; 938 };
939 939
940 return 0; 940 return 0;
941 } 941 }
942 942
943 function cmd_make_rootfs() { 943 function cmd_make_rootfs() {
944 make_prepare; 944 make_prepare;
945 945
946 ## make debian rootfs 946 ## make debian rootfs
947 cd ${G_ROOTFS_DIR} 947 cd ${G_ROOTFS_DIR}
948 make_debian_rootfs ${G_ROOTFS_DIR} || { 948 make_debian_rootfs ${G_ROOTFS_DIR} || {
949 pr_error "Failed #$? in function make_debian_rootfs" 949 pr_error "Failed #$? in function make_debian_rootfs"
950 cd -; 950 cd -;
951 return 1; 951 return 1;
952 } 952 }
953 cd - 953 cd -
954 954
955 ## pack rootfs 955 ## pack rootfs
956 make_tarbar ${G_ROOTFS_DIR} ${G_ROOTFS_TARBAR_PATH} || { 956 make_tarbar ${G_ROOTFS_DIR} ${G_ROOTFS_TARBAR_PATH} || {
957 pr_error "Failed #$? in function make_tarbar" 957 pr_error "Failed #$? in function make_tarbar"
958 return 4; 958 return 4;
959 } 959 }
960 960
961 return 0; 961 return 0;
962 } 962 }
963 963
964 function cmd_make_uboot() { 964 function cmd_make_uboot() {
965 make_uboot ${G_UBOOT_SRC_DIR} ${PARAM_OUTPUT_DIR} || { 965 make_uboot ${G_UBOOT_SRC_DIR} ${PARAM_OUTPUT_DIR} || {
966 pr_error "Failed #$? in function make_uboot" 966 pr_error "Failed #$? in function make_uboot"
967 return 1; 967 return 1;
968 }; 968 };
969 969
970 return 0; 970 return 0;
971 } 971 }
972 972
973 function cmd_make_kernel() { 973 function cmd_make_kernel() {
974 make_kernel ${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_LINUX_KERNEL_DEF_CONFIG} "${G_LINUX_DTB}" ${G_LINUX_KERNEL_SRC_DIR} ${PARAM_OUTPUT_DIR} || { 974 make_kernel ${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_LINUX_KERNEL_DEF_CONFIG} "${G_LINUX_DTB}" ${G_LINUX_KERNEL_SRC_DIR} ${PARAM_OUTPUT_DIR} || {
975 pr_error "Failed #$? in function make_kernel" 975 pr_error "Failed #$? in function make_kernel"
976 return 1; 976 return 1;
977 }; 977 };
978 978
979 return 0; 979 return 0;
980 } 980 }
981 981
982 function cmd_make_kmodules() { 982 function cmd_make_kmodules() {
983 make_prepare; 983 make_prepare;
984 984
985 rm -rf ${G_ROOTFS_DIR}/lib/modules/* || { 985 rm -rf ${G_ROOTFS_DIR}/lib/modules/* || {
986 pr_error "Failed #$? prepare modules dir" 986 pr_error "Failed #$? prepare modules dir"
987 return 1; 987 return 1;
988 }; 988 };
989 989
990 make_kernel_modules ${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_LINUX_KERNEL_DEF_CONFIG} ${G_LINUX_KERNEL_SRC_DIR} ${G_ROOTFS_DIR} || { 990 make_kernel_modules ${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_LINUX_KERNEL_DEF_CONFIG} ${G_LINUX_KERNEL_SRC_DIR} ${G_ROOTFS_DIR} || {
991 pr_error "Failed #$? in function make_kernel_modules" 991 pr_error "Failed #$? in function make_kernel_modules"
992 return 2; 992 return 2;
993 }; 993 };
994 994
995 install_kernel_modules ${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_LINUX_KERNEL_DEF_CONFIG} ${G_LINUX_KERNEL_SRC_DIR} ${G_ROOTFS_DIR} || { 995 install_kernel_modules ${G_CROSS_COMPILER_PATH}/${G_CROSS_COMPILER_PREFIX} ${G_LINUX_KERNEL_DEF_CONFIG} ${G_LINUX_KERNEL_SRC_DIR} ${G_ROOTFS_DIR} || {
996 pr_error "Failed #$? in function install_kernel_modules" 996 pr_error "Failed #$? in function install_kernel_modules"
997 return 2; 997 return 2;
998 }; 998 };
999 999
1000 return 0; 1000 return 0;
1001 } 1001 }
1002 1002
1003 function cmd_make_rfs_tar() { 1003 function cmd_make_rfs_tar() {
1004 ## pack rootfs 1004 ## pack rootfs
1005 make_tarbar ${G_ROOTFS_DIR} ${G_ROOTFS_TARBAR_PATH} || { 1005 make_tarbar ${G_ROOTFS_DIR} ${G_ROOTFS_TARBAR_PATH} || {
1006 pr_error "Failed #$? in function make_tarbar" 1006 pr_error "Failed #$? in function make_tarbar"
1007 return 1; 1007 return 1;
1008 } 1008 }
1009 1009
1010 return 0; 1010 return 0;
1011 } 1011 }
1012 1012
1013 function cmd_make_sdcard() { 1013 function cmd_make_sdcard() {
1014 make_sdcard ${PARAM_BLOCK_DEVICE} ${PARAM_OUTPUT_DIR} || { 1014 make_sdcard ${PARAM_BLOCK_DEVICE} ${PARAM_OUTPUT_DIR} || {
1015 pr_error "Failed #$? in function make_sdcard" 1015 pr_error "Failed #$? in function make_sdcard"
1016 return 1; 1016 return 1;
1017 }; 1017 };
1018 1018
1019 return 0; 1019 return 0;
1020 } 1020 }
1021 1021
1022 function cmd_make_clean() { 1022 function cmd_make_clean() {
1023 1023
1024 ## clean kernel, dtb, modules 1024 ## clean kernel, dtb, modules
1025 clean_kernel ${G_LINUX_KERNEL_SRC_DIR} || { 1025 clean_kernel ${G_LINUX_KERNEL_SRC_DIR} || {
1026 pr_error "Failed #$? in function clean_kernel" 1026 pr_error "Failed #$? in function clean_kernel"
1027 return 1; 1027 return 1;
1028 }; 1028 };
1029 1029
1030 ## clean u-boot 1030 ## clean u-boot
1031 clean_uboot ${G_UBOOT_SRC_DIR} || { 1031 clean_uboot ${G_UBOOT_SRC_DIR} || {
1032 pr_error "Failed #$? in function clean_uboot" 1032 pr_error "Failed #$? in function clean_uboot"
1033 return 2; 1033 return 2;
1034 }; 1034 };
1035 1035
1036 ## delete tmp dirs and etc 1036 ## delete tmp dirs and etc
1037 pr_info "Delete tmp dir ${G_TMP_DIR}" 1037 pr_info "Delete tmp dir ${G_TMP_DIR}"
1038 rm -rf ${G_TMP_DIR} && :; 1038 rm -rf ${G_TMP_DIR} && :;
1039 1039
1040 pr_info "Delete rootfs dir ${G_ROOTFS_DIR}" 1040 pr_info "Delete rootfs dir ${G_ROOTFS_DIR}"
1041 rm -rf ${G_ROOTFS_DIR} && :; 1041 rm -rf ${G_ROOTFS_DIR} && :;
1042 1042
1043 return 0; 1043 return 0;
1044 } 1044 }
1045 1045
1046 #################### main function ####################### 1046 #################### main function #######################
1047 1047
1048 ## test for root access support (msrc not allowed) 1048 ## test for root access support (msrc not allowed)
1049 [ "$PARAM_CMD" != "deploy" ] && [ "$PARAM_CMD" != "bootloader" ] && [ "$PARAM_CMD" != "kernel" ] && [ "$PARAM_CMD" != "modules" ] && [ ${EUID} -ne 0 ] && { 1049 [ "$PARAM_CMD" != "deploy" ] && [ "$PARAM_CMD" != "bootloader" ] && [ "$PARAM_CMD" != "kernel" ] && [ "$PARAM_CMD" != "modules" ] && [ ${EUID} -ne 0 ] && {
1050 pr_error "this command must be run as root (or sudo/su)" 1050 pr_error "this command must be run as root (or sudo/su)"
1051 exit 1; 1051 exit 1;
1052 }; 1052 };
1053 1053
1054 V_RET_CODE=0; 1054 V_RET_CODE=0;
1055 1055
1056 pr_info "Command: \"$PARAM_CMD\" start..." 1056 pr_info "Command: \"$PARAM_CMD\" start..."
1057 1057
1058 case $PARAM_CMD in 1058 case $PARAM_CMD in
1059 deploy ) 1059 deploy )
1060 cmd_make_deploy || { 1060 cmd_make_deploy || {
1061 V_RET_CODE=1; 1061 V_RET_CODE=1;
1062 }; 1062 };
1063 ;; 1063 ;;
1064 rootfs ) 1064 rootfs )
1065 cmd_make_rootfs || { 1065 cmd_make_rootfs || {
1066 V_RET_CODE=1; 1066 V_RET_CODE=1;
1067 }; 1067 };
1068 ;; 1068 ;;
1069 bootloader ) 1069 bootloader )
1070 cmd_make_uboot || { 1070 cmd_make_uboot || {
1071 V_RET_CODE=1; 1071 V_RET_CODE=1;
1072 } 1072 }
1073 ;; 1073 ;;
1074 kernel ) 1074 kernel )
1075 cmd_make_kernel || { 1075 cmd_make_kernel || {
1076 V_RET_CODE=1; 1076 V_RET_CODE=1;
1077 }; 1077 };
1078 ;; 1078 ;;
1079 modules ) 1079 modules )
1080 cmd_make_kmodules || { 1080 cmd_make_kmodules || {
1081 V_RET_CODE=1; 1081 V_RET_CODE=1;
1082 }; 1082 };
1083 ;; 1083 ;;
1084 sdcard ) 1084 sdcard )
1085 cmd_make_sdcard || { 1085 cmd_make_sdcard || {
1086 V_RET_CODE=1; 1086 V_RET_CODE=1;
1087 }; 1087 };
1088 ;; 1088 ;;
1089 rtar ) 1089 rtar )
1090 cmd_make_rfs_tar || { 1090 cmd_make_rfs_tar || {
1091 V_RET_CODE=1; 1091 V_RET_CODE=1;
1092 }; 1092 };
1093 ;; 1093 ;;
1094 all ) 1094 all )
1095 (cmd_make_uboot && 1095 (cmd_make_uboot &&
1096 cmd_make_kernel && 1096 cmd_make_kernel &&
1097 cmd_make_kmodules && 1097 cmd_make_kmodules &&
1098 cmd_make_rootfs) || { 1098 cmd_make_rootfs) || {
1099 V_RET_CODE=1; 1099 V_RET_CODE=1;
1100 }; 1100 };
1101 ;; 1101 ;;
1102 clean ) 1102 clean )
1103 cmd_make_clean || { 1103 cmd_make_clean || {
1104 V_RET_CODE=1; 1104 V_RET_CODE=1;
1105 }; 1105 };
1106 ;; 1106 ;;
1107 * ) 1107 * )
1108 pr_error "Invalid input command: \"${PARAM_CMD}\""; 1108 pr_error "Invalid input command: \"${PARAM_CMD}\"";
1109 V_RET_CODE=1; 1109 V_RET_CODE=1;
1110 ;; 1110 ;;
1111 esac 1111 esac
1112 1112
1113 pr_info "" 1113 pr_info ""
1114 pr_info "Command: \"$PARAM_CMD\" end. Exit code: ${V_RET_CODE}" 1114 pr_info "Command: \"$PARAM_CMD\" end. Exit code: ${V_RET_CODE}"
1115 pr_info "" 1115 pr_info ""
1116 1116
1117 1117
1118 exit ${V_RET_CODE}; 1118 exit ${V_RET_CODE};
1119 1119