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 73

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

powered by: WebSVN 2.1.0

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