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 1772

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

powered by: WebSVN 2.1.0

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