diff sh/c1xx-analyze-image @ 17:632d62e5efb4

c1xx-analyze-image: add bootloader analysis
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 10 Jun 2023 06:24:15 +0000
parents 12810ff4aa92
children
line wrap: on
line diff
--- a/sh/c1xx-analyze-image	Sat Jun 10 05:49:00 2023 +0000
+++ b/sh/c1xx-analyze-image	Sat Jun 10 06:24:15 2023 +0000
@@ -15,27 +15,27 @@
 length=`wc -c $1 | cut -d ' ' -f 1`
 
 case "$length" in
-	2097152)
-		echo 'Flash dump file size is 2 MiB'
-		echo 'Is it a small-flash C11x/12x phone?'
-		flash=2m
-		cal_offset=0x1FC000
-		;;
-	4194304)
-		echo 'Flash dump file size is 4 MiB'
-		echo 'Possible Compal phones: C11x/12x, C139/140, SE J100'
-		flash=4m
-		cal_offset=0x3FC000
-		;;
-	8388608)
-		echo 'Flash dump file size is 8 MiB'
-		echo 'Is it a Motorola C155/156 phone?'
-		flash=8m
-		cal_offset=0x7E0000
-		;;
-	*)
-		echo "Error: file length of $1 is not understood" 1>&2
-		exit 1
+  2097152)
+	echo 'Flash dump file size is 2 MiB'
+	echo 'Is it a small-flash C11x/12x phone?'
+	flash=2m
+	cal_offset=0x1FC000
+	;;
+  4194304)
+	echo 'Flash dump file size is 4 MiB'
+	echo 'Possible Compal phones: C11x/12x, C139/140, SE J100'
+	flash=4m
+	cal_offset=0x3FC000
+	;;
+  8388608)
+	echo 'Flash dump file size is 8 MiB'
+	echo 'Is it a Motorola C155/156 phone?'
+	flash=8m
+	cal_offset=0x7E0000
+	;;
+  *)
+	echo "Error: file length of $1 is not understood" 1>&2
+	exit 1
 esac
 
 set -e
@@ -48,3 +48,57 @@
 	echo "Error: no RF calibration records found" 1>&2
 	exit 1
 fi
+
+case $flash in
+  2m|4m)
+	echo 'Analyzing bootloader'
+	boot=`c139-analyze-boot "$1"`
+	case "$boot" in
+	  unlocked)
+		echo 'Found original Compal bootloader, unlocked'
+		echo 'Generating restore-flash script'
+		echo "flash erase-program-boot $1 0x10000" > restore-flash
+		echo "flash e-program-bin 0x10000 $1 0x10000" >> restore-flash
+		;;
+	  locked)
+		echo 'Found original Compal bootloader, LOCKED!'
+		u=unlocked-orig-fw.bin
+		echo "Generating unlocked version in $u"
+		cp "$1" $u
+		c139-patch-dmagic $u
+		echo 'Generating restore-flash script using this image'
+		echo "flash erase-program-boot $u 0x10000" > restore-flash
+		echo "flash e-program-bin 0x10000 $u 0x10000" >> restore-flash
+		;;
+	  fc)
+		echo 'Found FreeCalypso C11x/12x/139/140 bootloader'
+		echo 'It is a FreeCalypso C1xx flash image, not original,'
+		echo 'hence not generating restore-flash script.'
+		;;
+	  *)
+		echo 'Not found a good bootloader version - this flash image'
+		echo 'is UNSAFE! If you proceed with flashing FreeCalypso,'
+		echo 'you will not be able to restore the original fw without'
+		echo 'bricking the phone! Recommendation: please reflash your'
+		echo 'phone to a different, known-good official Motorola fw'
+		echo 'version before venturing into FreeCalypso fw.'
+		;;
+	esac
+	;;
+  8m)
+	echo 'Analyzing bootloader'
+	boot=`c155-analyze-boot "$1"`
+	case "$boot" in
+	  ok)
+		echo 'Found classic C155/156 bootloader, all good'
+		echo 'Generating restore-flash script'
+		echo "flash e-program-bin 0x20000 $1 0x20000" > restore-flash
+		;;
+	  *)
+		echo 'Not found a good bootloader version - this flash image'
+		echo 'is UNSAFE! Please contact FreeCalypso and share your'
+		echo 'flash image before taking any further action.'
+		;;
+	esac
+	;;
+esac