From fabdc4e8ce3a9b77f425894fc15717f872ddf06c Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Mon, 21 Sep 2020 03:00:55 +0200 Subject: [PATCH] Updated setup script, added file that can be sourced that sets up the path properly and improved upload --- .gitignore | 9 ++- upload.py => bin/upload | 14 ++-- build-mb.sh | 157 ++++++++++++++++++++++++++++++++++++++++ setup.sh | 15 +++- source.sh | 3 + 5 files changed, 185 insertions(+), 13 deletions(-) rename upload.py => bin/upload (87%) create mode 100755 build-mb.sh create mode 100644 source.sh diff --git a/.gitignore b/.gitignore index fe4cbb9..aef0905 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -arm-none-eabi-gcc +arm-none-eabi/* +microblazeel-xilinx-elf/* +env/* +sdcc-code/* + disk.img -env -sdcc-code -zasm diff --git a/upload.py b/bin/upload similarity index 87% rename from upload.py rename to bin/upload index e2041da..b75832d 100755 --- a/upload.py +++ b/bin/upload @@ -4,6 +4,7 @@ import os import sys import time import argparse +import math def progressbar(it, prefix="", size=60, file=sys.stdout): count = len(it) @@ -51,12 +52,16 @@ def rom_upload(filename): else: print("Failed to open serial port") -def serial_upload(filename): +def bload_upload(filename): # ser = serial.Serial("COM3", timeout=1, write_timeout=1) ser = serial.Serial("/dev/ttyUSB0", timeout=1, write_timeout=1, baudrate=115200) if ser.is_open: size = os.path.getsize(filename) + print("Size: {} ({} pages)".format(size, math.ceil(size/256))) + + input("Press enter to start upload") + with open(filename, "rb") as f: for i in progressbar(range(size), "Upload: ", 40): byte = f.read(1) @@ -79,18 +84,17 @@ def main(): parser = argparse.ArgumentParser(description="Upload binaries to the z80 computer.") parser.add_argument("filename", help="file to upload") parser.add_argument("--rom", dest="rom", action="store_const", const=True, default=False, help="Upload binary to rom") - parser.add_argument("--serial", dest="serial", action="store_const", const=True, default=False, help="Upload binary over serial") + parser.add_argument("--bload", dest="bload", action="store_const", const=True, default=False, help="Upload binary to bload") args = parser.parse_args() if (args.rom): rom_upload(args.filename) - elif (args.serial): - serial_upload(args.filename) + elif (args.bload): + bload_upload(args.filename) else: print("You needs to specify a target") - if "__main__": main() diff --git a/build-mb.sh b/build-mb.sh new file mode 100755 index 0000000..9eac9af --- /dev/null +++ b/build-mb.sh @@ -0,0 +1,157 @@ +#!/bin/bash +## +# Script to build GCC for microblaze. +# Written by Martijn Koedam (m.l.p.j.koedam@tue.nl) +# Modified by Foivos S. Zakkak (foivos@zakkak.net) +# +# Current version is tested on Archlinux +## + +TARGET=microblazeel-xilinx-elf +PROGRAM_PREFIX=mb- + +BUILD_DIR=build-mb +CUR=$(pwd) +INSTALL_DIR=$CUR/$TARGET + +CORES=12 + +GCC_URL=ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-10.2.0/gcc-10.2.0.tar.xz +NEWLIB_URL=ftp://sources.redhat.com/pub/newlib/newlib-3.1.0.tar.gz +BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/binutils-2.35.tar.xz + +GCC_FILE=$(basename $GCC_URL) +NEWLIB_FILE=$(basename $NEWLIB_URL) +BINUTILS_FILE=$(basename $BINUTILS_URL) + +GCC=${GCC_FILE%.tar.*} +BINUTILS=${BINUTILS_FILE%.tar.*} +NEWLIB=${NEWLIB_FILE%.tar.*} + +# Explicitly define the PATH to avoid ambiguities. Especially '.' +# should not be present in PATH. +export PATH=/usr/local/bin:/usr/bin:/bin + +# target +# needed for newlib, because of non-standard PROGRAM_PREFIX. +export CC_FOR_TARGET="$PROGRAM_PREFIX"gcc +export CXX_FOR_TARGET="$PROGRAM_PREFIX"g++ +export GCC_FOR_TARGET="$PROGRAM_PREFIX"gcc +export AR_FOR_TARGET="$PROGRAM_PREFIX"ar +export AS_FOR_TARGET="$PROGRAM_PREFIX"as +export LD_FOR_TARGET="$PROGRAM_PREFIX"ld +export NM_FOR_TARGET="$PROGRAM_PREFIX"nm +export RANLIB_FOR_TARGET="$PROGRAM_PREFIX"ranlib +export STRIP_FOR_TARGET="$PROGRAM_PREFIX"strip + + +function download() +{ + if [ ! -f $1 ] + then + wget -O $1 $2 + else + echo "$1 exists" + fi +} + +function extract() +{ + if [ ! -d "$BUILD_DIR/$2" ] + then + tar xf $1 -C $BUILD_DIR + fi + + if [ ! -d "$BUILD_DIR/$2" ] + then + echo "Failed to extract $2 to $1" + exit 1 + fi +} + +function build() +{ + pushd $BUILD_DIR + pushd $1 + + if [ ! -d "build" ] + then + mkdir "build" + pushd "build" + else + pushd "build" + make distclean + fi + + ../configure --target=$TARGET --program-prefix=$PROGRAM_PREFIX --prefix=$INSTALL_DIR $2 + if [ $? != 0 ] + then + echo "Failed to configure" + exit 1; + fi + env + make -j"$CORES" all$3 + if [ $? != 0 ] + then + echo "Failed to build" + exit 1; + fi + env "PATH=$PATH" make install$3 + if [ $? != 0 ] + then + echo "Failed to install" + exit 1; + fi + + popd + popd + popd +} + +function gcc_dependencies() +{ + + pushd $BUILD_DIR + pushd $1 + ./contrib/download_prerequisites + popd + popd +} + +if [ ! -d $BUILD_DIR ] +then + mkdir $BUILD_DIR +fi + +#download files. +echo "Downloading" +download "$GCC_FILE" "$GCC_URL" +download "$NEWLIB_FILE" "$NEWLIB_URL" +download "$BINUTILS_FILE" "$BINUTILS_URL" + +echo "Building binutils" +extract "$BINUTILS_FILE" "$BINUTILS" +build $BINUTILS "" "" + +# put results into PATH. +export PATH=$INSTALL_DIR/bin/:$PATH + +echo "Building gcc-stage1" +extract "$GCC_FILE" "$GCC" +gcc_dependencies "$GCC" +build $GCC "--enable-languages=c --disable-nls --without-headers --disable-multilib --disable-libssp --with-newlib" "-host" + +echo "Building newlib" +extract "$NEWLIB_FILE" "$NEWLIB" +build $NEWLIB "" "" + + +echo "Building gcc,g++ stage2" +extract "$GCC_FILE" "$GCC" +build $GCC "--enable-languages=c,c++ --disable-nls --without-headers --disable-multilib --disable-libssp --with-newlib" "" + +# Remove leftover files +rm gcc-10.2.0.tar.xz +rm binutils-2.35.tar.xz +rm newlib-3.1.0.tar.gz +rm -rf build-mb diff --git a/setup.sh b/setup.sh index 049b2e8..9b93094 100755 --- a/setup.sh +++ b/setup.sh @@ -1,10 +1,17 @@ #!/bin/bash # @todo Check if all the required programs are installed -wget https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v9.2.1-1.1/xpack-arm-none-eabi-gcc-9.2.1-1.1-linux-x64.tar.gz -O arm-none-eabi-gcc.tar.gz -tar xvf arm-none-eabi-gcc.tar.gz -mv xpack-arm-none-eabi-gcc-9.2.1-1.1 arm-none-eabi-gcc -rm arm-none-eabi-gcc.tar.gz +# Cleanup old files +rm -rf arm-none-eabi +rm -rf env +rm -rf sdcc-code + +wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2 -O arm-none-eabi-gcc.tar.bz2 +tar xvf arm-none-eabi-gcc.tar.bz2 +mv gcc-arm-none-eabi-9-2020-q2-update arm-none-eabi +rm arm-none-eabi-gcc.tar.bz2 + +./build-mb.sh svn checkout svn://svn.code.sf.net/p/sdcc/code/trunk sdcc-code diff --git a/source.sh b/source.sh new file mode 100644 index 0000000..0af5962 --- /dev/null +++ b/source.sh @@ -0,0 +1,3 @@ +# This order makes it so we can use deactive to also deactive the other additions to the path +source $(dirname $(readlink -f $0))/env/bin/activate +PATH=$(dirname $(readlink -f $0))/arm-none-eabi/bin:$(dirname $(readlink -f $0))/microblazeel-xilinx-elf/bin:$(dirname $(readlink -f $0))/bin:/opt/Xilinx/14.7/ISE_DS/EDK/bin/lin64:$PATH