OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [toolchain_install_scripts/] [MOF_ORSOC_TCHN_v5c_or32-elf.sh] - Blame information for rev 72

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 22 ocadmin
#!/bin/bash
2
 
3 72 julius
# Copyright (C) 2008,2009,2010 www.meansoffreedom.org, www.orsoc.se
4 22 ocadmin
# This file is free software; you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
# General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
 
18 72 julius
##Date: 11/03/2010
19 22 ocadmin
##Title: MOF_ORSOC_TCN_v5c_or32-elf.sh
20
##Purpose: Complete Toolchain Builder from MOF & ORSoC.
21
##initial rgd, mse
22
##updated jb
23
 
24
#Changelog
25
# 090306 - jb
26
#        - added exit code checking after each make and patch
27
#        - changed download method to instead generate a script and run it in
28
#          kermit (requiring single ftp logon per host)
29
# 090309 - jb
30
#        - changed download of GNU tools so they occurr from the GNU.org ftp
31
#          (except binutils-2.18.50, it's not there)
32
#        - changed download of Linux kernel so it's now from ftp.kernel.org
33
#        - changed patch for binutils (fixes gcc-4.3.2 compilation problem
34
#          caused by non-string literals in printf)
35
#        - changed or1ksim version from 0.3.0rc2 to 0.3.0
36
#        - changed Linux kernel version from 2.6.19 to 2.6.24
37
#        - changed Linux kernel patch version for this new kernel version
38
#          generated new patch for Linux kernel, based on one from MOF
39
#          (www.meansoffreedom.net) which contains a more complete config file.
40
#          removing need for user input during "make oldconfig"
41
#        - changed organisation so that all the packages are not copied into
42
#          the build directory before they are extracted, instead it's done
43
#          from where they are.
44
#        - changed gdb-6.8 patch version due to stricter gcc-4.3.2 checking
45
#          return types.
46
#        - included better or1ksim config file in Linux sources patch, now
47
#          named "or1ksim_linux.cfg"
48
# 100309 - jb
49
#        - changed back to wget for file retrieval
50
#        - changed introduction readme
51
#        - changed install destination checking and setup
52
#        - added md5sum checking of any existing downloaded files, removing
53
#          need for redownloading things every time
54
#        - added debug build mode - run script with -d at command line
55
#          note: not everything in this mode has been tested, may not work
56
#          in certain combinations!
57
# 120309 - jb
58
#        - New OS X version - busybox doesn't work (removed from script),
59
#          nor does ors1ksim (compiles but segfaults somewhere during test).
60
# 140309 - Added ability to change target name. Included some sed commands to
61
#          change or32-uclinux to whatever $TARGET is set to in some scripts
62
#          (mainly for uClibc install, the are set at configure time)
63
# 160309 - (v5a) Replaced busybox sources in download list (removed for OS X
64
#          version and forgot to replace it when running on Linux again.)
65
# 270309 - Changed the declaration of the check_exit_code function to be without
66
#          the preceeding "function" as this isn't valid in sh, and the new way
67
#          appears to be valid in bash.
68
#        - Changed the link in the error output to the new OpenCores forum.
69
# 210409 - Changed linux kernel and uClibc patch versions to latest
70
#        - Changed output to all be piped to appropriate files, makes things neater
71
# 260409 - Added Cygwin exports section
72
#        - Hopefully now runs on Cygwin with new patch for uClibc
73
# 300409 - New Binutils patch - fixes objdump instruction decode issue
74
# 110509 - (v5c) Put in check for required build tools before building
75 37 julius
# 260509 - Changed gcc's package download to gcc-core as we only use the
76
#          c-language compiler and libraries right now.
77 39 julius
# 030609 - Fixed odd problem with uClibc build on latest Cygwin where it tried
78
#          to run the INSTALL script file instead of the systems install binary
79
#          by adding a suffix to the text file.
80 43 julius
# 290609 - Changed linux patch to 2.3 - is a patch derived from revision 42 of
81
#          OpenRISC repository's kernel.
82 59 julius
# 301109 - Changed GCC patch to one with single precision floating point as
83
#          default
84
# 021209 - Added --disable-werror flag to gdb-6.8 configure line to fix issue
85
#          with gcc-4.4.1
86 72 julius
# 110310 - Moved or1ksim to its own directory in the chosen install directory
87 59 julius
 
88 22 ocadmin
# TODO: OS X build things - need an "elf.h" from some Linux machine's
89
#       /usr/local/include dir and put in Mac's /usr/local/include dir -
90
#       this solves issue with Linux compilation
91
# TODO: OS X build things - add HOST_LOADLIBES="lintl" to make line of uClibc
92
# TODO: OS X build things - must remove the -Werror line in $GDB_VER/gdb/Makefile,
93
#       sed command:
94
#       sed 's/WERROR\_CFLAGS\ \=\ \-Werror/WERROR\_CFLAGS\ \=/' $GDB_VER/gdb/Makefile
95
#       Can also just change the gdb-6.8/gdb/Makefile.in and remove the Werror= thing
96
# TODO: OS X build things - or1ksim, in or1ksim-0.3.0/peripheral/atadevice.c, it
97
#       includes byteswap.h - actually it's abstract.h that defines #LE_16() bswap_16(),
98
#       so in abstract.h we put in defines for bswap_16 as
99
#       #define bswap_16(value) ((((value) & 0xff) << 8) | ((value) >> 8))
100
# TODO: OS X Build things - or1ksim strndup.c, in or1k-0.3.0/port/strndup.c strndup function,
101
#       types not exist etc. Need to include sys/types.h and string.h to this file to fix
102
#       a few problems.
103
# TODO: OS X build things - or1ksim - or1ksim-0.3.0/sim-cmd.c passes one of our functions
104
#       to a readline function, rl_event_hook, but this is not defined in the OS X (BSD)
105
#       readline package, so the GNU readline package must be used.
106
# TODO: OS X build things - or1ksim segfaults when run for some reason.
107
 
108
## A function we'll call throughout the setup process to check if the previous
109
## command finished without error
110
check_exit_code()
111
{
112
    if [ $? -ne 0 ]
113
    then
114
        echo
115
        echo "############################ERROR#############################"
116
        echo
117
        echo "Error during toolchain installation."
118
        echo
119
        echo "Please report this to the script maintainers."
120
        echo
121 45 julius
        echo "A useful report would contain information such as the tool"
122
        echo "being built/\"make\"d when the error occurred and the relevant"
123
        echo "lines of console output or log file relating to the error. It"
124
        echo "also helps to include information about your the host OS and"
125
        echo "version of GCC."
126
        echo "A good place to look for solutions, and report any bugs, is at"
127
        echo "the OpenRISC project's bug tracker on OpenCores.org:"
128 22 ocadmin
        echo
129 45 julius
        echo "           http://opencores.org/openrisc,bugtracker"
130
        echo
131 22 ocadmin
        exit $?
132
    fi
133
}
134
 
135
REQUIRED_TOOL_LIST="
136
make
137
patch
138
gcc
139
g++
140
bzip2
141
wget
142
makeinfo
143
"
144
check_essential_build_tools()
145
{
146
 
147
echo "#########################Checking for required build tools######################"
148
echo
149
        for TOOL in $REQUIRED_TOOL_LIST
150
        do
151
            echo -n "Checking for $TOOL    "
152
            WHICHTOOL=`which $TOOL`
153
            echo "$WHICHTOOL"
154
            if [ -z $WHICHTOOL ]
155
            then
156
                echo
157
                echo "\t$TOOL not found"
158
                echo
159
                echo "Please install $TOOL and re-run this script"
160
                echo
161
                exit 2
162
            fi
163
        done
164
 
165
# Now check if libncurses-dev has been installed - check for the header
166
# Get host system's GCC prefix dir (usually /usr, but just to be sure)
167
# Get the verbose output of GCC, redirect STDERR to STDOUT, pipe to grep replacing spaces with newlines
168
# grep for the prefix dir line, cut away after the equals sign and we should have the right dir
169
        echo "Checking for libncurses-dev (headers)"
170 72 julius
        GCC_V_LIST=`gcc -v 2>&1 | sed -e s/\ /'\\\n'/g`
171
        HOST_GCC_PREFIX=`echo $GCC_V_LIST | grep prefix | cut -d = -f 2 | head -1`
172 22 ocadmin
        NCURSES_HEADER_COUNT=`find $HOST_GCC_PREFIX/include -name "ncurses.h" | grep ncurses -c`
173
        if [ $NCURSES_HEADER_COUNT -eq 0 ]; then
174
            echo
175
            echo "\tlibncurses-dev not found"
176
            echo ; echo "Please install libncurses-dev and re-run this script"; echo
177
            exit 2
178
        fi
179
# Todo: somehow inform the user that if we're checking for makeinfo they need to install texinfo package
180
        echo
181
}
182
 
183
## SCRIPT VERSION ##
184
SCRIPT_VERSION="v5c"
185
 
186
## Beginning globals ##
187
 
188
## ORSoC FTP download settings ##
189
ORSOC_FTP_HOST="195.67.9.12"
190
ORSOC_FTP_USER="ocuser"
191
ORSOC_FTP_PASSWD="oc"
192
ORSOC_FTP_DIR="toolchain"
193
 
194
## GNU FTP download settings ##
195
GNU_FTP_HOST="ftp.gnu.org"
196
GNU_FTP_USER="anonymous"
197
#GNU_FTP_BINUTILS_DIR="gnu/binutils"
198
GNU_FTP_GCC_DIR="gnu/gcc/gcc-4.2.2"
199
GNU_FTP_GDB_DIR="gnu/gdb"
200
 
201
## Linux kernel download settings ##
202
KERNEL_FTP_HOST="ftp.kernel.org"
203
KERNEL_FTP_USER="anonymous"
204
KERNEL_FTP_PASSWD="anonymous"
205
KERNEL_FTP_DIR="pub/linux/kernel/v2.6"
206
 
207
## Local directory variables ##
208
START_DIR=`pwd`
209
DN="n"
210
DIR=`pwd`
211
 
212 72 julius
## Makedir command we'll use ##
213
MKDIR=mkdir -p
214 22 ocadmin
## Versions of the toolchain components ##
215
BINUTILS_VER=binutils-2.18.50
216 37 julius
GCC_VER_NUM=4.2.2
217
GCC_VER=gcc-$GCC_VER_NUM
218 22 ocadmin
GDB_VER=gdb-6.8
219
UCLIB_VER=uClibc-0.9.29
220
LINUX_VER=linux-2.6.24
221
BUSY_VER=busybox-1.7.5
222
SIM_VER=or1ksim-0.3.0
223
 
224
## Patches ##
225
BINUTILS_PATCH="$BINUTILS_VER.or32_fixed_patch-v2.1.bz2"
226 59 julius
GCC_PATCH=$GCC_VER-or32-fp.patch.bz2
227 43 julius
LINUX_PATCH="linux_2.6.24_or32_unified_v2.3.bz2"
228 22 ocadmin
UCLIBC_PATCH="uClibc-0.9.29-or32-patch-1.1.bz2"
229
GDB_PATCH="or32-gdb-6.8-patch-2.4.bz2"
230
 
231
## MD5sum file ##
232
MD5SUM_FILE=md5sums
233
 
234
## Configs ##
235
#CONFIG1="rgd_uc_29dotconfig" ## Now changed to rgd_uc_29v5dotconfig as it uses paths to the 2.6.24 kernel ##
236
CONFIG1="rgd_uc_29v5dotconfig"
237
CONFIG2="rgd_bb_1.75dotconfig"
238
 
239
## Ramdisk name ##
240
RAMDISK_FILE=initrd-fb-03.ext2.last.work.1.7.5
241
LINUX_RAMDISK_FILE=arch/or32/support/initrd-fb-03.ext2 ## The location and name of the ramdisk that Linux wants when it compiles
242
 
243
## Toolchain prefix ##
244
TARGET=or32-elf
245
 
246
 
247
## Tarballs ##
248
ZBALL1=$BINUTILS_VER.tar.bz2
249
TBALL1=$BINUTILS_VER.tar
250 37 julius
ZBALL2=gcc-core-$GCC_VER_NUM.tar.bz2
251 22 ocadmin
TBALL2=$GCC_VER.tar
252
ZBALL3=$UCLIB_VER.tar.bz2
253
TBALL3=$UCLIB_VER.tar
254
ZBALL4=$LINUX_VER.tar.bz2
255
TBALL4=$LINUX_VER.tar
256
ZBALL5=$BUSY_VER.tar.bz2
257
TBALL5=$BUSY_VER.tar
258
ZBALL6=$SIM_VER.tar.bz2
259
TBALL6=$SIM_VER.tar
260
ZBALL7=$RAMDISK_FILE.bz2
261
ZBALL8=$GDB_VER.tar.bz2
262
TBALL8=$GDB_VER.tar
263
 
264
ORSOC_FTP_FILE_LIST="$ZBALL1
265
        $ZBALL3
266
        $ZBALL5
267
        $ZBALL6
268
        $ZBALL7
269
        $BINUTILS_PATCH
270
        $GCC_PATCH
271
        $LINUX_PATCH
272
        $UCLIBC_PATCH
273
        $GDB_PATCH
274
        $CONFIG1
275
        $CONFIG2"
276
 
277
GNU_FTP_FILE_LIST="$ZBALL2
278
$ZBALL8"
279
 
280
KERNEL_FTP_FILE_LIST=$ZBALL4
281
 
282
 
283
 
284
## Check if we've been given the debug mode flag ##
285
## We won't clear away all the directories if run with the -d or -D options ##
286
DBG_BUILD=0
287
while getopts d OPT; do
288
    case "$OPT" in
289
        d)
290
        DBG_BUILD=1
291
        ;;
292
    esac
293
done
294
 
295
##Welcome message
296
echo
297
echo "The OpenRISC toolchain install script - Provided by ORSoC & MeansOfFreedom.net"
298
echo "Version $SCRIPT_VERSION"
299
echo
300
echo "#####################################README#####################################"
301
echo
302
echo "This script will install tools required for development on the OpenRISC platform"
303
echo "This version ($SCRIPT_VERSION) includes: "
304
echo "        $GCC_VER, $BINUTILS_VER, $UCLIB_VER"
305
echo "        $LINUX_VER, $GDB_VER, $BUSY_VER and $SIM_VER"
306
echo
307
echo "Please follow the prompts to select the install location."
308
echo
309
echo "Note: Two new directories, or32-build and or32-download, will be created in the"
310
echo "current directory for storing downloaded files and building the tools."
311
echo "Also: This script attempts to mount a ramdisk image in a local directory to copy"
312
echo "in the freshly built busybox. This requires root user privileges - if they are"
313
echo "not deteceted the existing busybox binaries will remain in the ramdisk image."
314
echo
315
echo "#####################################README#####################################"
316
echo
317
 
318
echo "Install the toolchain under current directory?"
319
echo "Current directory: [$DIR]"
320
echo "Tools will be installed in [$DIR/$TARGET]"
321
echo [Y/n]:
322
read YN
323
 
324 72 julius
 
325 22 ocadmin
## $YN will be zero length string if user just pressed enter ##
326
if [ -z $YN ]
327
    then
328
    VAL="y"
329
else
330
    VAL=$(echo $YN | tr [:upper:] [:lower:])
331
fi
332
 
333
if [ $VAL = "n" ]
334
    then
335
    # Optional install path
336
    echo "Enter the path the toolchain will be installed in:"
337
    read DIR
338
 
339
    # Check if the path exists and ask the user to verify it
340
    until [ $DN = "y" ]
341
      do
342
 
343
        #Check the path exists
344
        if [ -d $DIR ]
345
            then
346
            # The path entered is OK
347
            echo "Chosen directory is [$DIR]"
348 72 julius
            echo "Tools will be installed in [$DIR/$TARGET], or1ksim in [$DIR/or1ksim]"
349 22 ocadmin
            echo "[y/n]:"
350
            read DN
351
 
352
            if [ -z $DN ]
353
                then
354
                # Presume yes here
355
                DN="y"
356
            fi
357
 
358
            VAL=$(echo $DN | tr [:upper:] [:lower:])
359
        else
360
            echo
361
            #echo "Path does not exist. Please create it and ensure user has correct permissions."
362
            echo "Path does not exist. Create $DIR now?"
363
            echo "[y/N]:"
364
            read MKPATH
365
            if [ -z $MKPATH ]
366
                then
367
                ## $MKPATH was zero, so user probably just pressed enter without entering anything, which we'll interpret as "n" ##
368
                MKPATHYN="n"
369
            else
370
                MKPATHYN=$(echo $MKPATH | tr [:upper:] [:lower:])
371
            fi
372
 
373
            if [ $MKPATHYN = "y" ]
374
                then
375 72 julius
                `mkdir -p $DIR`
376 22 ocadmin
 
377
                # Check we made it successfully
378
                if [ $? -ne 0 ]
379
                    then
380
                    DN="n"
381
                else
382
                    DN="x" # Set this so we do go back through and ask the user to verify
383
                fi
384
 
385
            else
386
                DN="n"
387
            fi
388
        fi
389
 
390
        if [ $DN = "n" ]
391
            then
392
            echo "Enter the path the toolchain should be installed in:"
393
            read DIR
394
        fi
395
 
396
    done
397
    cd $DIR
398
#    echo "loop done"
399
#    echo "Working in " `pwd`
400
fi
401
 
402
## Now check that the required tools to build the toolchain are installed
403
check_essential_build_tools
404
 
405
BUILD_TOP=$START_DIR/or32-build
406
export BUILD_TOP
407
 
408
## Set donload directory to be under the current directory ##
409
DOWNLOAD_DIR=$START_DIR/or32-download
410
 
411
## Setup the target tool installation directory ##
412
INSTALL_DIR=$DIR
413
 
414 72 julius
$MKDIR $INSTALL_DIR
415 22 ocadmin
 
416
####################################################################################################
417
## Now check which sources have already been downloaded, if any ##
418 39 julius
DO_DOWNLOADS="y" ## Default is to NOT do downloads
419 22 ocadmin
 
420
if [ $DBG_BUILD -eq 1 ]
421
    then
422
    ## Ask if we should do downloads ##
423
    echo "Do downloads?"
424
    echo "[y/N]:"
425
    read DO_DOWNLOADS
426
    ## $YN will be zero length string if user just pressed enter ##
427
    if [ -z $DO_DOWNLOADS ]
428
        then
429
        DO_DOWNLOADS="n"
430
    else
431 39 julius
        DO_DOWNLOADS=$(echo $DO_DOWNLOADS | tr [:upper:] [:lower:])
432 22 ocadmin
    fi
433
 
434
fi
435
 
436
if [ $DO_DOWNLOADS = "y" ]
437
then
438
## Check if download directory exists, if not create it ##
439 39 julius
    if [ ! -d $DOWNLOAD_DIR ]; then
440 72 julius
        $MKDIR $DOWNLOAD_DIR
441 22 ocadmin
    fi
442
 
443 39 julius
    cd $DOWNLOAD_DIR
444
 
445 22 ocadmin
## We'll need the md5sum file ##
446
## This is a file stored on the ORSoC FTP server, containing checksums of all the files we need ##
447
    rm -f $MD5SUM_FILE
448
    wget ftp://$ORSOC_FTP_USER:$ORSOC_FTP_PASSWD@$ORSOC_FTP_HOST/$ORSOC_FTP_DIR/$MD5SUM_FILE
449
## Make sure we got that OK ##
450
    check_exit_code
451
 
452
## We have lists of what to get from each FTP let's create a loop for each ##
453
 
454
## ORSoC FTP server downloads ##
455
    for CURRENT_FILE in $ORSOC_FTP_FILE_LIST
456
      do
457
  # Check if we've already got the file
458
      if [ -e $CURRENT_FILE ]
459
          then
460
          echo "File $CURRENT_FILE exists locally."
461
          echo "Verifying MD5 checksum:"
462
      ## Verify it's right by checking the MD5 checksum ##
463
      ## First we get the line for $CURRENT_FILE out of the $MD5SUM_FILE, then feed it to "md5sum -c"
464
      ## which checks it and sets the return code, $? to 0 if OK, 1 if problem ##
465
          cat $MD5SUM_FILE | grep $CURRENT_FILE | md5sum -c
466
          if [ $? -ne 0 ]
467
              then
468
          #MD5sum of $CURRENT_FILE differs from expected value - we'll download it again
469
              echo "MD5 checksum of $CURRENT_FILE differs from expected value. Re-downloading."
470
              rm -f $CURRENT_FILE
471
              wget ftp://$ORSOC_FTP_USER:$ORSOC_FTP_PASSWD@$ORSOC_FTP_HOST/$ORSOC_FTP_DIR/$CURRENT_FILE
472
              check_exit_code
473
          fi
474
      else
475
      # File doesn't exist locally - we'll download it
476
          echo "Downloading $CURRENT_FILE"
477
          wget ftp://$ORSOC_FTP_USER:$ORSOC_FTP_PASSWD@$ORSOC_FTP_HOST/$ORSOC_FTP_DIR/$CURRENT_FILE
478
          check_exit_code
479
      fi
480
      echo
481
    done
482
 
483
## GNU FTP server downloads ##
484
    for CURRENT_FILE in $GNU_FTP_FILE_LIST
485
      do
486
  ## Check if we've already got the file ##
487
      if [ -e $CURRENT_FILE ]
488
          then
489
          echo "File $CURRENT_FILE exists locally."
490
          echo "Verifying MD5 checksum:"
491
      ## Verify it's right by checking the MD5 checksum ##
492
      ## First we get the line for $CURRENT_FILE out of the $MD5SUM_FILE, then feed it to "md5sum -c"
493
      ## which checks it and sets the return code, $? to 0 if OK, 1 if problem ##
494
          cat $MD5SUM_FILE | grep $CURRENT_FILE | md5sum -c
495
          if [ $? -ne 0 ]
496
              then
497
          ## MD5sum of present one is incorrect - we'll download it again ##
498
              echo "MD5 checksum of $CURRENT_FILE differs from expected value. Re-downloading."
499
              rm -f $CURRENT_FILE
500
          ## Depending on the file, we need a specific path ##
501
          ## gcc's path on ftp ##
502
              if [ $CURRENT_FILE = $ZBALL2 ]; then
503
                  GNU_FTP_DIR=$GNU_FTP_GCC_DIR
504
              fi
505
          ## gdb's path on ftp ##
506
              if [ $CURRENT_FILE = $ZBALL8 ]; then
507
                  GNU_FTP_DIR=$GNU_FTP_GDB_DIR
508
              fi
509
              wget ftp://$GNU_FTP_USER:$GNU_FTP_USER@$GNU_FTP_HOST/$GNU_FTP_DIR/$CURRENT_FILE
510
              check_exit_code
511
          fi
512
      else
513
      # File doesn't exist - we'll download it
514
          echo "Downloading $CURRENT_FILE"
515
      ## Depending on the file, we need a specific path ##
516
      ## gcc's path on ftp ##
517
          if [ $CURRENT_FILE = $ZBALL2 ]; then
518
              GNU_FTP_DIR=$GNU_FTP_GCC_DIR
519
          fi
520
      ## gdb's path on ftp ##
521
          if [ $CURRENT_FILE = $ZBALL8 ]; then
522
              GNU_FTP_DIR=$GNU_FTP_GDB_DIR
523
          fi
524
          wget ftp://$GNU_FTP_USER:$GNU_FTP_USER@$GNU_FTP_HOST/$GNU_FTP_DIR/$CURRENT_FILE
525
          check_exit_code
526
      fi
527
      echo
528
    done
529
 
530
## Kernel.org FTP server downloads ##
531
    CURRENT_FILE=$KERNEL_FTP_FILE_LIST
532
## Usually just a single file from the kernel.org ftp site ##
533
    if [ -e $CURRENT_FILE ]
534
    then
535
        echo "File $CURRENT_FILE exists locally."
536
        echo "Verifying MD5 checksum:"
537
    ## Verify it's right by checking the MD5 checksum ##
538
    ## First we get the line for $CURRENT_FILE out of the $MD5SUM_FILE, then feed it to "md5sum -c"
539
    ## which checks it and sets the return code, $? to 0 if OK, 1 if problem ##
540
        cat $MD5SUM_FILE | grep $CURRENT_FILE | md5sum -c
541
        if [ $? -ne 0 ]
542
            then
543
        #MD5sum of present one is incorrect - we'll download it again
544
            echo "MD5 checksum of $CURRENT_FILE differs from expected value. Re-downloading."
545
            rm -f $CURRENT_FILE
546
            wget ftp://$KERNEL_FTP_USER:$KERNEL_FTP_USER@$KERNEL_FTP_HOST/$KERNEL_FTP_DIR/$CURRENT_FILE
547
            check_exit_code
548
        fi
549
    else
550
    ## Download it ##
551
        echo "Downloading $CURRENT_FILE"
552
        wget ftp://$KERNEL_FTP_USER:$KERNEL_FTP_PASSWD@$KERNEL_FTP_HOST/$KERNEL_FTP_DIR/$CURRENT_FILE
553
    check_exit_code
554
    fi
555
 
556
echo
557
fi # if [ $DO_DOWNLOADS = "y" ]
558
 
559
####################################################################################################
560
 
561
## Cygwin exports ##
562
ON_CYGWIN=`set | grep -i mach|grep -i -c cygwin`
563
if [ $ON_CYGWIN -ge 1 ]
564
    then
565
    echo
566 39 julius
    echo "Cygwin host detected"
567
    echo "Platform specific exports:"
568 22 ocadmin
    echo  "export HOST_LOADLIBES=\"-lcurses -lintl\" "
569
    echo
570 39 julius
    export ON_CYGWIN=1
571 22 ocadmin
    export HOST_LOADLIBES="-lcurses -lintl"
572
fi
573
 
574
####################################################################################################
575
 
576
cd $START_DIR
577
 
578
## if not debug building, let's remove all the old stuff ##
579
 
580
if [ $DBG_BUILD -eq 0 ]
581
    then
582
## Always start with a clean build dir ##
583
    rm -fr $BUILD_TOP
584 72 julius
    $MKDIR $BUILD_TOP
585 22 ocadmin
    chmod 777 $BUILD_TOP
586
 
587 72 julius
    $MKDIR $BUILD_TOP/b-gcc
588
    $MKDIR $BUILD_TOP/b-b
589 22 ocadmin
fi
590
 
591
## default build option is yes ##
592
BUILD_THIS="y"
593
 
594
if [ $DBG_BUILD -eq 1 ]
595
    then
596
    ## Ask if we should build binutils ##
597
    echo "Re-build $BINUTILS_VER ?"
598
    echo "[y/N]:"
599
    read YN
600
    ## $YN will be zero length string if user just pressed enter ##
601
    if [ -z $YN ]
602
        then
603
        BUILD_THIS="n"
604
    else
605
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
606
    fi
607
 
608
    if [ $BUILD_THIS = "y" ]
609
        then
610
        ## Delete and recreate the binutils directory ##
611
        rm -rf $BUILD_TOP/b-b
612
        rm -rf $BUILD_TOP/$BINUTILS_VER
613 72 julius
        $MKDIR $BUILD_TOP/b-b
614 22 ocadmin
 
615
    fi
616
fi
617
 
618
##########################Building Binutils#######################
619
if [ $BUILD_THIS = "y" ]
620
    then
621
 
622
    echo "############################## Building binutils ###############################"
623
    echo
624
    echo "Decompressing source"
625
    cd $BUILD_TOP
626
 
627
## Extract sources ##
628
    tar xjf $DOWNLOAD_DIR/$ZBALL1
629
 
630
    echo
631
    echo "Patching binutils with $BINUTILS_PATCH"
632
 
633
    cd $BINUTILS_VER
634
 
635
    bzip2 -dc $DOWNLOAD_DIR/$BINUTILS_PATCH | patch -p1 > $BINUTILS_VER-patch.log 2>&1
636
 
637
## Make sure that patched ok ##
638
    check_exit_code
639
 
640
    cd ..
641
    cd $BUILD_TOP/b-b
642
 
643
    echo
644
    echo "Configuring $BINUTILS_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-checking"
645
    echo "Logging output to $BINUTILS_VER-configure.log"
646
    $BUILD_TOP/$BINUTILS_VER/configure --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-checking > $BINUTILS_VER-configure.log 2>&1
647
 
648
    echo
649
    echo "Making and installing $BINUTILS_VER"
650
    echo "Logging output to $BINUTILS_VER-make.log "
651
    make all install > $BINUTILS_VER-make.log 2>&1
652
 
653
## Make sure that built ok ##
654
    check_exit_code
655
 
656
    cd $BUILD_TOP
657
 
658
fi
659
#######################Finish Building Binutils#####################
660
 
661
## Export the path to the new or32 binaries directory, used by the rest of this script ##
662
echo
663
echo "Adding $INSTALL_DIR/$TARGET/bin to the PATH variable"
664
export PATH=$INSTALL_DIR/$TARGET/bin:$PATH
665
 
666
## default build option is yes ##
667
BUILD_THIS="y"
668
 
669
if [ $DBG_BUILD -eq 1 ]
670
    then
671
    ## Ask if we should do the initial builds of GCC and Linux ##
672
    echo "Re-do initial $GCC_VER and $LINUX_VER builds (note if you choose to do this then it's EXTREMELY likely that you will have to do the rest of the script, particularly the re-build of gcc that occurs later)?"
673
    echo "[y/N]:"
674
    read YN
675
    ## $YN will be zero length string if user just pressed enter ##
676
    if [ -z $YN ]
677
        then
678
        BUILD_THIS="n" # default is no
679
    else
680
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
681
    fi
682
 
683
    if [ $BUILD_THIS = "y" ]
684
        then
685
        ## Delete and recreate the gcc directory ##
686
        rm -rf $BUILD_TOP/b-gcc
687
        rm -rf $BUILD_TOP/$GCC_VER
688
        rm -rf $BUILD_TOP/$LINUX_VER
689
 
690 72 julius
        $MKDIR $BUILD_TOP/b-gcc
691 22 ocadmin
 
692
        ## Undo everything done in the next part
693
        rm -rf $INSTALL_DIR/$TARGET/include
694
        unlink $INSTALL_DIR/$TARGET/sys-include
695
 
696
    fi
697
fi
698
 
699
##########################Building GCC and Linux############################
700
if [ $BUILD_THIS = "y" ]
701
    then
702
 
703
    echo
704
    echo "####################### Building or32 gcc and Linux ############################"
705
    echo
706
    echo "Decompressing source"
707
 
708
    cd $BUILD_TOP
709
 
710
## Extract sources ##
711
    tar xjf $DOWNLOAD_DIR/$ZBALL2 ## gcc sources ##
712
 
713
    tar xjf $DOWNLOAD_DIR/$ZBALL4 ## Linux kernel sources ##
714
 
715
    echo
716
    echo "Patching $LINUX_VER with patch file $LINUX_PATCH"
717
 
718
    cd $LINUX_VER
719
 
720
## Apply patch to linux kernel sources ##
721
    bzip2 -dc $DOWNLOAD_DIR/$LINUX_PATCH | patch -p1 > $LINUX_VER-patch.log 2>&1
722
 
723
## Make sure that patched ok ##
724
    check_exit_code
725 39 julius
## Copy our preconfigured configuration file into place ##
726 22 ocadmin
    cp rgd_dot_config .config
727
 
728
    echo
729
    echo "Making Linux oldconfig"
730
 
731
    make oldconfig > $LINUX_VER-make-oldconfig.log 2>&1
732
 
733
## Make sure that built ok ##
734
    check_exit_code
735
 
736
    cd $BUILD_TOP
737
 
738 72 julius
    $MKDIR $INSTALL_DIR/$TARGET/include
739
    $MKDIR $INSTALL_DIR/$TARGET/include/asm
740
    $MKDIR $INSTALL_DIR/$TARGET/include/linux
741 22 ocadmin
 
742
    cp -f -dR $LINUX_VER/include/linux/* $INSTALL_DIR/$TARGET/include/linux
743
    cp -f -dR $LINUX_VER/include/asm-or32/* $INSTALL_DIR/$TARGET/include/asm
744
 
745
    cd $INSTALL_DIR/$TARGET
746
    ln -s include sys-include
747
    cd $BUILD_TOP
748
 
749
    cd $GCC_VER
750
 
751
## Patch gcc ##
752
    echo
753
    echo "Patching $GCC_VER with $GCC_PATCH"
754
 
755
    bzip2 -dc $DOWNLOAD_DIR/$GCC_PATCH | patch -p1 > $GCC_VER-patch.log 2>&1
756
 
757
## Make sure that patched ok ##
758
    check_exit_code
759
 
760
    cd $BUILD_TOP
761
    cd b-gcc
762
 
763
    # configure GCC
764
    echo
765
    echo "Configuring $GCC_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --with-local-prefix=$INSTALL_DIR/$TARGET/$TARGET --with-gnu-as --with-gnu-ld --disable-libssp --enable-languages=c"
766
    echo "Logging output to $GCC_VER-configure.log"
767
    $BUILD_TOP/$GCC_VER/configure --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --with-local-prefix=$INSTALL_DIR/$TARGET/$TARGET --with-gnu-as --with-gnu-ld --disable-libssp --enable-languages=c > $GCC_VER-configure.log 2>&1
768
 
769
    echo
770
    echo "Making and installing $GCC_VER"
771
    echo "Logging output to $GCC_VER-make.log"
772
    make all install > $GCC_VER-make.log 2>&1
773
 
774
## Make sure that built ok ##
775
    check_exit_code
776
 
777
    cd $BUILD_TOP
778
 
779
    echo
780
    echo "Making vmlinux image"
781
    echo "Logging output to vmlinux-make.log"
782
 
783
    cd $LINUX_VER
784
    make vmlinux ARCH=or32 CROSS_COMPILE=$INSTALL_DIR/$TARGET/bin/$TARGET- > vmlinux-make.log 2>&1
785
 
786
## Make sure that built ok ##
787
    check_exit_code
788
fi
789
##########################Finish Building GCC and Linux############################
790
 
791
 
792
## default build option is yes ##
793
BUILD_THIS="y"
794
 
795
if [ $DBG_BUILD -eq 1 ]
796
    then
797
    ## Ask if we should rebuild uClibc ##
798
    echo "Re-build $UCLIB_VER ?"
799
    echo "[y/N]:"
800
    read YN
801
    ## $YN will be zero length string if user just pressed enter ##
802
    if [ -z $YN ]
803
        then
804
        BUILD_THIS="n" # default is no
805
    else
806
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
807
    fi
808
 
809
    if [ $BUILD_THIS = "y" ]
810
        then
811
        ## Delete the uClibc directory ##
812
        rm -rf $BUILD_TOP/$UCLIB_VER
813
    fi
814
fi
815
 
816
##########################Building uClibc#########################
817
if [ $BUILD_THIS = "y" ]
818
    then
819
 
820
    echo
821
    echo "############################## Building uClibc #################################"
822
    echo
823
    echo "Decompressing source"
824
 
825
    cd $BUILD_TOP
826
    tar xjf $DOWNLOAD_DIR/$ZBALL3 ## uClibc sources ##
827
 
828
    echo
829
    echo "Patching $UCLIB_VER with $UCLIBC_PATCH"
830
 
831
    cd $UCLIB_VER
832
 
833
## Patch uClibc sources ##
834
    bzip2 -dc $DOWNLOAD_DIR/$UCLIBC_PATCH  | patch -p1 > $UCLIB_VER-patch.log 2>&1
835
 
836
## Make sure that patched ok ##
837
    check_exit_code
838
 
839
    export CC=$TARGET-gcc
840
    export BUILD_TOP
841
    #cp $DOWNLOAD_DIR/$CONFIG1  $BUILD_TOP/$UCLIB_VER/.config
842
    #cp $DOWNLOAD_DIR/$CONFIG1  $BUILD_TOP/$UCLIB_VER/.config.old
843
 
844
    ## $TARGET name implementation into config script ##
845
    ## First get the second part of the target name, after the "-", the "elf" in "or32-elf", for example ##
846
    TARGET_SECOND_PART=`echo $TARGET | cut -f 2 -d "-"`
847
    ## First change any references to the uclinux target ##
848
    ## And delete the line saying DEVEL_PREFIX so we can put our $INSTALL_DIR path in ##
849
    sed "s/or32\-uclinux/\or32\-$TARGET_SECOND_PART/" $DOWNLOAD_DIR/$CONFIG1 | sed "/DEVEL\_PREFIX\=/d"  > $BUILD_TOP/$UCLIB_VER/.config  ## Output to the .config ##
850
    ## Now output the new DEVEL_PATH= value ##
851
    echo "DEVEL_PREFIX=\"$INSTALL_DIR/$TARGET\"" >> $BUILD_TOP/$UCLIB_VER/.config
852
    ## copy it to .config.old ##
853
    cp $BUILD_TOP/$UCLIB_VER/.config $BUILD_TOP/$UCLIB_VER/.config.old
854
    ## Do the configuration ##
855
 
856
## Change the cross compiler name in the Config.or32 file
857
## First get the second part of the target name, after the "-" ##
858
    TARGET_SECOND_PART=`echo $TARGET | cut -f 2 -d "-"`
859
## Removes the uclinux line and changes to whatever our current target is ##
860
    sed "s/or32\-uclinux/\or32\-$TARGET_SECOND_PART/" $BUILD_TOP/$UCLIB_VER/extra/Configs/Config.or32  > $BUILD_TOP/$UCLIB_VER/extra/Configs/Config.or32.newtarget
861
    mv $BUILD_TOP/$UCLIB_VER/extra/Configs/Config.or32.newtarget $BUILD_TOP/$UCLIB_VER/extra/Configs/Config.or32
862
 
863 39 julius
if [ $ON_CYGWIN -ge 1 ]
864
    then
865
## If on Cygwin, fix strange error where 'install' command by the makefile ##
866
## results in it trying to execute the INSTALL text file in the root of the ##
867
## package ##
868
    mv INSTALL INSTALL.txt
869
fi
870
 
871 22 ocadmin
    echo
872
    echo "Making uClibc oldconfig"
873
 
874
    HOST_LOADLIBES="-lcurses -lintl" HOSTCC=`which gcc` make oldconfig > $UCLIB_VER-make-oldconfig.log 2>&1
875
 
876
## Make sure that built ok ##
877
    check_exit_code
878
 
879
    ln -s extra/Configs/Config.or32 Config
880
 
881
    echo
882
    echo "Making and install $UCLIB_VER"
883
    echo "Logging output to $UCLIB_VER-make.log"
884
    make all install > $UCLIB_VER-make.log 2>&1
885
 
886
## Make sure that built ok ##
887
    check_exit_code
888
 
889
    unset CC
890
fi
891
##########################Finish Building uClibc#########################
892
 
893
 
894
## default build option is yes ##
895
BUILD_THIS="y"
896
 
897
if [ $DBG_BUILD -eq 1 ]
898
    then
899
    ## Ask if we should rebuild gcc ##
900
    echo "Perform $GCC_VER re-build? - YES (y) if you rebuilt GCC and Linux previously, otherwise definitely NO (n)."
901
    echo "[y/N]:"
902
    read YN
903
    ## $YN will be zero length string if user just pressed enter ##
904
    if [ -z $YN ]
905
        then
906
        BUILD_THIS="n" # default is no
907
    else
908
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
909
    fi
910
 
911
    if [ $BUILD_THIS = "y" ]
912
        then
913
        ## Undo some things we did before after doing this compile ##
914
        unlink $INSTALL_DIR/$TARGET/$TARGET/sys-include
915
        rm -rf $INSTALL_DIR/$TARGET/$TARGET/lib/*
916
    fi
917
fi
918
 
919
 
920
##########################re-Building GCC########################
921
if [ $BUILD_THIS = "y" ]
922
    then
923
 
924
    echo
925
    echo "############################## Re-building or-32 gcc ###########################"
926
    echo
927
    echo "Re-building $GCC_VER"
928
 
929
    cd $BUILD_TOP
930
 
931
    cd b-gcc
932
 
933
    echo
934
    echo "Re-configuring $GCC_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --with-local-prefix=$INSTALL_DIR/$TARGET/$TARGET --with-gnu-as --with-gnu-ld --disable-libssp --enable-languages=c"
935
    echo "Logging output to $GCC_VER-rebuild-configure.log"
936
 
937
    $BUILD_TOP/$GCC_VER/configure --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --with-local-prefix=$INSTALL_DIR/$TARGET/$TARGET --with-gnu-as --with-gnu-ld --disable-libssp --enable-languages=c > $GCC_VER-rebuild-configure.log 2>&1
938
 
939
 
940
 
941
    echo
942
    echo "Re-building and re-installing $GCC_VER"
943
    echo "Logging output to $GCC_VER-rebuild-make.log"
944
    make all install > $GCC_VER-rebuild-make.log 2>&1
945
 
946
## Make sure that built ok ##
947
    check_exit_code
948
 
949
    cd $INSTALL_DIR/$TARGET/$TARGET
950
    ln -s ../include sys-include
951
    cd lib
952
    cp -f -dR ../../lib/* .
953
    cd $BUILD_TOP
954
 
955
fi
956
 
957
##########################finish re-Building GCC########################
958
 
959
 
960
## default build option is yes ##
961
BUILD_THIS="y"
962
 
963
if [ $DBG_BUILD -eq 1 ]
964
    then
965
    ## Ask if we should rebuild gdb ##
966
    echo "Rebuild $GDB_VER?"
967
    echo "[y/N]:"
968
    read YN
969
    ## $YN will be zero length string if user just pressed enter ##
970
    if [ -z $YN ]
971
        then
972
        BUILD_THIS="n" # default is no
973
    else
974
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
975
    fi
976
 
977
    if [ $BUILD_THIS = "y" ]
978
        then
979
        ## Delete existing gdb dir ##
980
        rm -rf $BUILD_TOP/$GDB_VER
981
    fi
982
fi
983
 
984
 
985
########################## GDB build ################
986
if [ $BUILD_THIS = "y" ]
987
    then
988
 
989
    echo
990
    echo "############################## Building GDB ####################################"
991
    echo
992
    echo "Decompressing source"
993
 
994
 
995
    cd $BUILD_TOP
996
 
997
    tar xjf $DOWNLOAD_DIR/$ZBALL8
998
 
999
    echo
1000
    echo "Patching $GDB_VER with $GDB_PATCH"
1001 59 julius
    echo "Logging output to $GDB_VER-patch.log"
1002 22 ocadmin
    cd $GDB_VER
1003
 
1004
    bzcat -dc $DOWNLOAD_DIR/$GDB_PATCH | patch -p1 > $GDB_VER-patch.log 2>&1
1005
 
1006
## Make sure that patched ok ##
1007
    check_exit_code
1008
 
1009
    echo
1010 59 julius
    echo "Configuring $GDB_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-werror"
1011
    echo "Logging output to $GDB_VER-configure.log"
1012 22 ocadmin
 
1013 59 julius
    ./configure --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-werror > $GDB_VER-configure.log 2>&1
1014 22 ocadmin
 
1015
    echo
1016
    echo "Making and installing $GDB_VER"
1017 59 julius
    echo "Logging output to $GDB_VER-make.log"
1018 22 ocadmin
    make all install > $GDB_VER-make.log 2>&1
1019
 
1020
## Make sure that built ok ##
1021
    check_exit_code
1022
 
1023
    cd $BUILD_TOP
1024
 
1025
fi
1026
########################## finish GDB build ################
1027
 
1028
## default build option is yes ##
1029
BUILD_THIS="y"
1030
 
1031
if [ $DBG_BUILD -eq 1 ]
1032
    then
1033
    ## Ask if we should rebuild busybox ##
1034
    echo "Rebuild $BUSY_VER?"
1035
    echo "[y/N]:"
1036
    read YN
1037
    ## $YN will be zero length string if user just pressed enter ##
1038
    if [ -z $YN ]
1039
        then
1040
        BUILD_THIS="n" # default is no
1041
    else
1042
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
1043
    fi
1044
 
1045
    if [ $BUILD_THIS = "y" ]
1046
        then
1047
        ## Delete existing busybox stuff ##
1048
        rm -rf $BUILD_TOP/$BUSY_VER
1049
    fi
1050
fi
1051
 
1052
##########################Building Busybox########################
1053
if [ $BUILD_THIS = "y" ]
1054
    then
1055
 
1056
    echo
1057
    echo "############################## Building BusyBox ################################"
1058
    echo
1059
    echo "Decompressing source"
1060
 
1061
 
1062
    cd $BUILD_TOP
1063
 
1064
    tar xjf $DOWNLOAD_DIR/$ZBALL5
1065
 
1066
 
1067
    cd $BUSY_VER
1068
    cp $DOWNLOAD_DIR/$CONFIG2  $BUILD_TOP/$BUSY_VER/.config
1069
    cp $DOWNLOAD_DIR/$CONFIG2  $BUILD_TOP/$BUSY_VER/.config.old
1070
 
1071
    echo
1072
    echo "Making $BUSY_VER oldconfig"
1073
    make oldconfig > $BUSY_VER-make-oldconfig.log 2>&1
1074
 
1075
## Make Sure that built ok ##
1076
    check_exit_code
1077
 
1078
## Put the Linux headers in BusyBox's include dir ##
1079
 
1080
    ln -s $BUILD_TOP/$LINUX_VER/include/linux $BUILD_TOP/$BUSY_VER/include/.
1081
    ln -s $BUILD_TOP/$LINUX_VER/include/asm $BUILD_TOP/$BUSY_VER/include/.
1082
 
1083
    echo
1084
    echo "Making $BUSY_VER"
1085
    echo "Logging output to $BUSY_VER-make.log"
1086
    make ARCH=or32 CROSS_COMPILE=$INSTALL_DIR/$TARGET/bin/$TARGET- > $BUSY_VER-make.log 2>&1
1087
 
1088
## Make sure that built ok ##
1089
    check_exit_code
1090
 
1091
    echo
1092
    echo "Installing $BUSY_VER"
1093
    echo "Logging output to $BUSY_VER-install.log"
1094
    make install ARCH=or32 CROSS_COMPILE=$INSTALL_DIR/$TARGET/bin/$TARGET- > $BUSY_VER-install.log 2>&1
1095
 
1096
## Make sure that built ok ##
1097
    check_exit_code
1098
 
1099
    cd $BUILD_TOP
1100
 
1101
## Copy and extract the ramdisk image file
1102
 
1103
    cp $DOWNLOAD_DIR/$ZBALL7 . ## Ramdisk file ##
1104
 
1105
    bunzip2 $RAMDISK_FILE.bz2
1106
 
1107
## We can only play with the ext2 image if we're not on Cygwin ##
1108
    if [ -z $ON_CYGWIN ]
1109
        then
1110
 
1111
        RT=`whoami`
1112
        if [ $RT = "root" ];then
1113 72 julius
            $MKDIR rd_mount
1114 22 ocadmin
            chmod 777 rd_mount
1115
            mount -t ext2 -o loop $RAMDISK_FILE rd_mount
1116
            cp -f -dR $BUILD_TOP/busy_out.1.7.5/* $BUILD_TOP/rd_mount
1117
            umount rd_mount
1118
            cp -f $RAMDISK_FILE $LINUX_VER/$LINUX_RAMDISK_FILE
1119
        else
1120
            echo
1121
            echo "User is not root. Unable to mount Linux ramdisk."
1122
            echo "Note that this program built BusyBox but did not"
1123
            echo "install it on the ramdisk. Defaults are used."
1124
            cp -f $RAMDISK_FILE $LINUX_VER/$LINUX_RAMDISK_FILE
1125
        fi
1126
 
1127
    fi ## if [ -z $ON_CYGWIN ]
1128
 
1129
    cd $BUILD_TOP
1130
fi
1131
 
1132
########################## Finish BusyBox build ################
1133
 
1134
## default build option is yes ##
1135
BUILD_THIS="y"
1136
 
1137
if [ $DBG_BUILD -eq 1 ]
1138
    then
1139
    ## Ask if we should rebuild linux again##
1140
    echo "Rebuild the $LINUX_VER rebuild (only ever yes (y) if performed previous linux rebuild)?"
1141
    echo "[y/N]:"
1142
    read YN
1143
    ## $YN will be zero length string if user just pressed enter ##
1144
    if [ -z $YN ]
1145
        then
1146
        BUILD_THIS="n" # default is no
1147
    else
1148
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
1149
    fi
1150
 
1151
fi
1152
 
1153
#echo "Start Building Linux kernel?"
1154
#read Q
1155
##########################Final Linux kernel build################
1156
if [ $BUILD_THIS = "y" ]
1157
    then
1158
 
1159
    echo
1160
    echo "########################### Linux image generation #############################"
1161
    cd $BUILD_TOP
1162
    cd $LINUX_VER
1163
 
1164
    echo
1165
    echo "Making vmlinux"
1166
    echo "Logging output to vmlinux-remake.log"
1167
    make vmlinux ARCH=or32 CROSS_COMPILE=$INSTALL_DIR/$TARGET/bin/$TARGET- > vmlinux-remake.log 2>&1
1168
 
1169
## Make sure that built ok ##
1170
    check_exit_code
1171
 
1172
    cd $BUILD_TOP
1173
fi
1174
##########################Finished Final Linux kernel build################
1175
 
1176
BUILD_THIS="y"
1177
 
1178
if [ $DBG_BUILD -eq 1 ]
1179
    then
1180
    ## Ask if we should rebuild or1ksim##
1181
    echo "Rebuild $SIM_VER ?"
1182
    echo "[y/N]:"
1183
    read YN
1184
    ## $YN will be zero length string if user just pressed enter ##
1185
    if [ -z $YN ]
1186
        then
1187
        BUILD_THIS="n" # default is no
1188
    else
1189
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
1190
    fi
1191
 
1192
    if [ $BUILD_THIS = "y" ]
1193
        then
1194
        ## Clean previous or1ksim directories ##
1195
        rm -rf $BUILD_TOP/$SIM_VER
1196
    fi
1197
fi
1198
 
1199
 
1200
##########################Simulator build#########################
1201
if [ $BUILD_THIS = "y" ]
1202
    then
1203
 
1204
    echo
1205
    echo "############################## Building or1ksim ################################"
1206
    echo
1207
    echo "Decompressing source"
1208
 
1209
    cd $BUILD_TOP
1210
 
1211
    tar xjf $DOWNLOAD_DIR/$ZBALL6
1212
 
1213
    cd $SIM_VER
1214
 
1215
    echo
1216 72 julius
    echo "Configuring $SIM_VER: --target=$TARGET --prefix=$INSTALL_DIR/$SIM_VER"
1217 22 ocadmin
 
1218 72 julius
    ./configure --target=$TARGET --prefix=$INSTALL_DIR/$SIM_VER > $SIM_VER-configure.log 2>&1
1219 22 ocadmin
 
1220
    echo
1221
    echo "Making and installing $SIM_VER"
1222
    echo "Logging output to $SIM_VER-make.log"
1223
    make all install > $SIM_VER-make.log 2>&1
1224 72 julius
 
1225 22 ocadmin
## Make sure that built ok ##
1226
    check_exit_code
1227 72 julius
 
1228
## Setup symbolic link from or1ksim-x.y.z to simply or1ksim
1229
 
1230
    echo "Symbolically linking $INSTALL_DIR/$SIM_VER to $INSTALL_DIR/or1ksim"
1231
    if [ -e $INSTALL_DIR/or1ksim ]; then
1232
        echo "Symlink $INSTALL_DIR/or1ksim already exists. Updating to this version"
1233
        unlink $INSTALL_DIR/or1ksim;
1234
        check_exit_code
1235
    fi
1236
    echo "ln -s $INSTALL_DIR/$SIM_VER $INSTALL_DIR/or1ksim"
1237
    ln -s $INSTALL_DIR/$SIM_VER $INSTALL_DIR/or1ksim
1238
 
1239 22 ocadmin
    cd $BUILD_TOP
1240
fi
1241
##########################Finish Simulator build#########################
1242
 
1243
 
1244
##########################Code Test###############################
1245
cd $BUILD_TOP
1246
echo "Launch the simulator with the newly compiled Linux image and BusyBox apps?"
1247
echo "[y/N]:"
1248
read SI
1249
 
1250
if [ -z $SI ]
1251
    then
1252
    SVAL="n" ## Default is no ##
1253
else
1254
    SVAL=$(echo $SI | tr [:upper:] [:lower:])
1255
fi
1256
 
1257
if [ $SVAL = "y" ];then
1258
 
1259
    ## Check for X's xterm, if we find it, and a valid $DISPLAY variable, we'll open the simulator with an xterm tty ##
1260
    which xterm
1261
 
1262
 
1263
    if [ $? -eq 0 ]
1264
        then
1265
        # Xterm exists, check if the $DISPLAY variable is set
1266
        # Get the display variable
1267
        DISPLAY=`printenv DISPLAY`
1268
        echo "DISPLAY variable is set to $DISPLAY"
1269
        if [ -n $DISPLAY ]
1270
            then
1271
            ## It appears display is set, let's set the or1ksim_linux.cfg file to use an xterm instead of telnet ##
1272
            cd $LINUX_VER
1273
            ## Rename the original script, adding .orig to the end ##
1274
            mv or1ksim_linux.cfg or1ksim_linux.cfg.orig
1275
            ## Now use sed to comment the line specifiying a telnet tty and uncomment the xterm line, restoring the original script ##
1276
            sed 's/channel\ \=\ \"tcp\:10084\"/\/\*\ channel\ \=\ \"tcp\:10084\"\ \*\//' or1ksim_linux.cfg.orig | sed 's/\/\*\ channel\ \=\ \"xterm\:\"\ \*\//\ channel\ \=\ \"xterm\:\"\ /' > or1ksim_linux.cfg
1277
            echo "########################## or1ksim ###############################"
1278
            echo
1279
            echo "or1ksim will open an xterm for console output as Linux is booting."
1280
            echo
1281
            echo "########################## or1ksim ###############################"
1282
            cd $BUILD_TOP
1283
        fi
1284
 
1285
    else
1286
        echo "########################## or1ksim ###############################"
1287
        echo
1288
        echo "     To connect to the simulator run: telnet 127.0.0.1 10084"
1289
        echo
1290
        echo "########################## or1ksim ###############################"
1291
 
1292
    fi
1293
 
1294
 
1295
    cd $BUILD_TOP/$LINUX_VER
1296 72 julius
    $INSTALL_DIR/or1ksim/bin/$TARGET-sim -f or1ksim_linux.cfg vmlinux
1297 22 ocadmin
 
1298
else
1299
    ## User didn't run the sim, but tell them how to anyway ##
1300
    echo "The compiled linux image is found in $BUILD_TOP/$LINUX_VER/vmlinux"
1301
    echo "To run it in the simulator, cd to $BUILD_TOP/$LINUX_VER"
1302
    echo "and run:"
1303
    echo "$TARGET-sim -f or1ksim_linux.cfg vmlinux"
1304
    echo
1305
 
1306
fi
1307
 
1308
echo
1309
echo "OpenRISC toolchain and architectural simulator build is complete!"
1310
echo
1311
echo "Your tools are installed in: $INSTALL_DIR/$TARGET"
1312 72 julius
echo "or1ksim has been installed in: $INSTALL_DIR/$SIM_VER"
1313 22 ocadmin
echo
1314 72 julius
echo "Please add the paths:"
1315
echo "\t$INSTALL_DIR/$TARGET/bin"
1316
echo "\t$INSTALL_DIR/or1ksim/bin"
1317
echo "to your PATH variable, for example, in most systems add the line"
1318
echo "below to your ~/.bashrc file:"
1319 22 ocadmin
echo
1320 72 julius
echo "\texport PATH=\$PATH:$INSTALL_DIR/$TARGET/bin:$INSTALL_DIR/or1ksim/bin"
1321
echo
1322
echo "For further support please visit the OpenRISC forum at OpenCores"
1323
echo "http://opencores.org/forum,OpenRISC"
1324
echo
1325 22 ocadmin
exit 0
1326
 
1327
##########################End Script##############################

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.