]> cvs.zerfleddert.de Git - proxmark3-svn/blob - tools/install-gnuarm4.sh
631717f09526acbf8d25b7fec09f87620be9ac67
[proxmark3-svn] / tools / install-gnuarm4.sh
1 #!/bin/bash
2
3 # Some things for you to configure
4 BINUTILS_VER="2.19.1a"
5 GCC_VER="4.3.3"
6 GDB_VER="6.8a"
7 NEWLIB_VER="1.17.0"
8 GMP_VER="4.2.4"
9 MPFR_VER="2.4.2"
10 INSIGHT_VER="6.8a"
11
12 # Where you want to install the tools
13 if [ "${1}" = "" ]; then
14 echo "Syntax: ${0} </installation/target/directory> [download & build directory (default ${PWD})]"
15 exit 1
16 else
17 DESTDIR="${1}"
18 fi
19
20 # Where do you want to build the tools. This is where the log files
21 # will be written (which you can monitor with 'tail' during compilation).
22 # You can delete this directory after everything is done.
23 if [ ! "${2}" = "" ]; then
24 SRCDIR="${2}"
25 else
26 SRCDIR="${PWD}"
27 fi
28 BUILDDIR=${SRCDIR}/build-gnuarm4
29
30 # Where to get each of the toolchain components
31 BINUTILS=http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VER}.tar.bz2
32 BINUTILS_TAR=binutils-${BINUTILS_VER}.tar.bz2
33 GCCCORE=http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-core-${GCC_VER}.tar.bz2
34 GCCCORE_TAR=gcc-core-${GCC_VER}.tar.bz2
35 GPP=http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-g++-${GCC_VER}.tar.bz2
36 GPP_TAR=gcc-g++-${GCC_VER}.tar.bz2
37 NEWLIB=ftp://sources.redhat.com/pub/newlib/newlib-${NEWLIB_VER}.tar.gz
38 NEWLIB_TAR=newlib-${NEWLIB_VER}.tar.gz
39 #INSIGHT=ftp://sourceware.org/pub/insight/releases/insight-${INSIGHT_VER}.tar.bz2
40 INSIGHT=http://mirrors.kernel.org/sources.redhat.com/insight/releases/insight-${INSIGHT_VER}.tar.bz2
41 INSIGHT_TAR=insight-${INSIGHT_VER}.tar.bz2
42 #INSIGHT=http://www.mirrorservice.org/sites/sources.redhat.com/pub/insight/releases/insight-${INSIGHT_VER}.tar.bz2
43 GDB=http://ftp.gnu.org/gnu/gdb/gdb-${GDB_VER}.tar.bz2
44 GDB_TAR=gdb-${GDB_VER}.tar.bz2
45 GMP=http://ftp.sunet.se/pub/gnu/gmp/gmp-${GMP_VER}.tar.bz2
46 GMP_TAR=gmp-${GMP_VER}.tar.bz2
47 MPFR=http://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VER}.tar.bz2
48 MPFR_TAR=mpfr-${MPFR_VER}.tar.bz2
49 GNU_KEYRING_GPG=gnu-keyring.gpg
50 GNU_KEYRING=ftp://ftp.gnu.org/gnu/${GNU_KEYRING_GPG}
51
52 # Common configuration options (i.e., things to pass to 'configure')
53 COMMON_CFG="--enable-interwork --target=arm-eabi --program-prefix=arm-eabi- --prefix=${DESTDIR} --disable-werror --enable-languages=c,c++ --enable-multilib --disable-shared"
54
55 # Extra configuration options for each toolchain component
56 BINUTILS_CFG=
57 GCCCORE_CFG="--disable-nls --disable-threads --with-gcc --with-gnu-ld --with-gnu-as --with-dwarf2 --with-newlib --with-headers=${BUILDDIR}/newlib-${NEWLIB_VER}/newlib/libc/include --disable-libssp --disable-libstdcxx-pch --disable-libmudflap --disable-libgomp -v"
58 NEWLIB_CFG=
59 INSIGHT_CFG=
60 GDB_CFG=
61
62 # Make flags
63 MAKEFLAGS="-j 4"
64
65 # wget options
66 # -nv: non-verbose but not too quiet (still print errors/warnings)
67 # -nc: no-clobber, do not download a file that already exists
68 # -t 0: retry indefinitely
69 # -a wget.log: append errors/warnings to wget.log file
70 # -c continue
71 #WGET_OPTS="-nv -nc -t 0 -a wget.log"
72 WGET_OPTS="-c -t 0"
73
74 # Compiler flags for compiling Newlib (-O2 is already hard-coded)
75 NEWLIB_FLAGS="-march=armv4t -mcpu=arm7tdmi -g"
76
77 ############################################################################
78 # End of configuration section. You shouldn't have to modify anything below.
79 ############################################################################
80
81 if [[ `whoami` != "root" ]]; then
82 echo "*** Warning! Not running as root!"
83 echo "Installation may fail if you do not have appropriate permissions!"
84 fi
85
86 mkdir -p ${BUILDDIR}
87 cd ${SRCDIR}
88
89 if [[ -f all.downloaded ]]; then
90 echo Looks like all downloads are complete, skipping downloads
91 else
92 wget ${WGET_OPTS} ${GNU_KEYRING}
93 # TODO: need to avoid polluting the users keyring, but how?!
94 gpg --import ${GNU_KEYRING_GPG}
95
96 # TODO: guess it's better to have a function that "downloads, checks file-presence and signature, and returns true/false" whether the file is ok
97 # Function will check if file exists (otherwise try to download the file - if failed and file still doesn't exist, complain and exit the script)
98 # Check if signature file exists (otherwise download the signature file as well - if download fail, warn the user and return function)
99 # Check the signature. If failed, backup-by-renaming current files, redownload both file & signature, run the function body one more time - if still no success, warn and return from function
100
101 # NOTE: If new downloads are added here, please see the IMPORTANT note below
102 echo Now downloading BINUTILS...
103 wget ${WGET_OPTS} ${BINUTILS}
104 wget -N ${WGET_OPTS} ${BINUTILS}.sig
105 gpg --verify ${BINUTILS_TAR}.sig 2> /dev/null
106 if [[ $? != 0 ]]; then
107 echo "Failed signature check for:" ${BINUTILS_TAR}.sig
108 exit 1
109 fi
110
111 echo Now downloading GCC...
112 wget ${WGET_OPTS} ${GCCCORE}
113 wget -N ${WGET_OPTS} ${GCCCORE}.sig
114 gpg --verify ${GCCCORE_TAR}.sig 2> /dev/null
115 if [[ $? != 0 ]]; then
116 echo "Failed signature check for:" ${GCCCORE_TAR}.sig
117 exit 1
118 fi
119
120 echo Now downloading G++...
121 wget ${WGET_OPTS} ${GPP}
122 wget -N ${WGET_OPTS} ${GPP}.sig
123 gpg --verify ${GPP_TAR}.sig 2> /dev/null
124 if [[ $? != 0 ]]; then
125 echo "Failed signature check for:" ${GPP_TAR}.sig
126 exit 1
127 fi
128
129 echo Now downloading NEWLIB...
130 wget ${WGET_OPTS} ${NEWLIB}
131 # TODO: signature/hash check
132
133 echo Now downloading INSIGHT...
134 wget ${WGET_OPTS} ${INSIGHT}
135 # TODO: signature/hash check
136
137 echo Now downloading GDB...
138 wget ${WGET_OPTS} ${GDB}
139 wget -N ${WGET_OPTS} ${GDB}.sig
140 gpg --verify ${GDB_TAR}.sig 2> /dev/null
141 if [[ $? != 0 ]]; then
142 echo "Failed signature check for:" ${GDB_TAR}.sig
143 exit 1
144 fi
145
146 echo Now downloading GMP...
147 wget ${WGET_OPTS} ${GMP}
148 wget -N ${WGET_OPTS} ${GMP}.sig
149 gpg --verify ${GMP_TAR}.sig 2> /dev/null
150 if [[ $? != 0 ]]; then
151 echo "Failed signature check for:" ${GMP_TAR}.sig
152 exit 1
153 fi
154
155 echo Now downloading MPFR...
156 wget ${WGET_OPTS} ${MPFR}
157 wget -N ${WGET_OPTS} ${MPFR}.sig
158 gpg --verify ${MPFR_TAR}.sig 2> /dev/null
159 if [[ $? != 0 ]]; then
160 echo "Failed signature check for:" ${MPFR_TAR}.sig
161 exit 1
162 fi
163
164 # IMPORTANT: Here is the number of .tar. archives downloaded above. Please update if new .tar. are added to download list.
165 if [[ `ls -1 *.tar.bz2 *.tar.gz | wc -l` != 8 ]]; then
166 echo "Seems like not all prerequisite files donwloaded... Exiting."
167 exit 1
168 else
169 touch all.downloaded
170 fi
171 fi
172
173 cd ${BUILDDIR}
174 if [[ -f binutils.built ]]; then
175 echo Looks like BINUTILS was already built.
176 else
177 echo Building BINUTILS...
178 tar -xjf ../`basename ${BINUTILS}`
179 echo ___________________ > make.log
180 echo Building binutils... >> make.log
181 cd `find . -maxdepth 1 -type d -name 'binutils*'`
182 mkdir gnuarm
183 cd gnuarm
184 ../configure ${COMMON_CFG} ${BINUTILS_CFG} >> ../../make.log 2>&1
185 make ${MAKEFLAGS} MAKEINFO=`which makeinfo` >> ../../make.log 2>&1
186 make install >> ../../make.log 2>&1
187 cd ../..
188 touch binutils.built
189 fi
190
191 echo ___________________ >> make.log
192 echo Adding ${DESTDIR}/bin to PATH >> make.log
193 export PATH; PATH=${DESTDIR}/bin:$PATH
194 echo ___________________ >> make.log
195
196 if [[ -f gcc.built ]]; then
197 echo Looks like GCC was already built.
198 else
199 echo Building GCC...
200 tar -xjf ../`basename ${GCCCORE}`
201 tar -xjf ../`basename ${GPP}`
202 tar -xjf ../`basename ${GMP}`
203 ln -s "${BUILDDIR}/gmp-${GMP_VER}" "${BUILDDIR}/gcc-${GCC_VER}/gmp"
204 tar -xjf ../`basename ${MPFR}`
205 ln -s "${BUILDDIR}/mpfr-${MPFR_VER}" "${BUILDDIR}/gcc-${GCC_VER}/mpfr"
206 tar -xzf ../`basename ${NEWLIB}`
207
208 echo ___________________ >> make.log
209
210 cat << EOF > gcc.patch
211 --- gcc-4.3.3.orig/gcc/config/arm/t-arm-elf
212 +++ gcc-4.3.3.mod/gcc/config/arm/t-arm-elf
213 @@ -33,8 +33,8 @@
214 # MULTILIB_DIRNAMES += fpu soft
215 # MULTILIB_EXCEPTIONS += *mthumb/*mhard-float*
216 #
217 -# MULTILIB_OPTIONS += mno-thumb-interwork/mthumb-interwork
218 -# MULTILIB_DIRNAMES += normal interwork
219 +MULTILIB_OPTIONS += mno-thumb-interwork/mthumb-interwork
220 +MULTILIB_DIRNAMES += normal interwork
221 #
222 # MULTILIB_OPTIONS += fno-leading-underscore/fleading-underscore
223 # MULTILIB_DIRNAMES += elf under
224 EOF
225
226 echo Patching GCC >> make.log
227 cd `find . -maxdepth 1 -type d -name 'gcc*'`
228 patch -p1 < ../gcc.patch
229 echo Building gcc... >> make.log
230 mkdir gnuarm
231 cd gnuarm
232 ../configure ${COMMON_CFG} ${GCCCORE_CFG} >> ../../make.log 2>&1
233 make ${MAKEFLAGS} all-gcc >> ../../make.log 2>&1
234 make install >> ../../make.log 2>&1
235 cd ../..
236 touch gcc.built
237 fi
238
239 if [[ -f newlib.built ]]; then
240 echo Looks like NEWLIB was already built.
241 else
242 echo Building NEWLIB...
243 echo ___________________ >> make.log
244 echo Building newlib... >> make.log
245 cd `find . -maxdepth 1 -type d -name 'newlib*'`
246 mkdir gnuarm
247 cd gnuarm
248 ../configure ${COMMON_CFG} ${NEWLIB_CFG} >> ../../make.log 2>&1
249
250 # This line adds our NEWLIB_CFLAGS to the configure.host file in the
251 # newlib subdirectory. This is the only way I could find to tell Newlib to
252 # compile itself with the -mmarch=armv4t and -mcpu=arm7tdmi flags.
253 # sed -i "/^newlib_cflags=/s/=.*\$/=\"${NEWLIB_FLAGS}\"/" ../newlib/configure.host
254 make ${MAKEFLAGS} >> ../../make.log 2>&1
255 make install >> ../../make.log 2>&1
256 cd ../..
257 touch newlib.built
258 fi
259
260 echo ___________________ >> make.log
261 echo "Now that newlib is built, second pass for GCC..." >> make.log
262 cd `find . -maxdepth 1 -type d -name 'gcc*'`
263 cd gnuarm
264 make ${MAKEFLAGS} >> ../../make.log 2>&1
265 make install >> ../../make.log 2>&1
266 cd ../..
267
268
269 if [[ -f insight.built ]]; then
270 echo Looks like INSIGHT was already built.
271 else
272 echo Building INSIGHT...
273 tar -xjf ../`basename ${INSIGHT}`
274 echo ___________________ >> make.log
275 echo Building insight... >> make.log
276 cd `find . -maxdepth 1 -type d -name 'insight*'`
277 mkdir gnuarm
278 cd gnuarm
279 ../configure ${COMMON_CFG} ${INSIGHT_CFG} >> ../../make.log 2>&1
280 make ${MAKEFLAGS} >> ../../make.log 2>&1
281 make install >> ../../make.log 2>&1
282 cd ../..
283 touch insight.built
284 fi
285
286 if [[ -f gdb.built ]]; then
287 echo Looks like GDB was already built.
288 else
289 echo Building GDB...
290 tar -xjf ../`basename ${GDB}`
291 echo ___________________ >> make.log
292 echo Building insight... >> make.log
293 cd `find . -maxdepth 1 -type d -name 'gdb*'`
294 mkdir gnuarm
295 cd gnuarm
296 ../configure ${COMMON_CFG} ${GDB_CFG} >> ../../make.log 2>&1
297 make ${MAKEFLAGS} >> ../../make.log 2>&1
298 make install >> ../../make.log 2>&1
299 cd ../..
300 touch gdb.built
301 fi
302
303 echo ___________________ >> make.log
304 echo Build complete. >> make.log
305
306 cd ${DESTDIR}
307 chmod -R a+rX .
308
309 echo Downloaded archives are in ${SRCDIR}
310 echo build driectory: ${BUILDDIR}
311 echo set environment variable ARMLIB to ${DESTDIR}/lib/gcc/arm-elf/4.3.3/interwork for Makefile.linux
312 exit 0
Impressum, Datenschutz