| 1 |
73 |
olivier.gi |
#!/bin/bash
|
| 2 |
2 |
olivier.gi |
#------------------------------------------------------------------------------
|
| 3 |
|
|
# Copyright (C) 2001 Authors
|
| 4 |
|
|
#
|
| 5 |
|
|
# This source file may be used and distributed without restriction provided
|
| 6 |
|
|
# that this copyright statement is not removed from the file and that any
|
| 7 |
|
|
# derivative work contains the original copyright notice and the associated
|
| 8 |
|
|
# disclaimer.
|
| 9 |
|
|
#
|
| 10 |
|
|
# This source file is free software; you can redistribute it and/or modify
|
| 11 |
|
|
# it under the terms of the GNU Lesser General Public License as published
|
| 12 |
|
|
# by the Free Software Foundation; either version 2.1 of the License, or
|
| 13 |
|
|
# (at your option) any later version.
|
| 14 |
|
|
#
|
| 15 |
|
|
# This source is distributed in the hope that it will be useful, but WITHOUT
|
| 16 |
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 17 |
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
| 18 |
|
|
# License for more details.
|
| 19 |
|
|
#
|
| 20 |
|
|
# You should have received a copy of the GNU Lesser General Public License
|
| 21 |
|
|
# along with this source; if not, write to the Free Software Foundation,
|
| 22 |
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 23 |
|
|
#
|
| 24 |
|
|
#------------------------------------------------------------------------------
|
| 25 |
|
|
#
|
| 26 |
|
|
# File Name: asm2ihex.sh
|
| 27 |
|
|
#
|
| 28 |
17 |
olivier.gi |
# Author(s):
|
| 29 |
|
|
# - Olivier Girard, olgirard@gmail.com
|
| 30 |
|
|
#
|
| 31 |
2 |
olivier.gi |
#------------------------------------------------------------------------------
|
| 32 |
17 |
olivier.gi |
# $Rev: 73 $
|
| 33 |
|
|
# $LastChangedBy: olivier.girard $
|
| 34 |
|
|
# $LastChangedDate: 2010-08-03 21:26:39 +0200 (Tue, 03 Aug 2010) $
|
| 35 |
|
|
#------------------------------------------------------------------------------
|
| 36 |
2 |
olivier.gi |
|
| 37 |
|
|
###############################################################################
|
| 38 |
|
|
# Parameter Check #
|
| 39 |
|
|
###############################################################################
|
| 40 |
|
|
EXPECTED_ARGS=5
|
| 41 |
|
|
if [ $# -ne $EXPECTED_ARGS ]; then
|
| 42 |
|
|
echo "ERROR : wrong number of arguments"
|
| 43 |
33 |
olivier.gi |
echo "USAGE : asm2ihex.sh <test name> <test assembler file> <definition file> <prog mem size> <data mem size>"
|
| 44 |
|
|
echo "Example : asm2ihex.sh c-jump_jge ../src/c-jump_jge.s43 ../bin/template.def 2048 128"
|
| 45 |
2 |
olivier.gi |
exit 1
|
| 46 |
|
|
fi
|
| 47 |
|
|
|
| 48 |
|
|
|
| 49 |
|
|
###############################################################################
|
| 50 |
|
|
# Check if definition & assembler files exist #
|
| 51 |
|
|
###############################################################################
|
| 52 |
|
|
|
| 53 |
|
|
if [ ! -e $2 ]; then
|
| 54 |
|
|
echo "Assembler file doesn't exist: $2"
|
| 55 |
|
|
exit 1
|
| 56 |
|
|
fi
|
| 57 |
|
|
if [ ! -e $3 ]; then
|
| 58 |
|
|
echo "Linker definition file template doesn't exist: $3"
|
| 59 |
|
|
exit 1
|
| 60 |
|
|
fi
|
| 61 |
|
|
|
| 62 |
|
|
|
| 63 |
|
|
###############################################################################
|
| 64 |
|
|
# Generate the linker definition file #
|
| 65 |
|
|
###############################################################################
|
| 66 |
|
|
|
| 67 |
33 |
olivier.gi |
DMEM_SIZE=$5
|
| 68 |
|
|
PMEM_SIZE=$4
|
| 69 |
|
|
PMEM_BASE=$((0x10000-$PMEM_SIZE))
|
| 70 |
2 |
olivier.gi |
|
| 71 |
33 |
olivier.gi |
cp $3 ./pmem.def
|
| 72 |
|
|
sed -i "s/PMEM_BASE/$PMEM_BASE/g" pmem.def
|
| 73 |
|
|
sed -i "s/PMEM_SIZE/$PMEM_SIZE/g" pmem.def
|
| 74 |
|
|
sed -i "s/DMEM_SIZE/$DMEM_SIZE/g" pmem.def
|
| 75 |
2 |
olivier.gi |
|
| 76 |
|
|
|
| 77 |
|
|
###############################################################################
|
| 78 |
|
|
# Compile, link & generate IHEX file #
|
| 79 |
|
|
###############################################################################
|
| 80 |
|
|
msp430-as -alsm $2 -o $1.o > $1.l43
|
| 81 |
|
|
msp430-objdump -xdsStr $1.o >> $1.l43
|
| 82 |
33 |
olivier.gi |
msp430-ld -T ./pmem.def $1.o -o $1.elf
|
| 83 |
2 |
olivier.gi |
msp430-objcopy -O ihex $1.elf $1.ihex
|