forked from foss-for-synopsys-dwc-arc-processors/toolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-kernel.sh
executable file
·388 lines (312 loc) · 10.7 KB
/
build-kernel.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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#!/bin/sh
# Copyright (C) 2012-2015 Synopsys Inc.
# Contributor Jeremy Bennett <[email protected]>
# This file is a script to build BusyBox and the Linux kernel for ARC700.
# 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 3 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, see <http://www.gnu.org/licenses/>.
# SCRIPT TO BUILD BUSYBOX and LINUX for ARC700
# ============================================
# This convenience script does a completely clean build of busybox, installs
# from that into the initramfs , fixes libraries in the initramfs and then
# builds the kernel.
# This is not part of the official process (which uses buildroot), but is
# convenient for developers who wish to build/rebuild a kernel quickly. The
# options to the script are documented in the comments.
# There is an assumption that the layout of repositories is standard.
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
#
# Shell functions
#
# ------------------------------------------------------------------------------
# Convenience function to copy a message to the log and terminal
# @param[in] $1 The message to log
logterm () {
echo $1 | tee -a ${logfile}
}
# Convenience function to copy a message to the log only
# @param[in] $1 The message to log
logonly () {
echo $1 >> ${logfile}
}
# Convenience function to exit with a suitable message.
failedbuild () {
echo "Build failed. See ${logfile} for details."
exit 1
}
# ------------------------------------------------------------------------------
#
# Parse args
#
# ------------------------------------------------------------------------------
# Default source directory is where we have this script.
d=`dirname "$0"`
ARC_GNU=`(cd "$d/.." && pwd)`
# Generic release set up, which we'll share with sub-scripts. This defines
# (and exports RELEASE, LOGDIR and RESDIR, creating directories named $LOGDIR
# and $RESDIR if they don't exist.
. "${ARC_GNU}"/toolchain/define-release.sh
# Set defaults for some options
do_busybox="--busybox"
busybox_version="1_22_1"
linux_dir=linux
linux_defconfig=nsimosci_defconfig
linux_version="arc-3.13"
arc_initramfs="ARC700/arc_initramfs_12_2013_gnu_4_8_ABI_v3.tgz"
tooldir=/opt/arc-${RELEASE}
# Parse options
getopt_string=`getopt -n build-kernel.sh -o d:i:l:t:h -l linux-defconfig: \
-l initramfs: -l linux-dir: -l tooldir -l help \
-l busybox -l no-busybox \
-l busybox-version: -l linux-version: \
-s sh -- "$@"`
eval set -- "$getopt_string"
while true
do
case $1 in
-d|--linux-defconfig)
# If set, argument specifies the Linux defconfig to use, otherwise
# no defconfig is run.
shift
linux_defconfig=$1
;;
-i|--initramfs)
# Argument specifies the initramfs to use relative to the
# arc_initramfs_archives directory.
shift
initramfs=$1
;;
-l|--linux-dir)
# Argument specifies the name of the Linux directory.
shift
linux_dir=$1
;;
-t|--tooldir)
# Argument specifies the name of the tool chain installation
# directory.
shift
tooldir="$1"
;;
--busybox | --no-busybox)
# Disable building BusyBox if desired.
do_busybox="$1"
;;
--busybox-version)
# Argument specifies the branch/tag of BusyBox to checkout. If set
# to the emptry string, no checkout is done.
shift
busybox_version=$1
;;
--linux-version)
# Argument specifies the branch/tag of Linux to checkout. If set
# to the emptry string, no checkout is done.
shift
linux_version=$1
;;
-h|--help)
echo "Usage: ./build-kernel.sh [-i|--initramfs <initramfs>]"
echo " [-d|--linux-defconfig <config>]"
echo " [-l|--linux-dir <dir>]"
echo " [-t|--tooldir <dir>]"
echo " [--busybox | --no-busybox]"
echo " [--busybox-version]"
echo " [--linux-version]"
echo " [-h|--help]"
exit 0
;;
--)
shift
break
;;
*)
echo "Internal error!"
echo $1
exit 1
;;
esac
shift
done
# Silently ignore any other arguments
# Set up logging
logfile="${LOGDIR}/kernel-build-$(date -u +%F-%H%M).log"
rm -f "${logfile}"
echo "Logging to ${logfile}"
# Ensure we have the right tool chain on the path!
PATH=${tooldir}/bin:${PATH}
export PATH
# ------------------------------------------------------------------------------
#
# Set up initramfs
#
# ------------------------------------------------------------------------------
# Create arc_initramfs if specified. Need to patch the ownership.
logterm "Creating initramfs..."
# Work from top level directory so arc_initramfs is created in the correct
# directory.
if ! cd ${ARC_GNU} >> ${logfile} 2>&1
then
logterm "ERROR: Could not change to root directory ${ARC_GNU}"
failedbuild
fi
if [ "x${arc_initramfs}" != "x" ]
then
echo "(sudo password may be needed to set up initramfs)"
sudo rm -rf arc_initramfs >> ${logfile} 2>&1
sudo tar zxpf arc_initramfs_archives/${arc_initramfs} >> ${logfile} 2>&1
sudo chown -hR `id -u`:`id -g` arc_initramfs >> ${logfile} 2>&1
fi
# Blow away all existing libraries and copy in all the shared libraries and
# one static library that is referred to. Edit libc.so to use the new
# filename.
logterm "Setting up libraries..."
# Do we need to blow away existing libraries?
rm -f arc_initramfs/lib/* >> ${logfile} 2>&1
cp -df ${tooldir}/arc-linux-uclibc/lib/*.so* \
arc_initramfs/lib >> $logfile 2>&1
cp -df ${tooldir}/arc-linux-uclibc/lib/uclibc_nonshared.a \
arc_initramfs/lib >> $logfile 2>&1
sed -i arc_initramfs/lib/libc.so -e 's#/opt/[^/]*/arc-linux-uclibc##g'
# Copy across custom binaries
logterm "Copy custom binaries..."
cp -d ${tooldir}/target-bin/* arc_initramfs/bin >> $logfile 2>&1
# Fix rcS
sed -i arc_initramfs/etc/init.d/rcS \
-e '/\/sbin\/udhcpc eth0/ d' \
-e '/Bringing up eth0/ a \
ifconfig eth0 192.168.218.2 netmask 255.255.255.0'
# ------------------------------------------------------------------------------
#
# Build BusyBox
#
# ------------------------------------------------------------------------------
# Building BusyBox is optional
if [ "${do_busybox}" = "--busybox" ]
then
# As a sanity check remove the busybox images from initramfs. This means a
# failed install of busybox will show up!
rm -f arc_initramfs/bin/busybox*
rm -f arc_initramfs/lib/busybox*
# Build busybox.
logterm "Building BusyBox..."
if ! cd ${ARC_GNU}/busybox
then
logterm "ERROR: Could not change to BusyBox directory"
failedbuild
fi
if [ "x${busybox_version}" != "x" ]
then
logterm "Checking out version ${busybox_version}"
if ! git checkout ${busybox_version}
then
logterm "ERROR: Could not check out BusyBox"
failedbuild
fi
fi
logterm "Cleaning BusyBox..."
if ! make clean >> $logfile 2>&1
then
logterm "ERROR: Could not clean BusyBox"
failedbuild
fi
logterm "Making BusyBox defconfig..."
if ! make defconfig >> $logfile 2>&1
then
logterm "ERROR: Could not build Busybox defconfig"
failedbuild
fi
# We need to turn off IPv6 and set the correct location for the
# installation.
logterm "Patching BusyBox config..."
sed -i .config \
-e 's/CONFIG_PING6=y/# CONFIG_PING6 is not set/' \
-e 's/CONFIG_FEATURE_IPV6=y/# CONFIG_FEATURE_IPV6 is not set/' \
-e 's/CONFIG_FEATURE_PREFER_IPV4_ADDRESS=y/# CONFIG_FEATURE_PREFER_IPV4_ADDRESS is not set/' \
-e 's/CONFIG_FEATURE_IFUPDOWN_IPV6=y/# CONFIG_FEATURE_IFUPDOWN_IPV6 is not set/' \
-e 's/CONFIG_TRACEROUTE6=y/# CONFIG_TRACEROUTE6 is not set/' \
-e 's/CONFIG_CROSS_COMPILER_PREFIX=""/CONFIG_CROSS_COMPILER_PREFIX="arc-linux-uclibc-"/' \
-e 's|CONFIG_PREFIX="./_install"|CONFIG_PREFIX="../arc_initramfs"|'
logterm "Making BusyBox..."
if ! make >> $logfile 2>&1
then
logterm "ERROR: Could not build Busybox"
failedbuild
fi
logterm "Installing BusyBox..."
if ! make install >> $logfile 2>&1
then
logterm "ERROR: Could not install Busybox"
failedbuild
fi
logterm "Changing ownership and setuid of BusyBox..."
echo "(sudo password may be needed)"
if ! sudo chown root.root ../arc_initramfs/bin/busybox
then
logterm "ERROR: Could not change BusyBox ownership to root"
failedbuild
fi
if ! sudo chmod ug+s ../arc_initramfs/bin/busybox
then
logterm "ERROR: Could not make BusyBox setuid root"
failedbuild
fi
fi
# ------------------------------------------------------------------------------
#
# Build Linux
#
# ------------------------------------------------------------------------------
logterm "Building linux..."
if ! cd ${ARC_GNU}/${linux_dir}
then
logterm "ERROR: Could not change to Linux directory ${linux_dir}"
failedbuild
fi
if [ "x${linux_version}" != "x" ]
then
logterm "Checking out version ${linux_version}"
if ! git checkout ${linux_version}
then
logterm "ERROR: Could not check out linux"
failedbuild
fi
fi
if [ "x${linux_defconfig}" != "x" ]
then
# Only clean if we are setting a defconfig
logterm "Cleaning Linux..."
if ! make ARCH=arc distclean >> $logfile 2>&1
then
logterm "ERROR: Could not clean Linux"
failedbuild
fi
logterm "Setting default config ${linux_defconfig}"
if ! make ARCH=arc KBUILD_DEFCONFIG=${linux_defconfig} defconfig \
>> $logfile 2>&1
then
logterm "ERROR: Could not make default config for Linux"
failedbuild
fi
#else
# make ARCH=arc defconfig >> $logfile 2>&1
fi
# Patch in the correct compiler and initramfs location for the kernel config
logterm "Patching LINUX .config..."
sed -i -e 's|CONFIG_INITRAMFS_SOURCE=".*"|CONFIG_INITRAMFS_SOURCE="../arc_initramfs/"|' \
-e 's/COMPILE="arc-elf32-"/COMPILE="arc-linux-uclibc-"/' .config
logterm "Making Linux..."
if ! make ARCH=arc >> $logfile 2>&1
then
logterm "ERROR: Could not build Linux"
failedbuild
fi
logterm "Linux build successful. See ${logfile} for details."
exit 0
# vim: noexpandtab sts=4 ts=8: