From 0fb435fa051047f1ecd4293f97f5ebcb139ebd9a Mon Sep 17 00:00:00 2001 From: Joseph Chen Date: Thu, 23 Apr 2020 19:53:56 +0800 Subject: [PATCH] scripts: fit-unpack: add hash verify Signed-off-by: Joseph Chen Change-Id: I11982ee2e6fb09f5c0007334832d7decb6025756 --- scripts/fit-unpack.sh | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/scripts/fit-unpack.sh b/scripts/fit-unpack.sh index cfef5a98ad..2fb7ba5eb4 100755 --- a/scripts/fit-unpack.sh +++ b/scripts/fit-unpack.sh @@ -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 @@ -79,4 +109,5 @@ function gen_images() } args_process $* -gen_images \ No newline at end of file +gen_images +