#!/bin/sh -u #- # Copyright (c) 2005 Oliver Lehmann # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $Id: mig_DUMP2bin.sh,v 1.13 2008/06/15 11:45:11 olivleh1 Exp $ # USAGE() { cat <<-EOF usage: $0 -f [-o|-u] [-c] [-w] -c move the dump back from dump/ to . and delete the binary in bin/ and the xxd file in xxd/ -f specify the dumpfile you have taken from UDOS -o file generated by OS/M dump, WEGA hd, or UPROG LIST -u file generated by UDOS DUMP -w migrate EPROM image in a.out format(WEGA format) to an Intel/binary formated EPROM EOF exit 1 } DUMP2XXD() { awk ' BEGIN { hexnum = 0; if( "'$1'" == "UDOS-DUMP" ) { starthex=3 endhex=19 startbin=63 } if( "'$1'" == "OS/M-DUMP" ) { starthex=2 endhex=18 rawdump=1 } if( "'$1'" == "UNIX-hd" ) { starthex=2 endhex=18 startbin=62 } } /^[0-9a-zA-Z][0-9a-zA-Z:]*[ ]/ { if( rawdump != 1) { a=sprintf("%07x: ",hexnum) } else { a="" } for( i=starthex; i $FILE.xxd return $? } if [ $# -lt 2 ] ; then USAGE fi if ! which xxd >/dev/null 2>&1 ; then echo "xxd not found!" echo "xxd can be installed by installing Vim (http://www.vim.org/)" exit 1 fi DUMP_TYPE= CLEAN=0 MIG_EPROM= while getopts f:ouwc OPT ; do case $OPT in c) CLEAN=1 ;; f) FILE=$OPTARG ;; o) if [ -z "$DUMP_TYPE" ] ; then DUMP_TYPE=O else USAGE fi ;; u) if [ -z "$DUMP_TYPE" ] ; then DUMP_TYPE=U else USAGE fi ;; w) MIG_EPROM=YES ;; *) USAGE ;; esac done [ -z "$DUMP_TYPE" -a ! "$CLEAN" = "1" ] && USAGE [ ! -d xxd ] && mkdir xxd [ ! -d dump ] && mkdir dump [ ! -d bin ] && mkdir bin if [ "$CLEAN" = "1" ] ; then if [ ! -f "dump/$FILE.dump" ] ; then echo "dump/$FILE.dump does not exists!" exit 1 fi mv dump/$FILE.dump ./$FILE rm -f bin/$FILE xxd/$FILE.xxd exit $? fi if [ -f "bin/$FILE" ] ; then echo "bin/$FILE is already there, move it away!" exit 1 fi if [ ! -f "$FILE" ] ; then echo "$FILE does not exists!" exit 1 fi echo "Going to migrate the dump to binary." if [ "$DUMP_TYPE" = "O" ] ; then DUMP2XXD OS/M-DUMP && xxd -c 16 -p -r $FILE.xxd $FILE.bin RC=$? else DUMP2XXD UDOS-DUMP && xxd -r $FILE.xxd $FILE.bin RC=$? fi if [ "$RC" = "0" ] ; then echo "Migration is done!" if [ "$MIG_EPROM" = "YES" ] ; then SIZE=$(( $(ls -l $FILE.bin | awk '{print $5}') - 512 )) if [ "$(( $SIZE % 1024 ))" != 0 ] ; then echo "Something went wrong with the size calculation!" echo "The size must be a power of 1024 but is $SIZE." exit 1 else echo "Start copying only the relevant part out of the image." if dd if=$FILE.bin of=$FILE.tmp skip=40 bs=1 count=$SIZE 2>/dev/null ; then mv $FILE.tmp $FILE.bin fi echo "Done!" fi fi mv $FILE dump/$FILE.dump mv $FILE.xxd xxd/ mv $FILE.bin bin/$FILE fi