Skip to content

Instantly share code, notes, and snippets.

@WillSams
Created May 12, 2019 21:11
Show Gist options
  • Save WillSams/be044ace3718b95bcbe83db570ea3d58 to your computer and use it in GitHub Desktop.
Save WillSams/be044ace3718b95bcbe83db570ea3d58 to your computer and use it in GitHub Desktop.
M68000 Bin2Elf
#!/bin/bash
echo "==================================================================="
echo " This script can be executed under Linux or Windows (using MSys2) "
echo " Modify GENDEV variable to fit your toolchain. "
echo
echo " Linux toolchain: "
echo " https://gist.github.com/WillSams/c4cbf6235b467d8b595693969342237e "
echo
echo " Windows toolchain: "
echo " https://gist.github.com/WillSams/f592f9d494b51119945440f7e91079b0 "
echo "==================================================================="
echo
echo
set -o nounset # unset variables are errors
SCRIPTVERSION="2019.05.12"
SCRIPTNAME="m68k-bin2elf.sh"
SCRIPTFULLNAME="$0"
GENDEV="/opt/m68k"
BINARY=""
echoerror() { printf "\033[1;31m * ERROR\033[0m: %s\\n" "$@" 1>&2; }
usage() {
cat << EOT
Usage : ${SCRIPTNAME} [options]
Options:
-h Display this message
-v Display script version
-d Location of the m68K cross compiler. Default is /opt/m68k.
-b Binary. You romfile goes here, i.e. m68k-bin2elf.sh -b nhl94.bin
EOT
} # ---------- end of function usage ----------
while getopts ':hvdb:' opt
do
case "${opt}" in
h ) usage; exit 0 ;;
v ) echo "$0 -- Version $SCRIPTVERSION"; exit 0 ;;
d ) GENDEV=$OPTARG ;;
b ) BINARY=$OPTARG ;;
\?) echo
echoerror "Option does not exist : $OPTARG"
usage
exit 1
;;
esac # --- end of case ---
done
shift $((OPTIND-1))
LD=$GENDEV/bin/m68k-elf-ld
READELF=$GENDEV/bin/m68k-elf-readelf
OBJCOPY=$GENDEV/bin/m68k-elf-objcopy
LDFLAGS="-O1 -static -nostdlib"
$OBJCOPY -B m68k -I binary -O elf32-m68k $BINARY output.o
$LD $LDFLAGS output.o --oformat elf32-m68k -o output.elf || echoerror " 'output.elf' not created."
#*****************************************************************************
echo "$SCRIPTFULLNAME ($SCRIPTVERSION) complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment