diff options
author | Lorenzo Miori <memorys60@gmail.com> | 2013-07-23 16:24:19 +0200 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2013-09-16 12:55:48 +0200 |
commit | 66aa00d3e051956b634ea157c71782add41d7ed1 (patch) | |
tree | 4c992994bbae116dae8ac90a08710fe84e4f4694 /utils | |
parent | 5ef1e2dcfa2845d7196223af2e170798f7621df6 (diff) | |
download | rockbox-66aa00d3e051956b634ea157c71782add41d7ed1.tar.gz rockbox-66aa00d3e051956b634ea157c71782add41d7ed1.zip |
Samsung YP-R0/YP-R1 Safe Mode improvement
This is an improvement for the special
mode present in the samsung ypr0 target.
Apart adding new useful functionalities, it
fixes a random disconnection bug, solved by debouncing
and fully support to YP-R1 target.
This opens also the possibility to interface
this operating mode to rockbox USB functionality.
Change-Id: Id70541541fcfaa1234328485fab0696a3bd491c9
Diffstat (limited to 'utils')
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 @@ -DEFINES= -CC=gcc -LD=gcc -CFLAGS=-g -std=c99 -W -Wall $(DEFINES) -LDFLAGS= -BINS=fwcrypt fwdecrypt +.PHONY: all clean dirs bmp2rb +CFLAGS += -O1 -g -std=c99 -W -Wall $(DEFINES) +PROGS = bmp2rb fwcrypt fwdecrypt +CROSS_COMPILE = arm-ypr0-linux-gnueabi- +R1_SAFEMODE_DIR = files/r1/etc/safemode +R0_SAFEMODE_DIR = files/r0/etc/safemode +DIRS = $(R1_SAFEMODE_DIR) $(R0_SAFEMODE_DIR) +R1_IMAGES = $(subst .bmp,.raw,$(addprefix $(R1_SAFEMODE_DIR)/,$(notdir $(wildcard files/images/r1/*.bmp)))) +R0_IMAGES = $(subst .bmp,.raw,$(addprefix $(R0_SAFEMODE_DIR)/,$(notdir $(wildcard files/images/r0/*.bmp)))) +BMP2RB = ../../tools/bmp2rb -all: $(BINS) - -%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< +all: $(R1_SAFEMODE_DIR)/cable_detect $(PROGS) $(R1_IMAGES) $(R0_IMAGES) + $(MAKE) -C cramfs-1.1 fwdecrypt: fwdecrypt.o common.o ../../tools/fwpatcher/md5.o - $(LD) -o $@ $^ $(LDFLAGS) fwcrypt: fwcrypt.o common.o ../../tools/fwpatcher/md5.o - $(LD) -o $@ $^ $(LDFLAGS) + +$(BMP2RB): + $(MAKE) -C ../../tools/ bmp2rb + +$(R1_SAFEMODE_DIR)/cable_detect: cable_detect.c $(R1_SAFEMODE_DIR) + $(CROSS_COMPILE)$(CC) $(CFLAGS) $< -o $@ + +$(R1_SAFEMODE_DIR)/%.raw: files/images/r1/%.bmp $(BMP2RB) $(R1_SAFEMODE_DIR) + $(BMP2RB) -r -f 9 $< > $@ + +$(R0_SAFEMODE_DIR)/%.raw: files/images/r0/%.bmp $(BMP2RB) $(R0_SAFEMODE_DIR) + $(BMP2RB) -r -f 9 $< > $@ + +$(DIRS): + $(SILENT)mkdir -p $@ + +dirs: $(DIRS) + +bmp2rb: $(BMP2RB) clean: - rm -fr *.o $(BINS) + $(MAKE) -C cramfs-1.1 clean + rm -f *.o fwdecrypt fwcrypt + 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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Samsung YP-R1 runtime USB cable detection + * + * Copyright (C) 2013 Lorenzo Miori + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include <sys/ioctl.h> +#include <fcntl.h> +#include <unistd.h> + +#define IOCTL_PMU_MAGIC 'A' + +#define E_IOCTL_PMU_GET_BATT_LVL 0 +#define E_IOCTL_PMU_GET_CHG_STATUS 1 +#define E_IOCTL_PMU_IS_EXT_PWR 2 +#define E_IOCTL_PMU_STOP_CHG 3 +#define E_IOCTL_PMU_START_CHG 4 +#define E_IOCTL_PMU_IS_EXT_PWR_OVP 5 +#define E_IOCTL_PMU_LCD_DIM_CTRL 6 +#define E_IOCTL_PMU_CORE_CTL_HIGH 7 +#define E_IOCTL_PMU_CORE_CTL_LOW 8 +#define E_IOCTL_PMU_TSP_USB_PWR_OFF 9 + +#define IOCTL_PMU_GET_BATT_LVL _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_GET_BATT_LVL) +#define IOCTL_PMU_GET_CHG_STATUS _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_GET_CHG_STATUS) +#define IOCTL_PMU_IS_EXT_PWR _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_IS_EXT_PWR) +#define IOCTL_PMU_STOP_CHG _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_STOP_CHG) +#define IOCTL_PMU_START_CHG _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_START_CHG) +#define IOCTL_PMU_IS_EXT_PWR_OVP _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_IS_EXT_PWR_OVP) +#define IOCTL_PMU_LCD_DIM_CTRL _IOW(IOCTL_PMU_MAGIC, E_IOCTL_PMU_LCD_DIM_CTRL, int) +#define IOCTL_PMU_CORE_CTL_HIGH _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_CORE_CTL_HIGH) +#define IOCTL_PMU_CORE_CTL_LOW _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_CORE_CTL_LOW) +#define IOCTL_PMU_TSP_USB_PWR_OFF _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_TSP_USB_PWR_OFF) + +/* + * This is a very simple program that runs on device. + * It returns error code either 0 when (power/usb) cable + * is not connected or >= 1 if connected. + */ +int main(void) +{ + int state = -1; + int dev = open("/dev/r1Pmu", O_RDONLY); + state = ioctl(dev, IOCTL_PMU_IS_EXT_PWR); + close(dev); + return state; +} 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 alias ls='ls --color=auto' alias ll='ls -l --color=auto' -# Start with lorenzo92's safe mode -SCRIPT="/etc/mods/safe_mode.sh" +# Start with safe mode +SCRIPT="/etc/safemode/smode" if [ -f $SCRIPT ] then /bin/sh $SCRIPT @@ -29,24 +29,16 @@ then fi fi -if [ -e "/mnt/media1/r0" ] +# Ironically, r1's ROM contains a lot of r0's executables, including the main one. +# So we need to check against r1 before! +if [ -e "/usr/local/bin/r1" ] then - MAINFILE="/mnt/media1/r0" -elif [ -f "/mnt/media0/r0" ] -then - # copy to media1 since USB wouldn't work - cp /mnt/media0/r0 /mnt/media1/r0_media0 - if [ "$?" = "0" ] - then # perhaps cp failed due to insufficient storage or so - MAINFILE="/mnt/media1/r0_media0" - else - MAINFILE="/usr/local/bin/r0" - fi + MAINFILE="/usr/local/bin/r1" else MAINFILE="/usr/local/bin/r0" fi -# Parameters for r0 +# Parameters for the application MAINFILE_ARGV="Application AppMain" # 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 @@ +#!/bin/sh + +###################################################################### +# __________ __ ___. +# Open \______ \ ____ ____ | | _\_ |__ _______ ___ +# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +# \/ \/ \/ \/ \/ +# +# * Safe Mode for Samsung YP-R0 / YP-R1 * +# * Copyright (C) 2013 Lorenzo Miori and VanniX +###################################################################### + +# 0 = R0 ; 1 = R1 +PLATFORM=0 +BUTTON_DEVICE="/dev/r0Btn" +PMK=$(echo -e -n "\x01") # same for both devices +STORAGES="/dev/stl3,/dev/stl2,/dev/mmcblk0" + +MODE="normal" + +if [ $# -eq 1 ] +then + MODE=$1 +fi + +# rather simple but effective check +# different key codes to trigger safe mode +if [ -e "/usr/local/bin/r1" ] +then + # running on YP-R1 model + BACK=$(echo -e -n "\x02") + PLATFORM=1 + BUTTON_DEVICE="/dev/r1Button" + STORAGES="/dev/stl3,/dev/stl2" +else + BACK=$(echo -e -n "\x08") + PLATFORM=0 + BUTTON_DEVICE="/dev/r0Btn" + STORAGES="/dev/stl3,/dev/stl2,/dev/mmcblk0" +fi + +power_pressed() +{ + VAR=$(dd if=$BUTTON_DEVICE bs=4 count=1) + [[ "$VAR" = "$PMK" ]] + return $? +} + +cable_disconnected() +{ + if [ $PLATFORM -eq 0 ] + then + /usr/local/bin/minird 0x0a | grep -q 0x00 + return $? + else + /etc/safemode/cable_detect + return $? + fi +} + +enable_display() +{ + echo -n "0" > /sys/devices/platform/afe.0/bli + echo -n "1" > /sys/class/graphics/fb0/blank + echo -n "0" >> /sys/class/graphics/fb0/blank + echo -n "1" > /sys/devices/platform/afe.0/bli +} + +display_image() +{ + cat $1 > "/dev/fb0" +} + +if [ $MODE != "forced" ] +then + KEY=$(dd if=$BUTTON_DEVICE bs=4 count=1) + if [[ "$KEY" != "$BACK" ]]; then + # do not enter safe mode and continue normal boot + exit 0 + fi +fi + +# Here we entered safe mode, so first clean the display +# and turn on backlight at minimum level +enable_display + +# there are different ROMs around... +if [ -e "/etc/safemode/safemode.raw" ] +then + DefIMG="/etc/safemode/safemode.raw" +else + DefIMG="/etc/mods/safe_mode.raw" +fi +RbtIMG="/etc/safemode/post_smode.raw" +PreIMG="/etc/safemode/pre_smode.raw" + +NOUSB=true + +if cable_disconnected +then + + display_image $PreIMG + + while $NOUSB + do + + # User aborts safe mode before mounting anything, just exit + # and continue normal boot + if power_pressed + then + sleep 1 + if power_pressed + then + exit 1 + fi + fi + + if cable_disconnected + then + echo "USB not connected - Waiting" + else + sleep 1 + if cable_disconnected + then + echo "USB first check OK - Waiting" + else + sleep 1 + if cable_disconnected + then + echo "USB second check OK - Waiting" + else + NOUSB=false + USB=true + fi + fi + fi + done +else + while $NOUSB + do + if cable_disconnected + then + echo "USB not connected - Waiting" + else + sleep 1 + if cable_disconnected + then + echo "USB first check OK - Waiting" + else + NOUSB=false + USB=true + fi + fi + done +fi + +display_image $DefIMG + +echo "Enabling usb storage..." +lsmod | grep g_file_storage +if [ $? == 0 ] +then + umount /mnt/media1/dev/gadget +fi + +umount /mnt/media1 +umount /mnt/media0 + +lsmod | grep rfs +if [ $? == 0 ] +then + rmmod rfs +fi + +lsmod | grep g_file_storage +if [ $? == 0 ] +then + rmmod gadgetfs + rmmod g_file_storage + rmmod arcotg_udc +fi + +lsmod | grep g_serial +if [ $? == 0 ] +then + rmmod g_serial +fi + +lsmod | grep g_file_storage +if [ $? != 0 ] +then + modprobe g-file-storage file=$STORAGES removable=1 +fi + +SAFE=true +while $SAFE +do + if power_pressed + then + sleep 1 + if power_pressed + then + SAFE=false + fi + fi +done + +echo "Removing loaded modules..." +rmmod g_file_storage +rmmod arcotg_udc + +display_image $RbtIMG + +USB=true + +while $USB +do + if cable_disconnected + then + sleep 1 + if cable_disconnected + then + if cable_disconnected + then + sleep 1 + if cable_disconnected + then + USB=false + else + echo "USB connected - Waiting" + USB=true + fi + else + echo "USB connected - Waiting" + USB=true + fi + else + echo "USB connected - Waiting" + USB=true + fi + else + echo "USB connected - Waiting" + USB=true + fi +done + +#power key pressed for almost 2 sec and cable disconnected. Power off! +exit 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 @@ -#!/bin/sh - -# YP-R0 Safe Mode!! -# - Part of the "Device Rescue Kit", modded ROM v2.20 and onwards -# Version: v0.3 -# v0.2 - initial version -# v0.3 - USB cable check implemented -# by lorenzo92 aka Memory -# memoryS60@gmail.com - -CustomIMG="/mnt/media1/safe_mode.raw" -DefIMG="/etc/mods/safe_mode.raw" - -timer=0 -# Seconds before turning the device OFF -timeout=2 - -shutdown () { - sync - reboot -} - -cableDaemon () { - cd /usr/local/bin - while [ 1 ] - do - if [ $timer -gt $timeout ] - then - shutdown - fi - - if ./minird 0x0a | grep -q 0x00 - then - timer=$(($timer+1)) - else - timer=0 - fi - sleep 1 - done -} - -# Back button is a \x08\x00\x00\x00 string... -# ...since bash removes null bytes for us, we must only care the single byte -var=$(dd if=/dev/r0Btn bs=4 count=1) -# Here a workaround to detect \x08 byte :S -var2=$(echo -e -n "\x08") -if [[ "$var" = "$var2" ]] -then - echo "Safe mode (USB) activated..." - # Put the backlight at the minimum level: no energy waste, please ;) - # Using low level interface - - cd /usr/local/bin - ./afewr 0x1b 0x3 0x8 - - # Long press reset time 5 secs - [ -e /etc/mods/reset_time_mod.sh ] && /bin/sh /etc/mods/reset_time_mod.sh - - # Clear the screen and show a nice picture :D - - echo -n "1" > /sys/class/graphics/fb0/blank - echo -n "0" >> /sys/class/graphics/fb0/blank -# echo -n "1" > /sys/class/graphics/fb2/blank -# echo -n "0" >> /sys/class/graphics/fb2/blank - if [ -e $CustomIMG ] - then - cat $CustomIMG > "/dev/fb0" - else - cat $DefIMG > "/dev/fb0" - fi - - # Here the real USB connection stuff - # This is slightly modified by me; it was contained in the cramfs shipped with - # YP-R0 opensource package... - - lsmod | grep g_file_storage - if [ $? == 0 ] - then - umount /mnt/media1/dev/gadget - fi - #if [ -d /mnt/media0 ] - #then - umount /mnt/media1 - umount /mnt/media0 - #umount /mnt/mmc - #fi - lsmod | grep rfs - if [ $? == 0 ] - then - rmmod rfs - fi - lsmod | grep g_file_storage - if [ $? == 0 ] - then - rmmod gadgetfs - rmmod g_file_storage - rmmod arcotg_udc - fi - lsmod | grep g_file_storage - if [ $? != 0 ] - then - modprobe g-file-storage file=/dev/stl3,/dev/stl2,/dev/mmcblk0 removable=1 - fi - - # Let's implement the check if usb cable is still inserted or not... - cableDaemon - - return 1 -else - return 0 -fi diff --git a/utils/ypr0tools/files/images/r0/post_smode.bmp b/utils/ypr0tools/files/images/r0/post_smode.bmp Binary files differnew file mode 100644 index 0000000000..5f09fcd54c --- /dev/null +++ b/utils/ypr0tools/files/images/r0/post_smode.bmp diff --git a/utils/ypr0tools/files/images/r0/pre_smode.bmp b/utils/ypr0tools/files/images/r0/pre_smode.bmp Binary files differnew file mode 100644 index 0000000000..42978842e9 --- /dev/null +++ b/utils/ypr0tools/files/images/r0/pre_smode.bmp diff --git a/utils/ypr0tools/files/etc/mods/safe_mode.raw b/utils/ypr0tools/files/images/r0/safemode.bmp Binary files differindex 1c1aa61dd1..410642024e 100644 --- a/utils/ypr0tools/files/etc/mods/safe_mode.raw +++ b/utils/ypr0tools/files/images/r0/safemode.bmp diff --git a/utils/ypr0tools/files/images/r1/post_smode.bmp b/utils/ypr0tools/files/images/r1/post_smode.bmp Binary files differnew file mode 100644 index 0000000000..cd713a8725 --- /dev/null +++ b/utils/ypr0tools/files/images/r1/post_smode.bmp diff --git a/utils/ypr0tools/files/images/r1/pre_smode.bmp b/utils/ypr0tools/files/images/r1/pre_smode.bmp Binary files differnew file mode 100644 index 0000000000..f6fd8f3fa7 --- /dev/null +++ b/utils/ypr0tools/files/images/r1/pre_smode.bmp diff --git a/utils/ypr0tools/files/images/r1/safemode.bmp b/utils/ypr0tools/files/images/r1/safemode.bmp Binary files differnew file mode 100644 index 0000000000..79da24f742 --- /dev/null +++ b/utils/ypr0tools/files/images/r1/safemode.bmp diff --git a/utils/ypr0tools/files/lib/modules/si4709.ko b/utils/ypr0tools/files/r0/lib/modules/si4709.ko Binary files differindex e2990d2b2d..e2990d2b2d 100755 --- a/utils/ypr0tools/files/lib/modules/si4709.ko +++ b/utils/ypr0tools/files/r0/lib/modules/si4709.ko 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 @@ # # * Script to patch an unpacked Samsung YP-R0 firmware file */ # Copyright (C) 2011 Thomas Martitz +# Copyright (C) 2013 Lorenzo Miori ###################################################################### # 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)" + echo "\t<files path> is expected to have a special resources and rootfs layout" exit 1 fi +MODEL="unknown" FILES=${1%/} FILES=${FILES:-"/"} +COMMON_FILES="$FILES/common" DIR=${2:-"."} DIR=${DIR%/} ROOTFS=$DIR/rootfs @@ -31,6 +33,35 @@ CRAMFS=$DIR/cramfs-fsl.rom # sanity checks +for subdir in common r0 r1 +do + if [ ! -d "$FILES/$subdir" ] + then + echo "Missing $FILES/$subdir. Invalid $FILES layout." + exit 1 + fi +done + +if [ ! -e "$FILES/r1/etc/safemode/cable_detect" ] +then + echo "Couldn't find cable_detect binary (try 'make' or select a valid layout directory)" + exit 1 +fi + +for image in pre_smode.raw post_smode.raw safemode.raw +do + if [ ! -e "$FILES/r1/etc/safemode/$image" ] + then + echo "Missing r1 .raw image file (try 'make'): $image" + exit 1 + fi + if [ ! -e "$FILES/r0/etc/safemode/$image" ] + then + echo "Missing r0 .raw image file (try 'make'): $image" + exit 1 + fi +done + # this needs to be run as root! if [ $(whoami) != "root" ] then @@ -55,13 +86,33 @@ fi echo "Extracting cramfs image" -[ ! -e $ROOTFS ] || rmdir -p $ROOTFS +[ ! -e $ROOTFS ] || rm -R $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/ +# now we can detect player version +# NOTE: order is important here, since ironically +# r1's ROM contains also r0's executables +if [ -e "$ROOTFS/usr/local/bin/r1" ] +then + MODEL="r1" +else + if [ -e "$ROOTFS/usr/local/bin/r0" ] + then + MODEL="r0" + fi +fi + +echo "$MODEL ROM found." + +echo "Patching rootfs (common files)" +echo "cp -r $COMMON_FILES/* $ROOTFS/" +cp -r $COMMON_FILES/.rockbox $ROOTFS/ +cp -r $COMMON_FILES/* $ROOTFS/ + +echo "Patching rootfs ($MODEL files)" +MODEL_FILES="$FILES/$MODEL" +echo "cp -r $MODEL_FILES/* $ROOTFS/" +cp -r $MODEL_FILES/* $ROOTFS/ echo "Packing new cramfs image" cramfs-1.1/mkcramfs $ROOTFS $CRAMFS |