summaryrefslogtreecommitdiffstats
path: root/utils/ypr0tools/test.sh
blob: 3c891e6e7ff5a1d04b942647f8f733b0b1268f74 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh

######################################################################
#             __________               __   ___.
#   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
#   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
#   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
#   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
#                     \/            \/     \/    \/            \/
#
#   Script to test packer and unpacker
#   Copyright (C) 2013 Lorenzo Miori
######################################################################

ROM_FILE="$1"
TMP_FOLDER=""

goto_temp()
{
    if [ -n "$TMP_FOLDER" ]
    then
        cd $TMP_FOLDER
    fi
}

cleanup()
{
    echo "$1"
    OLD_DIR=`pwd`
    goto_temp
    rm -f "$ROM_FILE"_TEST_CRYPT "MBoot.bin" "zImage" "cramfs-fsl.rom" "SYSDATA.bin" "TEST_MD5SUMS" "RevisionInfo.txt" > /dev/null
    cd $OLD_DIR
    if [ -n "$TMP_FOLDER" ]
    then
        rmdir $TMP_FOLDER
    fi
    make clean
    exit $2
}

if [ $# -lt 1 ]
then
    cleanup "FAIL: Missing parameter! Run with: test.sh <path to working rom to test> <optional: destination to temporary files>" 1
fi

if [ $# -eq 2 ]
then
    TMP_FOLDER="$2/"
    mkdir $TMP_FOLDER
    if [ $? -ne 0 ]
    then
        echo "FAIL: temporary directory exists!"
    fi
fi

# be sure we have the executables up-to-date
make clean
make

./fwdecrypt $1 $TMP_FOLDER
if [ $? -ne 0 ]
then
    cleanup "FAIL: Error while decrypting ROM file" 1
fi

./fwcrypt $TMP_FOLDER$1_TEST_CRYPT $TMP_FOLDER
if [ $? -ne 0 ]
then
    cleanup "FAIL: Error while decrypting ROM file" 1
fi

OLD_DIR=`pwd`
goto_temp

md5sum MBoot.bin zImage cramfs-fsl.rom SYSDATA.bin RevisionInfo.txt > "TEST_MD5SUMS"

md5sum --strict -c "TEST_MD5SUMS"
if [ $? -ne 0 ]
then
    cleanup "FAIL: MD5SUM mismatch!" 1
fi

cd $OLD_DIR

cleanup "OK: test completed without errors." 0