-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathinstall_kernel.sh
More file actions
executable file
·262 lines (215 loc) · 7.48 KB
/
install_kernel.sh
File metadata and controls
executable file
·262 lines (215 loc) · 7.48 KB
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
#!/bin/sh -e
#
# Copyright (c) 2009-2013 Robert Nelson <robertcnelson@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
unset KERNEL_UTS
unset MMC
unset ZRELADDR
BOOT_PARITION="1"
DIR=$PWD
. ${DIR}/version.sh
mmc_write_rootfs () {
echo "Installing ${KERNEL_UTS}-modules.tar.gz to ${partition}"
if [ -d "${location}/lib/modules/${KERNEL_UTS}" ] ; then
sudo rm -rf "${location}/lib/modules/${KERNEL_UTS}" || true
fi
sudo tar ${UNTAR} "${DIR}/deploy/${KERNEL_UTS}-modules.tar.gz" -C "${location}"
sync
echo "Installing ${KERNEL_UTS}-firmware.tar.gz to ${partition}"
if [ -d "${DIR}/deploy/tmp" ] ; then
rm -rf "${DIR}/deploy/tmp" || true
fi
mkdir -p "${DIR}/deploy/tmp/"
tar -xf "${DIR}/deploy/${KERNEL_UTS}-firmware.tar.gz" -C "${DIR}/deploy/tmp/"
sync
sudo cp -v "${DIR}/deploy/tmp"/*.dtbo "${location}/lib/firmware/" 2>/dev/null || true
sync
rm -rf "${DIR}/deploy/tmp/" || true
if [ "${ZRELADDR}" ] ; then
if [ ! -f "${location}/boot/SOC.sh" ] ; then
if [ -f "${location}/boot/uImage" ] ; then
#Possibly Angstrom: dump a newer uImage if one exists..
if [ -f "${location}/boot/uImage_bak" ] ; then
sudo rm -f "${location}/boot/uImage_bak" || true
fi
sudo mv "${location}/boot/uImage" "${location}/boot/uImage_bak"
sudo mkimage -A arm -O linux -T kernel -C none -a ${ZRELADDR} -e ${ZRELADDR} -n ${KERNEL_UTS} -d "${DIR}/deploy/${KERNEL_UTS}.zImage" "${location}/boot/uImage"
fi
fi
fi
if [ -f "${DIR}/deploy/config-${KERNEL_UTS}" ] ; then
if [ -f "${location}/boot/config-${KERNEL_UTS}" ] ; then
sudo rm -f "${location}/boot/config-${KERNEL_UTS}" || true
fi
sudo cp -v "${DIR}/deploy/config-${KERNEL_UTS}" "${location}/boot/config-${KERNEL_UTS}"
fi
}
mmc_write_boot () {
echo "Installing ${KERNEL_UTS} to ${partition}"
if [ -f "${location}/SOC.sh" ] ; then
. "${location}/SOC.sh"
ZRELADDR=${load_addr}
fi
if [ -f "${location}/uImage_bak" ] ; then
sudo rm -f "${location}/uImage_bak" || true
fi
if [ -f "${location}/uImage" ] ; then
sudo mv "${location}/uImage" "${location}/uImage_bak"
fi
if [ "${ZRELADDR}" ] ; then
sudo mkimage -A arm -O linux -T kernel -C none -a ${ZRELADDR} -e ${ZRELADDR} -n ${KERNEL_UTS} -d "${DIR}/deploy/${KERNEL_UTS}.zImage" "${location}/uImage"
fi
if [ -f "${location}/zImage_bak" ] ; then
sudo rm -f "${location}/zImage_bak" || true
fi
if [ -f "${location}/zImage" ] ; then
sudo mv "${location}/zImage" "${location}/zImage_bak"
fi
#Assuming boot via zImage on first partition...
sudo cp -v "${DIR}/deploy/${KERNEL_UTS}.zImage" "${location}/zImage"
if [ -f "${DIR}/deploy/${KERNEL_UTS}-dtbs.tar.gz" ] ; then
if [ -d "${location}/dtbs" ] ; then
sudo rm -rf "${location}/dtbs" || true
fi
sudo mkdir -p "${location}/dtbs"
echo "Installing ${KERNEL_UTS}-dtbs.tar.gz to ${partition}"
sudo tar ${UNTAR} "${DIR}/deploy/${KERNEL_UTS}-dtbs.tar.gz" -C "${location}/dtbs/"
sync
fi
}
mmc_partition_discover () {
if [ -f "${DIR}/deploy/disk/uEnv.txt" ] || [ -f "${DIR}/deploy/disk/BOOT.BIN" ] ; then
location="${DIR}/deploy/disk"
mmc_write_boot
fi
if [ -f "${DIR}/deploy/disk/boot/uEnv.txt" ] ; then
location="${DIR}/deploy/disk/boot"
mmc_write_boot
fi
if [ -f "${DIR}/deploy/disk/etc/fstab" ] ; then
location="${DIR}/deploy/disk"
mmc_write_rootfs
fi
}
mmc_unmount () {
cd "${DIR}/deploy/disk"
sync
sync
cd -
sudo umount "${DIR}/deploy/disk" || true
}
mmc_detect_n_mount () {
echo "Starting Partition Search"
echo "-----------------------------"
num_partitions=$(LC_ALL=C sudo fdisk ${MMC} -l 2>/dev/null | grep "^${MMC}" | grep -v "DM6" | grep -v "Extended" | grep -v "swap" | wc -l)
i=0 ; while test $i -le ${num_partitions} ; do
partition=$(LC_ALL=C sudo fdisk ${MMC} -l 2>/dev/null | grep "^${MMC}" | grep -v "DM6" | grep -v "Extended" | grep -v "swap" | head -${i} | tail -1 | awk '{print $1}')
if [ ! "x${partition}" = "x" ] ; then
echo "Trying: [${partition}]"
if [ ! -d "${DIR}/deploy/disk/" ] ; then
mkdir -p "${DIR}/deploy/disk/"
fi
echo "Partition: [${partition}] trying: [vfat], [ext4]"
if sudo mount -t vfat ${partition} "${DIR}/deploy/disk/" 2>/dev/null ; then
echo "Partition: [vfat]"
UNTAR="xfo"
mmc_partition_discover
mmc_unmount
elif sudo mount -t ext4 ${partition} "${DIR}/deploy/disk/" 2>/dev/null ; then
echo "Partition: [extX]"
UNTAR="xf"
mmc_partition_discover
mmc_unmount
fi
fi
i=$(($i+1))
done
echo "-----------------------------"
echo "This script has finished..."
echo "For verification, always test this media with your end device..."
}
unmount_partitions () {
echo ""
echo "Debug: Existing Partition on drive:"
echo "-----------------------------"
LC_ALL=C sudo fdisk -l ${MMC}
echo ""
echo "Unmounting Partitions"
echo "-----------------------------"
NUM_MOUNTS=$(mount | grep -v none | grep "${MMC}" | wc -l)
i=0 ; while test $i -le ${NUM_MOUNTS} ; do
DRIVE=$(mount | grep -v none | grep "${MMC}" | tail -1 | awk '{print $1}')
sudo umount ${DRIVE} >/dev/null 2>&1 || true
i=$(($i+1))
done
mkdir -p "${DIR}/deploy/disk/"
mmc_detect_n_mount
}
list_mmc () {
echo "fdisk -l:"
LC_ALL=C sudo fdisk -l 2>/dev/null | grep "Disk /dev/" --color=never
echo ""
echo "lsblk:"
lsblk | grep -v sr0
echo "-----------------------------"
}
check_mmc () {
FDISK=$(LC_ALL=C sudo fdisk ${MMC} -l 2>/dev/null | grep "Disk ${MMC}" | awk '{print $2}')
if [ "x${FDISK}" = "x${MMC}:" ] ; then
echo ""
echo "I see..."
list_mmc
echo -n "Are you 100% sure, on selecting [${MMC}] (y/n)? "
read response
if [ "x${response}" = "xy" ] ; then
unmount_partitions
fi
echo ""
else
echo ""
echo "Are you sure? I Don't see [${MMC}], here is what I do see..."
echo ""
list_mmc
echo "Please update MMC variable in system.sh"
fi
}
if [ -f "${DIR}/system.sh" ] ; then
. ${DIR}/system.sh
if [ -f "${DIR}/KERNEL/arch/arm/boot/zImage" ] ; then
KERNEL_UTS=$(cat "${DIR}/KERNEL/include/generated/utsrelease.h" | awk '{print $3}' | sed 's/\"//g' )
if [ "x${MMC}" = "x" ] ; then
echo "-----------------------------"
echo "lsblk:"
lsblk | grep -v sr0
echo "-----------------------------"
echo "ERROR: MMC is not defined in system.sh"
else
unset PARTITION_PREFIX
echo ${MMC} | grep mmcblk >/dev/null && PARTITION_PREFIX="p"
check_mmc
fi
else
echo "ERROR: arch/arm/boot/zImage not found, Please run build_kernel.sh before running this script..."
fi
else
echo "Missing system.sh, please copy system.sh.sample to system.sh and edit as needed"
echo "cp system.sh.sample system.sh"
echo "gedit system.sh"
fi