Thomas Martitz | 249bba0 | 2011-12-24 11:56:46 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | ###################################################################### |
| 4 | # __________ __ ___. |
| 5 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 6 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 7 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 8 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 9 | # \/ \/ \/ \/ \/ |
| 10 | # |
| 11 | # * Script to unpack a Samsung YP-R0 firmware file (R0.ROM) */ |
| 12 | ###################################################################### |
| 13 | |
| 14 | # The file was originally called MuonDecrypt.sh |
| 15 | # |
| 16 | # I'm not sure about the original author of this file, as it wasn't included in Samsung package. |
| 17 | # But I guess it was done by JeanLouis, an Italian user of the Hardware Upgrade Forum. If needed, we should search throug old posts for that... |
| 18 | # |
| 19 | |
| 20 | |
| 21 | # bail out early |
| 22 | set -e |
| 23 | |
| 24 | # some sanity checks |
| 25 | if [ $# -lt 1 ] || [ $# -gt 2 ]; then |
| 26 | echo "Usage $0 <rom file> [out dir]" |
| 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | |
| 31 | ROM=$1 |
| 32 | DIR=${2:-"."} |
| 33 | DIR=${DIR%/} |
| 34 | MBOOT="$DIR/MBoot.bin" |
| 35 | MBOOT_TMP="${TMP_DIR:-$DIR}/MBoot.tmp" |
| 36 | LINUX="$DIR/zImage" |
| 37 | CRAMFS="$DIR/cramfs-fsl.rom" |
| 38 | SYSDATA="$DIR/SYSDATA.bin" |
| 39 | MD5SUMS="$DIR/MD5SUMS" |
| 40 | TMP="${TMP_DIR:-$DIR}/_$$.tmp" |
| 41 | |
| 42 | |
| 43 | if [ ! -f ./extract_section ]; then |
| 44 | echo "Couldn't find extract_section binary (try 'make')" |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | if [ ! -f ./MuonEncrypt ]; then |
| 49 | echo "Couldn't find MuonEncrypt binary (try 'make')" |
| 50 | exit 1 |
| 51 | fi |
| 52 | |
| 53 | mkdir -p $DIR |
| 54 | |
| 55 | if [ ! -w $DIR ]; then |
| 56 | echo "Target dir not writable" |
| 57 | exit 1 |
| 58 | fi |
| 59 | |
| 60 | ExtractAndDecrypt() { |
| 61 | START=$(expr $START - $2) |
| 62 | echo "Extracting $1..." |
| 63 | ./extract_section $ROM $TMP $START $2 |
| 64 | echo "Decrypt $1..." |
| 65 | ./MuonEncrypt $TMP > $1 |
| 66 | } |
| 67 | |
| 68 | size=( `head -n 9 $ROM | tail -n 4 | while read LINE; do echo $LINE | cut -d\( -f 2 | cut -d\) -f 1; done`) |
| 69 | checksum=( `head -n 9 $ROM | tail -n 4 | while read LINE; do echo $LINE | cut -d\( -f 3 | cut -d\) -f 1; done`) |
| 70 | |
| 71 | echo "${checksum[0]} $MBOOT" > $MD5SUMS |
| 72 | echo "${checksum[1]} $LINUX" >> $MD5SUMS |
| 73 | echo "${checksum[2]} $CRAMFS" >> $MD5SUMS |
| 74 | echo "${checksum[3]} $SYSDATA" >> $MD5SUMS |
| 75 | |
| 76 | START=`stat -c%s $ROM` |
| 77 | |
| 78 | ExtractAndDecrypt $SYSDATA ${size[3]} |
| 79 | ExtractAndDecrypt $CRAMFS ${size[2]} |
| 80 | ExtractAndDecrypt $LINUX ${size[1]} |
| 81 | ExtractAndDecrypt $MBOOT_TMP ${size[0]} |
| 82 | |
| 83 | rm $TMP |
| 84 | echo "Create $MBOOT..." |
| 85 | dd if=$MBOOT_TMP of=$MBOOT bs=96 count=1 2>/dev/null |
| 86 | dd if=$MBOOT_TMP of=$MBOOT bs=1088 skip=1 seek=1 2>/dev/null |
| 87 | rm $MBOOT_TMP |
| 88 | |
| 89 | echo "Check integrity:" |
| 90 | md5sum -c $MD5SUMS |