blob: ab80670c79d577ef25cc1db10beb00a47604e958 [file] [log] [blame]
Thomas Martitz249bba02011-12-24 11:56:46 +00001#!/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
22set -e
23
24# some sanity checks
25if [ $# -lt 1 ] || [ $# -gt 2 ]; then
26 echo "Usage $0 <rom file> [out dir]"
27 exit 1
28fi
29
30
31ROM=$1
32DIR=${2:-"."}
33DIR=${DIR%/}
34MBOOT="$DIR/MBoot.bin"
35MBOOT_TMP="${TMP_DIR:-$DIR}/MBoot.tmp"
36LINUX="$DIR/zImage"
37CRAMFS="$DIR/cramfs-fsl.rom"
38SYSDATA="$DIR/SYSDATA.bin"
39MD5SUMS="$DIR/MD5SUMS"
40TMP="${TMP_DIR:-$DIR}/_$$.tmp"
41
42
43if [ ! -f ./extract_section ]; then
44 echo "Couldn't find extract_section binary (try 'make')"
45 exit 1
46fi
47
48if [ ! -f ./MuonEncrypt ]; then
49 echo "Couldn't find MuonEncrypt binary (try 'make')"
50 exit 1
51fi
52
53mkdir -p $DIR
54
55if [ ! -w $DIR ]; then
56 echo "Target dir not writable"
57 exit 1
58fi
59
60ExtractAndDecrypt() {
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
68size=( `head -n 9 $ROM | tail -n 4 | while read LINE; do echo $LINE | cut -d\( -f 2 | cut -d\) -f 1; done`)
69checksum=( `head -n 9 $ROM | tail -n 4 | while read LINE; do echo $LINE | cut -d\( -f 3 | cut -d\) -f 1; done`)
70
71echo "${checksum[0]} $MBOOT" > $MD5SUMS
72echo "${checksum[1]} $LINUX" >> $MD5SUMS
73echo "${checksum[2]} $CRAMFS" >> $MD5SUMS
74echo "${checksum[3]} $SYSDATA" >> $MD5SUMS
75
76START=`stat -c%s $ROM`
77
78ExtractAndDecrypt $SYSDATA ${size[3]}
79ExtractAndDecrypt $CRAMFS ${size[2]}
80ExtractAndDecrypt $LINUX ${size[1]}
81ExtractAndDecrypt $MBOOT_TMP ${size[0]}
82
83rm $TMP
84echo "Create $MBOOT..."
85dd if=$MBOOT_TMP of=$MBOOT bs=96 count=1 2>/dev/null
86dd if=$MBOOT_TMP of=$MBOOT bs=1088 skip=1 seek=1 2>/dev/null
87rm $MBOOT_TMP
88
89echo "Check integrity:"
90md5sum -c $MD5SUMS