forked from friendlyarm/sd-fuse_s5p6818
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmk-sd-image.sh
executable file
·191 lines (167 loc) · 4.58 KB
/
mk-sd-image.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
#!/bin/bash
set -eu
# Copyright (C) Guangzhou FriendlyARM Computer Tech. Co., Ltd.
# (http://www.friendlyarm.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can access it online at
# http://www.gnu.org/licenses/gpl-2.0.html.
function usage() {
echo "Usage: $0 <friendlycore-arm64|friendlycore|friendlycore-arm64|friendlycore-lite-focal|friendlycore-lite-focal-arm64|lubuntu|android|android7|friendlywrt|eflasher>"
exit 0
}
if [ $# -eq 0 ]; then
usage
fi
# Automatically re-run script under sudo if not root
if [ $(id -u) -ne 0 ]; then
echo "Re-running script under sudo..."
sudo --preserve-env "$0" "$@"
exit
fi
. tools/util.sh
check_and_install_package
# ----------------------------------------------------------
# Get platform, target OS
true ${SOC:=s5p6818}
true ${TARGET_OS:=$(echo ${1,,}|sed 's/\///g')}
case ${TARGET_OS} in
friendlycore* | lubuntu* | android | android7 | friendlywrt | eflasher)
;;
*)
echo "Error: Unsupported target OS: ${TARGET_OS}"
exit 0
esac
true ${RAW_SIZE_MB:=0}
if [ $RAW_SIZE_MB -eq 0 ]; then
case ${TARGET_OS} in
friendlycore-arm64)
RAW_SIZE_MB=7800 ;;
friendlycore)
RAW_SIZE_MB=7800 ;;
friendlycore-lite-focal)
RAW_SIZE_MB=7800 ;;
friendlycore-lite-focal-arm64)
RAW_SIZE_MB=7800 ;;
lubuntu)
RAW_SIZE_MB=7800 ;;
friendlywrt)
RAW_SIZE_MB=1000 ;;
android)
RAW_SIZE_MB=7800 ;;
android7)
RAW_SIZE_MB=7800 ;;
eflasher)
RAW_SIZE_MB=7800 ;;
*)
RAW_SIZE_MB=7800 ;;
esac
fi
if [ $# -eq 2 ]; then
RAW_FILE=$2
else
case ${TARGET_OS} in
friendlycore-arm64)
RAW_FILE=${SOC}-sd-friendly-core-xenial-4.4-arm64-$(date +%Y%m%d).img
;;
friendlycore)
RAW_FILE=${SOC}-sd-friendlycore-xenial-4.4-armhf-$(date +%Y%m%d).img
;;
friendlycore-lite-focal)
RAW_FILE=${SOC}-sd-friendlycore-lite-focal-4.4-armhf-$(date +%Y%m%d).img
;;
friendlycore-lite-focal-arm64)
RAW_FILE=${SOC}-sd-friendlycore-lite-focal-4.4-arm64-$(date +%Y%m%d).img
;;
lubuntu)
RAW_FILE=${SOC}-sd-lubuntu-desktop-xenial-4.4-armhf-$(date +%Y%m%d).img
;;
friendlywrt)
RAW_FILE=${SOC}-sd-friendlywrt-xenial-4.4-armhf-$(date +%Y%m%d).img
;;
android)
RAW_FILE=${SOC}-sd-android-lollipop-$(date +%Y%m%d).img
;;
android7)
RAW_FILE=${SOC}-sd-android7-$(date +%Y%m%d).img
;;
eflasher)
RAW_FILE=${SOC}-eflasher-$(date +%Y%m%d).img
;;
*)
RAW_FILE=${SOC}-sd-${TARGET_OS}-$(date +%Y%m%d).img
;;
esac
fi
OUT=out
if [ ! -d $OUT ]; then
echo "path not found: $PWD/$OUT"
exit 1
fi
RAW_FILE=${OUT}/${RAW_FILE}
if [ -f "${RAW_FILE}" ]; then
rm -f ${RAW_FILE}
fi
BLOCK_SIZE=1024
let RAW_SIZE=(${RAW_SIZE_MB}*1000*1000)/${BLOCK_SIZE}
echo "Creating RAW image: ${RAW_FILE} (${RAW_SIZE_MB} MB)"
echo "---------------------------------"
dd if=/dev/zero of=${RAW_FILE} bs=${BLOCK_SIZE} count=0 \
seek=${RAW_SIZE} || exit 1
sfdisk -u S -L -q ${RAW_FILE} 2>/dev/null << EOF
2048,,0x0C,-
EOF
if [ $? -ne 0 ]; then
echo "Error: ${RAW_FILE}: Creating RAW file failed"
exit 1
fi
# ----------------------------------------------------------
# Setup loop device
LOOP_DEVICE=$(losetup -f)
echo "Using device: ${LOOP_DEVICE}"
for i in `seq 3`; do
if [ -b ${LOOP_DEVICE} ]; then
break
else
echo "Waitting ${LOOP_DEVICE}"
sleep 1
fi
done
if losetup ${LOOP_DEVICE} ${RAW_FILE}; then
USE_KPARTX=1
PART_DEVICE=/dev/mapper/`basename ${LOOP_DEVICE}`
sleep 1
else
echo "Error: attaching ${LOOP_DEVICE} failed, stop now."
rm ${RAW_FILE}
exit 1
fi
# ----------------------------------------------------------
# Fusing all
true ${SD_FUSING:=$(dirname $0)/fusing.sh}
${SD_FUSING} ${LOOP_DEVICE} ${TARGET_OS}
RET=$?
if [ "x${TARGET_OS}" = "xeflasher" ]; then
sudo mkfs.exfat ${LOOP_DEVICE}p1 -n FriendlyARM
fi
# cleanup
losetup -d ${LOOP_DEVICE}
if [ ${RET} -ne 0 ]; then
echo "Error: ${RAW_FILE}: Fusing image failed, cleanup"
rm -f ${RAW_FILE}
exit 1
fi
echo "---------------------------------"
echo "RAW image successfully created (`date +%T`)."
ls -l ${RAW_FILE}
echo "Tip: You can compress it to save disk space."