forked from sifive/elf2hex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreedom-elf2hex.sh
46 lines (40 loc) · 1.01 KB
/
freedom-elf2hex.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
unset bit_width
unset input
unset output
objcopy="@OBJCOPY@"
bin2hex="@BIN2HEX@"
while [[ "$1" != "" ]]
do
case "$1" in
-h | --help) echo "$0 [-h, --help] --bit-width BIT_WIDTH --input INPUT.ELF [--output OUTPUT.HEX]" >&2; exit 0;;
-w | --bit-width) bit_width="$2"; shift 2;;
--input) input="$2"; shift 2;;
--output) output="$2"; shift 2;;
*) echo "$0: unknown argument $1">&2; exit 1;;
esac
done
if [[ "$bit_width" == "" ]]
then
echo "$0 [-h] --bit-width BIT_WIDTH --input INPUT.ELF [--output OUTPUT.HEX]" >&2
exit 1
fi
if [[ "$input" == "" ]]
then
echo "$0 [-h] --bit-width BIT_WIDTH --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
"$bin2hex" -w "$bit_width" "$temp"/output.bin
else
"$bin2hex" -w "$bit_width" "$temp"/output.bin "$output"
fi