view sh/c1xx-analyze-image @ 25:afd760eb1f8d

doc/C1xx-updates: new article
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 11 Jun 2023 20:57:23 +0000
parents 632d62e5efb4
children
line wrap: on
line source

#!/bin/sh

if [ $# != 1 ]
then
	echo "usage: $0 flashdump.bin" 1>&2
	exit 1
fi

if [ ! -f "$1" ]
then
	echo "Error: $1 does not exist or is not a regular file" 1>&2
	exit 1
fi

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
esac

set -e

echo 'Parsing for RF calibration records'
c1xx-calextr -a rfasc -b rfbin "$1" $cal_offset

if [ ! -d rfbin/rx -o ! -d rfbin/tx ]
then
	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