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