summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/ypr0tools/Makefile47
-rw-r--r--utils/ypr0tools/cable_detect.c63
-rw-r--r--utils/ypr0tools/files/common/.rockbox/README (renamed from utils/ypr0tools/files/.rockbox/README)0
-rw-r--r--utils/ypr0tools/files/common/Playlists/README (renamed from utils/ypr0tools/files/Playlists/README)0
-rwxr-xr-xutils/ypr0tools/files/common/etc/profile (renamed from utils/ypr0tools/files/etc/profile)22
-rwxr-xr-xutils/ypr0tools/files/common/etc/safemode/smode250
-rwxr-xr-xutils/ypr0tools/files/etc/mods/safe_mode.sh111
-rw-r--r--utils/ypr0tools/files/images/r0/post_smode.bmpbin0 -> 230456 bytes
-rw-r--r--utils/ypr0tools/files/images/r0/pre_smode.bmpbin0 -> 230456 bytes
-rw-r--r--utils/ypr0tools/files/images/r0/safemode.bmp (renamed from utils/ypr0tools/files/etc/mods/safe_mode.raw)bin230400 -> 230456 bytes
-rw-r--r--utils/ypr0tools/files/images/r1/post_smode.bmpbin0 -> 288056 bytes
-rw-r--r--utils/ypr0tools/files/images/r1/pre_smode.bmpbin0 -> 288056 bytes
-rw-r--r--utils/ypr0tools/files/images/r1/safemode.bmpbin0 -> 288056 bytes
-rwxr-xr-xutils/ypr0tools/files/r0/lib/modules/si4709.ko (renamed from utils/ypr0tools/files/lib/modules/si4709.ko)bin129816 -> 129816 bytes
-rwxr-xr-xutils/ypr0tools/patch-firmware.sh65
15 files changed, 412 insertions, 146 deletions
diff --git a/utils/ypr0tools/Makefile b/utils/ypr0tools/Makefile
index 3efdc61443..d4715bdca8 100644
--- a/utils/ypr0tools/Makefile
+++ b/utils/ypr0tools/Makefile
@@ -1,20 +1,41 @@
1DEFINES= 1.PHONY: all clean dirs bmp2rb
2CC=gcc 2CFLAGS += -O1 -g -std=c99 -W -Wall $(DEFINES)
3LD=gcc 3PROGS = bmp2rb fwcrypt fwdecrypt
4CFLAGS=-g -std=c99 -W -Wall $(DEFINES) 4CROSS_COMPILE = arm-ypr0-linux-gnueabi-
5LDFLAGS= 5R1_SAFEMODE_DIR = files/r1/etc/safemode
6BINS=fwcrypt fwdecrypt 6R0_SAFEMODE_DIR = files/r0/etc/safemode
7DIRS = $(R1_SAFEMODE_DIR) $(R0_SAFEMODE_DIR)
8R1_IMAGES = $(subst .bmp,.raw,$(addprefix $(R1_SAFEMODE_DIR)/,$(notdir $(wildcard files/images/r1/*.bmp))))
9R0_IMAGES = $(subst .bmp,.raw,$(addprefix $(R0_SAFEMODE_DIR)/,$(notdir $(wildcard files/images/r0/*.bmp))))
10BMP2RB = ../../tools/bmp2rb
7 11
8all: $(BINS) 12all: $(R1_SAFEMODE_DIR)/cable_detect $(PROGS) $(R1_IMAGES) $(R0_IMAGES)
9 13 $(MAKE) -C cramfs-1.1
10%.o: %.c
11 $(CC) $(CFLAGS) -c -o $@ $<
12 14
13fwdecrypt: fwdecrypt.o common.o ../../tools/fwpatcher/md5.o 15fwdecrypt: fwdecrypt.o common.o ../../tools/fwpatcher/md5.o
14 $(LD) -o $@ $^ $(LDFLAGS)
15 16
16fwcrypt: fwcrypt.o common.o ../../tools/fwpatcher/md5.o 17fwcrypt: fwcrypt.o common.o ../../tools/fwpatcher/md5.o
17 $(LD) -o $@ $^ $(LDFLAGS) 18
19$(BMP2RB):
20 $(MAKE) -C ../../tools/ bmp2rb
21
22$(R1_SAFEMODE_DIR)/cable_detect: cable_detect.c $(R1_SAFEMODE_DIR)
23 $(CROSS_COMPILE)$(CC) $(CFLAGS) $< -o $@
24
25$(R1_SAFEMODE_DIR)/%.raw: files/images/r1/%.bmp $(BMP2RB) $(R1_SAFEMODE_DIR)
26 $(BMP2RB) -r -f 9 $< > $@
27
28$(R0_SAFEMODE_DIR)/%.raw: files/images/r0/%.bmp $(BMP2RB) $(R0_SAFEMODE_DIR)
29 $(BMP2RB) -r -f 9 $< > $@
30
31$(DIRS):
32 $(SILENT)mkdir -p $@
33
34dirs: $(DIRS)
35
36bmp2rb: $(BMP2RB)
18 37
19clean: 38clean:
20 rm -fr *.o $(BINS) 39 $(MAKE) -C cramfs-1.1 clean
40 rm -f *.o fwdecrypt fwcrypt
41 rm -rf $(R1_SAFEMODE_DIR)/../../etc $(R0_SAFEMODE_DIR)/../../etc
diff --git a/utils/ypr0tools/cable_detect.c b/utils/ypr0tools/cable_detect.c
new file mode 100644
index 0000000000..57679d4b79
--- /dev/null
+++ b/utils/ypr0tools/cable_detect.c
@@ -0,0 +1,63 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Samsung YP-R1 runtime USB cable detection
10 *
11 * Copyright (C) 2013 Lorenzo Miori
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22
23#include <sys/ioctl.h>
24#include <fcntl.h>
25#include <unistd.h>
26
27#define IOCTL_PMU_MAGIC 'A'
28
29#define E_IOCTL_PMU_GET_BATT_LVL 0
30#define E_IOCTL_PMU_GET_CHG_STATUS 1
31#define E_IOCTL_PMU_IS_EXT_PWR 2
32#define E_IOCTL_PMU_STOP_CHG 3
33#define E_IOCTL_PMU_START_CHG 4
34#define E_IOCTL_PMU_IS_EXT_PWR_OVP 5
35#define E_IOCTL_PMU_LCD_DIM_CTRL 6
36#define E_IOCTL_PMU_CORE_CTL_HIGH 7
37#define E_IOCTL_PMU_CORE_CTL_LOW 8
38#define E_IOCTL_PMU_TSP_USB_PWR_OFF 9
39
40#define IOCTL_PMU_GET_BATT_LVL _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_GET_BATT_LVL)
41#define IOCTL_PMU_GET_CHG_STATUS _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_GET_CHG_STATUS)
42#define IOCTL_PMU_IS_EXT_PWR _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_IS_EXT_PWR)
43#define IOCTL_PMU_STOP_CHG _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_STOP_CHG)
44#define IOCTL_PMU_START_CHG _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_START_CHG)
45#define IOCTL_PMU_IS_EXT_PWR_OVP _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_IS_EXT_PWR_OVP)
46#define IOCTL_PMU_LCD_DIM_CTRL _IOW(IOCTL_PMU_MAGIC, E_IOCTL_PMU_LCD_DIM_CTRL, int)
47#define IOCTL_PMU_CORE_CTL_HIGH _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_CORE_CTL_HIGH)
48#define IOCTL_PMU_CORE_CTL_LOW _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_CORE_CTL_LOW)
49#define IOCTL_PMU_TSP_USB_PWR_OFF _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_TSP_USB_PWR_OFF)
50
51/*
52 * This is a very simple program that runs on device.
53 * It returns error code either 0 when (power/usb) cable
54 * is not connected or >= 1 if connected.
55 */
56int main(void)
57{
58 int state = -1;
59 int dev = open("/dev/r1Pmu", O_RDONLY);
60 state = ioctl(dev, IOCTL_PMU_IS_EXT_PWR);
61 close(dev);
62 return state;
63}
diff --git a/utils/ypr0tools/files/.rockbox/README b/utils/ypr0tools/files/common/.rockbox/README
index f0e306e196..f0e306e196 100644
--- a/utils/ypr0tools/files/.rockbox/README
+++ b/utils/ypr0tools/files/common/.rockbox/README
diff --git a/utils/ypr0tools/files/Playlists/README b/utils/ypr0tools/files/common/Playlists/README
index f0e306e196..f0e306e196 100644
--- a/utils/ypr0tools/files/Playlists/README
+++ b/utils/ypr0tools/files/common/Playlists/README
diff --git a/utils/ypr0tools/files/etc/profile b/utils/ypr0tools/files/common/etc/profile
index 9fa1505544..5a51167ac1 100755
--- a/utils/ypr0tools/files/etc/profile
+++ b/utils/ypr0tools/files/common/etc/profile
@@ -15,8 +15,8 @@ hwclock -s
15alias ls='ls --color=auto' 15alias ls='ls --color=auto'
16alias ll='ls -l --color=auto' 16alias ll='ls -l --color=auto'
17 17
18# Start with lorenzo92's safe mode 18# Start with safe mode
19SCRIPT="/etc/mods/safe_mode.sh" 19SCRIPT="/etc/safemode/smode"
20if [ -f $SCRIPT ] 20if [ -f $SCRIPT ]
21then 21then
22 /bin/sh $SCRIPT 22 /bin/sh $SCRIPT
@@ -29,24 +29,16 @@ then
29 fi 29 fi
30fi 30fi
31 31
32if [ -e "/mnt/media1/r0" ] 32# Ironically, r1's ROM contains a lot of r0's executables, including the main one.
33# So we need to check against r1 before!
34if [ -e "/usr/local/bin/r1" ]
33then 35then
34 MAINFILE="/mnt/media1/r0" 36 MAINFILE="/usr/local/bin/r1"
35elif [ -f "/mnt/media0/r0" ]
36then
37 # copy to media1 since USB wouldn't work
38 cp /mnt/media0/r0 /mnt/media1/r0_media0
39 if [ "$?" = "0" ]
40 then # perhaps cp failed due to insufficient storage or so
41 MAINFILE="/mnt/media1/r0_media0"
42 else
43 MAINFILE="/usr/local/bin/r0"
44 fi
45else 37else
46 MAINFILE="/usr/local/bin/r0" 38 MAINFILE="/usr/local/bin/r0"
47fi 39fi
48 40
49# Parameters for r0 41# Parameters for the application
50MAINFILE_ARGV="Application AppMain" 42MAINFILE_ARGV="Application AppMain"
51 43
52# source the rockbox loader script 44# source the rockbox loader script
diff --git a/utils/ypr0tools/files/common/etc/safemode/smode b/utils/ypr0tools/files/common/etc/safemode/smode
new file mode 100755
index 0000000000..f94d09a26d
--- /dev/null
+++ b/utils/ypr0tools/files/common/etc/safemode/smode
@@ -0,0 +1,250 @@
1#!/bin/sh
2
3######################################################################
4# __________ __ ___.
5# Open \______ \ ____ ____ | | _\_ |__ _______ ___
6# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
7# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
8# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9# \/ \/ \/ \/ \/
10#
11# * Safe Mode for Samsung YP-R0 / YP-R1 *
12# * Copyright (C) 2013 Lorenzo Miori and VanniX
13######################################################################
14
15# 0 = R0 ; 1 = R1
16PLATFORM=0
17BUTTON_DEVICE="/dev/r0Btn"
18PMK=$(echo -e -n "\x01") # same for both devices
19STORAGES="/dev/stl3,/dev/stl2,/dev/mmcblk0"
20
21MODE="normal"
22
23if [ $# -eq 1 ]
24then
25 MODE=$1
26fi
27
28# rather simple but effective check
29# different key codes to trigger safe mode
30if [ -e "/usr/local/bin/r1" ]
31then
32 # running on YP-R1 model
33 BACK=$(echo -e -n "\x02")
34 PLATFORM=1
35 BUTTON_DEVICE="/dev/r1Button"
36 STORAGES="/dev/stl3,/dev/stl2"
37else
38 BACK=$(echo -e -n "\x08")
39 PLATFORM=0
40 BUTTON_DEVICE="/dev/r0Btn"
41 STORAGES="/dev/stl3,/dev/stl2,/dev/mmcblk0"
42fi
43
44power_pressed()
45{
46 VAR=$(dd if=$BUTTON_DEVICE bs=4 count=1)
47 [[ "$VAR" = "$PMK" ]]
48 return $?
49}
50
51cable_disconnected()
52{
53 if [ $PLATFORM -eq 0 ]
54 then
55 /usr/local/bin/minird 0x0a | grep -q 0x00
56 return $?
57 else
58 /etc/safemode/cable_detect
59 return $?
60 fi
61}
62
63enable_display()
64{
65 echo -n "0" > /sys/devices/platform/afe.0/bli
66 echo -n "1" > /sys/class/graphics/fb0/blank
67 echo -n "0" >> /sys/class/graphics/fb0/blank
68 echo -n "1" > /sys/devices/platform/afe.0/bli
69}
70
71display_image()
72{
73 cat $1 > "/dev/fb0"
74}
75
76if [ $MODE != "forced" ]
77then
78 KEY=$(dd if=$BUTTON_DEVICE bs=4 count=1)
79 if [[ "$KEY" != "$BACK" ]]; then
80 # do not enter safe mode and continue normal boot
81 exit 0
82 fi
83fi
84
85# Here we entered safe mode, so first clean the display
86# and turn on backlight at minimum level
87enable_display
88
89# there are different ROMs around...
90if [ -e "/etc/safemode/safemode.raw" ]
91then
92 DefIMG="/etc/safemode/safemode.raw"
93else
94 DefIMG="/etc/mods/safe_mode.raw"
95fi
96RbtIMG="/etc/safemode/post_smode.raw"
97PreIMG="/etc/safemode/pre_smode.raw"
98
99NOUSB=true
100
101if cable_disconnected
102then
103
104 display_image $PreIMG
105
106 while $NOUSB
107 do
108
109 # User aborts safe mode before mounting anything, just exit
110 # and continue normal boot
111 if power_pressed
112 then
113 sleep 1
114 if power_pressed
115 then
116 exit 1
117 fi
118 fi
119
120 if cable_disconnected
121 then
122 echo "USB not connected - Waiting"
123 else
124 sleep 1
125 if cable_disconnected
126 then
127 echo "USB first check OK - Waiting"
128 else
129 sleep 1
130 if cable_disconnected
131 then
132 echo "USB second check OK - Waiting"
133 else
134 NOUSB=false
135 USB=true
136 fi
137 fi
138 fi
139 done
140else
141 while $NOUSB
142 do
143 if cable_disconnected
144 then
145 echo "USB not connected - Waiting"
146 else
147 sleep 1
148 if cable_disconnected
149 then
150 echo "USB first check OK - Waiting"
151 else
152 NOUSB=false
153 USB=true
154 fi
155 fi
156 done
157fi
158
159display_image $DefIMG
160
161echo "Enabling usb storage..."
162lsmod | grep g_file_storage
163if [ $? == 0 ]
164then
165 umount /mnt/media1/dev/gadget
166fi
167
168umount /mnt/media1
169umount /mnt/media0
170
171lsmod | grep rfs
172if [ $? == 0 ]
173then
174 rmmod rfs
175fi
176
177lsmod | grep g_file_storage
178if [ $? == 0 ]
179then
180 rmmod gadgetfs
181 rmmod g_file_storage
182 rmmod arcotg_udc
183fi
184
185lsmod | grep g_serial
186if [ $? == 0 ]
187then
188 rmmod g_serial
189fi
190
191lsmod | grep g_file_storage
192if [ $? != 0 ]
193then
194 modprobe g-file-storage file=$STORAGES removable=1
195fi
196
197SAFE=true
198while $SAFE
199do
200 if power_pressed
201 then
202 sleep 1
203 if power_pressed
204 then
205 SAFE=false
206 fi
207 fi
208done
209
210echo "Removing loaded modules..."
211rmmod g_file_storage
212rmmod arcotg_udc
213
214display_image $RbtIMG
215
216USB=true
217
218while $USB
219do
220 if cable_disconnected
221 then
222 sleep 1
223 if cable_disconnected
224 then
225 if cable_disconnected
226 then
227 sleep 1
228 if cable_disconnected
229 then
230 USB=false
231 else
232 echo "USB connected - Waiting"
233 USB=true
234 fi
235 else
236 echo "USB connected - Waiting"
237 USB=true
238 fi
239 else
240 echo "USB connected - Waiting"
241 USB=true
242 fi
243 else
244 echo "USB connected - Waiting"
245 USB=true
246 fi
247done
248
249#power key pressed for almost 2 sec and cable disconnected. Power off!
250exit 1
diff --git a/utils/ypr0tools/files/etc/mods/safe_mode.sh b/utils/ypr0tools/files/etc/mods/safe_mode.sh
deleted file mode 100755
index 122b2eabfe..0000000000
--- a/utils/ypr0tools/files/etc/mods/safe_mode.sh
+++ /dev/null
@@ -1,111 +0,0 @@
1#!/bin/sh
2
3# YP-R0 Safe Mode!!
4# - Part of the "Device Rescue Kit", modded ROM v2.20 and onwards
5# Version: v0.3
6# v0.2 - initial version
7# v0.3 - USB cable check implemented
8# by lorenzo92 aka Memory
9# memoryS60@gmail.com
10
11CustomIMG="/mnt/media1/safe_mode.raw"
12DefIMG="/etc/mods/safe_mode.raw"
13
14timer=0
15# Seconds before turning the device OFF
16timeout=2
17
18shutdown () {
19 sync
20 reboot
21}
22
23cableDaemon () {
24 cd /usr/local/bin
25 while [ 1 ]
26 do
27 if [ $timer -gt $timeout ]
28 then
29 shutdown
30 fi
31
32 if ./minird 0x0a | grep -q 0x00
33 then
34 timer=$(($timer+1))
35 else
36 timer=0
37 fi
38 sleep 1
39 done
40}
41
42# Back button is a \x08\x00\x00\x00 string...
43# ...since bash removes null bytes for us, we must only care the single byte
44var=$(dd if=/dev/r0Btn bs=4 count=1)
45# Here a workaround to detect \x08 byte :S
46var2=$(echo -e -n "\x08")
47if [[ "$var" = "$var2" ]]
48then
49 echo "Safe mode (USB) activated..."
50 # Put the backlight at the minimum level: no energy waste, please ;)
51 # Using low level interface
52
53 cd /usr/local/bin
54 ./afewr 0x1b 0x3 0x8
55
56 # Long press reset time 5 secs
57 [ -e /etc/mods/reset_time_mod.sh ] && /bin/sh /etc/mods/reset_time_mod.sh
58
59 # Clear the screen and show a nice picture :D
60
61 echo -n "1" > /sys/class/graphics/fb0/blank
62 echo -n "0" >> /sys/class/graphics/fb0/blank
63# echo -n "1" > /sys/class/graphics/fb2/blank
64# echo -n "0" >> /sys/class/graphics/fb2/blank
65 if [ -e $CustomIMG ]
66 then
67 cat $CustomIMG > "/dev/fb0"
68 else
69 cat $DefIMG > "/dev/fb0"
70 fi
71
72 # Here the real USB connection stuff
73 # This is slightly modified by me; it was contained in the cramfs shipped with
74 # YP-R0 opensource package...
75
76 lsmod | grep g_file_storage
77 if [ $? == 0 ]
78 then
79 umount /mnt/media1/dev/gadget
80 fi
81 #if [ -d /mnt/media0 ]
82 #then
83 umount /mnt/media1
84 umount /mnt/media0
85 #umount /mnt/mmc
86 #fi
87 lsmod | grep rfs
88 if [ $? == 0 ]
89 then
90 rmmod rfs
91 fi
92 lsmod | grep g_file_storage
93 if [ $? == 0 ]
94 then
95 rmmod gadgetfs
96 rmmod g_file_storage
97 rmmod arcotg_udc
98 fi
99 lsmod | grep g_file_storage
100 if [ $? != 0 ]
101 then
102 modprobe g-file-storage file=/dev/stl3,/dev/stl2,/dev/mmcblk0 removable=1
103 fi
104
105 # Let's implement the check if usb cable is still inserted or not...
106 cableDaemon
107
108 return 1
109else
110 return 0
111fi
diff --git a/utils/ypr0tools/files/images/r0/post_smode.bmp b/utils/ypr0tools/files/images/r0/post_smode.bmp
new file mode 100644
index 0000000000..5f09fcd54c
--- /dev/null
+++ b/utils/ypr0tools/files/images/r0/post_smode.bmp
Binary files differ
diff --git a/utils/ypr0tools/files/images/r0/pre_smode.bmp b/utils/ypr0tools/files/images/r0/pre_smode.bmp
new file mode 100644
index 0000000000..42978842e9
--- /dev/null
+++ b/utils/ypr0tools/files/images/r0/pre_smode.bmp
Binary files differ
diff --git a/utils/ypr0tools/files/etc/mods/safe_mode.raw b/utils/ypr0tools/files/images/r0/safemode.bmp
index 1c1aa61dd1..410642024e 100644
--- a/utils/ypr0tools/files/etc/mods/safe_mode.raw
+++ b/utils/ypr0tools/files/images/r0/safemode.bmp
Binary files differ
diff --git a/utils/ypr0tools/files/images/r1/post_smode.bmp b/utils/ypr0tools/files/images/r1/post_smode.bmp
new file mode 100644
index 0000000000..cd713a8725
--- /dev/null
+++ b/utils/ypr0tools/files/images/r1/post_smode.bmp
Binary files differ
diff --git a/utils/ypr0tools/files/images/r1/pre_smode.bmp b/utils/ypr0tools/files/images/r1/pre_smode.bmp
new file mode 100644
index 0000000000..f6fd8f3fa7
--- /dev/null
+++ b/utils/ypr0tools/files/images/r1/pre_smode.bmp
Binary files differ
diff --git a/utils/ypr0tools/files/images/r1/safemode.bmp b/utils/ypr0tools/files/images/r1/safemode.bmp
new file mode 100644
index 0000000000..79da24f742
--- /dev/null
+++ b/utils/ypr0tools/files/images/r1/safemode.bmp
Binary files differ
diff --git a/utils/ypr0tools/files/lib/modules/si4709.ko b/utils/ypr0tools/files/r0/lib/modules/si4709.ko
index e2990d2b2d..e2990d2b2d 100755
--- a/utils/ypr0tools/files/lib/modules/si4709.ko
+++ b/utils/ypr0tools/files/r0/lib/modules/si4709.ko
Binary files differ
diff --git a/utils/ypr0tools/patch-firmware.sh b/utils/ypr0tools/patch-firmware.sh
index 879b3f879d..acc1b48631 100755
--- a/utils/ypr0tools/patch-firmware.sh
+++ b/utils/ypr0tools/patch-firmware.sh
@@ -11,19 +11,21 @@
11# 11#
12# * Script to patch an unpacked Samsung YP-R0 firmware file */ 12# * Script to patch an unpacked Samsung YP-R0 firmware file */
13# Copyright (C) 2011 Thomas Martitz 13# Copyright (C) 2011 Thomas Martitz
14# Copyright (C) 2013 Lorenzo Miori
14###################################################################### 15######################################################################
15# bail out early 16# bail out early
16set -e 17set -e
17 18
18if [ $# -lt 1 ] || [ $# -gt 2 ]; then 19if [ $# -lt 1 ] || [ $# -gt 2 ]; then
19 echo "Usage: $0 <files path> [path to unpacked rom]" 20 echo "Usage: $0 <files path> [path to unpacked rom]"
20 echo "\t<files path> is expected to have a rootfs layout and to contain" 21 echo "\t<files path> is expected to have a special resources and rootfs layout"
21 echo "\tonly the files to overwrite (plain cp -r is used)"
22 exit 1 22 exit 1
23fi 23fi
24 24
25MODEL="unknown"
25FILES=${1%/} 26FILES=${1%/}
26FILES=${FILES:-"/"} 27FILES=${FILES:-"/"}
28COMMON_FILES="$FILES/common"
27DIR=${2:-"."} 29DIR=${2:-"."}
28DIR=${DIR%/} 30DIR=${DIR%/}
29ROOTFS=$DIR/rootfs 31ROOTFS=$DIR/rootfs
@@ -31,6 +33,35 @@ CRAMFS=$DIR/cramfs-fsl.rom
31 33
32# sanity checks 34# sanity checks
33 35
36for subdir in common r0 r1
37do
38 if [ ! -d "$FILES/$subdir" ]
39 then
40 echo "Missing $FILES/$subdir. Invalid $FILES layout."
41 exit 1
42 fi
43done
44
45if [ ! -e "$FILES/r1/etc/safemode/cable_detect" ]
46then
47 echo "Couldn't find cable_detect binary (try 'make' or select a valid layout directory)"
48 exit 1
49fi
50
51for image in pre_smode.raw post_smode.raw safemode.raw
52do
53 if [ ! -e "$FILES/r1/etc/safemode/$image" ]
54 then
55 echo "Missing r1 .raw image file (try 'make'): $image"
56 exit 1
57 fi
58 if [ ! -e "$FILES/r0/etc/safemode/$image" ]
59 then
60 echo "Missing r0 .raw image file (try 'make'): $image"
61 exit 1
62 fi
63done
64
34# this needs to be run as root! 65# this needs to be run as root!
35if [ $(whoami) != "root" ] 66if [ $(whoami) != "root" ]
36then 67then
@@ -55,13 +86,33 @@ fi
55 86
56echo "Extracting cramfs image" 87echo "Extracting cramfs image"
57 88
58[ ! -e $ROOTFS ] || rmdir -p $ROOTFS 89[ ! -e $ROOTFS ] || rm -R $ROOTFS
59cramfs-1.1/cramfsck -x $ROOTFS $CRAMFS 90cramfs-1.1/cramfsck -x $ROOTFS $CRAMFS
60 91
61echo "Patching rootfs" 92# now we can detect player version
62echo "cp -r $FILES/* $ROOTFS/" 93# NOTE: order is important here, since ironically
63cp -r $FILES/.rockbox $ROOTFS/ 94# r1's ROM contains also r0's executables
64cp -r $FILES/* $ROOTFS/ 95if [ -e "$ROOTFS/usr/local/bin/r1" ]
96then
97 MODEL="r1"
98else
99 if [ -e "$ROOTFS/usr/local/bin/r0" ]
100 then
101 MODEL="r0"
102 fi
103fi
104
105echo "$MODEL ROM found."
106
107echo "Patching rootfs (common files)"
108echo "cp -r $COMMON_FILES/* $ROOTFS/"
109cp -r $COMMON_FILES/.rockbox $ROOTFS/
110cp -r $COMMON_FILES/* $ROOTFS/
111
112echo "Patching rootfs ($MODEL files)"
113MODEL_FILES="$FILES/$MODEL"
114echo "cp -r $MODEL_FILES/* $ROOTFS/"
115cp -r $MODEL_FILES/* $ROOTFS/
65 116
66echo "Packing new cramfs image" 117echo "Packing new cramfs image"
67cramfs-1.1/mkcramfs $ROOTFS $CRAMFS 118cramfs-1.1/mkcramfs $ROOTFS $CRAMFS