Remove unnecessary bash-ism.
[buildrom.git] / buildrom-devel / bin / construct-rom.sh
blob00da4815ffaafa00b93dc0bcf3da117c25141dd9
1 #!/bin/sh -e
2 # Usage: ./construct-rom.sh [-p] components ...
4 DOPAD=0
6 if [ "$1" = "-p" ]; then
7 DOPAD=1
8 shift
9 fi
11 COMPONENTS=$*
13 if [ $DOPAD -eq 1 ]; then
15 ROMSIZE=0
17 # Get the size of all the components together
19 for c in $COMPONENTS; do
20 size=`du -b $c | cut -f1`
21 ROMSIZE=`expr $ROMSIZE + $size` || true
22 done
24 # Pad to a power of 2, starting with 128k
25 RSIZE=131072
27 while true; do
28 PAD=0
30 if [ $ROMSIZE -gt $RSIZE ]; then
31 RSIZE=`expr $RSIZE "*" 2`
32 continue
35 if [ $ROMSIZE -lt $RSIZE ]; then
36 PAD=`expr $RSIZE - $ROMSIZE`
39 break
40 done
42 PADFILE=`mktemp`
43 dd if=/dev/zero of=$PADFILE bs=1 count=$PAD > /dev/null 2>&1
44 COMPONENTS="$PADFILE $COMPONENTS"
47 cat $COMPONENTS
49 if [ $DOPAD -eq 1 ]; then
50 rm -rf $PADFILE