This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·215 lines (190 loc) · 5.76 KB
/
build.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
#! /bin/bash
# Builds a toolchain and qemu-system for testing and debugging WebKit.
#
# Usage:
# build.sh [ --? | -h | --help ]
# [ -a | --arch "..." ]
# [ -j ] Number of cores to use during build (default: $(nproc))
# [ -k ]
# [ --br2 "..." ]
# [ --br2-version "..." ]
# [ --br2-external "..." ]
# [ --temp | --tmp "..." ]
# [ --sdk ]
# [ --version ]
# output-directory
#
PROGRAM=$(basename "$0")
VERSION=1.0
ARCH=
BR2PATH=
BR2VERSION='2020.05.2'
BR2EXTERNAL=
TEMPPATH=
JLEVEL=$(nproc)
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
SDK=0
KEEP=0
# shellcheck source=./common.sh
source "${DIR}/common.sh"
usage()
{
cat <<EOF
Usage:
$PROGRAM
[ -h | --help | --? ] Show help and exit
[ -a | --arch ] Platform to build system for (required!)
[ -j ] Number of cores to use during build (default: $(nproc))
[ -k ] Keep temporary files
[ --br2 "..." ] Path to custom buildroot tree (default: checkout)
[ --br2-version "..." ] Buildroot tag to checkout (default: $BR2VERSION)
[ --br2-external "..." ] Path to custom buildroot JSC external tree (default: checkout)
[ --temp | --tmp "..." ] Path to custom temporary directory (default: create)
[ --sdk ] Generate SDK file
[ --version ] Show version and exit
output-directory Directory to install buildroot to
EOF
}
while test $# -gt 0
do
case $1 in
--br2 )
shift
BR2PATH="$1"
;;
--br2-version )
shift
BR2VERSION="$1"
;;
--br2-external )
shift
BR2EXTERNAL="$1"
;;
--temp | --tmp )
shift
TEMPPATH="$1"
;;
-a | --arch )
shift
ARCH="$1"
;;
-j )
shift
JLEVEL="$1"
;;
--sdk )
SDK=1
;;
-k )
KEEP=1
;;
--version )
version "${PROGRAM}" "${VERSION}"
exit 0
;;
--help | -h | '--?' )
usage_and_exit 0
;;
-*)
error "Unrecognized option: $1"
;;
*)
break
;;
esac
shift
done
# Argument and flag option checks
if [ -z "${ARCH}" ]; then
error "architecture option -a or --arch is required (supported archs: mips, arm)"
fi
# Also accept mipsel for mips
if [[ "${ARCH}" == "mipsel" ]]; then
ARCH="mips"
fi
if [[ "${ARCH}" != "mips" ]] && [[ "${ARCH}" != "arm" ]]; then
error "unsupported architecture ${ARCH}, select arm or mips"
fi
BR2_DEFCONFIG=
if [[ "${ARCH}" == "mips" ]]; then
BR2_DEFCONFIG="qemu-mips32elr2-jsc_defconfig"
else
BR2_DEFCONFIG="qemu-arm32-jsc_defconfig"
fi
if [ "$#" != "1" ]; then
error "expected a single argument, got $#"
fi
if [ -z "${TEMPPATH}" ]; then
TEMPPATH=$(mktemp -d)
fi
# Receives one argument, the destination directory for the build
OUTPUT=$(realpath -m "$1")
if ! mkdir -p "${OUTPUT}" &> /dev/null; then
error "output path already exists: ${OUTPUT}"
fi
progress "Creating toolchain in ${OUTPUT}"
pushd "${TEMPPATH}" || error "cannot pushd"
if [ -z "${BR2EXTERNAL}" ]; then
progress "cloning jsc br2 external"
git clone --quiet --depth=1 https://github.com/pmatos/jsc-br2-external.git
fi
if [ -z "${BR2PATH}" ]; then
progress "cloning buildroot"
git clone --quiet --depth=1 --branch "${BR2VERSION}" https://github.com/buildroot/buildroot
fi
popd || error "cannot popd"
pushd "${OUTPUT}" || error "cannot pushd"
progress "configuring buildroot defconfig"
if ! make O="${PWD}" -C "${TEMPPATH}/buildroot" BR2_EXTERNAL="${TEMPPATH}/jsc-br2-external" "${BR2_DEFCONFIG}" &> "${TEMPPATH}/configure.log"; then
tail "${TEMPPATH}/configure.log"
error "failed to configure buildroot"
fi
if [[ "${ARCH}" == "arm" ]]; then
progress "extraordinary patching of gdb-8.3.1 in ARMv7"
pushd "${OUTPUT}" || error "cannot pushd"
make host-gdb-patch
pushd "${OUTPUT}/build/host-gdb-8.3.1" || error "cannot pushd"
if ! patch -p1 < "${DIR}/851c0536cabb661847c45c73ebd796eb3299066b.diff"; then
error "failed to patch"
fi
popd || error "cannot popd"
popd || error "cannot popd"
fi
progress "extraordinary patching of kernel 4.19"
pushd "${OUTPUT}" || error "cannot pushd"
make linux-patch
sed -i 's/^YYLTYPE yylloc;$/extern YYLTYPE yylloc;/' ./build/linux-4.19.91/scripts/dtc/dtc-lexer.l
popd || error "cannot popd"
progress "building root"
if ! make BR2_JLEVEL="${JLEVEL}" &> "${TEMPPATH}/build.log"; then
tail "${TEMPPATH}/build.log"
error "failed to build buildroot"
fi
# Need to convert image to use it as backing file
progress "Converting raw image to qcow2"
if ! host/bin/qemu-img convert -q -O qcow2 images/rootfs.ext2 images/rootfs.qcow2; then
error "Failed to convert image"
fi
if [[ "${SDK}" == "1" ]]; then
progress "building sdk"
if ! make BR2_JLEVEL="${JLEVEL}" sdk &> "${TEMPPATH}/sdk.log"; then
tail "${TEMPPATH}/sdk.log"
error "failed to build sdk"
fi
if [[ "${ARCH}" == "mips" ]] && [[ -f "images/mipsel-buildroot-linux-gnu_sdk-buildroot.tar.gz" ]]; then
progress "SDK image in: images/mipsel-buildroot-linux-gnu_sdk-buildroot.tar.gz"
ln images/mipsel-buildroot-linux-gnu_sdk-buildroot.tar.gz images/sdk.tar.gz
elif [[ "${ARCH}" == "arm" ]] && [[ -f "images/arm-buildroot-linux-gnueabihf_sdk-buildroot.tar.gz" ]]; then
progress "SDK image in: images/arm-buildroot-linux-gnueabihf_sdk-buildroot.tar.gz"
ln images/arm-buildroot-linux-gnueabihf_sdk-buildroot.tar.gz images/sdk.tar.gz
else
error "cannot find SDK image"
fi
fi
popd || error "cannot popd"
if [[ "${KEEP}" == "1" ]]; then
progress "Keeping temporary files in ${TEMPPATH}"
else
progress "Cleaning up temporary folder ${TEMPPATH}"
rm -Rf "${TEMPPATH}"
fi