Skip to content

Commit

Permalink
Merge pull request #677 from ucb-bar/smartelf2hex-fix
Browse files Browse the repository at this point in the history
Fix smartelf2hex.sh creating files 64x the minimum size
  • Loading branch information
jerryz123 authored Sep 23, 2020
2 parents ba05b32 + d5660c0 commit 023d809
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions scripts/smartelf2hex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ binary=$1
segments=`readelf --segments --wide $binary`
entry_hex=`echo -e "$segments" | grep "Entry point" | cut -f3 -d' ' | sed 's/0x//' | tr [:lower:] [:upper:]`
entry_dec=`bc <<< "ibase=16;$entry_hex"`
length_hex=`echo "$segments" | grep LOAD | tail -n 1 | tr -s [:space:] | cut -f4,6 -d' '`
length_hex=`echo "$segments" | grep "LOAD\|TLS" | tail -n 1 | tr -s [:space:] | cut -f4,6 -d' '`
length_dec=`echo $length_hex | tr -d x | tr [:lower:] [:upper:] | tr ' ' + | sed 's/^/ibase=16;/' | sed "s/$/-$entry_hex/" | bc`
power_2_length=`echo "x=l($length_dec)/l(2); scale=0; 2^((x+1)/1)" | bc -l`
elf2hex 64 $power_2_length $binary $entry_dec
width=64
depth=$((power_2_length / width))
elf2hex $width $depth $binary $entry_dec
2 changes: 1 addition & 1 deletion toolchains/esp-tools/riscv-isa-sim

0 comments on commit 023d809

Please sign in to comment.