annotate sh/c1xx-analyze-image @ 30:2d60f9a3032b default tip

LICENSE: public domain, copied from freecalypso-tools
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 24 Jun 2023 04:24:38 +0000
parents 632d62e5efb4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #!/bin/sh
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 if [ $# != 1 ]
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 then
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 echo "usage: $0 flashdump.bin" 1>&2
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 exit 1
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 fi
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 if [ ! -f "$1" ]
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 then
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 echo "Error: $1 does not exist or is not a regular file" 1>&2
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 exit 1
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 fi
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 length=`wc -c $1 | cut -d ' ' -f 1`
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 case "$length" in
17
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
18 2097152)
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
19 echo 'Flash dump file size is 2 MiB'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
20 echo 'Is it a small-flash C11x/12x phone?'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
21 flash=2m
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
22 cal_offset=0x1FC000
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
23 ;;
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
24 4194304)
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
25 echo 'Flash dump file size is 4 MiB'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
26 echo 'Possible Compal phones: C11x/12x, C139/140, SE J100'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
27 flash=4m
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
28 cal_offset=0x3FC000
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
29 ;;
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
30 8388608)
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
31 echo 'Flash dump file size is 8 MiB'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
32 echo 'Is it a Motorola C155/156 phone?'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
33 flash=8m
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
34 cal_offset=0x7E0000
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
35 ;;
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
36 *)
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
37 echo "Error: file length of $1 is not understood" 1>&2
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
38 exit 1
2
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 esac
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 set -e
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 echo 'Parsing for RF calibration records'
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 c1xx-calextr -a rfasc -b rfbin "$1" $cal_offset
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if [ ! -d rfbin/rx -o ! -d rfbin/tx ]
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 then
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 echo "Error: no RF calibration records found" 1>&2
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 exit 1
12810ff4aa92 c1xx-analyze-image: initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 fi
17
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
51
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
52 case $flash in
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
53 2m|4m)
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
54 echo 'Analyzing bootloader'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
55 boot=`c139-analyze-boot "$1"`
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
56 case "$boot" in
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
57 unlocked)
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
58 echo 'Found original Compal bootloader, unlocked'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
59 echo 'Generating restore-flash script'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
60 echo "flash erase-program-boot $1 0x10000" > restore-flash
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
61 echo "flash e-program-bin 0x10000 $1 0x10000" >> restore-flash
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
62 ;;
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
63 locked)
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
64 echo 'Found original Compal bootloader, LOCKED!'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
65 u=unlocked-orig-fw.bin
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
66 echo "Generating unlocked version in $u"
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
67 cp "$1" $u
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
68 c139-patch-dmagic $u
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
69 echo 'Generating restore-flash script using this image'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
70 echo "flash erase-program-boot $u 0x10000" > restore-flash
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
71 echo "flash e-program-bin 0x10000 $u 0x10000" >> restore-flash
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
72 ;;
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
73 fc)
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
74 echo 'Found FreeCalypso C11x/12x/139/140 bootloader'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
75 echo 'It is a FreeCalypso C1xx flash image, not original,'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
76 echo 'hence not generating restore-flash script.'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
77 ;;
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
78 *)
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
79 echo 'Not found a good bootloader version - this flash image'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
80 echo 'is UNSAFE! If you proceed with flashing FreeCalypso,'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
81 echo 'you will not be able to restore the original fw without'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
82 echo 'bricking the phone! Recommendation: please reflash your'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
83 echo 'phone to a different, known-good official Motorola fw'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
84 echo 'version before venturing into FreeCalypso fw.'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
85 ;;
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
86 esac
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
87 ;;
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
88 8m)
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
89 echo 'Analyzing bootloader'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
90 boot=`c155-analyze-boot "$1"`
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
91 case "$boot" in
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
92 ok)
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
93 echo 'Found classic C155/156 bootloader, all good'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
94 echo 'Generating restore-flash script'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
95 echo "flash e-program-bin 0x20000 $1 0x20000" > restore-flash
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
96 ;;
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
97 *)
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
98 echo 'Not found a good bootloader version - this flash image'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
99 echo 'is UNSAFE! Please contact FreeCalypso and share your'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
100 echo 'flash image before taking any further action.'
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
101 ;;
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
102 esac
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
103 ;;
632d62e5efb4 c1xx-analyze-image: add bootloader analysis
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
104 esac