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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [toolchain_script/] [MOF_ORSOC_TCHN_v5a_or32-elf.sh] - Blame information for rev 1775

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

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

powered by: WebSVN 2.1.0

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