setup gcc minimum build env

This commit is contained in:
eggman 2016-06-22 23:08:09 +09:00
parent ddad8cdcfd
commit 4e0103b0f5
52 changed files with 16714 additions and 0 deletions

98
makebin/makebin.sh Normal file
View file

@ -0,0 +1,98 @@
###!/bin/bash
TOOLCHAIN=arm-none-eabi
chr() {
[ ${1} -lt 256 ] || return 1
printf \\$(printf '%03o' $1)
}
# Another version doing the octal conversion with arithmetic
# faster as it avoids a subshell
chr () {
[ ${1} -lt 256 ] || return 1
printf \\$(($1/64*100+$1%64/8*10+$1%8))
}
# Another version using a temporary variable to avoid subshell.
# This one requires bash 3.1.
chr() {
local tmp
[ ${1} -lt 256 ] || return 1
printf -v tmp '%03o' "$1"
printf \\"$tmp"
}
ord() {
LC_CTYPE=C printf '%d' "'$1"
}
SOURCE="${BASH_SOURCE[0]}"
# resolve $SOURCE until the file is no longer a symlink
# if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
while [ -h "$SOURCE" ]; do
TARGET="$(readlink "$SOURCE")"
if [[ $SOURCE == /* ]]; then
# echo "SOURCE '$SOURCE' is an absolute symlink to '$TARGET'"
SOURCE="$TARGET"
else
DIR="$( dirname "$SOURCE" )"
# echo "SOURCE '$SOURCE' is a relative symlink to '$TARGET' (relative to '$DIR')"
SOURCE="$DIR/$TARGET"
fi
done
RDIR="$( dirname "$SOURCE" )"
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
cd $DIR
cp -f ../build/target.axf .
cp ./target.axf ./target_pure.axf
${TOOLCHAIN}-strip ./target_pure.axf
${TOOLCHAIN}-objcopy -j .ram.start.table -j .ram_image1.text \
-Obinary ./target_pure.axf ./ram_1.bin
${TOOLCHAIN}-objcopy -j .image2.start.table -j .ram_image2.text -j .ram.data \
-Obinary ./target_pure.axf ./ram_2.bin
${TOOLCHAIN}-nm target.axf | sort > target.map
${TOOLCHAIN}-objdump -d target.axf > target.asm
./prepend_header.sh ./ram_1.bin __ram_image1_text_start__ ./target.map 0
./prepend_header.sh ./ram_2.bin __ram_image2_text_start__ ./target.map
cat ./ram_1_prepend.bin ./ram_2_prepend.bin > ./ram_all.bin
#mbed_disk=100
#while [[ $mbed_disk -le 122 ]]
#do
#
# diskname=`chr $mbed_disk`
# filename="/cygdrive/$diskname/mbed.htm"
# if [ -f $filename ];
# then
# break
# fi
# mbed_disk=$((mbed_disk+1))
#done
#if [[ $mbed_disk -le 122 ]];
#then
# echo cp ./ram_all.bin /cygdrive/$diskname/
# cp ./ram_all.bin /cygdrive/$diskname/
#else
# echo mbed usb disk not found
#fi

88
makebin/prepend_header.sh Executable file
View file

@ -0,0 +1,88 @@
##!/bin/bash
################
# Library
################
Usage() {
echo "Usage: $0 [Image Name] [Start Symbol Name] [Symbols List File]"
}
# Parameter:
# value, width, dest
function MakeFixedWidthHeaderString() {
local __value=$1
local __width=$2
local __dest=$3
local __header_raw
local __header_raw_reorder
local __header_array
if [[ "$__dest" ]]; then
__header_raw=$(printf "%0""$__width""x" $__value)
# echo $__header_raw
# 20000680 to 80060020
for (( i=$__width; i > 0; i-=2 ))
do
__header_raw_reorder+=$(echo $__header_raw | cut -b $((i-1)))
__header_raw_reorder+=$(echo $__header_raw | cut -b $i)
done
# echo $__header_raw_reorder
__header_array=($(echo $__header_raw_reorder | sed 's/\(.\)/\1 /g'))
for (( i=0; i < $__width; i+=2))
do
eval $__dest+='\\x'"${__header_array[$i]}${__header_array[$i+1]}"
done
fi
}
################
# Main
################
if [ "$#" -lt 3 ]; then
Usage
exit 1
fi
# Get Parameters
IMAGE_FILENAME=$1
IMAGE_SECTION_START_NAME=$2
SYMBOL_LIST=$3
IMG2_OFFSET=$4
# Constant Variables
PATTERN_1=0x96969999
PATTERN_2=0xFC66CC3F
PATTERN_3=0x03CC33C0
PATTERN_4=0x6231DCE5
RSVD=0xFFFFFFFFFFFFFFFF
IMAGE_LEN=$(du -b $IMAGE_FILENAME | cut -f 1)
IMAGE_ADDR="0x$(grep $IMAGE_SECTION_START_NAME $SYMBOL_LIST | awk '{print $1}')"
IMAGE_FILENAME_PREPEND="${IMAGE_FILENAME%.*}"'_prepend.'"${IMAGE_FILENAME##*.}"
IMAGE_FILENAME_NEW=$(basename $IMAGE_FILENAME)
HEADER_FINAL=''
if [ "$IMAGE_FILENAME_NEW" == "ram_1.bin" ]; then
MakeFixedWidthHeaderString $PATTERN_1 8 HEADER_FINAL
MakeFixedWidthHeaderString $PATTERN_2 8 HEADER_FINAL
MakeFixedWidthHeaderString $PATTERN_3 8 HEADER_FINAL
MakeFixedWidthHeaderString $PATTERN_4 8 HEADER_FINAL
fi
MakeFixedWidthHeaderString $IMAGE_LEN 8 HEADER_FINAL
MakeFixedWidthHeaderString $IMAGE_ADDR 8 HEADER_FINAL
if [ "$IMAGE_FILENAME_NEW" == "ram_1.bin" ]; then
MakeFixedWidthHeaderString $IMG2_OFFSET 4 HEADER_FINAL
MakeFixedWidthHeaderString $RSVD 12 HEADER_FINAL
else
MakeFixedWidthHeaderString $RSVD 16 HEADER_FINAL
fi
# echo $HEADER_FINAL
echo -n -e $HEADER_FINAL | cat - $IMAGE_FILENAME > $IMAGE_FILENAME_PREPEND