summaryrefslogtreecommitdiff
path: root/utils/ypr0tools/patch-firmware.sh
blob: 879b3f879de9436096dbc256e115175a8c46395c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh


######################################################################
#             __________               __   ___.
#   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
#   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
#   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
#   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
#                     \/            \/     \/    \/            \/
#
#   * Script to patch an unpacked Samsung YP-R0 firmware file */
#   Copyright (C) 2011 Thomas Martitz
######################################################################
# bail out early
set -e

if [ $# -lt 1 ] || [ $# -gt 2 ]; then
    echo "Usage: $0 <files path> [path to unpacked rom]"
    echo "\t<files path> is expected to have a rootfs layout and to contain"
    echo "\tonly the files to overwrite (plain cp -r is used)"
    exit 1
fi

FILES=${1%/}
FILES=${FILES:-"/"}
DIR=${2:-"."}
DIR=${DIR%/}
ROOTFS=$DIR/rootfs
CRAMFS=$DIR/cramfs-fsl.rom

# sanity checks

# this needs to be run as root!
if [ $(whoami) != "root" ]
then
  echo "This needs to be run as root"
  exit 1
fi

if [ ! -e $1 ] || [ ! -e $2 ]; then
    echo "$1 or $2 does not exist"
    exit 1
fi

if [ -z $ROOTFS ] || [ -z $FILES ]; then
    echo "Invalid input directories"
    exit 1
fi

if [ ! -e $CRAMFS ]; then
    echo "Cramfs image not found (did you extract the firmware?)"
    exit 1
fi

echo "Extracting cramfs image"

[ ! -e $ROOTFS ] || rmdir -p $ROOTFS
cramfs-1.1/cramfsck -x $ROOTFS $CRAMFS

echo "Patching rootfs"
echo "cp -r $FILES/* $ROOTFS/"
cp -r $FILES/.rockbox $ROOTFS/
cp -r $FILES/* $ROOTFS/

echo "Packing new cramfs image"
cramfs-1.1/mkcramfs $ROOTFS $CRAMFS