Skip to content

Commit

Permalink
Merge pull request #5 from sifive/elf2bin
Browse files Browse the repository at this point in the history
elf2bin: New program
  • Loading branch information
bsousi5 authored Aug 22, 2018
2 parents 1cefad3 + 06382be commit 34fd237
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2018 SiFive, Inc
# SPDX-License-Identifier: Apache-2.0

bin_SCRIPTS = bin2hex elf2hex
bin_SCRIPTS = bin2hex elf2hex elf2bin

bin2hex: freedom-bin2hex.sh
cat $< | sed 's:[@]PYTHON[@]:$(PYTHON):g' | sed 's:[@]pythondir[@]:$(pythondir):g' > $@
Expand All @@ -11,11 +11,16 @@ elf2hex: freedom-elf2hex.sh
cat $< | sed 's:[@]OBJCOPY[@]:$(OBJCOPY):g' | sed 's:[@]BIN2HEX[@]:$(bindir)/$(target)-bin2hex:g' > $@
chmod +x $@

elf2bin: freedom-elf2bin.sh
cat $< | sed 's:[@]OBJCOPY[@]:$(OBJCOPY):g' | sed 's:[@]BIN2HEX[@]:$(bindir)/$(target)-bin2hex:g' > $@
chmod +x $@

python_PYTHON = freedom-bin2hex.py

EXTRA_DIST = freedom-bin2hex.sh
EXTRA_DIST += freedom-elf2hex.sh
EXTRA_DIST += freedom-elf2bin.sh
EXTRA_DIST += README.md

clean-local:
-rm -f bin2hex elf2hex
-rm -f bin2hex elf2hex elf2bin
37 changes: 37 additions & 0 deletions freedom-elf2bin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

unset input
unset output
objcopy="@OBJCOPY@"
while [[ "$1" != "" ]]
do
case "$1" in
-h | --help) echo "$0 [-h, --help] --input INPUT.ELF [--output OUTPUT.HEX]" >&2; exit 0;;
--input) input="$2"; shift 2;;
--output) output="$2"; shift 2;;
*) echo "$0: unknown argument $1">&2; exit 1;;
esac
done

if [[ "$input" == "" ]]
then
echo "$0 [-h, --help] --input INPUT.ELF [--output OUTPUT.HEX]" >&2
exit 1
fi

if [[ "$objcopy" == "" ]]
then
echo "$0: could not find objcopy"
exit 1
fi

temp="$(mktemp -d)"
trap "rm -rf $temp" EXIT

"$objcopy" "$input" -O binary "$temp"/output.bin
if [[ "$output" == "" ]]
then
cat "$temp"/output.bin
else
cp "$temp"/output.bin "$output"
fi

0 comments on commit 34fd237

Please sign in to comment.