-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpi-kernel-copy
executable file
·200 lines (179 loc) · 5.64 KB
/
rpi-kernel-copy
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
#!/bin/bash
set -e # fail on error
###
# #%L
# **********************************************************************
# PROJECT : rpi-scripts
# FILENAME : rpi-kernel-copy
# **********************************************************************
#
# Copyright (C) 2015 Robert Savage
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###
echo
echo
echo "******************************************************"
echo "******************************************************"
echo "** **"
echo "** THIS IS A CUSTOM BUILD SCRIPT FOR COPYING A **"
echo "** CUSTOM BUILD OF THE RASPBERRY PI LINUX KERNEL **"
echo "** TO AN EXISTING RASPIAN SDCARD or uSDCARD **"
echo "** **"
echo "******************************************************"
echo "******************************************************"
echo
echo " Please note that you must have the Raspberry Pi"
echo " cross-compiler tool chain available on your local"
echo " build machine and also have the cross compiler"
echo " path in your environment variables. It may look"
echo " something like the example below, however you will"
echo " need to modify to account for your filesystem location"
echo " and your local machine architecture x86/x64."
echo
echo " > export PATH=\$PATH:\$HOME/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin"
echo
echo
echo
echo " In addition to the compiler tools, you will also need"
echo " the linux kernel that you with to build against."
echo " The path to kernel that you want to build against must"
echo " defined in the environment variable: KERNELDIR"
echo
echo " > export KERNELDIR=$HOME/dev/rpi/linux"
echo
# validate that a kernel director environment variable exists
if [ -z $KERNELDIR ]
then
echo "-------------------------------"
echo " MISSING KERNELDIR ENV VAR"
echo "-------------------------------"
echo
exit
fi
# navigate to the kernel directory to build from
cd $KERNELDIR
# determine compiler tools path for RPI/ARM
ARM_GCC=$(eval which arm-linux-gnueabihf-gcc)
CCPATH=$(dirname "${ARM_GCC}")
echo
echo "-------------------------------"
echo " KERNEL PATH"
echo "-------------------------------"
echo " BUILDING KERNEL IN : $KERNELDIR"
echo " CROSS_COMPILER TOOLS : $CCPATH"
echo
echo "------------------------------"
echo " GCC COMPILER VERSION"
echo "------------------------------"
sudo $CCPATH/arm-linux-gnueabihf-gcc --version
echo
echo "------------------------------"
echo " RASPBERRY PI PLATFORM"
echo "------------------------------"
echo " (1) Raspberry Pi Models A, B, A+, B+, Compute Module"
echo " (2) Raspberry Pi Model 2B <DEFAULT>"
read -p "Which hardware platform do you wish to build the kernel for <1|2>? (2) " rpi_platform
case $rpi_platform in
[1]* )
echo "----------------------------------------"
echo " COPY KERNEL FOR RASPBERRY PI A,B,A+,B+"
echo "----------------------------------------"
KERNEL=kernel
;;
* )
echo "---------------------------------"
echo " COPY KERNEL7 FOR RASPBERRY PI 2B"
echo "---------------------------------"
KERNEL=kernel7
;;
esac
echo
echo "------------------------------"
echo " SDCARD MOUNTS"
echo "------------------------------"
lsblk
echo
echo "Provide SDCARD mount path for the FAT32 boot partition :"
read -p " > " FAT32
if [ -z $FAT32 ]
then exit
fi
echo
echo "Provide SDCARD mount path for the EXT4 data partition :"
read -p " > " EXT4
if [ -z $EXT4 ]
then exit
fi
echo
echo "You selected:"
echo " [FAT32 BOOT] : $FAT32"
echo " [EXT4 DATA] : $EXT4"
echo
read -p "Are these mount paths correct (!! DO NOT SCREW THIS UP !!) <y|n>? (y) " yn
case $yn in
[nN]* ) exit;;
* ) ;;
esac
echo
echo "------------------------------"
echo " COPY MODULES TO SDCARD"
echo "------------------------------"
set -x
sudo -E make ARCH=arm CROSS_COMPILE=$CCPATH/arm-linux-gnueabihf- INSTALL_MOD_PATH=$EXT4 modules_install
set +x
echo
echo "------------------------------"
echo " BACKUP EXISTING KERNEL IMAGE"
echo "------------------------------"
set -x
sudo -E cp $FAT32/$KERNEL.img $FAT32/$KERNEL-backup.img
set +x
echo
echo "------------------------------"
echo " COPY NEW KERNEL IMAGE"
echo "------------------------------"
set -x
sudo -E scripts/mkknlimg arch/arm/boot/zImage $FAT32/$KERNEL.img
set +x
echo
echo "------------------------------"
echo " COPY DEVICE TREE & OVERLAYS"
echo "------------------------------"
set -x
sudo -E cp arch/arm/boot/dts/*.dtb $FAT32
sudo -E cp arch/arm/boot/dts/overlays/*.dtb* $FAT32/overlays/
sudo -E cp arch/arm/boot/dts/overlays/README $FAT32/overlays/
set +x
echo
echo "------------------------------"
echo " SYNCING DATA TO SDCARD"
echo "------------------------------"
echo " ... please wait ... "
sync
echo
echo "------------------------------"
echo " UN-MOUNTING SDCARD"
echo "------------------------------"
echo " ... please wait ... "
echo
sudo -E umount $FAT32
sudo -E umount $EXT4
echo
echo "------------------------------"
echo " KERNEL COPIED TO SDCARD"
echo "------------------------------"
echo " You may now remove your SDCARD and boot your Raspberry Pi!"
echo
exit 0