#!/bin/bash
|
#!/bin/bash
|
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
# Copyright (C) 2001 Authors
|
# Copyright (C) 2001 Authors
|
#
|
#
|
# This source file may be used and distributed without restriction provided
|
# This source file may be used and distributed without restriction provided
|
# that this copyright statement is not removed from the file and that any
|
# that this copyright statement is not removed from the file and that any
|
# derivative work contains the original copyright notice and the associated
|
# derivative work contains the original copyright notice and the associated
|
# disclaimer.
|
# disclaimer.
|
#
|
#
|
# This source file is free software; you can redistribute it and/or modify
|
# This source file is free software; you can redistribute it and/or modify
|
# it under the terms of the GNU Lesser General Public License as published
|
# it under the terms of the GNU Lesser General Public License as published
|
# by the Free Software Foundation; either version 2.1 of the License, or
|
# by the Free Software Foundation; either version 2.1 of the License, or
|
# (at your option) any later version.1
|
# (at your option) any later version.1
|
#
|
#
|
# This source is distributed in the hope that it will be useful, but WITHOUT
|
# This source is distributed in the hope that it will be useful, but WITHOUT
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
# License for more details.
|
# License for more details.
|
#
|
#
|
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
# along with this source; if not, write to the Free Software Foundation,
|
# along with this source; if not, write to the Free Software Foundation,
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
#
|
#
|
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
#
|
#
|
# File Name: asm2ihex.sh
|
# File Name: asm2ihex.sh
|
#
|
#
|
# Author(s):
|
# Author(s):
|
# - Olivier Girard, olgirard@gmail.com
|
# - Olivier Girard, olgirard@gmail.com
|
#
|
#
|
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
# $Rev: 202 $
|
# $Rev: 207 $
|
# $LastChangedBy: olivier.girard $
|
# $LastChangedBy: olivier.girard $
|
# $LastChangedDate: 2015-07-01 23:13:32 +0200 (Wed, 01 Jul 2015) $
|
# $LastChangedDate: 2015-10-20 22:58:27 +0200 (Tue, 20 Oct 2015) $
|
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
|
|
###############################################################################
|
###############################################################################
|
# Parameter Check #
|
# Parameter Check #
|
###############################################################################
|
###############################################################################
|
EXPECTED_ARGS=7
|
EXPECTED_ARGS=7
|
if [ $# -ne $EXPECTED_ARGS ]; then
|
if [ $# -ne $EXPECTED_ARGS ]; then
|
echo "ERROR : wrong number of arguments"
|
echo "ERROR : wrong number of arguments"
|
echo "USAGE : asm2ihex.sh <test name> <test assembler file> <linker script> <assembler define> <prog mem size> <data mem size> <peripheral addr space size>"
|
echo "USAGE : asm2ihex.sh <test name> <test assembler file> <linker script> <assembler define> <prog mem size> <data mem size> <peripheral addr space size>"
|
echo "Example : asm2ihex.sh c-jump_jge ../src/c-jump_jge.s43 ../bin/template.x ../bin/pmem.h 2048 128 512"
|
echo "Example : asm2ihex.sh c-jump_jge ../src/c-jump_jge.s43 ../bin/template.x ../bin/pmem.h 2048 128 512"
|
exit 1
|
exit 1
|
fi
|
fi
|
|
|
# MSPGCC version prefix
|
# MSPGCC version prefix
|
if [ -z "$MSPGCC_PFX" ]; then
|
if [ -z "$MSPGCC_PFX" ]; then
|
if command -v msp430-gcc >/dev/null; then
|
if command -v msp430-gcc >/dev/null; then
|
MSPGCC_PFX=msp430
|
MSPGCC_PFX=msp430
|
else
|
else
|
MSPGCC_PFX=msp430-elf
|
MSPGCC_PFX=msp430-elf
|
fi
|
fi
|
fi
|
fi
|
|
|
###############################################################################
|
###############################################################################
|
# Check if definition & assembler files exist #
|
# Check if definition & assembler files exist #
|
###############################################################################
|
###############################################################################
|
|
|
if [ ! -e $2 ]; then
|
if [ ! -e $2 ]; then
|
echo "Assembler file doesn't exist: $2"
|
echo "Assembler file doesn't exist: $2"
|
exit 1
|
exit 1
|
fi
|
fi
|
if [ ! -e $3 ]; then
|
if [ ! -e $3 ]; then
|
echo "Linker definition file template doesn't exist: $3"
|
echo "Linker definition file template doesn't exist: $3"
|
exit 1
|
exit 1
|
fi
|
fi
|
if [ ! -e $4 ]; then
|
if [ ! -e $4 ]; then
|
echo "Assembler definition file template doesn't exist: $4"
|
echo "Assembler definition file template doesn't exist: $4"
|
exit 1
|
exit 1
|
fi
|
fi
|
|
|
|
|
###############################################################################
|
###############################################################################
|
# Generate the linker definition file #
|
# Generate the linker definition file #
|
###############################################################################
|
###############################################################################
|
|
|
PER_SIZE=$7
|
PER_SIZE=$7
|
DMEM_SIZE=$6
|
DMEM_SIZE=$6
|
PMEM_SIZE=$5
|
PMEM_SIZE=$5
|
PMEM_BASE=$((0x10000-$PMEM_SIZE))
|
PMEM_BASE=$((0x10000-$PMEM_SIZE))
|
STACK_INIT=$((PER_SIZE+0x0080))
|
STACK_INIT=$((PER_SIZE+0x0080))
|
|
|
cp $3 ./pmem.x
|
cp $3 ./pmem.x
|
cp $4 ./pmem_defs.asm
|
cp $4 ./pmem_defs.asm
|
sed -i "s/PMEM_BASE/$PMEM_BASE/g" pmem.x
|
sed -ie "s/PMEM_BASE/$PMEM_BASE/g" pmem.x
|
sed -i "s/PMEM_SIZE/$PMEM_SIZE/g" pmem.x
|
sed -ie "s/PMEM_SIZE/$PMEM_SIZE/g" pmem.x
|
sed -i "s/DMEM_SIZE/$DMEM_SIZE/g" pmem.x
|
sed -ie "s/DMEM_SIZE/$DMEM_SIZE/g" pmem.x
|
sed -i "s/PER_SIZE/$PER_SIZE/g" pmem.x
|
sed -ie "s/PER_SIZE/$PER_SIZE/g" pmem.x
|
sed -i "s/STACK_INIT/$STACK_INIT/g" pmem.x
|
sed -ie "s/STACK_INIT/$STACK_INIT/g" pmem.x
|
|
|
sed -i "s/PMEM_SIZE/$PMEM_SIZE/g" pmem_defs.asm
|
sed -ie "s/PMEM_SIZE/$PMEM_SIZE/g" pmem_defs.asm
|
sed -i "s/PER_SIZE_HEX/$PER_SIZE/g" pmem_defs.asm
|
sed -ie "s/PER_SIZE_HEX/$PER_SIZE/g" pmem_defs.asm
|
if [ $MSPGCC_PFX == "msp430-elf" ]; then
|
if [ $MSPGCC_PFX == "msp430-elf" ]; then
|
sed -i "s/PER_SIZE/.data/g" pmem_defs.asm
|
sed -ie "s/PER_SIZE/.data/g" pmem_defs.asm
|
sed -i "s/PMEM_BASE_VAL/.text/g" pmem_defs.asm
|
sed -ie "s/PMEM_BASE_VAL/.text/g" pmem_defs.asm
|
sed -i "s/PMEM_EDE_SIZE/0/g" pmem_defs.asm
|
sed -ie "s/PMEM_EDE_SIZE/0/g" pmem_defs.asm
|
else
|
else
|
sed -i "s/PER_SIZE/$PER_SIZE/g" pmem_defs.asm
|
sed -ie "s/PER_SIZE/$PER_SIZE/g" pmem_defs.asm
|
sed -i "s/PMEM_BASE_VAL/$PMEM_BASE/g" pmem_defs.asm
|
sed -ie "s/PMEM_BASE_VAL/$PMEM_BASE/g" pmem_defs.asm
|
sed -i "s/PMEM_EDE_SIZE/$PMEM_SIZE/g" pmem_defs.asm
|
sed -ie "s/PMEM_EDE_SIZE/$PMEM_SIZE/g" pmem_defs.asm
|
fi
|
fi
|
|
|
|
|
###############################################################################
|
###############################################################################
|
# Compile, link & generate IHEX file #
|
# Compile, link & generate IHEX file #
|
###############################################################################
|
###############################################################################
|
echo ""
|
echo ""
|
echo "\$ $MSPGCC_PFX-as -alsm $2 -o $1.o > $1.l43"
|
echo "\$ $MSPGCC_PFX-as -alsm $2 -o $1.o > $1.l43"
|
$MSPGCC_PFX-as -alsm $2 -o $1.o > $1.l43
|
$MSPGCC_PFX-as -alsm $2 -o $1.o > $1.l43
|
echo "\$ $MSPGCC_PFX-objdump -xdsStr $1.o >> $1.l43"
|
echo "\$ $MSPGCC_PFX-objdump -xdsStr $1.o >> $1.l43"
|
$MSPGCC_PFX-objdump -xdsStr $1.o >> $1.l43
|
$MSPGCC_PFX-objdump -xdsStr $1.o >> $1.l43
|
echo "\$ $MSPGCC_PFX-ld -T ./pmem.x $1.o -o $1.elf"
|
echo "\$ $MSPGCC_PFX-ld -T ./pmem.x $1.o -o $1.elf"
|
$MSPGCC_PFX-ld -T ./pmem.x $1.o -o $1.elf
|
$MSPGCC_PFX-ld -T ./pmem.x $1.o -o $1.elf
|
echo "\$ $MSPGCC_PFX-objcopy -O ihex $1.elf $1.ihex"
|
echo "\$ $MSPGCC_PFX-objcopy -O ihex $1.elf $1.ihex"
|
$MSPGCC_PFX-objcopy -O ihex $1.elf $1.ihex
|
$MSPGCC_PFX-objcopy -O ihex $1.elf $1.ihex
|
echo ""
|
echo ""
|
|
|