scripts: fit-unpack: add hash verify

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I11982ee2e6fb09f5c0007334832d7decb6025756
This commit is contained in:
Joseph Chen 2020-04-23 19:53:56 +08:00
parent 1f21bf610b
commit 0fb435fa05
1 changed files with 34 additions and 3 deletions

View File

@ -52,10 +52,11 @@ function args_process()
function gen_images()
{
printf "\n## Unpack $file to directory $output/\n"
printf "\n# Unpack $file to directory $output/\n"
fdtget -l $file /images > $output/unpack.txt
cat $output/unpack.txt | while read line
do
# generate image
node="/images/${line}"
name=`fdtget -ts $file $node image`
offs=`fdtget -ti $file $node data-position`
@ -64,7 +65,6 @@ function gen_images()
continue;
fi
printf " %-15s: %d bytes\n" ${name} $size
if [ $size -ne 0 ]; then
dd if=$file of=$output/dd.tmp bs=$offs skip=1 >/dev/null 2>&1
dd if=$output/dd.tmp of=$output/$name bs=$size count=1 >/dev/null 2>&1
@ -72,6 +72,36 @@ function gen_images()
else
touch $output/$name
fi
# hash verify
algo=`fdtget -ts $file $node/hash@1 algo`
if [ -z $algo ]; then
printf " %-20s: %d bytes" $name $size
continue;
fi
data=`fdtget -tx $file $node/hash@1 value`
data=`echo " "$data | sed "s/ / 0x/g"`
csum=`"$algo"sum $output/$name | awk '{ print $1}'`
hash=""
for((i=1;;i++));
do
hex=`echo $data | awk -v idx=$i '{ print $idx }'`
if [ -z $hex ]; then
break;
fi
hex=`printf "%08x" $hex` # align !!
hash="$hash$hex"
done
printf " %-20s: %d bytes... %s" $name $size $algo
if [ "$csum" = "$hash" -o $size -eq 0 ]; then
echo "+"
else
echo "-"
fi
done
rm $output/unpack.txt
@ -80,3 +110,4 @@ function gen_images()
args_process $*
gen_images