Commit 79edc1b632a9006d68557278ef1206e05a4e2f7b
1 parent
bbe190f190
Exists in
smarc-8mm-p9.0.0_2.0.0_ga
and in
1 other branch
Add flash emmc script and convert console messages to ttymxc0
Showing 2 changed files with 265 additions and 1 deletions Side-by-side Diff
imx8m/smarc_mx8mq/BoardConfig.mk
... | ... | @@ -144,7 +144,7 @@ |
144 | 144 | endif |
145 | 145 | |
146 | 146 | KERNEL_NAME := Image |
147 | -BOARD_KERNEL_CMDLINE := init=/init androidboot.gui_resolution=1080p androidboot.console=ttymxc0 androidboot.hardware=freescale androidboot.fbTileSupport=enable cma=$(CMASIZE) androidboot.primary_display=imx-drm firmware_class.path=/vendor/firmware transparent_hugepage=never | |
147 | +BOARD_KERNEL_CMDLINE := console=ttymxc0,115200 earlycon=imxuart,0x30860000,115200 init=/init androidboot.gui_resolution=1080p androidboot.console=ttymxc0 androidboot.hardware=freescale androidboot.fbTileSupport=enable cma=$(CMASIZE) androidboot.primary_display=imx-drm firmware_class.path=/vendor/firmware transparent_hugepage=never | |
148 | 148 | |
149 | 149 | # Default wificountrycode |
150 | 150 | BOARD_KERNEL_CMDLINE += androidboot.wificountrycode=CN |
scripts/sh/smarc-mkemmccard.sh
1 | +#!/bin/bash -e | |
2 | + | |
3 | +help() { | |
4 | + | |
5 | +bn=`basename $0` | |
6 | +cat << EOF | |
7 | + | |
8 | +Version: 1.2 | |
9 | +Last change: Exit on error, and general cleanup | |
10 | + | |
11 | +Usage: $bn <option> device_node | |
12 | + | |
13 | +options: | |
14 | + -h displays this help message | |
15 | + -s only get partition size | |
16 | + -np not partition. | |
17 | + -f soc_name flash android image file with soc_name | |
18 | + -F soc_name determine the device_node's offset to flash bootloader and flash default android image file | |
19 | + SoC offset(KB) | |
20 | + default 1 | |
21 | + imx8dv 16 | |
22 | + imx8qm/imx8qxp/imx8mq 33 | |
23 | + -a only flash image to slot_a | |
24 | + -b only flash image to slot_b | |
25 | + -c card_size optional setting: 7 / 14 / 28 | |
26 | + If not set, use partition-table.img (default) | |
27 | + If set to 7, use partition-table-7GB.img for 8GB SD card | |
28 | + If set to 14, use partition-table-14GB.img for 16GB SD card | |
29 | + If set to 28, use partition-table-28GB.img for 32GB SD card | |
30 | + Make sure the corresponding file exist for your platform. | |
31 | + -m flash m4 image | |
32 | + -o force_offset force set uboot offset | |
33 | +EOF | |
34 | + | |
35 | +} | |
36 | + | |
37 | +# parse command line | |
38 | +moreoptions=1 | |
39 | +node="na" | |
40 | +soc_name="" | |
41 | +force_offset="" | |
42 | +cal_only=0 | |
43 | +card_size=0 | |
44 | +bootloader_offset=1 | |
45 | +m4_image_offset=5120 | |
46 | +vaild_gpt_size=17 | |
47 | +not_partition=0 | |
48 | +slot="" | |
49 | +systemimage_file="system.img" | |
50 | +systemimage_raw_file="system_raw.img" | |
51 | +vendor_file="vendor.img" | |
52 | +vendor_raw_file="vendor_raw.img" | |
53 | +partition_file="partition-table.img" | |
54 | +g_sizes=0 | |
55 | +append_soc_name=0 | |
56 | +support_dtbo=0 | |
57 | +flash_m4=0 | |
58 | +RED='\033[0;31m' | |
59 | +STD='\033[0;0m' | |
60 | + | |
61 | +while [ "$moreoptions" = 1 -a $# -gt 0 ]; do | |
62 | + case $1 in | |
63 | + -h) help; exit ;; | |
64 | + -s) cal_only=1 ;; | |
65 | + -f) append_soc_name=1 ; soc_name=$2; shift;; | |
66 | + -F) soc_name=$2; shift;; | |
67 | + -c) card_size=$2; shift;; | |
68 | + -np) not_partition=1 ;; | |
69 | + -a) slot="_a" ;; | |
70 | + -b) slot="_b" ;; | |
71 | + -m) flash_m4=1 ;; | |
72 | + -o) force_offset=$2; shift;; | |
73 | + *) moreoptions=0; node=$1 ;; | |
74 | + esac | |
75 | + [ "$moreoptions" = 0 ] && [ $# -gt 1 ] && help && exit | |
76 | + [ "$moreoptions" = 1 ] && shift | |
77 | +done | |
78 | + | |
79 | +# check required applications are installed | |
80 | +#command -v simg2img >/dev/null 2>&1 || { echo -e >&2 "${RED}Missing simg2img app. Please run: sudo apt-get install android-tools-fsutils${STD}" ; exit 1 ; } | |
81 | +command -v hdparm >/dev/null 2>&1 || { echo -e >&2 "${RED}Missing hdparm app. Please make sure it is installed. Exiting.${STD}" ; exit 1 ; } | |
82 | +command -v gdisk >/dev/null 2>&1 || { echo -e >&2 "${RED}Missing gdisk app. Please make sure it is installed. Exiting.${STD}" ; exit 1 ; } | |
83 | + | |
84 | +if [ ${card_size} -ne 0 ] && [ ${card_size} -ne 7 ] && [ ${card_size} -ne 14 ] && [ ${card_size} -ne 28 ]; then | |
85 | + help; exit 1; | |
86 | +fi | |
87 | + | |
88 | +if [ "${soc_name}" = "imx8dv" ]; then | |
89 | + bootloader_offset=16 | |
90 | +fi | |
91 | + | |
92 | +if [ "${soc_name}" = "imx8qxp" -o "${soc_name}" = "imx8qm" ]; then | |
93 | + bootloader_offset=32 | |
94 | +fi | |
95 | + | |
96 | +if [ "${soc_name}" = "imx8mq" -o "${soc_name}" = "imx8mm" -o "${soc_name}" = "smarcimx8mq" -o "${soc_name}" = "smarcimx8mq-hdmi" -o "${soc_name}" = "smarcimx8mq-dp" -o "${soc_name}" = "smarcimx8mq-lcdif-lvds" -o "${soc_name}" = "smarcimx8mq-dcss-lvds" -o "${soc_name}" = "smarcimx8mq-dual-display" -o "${soc_name}" = "smarcimx8mq-edp" ]; then | |
97 | + bootloader_offset=33 | |
98 | +fi | |
99 | + | |
100 | +if [ "${force_offset}" != "" ]; then | |
101 | + bootloader_offset=${force_offset} | |
102 | +fi | |
103 | + | |
104 | +if [ ! -e ${node} ]; then | |
105 | + help | |
106 | + exit 1 | |
107 | +fi | |
108 | + | |
109 | +echo "${soc_name} bootloader offset is: ${bootloader_offset}" | |
110 | + | |
111 | +if [ "${soc_name}" != "" ] && [ "${append_soc_name}" -eq 1 ]; then | |
112 | + soc_name="-${soc_name}" | |
113 | +else | |
114 | + soc_name="" | |
115 | +fi | |
116 | + | |
117 | +# dump partitions | |
118 | +if [ "${cal_only}" -eq "1" ]; then | |
119 | + gdisk -l ${node} 2>/dev/null | grep -A 20 "Number " | |
120 | + exit 0 | |
121 | +fi | |
122 | + | |
123 | +function get_partition_size | |
124 | +{ | |
125 | + start_sector=`gdisk -l ${node} | grep -w $1 | awk '{print $2}'` | |
126 | + end_sector=`gdisk -l ${node} | grep -w $1 | awk '{print $3}'` | |
127 | + # 1 sector = 512 bytes. This will change unit from sector to MBytes. | |
128 | + let "g_sizes=($end_sector - $start_sector + 1) / 2048" | |
129 | +} | |
130 | + | |
131 | +function format_partition | |
132 | +{ | |
133 | + num=`gdisk -l ${node} | grep -w $1 | awk '{print $1}'` | |
134 | + if [ ${num} -gt 0 ] 2>/dev/null; then | |
135 | + echo "format_partition: $1:${node}p${num} ext4" | |
136 | + mkfs.ext4 -F ${node}p${num} -L$1 | |
137 | + fi | |
138 | +} | |
139 | + | |
140 | +function erase_partition | |
141 | +{ | |
142 | + num=`gdisk -l ${node} | grep -w $1 | awk '{print $1}'` | |
143 | + if [ ${num} -gt 0 ] 2>/dev/null; then | |
144 | + get_partition_size $1 | |
145 | + echo "erase_partition: $1 : ${node}p${num} ${g_sizes}M" | |
146 | + dd if=/dev/zero of=${node}p${num} bs=1048576 conv=fsync count=$g_sizes | |
147 | + fi | |
148 | +} | |
149 | + | |
150 | +function flash_partition | |
151 | +{ | |
152 | + for num in `gdisk -l ${node} | grep -E -w "$1|$1_a|$1_b" | awk '{print $1}'` | |
153 | + do | |
154 | + if [ $? -eq 0 ]; then | |
155 | + if [ $(echo ${1} | grep "system") != "" ] 2>/dev/null; then | |
156 | + img_name=${systemimage_raw_file} | |
157 | + elif [ $(echo ${1} | grep "vendor") != "" ] 2>/dev/null; then | |
158 | + img_name=${vendor_raw_file} | |
159 | + elif [ ${support_dtbo} -eq 1 ] && [ $(echo ${1} | grep "boot") != "" ] 2>/dev/null; then | |
160 | + img_name="boot.img" | |
161 | + else | |
162 | + img_name="${1%_*}${soc_name}.img" | |
163 | + fi | |
164 | + echo "flash_partition: ${img_name} ---> ${node}p${num}" | |
165 | + if [ ! -f "${img_name}" ]; then | |
166 | + echo -e >&2 "${RED}File ${img_name} not found. Please check. Exiting${STD}" | |
167 | + return 1 | |
168 | + fi | |
169 | + dd if=${img_name} of=${node}p${num} bs=10M conv=fsync | |
170 | + fi | |
171 | + done | |
172 | +} | |
173 | + | |
174 | +function format_android | |
175 | +{ | |
176 | + echo "formating android images" | |
177 | + format_partition userdata | |
178 | + format_partition cache | |
179 | + erase_partition presistdata | |
180 | + erase_partition fbmisc | |
181 | + erase_partition misc | |
182 | +} | |
183 | + | |
184 | +function make_partition | |
185 | +{ | |
186 | + if [ ${card_size} -gt 0 ]; then | |
187 | + partition_file="partition-table-${card_size}GB.img" | |
188 | + fi | |
189 | + if [ ! -f "${partition_file}" ]; then | |
190 | + echo -e >&2 "${RED}File ${partition_file} not found. Please check. Exiting${STD}" | |
191 | + return 1 | |
192 | + fi | |
193 | + echo "make gpt partition for android: ${partition_file}" | |
194 | + dd if=${partition_file} of=${node} bs=1k count=${vaild_gpt_size} conv=fsync | |
195 | +} | |
196 | + | |
197 | +function flash_android | |
198 | +{ | |
199 | + boot_partition="boot"${slot} | |
200 | + recovery_partition="recovery"${slot} | |
201 | + system_partition="system"${slot} | |
202 | + vendor_partition="vendor"${slot} | |
203 | + vbmeta_partition="vbmeta"${slot} | |
204 | + dtbo_partition="dtbo"${slot} | |
205 | + gdisk -l ${node} 2>/dev/null | grep -q "dtbo" && support_dtbo=1 | |
206 | + | |
207 | + bootloader_file="u-boot-imx8mq-smarcimx8mq_2g.imx" | |
208 | + if [ "${support_dtbo}" -eq "1" ] ; then | |
209 | + flash_partition ${dtbo_partition} || exit 1 | |
210 | + fi | |
211 | + flash_partition ${boot_partition} || exit 1 | |
212 | + flash_partition ${recovery_partition} || exit 1 | |
213 | + #simg2img ${systemimage_file} ${systemimage_raw_file} | |
214 | + flash_partition ${system_partition} || exit 1 | |
215 | + #rm ${systemimage_raw_file} | |
216 | + #simg2img ${vendor_file} ${vendor_raw_file} | |
217 | + flash_partition ${vendor_partition} || exit 1 | |
218 | + #rm ${vendor_raw_file} | |
219 | + flash_partition ${vbmeta_partition} || exit 1 | |
220 | + echo "erase_partition: uboot : ${node}" | |
221 | + echo "flash_partition: ${bootloader_file} ---> ${node}" | |
222 | + first_partition_offset=`gdisk -l ${node} | grep ' 1 ' | awk '{print $2}'` | |
223 | + # the unit of first_partition_offset is sector size which is 512 Byte. | |
224 | + count_bootloader=`expr ${first_partition_offset} / 2 - ${bootloader_offset}` | |
225 | + echo "the bootloader partition size: ${count_bootloader}" | |
226 | + dd if=/dev/zero of=${node} bs=1k seek=${bootloader_offset} conv=fsync count=${count_bootloader} | |
227 | + dd if=${bootloader_file} of=${node} bs=1k seek=${bootloader_offset} conv=fsync | |
228 | + if [ "${flash_m4}" -eq "1" ] ; then | |
229 | + m4_image=${soc_name#*-}"_m4_demo.img" | |
230 | + echo "flash_partition: ${m4_image} ---> ${node}" | |
231 | + dd if=${m4_image} of=${node} bs=1k seek=${m4_image_offset} conv=fsync | |
232 | + fi | |
233 | +} | |
234 | + | |
235 | +if [ "${not_partition}" -eq "1" ] ; then | |
236 | + flash_android || exit 1 | |
237 | + exit 0 | |
238 | +fi | |
239 | + | |
240 | +make_partition || exit 1 | |
241 | + | |
242 | +sleep 3 | |
243 | +for i in `cat /proc/mounts | grep "${node}" | awk '{print $2}'`; do umount $i; done | |
244 | +hdparm -z ${node} | |
245 | + | |
246 | +# backup the GPT table to last LBA for sd card. | |
247 | +echo -e 'r\ne\nY\nw\nY\nY' | gdisk ${node} | |
248 | + | |
249 | +format_android | |
250 | +flash_android || exit 1 | |
251 | + | |
252 | +echo | |
253 | +echo ">>>>>>>>>>>>>> Flashing successfully completed <<<<<<<<<<<<<<" | |
254 | + | |
255 | +exit 0 | |
256 | + | |
257 | +# For MFGTool Notes: | |
258 | +# MFGTool use mksdcard-android.tar store this script | |
259 | +# if you want change it. | |
260 | +# do following: | |
261 | +# tar xf mksdcard-android.sh.tar | |
262 | +# vi mksdcard-android.sh | |
263 | +# [ edit want you want to change ] | |
264 | +# rm mksdcard-android.sh.tar; tar cf mksdcard-android.sh.tar mksdcard-android.sh |