3 # Copyright (C) 2008,2009,2010 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.
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.
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.
19 ##Title: MOF_ORSOC_TCN_v5c_or32-elf.sh
20 ##Purpose: Complete Toolchain Builder from MOF & ORSoC.
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)
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
46 # - included better or1ksim config file in Linux sources patch, now
47 # named "or1ksim_linux.cfg"
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!
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 # 260509 - Changed gcc's package download to gcc-core as we only use the
76 # c-language compiler and libraries right now.
77 # 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 # 290609 - Changed linux patch to 2.3 - is a patch derived from revision 42 of
81 # OpenRISC repository's kernel.
82 # 301109 - Changed GCC patch to one with single precision floating point as
84 # 021209 - Added --disable-werror flag to gdb-6.8 configure line to fix issue
86 # 110310 - Moved or1ksim to its own directory in the chosen install directory
87 # 140310 - Fixed problem with mkdir command
88 # 140310 - Fixed ncurses header checking
89 # 010410 - Fixed ncurses header checking on Cygwin (added -I path to gcc cmd)
90 # 270610 - Updated or1ksim version to 0.4.0
92 # TODO: OS X build things - need an "elf.h" from some Linux machine's
93 # /usr/local/include dir and put in Mac's /usr/local/include dir -
94 # this solves issue with Linux compilation
95 # TODO: OS X build things - add HOST_LOADLIBES="lintl" to make line of uClibc
96 # TODO: OS X build things - must remove the -Werror line in $GDB_VER/gdb/Makefile,
98 # sed 's/WERROR\_CFLAGS\ \=\ \-Werror/WERROR\_CFLAGS\ \=/' $GDB_VER/gdb/Makefile
99 # Can also just change the gdb-6.8/gdb/Makefile.in and remove the Werror= thing
100 # TODO: OS X build things - or1ksim, in or1ksim-0.3.0/peripheral/atadevice.c, it
101 # includes byteswap.h - actually it's abstract.h that defines #LE_16() bswap_16(),
102 # so in abstract.h we put in defines for bswap_16 as
103 # #define bswap_16(value) ((((value) & 0xff) << 8) | ((value) >> 8))
104 # TODO: OS X Build things - or1ksim strndup.c, in or1k-0.3.0/port/strndup.c strndup function,
105 # types not exist etc. Need to include sys/types.h and string.h to this file to fix
107 # TODO: OS X build things - or1ksim - or1ksim-0.3.0/sim-cmd.c passes one of our functions
108 # to a readline function, rl_event_hook, but this is not defined in the OS X (BSD)
109 # readline package, so the GNU readline package must be used.
110 # TODO: OS X build things - or1ksim segfaults when run for some reason.
112 ## A function we'll call throughout the setup process to check if the previous
113 ## command finished without error
119 echo "############################ERROR#############################"
121 echo "Error during toolchain installation."
123 echo "Please report this to the script maintainers."
125 echo "A useful report would contain information such as the tool"
126 echo "being built/\"make\"d when the error occurred and the relevant"
127 echo "lines of console output or log file relating to the error. It"
128 echo "also helps to include information about your the host OS and"
129 echo "version of GCC."
130 echo "A good place to look for solutions, and report any bugs, is at"
131 echo "the OpenRISC project's bug tracker on OpenCores.org:"
133 echo " http://opencores.org/openrisc,bugtracker"
149 # Compile a simple program, including the header we're checking for
150 echo "#include <$1.h>" > header_check.c
151 echo "int main () { return 0; }" >> header_check.c
152 gcc header_check.c
-I/usr
/include
/$1
155 check_essential_build_tools
()
158 echo "#########################Checking for required build tools######################"
160 for TOOL
in $REQUIRED_TOOL_LIST
162 echo -n "Checking for $TOOL "
163 WHICHTOOL
=`which $TOOL`
168 echo "\t$TOOL not found"
170 echo "Please install $TOOL and re-run this script"
176 echo "Checking for libncurses-dev (headers)"
177 header_check
"ncurses"
178 # Now check the return value of that function
179 if [ $?
-ne 0 ]; then
181 echo "\tlibncurses-dev not found"
182 echo ; echo "Please install libncurses-dev and re-run this script"; echo
183 rm -f header_check.c a.out
186 rm -f header_check.c a.out
188 # Todo: somehow inform the user that if we're checking for makeinfo they need to install texinfo package
195 ## Beginning globals ##
197 ## ORSoC FTP download settings ##
198 ORSOC_FTP_HOST
="opencores.org"
199 ORSOC_FTP_USER
="ocuser"
200 ORSOC_FTP_PASSWD
="oc"
201 ORSOC_FTP_DIR
="toolchain"
203 ## GNU FTP download settings ##
204 GNU_FTP_HOST
="ftp.gnu.org"
205 GNU_FTP_USER
="anonymous"
206 #GNU_FTP_BINUTILS_DIR="gnu/binutils"
207 GNU_FTP_GCC_DIR
="gnu/gcc/gcc-4.2.2"
208 GNU_FTP_GDB_DIR
="gnu/gdb"
210 ## Linux kernel download settings ##
211 KERNEL_FTP_HOST
="ftp.kernel.org"
212 KERNEL_FTP_USER
="anonymous"
213 KERNEL_FTP_PASSWD
="anonymous"
214 KERNEL_FTP_DIR
="pub/linux/kernel/v2.6"
216 ## Local directory variables ##
221 ## Makedir command we'll use ##
223 ## Versions of the toolchain components ##
224 BINUTILS_VER
=binutils-2.18
.50
226 GCC_VER
=gcc-
$GCC_VER_NUM
228 UCLIB_VER
=uClibc-0.9
.29
229 LINUX_VER
=linux-2.6
.24
230 BUSY_VER
=busybox-1.7
.5
231 SIM_VER
=or1ksim-0.4
.0
234 BINUTILS_PATCH
="$BINUTILS_VER.or32_fixed_patch-v2.1.bz2"
235 GCC_PATCH
=$GCC_VER-or32-fp.
patch.bz2
236 LINUX_PATCH
="linux_2.6.24_or32_unified_v2.3.bz2"
237 UCLIBC_PATCH
="uClibc-0.9.29-or32-patch-1.1.bz2"
238 GDB_PATCH
="or32-gdb-6.8-patch-2.4.bz2"
244 #CONFIG1="rgd_uc_29dotconfig" ## Now changed to rgd_uc_29v5dotconfig as it uses paths to the 2.6.24 kernel ##
245 CONFIG1
="rgd_uc_29v5dotconfig"
246 CONFIG2
="rgd_bb_1.75dotconfig"
249 RAMDISK_FILE
=initrd-fb-03.ext2.last.work
.1.7.5
250 LINUX_RAMDISK_FILE
=arch
/or32
/support
/initrd-fb-03.ext2
## The location and name of the ramdisk that Linux wants when it compiles
252 ## Toolchain prefix ##
257 ZBALL1
=$BINUTILS_VER.
tar.bz2
258 TBALL1
=$BINUTILS_VER.
tar
259 ZBALL2
=gcc-core-
$GCC_VER_NUM.
tar.bz2
261 ZBALL3
=$UCLIB_VER.
tar.bz2
262 TBALL3
=$UCLIB_VER.
tar
263 ZBALL4
=$LINUX_VER.
tar.bz2
264 TBALL4
=$LINUX_VER.
tar
265 ZBALL5
=$BUSY_VER.
tar.bz2
267 ZBALL6
=$SIM_VER.
tar.bz2
269 ZBALL7
=$RAMDISK_FILE.bz2
270 ZBALL8
=$GDB_VER.
tar.bz2
273 ORSOC_FTP_FILE_LIST
="$ZBALL1
286 GNU_FTP_FILE_LIST
="$ZBALL2
289 KERNEL_FTP_FILE_LIST
=$ZBALL4
293 ## Check if we've been given the debug mode flag ##
294 ## We won't clear away all the directories if run with the -d or -D options ##
296 while getopts d OPT
; do
306 echo "The OpenRISC toolchain install script - Provided by ORSoC & MeansOfFreedom.net"
307 echo "Version $SCRIPT_VERSION"
309 echo "#####################################README#####################################"
311 echo "This script will install tools required for development on the OpenRISC platform"
312 echo "This version ($SCRIPT_VERSION) includes: "
313 echo " $GCC_VER, $BINUTILS_VER, $UCLIB_VER"
314 echo " $LINUX_VER, $GDB_VER, $BUSY_VER and $SIM_VER"
316 echo "Please follow the prompts to select the install location."
318 echo "Note: Two new directories, or32-build and or32-download, will be created in the"
319 echo "current directory for storing downloaded files and building the tools."
320 echo "Also: This script attempts to mount a ramdisk image in a local directory to copy"
321 echo "in the freshly built busybox. This requires root user privileges - if they are"
322 echo "not deteceted the existing busybox binaries will remain in the ramdisk image."
324 echo "#####################################README#####################################"
327 echo "Install the toolchain under current directory?"
328 echo "Current directory: [$DIR]"
329 echo "Tools will be installed in [$DIR/$TARGET]"
334 ## $YN will be zero length string if user just pressed enter ##
339 VAL
=$
(echo $YN |
tr [:upper
:] [:lower
:])
344 # Optional install path
345 echo "Enter the path the toolchain will be installed in:"
348 # Check if the path exists and ask the user to verify it
352 #Check the path exists
355 # The path entered is OK
356 echo "Chosen directory is [$DIR]"
357 echo "Tools will be installed in [$DIR/$TARGET], or1ksim in [$DIR/or1ksim]"
367 VAL
=$
(echo $DN |
tr [:upper
:] [:lower
:])
370 #echo "Path does not exist. Please create it and ensure user has correct permissions."
371 echo "Path does not exist. Create $DIR now?"
376 ## $MKPATH was zero, so user probably just pressed enter without entering anything, which we'll interpret as "n" ##
379 MKPATHYN
=$
(echo $MKPATH |
tr [:upper
:] [:lower
:])
382 if [ $MKPATHYN = "y" ]
386 # Check we made it successfully
391 DN
="x" # Set this so we do go back through and ask the user to verify
401 echo "Enter the path the toolchain should be installed in:"
408 # echo "Working in " `pwd`
411 ## Now check that the required tools to build the toolchain are installed
412 check_essential_build_tools
414 BUILD_TOP
=$START_DIR/or32-build
417 ## Set donload directory to be under the current directory ##
418 DOWNLOAD_DIR
=$START_DIR/or32-download
420 ## Setup the target tool installation directory ##
425 ####################################################################################################
426 ## Now check which sources have already been downloaded, if any ##
427 DO_DOWNLOADS
="y" ## Default is to NOT do downloads
429 if [ $DBG_BUILD -eq 1 ]
431 ## Ask if we should do downloads ##
435 ## $YN will be zero length string if user just pressed enter ##
436 if [ -z $DO_DOWNLOADS ]
440 DO_DOWNLOADS
=$
(echo $DO_DOWNLOADS |
tr [:upper
:] [:lower
:])
445 if [ $DO_DOWNLOADS = "y" ]
447 ## Check if download directory exists, if not create it ##
448 if [ ! -d $DOWNLOAD_DIR ]; then
454 ## We'll need the md5sum file ##
455 ## This is a file stored on the ORSoC FTP server, containing checksums of all the files we need ##
457 wget
ftp://$ORSOC_FTP_USER:$ORSOC_FTP_PASSWD@
$ORSOC_FTP_HOST/$ORSOC_FTP_DIR/$MD5SUM_FILE
458 ## Make sure we got that OK ##
461 ## We have lists of what to get from each FTP let's create a loop for each ##
463 ## ORSoC FTP server downloads ##
464 for CURRENT_FILE
in $ORSOC_FTP_FILE_LIST
466 # Check if we've already got the file
467 if [ -e $CURRENT_FILE ]
469 echo "File $CURRENT_FILE exists locally."
470 echo "Verifying MD5 checksum:"
471 ## Verify it's right by checking the MD5 checksum ##
472 ## First we get the line for $CURRENT_FILE out of the $MD5SUM_FILE, then feed it to "md5sum -c"
473 ## which checks it and sets the return code, $? to 0 if OK, 1 if problem ##
474 cat $MD5SUM_FILE |
grep $CURRENT_FILE |
md5sum -c
477 #MD5sum of $CURRENT_FILE differs from expected value - we'll download it again
478 echo "MD5 checksum of $CURRENT_FILE differs from expected value. Re-downloading."
480 wget
ftp://$ORSOC_FTP_USER:$ORSOC_FTP_PASSWD@
$ORSOC_FTP_HOST/$ORSOC_FTP_DIR/$CURRENT_FILE
484 # File doesn't exist locally - we'll download it
485 echo "Downloading $CURRENT_FILE"
486 wget
ftp://$ORSOC_FTP_USER:$ORSOC_FTP_PASSWD@
$ORSOC_FTP_HOST/$ORSOC_FTP_DIR/$CURRENT_FILE
492 ## GNU FTP server downloads ##
493 for CURRENT_FILE
in $GNU_FTP_FILE_LIST
495 ## Check if we've already got the file ##
496 if [ -e $CURRENT_FILE ]
498 echo "File $CURRENT_FILE exists locally."
499 echo "Verifying MD5 checksum:"
500 ## Verify it's right by checking the MD5 checksum ##
501 ## First we get the line for $CURRENT_FILE out of the $MD5SUM_FILE, then feed it to "md5sum -c"
502 ## which checks it and sets the return code, $? to 0 if OK, 1 if problem ##
503 cat $MD5SUM_FILE |
grep $CURRENT_FILE |
md5sum -c
506 ## MD5sum of present one is incorrect - we'll download it again ##
507 echo "MD5 checksum of $CURRENT_FILE differs from expected value. Re-downloading."
509 ## Depending on the file, we need a specific path ##
510 ## gcc's path on ftp ##
511 if [ $CURRENT_FILE = $ZBALL2 ]; then
512 GNU_FTP_DIR
=$GNU_FTP_GCC_DIR
514 ## gdb's path on ftp ##
515 if [ $CURRENT_FILE = $ZBALL8 ]; then
516 GNU_FTP_DIR
=$GNU_FTP_GDB_DIR
518 wget
ftp://$GNU_FTP_USER:$GNU_FTP_USER@
$GNU_FTP_HOST/$GNU_FTP_DIR/$CURRENT_FILE
522 # File doesn't exist - we'll download it
523 echo "Downloading $CURRENT_FILE"
524 ## Depending on the file, we need a specific path ##
525 ## gcc's path on ftp ##
526 if [ $CURRENT_FILE = $ZBALL2 ]; then
527 GNU_FTP_DIR
=$GNU_FTP_GCC_DIR
529 ## gdb's path on ftp ##
530 if [ $CURRENT_FILE = $ZBALL8 ]; then
531 GNU_FTP_DIR
=$GNU_FTP_GDB_DIR
533 wget
ftp://$GNU_FTP_USER:$GNU_FTP_USER@
$GNU_FTP_HOST/$GNU_FTP_DIR/$CURRENT_FILE
539 ## Kernel.org FTP server downloads ##
540 CURRENT_FILE
=$KERNEL_FTP_FILE_LIST
541 ## Usually just a single file from the kernel.org ftp site ##
542 if [ -e $CURRENT_FILE ]
544 echo "File $CURRENT_FILE exists locally."
545 echo "Verifying MD5 checksum:"
546 ## Verify it's right by checking the MD5 checksum ##
547 ## First we get the line for $CURRENT_FILE out of the $MD5SUM_FILE, then feed it to "md5sum -c"
548 ## which checks it and sets the return code, $? to 0 if OK, 1 if problem ##
549 cat $MD5SUM_FILE |
grep $CURRENT_FILE |
md5sum -c
552 #MD5sum of present one is incorrect - we'll download it again
553 echo "MD5 checksum of $CURRENT_FILE differs from expected value. Re-downloading."
555 wget
ftp://$KERNEL_FTP_USER:$KERNEL_FTP_USER@
$KERNEL_FTP_HOST/$KERNEL_FTP_DIR/$CURRENT_FILE
560 echo "Downloading $CURRENT_FILE"
561 wget
ftp://$KERNEL_FTP_USER:$KERNEL_FTP_PASSWD@
$KERNEL_FTP_HOST/$KERNEL_FTP_DIR/$CURRENT_FILE
566 fi # if [ $DO_DOWNLOADS = "y" ]
568 ####################################################################################################
571 ON_CYGWIN
=`set | grep -i mach|grep -i -c cygwin`
572 if [ $ON_CYGWIN -ge 1 ]
575 echo "Cygwin host detected"
576 echo "Platform specific exports:"
577 echo "export HOST_LOADLIBES=\"-lcurses -lintl\" "
580 export HOST_LOADLIBES
="-lcurses -lintl"
583 ####################################################################################################
587 ## if not debug building, let's remove all the old stuff ##
589 if [ $DBG_BUILD -eq 0 ]
591 ## Always start with a clean build dir ##
596 $MKDIR $BUILD_TOP/b-gcc
597 $MKDIR $BUILD_TOP/b-b
600 ## default build option is yes ##
603 if [ $DBG_BUILD -eq 1 ]
605 ## Ask if we should build binutils ##
606 echo "Re-build $BINUTILS_VER ?"
609 ## $YN will be zero length string if user just pressed enter ##
614 BUILD_THIS
=$
(echo $YN |
tr [:upper
:] [:lower
:])
617 if [ $BUILD_THIS = "y" ]
619 ## Delete and recreate the binutils directory ##
620 rm -rf $BUILD_TOP/b-b
621 rm -rf $BUILD_TOP/$BINUTILS_VER
622 $MKDIR $BUILD_TOP/b-b
627 ##########################Building Binutils#######################
628 if [ $BUILD_THIS = "y" ]
631 echo "############################## Building binutils ###############################"
633 echo "Decompressing source"
636 ## Extract sources ##
637 tar xjf
$DOWNLOAD_DIR/$ZBALL1
640 echo "Patching binutils with $BINUTILS_PATCH"
644 bzip2 -dc $DOWNLOAD_DIR/$BINUTILS_PATCH |
patch -p1 > $BINUTILS_VER-patch.log
2>&1
646 ## Make sure that patched ok ##
653 echo "Configuring $BINUTILS_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-checking"
654 echo "Logging output to $BINUTILS_VER-configure.log"
655 $BUILD_TOP/$BINUTILS_VER/configure
--target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-checking > $BINUTILS_VER-configure.log
2>&1
658 echo "Making and installing $BINUTILS_VER"
659 echo "Logging output to $BINUTILS_VER-make.log "
660 make all
install > $BINUTILS_VER-make.log
2>&1
662 ## Make sure that built ok ##
668 #######################Finish Building Binutils#####################
670 ## Export the path to the new or32 binaries directory, used by the rest of this script ##
672 echo "Adding $INSTALL_DIR/$TARGET/bin to the PATH variable"
673 export PATH
=$INSTALL_DIR/$TARGET/bin
:$PATH
675 ## default build option is yes ##
678 if [ $DBG_BUILD -eq 1 ]
680 ## Ask if we should do the initial builds of GCC and Linux ##
681 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)?"
684 ## $YN will be zero length string if user just pressed enter ##
687 BUILD_THIS
="n" # default is no
689 BUILD_THIS
=$
(echo $YN |
tr [:upper
:] [:lower
:])
692 if [ $BUILD_THIS = "y" ]
694 ## Delete and recreate the gcc directory ##
695 rm -rf $BUILD_TOP/b-gcc
696 rm -rf $BUILD_TOP/$GCC_VER
697 rm -rf $BUILD_TOP/$LINUX_VER
699 $MKDIR $BUILD_TOP/b-gcc
701 ## Undo everything done in the next part
702 rm -rf $INSTALL_DIR/$TARGET/include
703 unlink
$INSTALL_DIR/$TARGET/sys-include
708 ##########################Building GCC and Linux############################
709 if [ $BUILD_THIS = "y" ]
713 echo "####################### Building or32 gcc and Linux ############################"
715 echo "Decompressing source"
719 ## Extract sources ##
720 tar xjf
$DOWNLOAD_DIR/$ZBALL2 ## gcc sources ##
722 tar xjf
$DOWNLOAD_DIR/$ZBALL4 ## Linux kernel sources ##
725 echo "Patching $LINUX_VER with patch file $LINUX_PATCH"
729 ## Apply patch to linux kernel sources ##
730 bzip2 -dc $DOWNLOAD_DIR/$LINUX_PATCH |
patch -p1 > $LINUX_VER-patch.log
2>&1
732 ## Make sure that patched ok ##
734 ## Copy our preconfigured configuration file into place ##
735 cp rgd_dot_config .config
738 echo "Making Linux oldconfig"
740 make oldconfig
> $LINUX_VER-make-oldconfig.log
2>&1
742 ## Make sure that built ok ##
747 $MKDIR $INSTALL_DIR/$TARGET/include
748 $MKDIR $INSTALL_DIR/$TARGET/include
/asm
749 $MKDIR $INSTALL_DIR/$TARGET/include
/linux
751 cp -f -dR $LINUX_VER/include
/linux
/* $INSTALL_DIR/$TARGET/include
/linux
752 cp -f -dR $LINUX_VER/include
/asm-or32
/* $INSTALL_DIR/$TARGET/include
/asm
754 cd $INSTALL_DIR/$TARGET
755 ln -s include sys-include
762 echo "Patching $GCC_VER with $GCC_PATCH"
764 bzip2 -dc $DOWNLOAD_DIR/$GCC_PATCH |
patch -p1 > $GCC_VER-patch.log
2>&1
766 ## Make sure that patched ok ##
774 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"
775 echo "Logging output to $GCC_VER-configure.log"
776 $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
779 echo "Making and installing $GCC_VER"
780 echo "Logging output to $GCC_VER-make.log"
781 make all
install > $GCC_VER-make.log
2>&1
783 ## Make sure that built ok ##
789 echo "Making vmlinux image"
790 echo "Logging output to vmlinux-make.log"
793 make vmlinux ARCH
=or32 CROSS_COMPILE
=$INSTALL_DIR/$TARGET/bin
/$TARGET- > vmlinux-make.log
2>&1
795 ## Make sure that built ok ##
798 ##########################Finish Building GCC and Linux############################
801 ## default build option is yes ##
804 if [ $DBG_BUILD -eq 1 ]
806 ## Ask if we should rebuild uClibc ##
807 echo "Re-build $UCLIB_VER ?"
810 ## $YN will be zero length string if user just pressed enter ##
813 BUILD_THIS
="n" # default is no
815 BUILD_THIS
=$
(echo $YN |
tr [:upper
:] [:lower
:])
818 if [ $BUILD_THIS = "y" ]
820 ## Delete the uClibc directory ##
821 rm -rf $BUILD_TOP/$UCLIB_VER
825 ##########################Building uClibc#########################
826 if [ $BUILD_THIS = "y" ]
830 echo "############################## Building uClibc #################################"
832 echo "Decompressing source"
835 tar xjf
$DOWNLOAD_DIR/$ZBALL3 ## uClibc sources ##
838 echo "Patching $UCLIB_VER with $UCLIBC_PATCH"
842 ## Patch uClibc sources ##
843 bzip2 -dc $DOWNLOAD_DIR/$UCLIBC_PATCH |
patch -p1 > $UCLIB_VER-patch.log
2>&1
845 ## Make sure that patched ok ##
848 export CC
=$TARGET-gcc
850 #cp $DOWNLOAD_DIR/$CONFIG1 $BUILD_TOP/$UCLIB_VER/.config
851 #cp $DOWNLOAD_DIR/$CONFIG1 $BUILD_TOP/$UCLIB_VER/.config.old
853 ## $TARGET name implementation into config script ##
854 ## First get the second part of the target name, after the "-", the "elf" in "or32-elf", for example ##
855 TARGET_SECOND_PART
=`echo $TARGET | cut -f 2 -d "-"`
856 ## First change any references to the uclinux target ##
857 ## And delete the line saying DEVEL_PREFIX so we can put our $INSTALL_DIR path in ##
858 sed "s/or32\-uclinux/\or32\-$TARGET_SECOND_PART/" $DOWNLOAD_DIR/$CONFIG1 |
sed "/DEVEL\_PREFIX\=/d" > $BUILD_TOP/$UCLIB_VER/.config
## Output to the .config ##
859 ## Now output the new DEVEL_PATH= value ##
860 echo "DEVEL_PREFIX=\"$INSTALL_DIR/$TARGET\"" >> $BUILD_TOP/$UCLIB_VER/.config
861 ## copy it to .config.old ##
862 cp $BUILD_TOP/$UCLIB_VER/.config
$BUILD_TOP/$UCLIB_VER/.config.old
863 ## Do the configuration ##
865 ## Change the cross compiler name in the Config.or32 file
866 ## First get the second part of the target name, after the "-" ##
867 TARGET_SECOND_PART
=`echo $TARGET | cut -f 2 -d "-"`
868 ## Removes the uclinux line and changes to whatever our current target is ##
869 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
870 mv $BUILD_TOP/$UCLIB_VER/extra
/Configs
/Config.or32.newtarget
$BUILD_TOP/$UCLIB_VER/extra
/Configs
/Config.or32
872 if [ $ON_CYGWIN -ge 1 ]
874 ## If on Cygwin, fix strange error where 'install' command by the makefile ##
875 ## results in it trying to execute the INSTALL text file in the root of the ##
877 mv INSTALL INSTALL.txt
881 echo "Making uClibc oldconfig"
883 HOST_LOADLIBES
="-lcurses -lintl" HOSTCC
=`which gcc` make oldconfig
> $UCLIB_VER-make-oldconfig.log
2>&1
885 ## Make sure that built ok ##
888 ln -s extra
/Configs
/Config.or32 Config
891 echo "Making and install $UCLIB_VER"
892 echo "Logging output to $UCLIB_VER-make.log"
893 make all
install > $UCLIB_VER-make.log
2>&1
895 ## Make sure that built ok ##
900 ##########################Finish Building uClibc#########################
903 ## default build option is yes ##
906 if [ $DBG_BUILD -eq 1 ]
908 ## Ask if we should rebuild gcc ##
909 echo "Perform $GCC_VER re-build? - YES (y) if you rebuilt GCC and Linux previously, otherwise definitely NO (n)."
912 ## $YN will be zero length string if user just pressed enter ##
915 BUILD_THIS
="n" # default is no
917 BUILD_THIS
=$
(echo $YN |
tr [:upper
:] [:lower
:])
920 if [ $BUILD_THIS = "y" ]
922 ## Undo some things we did before after doing this compile ##
923 unlink
$INSTALL_DIR/$TARGET/$TARGET/sys-include
924 rm -rf $INSTALL_DIR/$TARGET/$TARGET/lib
/*
929 ##########################re-Building GCC########################
930 if [ $BUILD_THIS = "y" ]
934 echo "############################## Re-building or-32 gcc ###########################"
936 echo "Re-building $GCC_VER"
943 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"
944 echo "Logging output to $GCC_VER-rebuild-configure.log"
946 $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
951 echo "Re-building and re-installing $GCC_VER"
952 echo "Logging output to $GCC_VER-rebuild-make.log"
953 make all
install > $GCC_VER-rebuild-make.log
2>&1
955 ## Make sure that built ok ##
958 cd $INSTALL_DIR/$TARGET/$TARGET
959 ln -s ..
/include sys-include
961 cp -f -dR ..
/..
/lib
/* .
966 ##########################finish re-Building GCC########################
969 ## default build option is yes ##
972 if [ $DBG_BUILD -eq 1 ]
974 ## Ask if we should rebuild gdb ##
975 echo "Rebuild $GDB_VER?"
978 ## $YN will be zero length string if user just pressed enter ##
981 BUILD_THIS
="n" # default is no
983 BUILD_THIS
=$
(echo $YN |
tr [:upper
:] [:lower
:])
986 if [ $BUILD_THIS = "y" ]
988 ## Delete existing gdb dir ##
989 rm -rf $BUILD_TOP/$GDB_VER
994 ########################## GDB build ################
995 if [ $BUILD_THIS = "y" ]
999 echo "############################## Building GDB ####################################"
1001 echo "Decompressing source"
1006 tar xjf
$DOWNLOAD_DIR/$ZBALL8
1009 echo "Patching $GDB_VER with $GDB_PATCH"
1010 echo "Logging output to $GDB_VER-patch.log"
1013 bzcat
-dc $DOWNLOAD_DIR/$GDB_PATCH |
patch -p1 > $GDB_VER-patch.log
2>&1
1015 ## Make sure that patched ok ##
1019 echo "Configuring $GDB_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-werror"
1020 echo "Logging output to $GDB_VER-configure.log"
1022 .
/configure
--target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-werror > $GDB_VER-configure.log
2>&1
1025 echo "Making and installing $GDB_VER"
1026 echo "Logging output to $GDB_VER-make.log"
1027 make all
install > $GDB_VER-make.log
2>&1
1029 ## Make sure that built ok ##
1035 ########################## finish GDB build ################
1037 ## default build option is yes ##
1040 if [ $DBG_BUILD -eq 1 ]
1042 ## Ask if we should rebuild busybox ##
1043 echo "Rebuild $BUSY_VER?"
1046 ## $YN will be zero length string if user just pressed enter ##
1049 BUILD_THIS
="n" # default is no
1051 BUILD_THIS
=$
(echo $YN |
tr [:upper
:] [:lower
:])
1054 if [ $BUILD_THIS = "y" ]
1056 ## Delete existing busybox stuff ##
1057 rm -rf $BUILD_TOP/$BUSY_VER
1061 ##########################Building Busybox########################
1062 if [ $BUILD_THIS = "y" ]
1066 echo "############################## Building BusyBox ################################"
1068 echo "Decompressing source"
1073 tar xjf
$DOWNLOAD_DIR/$ZBALL5
1077 cp $DOWNLOAD_DIR/$CONFIG2 $BUILD_TOP/$BUSY_VER/.config
1078 cp $DOWNLOAD_DIR/$CONFIG2 $BUILD_TOP/$BUSY_VER/.config.old
1081 echo "Making $BUSY_VER oldconfig"
1082 make oldconfig
> $BUSY_VER-make-oldconfig.log
2>&1
1084 ## Make Sure that built ok ##
1087 ## Put the Linux headers in BusyBox's include dir ##
1089 ln -s $BUILD_TOP/$LINUX_VER/include
/linux
$BUILD_TOP/$BUSY_VER/include
/.
1090 ln -s $BUILD_TOP/$LINUX_VER/include
/asm
$BUILD_TOP/$BUSY_VER/include
/.
1093 echo "Making $BUSY_VER"
1094 echo "Logging output to $BUSY_VER-make.log"
1095 make ARCH
=or32 CROSS_COMPILE
=$INSTALL_DIR/$TARGET/bin
/$TARGET- > $BUSY_VER-make.log
2>&1
1097 ## Make sure that built ok ##
1101 echo "Installing $BUSY_VER"
1102 echo "Logging output to $BUSY_VER-install.log"
1103 make install ARCH
=or32 CROSS_COMPILE
=$INSTALL_DIR/$TARGET/bin
/$TARGET- > $BUSY_VER-install.log
2>&1
1105 ## Make sure that built ok ##
1110 ## Copy and extract the ramdisk image file
1112 cp $DOWNLOAD_DIR/$ZBALL7 .
## Ramdisk file ##
1114 bunzip2
$RAMDISK_FILE.bz2
1116 ## We can only play with the ext2 image if we're not on Cygwin ##
1117 if [ -z $ON_CYGWIN ]
1121 if [ $RT = "root" ];then
1124 mount
-t ext2
-o loop
$RAMDISK_FILE rd_mount
1125 cp -f -dR $BUILD_TOP/busy_out
.1.7.5/* $BUILD_TOP/rd_mount
1127 cp -f $RAMDISK_FILE $LINUX_VER/$LINUX_RAMDISK_FILE
1130 echo "User is not root. Unable to mount Linux ramdisk."
1131 echo "Note that this program built BusyBox but did not"
1132 echo "install it on the ramdisk. Defaults are used."
1133 cp -f $RAMDISK_FILE $LINUX_VER/$LINUX_RAMDISK_FILE
1136 fi ## if [ -z $ON_CYGWIN ]
1141 ########################## Finish BusyBox build ################
1143 ## default build option is yes ##
1146 if [ $DBG_BUILD -eq 1 ]
1148 ## Ask if we should rebuild linux again##
1149 echo "Rebuild the $LINUX_VER rebuild (only ever yes (y) if performed previous linux rebuild)?"
1152 ## $YN will be zero length string if user just pressed enter ##
1155 BUILD_THIS
="n" # default is no
1157 BUILD_THIS
=$
(echo $YN |
tr [:upper
:] [:lower
:])
1162 #echo "Start Building Linux kernel?"
1164 ##########################Final Linux kernel build################
1165 if [ $BUILD_THIS = "y" ]
1169 echo "########################### Linux image generation #############################"
1174 echo "Making vmlinux"
1175 echo "Logging output to vmlinux-remake.log"
1176 make vmlinux ARCH
=or32 CROSS_COMPILE
=$INSTALL_DIR/$TARGET/bin
/$TARGET- > vmlinux-remake.log
2>&1
1178 ## Make sure that built ok ##
1183 ##########################Finished Final Linux kernel build################
1187 if [ $DBG_BUILD -eq 1 ]
1189 ## Ask if we should rebuild or1ksim##
1190 echo "Rebuild $SIM_VER ?"
1193 ## $YN will be zero length string if user just pressed enter ##
1196 BUILD_THIS
="n" # default is no
1198 BUILD_THIS
=$
(echo $YN |
tr [:upper
:] [:lower
:])
1201 if [ $BUILD_THIS = "y" ]
1203 ## Clean previous or1ksim directories ##
1204 rm -rf $BUILD_TOP/$SIM_VER
1209 ##########################Simulator build#########################
1210 if [ $BUILD_THIS = "y" ]
1214 echo "############################## Building or1ksim ################################"
1216 echo "Decompressing source"
1220 tar xjf
$DOWNLOAD_DIR/$ZBALL6
1225 echo "Configuring $SIM_VER: --target=$TARGET --prefix=$INSTALL_DIR/$SIM_VER"
1227 .
/configure
--target=$TARGET --prefix=$INSTALL_DIR/$SIM_VER > $SIM_VER-configure.log
2>&1
1230 echo "Making and installing $SIM_VER"
1231 echo "Logging output to $SIM_VER-make.log"
1232 make all
install > $SIM_VER-make.log
2>&1
1234 ## Make sure that built ok ##
1237 ## Setup symbolic link from or1ksim-x.y.z to simply or1ksim
1239 echo "Symbolically linking $INSTALL_DIR/$SIM_VER to $INSTALL_DIR/or1ksim"
1240 if [ -e $INSTALL_DIR/or1ksim
]; then
1241 echo "Symlink $INSTALL_DIR/or1ksim already exists. Updating to this version"
1242 unlink
$INSTALL_DIR/or1ksim
;
1245 echo "ln -s $INSTALL_DIR/$SIM_VER $INSTALL_DIR/or1ksim"
1246 ln -s $INSTALL_DIR/$SIM_VER $INSTALL_DIR/or1ksim
1250 ##########################Finish Simulator build#########################
1253 ##########################Code Test###############################
1255 echo "Launch the simulator with the newly compiled Linux image and BusyBox apps?"
1261 SVAL
="n" ## Default is no ##
1263 SVAL
=$
(echo $SI |
tr [:upper
:] [:lower
:])
1266 if [ $SVAL = "y" ];then
1268 ## Check for X's xterm, if we find it, and a valid $DISPLAY variable, we'll open the simulator with an xterm tty ##
1274 # Xterm exists, check if the $DISPLAY variable is set
1275 # Get the display variable
1276 DISPLAY
=`printenv DISPLAY`
1277 echo "DISPLAY variable is set to $DISPLAY"
1280 ## It appears display is set, let's set the or1ksim_linux.cfg file to use an xterm instead of telnet ##
1282 ## Rename the original script, adding .orig to the end ##
1283 mv or1ksim_linux.cfg or1ksim_linux.cfg.orig
1284 ## Now use sed to comment the line specifiying a telnet tty and uncomment the xterm line, restoring the original script ##
1285 sed 's/channel\ \=\ \"tcp\:10084\"/\/\*\ channel\ \=\ \"tcp\:10084\"\ \*\//' or1ksim_linux.cfg.orig |
sed 's/\/\*\ channel\ \=\ \"xterm\:\"\ \*\//\ channel\ \=\ \"xterm\:\"\ /' > or1ksim_linux.cfg
1286 echo "########################## or1ksim ###############################"
1288 echo "or1ksim will open an xterm for console output as Linux is booting."
1290 echo "########################## or1ksim ###############################"
1295 echo "########################## or1ksim ###############################"
1297 echo " To connect to the simulator run: telnet 127.0.0.1 10084"
1299 echo "########################## or1ksim ###############################"
1304 cd $BUILD_TOP/$LINUX_VER
1305 $INSTALL_DIR/or1ksim
/bin
/$TARGET-sim -f or1ksim_linux.cfg vmlinux
1308 ## User didn't run the sim, but tell them how to anyway ##
1309 echo "The compiled linux image is found in $BUILD_TOP/$LINUX_VER/vmlinux"
1310 echo "To run it in the simulator, cd to $BUILD_TOP/$LINUX_VER"
1312 echo "$TARGET-sim -f or1ksim_linux.cfg vmlinux"
1318 echo "OpenRISC toolchain and architectural simulator build is complete!"
1320 echo "Your tools are installed in: $INSTALL_DIR/$TARGET"
1321 echo "or1ksim has been installed in: $INSTALL_DIR/$SIM_VER"
1323 echo "Please add the paths:"
1324 echo "\t$INSTALL_DIR/$TARGET/bin"
1325 echo "\t$INSTALL_DIR/or1ksim/bin"
1326 echo "to your PATH variable, for example, in most systems add the line"
1327 echo "below to your ~/.bashrc file:"
1329 echo "\texport PATH=\$PATH:$INSTALL_DIR/$TARGET/bin:$INSTALL_DIR/or1ksim/bin"
1331 echo "For further support please visit the OpenRISC forum at OpenCores"
1332 echo "http://opencores.org/forum,OpenRISC"
1336 ##########################End Script##############################