summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/SOURCES2
-rw-r--r--apps/keymaps/keymap-ypr0.c258
-rw-r--r--apps/plugin.h2
-rw-r--r--apps/plugins/SOURCES.app_build6
-rw-r--r--apps/plugins/SUBDIRS2
-rw-r--r--apps/plugins/SUBDIRS.app_build10
-rw-r--r--apps/plugins/battery_bench.c3
-rw-r--r--apps/plugins/blackjack.c16
-rw-r--r--apps/plugins/bounce.c3
-rw-r--r--apps/plugins/brickmania.c3
-rw-r--r--apps/plugins/calculator.c11
-rw-r--r--apps/plugins/calendar.c10
-rw-r--r--apps/plugins/chessbox/chessbox_pgn.h10
-rw-r--r--apps/plugins/chessclock.c10
-rw-r--r--apps/plugins/chip8.c12
-rw-r--r--apps/plugins/chopper.c3
-rw-r--r--apps/plugins/clix.c3
-rw-r--r--apps/plugins/cube.c10
-rw-r--r--apps/plugins/doom/i_video.c11
-rw-r--r--apps/plugins/fft/fft.c9
-rw-r--r--apps/plugins/fireworks.c3
-rw-r--r--apps/plugins/flipit.c12
-rw-r--r--apps/plugins/fractals/fractal.h12
-rw-r--r--apps/plugins/goban/goban.h10
-rw-r--r--apps/plugins/imageviewer/imageviewer_button.h12
-rw-r--r--apps/plugins/invadrox.c3
-rw-r--r--apps/plugins/jewels.c3
-rw-r--r--apps/plugins/lamp.c3
-rw-r--r--apps/plugins/lib/pluginlib_actions.c6
-rw-r--r--apps/plugins/lib/simple_viewer.c1
-rw-r--r--apps/plugins/logo.c3
-rw-r--r--apps/plugins/lua/strcspn.c1
-rw-r--r--apps/plugins/lua/strpbrk.c1
-rw-r--r--apps/plugins/matrix.c3
-rw-r--r--apps/plugins/midi/midiplay.c8
-rw-r--r--apps/plugins/minesweeper.c10
-rw-r--r--apps/plugins/mosaique.c3
-rw-r--r--apps/plugins/mp3_encoder.c3
-rw-r--r--apps/plugins/mpegplayer/mpeg_settings.c8
-rw-r--r--apps/plugins/mpegplayer/mpegplayer.c9
-rw-r--r--apps/plugins/oscilloscope.c11
-rw-r--r--apps/plugins/pacbox/pacbox.h11
-rw-r--r--apps/plugins/pdbox/pdbox.h19
-rw-r--r--apps/plugins/pegbox.c18
-rw-r--r--apps/plugins/pong.c8
-rw-r--r--apps/plugins/reversi/reversi-gui.h9
-rw-r--r--apps/plugins/rockblox.c12
-rw-r--r--apps/plugins/rockblox1d.c3
-rw-r--r--apps/plugins/rockboy/rockboy.c12
-rw-r--r--apps/plugins/rockboy/rockmacros.h2
-rw-r--r--apps/plugins/rockpaint.c11
-rw-r--r--apps/plugins/sliding_puzzle.c6
-rw-r--r--apps/plugins/snake.c3
-rw-r--r--apps/plugins/snake2.c3
-rw-r--r--apps/plugins/snow.c3
-rw-r--r--apps/plugins/sokoban.c15
-rw-r--r--apps/plugins/solitaire.c18
-rw-r--r--apps/plugins/spacerocks.c9
-rw-r--r--apps/plugins/star.c17
-rw-r--r--apps/plugins/starfield.c3
-rw-r--r--apps/plugins/stats.c3
-rw-r--r--apps/plugins/stopwatch.c8
-rw-r--r--apps/plugins/sudoku/sudoku.h10
-rw-r--r--apps/plugins/superdom.c3
-rw-r--r--apps/plugins/test_codec.c2
-rw-r--r--apps/plugins/test_fps.c2
-rw-r--r--apps/plugins/test_gfx.c6
-rw-r--r--apps/plugins/text_viewer/tv_button.h10
-rw-r--r--apps/plugins/vu_meter.c11
-rw-r--r--apps/plugins/wormlet.c3
-rw-r--r--apps/plugins/xobox.c9
-rw-r--r--apps/plugins/zxbox/keymaps.h12
-rw-r--r--apps/plugins/zxbox/zxbox_keyb.c9
-rw-r--r--docs/CREDITS1
-rw-r--r--firmware/SOURCES29
-rw-r--r--firmware/common/rbpaths.c34
-rw-r--r--firmware/drivers/audio/as3514.c42
-rw-r--r--firmware/drivers/rtc/rtc_as3514.c4
-rw-r--r--firmware/export/as3514.h5
-rw-r--r--firmware/export/ascodec.h4
-rw-r--r--firmware/export/audiohw.h2
-rw-r--r--firmware/export/config.h16
-rw-r--r--firmware/export/config/ypr0.h168
-rw-r--r--firmware/export/rbpaths.h5
-rw-r--r--firmware/include/dir_uncached.h2
-rw-r--r--firmware/pcm_mixer.c5
-rw-r--r--firmware/sound.c5
-rw-r--r--firmware/system.c2
-rw-r--r--firmware/target/hosted/pcm-alsa.c518
-rw-r--r--firmware/target/hosted/ypr0/adc-target.h25
-rw-r--r--firmware/target/hosted/ypr0/ascodec-target.h92
-rw-r--r--firmware/target/hosted/ypr0/ascodec-ypr0.c206
-rw-r--r--firmware/target/hosted/ypr0/backlight-target.h29
-rw-r--r--firmware/target/hosted/ypr0/backlight-ypr0.c89
-rw-r--r--firmware/target/hosted/ypr0/button-target.h53
-rw-r--r--firmware/target/hosted/ypr0/button-ypr0.c103
-rw-r--r--firmware/target/hosted/ypr0/dir-target.h56
-rw-r--r--firmware/target/hosted/ypr0/fs-ypr0.c141
-rw-r--r--firmware/target/hosted/ypr0/i2c-target.h25
-rw-r--r--firmware/target/hosted/ypr0/kernel-ypr0.c163
-rw-r--r--firmware/target/hosted/ypr0/lc-ypr0.c40
-rw-r--r--firmware/target/hosted/ypr0/lcd-ypr0.c147
-rw-r--r--firmware/target/hosted/ypr0/powermgmt-ypr0.c133
-rw-r--r--firmware/target/hosted/ypr0/system-target.h37
-rw-r--r--firmware/target/hosted/ypr0/system-ypr0.c106
-rw-r--r--firmware/target/hosted/ypr0/usb-target.h25
-rw-r--r--firmware/target/hosted/ypr0/ypr0.make25
-rwxr-xr-xtools/buildzip.pl7
-rwxr-xr-xtools/configure48
-rw-r--r--tools/root.make4
-rw-r--r--utils/ypr0tools/Makefile13
-rwxr-xr-xutils/ypr0tools/MuonEncryptbin0 -> 11006 bytes
-rw-r--r--utils/ypr0tools/README12
-rw-r--r--utils/ypr0tools/cramfs-1.1/COPYING340
-rw-r--r--utils/ypr0tools/cramfs-1.1/GNUmakefile12
-rw-r--r--utils/ypr0tools/cramfs-1.1/NOTES168
-rw-r--r--utils/ypr0tools/cramfs-1.1/README76
-rw-r--r--utils/ypr0tools/cramfs-1.1/cramfsck.c716
-rw-r--r--utils/ypr0tools/cramfs-1.1/linux/cramfs_fs.h98
-rw-r--r--utils/ypr0tools/cramfs-1.1/linux/cramfs_fs_sb.h15
-rw-r--r--utils/ypr0tools/cramfs-1.1/mkcramfs.c889
-rw-r--r--utils/ypr0tools/extract_section.c85
-rw-r--r--utils/ypr0tools/files/.rockbox/README1
-rw-r--r--utils/ypr0tools/files/Playlists/README1
-rw-r--r--utils/ypr0tools/files/etc/mods/safe_mode.rawbin0 -> 230400 bytes
-rwxr-xr-xutils/ypr0tools/files/etc/mods/safe_mode.sh111
-rwxr-xr-xutils/ypr0tools/files/etc/profile66
-rwxr-xr-xutils/ypr0tools/pack-firmware.sh132
-rwxr-xr-xutils/ypr0tools/patch-firmware.sh67
-rwxr-xr-xutils/ypr0tools/rockbox.sh47
-rwxr-xr-xutils/ypr0tools/unpack-firmware.sh90
131 files changed, 6075 insertions, 49 deletions
diff --git a/apps/SOURCES b/apps/SOURCES
index 34dc202345..53a67fd307 100644
--- a/apps/SOURCES
+++ b/apps/SOURCES
@@ -332,5 +332,7 @@ keymaps/keymap-hm60x.c
332keymaps/keymap-hm801.c 332keymaps/keymap-hm801.c
333#elif CONFIG_KEYPAD == SANSA_CONNECT_PAD 333#elif CONFIG_KEYPAD == SANSA_CONNECT_PAD
334keymaps/keymap-sansa-connect.c 334keymaps/keymap-sansa-connect.c
335#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
336keymaps/keymap-ypr0.c
335#endif 337#endif
336 338
diff --git a/apps/keymaps/keymap-ypr0.c b/apps/keymaps/keymap-ypr0.c
new file mode 100644
index 0000000000..b5706760ba
--- /dev/null
+++ b/apps/keymaps/keymap-ypr0.c
@@ -0,0 +1,258 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: keymap-sdl.c 28704 2010-11-29 11:28:53Z teru $
9 *
10 * Copyright (C) 2011 Lorenzo Miori
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22/* Button Code Definitions for Samsung YP-R0 target */
23
24#include <stdio.h>
25#include <string.h>
26#include <stdlib.h>
27
28#include "config.h"
29#include "action.h"
30#include "button.h"
31#include "settings.h"
32
33/*
34 * The format of the list is as follows
35 * { Action Code, Button code, Prereq button code }
36 * if there's no need to check the previous button's value, use BUTTON_NONE
37 * Insert LAST_ITEM_IN_LIST at the end of each mapping
38 */
39
40static const struct button_mapping button_context_standard[] = {
41 { ACTION_STD_PREV, BUTTON_UP, BUTTON_NONE },
42 { ACTION_STD_PREVREPEAT, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE },
43 { ACTION_STD_NEXT, BUTTON_DOWN, BUTTON_NONE },
44 { ACTION_STD_NEXTREPEAT, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE },
45
46 { ACTION_STD_CANCEL, BUTTON_LEFT, BUTTON_NONE },
47 { ACTION_STD_CANCEL, BUTTON_BACK|BUTTON_REL, BUTTON_BACK },
48
49 { ACTION_STD_OK, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT },
50 { ACTION_STD_OK, BUTTON_RIGHT, BUTTON_NONE },
51
52 { ACTION_STD_QUICKSCREEN, BUTTON_MENU|BUTTON_REPEAT, BUTTON_NONE },
53 { ACTION_STD_CONTEXT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_SELECT },
54 { ACTION_STD_MENU, BUTTON_MENU|BUTTON_REL, BUTTON_MENU },
55
56 { ACTION_STD_CONTEXT, BUTTON_MENU|BUTTON_REL, BUTTON_NONE },
57 { ACTION_STD_QUICKSCREEN, BUTTON_MENU|BUTTON_REPEAT, BUTTON_NONE },
58
59 { ACTION_STD_KEYLOCK, BUTTON_POWER|BUTTON_REL, BUTTON_POWER },
60
61 LAST_ITEM_IN_LIST
62}; /* button_context_standard */
63
64static const struct button_mapping button_context_wps[] = {
65 { ACTION_WPS_PLAY, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT },
66 { ACTION_WPS_STOP, BUTTON_POWER|BUTTON_REPEAT, BUTTON_NONE },
67
68 { ACTION_WPS_BROWSE, BUTTON_BACK|BUTTON_REL, BUTTON_BACK },
69 { ACTION_WPS_MENU, BUTTON_MENU|BUTTON_REL, BUTTON_MENU },
70
71 /* NOTE: this is available only enabling AB-Repeat mode */
72 { ACTION_WPS_HOTKEY, BUTTON_USER|BUTTON_REL, BUTTON_USER },
73 { ACTION_WPSAB_SINGLE, BUTTON_USER|BUTTON_REPEAT, BUTTON_NONE },
74 { ACTION_STD_KEYLOCK, BUTTON_POWER|BUTTON_REL, BUTTON_POWER },
75 { ACTION_WPS_CONTEXT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_SELECT },
76 { ACTION_WPS_QUICKSCREEN, BUTTON_MENU|BUTTON_REPEAT, BUTTON_NONE },
77
78 { ACTION_WPS_SKIPPREV, BUTTON_LEFT|BUTTON_REL, BUTTON_LEFT },
79 { ACTION_WPS_SEEKBACK, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
80 { ACTION_WPS_STOPSEEK, BUTTON_LEFT|BUTTON_REL, BUTTON_LEFT|BUTTON_REPEAT },
81
82 { ACTION_WPS_SKIPNEXT, BUTTON_RIGHT|BUTTON_REL, BUTTON_RIGHT },
83 { ACTION_WPS_SEEKFWD, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
84 { ACTION_WPS_STOPSEEK, BUTTON_RIGHT|BUTTON_REL, BUTTON_RIGHT|BUTTON_REPEAT },
85
86
87 { ACTION_WPS_VOLUP, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE },
88 { ACTION_WPS_VOLUP, BUTTON_UP, BUTTON_NONE },
89 { ACTION_WPS_VOLDOWN, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE },
90 { ACTION_WPS_VOLDOWN, BUTTON_DOWN, BUTTON_NONE },
91
92 LAST_ITEM_IN_LIST
93}; /* button_context_wps */
94
95static const struct button_mapping button_context_list[] = {
96 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
97}; /* button_context_list */
98
99static const struct button_mapping button_context_tree[] = {
100 { ACTION_TREE_WPS, BUTTON_USER|BUTTON_REPEAT, BUTTON_USER },
101 { ACTION_TREE_STOP, BUTTON_POWER|BUTTON_REPEAT, BUTTON_NONE },
102 { ACTION_TREE_HOTKEY, BUTTON_USER|BUTTON_REL, BUTTON_NONE },
103
104 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST)
105}; /* button_context_tree */
106
107static const struct button_mapping button_context_settings[] = {
108
109 { ACTION_SETTINGS_INC, BUTTON_RIGHT, BUTTON_NONE },
110 { ACTION_SETTINGS_INCREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
111 { ACTION_SETTINGS_DEC, BUTTON_LEFT, BUTTON_NONE },
112 { ACTION_SETTINGS_DECREPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
113
114 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_TREE)
115}; /* button_context_settings */
116
117static const struct button_mapping button_context_yesno[] = {
118 { ACTION_YESNO_ACCEPT, BUTTON_SELECT, BUTTON_NONE },
119
120 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
121}; /* button_context_settings_yesno */
122
123static const struct button_mapping button_context_colorchooser[] = { //check
124 { ACTION_STD_OK, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT },
125 { ACTION_STD_CANCEL, BUTTON_BACK, BUTTON_NONE },
126
127 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_SETTINGS),
128}; /* button_context_colorchooser */
129
130static const struct button_mapping button_context_eq[] = {
131
132 { ACTION_STD_CANCEL, BUTTON_MENU|BUTTON_REL, BUTTON_MENU },
133
134 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_SETTINGS),
135}; /* button_context_eq */
136
137/** Bookmark Screen **/
138static const struct button_mapping button_context_bmark[] = {
139 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST),
140}; /* button_context_bmark */
141
142static const struct button_mapping button_context_time[] = {
143
144 { ACTION_SETTINGS_INC, BUTTON_UP, BUTTON_NONE },
145 { ACTION_SETTINGS_INCREPEAT, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE },
146 { ACTION_SETTINGS_DEC, BUTTON_DOWN, BUTTON_NONE },
147 { ACTION_SETTINGS_DECREPEAT, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE },
148 { ACTION_STD_PREV, BUTTON_LEFT, BUTTON_NONE },
149 { ACTION_STD_PREVREPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
150 { ACTION_STD_NEXT, BUTTON_RIGHT, BUTTON_NONE },
151 { ACTION_STD_NEXTREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
152
153 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD),
154}; /* button_context_time */
155
156static const struct button_mapping button_context_quickscreen[] = {
157
158 { ACTION_QS_TOP, BUTTON_UP, BUTTON_NONE },
159 { ACTION_QS_TOP, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE },
160 { ACTION_QS_DOWN, BUTTON_DOWN, BUTTON_NONE },
161 { ACTION_QS_DOWN, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE },
162 { ACTION_QS_LEFT, BUTTON_LEFT, BUTTON_NONE },
163 { ACTION_QS_LEFT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
164 { ACTION_QS_RIGHT, BUTTON_RIGHT, BUTTON_NONE },
165 { ACTION_QS_RIGHT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
166 { ACTION_STD_CANCEL, BUTTON_MENU, BUTTON_NONE },
167
168 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
169}; /* button_context_quickscreen */
170
171static const struct button_mapping button_context_pitchscreen[] = {
172
173 { ACTION_PS_INC_SMALL, BUTTON_UP, BUTTON_NONE },
174 { ACTION_PS_INC_BIG, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE },
175 { ACTION_PS_DEC_SMALL, BUTTON_DOWN, BUTTON_NONE },
176 { ACTION_PS_DEC_BIG, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE },
177
178 { ACTION_PS_SLOWER, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
179 { ACTION_PS_FASTER, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
180
181 { ACTION_PS_NUDGE_LEFT, BUTTON_LEFT, BUTTON_NONE },
182 { ACTION_PS_NUDGE_LEFTOFF, BUTTON_LEFT|BUTTON_REL, BUTTON_NONE },
183 { ACTION_PS_NUDGE_RIGHT, BUTTON_RIGHT, BUTTON_NONE },
184 { ACTION_PS_NUDGE_RIGHTOFF, BUTTON_RIGHT|BUTTON_REL, BUTTON_NONE },
185
186 { ACTION_PS_RESET, BUTTON_SELECT, BUTTON_NONE },
187 { ACTION_PS_TOGGLE_MODE, BUTTON_USER, BUTTON_NONE },
188 { ACTION_PS_EXIT, BUTTON_MENU|BUTTON_REL, BUTTON_NONE },
189 { ACTION_PS_EXIT, BUTTON_BACK|BUTTON_REL, BUTTON_NONE },
190
191 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
192}; /* button_context_pitchcreen */
193
194static const struct button_mapping button_context_keyboard[] = {
195
196 { ACTION_KBD_UP, BUTTON_UP, BUTTON_NONE },
197 { ACTION_KBD_UP, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE },
198 { ACTION_KBD_DOWN, BUTTON_DOWN, BUTTON_NONE },
199 { ACTION_KBD_DOWN, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE },
200 { ACTION_KBD_LEFT, BUTTON_LEFT, BUTTON_NONE },
201 { ACTION_KBD_LEFT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
202 { ACTION_KBD_RIGHT, BUTTON_RIGHT, BUTTON_NONE },
203 { ACTION_KBD_RIGHT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
204
205 { ACTION_KBD_SELECT, BUTTON_SELECT, BUTTON_NONE },
206 { ACTION_KBD_ABORT, BUTTON_BACK|BUTTON_REL, BUTTON_BACK },
207 { ACTION_KBD_DONE, BUTTON_MENU|BUTTON_REL, BUTTON_MENU },
208 { ACTION_KBD_BACKSPACE, BUTTON_USER, BUTTON_NONE },
209 { ACTION_KBD_PAGE_FLIP, BUTTON_POWER, BUTTON_NONE },
210
211 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
212}; /* button_context_keyboard */
213
214static const struct button_mapping button_context_radio[] = {
215 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_SETTINGS)
216}; /* button_context_radio */
217
218const struct button_mapping* get_context_mapping(int context)
219{
220 switch (context)
221 {
222 case CONTEXT_STD:
223 return button_context_standard;
224 case CONTEXT_WPS:
225 return button_context_wps;
226
227 case CONTEXT_LIST:
228 return button_context_list;
229 case CONTEXT_MAINMENU:
230 case CONTEXT_TREE:
231 return button_context_tree;
232
233 case CONTEXT_SETTINGS:
234 return button_context_settings;
235
236 case CONTEXT_SETTINGS_COLOURCHOOSER:
237 return button_context_colorchooser;
238 case CONTEXT_SETTINGS_EQ:
239 return button_context_eq;
240
241 case CONTEXT_SETTINGS_TIME:
242 return button_context_time;
243
244 case CONTEXT_YESNOSCREEN:
245 return button_context_yesno;
246 case CONTEXT_FM:
247 return button_context_radio;
248 case CONTEXT_BOOKMARKSCREEN:
249 return button_context_bmark;
250 case CONTEXT_QUICKSCREEN:
251 return button_context_quickscreen;
252 case CONTEXT_PITCHSCREEN:
253 return button_context_pitchscreen;
254 case CONTEXT_KEYBOARD:
255 return button_context_keyboard;
256 }
257 return button_context_standard;
258}
diff --git a/apps/plugin.h b/apps/plugin.h
index 4a62697724..e778f51f62 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -121,6 +121,8 @@ void* plugin_get_buffer(size_t *buffer_size);
121/* on some platforms strcmp() seems to be a tricky define which 121/* on some platforms strcmp() seems to be a tricky define which
122 * breaks if we write down strcmp's prototype */ 122 * breaks if we write down strcmp's prototype */
123#undef strcmp 123#undef strcmp
124#undef strncmp
125#undef strchr
124 126
125#ifdef PLUGIN 127#ifdef PLUGIN
126 128
diff --git a/apps/plugins/SOURCES.app_build b/apps/plugins/SOURCES.app_build
index ddac2b9ba8..e374062536 100644
--- a/apps/plugins/SOURCES.app_build
+++ b/apps/plugins/SOURCES.app_build
@@ -1,3 +1,7 @@
1#ifndef HAVE_TOUCHSCREEN
2/* In devices running RockBox as an application, but having a keypad */
3#include "SOURCES"
4#else
1/* plugins common to all models */ 5/* plugins common to all models */
2credits.c 6credits.c
3properties.c 7properties.c
@@ -39,3 +43,5 @@ test_sampr.c
39#endif 43#endif
40test_viewports.c 44test_viewports.c
41#endif /* HAVE_TEST_PLUGINS */ 45#endif /* HAVE_TEST_PLUGINS */
46
47#endif /* HAVE_TOUCHSCREEN */
diff --git a/apps/plugins/SUBDIRS b/apps/plugins/SUBDIRS
index c497c49b14..d2feb721d4 100644
--- a/apps/plugins/SUBDIRS
+++ b/apps/plugins/SUBDIRS
@@ -73,7 +73,7 @@ mikmod
73#if defined(IRIVER_H300_SERIES) || defined(IRIVER_H100_SERIES) || \ 73#if defined(IRIVER_H300_SERIES) || defined(IRIVER_H100_SERIES) || \
74 (CONFIG_KEYPAD == SANSA_FUZE_PAD) || (CONFIG_KEYPAD == SANSA_E200_PAD) || \ 74 (CONFIG_KEYPAD == SANSA_FUZE_PAD) || (CONFIG_KEYPAD == SANSA_E200_PAD) || \
75 (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \ 75 (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
76 (CONFIG_KEYPAD == IPOD_1G2G_PAD) 76 (CONFIG_KEYPAD == IPOD_1G2G_PAD || CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
77/* PDBox is confirmed to run on these player models. */ 77/* PDBox is confirmed to run on these player models. */
78pdbox 78pdbox
79#endif 79#endif
diff --git a/apps/plugins/SUBDIRS.app_build b/apps/plugins/SUBDIRS.app_build
index dbf4382b62..23b840fd87 100644
--- a/apps/plugins/SUBDIRS.app_build
+++ b/apps/plugins/SUBDIRS.app_build
@@ -1,4 +1,11 @@
1/* For all targets with a bitmap display */ 1#ifndef HAVE_TOUCHSCREEN
2/* This is for devices having a keypad, running RockBox as an application */
3#include "SUBDIRS"
4
5#else
6/* For all targets with a bitmap display and a touchscreen
7 * In fact, most of the plugins aren't supposed to be used on a touch(mouse) device
8 */
2#ifdef HAVE_LCD_BITMAP 9#ifdef HAVE_LCD_BITMAP
3 10
4#ifdef HAVE_TAGCACHE 11#ifdef HAVE_TAGCACHE
@@ -15,3 +22,4 @@ mikmod
15#endif 22#endif
16 23
17#endif /* CONFIG_CODEC == SWCODEC */ 24#endif /* CONFIG_CODEC == SWCODEC */
25#endif /* HAVE_TOUCHSCREEN */ \ No newline at end of file
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c
index a16302e8b0..be509cffcb 100644
--- a/apps/plugins/battery_bench.c
+++ b/apps/plugins/battery_bench.c
@@ -125,7 +125,8 @@
125#define BATTERY_ON_TXT "SELECT - start" 125#define BATTERY_ON_TXT "SELECT - start"
126#define BATTERY_OFF_TXT "POWER" 126#define BATTERY_OFF_TXT "POWER"
127 127
128#elif CONFIG_KEYPAD == GIGABEAT_S_PAD 128#elif CONFIG_KEYPAD == GIGABEAT_S_PAD \
129 || CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
129 130
130#define BATTERY_ON BUTTON_SELECT 131#define BATTERY_ON BUTTON_SELECT
131#define BATTERY_OFF BUTTON_BACK 132#define BATTERY_OFF BUTTON_BACK
diff --git a/apps/plugins/blackjack.c b/apps/plugins/blackjack.c
index 0c35306cfc..ab4da37b0a 100644
--- a/apps/plugins/blackjack.c
+++ b/apps/plugins/blackjack.c
@@ -466,6 +466,22 @@ enum {
466#define BJACK_RIGHT BUTTON_RIGHT 466#define BJACK_RIGHT BUTTON_RIGHT
467#define BJACK_LEFT BUTTON_LEFT 467#define BJACK_LEFT BUTTON_LEFT
468 468
469#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
470#define BJACK_SELECT_NAME "SELECT"
471#define BJACK_STAY_NAME "MENU"
472#define BJACK_QUIT_NAME "BACK"
473#define BJACK_DOUBLE_NAME "USER"
474#define BJACK_SELECT BUTTON_SELECT
475#define BJACK_QUIT BUTTON_BACK
476#define BJACK_MAX (BUTTON_LEFT|BUTTON_UP)
477#define BJACK_MIN (BUTTON_RIGHT|BUTTON_DOWN)
478#define BJACK_STAY BUTTON_MENU
479#define BJACK_DOUBLEDOWN BUTTON_USER
480#define BJACK_UP BUTTON_UP
481#define BJACK_DOWN BUTTON_DOWN
482#define BJACK_RIGHT BUTTON_RIGHT
483#define BJACK_LEFT BUTTON_LEFT
484
469#else 485#else
470#error No keymap defined! 486#error No keymap defined!
471#endif 487#endif
diff --git a/apps/plugins/bounce.c b/apps/plugins/bounce.c
index 6880e269e2..5bd81b7fed 100644
--- a/apps/plugins/bounce.c
+++ b/apps/plugins/bounce.c
@@ -127,7 +127,8 @@
127#define BOUNCE_QUIT BUTTON_POWER 127#define BOUNCE_QUIT BUTTON_POWER
128#define BOUNCE_MODE BUTTON_PLAY 128#define BOUNCE_MODE BUTTON_PLAY
129 129
130#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) 130#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) \
131 || (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
131#define BOUNCE_LEFT BUTTON_LEFT 132#define BOUNCE_LEFT BUTTON_LEFT
132#define BOUNCE_RIGHT BUTTON_RIGHT 133#define BOUNCE_RIGHT BUTTON_RIGHT
133#define BOUNCE_UP BUTTON_UP 134#define BOUNCE_UP BUTTON_UP
diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c
index c362ffe702..dd3903eb26 100644
--- a/apps/plugins/brickmania.c
+++ b/apps/plugins/brickmania.c
@@ -158,7 +158,8 @@ CONFIG_KEYPAD == SANSA_CONNECT_PAD
158#define UP BUTTON_SCROLL_UP 158#define UP BUTTON_SCROLL_UP
159#define DOWN BUTTON_SCROLL_DOWN 159#define DOWN BUTTON_SCROLL_DOWN
160 160
161#elif CONFIG_KEYPAD == GIGABEAT_S_PAD 161#elif CONFIG_KEYPAD == GIGABEAT_S_PAD \
162 || CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
162#define QUIT BUTTON_BACK 163#define QUIT BUTTON_BACK
163#define LEFT BUTTON_LEFT 164#define LEFT BUTTON_LEFT
164#define RIGHT BUTTON_RIGHT 165#define RIGHT BUTTON_RIGHT
diff --git a/apps/plugins/calculator.c b/apps/plugins/calculator.c
index 8288f34c28..77c7a5588d 100644
--- a/apps/plugins/calculator.c
+++ b/apps/plugins/calculator.c
@@ -431,6 +431,17 @@ F3: equal to "="
431#define CALCULATOR_CALC BUTTON_NEXT 431#define CALCULATOR_CALC BUTTON_NEXT
432#define CALCULATOR_CLEAR BUTTON_PREV 432#define CALCULATOR_CLEAR BUTTON_PREV
433 433
434#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
435
436#define CALCULATOR_LEFT BUTTON_LEFT
437#define CALCULATOR_RIGHT BUTTON_RIGHT
438#define CALCULATOR_UP BUTTON_UP
439#define CALCULATOR_DOWN BUTTON_DOWN
440#define CALCULATOR_QUIT BUTTON_BACK
441#define CALCULATOR_INPUT BUTTON_SELECT
442#define CALCULATOR_CALC BUTTON_MENU
443#define CALCULATOR_CLEAR BUTTON_USER
444
434#else 445#else
435#error No keymap defined! 446#error No keymap defined!
436#endif 447#endif
diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c
index d8d8f1ad12..d498b97ffb 100644
--- a/apps/plugins/calendar.c
+++ b/apps/plugins/calendar.c
@@ -308,6 +308,16 @@
308#define CALENDAR_NEXT_MONTH BUTTON_NEXT 308#define CALENDAR_NEXT_MONTH BUTTON_NEXT
309#define CALENDAR_PREV_MONTH BUTTON_PREV 309#define CALENDAR_PREV_MONTH BUTTON_PREV
310 310
311#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
312#define CALENDAR_QUIT BUTTON_BACK
313#define CALENDAR_SELECT BUTTON_SELECT
314#define CALENDAR_NEXT_WEEK BUTTON_DOWN
315#define CALENDAR_PREV_WEEK BUTTON_UP
316#define CALENDAR_NEXT_DAY BUTTON_RIGHT
317#define CALENDAR_PREV_DAY BUTTON_LEFT
318#define CALENDAR_NEXT_MONTH BUTTON_POWER
319#define CALENDAR_PREV_MONTH BUTTON_USER
320
311#else 321#else
312#error "No keypad setting." 322#error "No keypad setting."
313#endif 323#endif
diff --git a/apps/plugins/chessbox/chessbox_pgn.h b/apps/plugins/chessbox/chessbox_pgn.h
index 1627426cef..765e52ec8c 100644
--- a/apps/plugins/chessbox/chessbox_pgn.h
+++ b/apps/plugins/chessbox/chessbox_pgn.h
@@ -422,6 +422,16 @@
422#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT) 422#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
423#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT) 423#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
424 424
425#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
426#define CB_SELECT BUTTON_SELECT
427#define CB_UP BUTTON_UP
428#define CB_DOWN BUTTON_DOWN
429#define CB_LEFT BUTTON_LEFT
430#define CB_RIGHT BUTTON_RIGHT
431#define CB_PLAY BUTTON_USER
432#define CB_LEVEL BUTTON_BACK
433#define CB_MENU BUTTON_MENU
434
425#else 435#else
426#error No keymap defined! 436#error No keymap defined!
427#endif 437#endif
diff --git a/apps/plugins/chessclock.c b/apps/plugins/chessclock.c
index dca5c4040e..94f069d0a0 100644
--- a/apps/plugins/chessclock.c
+++ b/apps/plugins/chessclock.c
@@ -326,6 +326,16 @@
326#define CHC_SETTINGS_OK BUTTON_SELECT 326#define CHC_SETTINGS_OK BUTTON_SELECT
327#define CHC_SETTINGS_CANCEL BUTTON_LEFT 327#define CHC_SETTINGS_CANCEL BUTTON_LEFT
328 328
329#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
330#define CHC_QUIT BUTTON_BACK
331#define CHC_STARTSTOP BUTTON_SELECT
332#define CHC_RESET BUTTON_USER
333#define CHC_MENU BUTTON_MENU
334#define CHC_SETTINGS_INC BUTTON_UP
335#define CHC_SETTINGS_DEC BUTTON_DOWN
336#define CHC_SETTINGS_OK BUTTON_SELECT
337#define CHC_SETTINGS_CANCEL BUTTON_BACK
338
329#else 339#else
330#error No keymap defined! 340#error No keymap defined!
331#endif 341#endif
diff --git a/apps/plugins/chip8.c b/apps/plugins/chip8.c
index 97d8351fe9..470a8e4c89 100644
--- a/apps/plugins/chip8.c
+++ b/apps/plugins/chip8.c
@@ -1193,6 +1193,18 @@ CONFIG_KEYPAD == MROBE500_PAD
1193#define CHIP8_KEY8 BUTTON_VOL_DOWN 1193#define CHIP8_KEY8 BUTTON_VOL_DOWN
1194#define CHIP8_KEY9 BUTTON_VOL_UP 1194#define CHIP8_KEY9 BUTTON_VOL_UP
1195 1195
1196#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
1197#define CHIP8_OFF (BUTTON_BACK|BUTTON_REPEAT)
1198#define CHIP8_KEY1 BUTTON_MENU
1199#define CHIP8_KEY2 BUTTON_UP
1200#define CHIP8_KEY3 BUTTON_DOWN
1201#define CHIP8_KEY4 BUTTON_LEFT
1202#define CHIP8_KEY5 BUTTON_SELECT
1203#define CHIP8_KEY6 BUTTON_RIGHT
1204#define CHIP8_KEY7 BUTTON_BACK
1205#define CHIP8_KEY8 BUTTON_POWER
1206#define CHIP8_KEY9 BUTTON_USER
1207
1196#else 1208#else
1197#error No keymap defined! 1209#error No keymap defined!
1198#endif 1210#endif
diff --git a/apps/plugins/chopper.c b/apps/plugins/chopper.c
index 71ea8f835f..d819da421b 100644
--- a/apps/plugins/chopper.c
+++ b/apps/plugins/chopper.c
@@ -97,7 +97,8 @@ Still To do:
97#define ACTION2 BUTTON_MENU 97#define ACTION2 BUTTON_MENU
98#define ACTIONTEXT "UP" 98#define ACTIONTEXT "UP"
99 99
100#elif CONFIG_KEYPAD == GIGABEAT_S_PAD 100#elif CONFIG_KEYPAD == GIGABEAT_S_PAD \
101 || CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
101#define QUIT BUTTON_BACK 102#define QUIT BUTTON_BACK
102#define ACTION BUTTON_SELECT 103#define ACTION BUTTON_SELECT
103#define ACTION2 BUTTON_MENU 104#define ACTION2 BUTTON_MENU
diff --git a/apps/plugins/clix.c b/apps/plugins/clix.c
index 378e9813e6..06fe0d84e0 100644
--- a/apps/plugins/clix.c
+++ b/apps/plugins/clix.c
@@ -83,7 +83,8 @@
83#define CLIX_BUTTON_UP BUTTON_UP 83#define CLIX_BUTTON_UP BUTTON_UP
84#define CLIX_BUTTON_DOWN BUTTON_DOWN 84#define CLIX_BUTTON_DOWN BUTTON_DOWN
85 85
86#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) 86#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
87 (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
87#define CLIX_BUTTON_QUIT BUTTON_BACK 88#define CLIX_BUTTON_QUIT BUTTON_BACK
88#define CLIX_BUTTON_LEFT BUTTON_LEFT 89#define CLIX_BUTTON_LEFT BUTTON_LEFT
89#define CLIX_BUTTON_RIGHT BUTTON_RIGHT 90#define CLIX_BUTTON_RIGHT BUTTON_RIGHT
diff --git a/apps/plugins/cube.c b/apps/plugins/cube.c
index 7e97eaf569..cecb10e1f2 100644
--- a/apps/plugins/cube.c
+++ b/apps/plugins/cube.c
@@ -329,6 +329,16 @@
329#define CUBE_PAUSE BUTTON_DOWN 329#define CUBE_PAUSE BUTTON_DOWN
330#define CUBE_HIGHSPEED BUTTON_LEFT 330#define CUBE_HIGHSPEED BUTTON_LEFT
331 331
332#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
333#define CUBE_QUIT BUTTON_BACK
334#define CUBE_NEXT BUTTON_RIGHT
335#define CUBE_PREV BUTTON_LEFT
336#define CUBE_INC BUTTON_UP
337#define CUBE_DEC BUTTON_DOWN
338#define CUBE_MODE BUTTON_MENU
339#define CUBE_PAUSE BUTTON_USER
340#define CUBE_HIGHSPEED BUTTON_SELECT
341
332#else 342#else
333#error No keymap defined! 343#error No keymap defined!
334#endif 344#endif
diff --git a/apps/plugins/doom/i_video.c b/apps/plugins/doom/i_video.c
index d12799cac4..9009acc67f 100644
--- a/apps/plugins/doom/i_video.c
+++ b/apps/plugins/doom/i_video.c
@@ -424,6 +424,17 @@ void I_ShutdownGraphics(void)
424#define DOOMBUTTON_ENTER BUTTON_NEXT 424#define DOOMBUTTON_ENTER BUTTON_NEXT
425#define DOOMBUTTON_WEAPON BUTTON_PREV 425#define DOOMBUTTON_WEAPON BUTTON_PREV
426 426
427#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
428#define DOOMBUTTON_UP BUTTON_UP
429#define DOOMBUTTON_DOWN BUTTON_DOWN
430#define DOOMBUTTON_LEFT BUTTON_LEFT
431#define DOOMBUTTON_RIGHT BUTTON_RIGHT
432#define DOOMBUTTON_SHOOT BUTTON_SELECT
433#define DOOMBUTTON_OPEN BUTTON_MENU
434#define DOOMBUTTON_ESC BUTTON_BACK
435#define DOOMBUTTON_ENTER BUTTON_POWER
436#define DOOMBUTTON_WEAPON BUTTON_USER
437
427#else 438#else
428#error Keymap not defined! 439#error Keymap not defined!
429#endif 440#endif
diff --git a/apps/plugins/fft/fft.c b/apps/plugins/fft/fft.c
index 89205503e7..b2ef8d8e33 100644
--- a/apps/plugins/fft/fft.c
+++ b/apps/plugins/fft/fft.c
@@ -257,6 +257,15 @@ GREY_INFO_STRUCT
257# define FFT_FREQ_SCALE BUTTON_DOWN 257# define FFT_FREQ_SCALE BUTTON_DOWN
258# define FFT_QUIT BUTTON_POWER 258# define FFT_QUIT BUTTON_POWER
259 259
260#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
261# define FFT_PREV_GRAPH BUTTON_LEFT
262# define FFT_NEXT_GRAPH BUTTON_RIGHT
263# define FFT_ORIENTATION BUTTON_USER
264# define FFT_WINDOW BUTTON_MENU
265# define FFT_AMP_SCALE BUTTON_SELECT
266# define FFT_FREQ_SCALE BUTTON_DOWN
267# define FFT_QUIT BUTTON_BACK
268
260#else 269#else
261#error No keymap defined! 270#error No keymap defined!
262#endif 271#endif
diff --git a/apps/plugins/fireworks.c b/apps/plugins/fireworks.c
index e3a391035a..52b11b7079 100644
--- a/apps/plugins/fireworks.c
+++ b/apps/plugins/fireworks.c
@@ -63,7 +63,8 @@
63 63
64#elif (CONFIG_KEYPAD == GIGABEAT_PAD) || \ 64#elif (CONFIG_KEYPAD == GIGABEAT_PAD) || \
65 (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \ 65 (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
66 (CONFIG_KEYPAD == MROBE100_PAD) 66 (CONFIG_KEYPAD == MROBE100_PAD) || \
67 (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
67#define BTN_MENU BUTTON_MENU 68#define BTN_MENU BUTTON_MENU
68#define BTN_FIRE BUTTON_SELECT 69#define BTN_FIRE BUTTON_SELECT
69 70
diff --git a/apps/plugins/flipit.c b/apps/plugins/flipit.c
index ffc691c720..da5a9e8c6b 100644
--- a/apps/plugins/flipit.c
+++ b/apps/plugins/flipit.c
@@ -380,6 +380,18 @@
380#define FLIPIT_STEP_BY_STEP BUTTON_NEXT 380#define FLIPIT_STEP_BY_STEP BUTTON_NEXT
381#define FLIPIT_TOGGLE BUTTON_SELECT 381#define FLIPIT_TOGGLE BUTTON_SELECT
382 382
383#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
384
385#define FLIPIT_LEFT BUTTON_LEFT
386#define FLIPIT_RIGHT BUTTON_RIGHT
387#define FLIPIT_UP BUTTON_UP
388#define FLIPIT_DOWN BUTTON_DOWN
389#define FLIPIT_QUIT BUTTON_BACK
390#define FLIPIT_SHUFFLE BUTTON_MENU
391#define FLIPIT_SOLVE BUTTON_USER
392#define FLIPIT_STEP_BY_STEP BUTTON_POWER
393#define FLIPIT_TOGGLE BUTTON_SELECT
394
383#else 395#else
384#error No keymap defined! 396#error No keymap defined!
385#endif 397#endif
diff --git a/apps/plugins/fractals/fractal.h b/apps/plugins/fractals/fractal.h
index 76f3229399..0d1aff3078 100644
--- a/apps/plugins/fractals/fractal.h
+++ b/apps/plugins/fractals/fractal.h
@@ -378,6 +378,18 @@
378#define FRACTAL_PRECISION_DEC BUTTON_VOL_DOWN 378#define FRACTAL_PRECISION_DEC BUTTON_VOL_DOWN
379#define FRACTAL_RESET BUTTON_PREV 379#define FRACTAL_RESET BUTTON_PREV
380 380
381#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
382#define FRACTAL_QUIT BUTTON_BACK
383#define FRACTAL_UP BUTTON_UP
384#define FRACTAL_DOWN BUTTON_DOWN
385#define FRACTAL_LEFT BUTTON_LEFT
386#define FRACTAL_RIGHT BUTTON_RIGHT
387#define FRACTAL_ZOOM_IN (BUTTON_MENU|BUTTON_REL)
388#define FRACTAL_ZOOM_OUT (BUTTON_USER|BUTTON_REL)
389#define FRACTAL_PRECISION_INC (BUTTON_MENU|BUTTON_REPEAT)
390#define FRACTAL_PRECISION_DEC (BUTTON_USER|BUTTON_REPEAT)
391#define FRACTAL_RESET BUTTON_POWER
392
381#else 393#else
382#error No keymap defined! 394#error No keymap defined!
383#endif 395#endif
diff --git a/apps/plugins/goban/goban.h b/apps/plugins/goban/goban.h
index d03bc82474..20940d74f0 100644
--- a/apps/plugins/goban/goban.h
+++ b/apps/plugins/goban/goban.h
@@ -364,6 +364,16 @@
364#define GBN_BUTTON_PLAY BUTTON_SELECT 364#define GBN_BUTTON_PLAY BUTTON_SELECT
365#define GBN_BUTTON_MENU BUTTON_POWER 365#define GBN_BUTTON_MENU BUTTON_POWER
366 366
367#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
368#define GBN_BUTTON_UP BUTTON_UP
369#define GBN_BUTTON_DOWN BUTTON_DOWN
370#define GBN_BUTTON_LEFT BUTTON_LEFT
371#define GBN_BUTTON_RIGHT BUTTON_RIGHT
372#define GBN_BUTTON_RETREAT BUTTON_BACK
373#define GBN_BUTTON_ADVANCE BUTTON_USER
374#define GBN_BUTTON_PLAY BUTTON_SELECT
375#define GBN_BUTTON_MENU BUTTON_MENU
376
367#else 377#else
368#error Unsupported keypad 378#error Unsupported keypad
369#endif 379#endif
diff --git a/apps/plugins/imageviewer/imageviewer_button.h b/apps/plugins/imageviewer/imageviewer_button.h
index 9f345d83f3..10d239922e 100644
--- a/apps/plugins/imageviewer/imageviewer_button.h
+++ b/apps/plugins/imageviewer/imageviewer_button.h
@@ -379,6 +379,18 @@
379#define IMGVIEW_MENU BUTTON_POWER 379#define IMGVIEW_MENU BUTTON_POWER
380#define IMGVIEW_SLIDE_SHOW BUTTON_NEXT 380#define IMGVIEW_SLIDE_SHOW BUTTON_NEXT
381 381
382#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
383#define IMGVIEW_ZOOM_IN BUTTON_POWER
384#define IMGVIEW_ZOOM_OUT BUTTON_USER
385#define IMGVIEW_UP BUTTON_UP
386#define IMGVIEW_DOWN BUTTON_DOWN
387#define IMGVIEW_LEFT BUTTON_LEFT
388#define IMGVIEW_RIGHT BUTTON_RIGHT
389#define IMGVIEW_NEXT BUTTON_SELECT
390#define IMGVIEW_PREVIOUS 0xFFFFFFA //not used
391#define IMGVIEW_MENU BUTTON_MENU
392#define IMGVIEW_QUIT BUTTON_BACK
393
382#else 394#else
383#error No keymap defined! 395#error No keymap defined!
384#endif 396#endif
diff --git a/apps/plugins/invadrox.c b/apps/plugins/invadrox.c
index 96e04a976f..c52208d3c6 100644
--- a/apps/plugins/invadrox.c
+++ b/apps/plugins/invadrox.c
@@ -122,7 +122,8 @@
122#define RIGHT BUTTON_RIGHT 122#define RIGHT BUTTON_RIGHT
123#define FIRE BUTTON_SELECT 123#define FIRE BUTTON_SELECT
124 124
125#elif CONFIG_KEYPAD == GIGABEAT_PAD 125#elif CONFIG_KEYPAD == GIGABEAT_PAD \
126 || CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
126 127
127#define QUIT BUTTON_POWER 128#define QUIT BUTTON_POWER
128#define LEFT BUTTON_LEFT 129#define LEFT BUTTON_LEFT
diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c
index 4d5a5b6ce9..7d80a536dd 100644
--- a/apps/plugins/jewels.c
+++ b/apps/plugins/jewels.c
@@ -172,7 +172,8 @@ CONFIG_KEYPAD == SANSA_M200_PAD
172#define HK_SELECT "PLAY" 172#define HK_SELECT "PLAY"
173#define HK_CANCEL "POWER" 173#define HK_CANCEL "POWER"
174 174
175#elif CONFIG_KEYPAD == GIGABEAT_S_PAD 175#elif CONFIG_KEYPAD == GIGABEAT_S_PAD || \
176 CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
176#define JEWELS_UP BUTTON_UP 177#define JEWELS_UP BUTTON_UP
177#define JEWELS_DOWN BUTTON_DOWN 178#define JEWELS_DOWN BUTTON_DOWN
178#define JEWELS_LEFT BUTTON_LEFT 179#define JEWELS_LEFT BUTTON_LEFT
diff --git a/apps/plugins/lamp.c b/apps/plugins/lamp.c
index d9ad70b946..583e2753fa 100644
--- a/apps/plugins/lamp.c
+++ b/apps/plugins/lamp.c
@@ -57,7 +57,8 @@
57# define LAMP_UP BUTTON_UP 57# define LAMP_UP BUTTON_UP
58# define LAMP_DOWN BUTTON_DOWN 58# define LAMP_DOWN BUTTON_DOWN
59 59
60#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) 60#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
61 (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
61# define LAMP_LEFT BUTTON_LEFT 62# define LAMP_LEFT BUTTON_LEFT
62# define LAMP_RIGHT BUTTON_RIGHT 63# define LAMP_RIGHT BUTTON_RIGHT
63# define LAMP_UP BUTTON_UP 64# define LAMP_UP BUTTON_UP
diff --git a/apps/plugins/lib/pluginlib_actions.c b/apps/plugins/lib/pluginlib_actions.c
index 0a2f12da50..44a2cd8c03 100644
--- a/apps/plugins/lib/pluginlib_actions.c
+++ b/apps/plugins/lib/pluginlib_actions.c
@@ -116,7 +116,8 @@ const struct button_mapping pla_main_ctx[] =
116 || (CONFIG_KEYPAD == SANSA_FUZE_PAD) \ 116 || (CONFIG_KEYPAD == SANSA_FUZE_PAD) \
117 || (CONFIG_KEYPAD == SAMSUNG_YH_PAD) \ 117 || (CONFIG_KEYPAD == SAMSUNG_YH_PAD) \
118 || (CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD) \ 118 || (CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD) \
119 || (CONFIG_KEYPAD == SANSA_CONNECT_PAD)) 119 || (CONFIG_KEYPAD == SANSA_CONNECT_PAD) \
120 || (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD))
120 { PLA_UP, BUTTON_UP, BUTTON_NONE }, 121 { PLA_UP, BUTTON_UP, BUTTON_NONE },
121 { PLA_DOWN, BUTTON_DOWN, BUTTON_NONE }, 122 { PLA_DOWN, BUTTON_DOWN, BUTTON_NONE },
122 { PLA_LEFT, BUTTON_LEFT, BUTTON_NONE }, 123 { PLA_LEFT, BUTTON_LEFT, BUTTON_NONE },
@@ -278,7 +279,8 @@ const struct button_mapping pla_main_ctx[] =
278 {PLA_SELECT, BUTTON_SELECT, BUTTON_NONE}, 279 {PLA_SELECT, BUTTON_SELECT, BUTTON_NONE},
279 {PLA_SELECT_REL, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT}, 280 {PLA_SELECT_REL, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT},
280 {PLA_SELECT_REPEAT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_NONE}, 281 {PLA_SELECT_REPEAT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_NONE},
281#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) 282#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) \
283 || (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
282 {PLA_CANCEL, BUTTON_BACK, BUTTON_NONE}, 284 {PLA_CANCEL, BUTTON_BACK, BUTTON_NONE},
283 {PLA_EXIT, BUTTON_MENU, BUTTON_NONE}, 285 {PLA_EXIT, BUTTON_MENU, BUTTON_NONE},
284 {PLA_SELECT, BUTTON_SELECT, BUTTON_NONE}, 286 {PLA_SELECT, BUTTON_SELECT, BUTTON_NONE},
diff --git a/apps/plugins/lib/simple_viewer.c b/apps/plugins/lib/simple_viewer.c
index 16cbcb35de..06cc9c1a71 100644
--- a/apps/plugins/lib/simple_viewer.c
+++ b/apps/plugins/lib/simple_viewer.c
@@ -25,6 +25,7 @@
25#include "simple_viewer.h" 25#include "simple_viewer.h"
26#include <ctype.h> 26#include <ctype.h>
27 27
28
28struct view_info { 29struct view_info {
29#ifdef HAVE_LCD_BITMAP 30#ifdef HAVE_LCD_BITMAP
30 struct font* pf; 31 struct font* pf;
diff --git a/apps/plugins/logo.c b/apps/plugins/logo.c
index d651c2f634..be163f566e 100644
--- a/apps/plugins/logo.c
+++ b/apps/plugins/logo.c
@@ -123,7 +123,8 @@ const unsigned char rockbox16x7[] = {
123#elif CONFIG_KEYPAD == MROBE500_PAD 123#elif CONFIG_KEYPAD == MROBE500_PAD
124#define LP_QUIT BUTTON_POWER 124#define LP_QUIT BUTTON_POWER
125 125
126#elif CONFIG_KEYPAD == GIGABEAT_S_PAD 126#elif CONFIG_KEYPAD == GIGABEAT_S_PAD || \
127 CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
127#define LP_QUIT BUTTON_BACK 128#define LP_QUIT BUTTON_BACK
128#define LP_DEC_X BUTTON_LEFT 129#define LP_DEC_X BUTTON_LEFT
129#define LP_INC_X BUTTON_RIGHT 130#define LP_INC_X BUTTON_RIGHT
diff --git a/apps/plugins/lua/strcspn.c b/apps/plugins/lua/strcspn.c
index 7af6f693eb..0a19eaebf2 100644
--- a/apps/plugins/lua/strcspn.c
+++ b/apps/plugins/lua/strcspn.c
@@ -1,5 +1,6 @@
1#include "rocklibc.h" 1#include "rocklibc.h"
2 2
3#undef strcspn
3size_t strcspn(const char *s, const char *reject) 4size_t strcspn(const char *s, const char *reject)
4{ 5{
5 size_t l=0; 6 size_t l=0;
diff --git a/apps/plugins/lua/strpbrk.c b/apps/plugins/lua/strpbrk.c
index f416f391ae..1e0491f779 100644
--- a/apps/plugins/lua/strpbrk.c
+++ b/apps/plugins/lua/strpbrk.c
@@ -1,5 +1,6 @@
1#include "rocklibc.h" 1#include "rocklibc.h"
2 2
3#undef strpbrk
3char *strpbrk(const char *s, const char *accept) { 4char *strpbrk(const char *s, const char *accept) {
4 register int i,l=strlen(accept); 5 register int i,l=strlen(accept);
5 for (; *s; s++) 6 for (; *s; s++)
diff --git a/apps/plugins/matrix.c b/apps/plugins/matrix.c
index 1a1008073c..10b8ce578d 100644
--- a/apps/plugins/matrix.c
+++ b/apps/plugins/matrix.c
@@ -101,7 +101,8 @@
101#define MATRIX_SLEEP_LESS BUTTON_DOWN 101#define MATRIX_SLEEP_LESS BUTTON_DOWN
102#define MATRIX_PAUSE BUTTON_SELECT 102#define MATRIX_PAUSE BUTTON_SELECT
103 103
104#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) 104#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
105 (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
105#define MATRIX_EXIT BUTTON_BACK 106#define MATRIX_EXIT BUTTON_BACK
106#define MATRIX_SLEEP_MORE BUTTON_UP 107#define MATRIX_SLEEP_MORE BUTTON_UP
107#define MATRIX_SLEEP_LESS BUTTON_DOWN 108#define MATRIX_SLEEP_LESS BUTTON_DOWN
diff --git a/apps/plugins/midi/midiplay.c b/apps/plugins/midi/midiplay.c
index 1b5d18465b..ace7290a12 100644
--- a/apps/plugins/midi/midiplay.c
+++ b/apps/plugins/midi/midiplay.c
@@ -233,6 +233,14 @@
233#define BTN_DOWN BUTTON_DOWN 233#define BTN_DOWN BUTTON_DOWN
234#define BTN_PLAY BUTTON_SELECT 234#define BTN_PLAY BUTTON_SELECT
235 235
236#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
237#define BTN_QUIT BUTTON_BACK
238#define BTN_RIGHT BUTTON_RIGHT
239#define BTN_LEFT BUTTON_LEFT
240#define BTN_UP BUTTON_UP
241#define BTN_DOWN BUTTON_DOWN
242#define BTN_PLAY BUTTON_USER
243
236#else 244#else
237#error No keymap defined! 245#error No keymap defined!
238#endif 246#endif
diff --git a/apps/plugins/minesweeper.c b/apps/plugins/minesweeper.c
index ad67b1dd67..e0da928b02 100644
--- a/apps/plugins/minesweeper.c
+++ b/apps/plugins/minesweeper.c
@@ -311,6 +311,16 @@ CONFIG_KEYPAD == MROBE500_PAD
311# define MINESWP_DISCOVER BUTTON_SELECT 311# define MINESWP_DISCOVER BUTTON_SELECT
312# define MINESWP_INFO BUTTON_PREV 312# define MINESWP_INFO BUTTON_PREV
313 313
314#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
315# define MINESWP_LEFT BUTTON_LEFT
316# define MINESWP_RIGHT BUTTON_RIGHT
317# define MINESWP_UP BUTTON_UP
318# define MINESWP_DOWN BUTTON_DOWN
319# define MINESWP_QUIT BUTTON_BACK
320# define MINESWP_TOGGLE BUTTON_USER
321# define MINESWP_DISCOVER BUTTON_SELECT
322# define MINESWP_INFO BUTTON_MENU
323
314#else 324#else
315#error No keymap defined! 325#error No keymap defined!
316#endif 326#endif
diff --git a/apps/plugins/mosaique.c b/apps/plugins/mosaique.c
index ec41c8c02b..87e664e102 100644
--- a/apps/plugins/mosaique.c
+++ b/apps/plugins/mosaique.c
@@ -113,7 +113,8 @@
113#elif CONFIG_KEYPAD == MROBE500_PAD 113#elif CONFIG_KEYPAD == MROBE500_PAD
114#define MOSAIQUE_QUIT BUTTON_POWER 114#define MOSAIQUE_QUIT BUTTON_POWER
115 115
116#elif CONFIG_KEYPAD == GIGABEAT_S_PAD 116#elif CONFIG_KEYPAD == GIGABEAT_S_PAD || \
117 CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
117#define MOSAIQUE_QUIT BUTTON_BACK 118#define MOSAIQUE_QUIT BUTTON_BACK
118#define MOSAIQUE_SPEED BUTTON_SELECT 119#define MOSAIQUE_SPEED BUTTON_SELECT
119#define MOSAIQUE_RESTART BUTTON_MENU 120#define MOSAIQUE_RESTART BUTTON_MENU
diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c
index a70e316f06..567ec5dbc8 100644
--- a/apps/plugins/mp3_encoder.c
+++ b/apps/plugins/mp3_encoder.c
@@ -2394,7 +2394,8 @@ static void get_mp3_filename(const char *wav_name)
2394#define MP3ENC_DONE BUTTON_POWER 2394#define MP3ENC_DONE BUTTON_POWER
2395#define MP3ENC_SELECT BUTTON_SELECT 2395#define MP3ENC_SELECT BUTTON_SELECT
2396 2396
2397#elif CONFIG_KEYPAD == GIGABEAT_PAD 2397#elif CONFIG_KEYPAD == GIGABEAT_PAD || \
2398 CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
2398#define MP3ENC_PREV BUTTON_UP 2399#define MP3ENC_PREV BUTTON_UP
2399#define MP3ENC_NEXT BUTTON_DOWN 2400#define MP3ENC_NEXT BUTTON_DOWN
2400#define MP3ENC_DONE BUTTON_POWER 2401#define MP3ENC_DONE BUTTON_POWER
diff --git a/apps/plugins/mpegplayer/mpeg_settings.c b/apps/plugins/mpegplayer/mpeg_settings.c
index 90b547893e..e9b1c01680 100644
--- a/apps/plugins/mpegplayer/mpeg_settings.c
+++ b/apps/plugins/mpegplayer/mpeg_settings.c
@@ -248,6 +248,14 @@ struct mpeg_settings settings;
248#define MPEG_START_TIME_DOWN BUTTON_DOWN 248#define MPEG_START_TIME_DOWN BUTTON_DOWN
249#define MPEG_START_TIME_EXIT BUTTON_POWER 249#define MPEG_START_TIME_EXIT BUTTON_POWER
250 250
251#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
252#define MPEG_START_TIME_SELECT BUTTON_SELECT
253#define MPEG_START_TIME_LEFT BUTTON_LEFT
254#define MPEG_START_TIME_RIGHT BUTTON_RIGHT
255#define MPEG_START_TIME_UP BUTTON_UP
256#define MPEG_START_TIME_DOWN BUTTON_DOWN
257#define MPEG_START_TIME_EXIT BUTTON_BACK
258
251#else 259#else
252#error No keymap defined! 260#error No keymap defined!
253#endif 261#endif
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c
index e3d9865e12..f73e5f2090 100644
--- a/apps/plugins/mpegplayer/mpegplayer.c
+++ b/apps/plugins/mpegplayer/mpegplayer.c
@@ -362,6 +362,15 @@ CONFIG_KEYPAD == SANSA_M200_PAD
362#define MPEG_RW BUTTON_LEFT 362#define MPEG_RW BUTTON_LEFT
363#define MPEG_FF BUTTON_RIGHT 363#define MPEG_FF BUTTON_RIGHT
364 364
365#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
366#define MPEG_MENU BUTTON_MENU
367#define MPEG_PAUSE BUTTON_SELECT
368#define MPEG_STOP BUTTON_POWER
369#define MPEG_VOLDOWN BUTTON_DOWN
370#define MPEG_VOLUP BUTTON_UP
371#define MPEG_RW BUTTON_LEFT
372#define MPEG_FF BUTTON_RIGHT
373
365#else 374#else
366#error No keymap defined! 375#error No keymap defined!
367#endif 376#endif
diff --git a/apps/plugins/oscilloscope.c b/apps/plugins/oscilloscope.c
index 4469a92e12..0b1687da5c 100644
--- a/apps/plugins/oscilloscope.c
+++ b/apps/plugins/oscilloscope.c
@@ -342,6 +342,17 @@
342#define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP 342#define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
343#define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN 343#define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
344 344
345#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
346#define OSCILLOSCOPE_QUIT BUTTON_BACK
347#define OSCILLOSCOPE_DRAWMODE BUTTON_USER
348#define OSCILLOSCOPE_ADVMODE BUTTON_MENU
349#define OSCILLOSCOPE_ORIENTATION BUTTON_POWER
350#define OSCILLOSCOPE_PAUSE BUTTON_SELECT
351#define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
352#define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
353#define OSCILLOSCOPE_VOL_UP BUTTON_UP
354#define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
355
345#else 356#else
346#error No keymap defined! 357#error No keymap defined!
347#endif 358#endif
diff --git a/apps/plugins/pacbox/pacbox.h b/apps/plugins/pacbox/pacbox.h
index 3c906ac0aa..0183b0c3f6 100644
--- a/apps/plugins/pacbox/pacbox.h
+++ b/apps/plugins/pacbox/pacbox.h
@@ -265,6 +265,17 @@
265#define PACMAN_COIN BUTTON_VOL_DOWN 265#define PACMAN_COIN BUTTON_VOL_DOWN
266#define PACMAN_MENU BUTTON_POWER 266#define PACMAN_MENU BUTTON_POWER
267 267
268#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
269
270#define PACMAN_UP BUTTON_UP
271#define PACMAN_DOWN BUTTON_DOWN
272#define PACMAN_LEFT BUTTON_LEFT
273#define PACMAN_RIGHT BUTTON_RIGHT
274#define PACMAN_1UP BUTTON_SELECT
275#define PACMAN_2UP BUTTON_POWER
276#define PACMAN_COIN BUTTON_USER
277#define PACMAN_MENU BUTTON_MENU
278
268#else 279#else
269 280
270#error Keymap not defined! 281#error Keymap not defined!
diff --git a/apps/plugins/pdbox/pdbox.h b/apps/plugins/pdbox/pdbox.h
index 56ad568a3b..b53e15f94e 100644
--- a/apps/plugins/pdbox/pdbox.h
+++ b/apps/plugins/pdbox/pdbox.h
@@ -89,7 +89,9 @@ float rb_atan(float);
89float rb_atan2(float, float); 89float rb_atan2(float, float);
90float rb_sinh(float); 90float rb_sinh(float);
91float rb_tan(float); 91float rb_tan(float);
92#ifndef SIMULATOR 92//#ifndef SIMULATOR
93/*FIXME: is it a correct replacement??? */
94#if !(CONFIG_PLATFORM & PLATFORM_HOSTED)
93typedef struct 95typedef struct
94{ 96{
95 int quot; 97 int quot;
@@ -163,9 +165,12 @@ void pd_init(void);
163#define atoi rb->atoi 165#define atoi rb->atoi
164#define write rb->write 166#define write rb->write
165 167
168#undef strncat
166#define strncat rb_strncat 169#define strncat rb_strncat
167 170
168#ifndef SIMULATOR 171//#ifndef SIMULATOR
172/*FIXME: is it a correct replacement??? */
173#if !(CONFIG_PLATFORM & PLATFORM_HOSTED)
169#define floor rb_floor 174#define floor rb_floor
170#define atof rb_atof 175#define atof rb_atof
171#define atol rb_atol 176#define atol rb_atol
@@ -186,6 +191,7 @@ void pd_init(void);
186#endif 191#endif
187 192
188#define ftoan rb_ftoan 193#define ftoan rb_ftoan
194#undef strtok_r
189#define strtok_r rb->strtok_r 195#define strtok_r rb->strtok_r
190#define strstr rb->strcasestr 196#define strstr rb->strcasestr
191 197
@@ -282,6 +288,15 @@ enum pd_key_id
282 #define PDPOD_WHEELLEFT (BUTTON_SCROLL_BACK) 288 #define PDPOD_WHEELLEFT (BUTTON_SCROLL_BACK)
283 #define PDPOD_WHEELRIGHT (BUTTON_SCROLL_FWD) 289 #define PDPOD_WHEELRIGHT (BUTTON_SCROLL_FWD)
284 #define PDPOD_ACTION (BUTTON_SELECT) 290 #define PDPOD_ACTION (BUTTON_SELECT)
291#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
292 #define PDPOD_QUIT BUTTON_BACK
293 #define PDPOD_PLAY BUTTON_USER
294 #define PDPOD_PREVIOUS BUTTON_LEFT
295 #define PDPOD_NEXT BUTTON_RIGHT
296 #define PDPOD_MENU BUTTON_MENU
297 #define PDPOD_WHEELLEFT BUTTON_UP
298 #define PDPOD_WHEELRIGHT BUTTON_DOWN
299 #define PDPOD_ACTION BUTTON_SELECT
285#else 300#else
286 #warning "No keys defined for this architecture!" 301 #warning "No keys defined for this architecture!"
287#endif 302#endif
diff --git a/apps/plugins/pegbox.c b/apps/plugins/pegbox.c
index 3eb6008f76..479f7c5ec2 100644
--- a/apps/plugins/pegbox.c
+++ b/apps/plugins/pegbox.c
@@ -510,6 +510,24 @@ CONFIG_KEYPAD == MROBE500_PAD
510#define LVL_DOWN_TEXT "PREV" 510#define LVL_DOWN_TEXT "PREV"
511#define SELECT_TEXT "SELECT" 511#define SELECT_TEXT "SELECT"
512 512
513#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
514#define PEGBOX_SELECT BUTTON_SELECT
515#define PEGBOX_QUIT BUTTON_BACK
516#define PEGBOX_RESTART BUTTON_MENU
517#define PEGBOX_LVL_UP BUTTON_USER
518#define PEGBOX_LVL_DOWN BUTTON_POWER
519#define PEGBOX_UP BUTTON_UP
520#define PEGBOX_DOWN BUTTON_DOWN
521#define PEGBOX_RIGHT BUTTON_RIGHT
522#define PEGBOX_LEFT BUTTON_LEFT
523
524#define SAVE_TEXT "PLAYPAUSE"
525#define QUIT_TEXT "POWER"
526#define RESTART_TEXT "BACK"
527#define LVL_UP_TEXT "Vol+"
528#define LVL_DOWN_TEXT "Vol-"
529#define SELECT_TEXT "SELECT"
530
513#else 531#else
514#error Unsupported keymap! 532#error Unsupported keymap!
515#endif 533#endif
diff --git a/apps/plugins/pong.c b/apps/plugins/pong.c
index d3875f39e4..430b688f1f 100644
--- a/apps/plugins/pong.c
+++ b/apps/plugins/pong.c
@@ -244,6 +244,14 @@ CONFIG_KEYPAD == MROBE500_PAD
244#define PONG_RIGHT_UP BUTTON_UP 244#define PONG_RIGHT_UP BUTTON_UP
245#define PONG_RIGHT_DOWN BUTTON_RIGHT 245#define PONG_RIGHT_DOWN BUTTON_RIGHT
246 246
247#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
248#define PONG_QUIT BUTTON_BACK
249#define PONG_PAUSE BUTTON_SELECT
250#define PONG_LEFT_UP BUTTON_UP
251#define PONG_LEFT_DOWN BUTTON_DOWN
252#define PONG_RIGHT_UP BUTTON_MENU
253#define PONG_RIGHT_DOWN BUTTON_POWER
254
247#else 255#else
248#error No keymap defined! 256#error No keymap defined!
249#endif 257#endif
diff --git a/apps/plugins/reversi/reversi-gui.h b/apps/plugins/reversi/reversi-gui.h
index a36efe51cb..c0d6183c2f 100644
--- a/apps/plugins/reversi/reversi-gui.h
+++ b/apps/plugins/reversi/reversi-gui.h
@@ -252,6 +252,15 @@
252#define REVERSI_BUTTON_MAKE_MOVE BUTTON_PLAYPAUSE 252#define REVERSI_BUTTON_MAKE_MOVE BUTTON_PLAYPAUSE
253#define REVERSI_BUTTON_MENU BUTTON_BACK 253#define REVERSI_BUTTON_MENU BUTTON_BACK
254 254
255#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
256#define REVERSI_BUTTON_QUIT BUTTON_BACK
257#define REVERSI_BUTTON_UP BUTTON_UP
258#define REVERSI_BUTTON_DOWN BUTTON_DOWN
259#define REVERSI_BUTTON_LEFT BUTTON_LEFT
260#define REVERSI_BUTTON_RIGHT BUTTON_RIGHT
261#define REVERSI_BUTTON_MAKE_MOVE BUTTON_SELECT
262#define REVERSI_BUTTON_MENU BUTTON_MENU
263
255#else 264#else
256#error No keymap defined! 265#error No keymap defined!
257#endif 266#endif
diff --git a/apps/plugins/rockblox.c b/apps/plugins/rockblox.c
index 674b14ed83..c23c6b11cb 100644
--- a/apps/plugins/rockblox.c
+++ b/apps/plugins/rockblox.c
@@ -379,6 +379,18 @@
379#define ROCKBLOX_DROP BUTTON_SELECT 379#define ROCKBLOX_DROP BUTTON_SELECT
380#define ROCKBLOX_RESTART BUTTON_VOL_DOWN 380#define ROCKBLOX_RESTART BUTTON_VOL_DOWN
381 381
382#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
383
384#define ROCKBLOX_OFF BUTTON_BACK
385#define ROCKBLOX_ROTATE_CCW BUTTON_POWER
386#define ROCKBLOX_ROTATE_CW BUTTON_MENU
387#define ROCKBLOX_ROTATE BUTTON_UP
388#define ROCKBLOX_DOWN BUTTON_DOWN
389#define ROCKBLOX_LEFT BUTTON_LEFT
390#define ROCKBLOX_RIGHT BUTTON_RIGHT
391#define ROCKBLOX_DROP BUTTON_SELECT
392#define ROCKBLOX_RESTART BUTTON_USER
393
382#else 394#else
383#error No keymap defined! 395#error No keymap defined!
384#endif 396#endif
diff --git a/apps/plugins/rockblox1d.c b/apps/plugins/rockblox1d.c
index 49219c2eba..5b6e812abf 100644
--- a/apps/plugins/rockblox1d.c
+++ b/apps/plugins/rockblox1d.c
@@ -69,7 +69,8 @@
69#define ONEDROCKBLOX_DOWN BUTTON_PLAY 69#define ONEDROCKBLOX_DOWN BUTTON_PLAY
70#define ONEDROCKBLOX_QUIT BUTTON_POWER 70#define ONEDROCKBLOX_QUIT BUTTON_POWER
71 71
72#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) 72#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
73 (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
73#define ONEDROCKBLOX_DOWN BUTTON_SELECT 74#define ONEDROCKBLOX_DOWN BUTTON_SELECT
74#define ONEDROCKBLOX_QUIT BUTTON_BACK 75#define ONEDROCKBLOX_QUIT BUTTON_BACK
75 76
diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c
index 37f0566b21..bc73abee92 100644
--- a/apps/plugins/rockboy/rockboy.c
+++ b/apps/plugins/rockboy/rockboy.c
@@ -342,6 +342,18 @@ static void setoptions (void)
342 options.SELECT = BUTTON_NEXT; 342 options.SELECT = BUTTON_NEXT;
343 options.MENU = BUTTON_SELECT; 343 options.MENU = BUTTON_SELECT;
344 344
345#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
346 options.UP = BUTTON_UP;
347 options.DOWN = BUTTON_DOWN;
348 options.LEFT = BUTTON_LEFT;
349 options.RIGHT = BUTTON_RIGHT;
350
351 options.A = BUTTON_SELECT;
352 options.B = BUTTON_BACK;
353 options.START = BUTTON_POWER;
354 options.SELECT = BUTTON_USER;
355 options.MENU = BUTTON_MENU;
356
345#else 357#else
346#error No Keymap Defined! 358#error No Keymap Defined!
347#endif 359#endif
diff --git a/apps/plugins/rockboy/rockmacros.h b/apps/plugins/rockboy/rockmacros.h
index 724a0fb96d..87e570b55a 100644
--- a/apps/plugins/rockboy/rockmacros.h
+++ b/apps/plugins/rockboy/rockmacros.h
@@ -23,8 +23,6 @@
23 23
24#include "plugin.h" 24#include "plugin.h"
25 25
26#include "autoconf.h"
27
28#define malloc(a) my_malloc(a) 26#define malloc(a) my_malloc(a)
29void *my_malloc(size_t size); 27void *my_malloc(size_t size);
30 28
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c
index 7f16bf2763..eeca916d1d 100644
--- a/apps/plugins/rockpaint.c
+++ b/apps/plugins/rockpaint.c
@@ -243,6 +243,17 @@
243#define ROCKPAINT_LEFT BUTTON_LEFT 243#define ROCKPAINT_LEFT BUTTON_LEFT
244#define ROCKPAINT_RIGHT BUTTON_RIGHT 244#define ROCKPAINT_RIGHT BUTTON_RIGHT
245 245
246#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
247#define ROCKPAINT_QUIT BUTTON_BACK
248#define ROCKPAINT_DRAW BUTTON_SELECT
249#define ROCKPAINT_MENU BUTTON_MENU
250#define ROCKPAINT_TOOLBAR BUTTON_USER
251#define ROCKPAINT_TOOLBAR2 ( BUTTON_USER | BUTTON_REPEAT )
252#define ROCKPAINT_UP BUTTON_UP
253#define ROCKPAINT_DOWN BUTTON_DOWN
254#define ROCKPAINT_LEFT BUTTON_LEFT
255#define ROCKPAINT_RIGHT BUTTON_RIGHT
256
246#else 257#else
247#error "Please define keys for this keypad" 258#error "Please define keys for this keypad"
248#endif 259#endif
diff --git a/apps/plugins/sliding_puzzle.c b/apps/plugins/sliding_puzzle.c
index 653099a547..a176f75c91 100644
--- a/apps/plugins/sliding_puzzle.c
+++ b/apps/plugins/sliding_puzzle.c
@@ -136,7 +136,8 @@
136#define PUZZLE_SHUFFLE BUTTON_REW 136#define PUZZLE_SHUFFLE BUTTON_REW
137#define PUZZLE_PICTURE BUTTON_PLAY 137#define PUZZLE_PICTURE BUTTON_PLAY
138 138
139#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) 139#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
140 (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
140#define PUZZLE_QUIT BUTTON_BACK 141#define PUZZLE_QUIT BUTTON_BACK
141#define PUZZLE_LEFT BUTTON_LEFT 142#define PUZZLE_LEFT BUTTON_LEFT
142#define PUZZLE_RIGHT BUTTON_RIGHT 143#define PUZZLE_RIGHT BUTTON_RIGHT
@@ -784,7 +785,8 @@ enum plugin_status plugin_start(
784 rb->lcd_putsxy(0, 18, "[OFF] to stop"); 785 rb->lcd_putsxy(0, 18, "[OFF] to stop");
785 rb->lcd_putsxy(0, 28, "[REW] shuffle"); 786 rb->lcd_putsxy(0, 28, "[REW] shuffle");
786 rb->lcd_putsxy(0, 38, "[PLAY] change pic"); 787 rb->lcd_putsxy(0, 38, "[PLAY] change pic");
787#elif CONFIG_KEYPAD == GIGABEAT_S_PAD 788#elif CONFIG_KEYPAD == GIGABEAT_S_PAD || \
789 CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
788 rb->lcd_putsxy(0, 18, "[BACK] to stop"); 790 rb->lcd_putsxy(0, 18, "[BACK] to stop");
789 rb->lcd_putsxy(0, 28, "[SELECT] shuffle"); 791 rb->lcd_putsxy(0, 28, "[SELECT] shuffle");
790 rb->lcd_putsxy(0, 38, "[MENU] change pic"); 792 rb->lcd_putsxy(0, 38, "[MENU] change pic");
diff --git a/apps/plugins/snake.c b/apps/plugins/snake.c
index 09e72a5fff..a20376742f 100644
--- a/apps/plugins/snake.c
+++ b/apps/plugins/snake.c
@@ -130,7 +130,8 @@ dir is the current direction of the snake - 0=up, 1=right, 2=down, 3=left;
130#define SNAKE_DOWN BUTTON_SCROLL_DOWN 130#define SNAKE_DOWN BUTTON_SCROLL_DOWN
131#define SNAKE_PLAYPAUSE BUTTON_PLAY 131#define SNAKE_PLAYPAUSE BUTTON_PLAY
132 132
133#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) 133#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
134 (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
134#define SNAKE_QUIT BUTTON_BACK 135#define SNAKE_QUIT BUTTON_BACK
135#define SNAKE_LEFT BUTTON_LEFT 136#define SNAKE_LEFT BUTTON_LEFT
136#define SNAKE_RIGHT BUTTON_RIGHT 137#define SNAKE_RIGHT BUTTON_RIGHT
diff --git a/apps/plugins/snake2.c b/apps/plugins/snake2.c
index 0e7b499271..bd0257d2be 100644
--- a/apps/plugins/snake2.c
+++ b/apps/plugins/snake2.c
@@ -238,7 +238,8 @@ Head and Tail are stored
238#define SNAKE2_PLAYPAUSE BUTTON_FF 238#define SNAKE2_PLAYPAUSE BUTTON_FF
239#define SNAKE2_PLAYPAUSE_TEXT "FF" 239#define SNAKE2_PLAYPAUSE_TEXT "FF"
240 240
241#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) 241#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
242 (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
242#define SNAKE2_LEFT BUTTON_LEFT 243#define SNAKE2_LEFT BUTTON_LEFT
243#define SNAKE2_RIGHT BUTTON_RIGHT 244#define SNAKE2_RIGHT BUTTON_RIGHT
244#define SNAKE2_UP BUTTON_UP 245#define SNAKE2_UP BUTTON_UP
diff --git a/apps/plugins/snow.c b/apps/plugins/snow.c
index 8a2de39707..6371a697da 100644
--- a/apps/plugins/snow.c
+++ b/apps/plugins/snow.c
@@ -67,7 +67,8 @@
67#define SNOW_QUIT (BUTTON_HOME|BUTTON_REPEAT) 67#define SNOW_QUIT (BUTTON_HOME|BUTTON_REPEAT)
68 68
69#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \ 69#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
70(CONFIG_KEYPAD == CREATIVEZVM_PAD) 70(CONFIG_KEYPAD == CREATIVEZVM_PAD) || \
71(CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
71#define SNOW_QUIT BUTTON_BACK 72#define SNOW_QUIT BUTTON_BACK
72 73
73#elif (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) || \ 74#elif (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) || \
diff --git a/apps/plugins/sokoban.c b/apps/plugins/sokoban.c
index ddc95290da..942b101d4c 100644
--- a/apps/plugins/sokoban.c
+++ b/apps/plugins/sokoban.c
@@ -526,6 +526,21 @@
526#define BUTTON_SAVE (BUTTON_SELECT|BUTTON_REPEAT) 526#define BUTTON_SAVE (BUTTON_SELECT|BUTTON_REPEAT)
527#define BUTTON_SAVE_NAME "SELECT LONG" 527#define BUTTON_SAVE_NAME "SELECT LONG"
528 528
529#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
530#define SOKOBAN_LEFT BUTTON_LEFT
531#define SOKOBAN_RIGHT BUTTON_RIGHT
532#define SOKOBAN_UP BUTTON_UP
533#define SOKOBAN_DOWN BUTTON_DOWN
534#define SOKOBAN_MENU BUTTON_MENU
535#define SOKOBAN_UNDO BUTTON_BACK
536#define SOKOBAN_REDO BUTTON_USER
537//#define SOKOBAN_LEVEL_DOWN (BUTTON_POWER|BUTTON_REL)
538//#define SOKOBAN_LEVEL_REPEAT (BUTTON_CENTER|BUTTON_REPEAT)
539//#define SOKOBAN_LEVEL_UP (BUTTON_MENU|BUTTON_REPEAT)
540#define SOKOBAN_PAUSE BUTTON_SELECT
541#define BUTTON_SAVE BUTTON_SELECT
542#define BUTTON_SAVE_NAME "SELECT"
543
529#else 544#else
530#error No keymap defined! 545#error No keymap defined!
531#endif 546#endif
diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c
index 91ef346221..a1e8b7694b 100644
--- a/apps/plugins/solitaire.c
+++ b/apps/plugins/solitaire.c
@@ -544,6 +544,24 @@ CONFIG_KEYPAD == MROBE500_PAD
544# define HK_CUR2STACK "NEXT" 544# define HK_CUR2STACK "NEXT"
545# define HK_REM2STACK "PREV" 545# define HK_REM2STACK "PREV"
546 546
547#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
548# define SOL_QUIT BUTTON_BACK
549# define SOL_UP BUTTON_UP
550# define SOL_DOWN BUTTON_DOWN
551# define SOL_LEFT BUTTON_LEFT
552# define SOL_RIGHT BUTTON_RIGHT
553# define SOL_MOVE_PRE BUTTON_SELECT
554# define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
555# define SOL_DRAW BUTTON_MENU
556# define SOL_REM2CUR (BUTTON_USER | BUTTON_REPEAT)
557# define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
558# define SOL_REM2STACK BUTTON_POWER
559# define HK_MOVE "Select"
560# define HK_DRAW "Menu"
561# define HK_REM2CUR "Long User"
562# define HK_CUR2STACK "Long Select.."
563# define HK_REM2STACK "Power"
564
547#else 565#else
548#error No keymap defined! 566#error No keymap defined!
549#endif 567#endif
diff --git a/apps/plugins/spacerocks.c b/apps/plugins/spacerocks.c
index 0c03a3183b..946d97d075 100644
--- a/apps/plugins/spacerocks.c
+++ b/apps/plugins/spacerocks.c
@@ -278,6 +278,15 @@
278#define AST_RIGHT BUTTON_RIGHT 278#define AST_RIGHT BUTTON_RIGHT
279#define AST_FIRE BUTTON_SELECT 279#define AST_FIRE BUTTON_SELECT
280 280
281#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
282#define AST_PAUSE BUTTON_MENU
283#define AST_QUIT BUTTON_BACK
284#define AST_THRUST BUTTON_UP
285#define AST_HYPERSPACE BUTTON_DOWN
286#define AST_LEFT BUTTON_LEFT
287#define AST_RIGHT BUTTON_RIGHT
288#define AST_FIRE BUTTON_SELECT
289
281#else 290#else
282#error No keymap defined! 291#error No keymap defined!
283#endif 292#endif
diff --git a/apps/plugins/star.c b/apps/plugins/star.c
index 620cddf77e..cf04e02edc 100644
--- a/apps/plugins/star.c
+++ b/apps/plugins/star.c
@@ -480,6 +480,23 @@
480#define STAR_LEVEL_DOWN_NAME "Vol-" 480#define STAR_LEVEL_DOWN_NAME "Vol-"
481#define STAR_LEVEL_REPEAT_NAME "PREV LONG" 481#define STAR_LEVEL_REPEAT_NAME "PREV LONG"
482 482
483#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
484
485#define STAR_QUIT BUTTON_BACK
486#define STAR_LEFT BUTTON_LEFT
487#define STAR_RIGHT BUTTON_RIGHT
488#define STAR_UP BUTTON_UP
489#define STAR_DOWN BUTTON_DOWN
490#define STAR_TOGGLE_CONTROL BUTTON_SELECT
491#define STAR_LEVEL_UP BUTTON_MENU
492#define STAR_LEVEL_DOWN BUTTON_POWER
493#define STAR_LEVEL_REPEAT BUTTON_USER
494#define STAR_TOGGLE_CONTROL_NAME "Select"
495#define STAR_QUIT_NAME "Back"
496#define STAR_LEVEL_UP_NAME "Menu"
497#define STAR_LEVEL_DOWN_NAME "Power"
498#define STAR_LEVEL_REPEAT_NAME "User"
499
483#else 500#else
484#error No keymap defined! 501#error No keymap defined!
485#endif 502#endif
diff --git a/apps/plugins/starfield.c b/apps/plugins/starfield.c
index e3b5634978..c996da9234 100644
--- a/apps/plugins/starfield.c
+++ b/apps/plugins/starfield.c
@@ -78,7 +78,8 @@
78#define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT 78#define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
79#define STARFIELD_TOGGLE_COLOR BUTTON_SELECT 79#define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
80 80
81#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) 81#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
82 (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
82#define STARFIELD_QUIT BUTTON_BACK 83#define STARFIELD_QUIT BUTTON_BACK
83#define STARFIELD_INCREASE_ZMOVE BUTTON_UP 84#define STARFIELD_INCREASE_ZMOVE BUTTON_UP
84#define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN 85#define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
diff --git a/apps/plugins/stats.c b/apps/plugins/stats.c
index c5ff31e2bd..da231b772c 100644
--- a/apps/plugins/stats.c
+++ b/apps/plugins/stats.c
@@ -72,7 +72,8 @@ static bool cancel;
72#define STATS_STOP BUTTON_POWER 72#define STATS_STOP BUTTON_POWER
73#define STATS_STOP_REMOTE BUTTON_RC_DOWN 73#define STATS_STOP_REMOTE BUTTON_RC_DOWN
74 74
75#elif CONFIG_KEYPAD == GIGABEAT_S_PAD 75#elif CONFIG_KEYPAD == GIGABEAT_S_PAD || \
76 CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
76#define STATS_STOP BUTTON_BACK 77#define STATS_STOP BUTTON_BACK
77 78
78#elif CONFIG_KEYPAD == MROBE100_PAD 79#elif CONFIG_KEYPAD == MROBE100_PAD
diff --git a/apps/plugins/stopwatch.c b/apps/plugins/stopwatch.c
index 94785dc352..fd33bb7c03 100644
--- a/apps/plugins/stopwatch.c
+++ b/apps/plugins/stopwatch.c
@@ -263,6 +263,14 @@
263#define STOPWATCH_SCROLL_UP BUTTON_UP 263#define STOPWATCH_SCROLL_UP BUTTON_UP
264#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN 264#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
265 265
266#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
267#define STOPWATCH_QUIT BUTTON_BACK
268#define STOPWATCH_START_STOP BUTTON_SELECT
269#define STOPWATCH_RESET_TIMER BUTTON_MENU
270#define STOPWATCH_LAP_TIMER BUTTON_USER
271#define STOPWATCH_SCROLL_UP BUTTON_UP
272#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
273
266#else 274#else
267#error No keymap defined! 275#error No keymap defined!
268#endif 276#endif
diff --git a/apps/plugins/sudoku/sudoku.h b/apps/plugins/sudoku/sudoku.h
index 456e4fd9ee..07147185ae 100644
--- a/apps/plugins/sudoku/sudoku.h
+++ b/apps/plugins/sudoku/sudoku.h
@@ -329,6 +329,16 @@
329#define SUDOKU_BUTTON_MENU BUTTON_SELECT 329#define SUDOKU_BUTTON_MENU BUTTON_SELECT
330#define SUDOKU_BUTTON_POSSIBLE BUTTON_VOL_DOWN 330#define SUDOKU_BUTTON_POSSIBLE BUTTON_VOL_DOWN
331 331
332#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
333#define SUDOKU_BUTTON_QUIT BUTTON_BACK
334#define SUDOKU_BUTTON_UP BUTTON_UP
335#define SUDOKU_BUTTON_DOWN BUTTON_DOWN
336#define SUDOKU_BUTTON_LEFT BUTTON_LEFT
337#define SUDOKU_BUTTON_RIGHT BUTTON_RIGHT
338#define SUDOKU_BUTTON_MENU BUTTON_MENU
339#define SUDOKU_BUTTON_TOGGLE BUTTON_SELECT
340#define SUDOKU_BUTTON_POSSIBLE BUTTON_USER
341
332#else 342#else
333#error No keymap defined! 343#error No keymap defined!
334#endif 344#endif
diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c
index b4e25afdb1..135a6ae445 100644
--- a/apps/plugins/superdom.c
+++ b/apps/plugins/superdom.c
@@ -120,7 +120,8 @@ char buf[255];
120#define SUPERDOM_RIGHT BUTTON_RIGHT 120#define SUPERDOM_RIGHT BUTTON_RIGHT
121#define SUPERDOM_CANCEL (BUTTON_HOME|BUTTON_REPEAT) 121#define SUPERDOM_CANCEL (BUTTON_HOME|BUTTON_REPEAT)
122 122
123#elif CONFIG_KEYPAD == GIGABEAT_S_PAD 123#elif CONFIG_KEYPAD == GIGABEAT_S_PAD || \
124 CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
124#define SUPERDOM_OK BUTTON_SELECT 125#define SUPERDOM_OK BUTTON_SELECT
125#define SUPERDOM_UP BUTTON_UP 126#define SUPERDOM_UP BUTTON_UP
126#define SUPERDOM_DOWN BUTTON_DOWN 127#define SUPERDOM_DOWN BUTTON_DOWN
diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c
index 6e1b3b6f9e..849b40de42 100644
--- a/apps/plugins/test_codec.c
+++ b/apps/plugins/test_codec.c
@@ -39,6 +39,8 @@
39#define TESTCODEC_EXITBUTTON (BUTTON_REC | BUTTON_REPEAT) 39#define TESTCODEC_EXITBUTTON (BUTTON_REC | BUTTON_REPEAT)
40#elif CONFIG_KEYPAD == RK27XX_GENERIC_PAD 40#elif CONFIG_KEYPAD == RK27XX_GENERIC_PAD
41#define TESTCODEC_EXITBUTTON (BUTTON_M | BUTTON_REPEAT) 41#define TESTCODEC_EXITBUTTON (BUTTON_M | BUTTON_REPEAT)
42#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
43#define TESTCODEC_EXITBUTTON BUTTON_BACK
42#elif defined(HAVE_TOUCHSCREEN) 44#elif defined(HAVE_TOUCHSCREEN)
43#define TESTCODEC_EXITBUTTON BUTTON_TOPLEFT 45#define TESTCODEC_EXITBUTTON BUTTON_TOPLEFT
44#else 46#else
diff --git a/apps/plugins/test_fps.c b/apps/plugins/test_fps.c
index da4684f60a..4514aa61bb 100644
--- a/apps/plugins/test_fps.c
+++ b/apps/plugins/test_fps.c
@@ -37,6 +37,8 @@
37#define FPS_QUIT (BUTTON_REC|BUTTON_REPEAT) 37#define FPS_QUIT (BUTTON_REC|BUTTON_REPEAT)
38#elif CONFIG_KEYPAD == RK27XX_GENERIC_PAD 38#elif CONFIG_KEYPAD == RK27XX_GENERIC_PAD
39#define FPS_QUIT (BUTTON_M|BUTTON_REPEAT) 39#define FPS_QUIT (BUTTON_M|BUTTON_REPEAT)
40#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
41#define FPS_QUIT BUTTON_BACK
40#elif defined(BUTTON_OFF) 42#elif defined(BUTTON_OFF)
41#define FPS_QUIT BUTTON_OFF 43#define FPS_QUIT BUTTON_OFF
42#else 44#else
diff --git a/apps/plugins/test_gfx.c b/apps/plugins/test_gfx.c
index cde77c55fe..4081e64d13 100644
--- a/apps/plugins/test_gfx.c
+++ b/apps/plugins/test_gfx.c
@@ -402,7 +402,7 @@ static void time_text(void) /* tests mono_bitmap performance */
402/* plugin entry point */ 402/* plugin entry point */
403enum plugin_status plugin_start(const void* parameter) 403enum plugin_status plugin_start(const void* parameter)
404{ 404{
405#ifndef SIMULATOR 405#ifdef HAVE_ADJUSTABLE_CPU_FREQ
406 int cpu_freq; 406 int cpu_freq;
407#endif 407#endif
408 408
@@ -447,7 +447,7 @@ enum plugin_status plugin_start(const void* parameter)
447 6*4*DURATION/HZ); 447 6*4*DURATION/HZ);
448 init_rand_table(); 448 init_rand_table();
449 449
450#ifndef SIMULATOR 450#ifdef HAVE_ADJUSTABLE_CPU_FREQ
451 cpu_freq = *rb->cpu_frequency; /* remember CPU frequency */ 451 cpu_freq = *rb->cpu_frequency; /* remember CPU frequency */
452#endif 452#endif
453 453
@@ -458,7 +458,7 @@ enum plugin_status plugin_start(const void* parameter)
458 time_fillrect(); 458 time_fillrect();
459 time_text(); 459 time_text();
460 460
461#ifndef SIMULATOR 461#ifdef HAVE_ADJUSTABLE_CPU_FREQ
462 if (*rb->cpu_frequency != cpu_freq) 462 if (*rb->cpu_frequency != cpu_freq)
463 rb->fdprintf(log_fd, "\nCPU: %s\n", "clock changed!"); 463 rb->fdprintf(log_fd, "\nCPU: %s\n", "clock changed!");
464 else 464 else
diff --git a/apps/plugins/text_viewer/tv_button.h b/apps/plugins/text_viewer/tv_button.h
index 697076e643..fe16b5f8ce 100644
--- a/apps/plugins/text_viewer/tv_button.h
+++ b/apps/plugins/text_viewer/tv_button.h
@@ -436,6 +436,16 @@
436#define TV_LINE_DOWN BUTTON_SCROLL_FWD 436#define TV_LINE_DOWN BUTTON_SCROLL_FWD
437#define TV_BOOKMARK (BUTTON_DOWN|BUTTON_SELECT) 437#define TV_BOOKMARK (BUTTON_DOWN|BUTTON_SELECT)
438 438
439#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
440#define TV_QUIT BUTTON_BACK
441#define TV_SCROLL_UP BUTTON_UP
442#define TV_SCROLL_DOWN BUTTON_DOWN
443#define TV_SCREEN_LEFT BUTTON_LEFT
444#define TV_SCREEN_RIGHT BUTTON_RIGHT
445#define TV_MENU BUTTON_MENU
446#define TV_AUTOSCROLL BUTTON_USER
447#define TV_BOOKMARK BUTTON_SELECT
448
439#else 449#else
440#error No keymap defined! 450#error No keymap defined!
441#endif 451#endif
diff --git a/apps/plugins/vu_meter.c b/apps/plugins/vu_meter.c
index cf66070c6b..7ca7b43726 100644
--- a/apps/plugins/vu_meter.c
+++ b/apps/plugins/vu_meter.c
@@ -338,6 +338,17 @@
338#define LABEL_MENU "PREV" 338#define LABEL_MENU "PREV"
339#define LABEL_VOLUME "VOL+/VOL-" 339#define LABEL_VOLUME "VOL+/VOL-"
340 340
341#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
342#define VUMETER_QUIT BUTTON_BACK
343#define VUMETER_HELP BUTTON_USER
344#define VUMETER_MENU BUTTON_MENU
345#define VUMETER_UP BUTTON_UP
346#define VUMETER_DOWN BUTTON_DOWN
347#define LABEL_HELP "User"
348#define LABEL_QUIT "Back"
349#define LABEL_MENU "Menu"
350#define LABEL_VOLUME "Up/Down"
351
341#else 352#else
342#error No keymap defined! 353#error No keymap defined!
343#endif 354#endif
diff --git a/apps/plugins/wormlet.c b/apps/plugins/wormlet.c
index 016c4ad31b..f1834aade5 100644
--- a/apps/plugins/wormlet.c
+++ b/apps/plugins/wormlet.c
@@ -180,7 +180,8 @@ static long max_cycle;
180#define BTN_QUIT BUTTON_POWER 180#define BTN_QUIT BUTTON_POWER
181#define BTN_STOPRESET BUTTON_REW 181#define BTN_STOPRESET BUTTON_REW
182 182
183#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) 183#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
184 (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
184 185
185#define BTN_DIR_UP BUTTON_UP 186#define BTN_DIR_UP BUTTON_UP
186#define BTN_DIR_DOWN BUTTON_DOWN 187#define BTN_DIR_DOWN BUTTON_DOWN
diff --git a/apps/plugins/xobox.c b/apps/plugins/xobox.c
index 8de0c8fe16..30fd5fde13 100644
--- a/apps/plugins/xobox.c
+++ b/apps/plugins/xobox.c
@@ -277,6 +277,15 @@ CONFIG_KEYPAD == MROBE500_PAD
277#define DOWN BUTTON_DOWN 277#define DOWN BUTTON_DOWN
278#define PAUSE BUTTON_SELECT 278#define PAUSE BUTTON_SELECT
279 279
280#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
281
282#define QUIT BUTTON_BACK
283#define LEFT BUTTON_LEFT
284#define RIGHT BUTTON_RIGHT
285#define UP BUTTON_UP
286#define DOWN BUTTON_DOWN
287#define PAUSE BUTTON_SELECT
288
280#else 289#else
281#error No keymap defined! 290#error No keymap defined!
282#endif 291#endif
diff --git a/apps/plugins/zxbox/keymaps.h b/apps/plugins/zxbox/keymaps.h
index 4e5d73a343..317e67cd9f 100644
--- a/apps/plugins/zxbox/keymaps.h
+++ b/apps/plugins/zxbox/keymaps.h
@@ -28,7 +28,8 @@
28#define ZX_SELECT BUTTON_SELECT 28#define ZX_SELECT BUTTON_SELECT
29#define ZX_MENU BUTTON_MENU 29#define ZX_MENU BUTTON_MENU
30 30
31#elif CONFIG_KEYPAD == GIGABEAT_S_PAD 31#elif CONFIG_KEYPAD == GIGABEAT_S_PAD || \
32 CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
32 33
33#define ZX_UP BUTTON_UP 34#define ZX_UP BUTTON_UP
34#define ZX_DOWN BUTTON_DOWN 35#define ZX_DOWN BUTTON_DOWN
@@ -226,6 +227,15 @@
226#define ZX_LEFT BUTTON_LEFT 227#define ZX_LEFT BUTTON_LEFT
227#define ZX_RIGHT BUTTON_RIGHT 228#define ZX_RIGHT BUTTON_RIGHT
228 229
230#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
231
232#define ZX_MENU BUTTON_MENU
233#define ZX_UP BUTTON_UP
234#define ZX_DOWN BUTTON_DOWN
235#define ZX_SELECT BUTTON_CENTER
236#define ZX_LEFT BUTTON_LEFT
237#define ZX_RIGHT BUTTON_RIGHT
238
229#else 239#else
230#error Keymap not defined! 240#error Keymap not defined!
231 241
diff --git a/apps/plugins/zxbox/zxbox_keyb.c b/apps/plugins/zxbox/zxbox_keyb.c
index fc5ed41169..e8b5219de3 100644
--- a/apps/plugins/zxbox/zxbox_keyb.c
+++ b/apps/plugins/zxbox/zxbox_keyb.c
@@ -225,6 +225,15 @@
225 225
226#elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD 226#elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD
227 227
228#define KBD_SELECT BUTTON_CENTER
229#define KBD_ABORT BUTTON_BACK
230#define KBD_LEFT BUTTON_LEFT
231#define KBD_RIGHT BUTTON_RIGHT
232#define KBD_UP BUTTON_UP
233#define KBD_DOWN BUTTON_DOWN
234
235#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
236
228#define KBD_SELECT BUTTON_SELECT 237#define KBD_SELECT BUTTON_SELECT
229#define KBD_ABORT BUTTON_BACK 238#define KBD_ABORT BUTTON_BACK
230#define KBD_LEFT BUTTON_LEFT 239#define KBD_LEFT BUTTON_LEFT
diff --git a/docs/CREDITS b/docs/CREDITS
index 614b165afd..477741816a 100644
--- a/docs/CREDITS
+++ b/docs/CREDITS
@@ -610,6 +610,7 @@ Desu Rozen
610Olivier Kaloudoff 610Olivier Kaloudoff
611Kessia Pinheiro 611Kessia Pinheiro
612Jean-Louis Biasini 612Jean-Louis Biasini
613Lorenzo Miori
613 614
614The libmad team 615The libmad team
615The wavpack team 616The wavpack team
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 7053358bee..f59475e27a 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -14,8 +14,10 @@ target/hosted/cpuinfo-linux.c
14#endif 14#endif
15 15
16target/hosted/powermgmt.c 16target/hosted/powermgmt.c
17#ifndef SAMSUNG_YPR0 /* uses as3514 rtc */
17target/hosted/rtc.c 18target/hosted/rtc.c
18#endif 19#endif
20#endif
19system.c 21system.c
20usb.c 22usb.c
21#ifdef ROCKBOX_HAS_LOGF 23#ifdef ROCKBOX_HAS_LOGF
@@ -62,6 +64,26 @@ target/hosted/sdl/app/button-application.c
62#endif 64#endif
63#endif 65#endif
64 66
67#ifdef SAMSUNG_YPR0
68#if (CONFIG_RTC == RTC_AS3514)
69drivers/rtc/rtc_as3514.c
70#else
71target/hosted/rtc.c
72#endif
73target/hosted/ypr0/button-ypr0.c
74target/hosted/ypr0/kernel-ypr0.c
75target/hosted/ypr0/lcd-ypr0.c
76target/hosted/ypr0/system-ypr0.c
77target/hosted/ypr0/fs-ypr0.c
78target/hosted/ypr0/lc-ypr0.c
79thread.c
80#ifdef HAVE_BACKLIGHT
81target/hosted/ypr0/backlight-ypr0.c
82#endif
83target/hosted/ypr0/ascodec-ypr0.c
84target/hosted/ypr0/powermgmt-ypr0.c
85#endif
86
65/* Maemo specific files */ 87/* Maemo specific files */
66#if (CONFIG_PLATFORM & PLATFORM_MAEMO) 88#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
67target/hosted/maemo/maemo-thread.c 89target/hosted/maemo/maemo-thread.c
@@ -368,6 +390,10 @@ drivers/audio/aic3x.c
368#elif defined (HAVE_DUMMY_CODEC) 390#elif defined (HAVE_DUMMY_CODEC)
369drivers/audio/dummy_codec.c 391drivers/audio/dummy_codec.c
370#endif /* defined(HAVE_*) */ 392#endif /* defined(HAVE_*) */
393#else /* PLATFORM_HOSTED */
394#if defined(SAMSUNG_YPR0) && defined(HAVE_AS3514)
395drivers/audio/as3514.c
396target/hosted/pcm-alsa.c
371#elif defined(HAVE_SDL_AUDIO) 397#elif defined(HAVE_SDL_AUDIO)
372drivers/audio/sdl.c 398drivers/audio/sdl.c
373#if CONFIG_CODEC == SWCODEC 399#if CONFIG_CODEC == SWCODEC
@@ -377,6 +403,7 @@ target/hosted/maemo/pcm-gstreamer.c
377target/hosted/sdl/pcm-sdl.c 403target/hosted/sdl/pcm-sdl.c
378#endif /* (CONFIG_PLATFORM & PLATFORM_MAEMO) */ 404#endif /* (CONFIG_PLATFORM & PLATFORM_MAEMO) */
379#endif /* CONFIG_CODEC == SWCODEC */ 405#endif /* CONFIG_CODEC == SWCODEC */
406#endif
380#endif /* (CONFIG_PLATFORM & PLATFORM_NATIVE) && !defined(BOOTLOADER) */ 407#endif /* (CONFIG_PLATFORM & PLATFORM_NATIVE) && !defined(BOOTLOADER) */
381 408
382/* CPU Specific - By class then particular chip if applicable */ 409/* CPU Specific - By class then particular chip if applicable */
@@ -722,7 +749,7 @@ target/arm/ascodec-pp.c
722# endif 749# endif
723# if !defined(BOOTLOADER) || defined(CPU_PP) 750# if !defined(BOOTLOADER) || defined(CPU_PP)
724target/arm/adc-as3514.c 751target/arm/adc-as3514.c
725# ifndef SANSA_M200V4 752# if !defined(SANSA_M200V4) && !defined(SAMSUNG_YPR0)
726target/arm/powermgmt-ascodec.c 753target/arm/powermgmt-ascodec.c
727# endif 754# endif
728# endif 755# endif
diff --git a/firmware/common/rbpaths.c b/firmware/common/rbpaths.c
index ed413eb03e..95bff3341f 100644
--- a/firmware/common/rbpaths.c
+++ b/firmware/common/rbpaths.c
@@ -23,6 +23,7 @@
23#include <stdio.h> /* snprintf */ 23#include <stdio.h> /* snprintf */
24#include <stdlib.h> 24#include <stdlib.h>
25#include <stdarg.h> 25#include <stdarg.h>
26#include "config.h"
26#include "rbpaths.h" 27#include "rbpaths.h"
27#include "file.h" /* MAX_PATH */ 28#include "file.h" /* MAX_PATH */
28#include "logf.h" 29#include "logf.h"
@@ -38,11 +39,17 @@
38#undef mkdir 39#undef mkdir
39#undef rmdir 40#undef rmdir
40 41
42
41#if (CONFIG_PLATFORM & PLATFORM_ANDROID) 43#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
42#include "dir-target.h" 44#include "dir-target.h"
43#define opendir opendir_android 45#define opendir opendir_android
44#define mkdir mkdir_android 46#define mkdir mkdir_android
45#define rmdir rmdir_android 47#define rmdir rmdir_android
48#elif defined(SAMSUNG_YPR0)
49#include "dir-target.h"
50#define opendir opendir_ypr0
51#define mkdir mkdir_ypr0
52#define rmdir rmdir_ypr0
46#elif (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) 53#elif (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA))
47#define open sim_open 54#define open sim_open
48#define remove sim_remove 55#define remove sim_remove
@@ -59,6 +66,8 @@ extern int sim_rmdir(const char* name);
59const char *rbhome; 66const char *rbhome;
60#endif 67#endif
61 68
69#if !defined(SAMSUNG_YPR0)
70
62/* flags for get_user_file_path() */ 71/* flags for get_user_file_path() */
63/* whether you need write access to that file/dir, especially true 72/* whether you need write access to that file/dir, especially true
64 * for runtime generated files (config.cfg) */ 73 * for runtime generated files (config.cfg) */
@@ -238,3 +247,28 @@ int app_rmdir(const char* name)
238 } 247 }
239 return rmdir(fname); 248 return rmdir(fname);
240} 249}
250
251#else
252
253int app_open(const char *name, int o, ...)
254{
255 if (o & O_CREAT)
256 {
257 int ret;
258 va_list ap;
259 va_start(ap, o);
260 ret = open(name, o, va_arg(ap, mode_t));
261 va_end(ap);
262 return ret;
263 }
264 return open(name, o);
265}
266
267int app_creat(const char* name, mode_t mode) { return creat(name, mode); }
268int app_remove(const char *name) { return remove(name); }
269int app_rename(const char *old, const char *new) { return rename(old,new); }
270DIR *app_opendir(const char *name) { return opendir(name); }
271int app_mkdir(const char* name) { return mkdir(name); }
272int app_rmdir(const char* name) { return rmdir(name); }
273
274#endif
diff --git a/firmware/drivers/audio/as3514.c b/firmware/drivers/audio/as3514.c
index 64531cfc2b..0fe3070c19 100644
--- a/firmware/drivers/audio/as3514.c
+++ b/firmware/drivers/audio/as3514.c
@@ -78,6 +78,7 @@ const struct sound_settings_info audiohw_settings[] = {
78#endif 78#endif
79}; 79};
80 80
81#ifndef SAMSUNG_YPR0
81/* Shadow registers */ 82/* Shadow registers */
82static uint8_t as3514_regs[AS3514_NUM_AUDIO_REGS]; /* 8-bit registers */ 83static uint8_t as3514_regs[AS3514_NUM_AUDIO_REGS]; /* 8-bit registers */
83 84
@@ -110,7 +111,29 @@ static void as3514_write_masked(unsigned int reg, unsigned int bits,
110{ 111{
111 as3514_write(reg, (as3514_regs[reg] & ~mask) | (bits & mask)); 112 as3514_write(reg, (as3514_regs[reg] & ~mask) | (bits & mask));
112} 113}
114#else
115static void as3514_write(unsigned int reg, unsigned int value)
116{
117 ascodec_write(reg, value);
118}
119
120/* Helpers to set/clear bits */
121static void as3514_set(unsigned int reg, unsigned int bits)
122{
123 ascodec_write(reg, ascodec_read(reg) | bits);
124}
125
126static void as3514_clear(unsigned int reg, unsigned int bits)
127{
128 ascodec_write(reg, ascodec_read(reg) & ~bits);
129}
113 130
131static void as3514_write_masked(unsigned int reg, unsigned int bits,
132 unsigned int mask)
133{
134 ascodec_write(reg, (ascodec_read(reg) & ~mask) | (bits & mask));
135}
136#endif
114/* convert tenth of dB volume to master volume register value */ 137/* convert tenth of dB volume to master volume register value */
115int tenthdb2master(int db) 138int tenthdb2master(int db)
116{ 139{
@@ -145,8 +168,11 @@ int sound_val2phys(int setting, int value)
145 */ 168 */
146void audiohw_preinit(void) 169void audiohw_preinit(void)
147{ 170{
171
172#ifndef SAMSUNG_YPR0
148 /* read all reg values */ 173 /* read all reg values */
149 ascodec_readbytes(0x0, AS3514_NUM_AUDIO_REGS, as3514_regs); 174 ascodec_readbytes(0x0, AS3514_NUM_AUDIO_REGS, as3514_regs);
175#endif
150 176
151#ifdef HAVE_AS3543 177#ifdef HAVE_AS3543
152 178
@@ -284,9 +310,14 @@ void audiohw_set_master_vol(int vol_l, int vol_r)
284#if CONFIG_CPU == AS3525v2 310#if CONFIG_CPU == AS3525v2
285#define MIXER_MAX_VOLUME 0x1b 311#define MIXER_MAX_VOLUME 0x1b
286#else /* lets leave the AS3514 alone until its better tested*/ 312#else /* lets leave the AS3514 alone until its better tested*/
313#ifdef SAMSUNG_YPR0
314#define MIXER_MAX_VOLUME 0x1a
315#else
287#define MIXER_MAX_VOLUME 0x16 316#define MIXER_MAX_VOLUME 0x16
288#endif 317#endif
318#endif
289 319
320#ifndef SAMSUNG_YPR0
290 if (vol_r <= MIXER_MAX_VOLUME) { 321 if (vol_r <= MIXER_MAX_VOLUME) {
291 mix_r = vol_r; 322 mix_r = vol_r;
292 hph_r = 0; 323 hph_r = 0;
@@ -302,7 +333,16 @@ void audiohw_set_master_vol(int vol_l, int vol_r)
302 mix_l = MIXER_MAX_VOLUME; 333 mix_l = MIXER_MAX_VOLUME;
303 hph_l = vol_l - MIXER_MAX_VOLUME; 334 hph_l = vol_l - MIXER_MAX_VOLUME;
304 } 335 }
305 336#else
337/* Okay. This is shit coded indeed. It is just a test.
338 Some considerations: Samsung keeps DAC constantly to 0x1a volume. It modifies only the headphone amp volume
339*/
340
341 mix_r = 0x1a;
342 mix_l = 0x1a;
343 hph_l = vol_l;
344 hph_r = vol_r;
345#endif
306 346
307 as3514_write_masked(AS3514_DAC_R, mix_r, AS3514_VOL_MASK); 347 as3514_write_masked(AS3514_DAC_R, mix_r, AS3514_VOL_MASK);
308 as3514_write_masked(AS3514_DAC_L, mix_l, AS3514_VOL_MASK); 348 as3514_write_masked(AS3514_DAC_L, mix_l, AS3514_VOL_MASK);
diff --git a/firmware/drivers/rtc/rtc_as3514.c b/firmware/drivers/rtc/rtc_as3514.c
index 44ef3cc4a1..868fa9753b 100644
--- a/firmware/drivers/rtc/rtc_as3514.c
+++ b/firmware/drivers/rtc/rtc_as3514.c
@@ -141,11 +141,11 @@ void rtc_alarm_poweroff(void)
141 seconds = 24*3600; 141 seconds = 24*3600;
142 142
143 seconds -= tm.tm_sec; 143 seconds -= tm.tm_sec;
144 144#ifndef SAMSUNG_YPR0
145 /* disable MCLK, it is a wakeup source and prevents proper shutdown */ 145 /* disable MCLK, it is a wakeup source and prevents proper shutdown */
146 CGU_AUDIO = (2 << 0) | (1 << 11); 146 CGU_AUDIO = (2 << 0) | (1 << 11);
147 CGU_PLLBSUP = (1 << 2) | (1 << 3); 147 CGU_PLLBSUP = (1 << 2) | (1 << 3);
148 148#endif
149 /* write wakeup register */ 149 /* write wakeup register */
150 alarm.seconds = seconds; 150 alarm.seconds = seconds;
151 alarm.enabled = true; 151 alarm.enabled = true;
diff --git a/firmware/export/as3514.h b/firmware/export/as3514.h
index acf13444fa..bcdb1a78c6 100644
--- a/firmware/export/as3514.h
+++ b/firmware/export/as3514.h
@@ -131,9 +131,14 @@ extern void audiohw_set_sampr_dividers(int fsel);
131/* Headphone volume goes from -81.0 ... +6dB */ 131/* Headphone volume goes from -81.0 ... +6dB */
132#define VOLUME_MIN -810 132#define VOLUME_MIN -810
133#else 133#else
134#ifdef SAMSUNG_YPR0
135/* Headphone volume goes from -40.5 ... +6dB */
136#define VOLUME_MIN -405
137#else
134/* Headphone volume goes from -73.5 ... +6dB */ 138/* Headphone volume goes from -73.5 ... +6dB */
135#define VOLUME_MIN -735 139#define VOLUME_MIN -735
136#endif 140#endif
141#endif
137#define VOLUME_MAX 60 142#define VOLUME_MAX 60
138 143
139/*** Audio Registers ***/ 144/*** Audio Registers ***/
diff --git a/firmware/export/ascodec.h b/firmware/export/ascodec.h
index 93cd767608..658153e420 100644
--- a/firmware/export/ascodec.h
+++ b/firmware/export/ascodec.h
@@ -28,4 +28,8 @@
28#include "ascodec-target.h" 28#include "ascodec-target.h"
29#endif 29#endif
30 30
31#ifdef SAMSUNG_YPR0
32#include "ascodec-target.h"
33#endif
34
31#endif 35#endif
diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h
index 102d107d8a..304c5aa460 100644
--- a/firmware/export/audiohw.h
+++ b/firmware/export/audiohw.h
@@ -79,7 +79,7 @@
79#elif defined(HAVE_DUMMY_CODEC) 79#elif defined(HAVE_DUMMY_CODEC)
80#include "dummy_codec.h" 80#include "dummy_codec.h"
81#endif 81#endif
82#if (CONFIG_PLATFORM & PLATFORM_HOSTED) 82#if (CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO|PLATFORM_PANDORA|PLATFORM_SDL))
83/* #include <SDL_audio.h> gives errors in other code areas, 83/* #include <SDL_audio.h> gives errors in other code areas,
84 * we don't really need it here, so don't. but it should maybe be fixed */ 84 * we don't really need it here, so don't. but it should maybe be fixed */
85#ifndef SIMULATOR /* simulator gets values from the target .h files */ 85#ifndef SIMULATOR /* simulator gets values from the target .h files */
diff --git a/firmware/export/config.h b/firmware/export/config.h
index 039b48a759..542587fc9d 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -143,6 +143,7 @@
143#define HM60X_PAD 50 143#define HM60X_PAD 50
144#define HM801_PAD 51 144#define HM801_PAD 51
145#define SANSA_CONNECT_PAD 52 145#define SANSA_CONNECT_PAD 52
146#define SAMSUNG_YPR0_PAD 53
146 147
147/* CONFIG_REMOTE_KEYPAD */ 148/* CONFIG_REMOTE_KEYPAD */
148#define H100_REMOTE 1 149#define H100_REMOTE 1
@@ -232,6 +233,7 @@
232#define LCD_HX8340B 44 /* as used by the HiFiMAN HM-601/HM-602/HM-801 */ 233#define LCD_HX8340B 44 /* as used by the HiFiMAN HM-601/HM-602/HM-801 */
233#define LCD_CONNECT 45 /* as used by the Sandisk Sansa Connect */ 234#define LCD_CONNECT 45 /* as used by the Sandisk Sansa Connect */
234#define LCD_GIGABEATS 46 235#define LCD_GIGABEATS 46
236#define LCD_YPR0 47
235 237
236/* LCD_PIXELFORMAT */ 238/* LCD_PIXELFORMAT */
237#define HORIZONTAL_PACKING 1 239#define HORIZONTAL_PACKING 1
@@ -483,6 +485,8 @@ Lyre prototype 1 */
483#include "config/nokian900.h" 485#include "config/nokian900.h"
484#elif defined(PANDORA) 486#elif defined(PANDORA)
485#include "config/pandora.h" 487#include "config/pandora.h"
488#elif defined(SAMSUNG_YPR0)
489#include "config/ypr0.h"
486#else 490#else
487/* no known platform */ 491/* no known platform */
488#endif 492#endif
@@ -580,6 +584,10 @@ Lyre prototype 1 */
580#define CONFIG_BACKLIGHT_FADING BACKLIGHT_NO_FADING 584#define CONFIG_BACKLIGHT_FADING BACKLIGHT_NO_FADING
581#endif 585#endif
582 586
587#ifndef CONFIG_I2C
588#define CONFIG_I2C I2C_NONE
589#endif
590
583#ifndef CONFIG_TUNER 591#ifndef CONFIG_TUNER
584#define CONFIG_TUNER 0 592#define CONFIG_TUNER 0
585#endif 593#endif
@@ -600,6 +608,14 @@ Lyre prototype 1 */
600#define CONFIG_RTC 0 608#define CONFIG_RTC 0
601#endif 609#endif
602 610
611#ifndef BATTERY_TYPES_COUNT
612#define BATTERY_TYPES_COUNT 0
613#endif
614
615#ifndef BATTERY_CAPACITY_INC
616#define BATTERY_CAPACITY_INC 0
617#endif
618
603#ifndef CONFIG_ORIENTATION 619#ifndef CONFIG_ORIENTATION
604#if LCD_HEIGHT > LCD_WIDTH 620#if LCD_HEIGHT > LCD_WIDTH
605#define CONFIG_ORIENTATION SCREEN_PORTRAIT 621#define CONFIG_ORIENTATION SCREEN_PORTRAIT
diff --git a/firmware/export/config/ypr0.h b/firmware/export/config/ypr0.h
new file mode 100644
index 0000000000..25e1906a80
--- /dev/null
+++ b/firmware/export/config/ypr0.h
@@ -0,0 +1,168 @@
1/*
2 * This config file is for the RockBox as application on the Samsung YP-R0 player.
3 * The target name for ifdefs is: SAMSUNG_YPR0; or CONFIG_PLATFORM & PLAFTORM_YPR0
4 */
5
6#define TARGET_TREE /* this target is using the target tree system */
7
8/* We don't run on hardware directly */
9/* YP-R0 need it too of course */
10#define CONFIG_PLATFORM (PLATFORM_HOSTED)
11
12/* For Rolo and boot loader */
13#define MODEL_NUMBER 100
14
15#define MODEL_NAME "Samsung YP-R0"
16
17/* Indeed to check that */
18/*TODO: R0 should charge battery automatically, no software stuff to manage that. Just to know about some as3543 registers, that should be set after loading samsung's afe.ko module
19 */
20/*TODO: implement USB data transfer management -> see safe mode script and think a way to implemtent it in the code */
21#define USB_NONE
22
23/* Hardware controlled charging with monitoring */
24//#define CONFIG_CHARGING CHARGING_MONITOR
25
26/* There is only USB charging */
27//#define HAVE_USB_POWER
28
29/* define this if you have a bitmap LCD display */
30#define HAVE_LCD_BITMAP
31
32/* define this if you have a colour LCD */
33#define HAVE_LCD_COLOR
34
35/* define this if the LCD needs to be shutdown */
36/* TODO: Our framebuffer must be closed... */
37#define HAVE_LCD_SHUTDOWN
38
39/* define this if you want album art for this target */
40#define HAVE_ALBUMART
41
42/* define this to enable bitmap scaling */
43#define HAVE_BMP_SCALING
44
45/* define this to enable JPEG decoding */
46#define HAVE_JPEG
47
48/* define this if you have access to the quickscreen */
49#define HAVE_QUICKSCREEN
50
51/* define this if you have access to the pitchscreen */
52#define HAVE_PITCHSCREEN
53
54/* define this if you would like tagcache to build on this target */
55#define HAVE_TAGCACHE
56
57/* LCD dimensions
58 *
59 * overriden by configure for application builds */
60#ifndef LCD_WIDTH
61#define LCD_WIDTH 240
62#endif
63
64#ifndef LCD_HEIGHT
65#define LCD_HEIGHT 320
66#endif
67
68#define LCD_DEPTH 16
69/* Check that but should not matter */
70#define LCD_PIXELFORMAT 565
71
72/* YP-R0 has the backlight */
73#define HAVE_BACKLIGHT
74
75/* Define this for LCD backlight brightness available */
76#define HAVE_BACKLIGHT_BRIGHTNESS
77
78/* Main LCD backlight brightness range and defaults */
79/* 0 is turned off. 31 is the real maximum for the ASCODEC DCDC but samsung doesn't use any value over 15, so it safer to don't go up too much */
80#define MIN_BRIGHTNESS_SETTING 1
81#define MAX_BRIGHTNESS_SETTING 15
82#define DEFAULT_BRIGHTNESS_SETTING 4
83
84/* Which backlight fading type? */
85/* TODO: ASCODEC has an auto dim feature, so disabling the supply to leds should do the trick. But for now I tested SW fading only */
86#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
87
88/* define this if you have RTC RAM available for settings */
89/* TODO: in theory we could use that, ascodec offers us such a ram. we have also a small device, part of the nand of 1 MB size, that Samsung uses to store region code etc and it's almost unused space */
90//#define HAVE_RTC_RAM
91
92/* define this if you have a real-time clock */
93//#define CONFIG_RTC APPLICATION
94#define CONFIG_RTC RTC_AS3514
95#define HAVE_RTC_ALARM
96
97/* The number of bytes reserved for loadable codecs */
98#define CODEC_SIZE 0x80000
99
100/* The number of bytes reserved for loadable plugins */
101#define PLUGIN_BUFFER_SIZE 0x100000
102
103/* We can do AB-repeat -> we use User key, our hotkey */
104#define AB_REPEAT_ENABLE
105#define ACTION_WPSAB_SINGLE ACTION_WPS_HOTKEY
106
107/* Define this if you do software codec */
108#define CONFIG_CODEC SWCODEC
109
110/* R0 KeyPad configuration for plugins */
111#define CONFIG_KEYPAD SAMSUNG_YPR0_PAD
112/* It's better to close /dev/r0Btn at shutdown */
113#define BUTTON_DRIVER_CLOSE
114
115/* The YPR0 has a as3534 codec and we use that to control the volume */
116#define HAVE_AS3514
117#define HAVE_AS3543
118
119#define HAVE_SW_TONE_CONTROLS
120
121/* TODO: Make use of the si4703 tuner hardware */
122/* #define CONFIG_TUNER SI4700 */
123/* #define HAVE_TUNER_PWR_CTRL*/
124
125/*TODO: In R0 there is an interrupt for this (figure out ioctls)*/
126/* #define HAVE_HEADPHONE_DETECTION */
127
128/* Define current usage levels. */
129/* TODO: to be filled with correct values after implementing power management */
130#define CURRENT_NORMAL 88 /* 18 hours from a 1600 mAh battery */
131#define CURRENT_BACKLIGHT 30 /* TBD */
132#define CURRENT_RECORD 0 /* no recording yet */
133
134/* TODO: We need to do battery handling */
135//#define BATTERY_CAPACITY_DEFAULT 600 /* default battery capacity */
136//#define BATTERY_CAPACITY_MIN 600 /* min. capacity selectable */
137//#define BATTERY_CAPACITY_MAX 700 /* max. capacity selectable */
138//#define BATTERY_CAPACITY_INC 50 /* capacity increment */
139//#define BATTERY_TYPES_COUNT 1 /* only one type */
140
141/* TODO: We possibly can only watch linux charging */
142//#define CONFIG_CHARGING CHARGING_TARGET
143//#define HAVE_RESET_BATTERY_FILTER
144
145/* same dimensions as gigabeats */
146#define CONFIG_LCD LCD_YPR0
147
148/* Define this if a programmable hotkey is mapped */
149#define HAVE_HOTKEY
150
151/* Define this if you have a software controlled poweroff */
152#define HAVE_SW_POWEROFF
153
154/* Define this if you have adjustable CPU frequency
155 * NOTE: We could do that on this device, but it's probably better
156 * to let linux do it (we set ondemand governor before loading Rockbox) */
157/* #define HAVE_ADJUSTABLE_CPU_FREQ */
158/* Define this to the CPU frequency */
159#define CPU_FREQ 532000000
160/* 0.8Vcore using 200 MHz */
161/* #define CPUFREQ_DEFAULT 200000000 */
162/* This is 400 MHz -> not so powersaving-ful */
163/* #define CPUFREQ_NORMAL 400000000 */
164/* Max IMX37 Cpu Frequency */
165/* #define CPUFREQ_MAX CPU_FREQ */
166
167/* TODO: my idea is to create a folder in the cramfs [/.rockbox], mounting it by the starter script as the current working directory, so no issues of any type keeping the rockbox folder as in all other players */
168#define BOOTDIR "/.rockbox"
diff --git a/firmware/export/rbpaths.h b/firmware/export/rbpaths.h
index 74d26f93d3..8f554c25f4 100644
--- a/firmware/export/rbpaths.h
+++ b/firmware/export/rbpaths.h
@@ -44,7 +44,7 @@
44#define ROCKBOX_DIR_LEN (sizeof(ROCKBOX_DIR)-1) 44#define ROCKBOX_DIR_LEN (sizeof(ROCKBOX_DIR)-1)
45#endif /* def __PCTOOL__ */ 45#endif /* def __PCTOOL__ */
46 46
47#ifndef APPLICATION 47#if !defined(APPLICATION) || defined(SAMSUNG_YPR0)
48 48
49/* make sure both are the same for native builds */ 49/* make sure both are the same for native builds */
50#undef ROCKBOX_LIBRARY_PATH 50#undef ROCKBOX_LIBRARY_PATH
@@ -57,6 +57,7 @@
57#define PLAYLIST_CATALOG_DEFAULT_DIR "/Playlists" 57#define PLAYLIST_CATALOG_DEFAULT_DIR "/Playlists"
58 58
59#define paths_init() 59#define paths_init()
60
60#else /* application */ 61#else /* application */
61 62
62#define PLUGIN_DIR ROCKBOX_LIBRARY_PATH "/rockbox/rocks" 63#define PLUGIN_DIR ROCKBOX_LIBRARY_PATH "/rockbox/rocks"
@@ -80,7 +81,7 @@ extern void paths_init(void);
80#define PLUGIN_DEMOS_DIR PLUGIN_DIR "/demos" 81#define PLUGIN_DEMOS_DIR PLUGIN_DIR "/demos"
81#define VIEWERS_DIR PLUGIN_DIR "/viewers" 82#define VIEWERS_DIR PLUGIN_DIR "/viewers"
82 83
83#ifdef APPLICATION 84#if defined(APPLICATION) && !defined(SAMSUNG_YPR0)
84#define PLUGIN_DATA_DIR "/.rockbox/rocks.data" 85#define PLUGIN_DATA_DIR "/.rockbox/rocks.data"
85#define PLUGIN_GAMES_DATA_DIR PLUGIN_DATA_DIR 86#define PLUGIN_GAMES_DATA_DIR PLUGIN_DATA_DIR
86#define PLUGIN_APPS_DATA_DIR PLUGIN_DATA_DIR 87#define PLUGIN_APPS_DATA_DIR PLUGIN_DATA_DIR
diff --git a/firmware/include/dir_uncached.h b/firmware/include/dir_uncached.h
index d9a29fbada..e0fea13c14 100644
--- a/firmware/include/dir_uncached.h
+++ b/firmware/include/dir_uncached.h
@@ -74,7 +74,7 @@ typedef struct {
74 74
75 75
76#if defined(APPLICATION) 76#if defined(APPLICATION)
77#if (CONFIG_PLATFORM & PLATFORM_ANDROID) 77#if (CONFIG_PLATFORM & PLATFORM_ANDROID) || defined(SAMSUNG_YPR0)
78#include "dir-target.h" 78#include "dir-target.h"
79#endif 79#endif
80# undef opendir_uncached 80# undef opendir_uncached
diff --git a/firmware/pcm_mixer.c b/firmware/pcm_mixer.c
index 25c41c2586..3194f76e04 100644
--- a/firmware/pcm_mixer.c
+++ b/firmware/pcm_mixer.c
@@ -70,6 +70,11 @@ static struct mixer_channel * active_channels[PCM_MIXER_NUM_CHANNELS+1] IBSS_ATT
70#define MAX_IDLE_FRAMES (NATIVE_FREQUENCY*3 / MIX_FRAME_SAMPLES) 70#define MAX_IDLE_FRAMES (NATIVE_FREQUENCY*3 / MIX_FRAME_SAMPLES)
71static unsigned int idle_counter = 0; 71static unsigned int idle_counter = 0;
72 72
73/* Cheapo buffer align macro to align to the 16-16 PCM size */
74#define ALIGN_CHANNEL(start, size) \
75 ({ start = (void *)(((uintptr_t)start + 3) & ~3); \
76 size &= ~3; })
77
73#if (CONFIG_PLATFORM & PLATFORM_NATIVE) 78#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
74 79
75/* Include any implemented CPU-optimized mixdown routines */ 80/* Include any implemented CPU-optimized mixdown routines */
diff --git a/firmware/sound.c b/firmware/sound.c
index c97ccc243f..99db7896ab 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -235,7 +235,8 @@ static void set_prescaled_volume(void)
235 dsp_callback(DSP_CALLBACK_SET_SW_VOLUME, 0); 235 dsp_callback(DSP_CALLBACK_SET_SW_VOLUME, 0);
236#endif 236#endif
237 237
238#ifndef HAVE_SDL_AUDIO 238/* ypr0 with sdl has separate volume controls */
239#if !defined(HAVE_SDL_AUDIO) || defined(SAMSUNG_YPR0)
239#if CONFIG_CODEC == MAS3507D 240#if CONFIG_CODEC == MAS3507D
240 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false); 241 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
241#elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \ 242#elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \
@@ -670,7 +671,7 @@ void sound_set(int setting, int value)
670 && !defined (HAVE_WM8711) && !defined (HAVE_WM8721) \ 671 && !defined (HAVE_WM8711) && !defined (HAVE_WM8721) \
671 && !defined (HAVE_WM8731) && !defined (HAVE_WM8978) \ 672 && !defined (HAVE_WM8731) && !defined (HAVE_WM8978) \
672 && !defined (HAVE_WM8750) && !defined (HAVE_WM8751) \ 673 && !defined (HAVE_WM8750) && !defined (HAVE_WM8751) \
673 && !defined(HAVE_AK4537)) || (CONFIG_PLATFORM & PLATFORM_HOSTED) 674 && !defined(HAVE_AK4537)) || defined(SIMULATOR)
674int sound_val2phys(int setting, int value) 675int sound_val2phys(int setting, int value)
675{ 676{
676#if CONFIG_CODEC == MAS3587F 677#if CONFIG_CODEC == MAS3587F
diff --git a/firmware/system.c b/firmware/system.c
index 7e269ee119..111a94f80e 100644
--- a/firmware/system.c
+++ b/firmware/system.c
@@ -26,7 +26,7 @@
26#include "string.h" 26#include "string.h"
27#include "file.h" 27#include "file.h"
28 28
29#if (CONFIG_PLATFORM & PLATFORM_NATIVE) 29#ifdef HAVE_ADJUSTABLE_CPU_FREQ
30long cpu_frequency SHAREDBSS_ATTR = CPU_FREQ; 30long cpu_frequency SHAREDBSS_ATTR = CPU_FREQ;
31#endif 31#endif
32 32
diff --git a/firmware/target/hosted/pcm-alsa.c b/firmware/target/hosted/pcm-alsa.c
new file mode 100644
index 0000000000..928187993e
--- /dev/null
+++ b/firmware/target/hosted/pcm-alsa.c
@@ -0,0 +1,518 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23/*
24 * Based, but heavily modified, on the example given at
25 * http://www.alsa-project.org/alsa-doc/alsa-lib/_2test_2pcm_8c-example.html
26 *
27 * This driver uses the so-called unsafe async callback method and hardcoded device
28 * names. It fails when the audio device is busy by other apps.
29 *
30 * TODO: Rewrite this to do it properly with multithreading
31 *
32 * Alternatively, a version using polling in a tick task is provided. While
33 * supposedly safer, it appears to use more CPU (however I didn't measure it
34 * accurately, only looked at htop). At least, in this mode the "default"
35 * device works which doesnt break with other apps running.
36 * device works which doesnt break with other apps running.
37 */
38
39
40#include "autoconf.h"
41
42#include <stdlib.h>
43#include <stdbool.h>
44#include <alsa/asoundlib.h>
45#include "system.h"
46#include "debug.h"
47#include "kernel.h"
48
49#include "pcm.h"
50#include "pcm-internal.h"
51#include "pcm_mixer.h"
52#include "pcm_sampr.h"
53
54#include <pthread.h>
55#include <signal.h>
56
57#define USE_ASYNC_CALLBACK
58/* plughw:0,0 works with both, however "default" is recommended.
59 * default doesnt seem to work with async callback but doesn't break
60 * with multple applications running */
61static char device[] = "plughw:0,0"; /* playback device */
62static const snd_pcm_access_t access_ = SND_PCM_ACCESS_RW_INTERLEAVED; /* access mode */
63static const snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample format */
64static const int channels = 2; /* count of channels */
65static unsigned int rate = 44100; /* stream rate */
66
67static snd_pcm_t *handle;
68static snd_pcm_sframes_t buffer_size = MIX_FRAME_SAMPLES * 32; /* ~16k */
69static snd_pcm_sframes_t period_size = MIX_FRAME_SAMPLES * 4; /* ~4k */
70static short *frames;
71
72static const char *pcm_data = 0;
73static size_t pcm_size = 0;
74
75#ifdef USE_ASYNC_CALLBACK
76static snd_async_handler_t *ahandler;
77static pthread_mutex_t pcm_mtx;
78#else
79static int recursion;
80#endif
81
82static int set_hwparams(snd_pcm_t *handle, unsigned sample_rate)
83{
84 unsigned int rrate;
85 int err;
86 snd_pcm_hw_params_t *params;
87 snd_pcm_hw_params_alloca(&params);
88
89
90 /* choose all parameters */
91 err = snd_pcm_hw_params_any(handle, params);
92 if (err < 0)
93 {
94 printf("Broken configuration for playback: no configurations available: %s\n", snd_strerror(err));
95 return err;
96 }
97 /* set the interleaved read/write format */
98 err = snd_pcm_hw_params_set_access(handle, params, access_);
99 if (err < 0)
100 {
101 printf("Access type not available for playback: %s\n", snd_strerror(err));
102 return err;
103 }
104 /* set the sample format */
105 err = snd_pcm_hw_params_set_format(handle, params, format);
106 if (err < 0)
107 {
108 printf("Sample format not available for playback: %s\n", snd_strerror(err));
109 return err;
110 }
111 /* set the count of channels */
112 err = snd_pcm_hw_params_set_channels(handle, params, channels);
113 if (err < 0)
114 {
115 printf("Channels count (%i) not available for playbacks: %s\n", channels, snd_strerror(err));
116 return err;
117 }
118 /* set the stream rate */
119 rrate = sample_rate;
120 err = snd_pcm_hw_params_set_rate_near(handle, params, &rrate, 0);
121 if (err < 0)
122 {
123 printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err));
124 return err;
125 }
126 if (rrate != sample_rate)
127 {
128 printf("Rate doesn't match (requested %iHz, get %iHz)\n", sample_rate, err);
129 return -EINVAL;
130 }
131
132 /* set the buffer size */
133 err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &buffer_size);
134 if (err < 0)
135 {
136 printf("Unable to set buffer size %i for playback: %s\n", buffer_size, snd_strerror(err));
137 return err;
138 }
139
140 /* set the period size */
141 err = snd_pcm_hw_params_set_period_size_near (handle, params, &period_size, NULL);
142 if (err < 0)
143 {
144 printf("Unable to set period size %i for playback: %s\n", period_size, snd_strerror(err));
145 return err;
146 }
147 if (!frames)
148 frames = malloc(period_size * channels * sizeof(short));
149
150 /* write the parameters to device */
151 err = snd_pcm_hw_params(handle, params);
152 if (err < 0)
153 {
154 printf("Unable to set hw params for playback: %s\n", snd_strerror(err));
155 return err;
156 }
157 return 0;
158}
159
160/* Set sw params: playback start threshold and low buffer watermark */
161static int set_swparams(snd_pcm_t *handle)
162{
163 int err;
164
165 snd_pcm_sw_params_t *swparams;
166 snd_pcm_sw_params_alloca(&swparams);
167
168 /* get the current swparams */
169 err = snd_pcm_sw_params_current(handle, swparams);
170 if (err < 0)
171 {
172 printf("Unable to determine current swparams for playback: %s\n", snd_strerror(err));
173 return err;
174 }
175 /* start the transfer when the buffer is haalmost full */
176 err = snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size / 2);
177 if (err < 0)
178 {
179 printf("Unable to set start threshold mode for playback: %s\n", snd_strerror(err));
180 return err;
181 }
182 /* allow the transfer when at least period_size samples can be processed */
183 err = snd_pcm_sw_params_set_avail_min(handle, swparams, period_size);
184 if (err < 0)
185 {
186 printf("Unable to set avail min for playback: %s\n", snd_strerror(err));
187 return err;
188 }
189 /* write the parameters to the playback device */
190 err = snd_pcm_sw_params(handle, swparams);
191 if (err < 0)
192 {
193 printf("Unable to set sw params for playback: %s\n", snd_strerror(err));
194 return err;
195 }
196 return 0;
197}
198
199/* copy pcm samples to a spare buffer, suitable for snd_pcm_writei() */
200static bool fill_frames(void)
201{
202 ssize_t copy_n, frames_left = period_size;
203 bool new_buffer = false;
204
205 while (frames_left > 0)
206 {
207 if (!pcm_size)
208 {
209 new_buffer = true;
210 pcm_play_get_more_callback((void **)&pcm_data, &pcm_size);
211 if (!pcm_size || !pcm_data)
212 return false;
213 }
214 copy_n = MIN((ssize_t)pcm_size, frames_left*4);
215 memcpy(&frames[2*(period_size-frames_left)], pcm_data, copy_n);
216
217 pcm_data += copy_n;
218 pcm_size -= copy_n;
219 frames_left -= copy_n/4;
220
221 if (new_buffer)
222 {
223 new_buffer = false;
224 pcm_play_dma_started_callback();
225 }
226 }
227 return true;
228}
229
230#ifdef USE_ASYNC_CALLBACK
231static void async_callback(snd_async_handler_t *ahandler)
232{
233 snd_pcm_t *handle = snd_async_handler_get_pcm(ahandler);
234
235 if (pthread_mutex_trylock(&pcm_mtx) != 0)
236 return;
237#else
238static void pcm_tick(void)
239{
240 if (snd_pcm_state(handle) != SND_PCM_STATE_RUNNING)
241 return;
242#endif
243
244 while (snd_pcm_avail_update(handle) >= period_size)
245 {
246 if (fill_frames())
247 {
248 int err = snd_pcm_writei(handle, frames, period_size);
249 if (err < 0 && err != period_size && err != -EAGAIN)
250 {
251 printf("Write error: written %i expected %li\n", err, period_size);
252 break;
253 }
254 }
255 else
256 {
257 DEBUGF("%s: No Data.\n", __func__);
258 break;
259 }
260 }
261#ifdef USE_ASYNC_CALLBACK
262 pthread_mutex_unlock(&pcm_mtx);
263#endif
264}
265
266static int async_rw(snd_pcm_t *handle)
267{
268 int err;
269 snd_pcm_sframes_t sample_size;
270 short *samples;
271
272#ifdef USE_ASYNC_CALLBACK
273 err = snd_async_add_pcm_handler(&ahandler, handle, async_callback, NULL);
274 if (err < 0)
275 {
276 DEBUGF("Unable to register async handler: %s\n", snd_strerror(err));
277 return err;
278 }
279#endif
280
281 /* fill buffer with silence to initiate playback without noisy click */
282 sample_size = buffer_size;
283 samples = malloc(sample_size * channels * sizeof(short));
284
285 snd_pcm_format_set_silence(format, samples, sample_size);
286 err = snd_pcm_writei(handle, samples, sample_size);
287 free(samples);
288
289 if (err < 0)
290 {
291 DEBUGF("Initial write error: %s\n", snd_strerror(err));
292 return err;
293 }
294 if (err != (ssize_t)sample_size)
295 {
296 DEBUGF("Initial write error: written %i expected %li\n", err, sample_size);
297 return err;
298 }
299 if (snd_pcm_state(handle) == SND_PCM_STATE_PREPARED)
300 {
301 err = snd_pcm_start(handle);
302 if (err < 0)
303 {
304 DEBUGF("Start error: %s\n", snd_strerror(err));
305 return err;
306 }
307 }
308 return 0;
309}
310
311
312void cleanup(void)
313{
314 free(frames);
315 frames = NULL;
316 snd_pcm_close(handle);
317}
318
319
320void pcm_play_dma_init(void)
321{
322 int err;
323
324
325 if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
326 {
327 printf("%s(): Cannot open device %s: %s\n", __func__, device, snd_strerror(err));
328 exit(EXIT_FAILURE);
329 return;
330 }
331
332 if ((err = snd_pcm_nonblock(handle, 1)))
333 printf("Could not set non-block mode: %s\n", snd_strerror(err));
334
335 if ((err = set_hwparams(handle, rate)) < 0)
336 {
337 printf("Setting of hwparams failed: %s\n", snd_strerror(err));
338 exit(EXIT_FAILURE);
339 }
340 if ((err = set_swparams(handle)) < 0)
341 {
342 printf("Setting of swparams failed: %s\n", snd_strerror(err));
343 exit(EXIT_FAILURE);
344 }
345
346#ifdef USE_ASYNC_CALLBACK
347 pthread_mutexattr_t attr;
348 pthread_mutexattr_init(&attr);
349 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
350 pthread_mutex_init(&pcm_mtx, &attr);
351#else
352 tick_add_task(pcm_tick);
353#endif
354
355
356 atexit(cleanup);
357 return;
358}
359
360
361void pcm_play_lock(void)
362{
363#ifdef USE_ASYNC_CALLBACK
364 pthread_mutex_lock(&pcm_mtx);
365#else
366 if (recursion++ == 0)
367 tick_remove_task(pcm_tick);
368#endif
369}
370
371void pcm_play_unlock(void)
372{
373#ifdef USE_ASYNC_CALLBACK
374 pthread_mutex_unlock(&pcm_mtx);
375#else
376 if (--recursion == 0)
377 tick_add_task(pcm_tick);
378#endif
379}
380
381static void pcm_dma_apply_settings_nolock(void)
382{
383 snd_pcm_drop(handle);
384 set_hwparams(handle, pcm_sampr);
385}
386
387void pcm_dma_apply_settings(void)
388{
389 pcm_play_lock();
390 pcm_dma_apply_settings_nolock();
391 pcm_play_unlock();
392}
393
394
395void pcm_play_dma_pause(bool pause)
396{
397 snd_pcm_pause(handle, pause);
398}
399
400
401void pcm_play_dma_stop(void)
402{
403 snd_pcm_drain(handle);
404}
405
406void pcm_play_dma_start(const void *addr, size_t size)
407{
408 pcm_dma_apply_settings_nolock();
409
410 pcm_data = addr;
411 pcm_size = size;
412
413 while (1)
414 {
415 snd_pcm_state_t state = snd_pcm_state(handle);
416 switch (state)
417 {
418 case SND_PCM_STATE_RUNNING:
419 return;
420 case SND_PCM_STATE_XRUN:
421 {
422 DEBUGF("Trying to recover from error\n");
423 int err = snd_pcm_recover(handle, -EPIPE, 0);
424 if (err < 0)
425 DEBUGF("Recovery failed: %s\n", snd_strerror(err));
426 continue;
427 }
428 case SND_PCM_STATE_SETUP:
429 {
430 int err = snd_pcm_prepare(handle);
431 if (err < 0)
432 printf("Prepare error: %s\n", snd_strerror(err));
433 /* fall through */
434 }
435 case SND_PCM_STATE_PREPARED:
436 { /* prepared state, we need to fill the buffer with silence before
437 * starting */
438 int err = async_rw(handle);
439 if (err < 0)
440 printf("Start error: %s\n", snd_strerror(err));
441 return;
442 }
443 case SND_PCM_STATE_PAUSED:
444 { /* paused, simply resume */
445 pcm_play_dma_pause(0);
446 return;
447 }
448 case SND_PCM_STATE_DRAINING:
449 /* run until drained */
450 continue;
451 default:
452 DEBUGF("Unhandled state: %s\n", snd_pcm_state_name(state));
453 return;
454 }
455 }
456}
457
458size_t pcm_get_bytes_waiting(void)
459{
460 return pcm_size;
461}
462
463const void * pcm_play_dma_get_peak_buffer(int *count)
464{
465 uintptr_t addr = (uintptr_t)pcm_data;
466 *count = pcm_size / 4;
467 return (void *)((addr + 3) & ~3);
468}
469
470void pcm_play_dma_postinit(void)
471{
472}
473
474
475void pcm_set_mixer_volume(int volume)
476{
477 (void)volume;
478}
479#ifdef HAVE_RECORDING
480void pcm_rec_lock(void)
481{
482}
483
484void pcm_rec_unlock(void)
485{
486}
487
488void pcm_rec_dma_init(void)
489{
490}
491
492void pcm_rec_dma_close(void)
493{
494}
495
496void pcm_rec_dma_start(void *start, size_t size)
497{
498 (void)start;
499 (void)size;
500}
501
502void pcm_rec_dma_stop(void)
503{
504}
505
506const void * pcm_rec_dma_get_peak_buffer(void)
507{
508 return NULL;
509}
510
511void audiohw_set_recvol(int left, int right, int type)
512{
513 (void)left;
514 (void)right;
515 (void)type;
516}
517
518#endif /* HAVE_RECORDING */
diff --git a/firmware/target/hosted/ypr0/adc-target.h b/firmware/target/hosted/ypr0/adc-target.h
new file mode 100644
index 0000000000..bdbc4cfabd
--- /dev/null
+++ b/firmware/target/hosted/ypr0/adc-target.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: adc-target.h 29516 2011-03-05 15:31:52Z thomasjfox $
9 *
10 * Copyright (C) 2011 by Lorenzo Miori
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __ADC_TARGET_H__
23#define __ADC_TARGET_H__
24
25#endif /* __ADC_TARGET_H__ */
diff --git a/firmware/target/hosted/ypr0/ascodec-target.h b/firmware/target/hosted/ypr0/ascodec-target.h
new file mode 100644
index 0000000000..f4ecf20a1b
--- /dev/null
+++ b/firmware/target/hosted/ypr0/ascodec-target.h
@@ -0,0 +1,92 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: ascodec-target.h 26116 2010-05-17 20:53:25Z funman $
9 *
10 * Module wrapper for AS3543 audio codec, using /dev/afe (afe.ko) of Samsung YP-R0
11 *
12 * Copyright (c) 2011 Lorenzo Miori
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#ifndef _ASCODEC_TARGET_H
25#define _ASCODEC_TARGET_H
26
27#include "as3514.h"
28#include "kernel.h"
29#include "adc.h"
30#include "ascodec.h"
31
32/* ioctl parameter struct */
33
34struct codec_req_struct {
35/* This works for every kind of afe.ko module requests */
36 unsigned char reg; /* Main register address */
37 unsigned char subreg; /* Set this only if you are reading/writing a PMU register*/
38 unsigned char value; /* To be read if reading a register; to be set if writing to a register */
39};
40
41int ascodec_init(void);
42void ascodec_close(void);
43int ascodec_write(unsigned int reg, unsigned int value);
44int ascodec_read(unsigned int reg);
45void ascodec_write_pmu(unsigned int index, unsigned int subreg, unsigned int value);
46int ascodec_read_pmu(unsigned int index, unsigned int subreg);
47void ascodec_set(unsigned int reg, unsigned int bits);
48void ascodec_clear(unsigned int reg, unsigned int bits);
49void ascodec_write_masked(unsigned int reg, unsigned int bits, unsigned int mask);
50int ascodec_readbytes(unsigned int index, unsigned int len, unsigned char *data);
51unsigned short adc_read(int channel);
52void ascodec_lock(void);
53void ascodec_unlock(void);
54
55static inline bool ascodec_chg_status(void)
56{
57 return ascodec_read(AS3514_IRQ_ENRD0) & CHG_STATUS;
58}
59
60static inline bool ascodec_endofch(void)
61{
62 return ascodec_read(AS3514_IRQ_ENRD0) & CHG_ENDOFCH;
63}
64
65static inline void ascodec_monitor_endofch(void)
66{
67 ascodec_write(AS3514_IRQ_ENRD0, IRQ_ENDOFCH);
68}
69
70static inline void ascodec_wait_adc_finished(void)
71{
72 /*
73 * FIXME: not implemented
74 *
75 * If irqs are not available on the target platform,
76 * this should be most likely implemented by polling
77 * AS3514_IRQ_ENRD2 in the same way powermgmt-ascodec.c
78 * is polling IRQ_ENDOFCH.
79 */
80}
81
82static inline void ascodec_write_charger(int value)
83{
84 ascodec_write_pmu(AS3543_CHARGER, 1, value);
85}
86
87static inline int ascodec_read_charger(void)
88{
89 return ascodec_read_pmu(AS3543_CHARGER, 1);
90}
91
92#endif /* !_ASCODEC_TARGET_H */
diff --git a/firmware/target/hosted/ypr0/ascodec-ypr0.c b/firmware/target/hosted/ypr0/ascodec-ypr0.c
new file mode 100644
index 0000000000..a4e92e6f6b
--- /dev/null
+++ b/firmware/target/hosted/ypr0/ascodec-ypr0.c
@@ -0,0 +1,206 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: ascodec-target.h 26116 2010-05-17 20:53:25Z funman $
9 *
10 * Module wrapper for AS3543 audio codec, using /dev/afe (afe.ko) of Samsung YP-R0
11 *
12 * Copyright (c) 2011 Lorenzo Miori
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#include "fcntl.h"
25#include "unistd.h"
26#include "stdio.h"
27#include "string.h"
28#include "sys/ioctl.h"
29#include "stdlib.h"
30
31#include "ascodec-target.h"
32
33int afe_dev = -1;
34
35/* Write to a normal register */
36#define IOCTL_REG_WRITE 0x40034101
37/* Write to a PMU register */
38#define IOCTL_SUBREG_WRITE 0x40034103
39/* Read from a normal register */
40#define IOCTL_REG_READ 0x80034102
41/* Read from a PMU register */
42#define IOCTL_SUBREG_READ 0x80034103
43
44static struct mutex as_mtx;
45
46int ascodec_init(void) {
47
48 afe_dev = open("/dev/afe", O_RDWR);
49
50 mutex_init(&as_mtx);
51
52 return afe_dev;
53
54}
55
56void ascodec_close(void) {
57
58 if (afe_dev >= 0) {
59 close(afe_dev);
60 }
61
62}
63
64/* Read functions returns -1 if fail, otherwise the register's value if success */
65/* Write functions return >= 0 if success, otherwise -1 if fail */
66
67int ascodec_write(unsigned int reg, unsigned int value)
68{
69 struct codec_req_struct y;
70 struct codec_req_struct *p;
71 p = &y;
72 p->reg = reg;
73 p->value = value;
74 return ioctl(afe_dev, IOCTL_REG_WRITE, p);
75}
76
77int ascodec_read(unsigned int reg)
78{
79 int retval = -1;
80 struct codec_req_struct y;
81 struct codec_req_struct *p;
82 p = &y;
83 p->reg = reg;
84 retval = ioctl(afe_dev, IOCTL_REG_READ, p);
85 if (retval >= 0)
86 return p->value;
87 else
88 return retval;
89}
90
91void ascodec_write_pmu(unsigned int index, unsigned int subreg,
92 unsigned int value)
93{
94 struct codec_req_struct y;
95 struct codec_req_struct *p;
96 p = &y;
97 p->reg = index;
98 p->subreg = subreg;
99 p->value = value;
100 ioctl(afe_dev, IOCTL_SUBREG_WRITE, p);
101}
102
103int ascodec_read_pmu(unsigned int index, unsigned int subreg)
104{
105 int retval = -1;
106 struct codec_req_struct y;
107 struct codec_req_struct *p;
108 p = &y;
109 p->reg = index;
110 p->subreg = subreg;
111 retval = ioctl(afe_dev, IOCTL_SUBREG_READ, p);
112 if (retval >= 0)
113 return p->value;
114 else
115 return retval;
116}
117
118/* Helpers to set/clear bits */
119void ascodec_set(unsigned int reg, unsigned int bits)
120{
121 ascodec_write(reg, ascodec_read(reg) | bits);
122}
123
124void ascodec_clear(unsigned int reg, unsigned int bits)
125{
126 ascodec_write(reg, ascodec_read(reg) & ~bits);
127}
128
129void ascodec_write_masked(unsigned int reg, unsigned int bits,
130 unsigned int mask)
131{
132 ascodec_write(reg, (ascodec_read(reg) & ~mask) | (bits & mask));
133}
134
135/*FIXME: doesn't work */
136int ascodec_readbytes(unsigned int index, unsigned int len, unsigned char *data)
137{
138 unsigned int i;
139
140 for (i=index; i<len; i++) {
141 data[i] = ascodec_read(i);
142 printf("Register %i: value=%i\n",index,data[i]);
143 }
144
145 printf("TOTAL: %i\n", i);
146
147 return i;
148}
149
150/*
151 * NOTE:
152 * After the conversion to interrupts, ascodec_(lock|unlock) are only used by
153 * adc-as3514.c to protect against other threads corrupting the result by using
154 * the ADC at the same time.
155 *
156 * Concurrent ascodec_(async_)?(read|write) calls are instead protected
157 * by the R0's Kernel I2C driver for ascodec (mutexed), so it's automatically safe
158 */
159
160void ascodec_lock(void)
161{
162 mutex_lock(&as_mtx);
163}
164
165void ascodec_unlock(void)
166{
167 mutex_unlock(&as_mtx);
168}
169
170/* Read 10-bit channel data */
171unsigned short adc_read(int channel)
172{
173 unsigned short data = 0;
174
175 if ((unsigned)channel >= NUM_ADC_CHANNELS)
176 return 0;
177
178 ascodec_lock();
179
180 /* Select channel */
181 ascodec_write(AS3514_ADC_0, (channel << 4));
182 unsigned char buf[2];
183
184 /*
185 * The AS3514 ADC will trigger an interrupt when the conversion
186 * is finished, if the corresponding enable bit in IRQ_ENRD2
187 * is set.
188 * Previously the code did not wait and this apparently did
189 * not pose any problems, but this should be more correct.
190 * Without the wait the data read back may be completely or
191 * partially (first one of the two bytes) stale.
192 */
193 /*FIXME: not implemented*/
194 ascodec_wait_adc_finished();
195
196 /* Read data */
197 ascodec_readbytes(AS3514_ADC_0, 2, buf);
198 data = (((buf[0] & 0x3) << 8) | buf[1]);
199
200 ascodec_unlock();
201 return data;
202}
203
204void adc_init(void)
205{
206}
diff --git a/firmware/target/hosted/ypr0/backlight-target.h b/firmware/target/hosted/ypr0/backlight-target.h
new file mode 100644
index 0000000000..561e159e8c
--- /dev/null
+++ b/firmware/target/hosted/ypr0/backlight-target.h
@@ -0,0 +1,29 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: backlight-target.h 19322 2008-12-04 04:16:53Z jethead71 $
9 *
10 * Copyright (C) 2011 by Lorenzo Miori
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef BACKLIGHT_TARGET_H
22#define BACKLIGHT_TARGET_H
23
24bool _backlight_init(void);
25void _backlight_on(void);
26void _backlight_off(void);
27void _backlight_set_brightness(int brightness);
28
29#endif /* BACKLIGHT_TARGET_H */
diff --git a/firmware/target/hosted/ypr0/backlight-ypr0.c b/firmware/target/hosted/ypr0/backlight-ypr0.c
new file mode 100644
index 0000000000..930b56be2e
--- /dev/null
+++ b/firmware/target/hosted/ypr0/backlight-ypr0.c
@@ -0,0 +1,89 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: backlight-gigabeat-s.c 25800 2010-05-04 10:07:53Z jethead71 $
9 *
10 * Copyright (C) 2011 by Lorenzo Miori
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
22#include "system.h"
23#include "backlight.h"
24#include "backlight-target.h"
25#include "lcd.h"
26#include "as3514.h"
27#include "ascodec-target.h"
28#include <fcntl.h>
29#include "unistd.h"
30
31static bool backlight_on_status = true; /* Is on or off? */
32
33/*TODO: see if LCD sleep could be implemented in a better way -> ie using a rockbox feature */
34/* Turn off LCD power supply */
35static void _backlight_lcd_sleep(void)
36{
37 int fp = open("/sys/class/graphics/fb0/blank", O_RDWR);
38 write(fp, "1", 1);
39 close(fp);
40}
41/* Turn on LCD screen */
42static void _backlight_lcd_power(void)
43{
44 int fp = open("/sys/class/graphics/fb0/blank", O_RDWR);
45 write(fp, "0", 1);
46 close(fp);
47}
48
49bool _backlight_init(void)
50{
51 /* We have nothing to do */
52 return true;
53}
54
55void _backlight_on(void)
56{
57 if (!backlight_on_status)
58 {
59 /* Turn on lcd power before backlight */
60 _backlight_lcd_power();
61 /* Original app sets this to 0xb1 when backlight is on... */
62 ascodec_write_pmu(AS3543_BACKLIGHT, 0x1, 0xb1);
63 }
64
65 backlight_on_status = true;
66
67}
68
69void _backlight_off(void)
70{
71 if (backlight_on_status) {
72 /* Disabling the DCDC15 completely, keeps brightness register value */
73 ascodec_write_pmu(AS3543_BACKLIGHT, 0x1, 0x00);
74 /* Turn off lcd power then */
75 _backlight_lcd_sleep();
76 }
77
78 backlight_on_status = false;
79}
80
81void _backlight_set_brightness(int brightness)
82{
83 /* Just another check... */
84 if (brightness > MAX_BRIGHTNESS_SETTING)
85 brightness = MAX_BRIGHTNESS_SETTING;
86 if (brightness < MIN_BRIGHTNESS_SETTING)
87 brightness = MIN_BRIGHTNESS_SETTING;
88 ascodec_write_pmu(AS3543_BACKLIGHT, 0x3, brightness << 3 & 0xf8);
89}
diff --git a/firmware/target/hosted/ypr0/button-target.h b/firmware/target/hosted/ypr0/button-target.h
new file mode 100644
index 0000000000..5d65d97607
--- /dev/null
+++ b/firmware/target/hosted/ypr0/button-target.h
@@ -0,0 +1,53 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: button-target.h 29248 2011-02-08 20:05:25Z thomasjfox $
9 *
10 * Copyright (C) 2011 by Lorenzo Miori
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _BUTTON_TARGET_H_
23#define _BUTTON_TARGET_H_
24
25#include <stdbool.h>
26#include "config.h"
27
28void button_init_device(void);
29void button_close_device(void);
30int button_read_device(void);
31
32/* Logical buttons key codes */
33#define BUTTON_UP 0x00000001
34#define BUTTON_DOWN 0x00000002
35#define BUTTON_LEFT 0x00000004
36#define BUTTON_RIGHT 0x00000008
37#define BUTTON_USER 0x00000010
38#define BUTTON_MENU 0x00000020
39#define BUTTON_BACK 0x00000040
40#define BUTTON_POWER 0x00000080
41#define BUTTON_SELECT 0x00000100
42
43#define BUTTON_MAIN 0x1FF /* all buttons */
44
45/* No remote */
46#define BUTTON_REMOTE 0
47
48/* Software power-off */
49#define POWEROFF_BUTTON BUTTON_POWER
50/* About 3 seconds */
51#define POWEROFF_COUNT 10
52
53#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/hosted/ypr0/button-ypr0.c b/firmware/target/hosted/ypr0/button-ypr0.c
new file mode 100644
index 0000000000..4298410161
--- /dev/null
+++ b/firmware/target/hosted/ypr0/button-ypr0.c
@@ -0,0 +1,103 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: button-sdl.c 30482 2011-09-08 14:53:28Z kugel $
9 *
10 * Copyright (C) 2011 Lorenzo Miori
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdio.h>
23#include <unistd.h>
24#include <fcntl.h>
25#include <stdlib.h> /* EXIT_SUCCESS */
26#include "config.h"
27#include "button.h"
28#include "kernel.h"
29#include "system.h"
30#include "button-target.h"
31
32/* R0 physical key codes */
33enum ypr0_buttons {
34 R0BTN_NONE = BUTTON_NONE,
35 R0BTN_POWER = 1,
36 R0BTN_UP,
37 R0BTN_DOWN,
38 R0BTN_RIGHT,
39 R0BTN_LEFT,
40 R0BTN_CENTRAL,
41 R0BTN_MENU,
42 R0BTN_BACK,
43 R0BTN_3DOTS = 11,
44};
45
46
47static int r0_btn_fd = 0;
48/* Samsung keypad driver doesn't allow multiple key combinations :( */
49static enum ypr0_buttons r0_read_key(void)
50{
51 unsigned char keys;
52
53 if (r0_btn_fd < 0)
54 return 0;
55
56 if (read(r0_btn_fd, &keys, 1))
57 return keys;
58
59 return 0;
60}
61
62/* Conversion from physical keypress code to logic key code */
63static int key_to_button(enum ypr0_buttons keyboard_button)
64{
65 switch (keyboard_button)
66 {
67 default: return BUTTON_NONE;
68 case R0BTN_POWER: return BUTTON_POWER;
69 case R0BTN_UP: return BUTTON_UP;
70 case R0BTN_DOWN: return BUTTON_DOWN;
71 case R0BTN_RIGHT: return BUTTON_RIGHT;
72 case R0BTN_LEFT: return BUTTON_LEFT;
73 case R0BTN_CENTRAL: return BUTTON_SELECT;
74 case R0BTN_MENU: return BUTTON_MENU;
75 case R0BTN_BACK: return BUTTON_BACK;
76 case R0BTN_3DOTS: return BUTTON_USER;
77 }
78}
79
80int button_read_device(void)
81{
82 return key_to_button(r0_read_key());
83}
84
85
86/* Open the keypad device: it is offered by r0Btn.ko module */
87void button_init_device(void)
88{
89 r0_btn_fd = open("/dev/r0Btn", O_RDONLY);
90 if (r0_btn_fd < 0)
91 printf("/dev/r0Btn open error!");
92}
93
94#ifdef BUTTON_DRIVER_CLOSE
95/* I'm not sure it's called at shutdown...give a check! */
96void button_close_device(void)
97{
98 if (r0_btn_fd >= 0) {
99 close(r0_btn_fd);
100 printf("/dev/r0Btn closed!");
101 }
102}
103#endif /* BUTTON_DRIVER_CLOSE */
diff --git a/firmware/target/hosted/ypr0/dir-target.h b/firmware/target/hosted/ypr0/dir-target.h
new file mode 100644
index 0000000000..48859526df
--- /dev/null
+++ b/firmware/target/hosted/ypr0/dir-target.h
@@ -0,0 +1,56 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __DIR_TARGET_H__
23#define __DIR_TARGET_H__
24
25#include <dirent.h>
26/* including unistd.h is too noisy */
27extern int rmdir(const char* name);
28
29
30#define dirent_uncached dirent
31#define DIR_UNCACHED DIR
32#define opendir_uncached _opendir
33#define readdir_uncached _readdir
34#define closedir_uncached _closedir
35#define mkdir_uncached _mkdir
36#define rmdir_uncached rmdir
37
38#define dirent_ypr0 dirent
39#define DIR_ypr0 DIR
40#define opendir_ypr0 _opendir
41#define readdir_ypr0 _readdir
42#define closedir_ypr0 _closedir
43#define mkdir_ypr0 _mkdir
44#define rmdir_ypr0 rmdir
45
46extern DIR* _opendir(const char* name);
47extern int _mkdir(const char* name);
48extern int _closedir(DIR* dir);
49extern struct dirent *_readdir(DIR* dir);
50extern void fat_size(unsigned long *size, unsigned long *free);
51
52#define DIRFUNCTIONS_DEFINED
53#define DIRENT_DEFINED
54#define DIR_DEFINED
55
56#endif /* __DIR_TARGET_H__ */
diff --git a/firmware/target/hosted/ypr0/fs-ypr0.c b/firmware/target/hosted/ypr0/fs-ypr0.c
new file mode 100644
index 0000000000..7f49a5f91a
--- /dev/null
+++ b/firmware/target/hosted/ypr0/fs-ypr0.c
@@ -0,0 +1,141 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdlib.h>
23#include <sys/stat.h> /* stat() */
24#include <stdio.h> /* snprintf */
25#include <string.h> /* size_t */
26#include <dirent.h>
27#include <time.h> /* localtime() */
28#include "system-target.h"
29#include "dir-target.h"
30#include "file.h"
31#include "dir.h"
32#include "rbpaths.h"
33
34
35long filesize(int fd)
36{
37 struct stat buf;
38
39 if (!fstat(fd, &buf))
40 return buf.st_size;
41 else
42 return -1;
43}
44
45/* do we really need this in the app? */
46void fat_size(unsigned long* size, unsigned long* free)
47{
48 *size = *free = 0;
49}
50
51#undef opendir
52#undef closedir
53#undef mkdir
54#undef readdir
55
56/* need to wrap around DIR* because we need to save the parent's
57 * directory path in order to determine dirinfo */
58struct __dir {
59 DIR *dir;
60 char *path;
61};
62
63DIR* _opendir(const char *name)
64{
65 char *buf = malloc(sizeof(struct __dir) + strlen(name)+1);
66 if (!buf)
67 return NULL;
68
69 struct __dir *this = (struct __dir*)buf;
70
71 this->path = buf+sizeof(struct __dir);
72 /* definitely fits due to strlen() */
73 strcpy(this->path, name);
74
75 this->dir = opendir(name);
76
77 if (!this->dir)
78 {
79 free(buf);
80 return NULL;
81 }
82 return (DIR*)this;
83}
84
85int _mkdir(const char *name)
86{
87 return mkdir(name, 0777);
88}
89
90int _closedir(DIR *dir)
91{
92 struct __dir *this = (struct __dir*)dir;
93 int ret = closedir(this->dir);
94 free(this);
95 return ret;
96}
97
98struct dirent* _readdir(DIR* dir)
99{
100 struct __dir *d = (struct __dir*)dir;
101 return readdir(d->dir);
102}
103
104struct dirinfo dir_get_info(DIR* _parent, struct dirent *dir)
105{
106 struct __dir *parent = (struct __dir*)_parent;
107 struct stat s;
108 struct tm *tm = NULL;
109 struct dirinfo ret;
110 char path[MAX_PATH];
111
112 snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name);
113 memset(&ret, 0, sizeof(ret));
114
115 if (!stat(path, &s))
116 {
117 if (S_ISDIR(s.st_mode))
118 {
119 ret.attribute = ATTR_DIRECTORY;
120 }
121 ret.size = s.st_size;
122 tm = localtime(&(s.st_mtime));
123 }
124
125 if (!lstat(path, &s) && S_ISLNK(s.st_mode))
126 {
127 ret.attribute |= ATTR_LINK;
128 }
129
130 if (tm)
131 {
132 ret.wrtdate = ((tm->tm_year - 80) << 9) |
133 ((tm->tm_mon + 1) << 5) |
134 tm->tm_mday;
135 ret.wrttime = (tm->tm_hour << 11) |
136 (tm->tm_min << 5) |
137 (tm->tm_sec >> 1);
138 }
139
140 return ret;
141}
diff --git a/firmware/target/hosted/ypr0/i2c-target.h b/firmware/target/hosted/ypr0/i2c-target.h
new file mode 100644
index 0000000000..3b046bba96
--- /dev/null
+++ b/firmware/target/hosted/ypr0/i2c-target.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: i2c-target.h 29516 2011-03-05 15:31:52Z thomasjfox $
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __I2C_TARGET_H__
23#define __I2C_TARGET_H__
24
25#endif /* __I2C_TARGET_H__ */
diff --git a/firmware/target/hosted/ypr0/kernel-ypr0.c b/firmware/target/hosted/ypr0/kernel-ypr0.c
new file mode 100644
index 0000000000..bcf2cee583
--- /dev/null
+++ b/firmware/target/hosted/ypr0/kernel-ypr0.c
@@ -0,0 +1,163 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2010 Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23#include <time.h>
24#include <signal.h>
25#include <errno.h>
26#include <unistd.h>
27#include <pthread.h>
28#include "config.h"
29#include "system.h"
30#include "button.h"
31#include "audio.h"
32#include "panic.h"
33#include "timer.h"
34
35
36static pthread_cond_t wfi_cond = PTHREAD_COND_INITIALIZER;
37static pthread_mutex_t wfi_mtx = PTHREAD_MUTEX_INITIALIZER;
38/*
39 * call tick tasks and wake the scheduler up */
40void timer_signal(union sigval arg)
41{
42 (void)arg;
43 call_tick_tasks();
44 interrupt();
45}
46
47/*
48 * wait on the sem which the signal handler posts to save cpu time (aka sleep)
49 *
50 * other mechanisms could use them as well */
51void wait_for_interrupt(void)
52{
53 pthread_cond_wait(&wfi_cond, &wfi_mtx);
54}
55
56/*
57 * Wakeup the kernel, if sleeping (shall not be called from a signal handler) */
58void interrupt(void)
59{
60 pthread_cond_signal(&wfi_cond);
61}
62
63
64/*
65 * setup a hrtimer to send a signal to our process every tick
66 */
67union sigval tick_arg = {
68 .sival_int = 0,
69};
70
71void tick_start(unsigned int interval_in_ms)
72{
73 int ret = 0;
74 timer_t timerid;
75 struct itimerspec ts;
76 sigevent_t sigev;
77
78 /* initializing in the declaration causes some weird warnings */
79 memset(&sigev, 0, sizeof(sigevent_t));
80 sigev.sigev_notify = SIGEV_THREAD,
81 sigev.sigev_notify_function = timer_signal;
82
83 ts.it_value.tv_sec = ts.it_interval.tv_sec = 0;
84 ts.it_value.tv_nsec = ts.it_interval.tv_nsec = interval_in_ms*1000*1000;
85
86 /* add the timer */
87 ret |= timer_create(CLOCK_REALTIME, &sigev, &timerid);
88 ret |= timer_settime(timerid, 0, &ts, NULL);
89
90 /* Grab the mutex already now and leave it to this thread. We don't
91 * care about race conditions when signaling the condition (because
92 * they are not critical), but a mutex is necessary due to the API */
93 pthread_mutex_lock(&wfi_mtx);
94
95 if (ret != 0)
96 panicf("%s(): %s\n", __func__, strerror(errno));
97}
98
99#define cycles_to_microseconds(cycles) \
100 ((int)((1000000*cycles)/TIMER_FREQ))
101
102
103static timer_t timer_tid;
104static int timer_prio = -1;
105void (*global_unreg_callback)(void);
106void (*global_timer_callback)(void);
107
108static void timer_cb(union sigval arg)
109{
110 (void)arg;
111 if (global_timer_callback)
112 global_timer_callback();
113}
114
115bool timer_register(int reg_prio, void (*unregister_callback)(void),
116 long cycles, void (*timer_callback)(void))
117{
118 int ret = 0;
119 struct itimerspec ts;
120 sigevent_t sigev;
121 long in_us = cycles_to_microseconds(cycles);
122
123 if (reg_prio <= timer_prio || in_us <= 0)
124 return false;
125
126 if (timer_prio >= 0 && global_unreg_callback)
127 global_unreg_callback();
128
129 /* initializing in the declaration causes some weird warnings */
130 memset(&sigev, 0, sizeof(sigevent_t));
131 sigev.sigev_notify = SIGEV_THREAD,
132 sigev.sigev_notify_function = timer_cb;
133
134 ts.it_value.tv_sec = ts.it_interval.tv_sec = in_us / 1000000;
135 ts.it_value.tv_nsec = ts.it_interval.tv_nsec = (in_us%1000000)*1000;
136
137 /* add the timer */
138 ret |= timer_create(CLOCK_REALTIME, &sigev, &timer_tid);
139 ret |= timer_settime(timer_tid, 0, &ts, NULL);
140
141 global_timer_callback = timer_callback;
142 global_unreg_callback = unregister_callback;
143 timer_prio = reg_prio;
144
145 return ret == 0;
146}
147
148bool timer_set_period(long cycles)
149{
150 struct itimerspec ts;
151 long in_us = cycles_to_microseconds(cycles);
152 ts.it_value.tv_sec = ts.it_interval.tv_sec = in_us / 1000000;
153 ts.it_value.tv_nsec = ts.it_interval.tv_nsec = (in_us%1000000)*1000;
154
155 return timer_settime(timer_tid, 0, &ts, NULL) == 0;
156}
157
158void timer_unregister(void)
159{
160 timer_delete(timer_tid);
161 timer_prio = -1;
162}
163
diff --git a/firmware/target/hosted/ypr0/lc-ypr0.c b/firmware/target/hosted/ypr0/lc-ypr0.c
new file mode 100644
index 0000000000..434e901a56
--- /dev/null
+++ b/firmware/target/hosted/ypr0/lc-ypr0.c
@@ -0,0 +1,40 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <string.h> /* size_t */
23#include "load_code.h"
24
25/* the load_code wrappers simply wrap, nothing to do */
26void *lc_open(const char *filename, unsigned char *buf, size_t buf_size)
27{
28 return _lc_open(filename, buf, buf_size);
29}
30
31void *lc_get_header(void *handle)
32{
33 return _lc_get_header(handle);
34}
35
36void lc_close(void *handle)
37{
38 _lc_close(handle);
39}
40
diff --git a/firmware/target/hosted/ypr0/lcd-ypr0.c b/firmware/target/hosted/ypr0/lcd-ypr0.c
new file mode 100644
index 0000000000..f0565ae2d4
--- /dev/null
+++ b/firmware/target/hosted/ypr0/lcd-ypr0.c
@@ -0,0 +1,147 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: lcd-bitmap.c 29248 2011-02-08 20:05:25Z thomasjfox $
9 *
10 * Copyright (C) 2011 Lorenzo Miori, Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdlib.h>
23#include <unistd.h>
24#include <stdio.h>
25#include "string.h"
26#include <linux/fb.h>
27#include <sys/mman.h>
28#include <sys/ioctl.h>
29
30#include "file.h"
31#include "debug.h"
32#include "system.h"
33#include "screendump.h"
34#include "lcd.h"
35
36/* eqivalent to fb + y*width + x */
37#define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
38
39static int dev_fd = 0;
40static fb_data *dev_fb = 0;
41
42void lcd_update(void)
43{
44 /* update the entire display */
45 memcpy(dev_fb, lcd_framebuffer, sizeof(lcd_framebuffer));
46}
47
48/* Copy Rockbox frame buffer to the mmapped lcd device */
49void lcd_update_rect(int x, int y, int width, int height)
50{
51 /* nothing to draw? */
52 if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) ||
53 (y >= LCD_HEIGHT) || (x + width <= 0) || (y + height <= 0))
54 return;
55
56 /* do the necessary clipping */
57 if (x < 0)
58 { /* clip left */
59 width += x;
60 x = 0;
61 }
62 if (y < 0)
63 { /* clip top */
64 height += y;
65 y = 0;
66 }
67 if (x + width > LCD_WIDTH)
68 width = LCD_WIDTH - x; /* clip right */
69 if (y + height > LCD_HEIGHT)
70 height = LCD_HEIGHT - y; /* clip bottom */
71
72 fb_data* src = LCDADDR(x, y);
73 fb_data* dst = dev_fb + y*LCD_WIDTH + x;
74
75 if (LCD_WIDTH == width)
76 { /* optimized full-width update */
77 memcpy(dst, src, width * height * sizeof(fb_data));
78 }
79 else
80 { /* row by row */
81 do
82 {
83 memcpy(dst, src, width * sizeof(fb_data));
84 src += LCD_WIDTH;
85 dst += LCD_WIDTH;
86 } while(--height > 0);
87 }
88}
89
90void lcd_shutdown(void)
91{
92 printf("FB closed.");
93 munmap(dev_fb, sizeof(lcd_framebuffer));
94 close(dev_fd);
95}
96
97void lcd_init_device(void)
98{
99 size_t screensize;
100 struct fb_var_screeninfo vinfo;
101 struct fb_fix_screeninfo finfo;
102
103 /* Open the framebuffer device */
104 dev_fd = open("/dev/fb0", O_RDWR);
105 if (dev_fd == -1) {
106 perror("Error: cannot open framebuffer device");
107 exit(1);
108 }
109 printf("The framebuffer device was opened successfully.\n");
110
111 /* Get the fixed properties */
112 if (ioctl(dev_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
113 perror("Error reading fixed information");
114 exit(2);
115 }
116
117 /* Now we get the settable settings, and we set 16 bit bpp */
118 if (ioctl(dev_fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
119 perror("Error reading variable information");
120 exit(3);
121 }
122
123 vinfo.bits_per_pixel = 16;
124
125 if (ioctl(dev_fd, FBIOPUT_VSCREENINFO, &vinfo)) {
126 perror("fbset(ioctl)");
127 exit(4);
128 }
129
130 printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
131
132 /* Figure out the size of the screen in bytes */
133 screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
134 if (screensize != sizeof(lcd_framebuffer))
135 {
136 exit(4);
137 perror("Display and framebuffer mismatch!\n");
138 }
139
140 /* Map the device to memory */
141 dev_fb = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, dev_fd, 0);
142 if ((int)dev_fb == -1) {
143 perror("Error: failed to map framebuffer device to memory");
144 exit(4);
145 }
146 printf("The framebuffer device was mapped to memory successfully.\n");
147}
diff --git a/firmware/target/hosted/ypr0/powermgmt-ypr0.c b/firmware/target/hosted/ypr0/powermgmt-ypr0.c
new file mode 100644
index 0000000000..5701e9f02f
--- /dev/null
+++ b/firmware/target/hosted/ypr0/powermgmt-ypr0.c
@@ -0,0 +1,133 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: powermgmt-sim.c 29543 2011-03-08 19:33:30Z thomasjfox $
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include "system.h"
21#include <time.h>
22#include "kernel.h"
23#include "powermgmt.h"
24#include "ascodec-target.h"
25#include "stdio.h"
26
27#if 0 /*still unused*/
28/* The battery manufacturer's website shows discharge curves down to 3.0V,
29 so 'dangerous' and 'shutoff' levels of 3.4V and 3.3V should be safe.
30 */
31const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
32{
33 3550
34};
35
36const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
37{
38 3450
39};
40
41/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
42const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
43{
44 { 3300, 3692, 3740, 3772, 3798, 3828, 3876, 3943, 4013, 4094, 4194 }
45};
46
47#if CONFIG_CHARGING
48/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
49const unsigned short percent_to_volt_charge[11] =
50{
51 3417, 3802, 3856, 3888, 3905, 3931, 3973, 4025, 4084, 4161, 4219
52};
53#endif /* CONFIG_CHARGING */
54#endif
55
56#define BATT_MINMVOLT 3450 /* minimum millivolts of battery */
57#define BATT_MAXMVOLT 4150 /* maximum millivolts of battery */
58#define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in
59 minutes */
60
61extern void send_battery_level_event(void);
62extern int last_sent_battery_level;
63extern int battery_percent;
64
65static unsigned int battery_millivolts = BATT_MAXMVOLT;
66/* estimated remaining time in minutes */
67static int powermgmt_est_runningtime_min = BATT_MAXRUNTIME;
68
69static void battery_status_update(void)
70{
71 static time_t last_change = 0;
72 time_t now;
73
74 time(&now);
75
76 if (last_change < now) {
77 last_change = now;
78
79 battery_percent = 100 * (battery_millivolts - BATT_MINMVOLT) /
80 (BATT_MAXMVOLT - BATT_MINMVOLT);
81
82 powermgmt_est_runningtime_min =
83 battery_percent * BATT_MAXRUNTIME / 100;
84 }
85
86 send_battery_level_event();
87}
88
89void battery_read_info(int *voltage, int *level)
90{
91 battery_status_update();
92
93 if (voltage)
94 *voltage = battery_millivolts;
95
96 if (level)
97 *level = battery_percent;
98}
99
100unsigned int battery_voltage(void)
101{
102 battery_status_update();
103 return battery_millivolts;
104}
105
106int battery_level(void)
107{
108 battery_status_update();
109 return battery_percent;
110}
111
112int battery_time(void)
113{
114 battery_status_update();
115 return powermgmt_est_runningtime_min;
116}
117
118bool battery_level_safe(void)
119{
120 return battery_level() >= 10;
121}
122
123void set_battery_capacity(int capacity)
124{
125 (void)capacity;
126}
127
128#if BATTERY_TYPES_COUNT > 1
129void set_battery_type(int type)
130{
131 (void)type;
132}
133#endif
diff --git a/firmware/target/hosted/ypr0/system-target.h b/firmware/target/hosted/ypr0/system-target.h
new file mode 100644
index 0000000000..07a3163ea9
--- /dev/null
+++ b/firmware/target/hosted/ypr0/system-target.h
@@ -0,0 +1,37 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef __SYSTEM_TARGET_H__
22#define __SYSTEM_TARGET_H__
23
24#define disable_irq()
25#define enable_irq()
26#define disable_irq_save() 0
27#define restore_irq(level) (void)level
28
29void wait_for_interrupt(void);
30void interrupt(void);
31
32static inline void commit_dcache(void) {}
33static inline void commit_discard_dcache(void) {}
34static inline void commit_discard_idcache(void) {}
35
36#define NEED_GENERIC_BYTESWAPS
37#endif /* __SYSTEM_TARGET_H__ */
diff --git a/firmware/target/hosted/ypr0/system-ypr0.c b/firmware/target/hosted/ypr0/system-ypr0.c
new file mode 100644
index 0000000000..3a2b30339f
--- /dev/null
+++ b/firmware/target/hosted/ypr0/system-ypr0.c
@@ -0,0 +1,106 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: system-sdl.c 29925 2011-05-25 20:11:03Z thomasjfox $
9 *
10 * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdlib.h>
23#include <string.h>
24#include <inttypes.h>
25#include "system.h"
26#include "panic.h"
27#include "debug.h"
28
29#if defined(HAVE_SDL_AUDIO) || defined(HAVE_SDL_THREADS) || defined(HAVE_SDL)
30#include <SDL.h>
31#endif
32
33#include "ascodec-target.h"
34
35void sim_do_exit(void)
36{
37 exit(EXIT_SUCCESS);
38}
39
40void shutdown_hw(void)
41{
42 /* Something that we need to do before exit on our platform YPR0 */
43 ascodec_close();
44 sim_do_exit();
45}
46
47uintptr_t *stackbegin;
48uintptr_t *stackend;
49void system_init(void)
50{
51 int *s;
52 /* fake stack, OS manages size (and growth) */
53 stackbegin = stackend = (uintptr_t*)&s;
54
55#if defined(HAVE_SDL_AUDIO) || defined(HAVE_SDL_THREADS) || defined(HAVE_SDL)
56 SDL_Init(0); /* need this if using any SDL subsystem */
57#endif
58 /* Here begins our platform specific initilization for various things */
59 ascodec_init();
60}
61
62
63void system_reboot(void)
64{
65 sim_do_exit();
66}
67
68void system_exception_wait(void)
69{
70 system_reboot();
71}
72
73#ifdef HAVE_ADJUSTABLE_CPU_FREQ
74#include <stdio.h>
75#include "file.h"
76/* This is the Linux Kernel CPU governor... */
77static void set_cpu_freq(int speed)
78{
79 char temp[10];
80 int cpu_dev;
81 cpu_dev = open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed", O_WRONLY);
82 if (cpu_dev < 0)
83 return;
84 write(cpu_dev, temp, sprintf(temp, "%d", speed) + 1);
85 close(cpu_dev);
86}
87
88void set_cpu_frequency(long frequency)
89{
90 switch (frequency)
91 {
92 case CPUFREQ_MAX:
93 set_cpu_freq(532000);
94 cpu_frequency = CPUFREQ_MAX;
95 break;
96 case CPUFREQ_NORMAL:
97 set_cpu_freq(400000);
98 cpu_frequency = CPUFREQ_NORMAL;
99 break;
100 default:
101 set_cpu_freq(200000);
102 cpu_frequency = CPUFREQ_DEFAULT;
103 break;
104 }
105}
106#endif
diff --git a/firmware/target/hosted/ypr0/usb-target.h b/firmware/target/hosted/ypr0/usb-target.h
new file mode 100644
index 0000000000..237d179775
--- /dev/null
+++ b/firmware/target/hosted/ypr0/usb-target.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: usb-target.h 29516 2011-03-05 15:31:52Z thomasjfox $
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __USB_TARGET_H__
23#define __USB_TARGET_H__
24
25#endif /* __USB_TARGET_H__ */
diff --git a/firmware/target/hosted/ypr0/ypr0.make b/firmware/target/hosted/ypr0/ypr0.make
new file mode 100644
index 0000000000..c2114878db
--- /dev/null
+++ b/firmware/target/hosted/ypr0/ypr0.make
@@ -0,0 +1,25 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
10INCLUDES += -I$(FIRMDIR)/include -I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR)
11
12SIMFLAGS += $(INCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS)
13
14.SECONDEXPANSION: # $$(OBJ) is not populated until after this
15
16
17$(BUILDDIR)/rockbox.elf : $$(OBJ) $$(FIRMLIB) $$(VOICESPEEXLIB) $$(SKINLIB)
18 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -o $@ $(OBJ) \
19 -L$(BUILDDIR)/firmware -lfirmware \
20 -L$(BUILDDIR)/apps/codecs $(VOICESPEEXLIB:lib%.a=-l%) \
21 -L$(BUILDDIR)/lib -lskin_parser \
22 $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,-Map,$(BUILDDIR)/rockbox.map
23
24$(BUILDDIR)/rockbox : $(BUILDDIR)/rockbox.elf
25 $(call PRINTS,OC $(@F))$(OC) -S -x $< $@
diff --git a/tools/buildzip.pl b/tools/buildzip.pl
index ed937d42e4..e17c2f0712 100755
--- a/tools/buildzip.pl
+++ b/tools/buildzip.pl
@@ -201,7 +201,7 @@ sub make_install {
201 @files = readdir(DIR); 201 @files = readdir(DIR);
202 closedir(DIR); 202 closedir(DIR);
203 203
204 foreach my $file (grep (/[a-zA-Z]+\.(txt|config|ignnore)/,@files)) { 204 foreach my $file (grep (/[a-zA-Z]+\.(txt|config|ignore|sh)/,@files)) {
205 glob_install("$src/$file", "$userdir/"); 205 glob_install("$src/$file", "$userdir/");
206 } 206 }
207 return 1; 207 return 1;
@@ -423,6 +423,11 @@ sub buildzip {
423 # create the file so the database does not try indexing a folder 423 # create the file so the database does not try indexing a folder
424 open(IGNORE, ">$temp_dir/database.ignore") || die "can't open database.ignore"; 424 open(IGNORE, ">$temp_dir/database.ignore") || die "can't open database.ignore";
425 close(IGNORE); 425 close(IGNORE);
426
427 # the samsung ypr0 has a loader script that's needed in the zip
428 if ($modelname =~ /samsungypr0/) {
429 glob_copy("$ROOT/utils/ypr0tools/rockbox.sh", "$temp_dir/");
430 }
426 431
427 glob_mkdir("$temp_dir/langs"); 432 glob_mkdir("$temp_dir/langs");
428 glob_mkdir("$temp_dir/rocks"); 433 glob_mkdir("$temp_dir/rocks");
diff --git a/tools/configure b/tools/configure
index 895aca8025..1cb4c5b240 100755
--- a/tools/configure
+++ b/tools/configure
@@ -647,6 +647,26 @@ pandoracc () {
647 GCCOPTS="$GCCOPTS -ffast-math -fsingle-precision-constant" 647 GCCOPTS="$GCCOPTS -ffast-math -fsingle-precision-constant"
648} 648}
649 649
650ypr0cc () {
651
652 GCCOPTS=`echo $CCOPTS | sed -e s/-ffreestanding// -e s/-nostdlib//`
653 GCCOPTIMIZE=''
654 LDOPTS="-lasound -lpthread -lm -ldl -lrt $LDOPTS"
655 GLOBAL_LDOPTS="$GLOBAL_LDOPTS -Wl,-z,defs"
656 SHARED_LDFLAG="-shared"
657 SHARED_CFLAGS=''
658 endian="little"
659 thread_support="HAVE_SIGALTSTACK_THREADS"
660 app_type="ypr0"
661
662 # Include path
663 GCCOPTS="$GCCOPTS -D_GNU_SOURCE=1 -U_FORTIFY_SOURCE -D_REENTRANT"
664
665 # Set up compiler
666 gccchoice="4.4.6"
667 prefixtools "arm-ypr0-linux-gnueabi-"
668}
669
650androidcc () { 670androidcc () {
651 if [ -z "$ANDROID_SDK_PATH" ]; then 671 if [ -z "$ANDROID_SDK_PATH" ]; then
652 echo "ERROR: You need the Android SDK installed and have the ANDROID_SDK_PATH" 672 echo "ERROR: You need the Android SDK installed and have the ANDROID_SDK_PATH"
@@ -1290,7 +1310,7 @@ cat <<EOF
1290 202) Nokia N8xx 131) Mini2440 1310 202) Nokia N8xx 131) Mini2440
1291 203) Nokia N900 ==ROCKCHIP== ==HiFiMAN== 1311 203) Nokia N900 ==ROCKCHIP== ==HiFiMAN==
1292 204) Pandora 180) rk27xx generic 190) HM-60x 1312 204) Pandora 180) rk27xx generic 190) HM-60x
1293 191) HM-801 1313 205) Samsung YP-R0 191) HM-801
1294 1314
1295EOF 1315EOF
1296 1316
@@ -3228,6 +3248,30 @@ fi
3228 t_model="app" 3248 t_model="app"
3229 ;; 3249 ;;
3230 3250
3251 205|samsungypr0)
3252 application="yes"
3253 target_id=78
3254 modelname="samsungypr0"
3255 target="SAMSUNG_YPR0"
3256 app_set_lcd_size 240 320
3257 memory=32
3258 uname=`uname`
3259 ypr0cc
3260 tool="cp "
3261 boottool="cp "
3262 bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
3263 bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
3264 output="rockbox"
3265 bootoutput="rockbox"
3266 appextra="recorder:gui:radio"
3267 plugins="yes"
3268 swcodec="yes"
3269 # architecture, manufacturer and model for the target-tree build
3270 t_cpu="hosted"
3271 t_manufacturer="ypr0"
3272 t_model="app"
3273 ;;
3274
3231 *) 3275 *)
3232 echo "Please select a supported target platform!" 3276 echo "Please select a supported target platform!"
3233 exit 7 3277 exit 7
@@ -3473,7 +3517,7 @@ gccver=`$CC -dumpversion`;
3473if [ $uname = "Darwin" ]; then 3517if [ $uname = "Darwin" ]; then
3474 ldver=`$LD -v 2>&1 | sed -e 's/[^0-9.-]//g'` 3518 ldver=`$LD -v 2>&1 | sed -e 's/[^0-9.-]//g'`
3475else 3519else
3476 ldver=`$LD --version | head -n 1 | sed -e 's/[^0-9.]//g'` 3520 ldver=`$LD --version | head -n 1 | sed -e 's/\ /\n/g' | tail -n 1`
3477fi 3521fi
3478 3522
3479if [ -z "$gccver" ]; then 3523if [ -z "$gccver" ]; then
diff --git a/tools/root.make b/tools/root.make
index f97588f158..dd827d6d3f 100644
--- a/tools/root.make
+++ b/tools/root.make
@@ -102,6 +102,10 @@ else
102 include $(ROOTDIR)/uisimulator/uisimulator.make 102 include $(ROOTDIR)/uisimulator/uisimulator.make
103 endif 103 endif
104 104
105 ifneq (,$(findstring ypr0,$(APP_TYPE)))
106 include $(ROOTDIR)/firmware/target/hosted/ypr0/ypr0.make
107 endif
108
105 ifneq (,$(findstring android, $(APP_TYPE))) 109 ifneq (,$(findstring android, $(APP_TYPE)))
106 include $(ROOTDIR)/android/android.make 110 include $(ROOTDIR)/android/android.make
107 endif 111 endif
diff --git a/utils/ypr0tools/Makefile b/utils/ypr0tools/Makefile
new file mode 100644
index 0000000000..efc1de63f2
--- /dev/null
+++ b/utils/ypr0tools/Makefile
@@ -0,0 +1,13 @@
1
2.PHONY: all clean
3PROGS = extract_section
4CC = gcc
5CFLAGS = -O1 -g -W -Wall
6
7
8all: $(PROGS)
9 $(MAKE) -C cramfs-1.1
10
11clean:
12 $(MAKE) -C cramfs-1.1 clean
13 rm -f extract_section
diff --git a/utils/ypr0tools/MuonEncrypt b/utils/ypr0tools/MuonEncrypt
new file mode 100755
index 0000000000..b1bc124523
--- /dev/null
+++ b/utils/ypr0tools/MuonEncrypt
Binary files differ
diff --git a/utils/ypr0tools/README b/utils/ypr0tools/README
new file mode 100644
index 0000000000..45777dd8c5
--- /dev/null
+++ b/utils/ypr0tools/README
@@ -0,0 +1,12 @@
1
2To generate a firmware, run (paths may differ):
3
4$ make
5$ ./unpack-firmware.sh R0.ROM /tmp/romfiles
6$ sudo ./patch-firmware.sh files /tmp/romfiles # needs sudo
7$ ./pack-firmware.sh R0.ROM /tmp/romfiles
8
9After that, R0.ROM is patched and can load Rockbox.
10
11rockbox.sh is a script to put into rockbox.zip. It's a small loader script
12that sets stuff up.
diff --git a/utils/ypr0tools/cramfs-1.1/COPYING b/utils/ypr0tools/cramfs-1.1/COPYING
new file mode 100644
index 0000000000..5b6e7c66c2
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/COPYING
@@ -0,0 +1,340 @@
1 GNU GENERAL PUBLIC LICENSE
2 Version 2, June 1991
3
4 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6 Everyone is permitted to copy and distribute verbatim copies
7 of this license document, but changing it is not allowed.
8
9 Preamble
10
11 The licenses for most software are designed to take away your
12freedom to share and change it. By contrast, the GNU General Public
13License is intended to guarantee your freedom to share and change free
14software--to make sure the software is free for all its users. This
15General Public License applies to most of the Free Software
16Foundation's software and to any other program whose authors commit to
17using it. (Some other Free Software Foundation software is covered by
18the GNU Library General Public License instead.) You can apply it to
19your programs, too.
20
21 When we speak of free software, we are referring to freedom, not
22price. Our General Public Licenses are designed to make sure that you
23have the freedom to distribute copies of free software (and charge for
24this service if you wish), that you receive source code or can get it
25if you want it, that you can change the software or use pieces of it
26in new free programs; and that you know you can do these things.
27
28 To protect your rights, we need to make restrictions that forbid
29anyone to deny you these rights or to ask you to surrender the rights.
30These restrictions translate to certain responsibilities for you if you
31distribute copies of the software, or if you modify it.
32
33 For example, if you distribute copies of such a program, whether
34gratis or for a fee, you must give the recipients all the rights that
35you have. You must make sure that they, too, receive or can get the
36source code. And you must show them these terms so they know their
37rights.
38
39 We protect your rights with two steps: (1) copyright the software, and
40(2) offer you this license which gives you legal permission to copy,
41distribute and/or modify the software.
42
43 Also, for each author's protection and ours, we want to make certain
44that everyone understands that there is no warranty for this free
45software. If the software is modified by someone else and passed on, we
46want its recipients to know that what they have is not the original, so
47that any problems introduced by others will not reflect on the original
48authors' reputations.
49
50 Finally, any free program is threatened constantly by software
51patents. We wish to avoid the danger that redistributors of a free
52program will individually obtain patent licenses, in effect making the
53program proprietary. To prevent this, we have made it clear that any
54patent must be licensed for everyone's free use or not licensed at all.
55
56 The precise terms and conditions for copying, distribution and
57modification follow.
58
59 GNU GENERAL PUBLIC LICENSE
60 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
62 0. This License applies to any program or other work which contains
63a notice placed by the copyright holder saying it may be distributed
64under the terms of this General Public License. The "Program", below,
65refers to any such program or work, and a "work based on the Program"
66means either the Program or any derivative work under copyright law:
67that is to say, a work containing the Program or a portion of it,
68either verbatim or with modifications and/or translated into another
69language. (Hereinafter, translation is included without limitation in
70the term "modification".) Each licensee is addressed as "you".
71
72Activities other than copying, distribution and modification are not
73covered by this License; they are outside its scope. The act of
74running the Program is not restricted, and the output from the Program
75is covered only if its contents constitute a work based on the
76Program (independent of having been made by running the Program).
77Whether that is true depends on what the Program does.
78
79 1. You may copy and distribute verbatim copies of the Program's
80source code as you receive it, in any medium, provided that you
81conspicuously and appropriately publish on each copy an appropriate
82copyright notice and disclaimer of warranty; keep intact all the
83notices that refer to this License and to the absence of any warranty;
84and give any other recipients of the Program a copy of this License
85along with the Program.
86
87You may charge a fee for the physical act of transferring a copy, and
88you may at your option offer warranty protection in exchange for a fee.
89
90 2. You may modify your copy or copies of the Program or any portion
91of it, thus forming a work based on the Program, and copy and
92distribute such modifications or work under the terms of Section 1
93above, provided that you also meet all of these conditions:
94
95 a) You must cause the modified files to carry prominent notices
96 stating that you changed the files and the date of any change.
97
98 b) You must cause any work that you distribute or publish, that in
99 whole or in part contains or is derived from the Program or any
100 part thereof, to be licensed as a whole at no charge to all third
101 parties under the terms of this License.
102
103 c) If the modified program normally reads commands interactively
104 when run, you must cause it, when started running for such
105 interactive use in the most ordinary way, to print or display an
106 announcement including an appropriate copyright notice and a
107 notice that there is no warranty (or else, saying that you provide
108 a warranty) and that users may redistribute the program under
109 these conditions, and telling the user how to view a copy of this
110 License. (Exception: if the Program itself is interactive but
111 does not normally print such an announcement, your work based on
112 the Program is not required to print an announcement.)
113
114These requirements apply to the modified work as a whole. If
115identifiable sections of that work are not derived from the Program,
116and can be reasonably considered independent and separate works in
117themselves, then this License, and its terms, do not apply to those
118sections when you distribute them as separate works. But when you
119distribute the same sections as part of a whole which is a work based
120on the Program, the distribution of the whole must be on the terms of
121this License, whose permissions for other licensees extend to the
122entire whole, and thus to each and every part regardless of who wrote it.
123
124Thus, it is not the intent of this section to claim rights or contest
125your rights to work written entirely by you; rather, the intent is to
126exercise the right to control the distribution of derivative or
127collective works based on the Program.
128
129In addition, mere aggregation of another work not based on the Program
130with the Program (or with a work based on the Program) on a volume of
131a storage or distribution medium does not bring the other work under
132the scope of this License.
133
134 3. You may copy and distribute the Program (or a work based on it,
135under Section 2) in object code or executable form under the terms of
136Sections 1 and 2 above provided that you also do one of the following:
137
138 a) Accompany it with the complete corresponding machine-readable
139 source code, which must be distributed under the terms of Sections
140 1 and 2 above on a medium customarily used for software interchange; or,
141
142 b) Accompany it with a written offer, valid for at least three
143 years, to give any third party, for a charge no more than your
144 cost of physically performing source distribution, a complete
145 machine-readable copy of the corresponding source code, to be
146 distributed under the terms of Sections 1 and 2 above on a medium
147 customarily used for software interchange; or,
148
149 c) Accompany it with the information you received as to the offer
150 to distribute corresponding source code. (This alternative is
151 allowed only for noncommercial distribution and only if you
152 received the program in object code or executable form with such
153 an offer, in accord with Subsection b above.)
154
155The source code for a work means the preferred form of the work for
156making modifications to it. For an executable work, complete source
157code means all the source code for all modules it contains, plus any
158associated interface definition files, plus the scripts used to
159control compilation and installation of the executable. However, as a
160special exception, the source code distributed need not include
161anything that is normally distributed (in either source or binary
162form) with the major components (compiler, kernel, and so on) of the
163operating system on which the executable runs, unless that component
164itself accompanies the executable.
165
166If distribution of executable or object code is made by offering
167access to copy from a designated place, then offering equivalent
168access to copy the source code from the same place counts as
169distribution of the source code, even though third parties are not
170compelled to copy the source along with the object code.
171
172 4. You may not copy, modify, sublicense, or distribute the Program
173except as expressly provided under this License. Any attempt
174otherwise to copy, modify, sublicense or distribute the Program is
175void, and will automatically terminate your rights under this License.
176However, parties who have received copies, or rights, from you under
177this License will not have their licenses terminated so long as such
178parties remain in full compliance.
179
180 5. You are not required to accept this License, since you have not
181signed it. However, nothing else grants you permission to modify or
182distribute the Program or its derivative works. These actions are
183prohibited by law if you do not accept this License. Therefore, by
184modifying or distributing the Program (or any work based on the
185Program), you indicate your acceptance of this License to do so, and
186all its terms and conditions for copying, distributing or modifying
187the Program or works based on it.
188
189 6. Each time you redistribute the Program (or any work based on the
190Program), the recipient automatically receives a license from the
191original licensor to copy, distribute or modify the Program subject to
192these terms and conditions. You may not impose any further
193restrictions on the recipients' exercise of the rights granted herein.
194You are not responsible for enforcing compliance by third parties to
195this License.
196
197 7. If, as a consequence of a court judgment or allegation of patent
198infringement or for any other reason (not limited to patent issues),
199conditions are imposed on you (whether by court order, agreement or
200otherwise) that contradict the conditions of this License, they do not
201excuse you from the conditions of this License. If you cannot
202distribute so as to satisfy simultaneously your obligations under this
203License and any other pertinent obligations, then as a consequence you
204may not distribute the Program at all. For example, if a patent
205license would not permit royalty-free redistribution of the Program by
206all those who receive copies directly or indirectly through you, then
207the only way you could satisfy both it and this License would be to
208refrain entirely from distribution of the Program.
209
210If any portion of this section is held invalid or unenforceable under
211any particular circumstance, the balance of the section is intended to
212apply and the section as a whole is intended to apply in other
213circumstances.
214
215It is not the purpose of this section to induce you to infringe any
216patents or other property right claims or to contest validity of any
217such claims; this section has the sole purpose of protecting the
218integrity of the free software distribution system, which is
219implemented by public license practices. Many people have made
220generous contributions to the wide range of software distributed
221through that system in reliance on consistent application of that
222system; it is up to the author/donor to decide if he or she is willing
223to distribute software through any other system and a licensee cannot
224impose that choice.
225
226This section is intended to make thoroughly clear what is believed to
227be a consequence of the rest of this License.
228
229 8. If the distribution and/or use of the Program is restricted in
230certain countries either by patents or by copyrighted interfaces, the
231original copyright holder who places the Program under this License
232may add an explicit geographical distribution limitation excluding
233those countries, so that distribution is permitted only in or among
234countries not thus excluded. In such case, this License incorporates
235the limitation as if written in the body of this License.
236
237 9. The Free Software Foundation may publish revised and/or new versions
238of the General Public License from time to time. Such new versions will
239be similar in spirit to the present version, but may differ in detail to
240address new problems or concerns.
241
242Each version is given a distinguishing version number. If the Program
243specifies a version number of this License which applies to it and "any
244later version", you have the option of following the terms and conditions
245either of that version or of any later version published by the Free
246Software Foundation. If the Program does not specify a version number of
247this License, you may choose any version ever published by the Free Software
248Foundation.
249
250 10. If you wish to incorporate parts of the Program into other free
251programs whose distribution conditions are different, write to the author
252to ask for permission. For software which is copyrighted by the Free
253Software Foundation, write to the Free Software Foundation; we sometimes
254make exceptions for this. Our decision will be guided by the two goals
255of preserving the free status of all derivatives of our free software and
256of promoting the sharing and reuse of software generally.
257
258 NO WARRANTY
259
260 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268REPAIR OR CORRECTION.
269
270 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278POSSIBILITY OF SUCH DAMAGES.
279
280 END OF TERMS AND CONDITIONS
281
282 How to Apply These Terms to Your New Programs
283
284 If you develop a new program, and you want it to be of the greatest
285possible use to the public, the best way to achieve this is to make it
286free software which everyone can redistribute and change under these terms.
287
288 To do so, attach the following notices to the program. It is safest
289to attach them to the start of each source file to most effectively
290convey the exclusion of warranty; and each file should have at least
291the "copyright" line and a pointer to where the full notice is found.
292
293 <one line to give the program's name and a brief idea of what it does.>
294 Copyright (C) <year> <name of author>
295
296 This program is free software; you can redistribute it and/or modify
297 it under the terms of the GNU General Public License as published by
298 the Free Software Foundation; either version 2 of the License, or
299 (at your option) any later version.
300
301 This program is distributed in the hope that it will be useful,
302 but WITHOUT ANY WARRANTY; without even the implied warranty of
303 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 GNU General Public License for more details.
305
306 You should have received a copy of the GNU General Public License
307 along with this program; if not, write to the Free Software
308 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309
310
311Also add information on how to contact you by electronic and paper mail.
312
313If the program is interactive, make it output a short notice like this
314when it starts in an interactive mode:
315
316 Gnomovision version 69, Copyright (C) year name of author
317 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318 This is free software, and you are welcome to redistribute it
319 under certain conditions; type `show c' for details.
320
321The hypothetical commands `show w' and `show c' should show the appropriate
322parts of the General Public License. Of course, the commands you use may
323be called something other than `show w' and `show c'; they could even be
324mouse-clicks or menu items--whatever suits your program.
325
326You should also get your employer (if you work as a programmer) or your
327school, if any, to sign a "copyright disclaimer" for the program, if
328necessary. Here is a sample; alter the names:
329
330 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331 `Gnomovision' (which makes passes at compilers) written by James Hacker.
332
333 <signature of Ty Coon>, 1 April 1989
334 Ty Coon, President of Vice
335
336This General Public License does not permit incorporating your program into
337proprietary programs. If your program is a subroutine library, you may
338consider it more useful to permit linking proprietary applications with the
339library. If this is what you want to do, use the GNU Library General
340Public License instead of this License.
diff --git a/utils/ypr0tools/cramfs-1.1/GNUmakefile b/utils/ypr0tools/cramfs-1.1/GNUmakefile
new file mode 100644
index 0000000000..e15fb22f01
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/GNUmakefile
@@ -0,0 +1,12 @@
1CC = gcc
2CFLAGS = -W -Wall -O2 -g -Wno-pointer-sign
3CPPFLAGS = -I.
4LDLIBS = -lz
5PROGS = mkcramfs cramfsck
6
7all: $(PROGS)
8
9distclean clean:
10 rm -f $(PROGS)
11
12.PHONY: all clean
diff --git a/utils/ypr0tools/cramfs-1.1/NOTES b/utils/ypr0tools/cramfs-1.1/NOTES
new file mode 100644
index 0000000000..445d1c2d76
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/NOTES
@@ -0,0 +1,168 @@
1Notes on Filesystem Layout
2--------------------------
3
4These notes describe what mkcramfs generates. Kernel requirements are
5a bit looser, e.g. it doesn't care if the <file_data> items are
6swapped around (though it does care that directory entries (inodes) in
7a given directory are contiguous, as this is used by readdir).
8
9All data is currently in host-endian format; neither mkcramfs nor the
10kernel ever do swabbing. (See section `Block Size' below.)
11
12<filesystem>:
13 <superblock>
14 <directory_structure>
15 <data>
16
17<superblock>: struct cramfs_super (see cramfs_fs.h).
18
19<directory_structure>:
20 For each file:
21 struct cramfs_inode (see cramfs_fs.h).
22 Filename. Not generally null-terminated, but it is
23 null-padded to a multiple of 4 bytes.
24
25The order of inode traversal is described as "width-first" (not to be
26confused with breadth-first); i.e. like depth-first but listing all of
27a directory's entries before recursing down its subdirectories: the
28same order as `ls -AUR' (but without the /^\..*:$/ directory header
29lines); put another way, the same order as `find -type d -exec
30ls -AU1 {} \;'.
31
32Beginning in 2.4.7, directory entries are sorted. This optimization
33allows cramfs_lookup to return more quickly when a filename does not
34exist, speeds up user-space directory sorts, etc.
35
36<data>:
37 One <file_data> for each file that's either a symlink or a
38 regular file of non-zero st_size.
39
40<file_data>:
41 nblocks * <block_pointer>
42 (where nblocks = (st_size - 1) / blksize + 1)
43 nblocks * <block>
44 padding to multiple of 4 bytes
45
46The i'th <block_pointer> for a file stores the byte offset of the
47*end* of the i'th <block> (i.e. one past the last byte, which is the
48same as the start of the (i+1)'th <block> if there is one). The first
49<block> immediately follows the last <block_pointer> for the file.
50<block_pointer>s are each 32 bits long.
51
52The order of <file_data>'s is a depth-first descent of the directory
53tree, i.e. the same order as `find -size +0 \( -type f -o -type l \)
54-print'.
55
56
57<block>: The i'th <block> is the output of zlib's compress function
58applied to the i'th blksize-sized chunk of the input data.
59(For the last <block> of the file, the input may of course be smaller.)
60Each <block> may be a different size. (See <block_pointer> above.)
61<block>s are merely byte-aligned, not generally u32-aligned.
62
63
64Holes
65-----
66
67This kernel supports cramfs holes (i.e. [efficient representation of]
68blocks in uncompressed data consisting entirely of NUL bytes), but by
69default mkcramfs doesn't test for & create holes, since cramfs in
70kernels up to at least 2.3.39 didn't support holes. Run mkcramfs
71with -z if you want it to create files that can have holes in them.
72
73
74Tools
75-----
76
77The cramfs user-space tools, including mkcramfs and cramfsck, are
78located at <http://sourceforge.net/projects/cramfs/>.
79
80
81Future Development
82==================
83
84Block Size
85----------
86
87(Block size in cramfs refers to the size of input data that is
88compressed at a time. It's intended to be somewhere around
89PAGE_CACHE_SIZE for cramfs_readpage's convenience.)
90
91The superblock ought to indicate the block size that the fs was
92written for, since comments in <linux/pagemap.h> indicate that
93PAGE_CACHE_SIZE may grow in future (if I interpret the comment
94correctly).
95
96Currently, mkcramfs #define's PAGE_CACHE_SIZE as 4096 and uses that
97for blksize, whereas Linux-2.3.39 uses its PAGE_CACHE_SIZE, which in
98turn is defined as PAGE_SIZE (which can be as large as 32KB on arm).
99This discrepancy is a bug, though it's not clear which should be
100changed.
101
102One option is to change mkcramfs to take its PAGE_CACHE_SIZE from
103<asm/page.h>. Personally I don't like this option, but it does
104require the least amount of change: just change `#define
105PAGE_CACHE_SIZE (4096)' to `#include <asm/page.h>'. The disadvantage
106is that the generated cramfs cannot always be shared between different
107kernels, not even necessarily kernels of the same architecture if
108PAGE_CACHE_SIZE is subject to change between kernel versions
109(currently possible with arm and ia64).
110
111The remaining options try to make cramfs more sharable.
112
113One part of that is addressing endianness. The two options here are
114`always use little-endian' (like ext2fs) or `writer chooses
115endianness; kernel adapts at runtime'. Little-endian wins because of
116code simplicity and little CPU overhead even on big-endian machines.
117
118The cost of swabbing is changing the code to use the le32_to_cpu
119etc. macros as used by ext2fs. We don't need to swab the compressed
120data, only the superblock, inodes and block pointers.
121
122
123The other part of making cramfs more sharable is choosing a block
124size. The options are:
125
126 1. Always 4096 bytes.
127
128 2. Writer chooses blocksize; kernel adapts but rejects blocksize >
129 PAGE_CACHE_SIZE.
130
131 3. Writer chooses blocksize; kernel adapts even to blocksize >
132 PAGE_CACHE_SIZE.
133
134It's easy enough to change the kernel to use a smaller value than
135PAGE_CACHE_SIZE: just make cramfs_readpage read multiple blocks.
136
137The cost of option 1 is that kernels with a larger PAGE_CACHE_SIZE
138value don't get as good compression as they can.
139
140The cost of option 2 relative to option 1 is that the code uses
141variables instead of #define'd constants. The gain is that people
142with kernels having larger PAGE_CACHE_SIZE can make use of that if
143they don't mind their cramfs being inaccessible to kernels with
144smaller PAGE_CACHE_SIZE values.
145
146Option 3 is easy to implement if we don't mind being CPU-inefficient:
147e.g. get readpage to decompress to a buffer of size MAX_BLKSIZE (which
148must be no larger than 32KB) and discard what it doesn't need.
149Getting readpage to read into all the covered pages is harder.
150
151The main advantage of option 3 over 1, 2, is better compression. The
152cost is greater complexity. Probably not worth it, but I hope someone
153will disagree. (If it is implemented, then I'll re-use that code in
154e2compr.)
155
156
157Another cost of 2 and 3 over 1 is making mkcramfs use a different
158block size, but that just means adding and parsing a -b option.
159
160
161Inode Size
162----------
163
164Given that cramfs will probably be used for CDs etc. as well as just
165silicon ROMs, it might make sense to expand the inode a little from
166its current 12 bytes. Inodes other than the root inode are followed
167by filename, so the expansion doesn't even have to be a multiple of 4
168bytes.
diff --git a/utils/ypr0tools/cramfs-1.1/README b/utils/ypr0tools/cramfs-1.1/README
new file mode 100644
index 0000000000..31f53f0ab9
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/README
@@ -0,0 +1,76 @@
1
2 Cramfs - cram a filesystem onto a small ROM
3
4cramfs is designed to be simple and small, and to compress things well.
5
6It uses the zlib routines to compress a file one page at a time, and
7allows random page access. The meta-data is not compressed, but is
8expressed in a very terse representation to make it use much less
9diskspace than traditional filesystems.
10
11You can't write to a cramfs filesystem (making it compressible and
12compact also makes it _very_ hard to update on-the-fly), so you have to
13create the disk image with the "mkcramfs" utility.
14
15
16Usage Notes
17-----------
18
19File sizes are limited to less than 16MB.
20
21Maximum filesystem size is a little over 256MB. (The last file on the
22filesystem is allowed to extend past 256MB.)
23
24Only the low 8 bits of gid are stored. The current version of
25mkcramfs simply truncates to 8 bits, which is a potential security
26issue.
27
28Hard links are supported, but hard linked files
29will still have a link count of 1 in the cramfs image.
30
31Cramfs directories have no `.' or `..' entries. Directories (like
32every other file on cramfs) always have a link count of 1. (There's
33no need to use -noleaf in `find', btw.)
34
35No timestamps are stored in a cramfs, so these default to the epoch
36(1970 GMT). Recently-accessed files may have updated timestamps, but
37the update lasts only as long as the inode is cached in memory, after
38which the timestamp reverts to 1970, i.e. moves backwards in time.
39
40Currently, cramfs must be written and read with architectures of the
41same endianness, and can be read only by kernels with PAGE_CACHE_SIZE
42== 4096. At least the latter of these is a bug, but it hasn't been
43decided what the best fix is. For the moment if you have larger pages
44you can just change the #define in mkcramfs.c, so long as you don't
45mind the filesystem becoming unreadable to future kernels.
46
47
48For /usr/share/magic
49--------------------
50
510 ulelong 0x28cd3d45 Linux cramfs offset 0
52>4 ulelong x size %d
53>8 ulelong x flags 0x%x
54>12 ulelong x future 0x%x
55>16 string >\0 signature "%.16s"
56>32 ulelong x fsid.crc 0x%x
57>36 ulelong x fsid.edition %d
58>40 ulelong x fsid.blocks %d
59>44 ulelong x fsid.files %d
60>48 string >\0 name "%.16s"
61512 ulelong 0x28cd3d45 Linux cramfs offset 512
62>516 ulelong x size %d
63>520 ulelong x flags 0x%x
64>524 ulelong x future 0x%x
65>528 string >\0 signature "%.16s"
66>544 ulelong x fsid.crc 0x%x
67>548 ulelong x fsid.edition %d
68>552 ulelong x fsid.blocks %d
69>556 ulelong x fsid.files %d
70>560 string >\0 name "%.16s"
71
72
73Hacker Notes
74------------
75
76See fs/cramfs/README for filesystem layout and implementation notes.
diff --git a/utils/ypr0tools/cramfs-1.1/cramfsck.c b/utils/ypr0tools/cramfs-1.1/cramfsck.c
new file mode 100644
index 0000000000..aef017a4b4
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/cramfsck.c
@@ -0,0 +1,716 @@
1/*
2 * cramfsck - check a cramfs file system
3 *
4 * Copyright (C) 2000-2002 Transmeta Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * 1999/12/03: Linus Torvalds (cramfs tester and unarchive program)
21 * 2000/06/03: Daniel Quinlan (CRC and length checking program)
22 * 2000/06/04: Daniel Quinlan (merged programs, added options, support
23 * for special files, preserve permissions and
24 * ownership, cramfs superblock v2, bogus mode
25 * test, pathname length test, etc.)
26 * 2000/06/06: Daniel Quinlan (support for holes, pretty-printing,
27 * symlink size test)
28 * 2000/07/11: Daniel Quinlan (file length tests, start at offset 0 or 512,
29 * fsck-compatible exit codes)
30 * 2000/07/15: Daniel Quinlan (initial support for block devices)
31 * 2002/01/10: Daniel Quinlan (additional checks, test more return codes,
32 * use read if mmap fails, standardize messages)
33 */
34
35/* compile-time options */
36#define INCLUDE_FS_TESTS /* include cramfs checking and extraction */
37
38#define _GNU_SOURCE
39#include <sys/types.h>
40#include <stdio.h>
41#include <stdarg.h>
42#include <sys/stat.h>
43#include <unistd.h>
44#include <sys/mman.h>
45#include <fcntl.h>
46#include <dirent.h>
47#include <stdlib.h>
48#include <errno.h>
49#include <string.h>
50#include <sys/sysmacros.h>
51#include <utime.h>
52#include <sys/ioctl.h>
53#define _LINUX_STRING_H_
54#include <linux/fs.h>
55#include <linux/cramfs_fs.h>
56#include <zlib.h>
57
58/* Exit codes used by fsck-type programs */
59#define FSCK_OK 0 /* No errors */
60#define FSCK_NONDESTRUCT 1 /* File system errors corrected */
61#define FSCK_REBOOT 2 /* System should be rebooted */
62#define FSCK_UNCORRECTED 4 /* File system errors left uncorrected */
63#define FSCK_ERROR 8 /* Operational error */
64#define FSCK_USAGE 16 /* Usage or syntax error */
65#define FSCK_LIBRARY 128 /* Shared library error */
66
67#define PAD_SIZE 512
68
69#define PAGE_CACHE_SIZE page_size
70
71static const char *progname = "cramfsck";
72
73static int fd; /* ROM image file descriptor */
74static char *filename; /* ROM image filename */
75struct cramfs_super super; /* just find the cramfs superblock once */
76static int opt_verbose = 0; /* 1 = verbose (-v), 2+ = very verbose (-vv) */
77#ifdef INCLUDE_FS_TESTS
78static int opt_extract = 0; /* extract cramfs (-x) */
79static char *extract_dir = "root"; /* extraction directory (-x) */
80static uid_t euid; /* effective UID */
81
82/* (cramfs_super + start) <= start_dir < end_dir <= start_data <= end_data */
83static unsigned long start_dir = ~0UL; /* start of first non-root inode */
84static unsigned long end_dir = 0; /* end of the directory structure */
85static unsigned long start_data = ~0UL; /* start of the data (256 MB = max) */
86static unsigned long end_data = 0; /* end of the data */
87
88/* Guarantee access to at least 8kB at a time */
89#define ROMBUFFER_BITS 13
90#define ROMBUFFERSIZE (1 << ROMBUFFER_BITS)
91#define ROMBUFFERMASK (ROMBUFFERSIZE-1)
92static char read_buffer[ROMBUFFERSIZE * 2];
93static unsigned long read_buffer_block = ~0UL;
94
95/* Uncompressing data structures... */
96static char *outbuffer;
97static z_stream stream;
98
99static size_t page_size;
100
101/* Prototypes */
102static void expand_fs(char *, struct cramfs_inode *);
103#endif /* INCLUDE_FS_TESTS */
104
105/* Input status of 0 to print help and exit without an error. */
106static void usage(int status)
107{
108 FILE *stream = status ? stderr : stdout;
109
110 fprintf(stream, "usage: %s [-hv] [-x dir] file\n"
111 " -h print this help\n"
112 " -x dir extract into dir\n"
113 " -v be more verbose\n"
114 " file file to test\n", progname);
115
116 exit(status);
117}
118
119static void die(int status, int syserr, const char *fmt, ...)
120{
121 va_list arg_ptr;
122 int save = errno;
123
124 fflush(0);
125 va_start(arg_ptr, fmt);
126 fprintf(stderr, "%s: ", progname);
127 vfprintf(stderr, fmt, arg_ptr);
128 if (syserr) {
129 fprintf(stderr, ": %s", strerror(save));
130 }
131 fprintf(stderr, "\n");
132 va_end(arg_ptr);
133 exit(status);
134}
135
136static void test_super(int *start, size_t *length) {
137 struct stat st;
138
139 /* find the physical size of the file or block device */
140 if (stat(filename, &st) < 0) {
141 die(FSCK_ERROR, 1, "stat failed: %s", filename);
142 }
143 fd = open(filename, O_RDONLY);
144 if (fd < 0) {
145 die(FSCK_ERROR, 1, "open failed: %s", filename);
146 }
147 if (S_ISBLK(st.st_mode)) {
148 if (ioctl(fd, BLKGETSIZE, length) < 0) {
149 die(FSCK_ERROR, 1, "ioctl failed: unable to determine device size: %s", filename);
150 }
151 *length = *length * 512;
152 }
153 else if (S_ISREG(st.st_mode)) {
154 *length = st.st_size;
155 }
156 else {
157 die(FSCK_ERROR, 0, "not a block device or file: %s", filename);
158 }
159
160 if (*length < sizeof(struct cramfs_super)) {
161 die(FSCK_UNCORRECTED, 0, "file length too short");
162 }
163
164 /* find superblock */
165 if (read(fd, &super, sizeof(super)) != sizeof(super)) {
166 die(FSCK_ERROR, 1, "read failed: %s", filename);
167 }
168 if (super.magic == CRAMFS_MAGIC) {
169 *start = 0;
170 }
171 else if (*length >= (PAD_SIZE + sizeof(super))) {
172 lseek(fd, PAD_SIZE, SEEK_SET);
173 if (read(fd, &super, sizeof(super)) != sizeof(super)) {
174 die(FSCK_ERROR, 1, "read failed: %s", filename);
175 }
176 if (super.magic == CRAMFS_MAGIC) {
177 *start = PAD_SIZE;
178 }
179 }
180
181 /* superblock tests */
182 if (super.magic != CRAMFS_MAGIC) {
183 die(FSCK_UNCORRECTED, 0, "superblock magic not found");
184 }
185 if (super.flags & ~CRAMFS_SUPPORTED_FLAGS) {
186 die(FSCK_ERROR, 0, "unsupported filesystem features");
187 }
188 if (super.size < PAGE_CACHE_SIZE) {
189 die(FSCK_UNCORRECTED, 0, "superblock size (%d) too small", super.size);
190 }
191 if (super.flags & CRAMFS_FLAG_FSID_VERSION_2) {
192 if (super.fsid.files == 0) {
193 die(FSCK_UNCORRECTED, 0, "zero file count");
194 }
195 if (*length < super.size) {
196 die(FSCK_UNCORRECTED, 0, "file length too short");
197 }
198 else if (*length > super.size) {
199 fprintf(stderr, "warning: file extends past end of filesystem\n");
200 }
201 }
202 else {
203 fprintf(stderr, "warning: old cramfs format\n");
204 }
205}
206
207static void test_crc(int start)
208{
209 void *buf;
210 u32 crc;
211
212 if (!(super.flags & CRAMFS_FLAG_FSID_VERSION_2)) {
213#ifdef INCLUDE_FS_TESTS
214 return;
215#else /* not INCLUDE_FS_TESTS */
216 die(FSCK_USAGE, 0, "unable to test CRC: old cramfs format");
217#endif /* not INCLUDE_FS_TESTS */
218 }
219
220 crc = crc32(0L, Z_NULL, 0);
221
222 buf = mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
223 if (buf == MAP_FAILED) {
224 buf = mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
225 if (buf != MAP_FAILED) {
226 lseek(fd, 0, SEEK_SET);
227 read(fd, buf, super.size);
228 }
229 }
230 if (buf != MAP_FAILED) {
231 ((struct cramfs_super *) (buf+start))->fsid.crc = crc32(0L, Z_NULL, 0);
232 crc = crc32(crc, buf+start, super.size-start);
233 munmap(buf, super.size);
234 }
235 else {
236 int retval;
237 size_t length = 0;
238
239 buf = malloc(4096);
240 if (!buf) {
241 die(FSCK_ERROR, 1, "malloc failed");
242 }
243 lseek(fd, start, SEEK_SET);
244 for (;;) {
245 retval = read(fd, buf, 4096);
246 if (retval < 0) {
247 die(FSCK_ERROR, 1, "read failed: %s", filename);
248 }
249 else if (retval == 0) {
250 break;
251 }
252 if (length == 0) {
253 ((struct cramfs_super *) buf)->fsid.crc = crc32(0L, Z_NULL, 0);
254 }
255 length += retval;
256 if (length > (super.size-start)) {
257 crc = crc32(crc, buf, retval - (length - (super.size-start)));
258 break;
259 }
260 crc = crc32(crc, buf, retval);
261 }
262 free(buf);
263 }
264
265 if (crc != super.fsid.crc) {
266 die(FSCK_UNCORRECTED, 0, "crc error");
267 }
268}
269
270#ifdef INCLUDE_FS_TESTS
271static void print_node(char type, struct cramfs_inode *i, char *name)
272{
273 char info[10];
274
275 if (S_ISCHR(i->mode) || (S_ISBLK(i->mode))) {
276 /* major/minor numbers can be as high as 2^12 or 4096 */
277 snprintf(info, 10, "%4d,%4d", major(i->size), minor(i->size));
278 }
279 else {
280 /* size be as high as 2^24 or 16777216 */
281 snprintf(info, 10, "%9d", i->size);
282 }
283
284 printf("%c %04o %s %5d:%-3d %s\n",
285 type, i->mode & ~S_IFMT, info, i->uid, i->gid, name);
286}
287
288/*
289 * Create a fake "blocked" access
290 */
291static void *romfs_read(unsigned long offset)
292{
293 unsigned int block = offset >> ROMBUFFER_BITS;
294 if (block != read_buffer_block) {
295 read_buffer_block = block;
296 lseek(fd, block << ROMBUFFER_BITS, SEEK_SET);
297 read(fd, read_buffer, ROMBUFFERSIZE * 2);
298 }
299 return read_buffer + (offset & ROMBUFFERMASK);
300}
301
302static struct cramfs_inode *cramfs_iget(struct cramfs_inode * i)
303{
304 struct cramfs_inode *inode = malloc(sizeof(struct cramfs_inode));
305
306 if (!inode) {
307 die(FSCK_ERROR, 1, "malloc failed");
308 }
309 *inode = *i;
310 return inode;
311}
312
313static struct cramfs_inode *iget(unsigned int ino)
314{
315 return cramfs_iget(romfs_read(ino));
316}
317
318static void iput(struct cramfs_inode *inode)
319{
320 free(inode);
321}
322
323/*
324 * Return the offset of the root directory
325 */
326static struct cramfs_inode *read_super(void)
327{
328 unsigned long offset = super.root.offset << 2;
329
330 if (!S_ISDIR(super.root.mode))
331 die(FSCK_UNCORRECTED, 0, "root inode is not directory");
332 if (!(super.flags & CRAMFS_FLAG_SHIFTED_ROOT_OFFSET) &&
333 ((offset != sizeof(struct cramfs_super)) &&
334 (offset != PAD_SIZE + sizeof(struct cramfs_super))))
335 {
336 die(FSCK_UNCORRECTED, 0, "bad root offset (%lu)", offset);
337 }
338 return cramfs_iget(&super.root);
339}
340
341static int uncompress_block(void *src, int len)
342{
343 int err;
344
345 stream.next_in = src;
346 stream.avail_in = len;
347
348 stream.next_out = (unsigned char *) outbuffer;
349 stream.avail_out = PAGE_CACHE_SIZE*2;
350
351 inflateReset(&stream);
352
353 if (len > PAGE_CACHE_SIZE*2) {
354 die(FSCK_UNCORRECTED, 0, "data block too large");
355 }
356 err = inflate(&stream, Z_FINISH);
357 if (err != Z_STREAM_END) {
358 die(FSCK_UNCORRECTED, 0, "decompression error %p(%d): %s",
359 zError(err), src, len);
360 }
361 return stream.total_out;
362}
363
364static void do_uncompress(char *path, int fd, unsigned long offset, unsigned long size)
365{
366 unsigned long curr = offset + 4 * ((size + PAGE_CACHE_SIZE - 1) / PAGE_CACHE_SIZE);
367
368 do {
369 unsigned long out = PAGE_CACHE_SIZE;
370 unsigned long next = *(u32 *) romfs_read(offset);
371
372 if (next > end_data) {
373 end_data = next;
374 }
375
376 offset += 4;
377 if (curr == next) {
378 if (opt_verbose > 1) {
379 printf(" hole at %ld (%d)\n", curr, PAGE_CACHE_SIZE);
380 }
381 if (size < PAGE_CACHE_SIZE)
382 out = size;
383 memset(outbuffer, 0x00, out);
384 }
385 else {
386 if (opt_verbose > 1) {
387 printf(" uncompressing block at %ld to %ld (%ld)\n", curr, next, next - curr);
388 }
389 out = uncompress_block(romfs_read(curr), next - curr);
390 }
391 if (size >= PAGE_CACHE_SIZE) {
392 if (out != PAGE_CACHE_SIZE) {
393 die(FSCK_UNCORRECTED, 0, "non-block (%ld) bytes", out);
394 }
395 } else {
396 if (out != size) {
397 die(FSCK_UNCORRECTED, 0, "non-size (%ld vs %ld) bytes", out, size);
398 }
399 }
400 size -= out;
401 if (opt_extract) {
402 if (write(fd, outbuffer, out) < 0) {
403 die(FSCK_ERROR, 1, "write failed: %s", path);
404 }
405 }
406 curr = next;
407 } while (size);
408}
409
410static void change_file_status(char *path, struct cramfs_inode *i)
411{
412 struct utimbuf epoch = { 0, 0 };
413
414 if (euid == 0) {
415 if (lchown(path, i->uid, i->gid) < 0) {
416 die(FSCK_ERROR, 1, "lchown failed: %s", path);
417 }
418 if (S_ISLNK(i->mode))
419 return;
420 if ((S_ISUID | S_ISGID) & i->mode) {
421 if (chmod(path, i->mode) < 0) {
422 die(FSCK_ERROR, 1, "chown failed: %s", path);
423 }
424 }
425 }
426 if (S_ISLNK(i->mode))
427 return;
428 if (utime(path, &epoch) < 0) {
429 die(FSCK_ERROR, 1, "utime failed: %s", path);
430 }
431}
432
433static void do_directory(char *path, struct cramfs_inode *i)
434{
435 int pathlen = strlen(path);
436 int count = i->size;
437 unsigned long offset = i->offset << 2;
438 char *newpath = malloc(pathlen + 256);
439
440 if (!newpath) {
441 die(FSCK_ERROR, 1, "malloc failed");
442 }
443 if (offset == 0 && count != 0) {
444 die(FSCK_UNCORRECTED, 0, "directory inode has zero offset and non-zero size: %s", path);
445 }
446 if (offset != 0 && offset < start_dir) {
447 start_dir = offset;
448 }
449 /* TODO: Do we need to check end_dir for empty case? */
450 memcpy(newpath, path, pathlen);
451 newpath[pathlen] = '/';
452 pathlen++;
453 if (opt_verbose) {
454 print_node('d', i, path);
455 }
456 if (opt_extract) {
457 if (mkdir(path, i->mode) < 0) {
458 die(FSCK_ERROR, 1, "mkdir failed: %s", path);
459 }
460 change_file_status(path, i);
461 }
462 while (count > 0) {
463 struct cramfs_inode *child = iget(offset);
464 int size;
465 int newlen = child->namelen << 2;
466
467 size = sizeof(struct cramfs_inode) + newlen;
468 count -= size;
469
470 offset += sizeof(struct cramfs_inode);
471
472 memcpy(newpath + pathlen, romfs_read(offset), newlen);
473 newpath[pathlen + newlen] = 0;
474 if (newlen == 0) {
475 die(FSCK_UNCORRECTED, 0, "filename length is zero");
476 }
477 if ((pathlen + newlen) - strlen(newpath) > 3) {
478 die(FSCK_UNCORRECTED, 0, "bad filename length");
479 }
480 expand_fs(newpath, child);
481
482 offset += newlen;
483
484 if (offset <= start_dir) {
485 die(FSCK_UNCORRECTED, 0, "bad inode offset");
486 }
487 if (offset > end_dir) {
488 end_dir = offset;
489 }
490 iput(child); /* free(child) */
491 }
492 free(newpath);
493}
494
495static void do_file(char *path, struct cramfs_inode *i)
496{
497 unsigned long offset = i->offset << 2;
498 int fd = 0;
499
500 if (offset == 0 && i->size != 0) {
501 die(FSCK_UNCORRECTED, 0, "file inode has zero offset and non-zero size");
502 }
503 if (i->size == 0 && offset != 0) {
504 die(FSCK_UNCORRECTED, 0, "file inode has zero size and non-zero offset");
505 }
506 if (offset != 0 && offset < start_data) {
507 start_data = offset;
508 }
509 if (opt_verbose) {
510 print_node('f', i, path);
511 }
512 if (opt_extract) {
513 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, i->mode);
514 if (fd < 0) {
515 die(FSCK_ERROR, 1, "open failed: %s", path);
516 }
517 }
518 if (i->size) {
519 do_uncompress(path, fd, offset, i->size);
520 }
521 if (opt_extract) {
522 close(fd);
523 change_file_status(path, i);
524 }
525}
526
527static void do_symlink(char *path, struct cramfs_inode *i)
528{
529 unsigned long offset = i->offset << 2;
530 unsigned long curr = offset + 4;
531 unsigned long next = *(u32 *) romfs_read(offset);
532 unsigned long size;
533
534 if (offset == 0) {
535 die(FSCK_UNCORRECTED, 0, "symbolic link has zero offset");
536 }
537 if (i->size == 0) {
538 die(FSCK_UNCORRECTED, 0, "symbolic link has zero size");
539 }
540
541 if (offset < start_data) {
542 start_data = offset;
543 }
544 if (next > end_data) {
545 end_data = next;
546 }
547
548 size = uncompress_block(romfs_read(curr), next - curr);
549 if (size != i->size) {
550 die(FSCK_UNCORRECTED, 0, "size error in symlink: %s", path);
551 }
552 outbuffer[size] = 0;
553 if (opt_verbose) {
554 char *str;
555
556 asprintf(&str, "%s -> %s", path, outbuffer);
557 print_node('l', i, str);
558 if (opt_verbose > 1) {
559 printf(" uncompressing block at %ld to %ld (%ld)\n", curr, next, next - curr);
560 }
561 free(str);
562 }
563 if (opt_extract) {
564 if (symlink(outbuffer, path) < 0) {
565 die(FSCK_ERROR, 1, "symlink failed: %s", path);
566 }
567 change_file_status(path, i);
568 }
569}
570
571static void do_special_inode(char *path, struct cramfs_inode *i)
572{
573 dev_t devtype = 0;
574 char type;
575
576 if (i->offset) { /* no need to shift offset */
577 die(FSCK_UNCORRECTED, 0, "special file has non-zero offset: %s", path);
578 }
579 if (S_ISCHR(i->mode)) {
580 devtype = i->size;
581 type = 'c';
582 }
583 else if (S_ISBLK(i->mode)) {
584 devtype = i->size;
585 type = 'b';
586 }
587 else if (S_ISFIFO(i->mode)) {
588 if (i->size != 0) {
589 die(FSCK_UNCORRECTED, 0, "fifo has non-zero size: %s", path);
590 }
591 type = 'p';
592 }
593 else if (S_ISSOCK(i->mode)) {
594 if (i->size != 0) {
595 die(FSCK_UNCORRECTED, 0, "socket has non-zero size: %s", path);
596 }
597 type = 's';
598 }
599 else {
600 die(FSCK_UNCORRECTED, 0, "bogus mode: %s (%o)", path, i->mode);
601 return; /* not reached */
602 }
603
604 if (opt_verbose) {
605 print_node(type, i, path);
606 }
607
608 if (opt_extract) {
609 if (mknod(path, i->mode, devtype) < 0) {
610 die(FSCK_ERROR, 1, "mknod failed: %s", path);
611 }
612 change_file_status(path, i);
613 }
614}
615
616static void expand_fs(char *path, struct cramfs_inode *inode)
617{
618 if (S_ISDIR(inode->mode)) {
619 do_directory(path, inode);
620 }
621 else if (S_ISREG(inode->mode)) {
622 do_file(path, inode);
623 }
624 else if (S_ISLNK(inode->mode)) {
625 do_symlink(path, inode);
626 }
627 else {
628 do_special_inode(path, inode);
629 }
630}
631
632static void test_fs(int start)
633{
634 struct cramfs_inode *root;
635
636 root = read_super();
637 umask(0);
638 euid = geteuid();
639 stream.next_in = NULL;
640 stream.avail_in = 0;
641 inflateInit(&stream);
642 expand_fs(extract_dir, root);
643 inflateEnd(&stream);
644 if (start_data != ~0UL) {
645 if (start_data < (sizeof(struct cramfs_super) + start)) {
646 die(FSCK_UNCORRECTED, 0, "directory data start (%ld) < sizeof(struct cramfs_super) + start (%ld)", start_data, sizeof(struct cramfs_super) + start);
647 }
648 if (end_dir != start_data) {
649 die(FSCK_UNCORRECTED, 0, "directory data end (%ld) != file data start (%ld)", end_dir, start_data);
650 }
651 }
652 if (super.flags & CRAMFS_FLAG_FSID_VERSION_2) {
653 if (end_data > super.size) {
654 die(FSCK_UNCORRECTED, 0, "invalid file data offset");
655 }
656 }
657 iput(root); /* free(root) */
658}
659#endif /* INCLUDE_FS_TESTS */
660
661int main(int argc, char **argv)
662{
663 int c; /* for getopt */
664 int start = 0;
665 size_t length;
666
667 page_size = sysconf(_SC_PAGESIZE);
668
669 if (argc)
670 progname = argv[0];
671
672 outbuffer = malloc(page_size * 2);
673 if (!outbuffer)
674 die(FSCK_ERROR, 1, "failed to allocate outbuffer");
675
676 /* command line options */
677 while ((c = getopt(argc, argv, "hx:v")) != EOF) {
678 switch (c) {
679 case 'h':
680 usage(FSCK_OK);
681 case 'x':
682#ifdef INCLUDE_FS_TESTS
683 opt_extract = 1;
684 extract_dir = optarg;
685 break;
686#else /* not INCLUDE_FS_TESTS */
687 die(FSCK_USAGE, 0, "compiled without -x support");
688#endif /* not INCLUDE_FS_TESTS */
689 case 'v':
690 opt_verbose++;
691 break;
692 }
693 }
694
695 if ((argc - optind) != 1)
696 usage(FSCK_USAGE);
697 filename = argv[optind];
698
699 test_super(&start, &length);
700 test_crc(start);
701#ifdef INCLUDE_FS_TESTS
702 test_fs(start);
703#endif /* INCLUDE_FS_TESTS */
704
705 if (opt_verbose) {
706 printf("%s: OK\n", filename);
707 }
708
709 exit(FSCK_OK);
710}
711
712/*
713 * Local variables:
714 * c-file-style: "linux"
715 * End:
716 */
diff --git a/utils/ypr0tools/cramfs-1.1/linux/cramfs_fs.h b/utils/ypr0tools/cramfs-1.1/linux/cramfs_fs.h
new file mode 100644
index 0000000000..a8948f34b7
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/linux/cramfs_fs.h
@@ -0,0 +1,98 @@
1#ifndef __CRAMFS_H
2#define __CRAMFS_H
3
4#ifndef __KERNEL__
5
6typedef unsigned char u8;
7typedef unsigned short u16;
8typedef unsigned int u32;
9
10#endif
11
12#define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
13#define CRAMFS_SIGNATURE "Compressed ROMFS"
14
15/*
16 * Width of various bitfields in struct cramfs_inode.
17 * Primarily used to generate warnings in mkcramfs.
18 */
19#define CRAMFS_MODE_WIDTH 16
20#define CRAMFS_UID_WIDTH 16
21#define CRAMFS_SIZE_WIDTH 24
22#define CRAMFS_GID_WIDTH 8
23#define CRAMFS_NAMELEN_WIDTH 6
24#define CRAMFS_OFFSET_WIDTH 26
25
26/*
27 * Since inode.namelen is a unsigned 6-bit number, the maximum cramfs
28 * path length is 63 << 2 = 252.
29 */
30#define CRAMFS_MAXPATHLEN (((1 << CRAMFS_NAMELEN_WIDTH) - 1) << 2)
31
32/*
33 * Reasonably terse representation of the inode data.
34 */
35struct cramfs_inode {
36 u32 mode:CRAMFS_MODE_WIDTH, uid:CRAMFS_UID_WIDTH;
37 /* SIZE for device files is i_rdev */
38 u32 size:CRAMFS_SIZE_WIDTH, gid:CRAMFS_GID_WIDTH;
39 /* NAMELEN is the length of the file name, divided by 4 and
40 rounded up. (cramfs doesn't support hard links.) */
41 /* OFFSET: For symlinks and non-empty regular files, this
42 contains the offset (divided by 4) of the file data in
43 compressed form (starting with an array of block pointers;
44 see README). For non-empty directories it is the offset
45 (divided by 4) of the inode of the first file in that
46 directory. For anything else, offset is zero. */
47 u32 namelen:CRAMFS_NAMELEN_WIDTH, offset:CRAMFS_OFFSET_WIDTH;
48};
49
50struct cramfs_info {
51 u32 crc;
52 u32 edition;
53 u32 blocks;
54 u32 files;
55};
56
57/*
58 * Superblock information at the beginning of the FS.
59 */
60struct cramfs_super {
61 u32 magic; /* 0x28cd3d45 - random number */
62 u32 size; /* length in bytes */
63 u32 flags; /* feature flags */
64 u32 future; /* reserved for future use */
65 u8 signature[16]; /* "Compressed ROMFS" */
66 struct cramfs_info fsid; /* unique filesystem info */
67 u8 name[16]; /* user-defined name */
68 struct cramfs_inode root; /* root inode data */
69};
70
71/*
72 * Feature flags
73 *
74 * 0x00000000 - 0x000000ff: features that work for all past kernels
75 * 0x00000100 - 0xffffffff: features that don't work for past kernels
76 */
77#define CRAMFS_FLAG_FSID_VERSION_2 0x00000001 /* fsid version #2 */
78#define CRAMFS_FLAG_SORTED_DIRS 0x00000002 /* sorted dirs */
79#define CRAMFS_FLAG_HOLES 0x00000100 /* support for holes */
80#define CRAMFS_FLAG_WRONG_SIGNATURE 0x00000200 /* reserved */
81#define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400 /* shifted root fs */
82
83/*
84 * Valid values in super.flags. Currently we refuse to mount
85 * if (flags & ~CRAMFS_SUPPORTED_FLAGS). Maybe that should be
86 * changed to test super.future instead.
87 */
88#define CRAMFS_SUPPORTED_FLAGS ( 0x000000ff \
89 | CRAMFS_FLAG_HOLES \
90 | CRAMFS_FLAG_WRONG_SIGNATURE \
91 | CRAMFS_FLAG_SHIFTED_ROOT_OFFSET )
92
93/* Uncompression interfaces to the underlying zlib */
94int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen);
95int cramfs_uncompress_init(void);
96int cramfs_uncompress_exit(void);
97
98#endif
diff --git a/utils/ypr0tools/cramfs-1.1/linux/cramfs_fs_sb.h b/utils/ypr0tools/cramfs-1.1/linux/cramfs_fs_sb.h
new file mode 100644
index 0000000000..afea368796
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/linux/cramfs_fs_sb.h
@@ -0,0 +1,15 @@
1#ifndef _CRAMFS_FS_SB
2#define _CRAMFS_FS_SB
3
4/*
5 * cramfs super-block data in memory
6 */
7struct cramfs_sb_info {
8 unsigned long magic;
9 unsigned long size;
10 unsigned long blocks;
11 unsigned long files;
12 unsigned long flags;
13};
14
15#endif
diff --git a/utils/ypr0tools/cramfs-1.1/mkcramfs.c b/utils/ypr0tools/cramfs-1.1/mkcramfs.c
new file mode 100644
index 0000000000..2eccb733be
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/mkcramfs.c
@@ -0,0 +1,889 @@
1/*
2 * mkcramfs - make a cramfs file system
3 *
4 * Copyright (C) 1999-2002 Transmeta Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * If you change the disk format of cramfs, please update fs/cramfs/README.
23 */
24
25#include <sys/types.h>
26#include <stdio.h>
27#include <sys/stat.h>
28#include <unistd.h>
29#include <sys/mman.h>
30#include <fcntl.h>
31#include <dirent.h>
32#include <stdlib.h>
33#include <errno.h>
34#include <string.h>
35#include <stdarg.h>
36#include <linux/cramfs_fs.h>
37#include <zlib.h>
38#include <stdint.h>
39
40/* Exit codes used by mkfs-type programs */
41#define MKFS_OK 0 /* No errors */
42#define MKFS_ERROR 8 /* Operational error */
43#define MKFS_USAGE 16 /* Usage or syntax error */
44
45/* The kernel only supports PAD_SIZE of 0 and 512. */
46#define PAD_SIZE 512
47
48/*
49 * The longest filename component to allow for in the input directory tree.
50 * ext2fs (and many others) allow up to 255 bytes. A couple of filesystems
51 * allow longer (e.g. smbfs 1024), but there isn't much use in supporting
52 * >255-byte names in the input directory tree given that such names get
53 * truncated to CRAMFS_MAXPATHLEN (252 bytes) when written to cramfs.
54 *
55 * Old versions of mkcramfs generated corrupted filesystems if any input
56 * filenames exceeded CRAMFS_MAXPATHLEN (252 bytes), however old
57 * versions of cramfsck seem to have been able to detect the corruption.
58 */
59#define MAX_INPUT_NAMELEN 255
60
61/*
62 * Maximum size fs you can create is roughly 256MB. (The last file's
63 * data must begin within 256MB boundary but can extend beyond that.)
64 *
65 * Note that if you want it to fit in a ROM then you're limited to what the
66 * hardware and kernel can support.
67 */
68#define MAXFSLEN ((((1 << CRAMFS_OFFSET_WIDTH) - 1) << 2) /* offset */ \
69 + (1 << CRAMFS_SIZE_WIDTH) - 1 /* filesize */ \
70 + (1 << CRAMFS_SIZE_WIDTH) * 4 / blksize /* block pointers */ )
71
72static const char *progname = "mkcramfs";
73static unsigned int blksize;
74static long total_blocks = 0, total_nodes = 1; /* pre-count the root node */
75static int image_length = 0;
76
77/*
78 * If opt_holes is set, then mkcramfs can create explicit holes in the
79 * data, which saves 26 bytes per hole (which is a lot smaller a
80 * saving than most most filesystems).
81 *
82 * Note that kernels up to at least 2.3.39 don't support cramfs holes,
83 * which is why this is turned off by default.
84 *
85 * If opt_verbose is 1, be verbose. If it is higher, be even more verbose.
86 */
87static u32 opt_edition = 0;
88static int opt_errors = 0;
89static int opt_holes = 0;
90static int opt_pad = 0;
91static int opt_verbose = 0;
92static char *opt_image = NULL;
93static char *opt_name = NULL;
94
95static int warn_dev, warn_gid, warn_namelen, warn_skip, warn_size, warn_uid;
96
97/* In-core version of inode / directory entry. */
98struct entry {
99 /* stats */
100 unsigned char *name;
101 unsigned int mode, size, uid, gid;
102
103 /* these are only used for non-empty files */
104 char *path; /* always null except non-empty files */
105 int fd; /* temporarily open files while mmapped */
106
107 /* FS data */
108 void *uncompressed;
109 /* points to other identical file */
110 struct entry *same;
111 unsigned int offset; /* pointer to compressed data in archive */
112 unsigned int dir_offset; /* Where in the archive is the directory entry? */
113
114 /* organization */
115 struct entry *child; /* null for non-directories and empty directories */
116 struct entry *next;
117};
118
119/* Input status of 0 to print help and exit without an error. */
120static void usage(int status)
121{
122 FILE *stream = status ? stderr : stdout;
123
124 fprintf(stream, "usage: %s [-h] [-b blksize] [-e edition] [-i file] [-n name] dirname outfile\n"
125 " -h print this help\n"
126 " -E make all warnings errors (non-zero exit status)\n"
127 " -b blksize blocksize to use\n"
128 " -e edition set edition number (part of fsid)\n"
129 " -i file insert a file image into the filesystem (requires >= 2.4.0)\n"
130 " -n name set name of cramfs filesystem\n"
131 " -p pad by %d bytes for boot code\n"
132 " -s sort directory entries (old option, ignored)\n"
133 " -v be more verbose\n"
134 " -z make explicit holes (requires >= 2.3.39)\n"
135 " dirname root of the directory tree to be compressed\n"
136 " outfile output file\n", progname, PAD_SIZE);
137
138 exit(status);
139}
140
141static void die(int status, int syserr, const char *fmt, ...)
142{
143 va_list arg_ptr;
144 int save = errno;
145
146 fflush(0);
147 va_start(arg_ptr, fmt);
148 fprintf(stderr, "%s: ", progname);
149 vfprintf(stderr, fmt, arg_ptr);
150 if (syserr) {
151 fprintf(stderr, ": %s", strerror(save));
152 }
153 fprintf(stderr, "\n");
154 va_end(arg_ptr);
155 exit(status);
156}
157
158static void map_entry(struct entry *entry)
159{
160 if (entry->path) {
161 entry->fd = open(entry->path, O_RDONLY);
162 if (entry->fd < 0) {
163 die(MKFS_ERROR, 1, "open failed: %s", entry->path);
164 }
165 entry->uncompressed = mmap(NULL, entry->size, PROT_READ, MAP_PRIVATE, entry->fd, 0);
166 if (entry->uncompressed == MAP_FAILED) {
167 die(MKFS_ERROR, 1, "mmap failed: %s", entry->path);
168 }
169 }
170}
171
172static void unmap_entry(struct entry *entry)
173{
174 if (entry->path) {
175 if (munmap(entry->uncompressed, entry->size) < 0) {
176 die(MKFS_ERROR, 1, "munmap failed: %s", entry->path);
177 }
178 close(entry->fd);
179 }
180}
181
182static int find_identical_file(struct entry *orig, struct entry *newfile)
183{
184 if (orig == newfile)
185 return 1;
186 if (!orig)
187 return 0;
188 if (orig->size == newfile->size && (orig->path || orig->uncompressed))
189 {
190 map_entry(orig);
191 map_entry(newfile);
192 if (!memcmp(orig->uncompressed, newfile->uncompressed, orig->size))
193 {
194 newfile->same = orig;
195 unmap_entry(newfile);
196 unmap_entry(orig);
197 return 1;
198 }
199 unmap_entry(newfile);
200 unmap_entry(orig);
201 }
202 return (find_identical_file(orig->child, newfile) ||
203 find_identical_file(orig->next, newfile));
204}
205
206static void eliminate_doubles(struct entry *root, struct entry *orig) {
207 if (orig) {
208 if (orig->size && (orig->path || orig->uncompressed))
209 find_identical_file(root, orig);
210 eliminate_doubles(root, orig->child);
211 eliminate_doubles(root, orig->next);
212 }
213}
214
215/*
216 * We define our own sorting function instead of using alphasort which
217 * uses strcoll and changes ordering based on locale information.
218 */
219static int cramsort (const void *a, const void *b)
220{
221 return strcmp ((*(const struct dirent **) a)->d_name,
222 (*(const struct dirent **) b)->d_name);
223}
224
225static unsigned int parse_directory(struct entry *root_entry, const char *name, struct entry **prev, loff_t *fslen_ub)
226{
227 struct dirent **dirlist;
228 int totalsize = 0, dircount, dirindex;
229 char *path, *endpath;
230 size_t len = strlen(name);
231
232 /* Set up the path. */
233 /* TODO: Reuse the parent's buffer to save memcpy'ing and duplication. */
234 path = malloc(len + 1 + MAX_INPUT_NAMELEN + 1);
235 if (!path) {
236 die(MKFS_ERROR, 1, "malloc failed");
237 }
238 memcpy(path, name, len);
239 endpath = path + len;
240 *endpath = '/';
241 endpath++;
242
243 /* read in the directory and sort */
244 dircount = scandir(name, &dirlist, 0, cramsort);
245
246 if (dircount < 0) {
247 die(MKFS_ERROR, 1, "scandir failed: %s", name);
248 }
249
250 /* process directory */
251 for (dirindex = 0; dirindex < dircount; dirindex++) {
252 struct dirent *dirent;
253 struct entry *entry;
254 struct stat st;
255 int size;
256 size_t namelen;
257
258 dirent = dirlist[dirindex];
259
260 /* Ignore "." and ".." - we won't be adding them to the archive */
261 if (dirent->d_name[0] == '.') {
262 if (dirent->d_name[1] == '\0')
263 continue;
264 if (dirent->d_name[1] == '.') {
265 if (dirent->d_name[2] == '\0')
266 continue;
267 }
268 }
269 namelen = strlen(dirent->d_name);
270 if (namelen > MAX_INPUT_NAMELEN) {
271 die(MKFS_ERROR, 0,
272 "very long (%u bytes) filename found: %s\n"
273 "please increase MAX_INPUT_NAMELEN in mkcramfs.c and recompile",
274 namelen, dirent->d_name);
275 }
276 memcpy(endpath, dirent->d_name, namelen + 1);
277
278 if (lstat(path, &st) < 0) {
279 warn_skip = 1;
280 continue;
281 }
282 entry = calloc(1, sizeof(struct entry));
283 if (!entry) {
284 die(MKFS_ERROR, 1, "calloc failed");
285 }
286 entry->name = strdup(dirent->d_name);
287 if (!entry->name) {
288 die(MKFS_ERROR, 1, "strdup failed");
289 }
290 /* truncate multi-byte UTF-8 filenames on character boundary */
291 if (namelen > CRAMFS_MAXPATHLEN) {
292 namelen = CRAMFS_MAXPATHLEN;
293 warn_namelen = 1;
294 /* the first lost byte must not be a trail byte */
295 while ((entry->name[namelen] & 0xc0) == 0x80) {
296 namelen--;
297 /* are we reasonably certain it was UTF-8 ? */
298 if (entry->name[namelen] < 0x80 || !namelen) {
299 die(MKFS_ERROR, 0, "cannot truncate filenames not encoded in UTF-8");
300 }
301 }
302 entry->name[namelen] = '\0';
303 }
304 entry->mode = st.st_mode;
305 entry->size = st.st_size;
306 entry->uid = st.st_uid;
307 if (entry->uid >= 1 << CRAMFS_UID_WIDTH)
308 warn_uid = 1;
309 entry->gid = st.st_gid;
310 if (entry->gid >= 1 << CRAMFS_GID_WIDTH)
311 /* TODO: We ought to replace with a default
312 gid instead of truncating; otherwise there
313 are security problems. Maybe mode should
314 be &= ~070. Same goes for uid once Linux
315 supports >16-bit uids. */
316 warn_gid = 1;
317 size = sizeof(struct cramfs_inode) + ((namelen + 3) & ~3);
318 *fslen_ub += size;
319 if (S_ISDIR(st.st_mode)) {
320 entry->size = parse_directory(root_entry, path, &entry->child, fslen_ub);
321 } else if (S_ISREG(st.st_mode)) {
322 if (entry->size) {
323 if (access(path, R_OK) < 0) {
324 warn_skip = 1;
325 continue;
326 }
327 entry->path = strdup(path);
328 if (!entry->path) {
329 die(MKFS_ERROR, 1, "strdup failed");
330 }
331 if ((entry->size >= 1 << CRAMFS_SIZE_WIDTH)) {
332 warn_size = 1;
333 entry->size = (1 << CRAMFS_SIZE_WIDTH) - 1;
334 }
335 }
336 } else if (S_ISLNK(st.st_mode)) {
337 int len;
338 entry->uncompressed = malloc(entry->size);
339 if (!entry->uncompressed) {
340 die(MKFS_ERROR, 1, "malloc failed");
341 }
342 len = readlink(path, entry->uncompressed, entry->size);
343 if (len < 0) {
344 warn_skip = 1;
345 continue;
346 }
347 entry->size = len;
348 } else if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) {
349 /* maybe we should skip sockets */
350 entry->size = 0;
351 } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
352 entry->size = st.st_rdev;
353 if (entry->size & -(1<<CRAMFS_SIZE_WIDTH))
354 warn_dev = 1;
355 } else {
356 die(MKFS_ERROR, 0, "bogus file type: %s", entry->name);
357 }
358
359 if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
360 int blocks = ((entry->size - 1) / blksize + 1);
361
362 /* block pointers & data expansion allowance + data */
363 if (entry->size)
364 *fslen_ub += (4+26)*blocks + entry->size + 3;
365 }
366
367 /* Link it into the list */
368 *prev = entry;
369 prev = &entry->next;
370 totalsize += size;
371 }
372 free(path);
373 free(dirlist); /* allocated by scandir() with malloc() */
374 return totalsize;
375}
376
377/* Returns sizeof(struct cramfs_super), which includes the root inode. */
378static unsigned int write_superblock(struct entry *root, char *base, int size)
379{
380 struct cramfs_super *super = (struct cramfs_super *) base;
381 unsigned int offset = sizeof(struct cramfs_super) + image_length;
382
383 offset += opt_pad; /* 0 if no padding */
384
385 super->magic = CRAMFS_MAGIC;
386 super->flags = CRAMFS_FLAG_FSID_VERSION_2 | CRAMFS_FLAG_SORTED_DIRS;
387 if (opt_holes)
388 super->flags |= CRAMFS_FLAG_HOLES;
389 if (image_length > 0)
390 super->flags |= CRAMFS_FLAG_SHIFTED_ROOT_OFFSET;
391 super->size = size;
392 memcpy(super->signature, CRAMFS_SIGNATURE, sizeof(super->signature));
393
394 super->fsid.crc = crc32(0L, Z_NULL, 0);
395 super->fsid.edition = opt_edition;
396 super->fsid.blocks = total_blocks;
397 super->fsid.files = total_nodes;
398
399 memset(super->name, 0x00, sizeof(super->name));
400 if (opt_name)
401 strncpy(super->name, opt_name, sizeof(super->name));
402 else
403 strncpy(super->name, "Compressed", sizeof(super->name));
404
405 super->root.mode = root->mode;
406 super->root.uid = root->uid;
407 super->root.gid = root->gid;
408 super->root.size = root->size;
409 super->root.offset = offset >> 2;
410
411 return offset;
412}
413
414static void set_data_offset(struct entry *entry, char *base, unsigned long offset)
415{
416 struct cramfs_inode *inode = (struct cramfs_inode *) (base + entry->dir_offset);
417
418 if ((offset & 3) != 0) {
419 die(MKFS_ERROR, 0, "illegal offset of %lu bytes", offset);
420 }
421 if (offset >= (1 << (2 + CRAMFS_OFFSET_WIDTH))) {
422 die(MKFS_ERROR, 0, "filesystem too big");
423 }
424 inode->offset = (offset >> 2);
425}
426
427/*
428 * TODO: Does this work for chars >= 0x80? Most filesystems use UTF-8
429 * encoding for filenames, whereas the console is a single-byte
430 * character set like iso-latin-1.
431 */
432static void print_node(struct entry *e)
433{
434 char info[10];
435 char type = '?';
436
437 if (S_ISREG(e->mode)) type = 'f';
438 else if (S_ISDIR(e->mode)) type = 'd';
439 else if (S_ISLNK(e->mode)) type = 'l';
440 else if (S_ISCHR(e->mode)) type = 'c';
441 else if (S_ISBLK(e->mode)) type = 'b';
442 else if (S_ISFIFO(e->mode)) type = 'p';
443 else if (S_ISSOCK(e->mode)) type = 's';
444
445 if (S_ISCHR(e->mode) || (S_ISBLK(e->mode))) {
446 /* major/minor numbers can be as high as 2^12 or 4096 */
447 snprintf(info, 10, "%4d,%4d", major(e->size), minor(e->size));
448 }
449 else {
450 /* size be as high as 2^24 or 16777216 */
451 snprintf(info, 10, "%9d", e->size);
452 }
453
454 printf("%c %04o %s %5d:%-3d %s\n",
455 type, e->mode & ~S_IFMT, info, e->uid, e->gid, e->name);
456}
457
458/*
459 * We do a width-first printout of the directory
460 * entries, using a stack to remember the directories
461 * we've seen.
462 */
463static unsigned int write_directory_structure(struct entry *entry, char *base, unsigned int offset)
464{
465 int stack_entries = 0;
466 int stack_size = 64;
467 struct entry **entry_stack;
468
469 entry_stack = malloc(stack_size * sizeof(struct entry *));
470 if (!entry_stack) {
471 die(MKFS_ERROR, 1, "malloc failed");
472 }
473
474 if (opt_verbose) {
475 printf("root:\n");
476 }
477
478 for (;;) {
479 int dir_start = stack_entries;
480 while (entry) {
481 struct cramfs_inode *inode = (struct cramfs_inode *) (base + offset);
482 size_t len = strlen(entry->name);
483
484 entry->dir_offset = offset;
485
486 inode->mode = entry->mode;
487 inode->uid = entry->uid;
488 inode->gid = entry->gid;
489 inode->size = entry->size;
490 inode->offset = 0;
491 /* Non-empty directories, regfiles and symlinks will
492 write over inode->offset later. */
493
494 offset += sizeof(struct cramfs_inode);
495 total_nodes++; /* another node */
496 memcpy(base + offset, entry->name, len);
497 /* Pad up the name to a 4-byte boundary */
498 while (len & 3) {
499 *(base + offset + len) = '\0';
500 len++;
501 }
502 inode->namelen = len >> 2;
503 offset += len;
504
505 if (opt_verbose)
506 print_node(entry);
507
508 if (entry->child) {
509 if (stack_entries >= stack_size) {
510 stack_size *= 2;
511 entry_stack = realloc(entry_stack, stack_size * sizeof(struct entry *));
512 if (!entry_stack) {
513 die(MKFS_ERROR, 1, "realloc failed");
514 }
515 }
516 entry_stack[stack_entries] = entry;
517 stack_entries++;
518 }
519 entry = entry->next;
520 }
521
522 /*
523 * Reverse the order the stack entries pushed during
524 * this directory, for a small optimization of disk
525 * access in the created fs. This change makes things
526 * `ls -UR' order.
527 */
528 {
529 struct entry **lo = entry_stack + dir_start;
530 struct entry **hi = entry_stack + stack_entries;
531 struct entry *tmp;
532
533 while (lo < --hi) {
534 tmp = *lo;
535 *lo++ = *hi;
536 *hi = tmp;
537 }
538 }
539
540 /* Pop a subdirectory entry from the stack, and recurse. */
541 if (!stack_entries)
542 break;
543 stack_entries--;
544 entry = entry_stack[stack_entries];
545
546 set_data_offset(entry, base, offset);
547 if (opt_verbose) {
548 printf("%s:\n", entry->name);
549 }
550 entry = entry->child;
551 }
552 free(entry_stack);
553 return offset;
554}
555
556static int is_zero(char const *begin, unsigned len)
557{
558 /* Returns non-zero iff the first LEN bytes from BEGIN are all NULs. */
559 return (len-- == 0 ||
560 (begin[0] == '\0' &&
561 (len-- == 0 ||
562 (begin[1] == '\0' &&
563 (len-- == 0 ||
564 (begin[2] == '\0' &&
565 (len-- == 0 ||
566 (begin[3] == '\0' &&
567 memcmp(begin, begin + 4, len) == 0))))))));
568}
569
570/*
571 * One 4-byte pointer per block and then the actual blocked
572 * output. The first block does not need an offset pointer,
573 * as it will start immediately after the pointer block;
574 * so the i'th pointer points to the end of the i'th block
575 * (i.e. the start of the (i+1)'th block or past EOF).
576 *
577 * Note that size > 0, as a zero-sized file wouldn't ever
578 * have gotten here in the first place.
579 */
580static unsigned int do_compress(char *base, unsigned int offset, char const *name, char *uncompressed, unsigned int size)
581{
582 unsigned long original_size = size;
583 unsigned long original_offset = offset;
584 unsigned long new_size;
585 unsigned long blocks = (size - 1) / blksize + 1;
586 unsigned long curr = offset + 4 * blocks;
587 int change;
588
589 total_blocks += blocks;
590
591 do {
592 unsigned long len = 2 * blksize;
593 unsigned int input = size;
594 int err;
595
596 if (input > blksize)
597 input = blksize;
598 size -= input;
599 if (!(opt_holes && is_zero (uncompressed, input))) {
600 err = compress2(base + curr, &len, uncompressed, input, Z_BEST_COMPRESSION);
601 if (err != Z_OK) {
602 die(MKFS_ERROR, 0, "compression error: %s", zError(err));
603 }
604 curr += len;
605 }
606 uncompressed += input;
607
608 if (len > blksize*2) {
609 /* (I don't think this can happen with zlib.) */
610 die(MKFS_ERROR, 0, "AIEEE: block \"compressed\" to > 2*blocklength (%ld)", len);
611 }
612
613 *(u32 *) (base + offset) = curr;
614 offset += 4;
615 } while (size);
616
617 curr = (curr + 3) & ~3;
618 new_size = curr - original_offset;
619 /* TODO: Arguably, original_size in these 2 lines should be
620 st_blocks * 512. But if you say that then perhaps
621 administrative data should also be included in both. */
622 change = new_size - original_size;
623 if (opt_verbose > 1) {
624 printf("%6.2f%% (%+d bytes)\t%s\n",
625 (change * 100) / (double) original_size, change, name);
626 }
627
628 return curr;
629}
630
631
632/*
633 * Traverse the entry tree, writing data for every item that has
634 * non-null entry->path (i.e. every non-empty regfile) and non-null
635 * entry->uncompressed (i.e. every symlink).
636 */
637static unsigned int write_data(struct entry *entry, char *base, unsigned int offset)
638{
639 do {
640 if (entry->path || entry->uncompressed) {
641 if (entry->same) {
642 set_data_offset(entry, base, entry->same->offset);
643 entry->offset = entry->same->offset;
644 }
645 else {
646 set_data_offset(entry, base, offset);
647 entry->offset = offset;
648 map_entry(entry);
649 offset = do_compress(base, offset, entry->name, entry->uncompressed, entry->size);
650 unmap_entry(entry);
651 }
652 }
653 else if (entry->child)
654 offset = write_data(entry->child, base, offset);
655 entry=entry->next;
656 } while (entry);
657 return offset;
658}
659
660static unsigned int write_file(char *file, char *base, unsigned int offset)
661{
662 int fd;
663 char *buf;
664
665 fd = open(file, O_RDONLY);
666 if (fd < 0) {
667 die(MKFS_ERROR, 1, "open failed: %s", file);
668 }
669 buf = mmap(NULL, image_length, PROT_READ, MAP_PRIVATE, fd, 0);
670 if (buf == MAP_FAILED) {
671 die(MKFS_ERROR, 1, "mmap failed");
672 }
673 memcpy(base + offset, buf, image_length);
674 munmap(buf, image_length);
675 close (fd);
676 /* Pad up the image_length to a 4-byte boundary */
677 while (image_length & 3) {
678 *(base + offset + image_length) = '\0';
679 image_length++;
680 }
681 return (offset + image_length);
682}
683
684int main(int argc, char **argv)
685{
686 struct stat st; /* used twice... */
687 struct entry *root_entry;
688 char *rom_image;
689 ssize_t offset, written;
690 int fd;
691 /* initial guess (upper-bound) of required filesystem size */
692 loff_t fslen_ub = sizeof(struct cramfs_super);
693 char const *dirname, *outfile;
694 u32 crc;
695 int c; /* for getopt */
696 char *ep; /* for strtoul */
697
698 blksize = sysconf(_SC_PAGESIZE);
699 total_blocks = 0;
700
701 if (argc)
702 progname = argv[0];
703
704 /* command line options */
705 while ((c = getopt(argc, argv, "hEb:e:i:n:psvz")) != EOF) {
706 switch (c) {
707 case 'h':
708 usage(MKFS_OK);
709 case 'E':
710 opt_errors = 1;
711 break;
712 case 'b':
713 errno = 0;
714 blksize = strtoul(optarg, &ep, 10);
715 if (errno || optarg[0] == '\0' || *ep != '\0')
716 usage(MKFS_USAGE);
717 if (blksize < 512 || (blksize & (blksize - 1)))
718 die(MKFS_ERROR, 0, "invalid blocksize: %u", blksize);
719 break;
720 case 'e':
721 errno = 0;
722 opt_edition = strtoul(optarg, &ep, 10);
723 if (errno || optarg[0] == '\0' || *ep != '\0')
724 usage(MKFS_USAGE);
725 break;
726 case 'i':
727 opt_image = optarg;
728 if (lstat(opt_image, &st) < 0) {
729 die(MKFS_ERROR, 1, "lstat failed: %s", opt_image);
730 }
731 image_length = st.st_size; /* may be padded later */
732 fslen_ub += (image_length + 3); /* 3 is for padding */
733 break;
734 case 'n':
735 opt_name = optarg;
736 break;
737 case 'p':
738 opt_pad = PAD_SIZE;
739 fslen_ub += PAD_SIZE;
740 break;
741 case 's':
742 /* old option, ignored */
743 break;
744 case 'v':
745 opt_verbose++;
746 break;
747 case 'z':
748 opt_holes = 1;
749 break;
750 }
751 }
752
753 if ((argc - optind) != 2)
754 usage(MKFS_USAGE);
755 dirname = argv[optind];
756 outfile = argv[optind + 1];
757
758 if (stat(dirname, &st) < 0) {
759 die(MKFS_USAGE, 1, "stat failed: %s", dirname);
760 }
761 fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
762 if (fd < 0) {
763 die(MKFS_USAGE, 1, "open failed: %s", outfile);
764 }
765
766 root_entry = calloc(1, sizeof(struct entry));
767 if (!root_entry) {
768 die(MKFS_ERROR, 1, "calloc failed");
769 }
770 root_entry->mode = st.st_mode;
771 root_entry->uid = st.st_uid;
772 root_entry->gid = st.st_gid;
773
774 root_entry->size = parse_directory(root_entry, dirname, &root_entry->child, &fslen_ub);
775
776 /* always allocate a multiple of blksize bytes because that's
777 what we're going to write later on */
778 fslen_ub = ((fslen_ub - 1) | (blksize - 1)) + 1;
779
780 if (fslen_ub > MAXFSLEN) {
781 fprintf(stderr,
782 "warning: estimate of required size (upper bound) is %jdMB, but maximum image size is %uMB, we might die prematurely\n",
783 (intmax_t) (fslen_ub >> 20),
784 MAXFSLEN >> 20);
785 fslen_ub = MAXFSLEN;
786 }
787
788 /* find duplicate files. TODO: uses the most inefficient algorithm
789 possible. */
790 eliminate_doubles(root_entry, root_entry);
791
792 /* TODO: Why do we use a private/anonymous mapping here
793 followed by a write below, instead of just a shared mapping
794 and a couple of ftruncate calls? Is it just to save us
795 having to deal with removing the file afterwards? If we
796 really need this huge anonymous mapping, we ought to mmap
797 in smaller chunks, so that the user doesn't need nn MB of
798 RAM free. If the reason is to be able to write to
799 un-mmappable block devices, then we could try shared mmap
800 and revert to anonymous mmap if the shared mmap fails. */
801 rom_image = mmap(NULL, fslen_ub?fslen_ub:1, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
802
803 if (rom_image == MAP_FAILED) {
804 die(MKFS_ERROR, 1, "mmap failed");
805 }
806
807 /* Skip the first opt_pad bytes for boot loader code */
808 offset = opt_pad;
809 memset(rom_image, 0x00, opt_pad);
810
811 /* Skip the superblock and come back to write it later. */
812 offset += sizeof(struct cramfs_super);
813
814 /* Insert a file image. */
815 if (opt_image) {
816 printf("Including: %s\n", opt_image);
817 offset = write_file(opt_image, rom_image, offset);
818 }
819
820 offset = write_directory_structure(root_entry->child, rom_image, offset);
821 printf("Directory data: %zd bytes\n", offset);
822
823 offset = write_data(root_entry, rom_image, offset);
824
825 /* We always write a multiple of blksize bytes, so that
826 losetup works. */
827 offset = ((offset - 1) | (blksize - 1)) + 1;
828 printf("Everything: %zd kilobytes\n", offset >> 10);
829
830 /* Write the superblock now that we can fill in all of the fields. */
831 write_superblock(root_entry, rom_image+opt_pad, offset);
832 printf("Super block: %zd bytes\n", sizeof(struct cramfs_super));
833
834 /* Put the checksum in. */
835 crc = crc32(0L, Z_NULL, 0);
836 crc = crc32(crc, (rom_image+opt_pad), (offset-opt_pad));
837 ((struct cramfs_super *) (rom_image+opt_pad))->fsid.crc = crc;
838 printf("CRC: %x\n", crc);
839
840 /* Check to make sure we allocated enough space. */
841 if (fslen_ub < offset) {
842 die(MKFS_ERROR, 0, "not enough space allocated for ROM image (%Ld allocated, %d used)", fslen_ub, offset);
843 }
844
845 written = write(fd, rom_image, offset);
846 if (written < 0) {
847 die(MKFS_ERROR, 1, "write failed");
848 }
849 if (offset != written) {
850 die(MKFS_ERROR, 0, "ROM image write failed (wrote %d of %d bytes): No space left on device?", written, offset);
851 }
852
853 /* (These warnings used to come at the start, but they scroll off the
854 screen too quickly.) */
855 if (warn_namelen)
856 fprintf(stderr, /* bytes, not chars: think UTF-8. */
857 "warning: filenames truncated to %d bytes (possibly less if multi-byte UTF-8)\n",
858 CRAMFS_MAXPATHLEN);
859 if (warn_skip)
860 fprintf(stderr, "warning: files were skipped due to errors\n");
861 if (warn_size)
862 fprintf(stderr,
863 "warning: file sizes truncated to %luMB (minus 1 byte)\n",
864 1L << (CRAMFS_SIZE_WIDTH - 20));
865 if (warn_uid) /* (not possible with current Linux versions) */
866 fprintf(stderr,
867 "warning: uids truncated to %u bits (this may be a security concern)\n",
868 CRAMFS_UID_WIDTH);
869 if (warn_gid)
870 fprintf(stderr,
871 "warning: gids truncated to %u bits (this may be a security concern)\n",
872 CRAMFS_GID_WIDTH);
873 if (warn_dev)
874 fprintf(stderr,
875 "WARNING: device numbers truncated to %u bits (this almost certainly means\n"
876 "that some device files will be wrong)\n",
877 CRAMFS_OFFSET_WIDTH);
878 if (opt_errors &&
879 (warn_namelen||warn_skip||warn_size||warn_uid||warn_gid||warn_dev))
880 exit(MKFS_ERROR);
881
882 exit(MKFS_OK);
883}
884
885/*
886 * Local variables:
887 * c-file-style: "linux"
888 * End:
889 */
diff --git a/utils/ypr0tools/extract_section.c b/utils/ypr0tools/extract_section.c
new file mode 100644
index 0000000000..8ad12bc7df
--- /dev/null
+++ b/utils/ypr0tools/extract_section.c
@@ -0,0 +1,85 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <unistd.h>
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <fcntl.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <stdarg.h>
29
30/* A simple replacement program for (
31 * dd if=$file1 of=$file2 bs=1 skip=$offset count=$size
32 *
33 * Written because byte-size operations with dd are unbearably slow.
34 */
35
36void usage(void)
37{
38 fprintf(stderr, "Usage: extract_section <romfile> <outfile> <offset> <byte count>\n");
39 exit(1);
40}
41
42void die(const char* fmt, ...)
43{
44 va_list ap;
45 va_start(ap, fmt);
46 vfprintf(stderr, fmt, ap);
47 va_end(ap);
48 exit(1);
49}
50
51int main(int argc, const char* argv[])
52{
53 if (argc != 5)
54 usage();
55
56 int ifd, ofd;
57 ssize_t size = atol(argv[4]);
58 long skip = atol(argv[3]);
59
60 if (!size)
61 die("invalid byte count\n");
62
63 ifd = open(argv[1], O_RDONLY);
64 if (ifd < 0)
65 die("Could not open %s for reading!\n", argv[1]);
66
67 ofd = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0666);
68 if (ofd < 0)
69 die("Could not create %s\n", argv[2]);
70
71 void *buf = malloc(size);
72 if (!buf) die("OOM\n");
73
74 lseek(ifd, skip, SEEK_SET);
75 lseek(ofd, 0, SEEK_SET);
76 if (read(ifd, buf, size) != size)
77 die("Read failed\n");
78 if (write(ofd, buf, size) != size)
79 die("write failed\n");
80
81 close(ifd);
82 close(ofd);
83
84 exit(EXIT_SUCCESS);
85}
diff --git a/utils/ypr0tools/files/.rockbox/README b/utils/ypr0tools/files/.rockbox/README
new file mode 100644
index 0000000000..f0e306e196
--- /dev/null
+++ b/utils/ypr0tools/files/.rockbox/README
@@ -0,0 +1 @@
This directory is empty and acts as mount point.
diff --git a/utils/ypr0tools/files/Playlists/README b/utils/ypr0tools/files/Playlists/README
new file mode 100644
index 0000000000..f0e306e196
--- /dev/null
+++ b/utils/ypr0tools/files/Playlists/README
@@ -0,0 +1 @@
This directory is empty and acts as mount point.
diff --git a/utils/ypr0tools/files/etc/mods/safe_mode.raw b/utils/ypr0tools/files/etc/mods/safe_mode.raw
new file mode 100644
index 0000000000..1c1aa61dd1
--- /dev/null
+++ b/utils/ypr0tools/files/etc/mods/safe_mode.raw
Binary files differ
diff --git a/utils/ypr0tools/files/etc/mods/safe_mode.sh b/utils/ypr0tools/files/etc/mods/safe_mode.sh
new file mode 100755
index 0000000000..122b2eabfe
--- /dev/null
+++ b/utils/ypr0tools/files/etc/mods/safe_mode.sh
@@ -0,0 +1,111 @@
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/etc/profile b/utils/ypr0tools/files/etc/profile
new file mode 100755
index 0000000000..4ba61d7535
--- /dev/null
+++ b/utils/ypr0tools/files/etc/profile
@@ -0,0 +1,66 @@
1export PS1='\u@\h \w$ '
2export PS2='> '
3export PS3='? '
4export PS4='[$LINENO]+'
5
6export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
7export LD_LIBRARY_PATH=/mnt/media1/Lib:/mnt/media1/Lib/ExtraLib:/usr/lib
8export FSL_OMX_COMPONENT_REGISTRY="/Sysdata/OpenMaxIL/ComponentRegistry.txt"
9export FSL_OMX_MAX_INDEX_SIZE=1048576
10export MALLOC_CHECK_=0
11
12ulimit -s unlimited
13hwclock -s
14
15alias ls='ls --color=auto'
16alias ll='ls -l --color=auto'
17
18# Start with lorenzo92's safe mode
19SCRIPT="/etc/mods/safe_mode.sh"
20if [ -f $SCRIPT ]
21then
22 /bin/sh $SCRIPT
23 # it returns 1 if usb was connected
24 if [ "$?" = "1" ]
25 then
26 sync
27 sleep 1
28 reboot
29 fi
30fi
31
32if [ -e "/mnt/media1/r0" ]
33then
34 MAINFILE="/mnt/media1/r0"
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
46 MAINFILE="/usr/local/bin/r0"
47fi
48
49# source the rockbox loader script
50SOURCE="/mnt/media0/.rockbox/rockbox.sh"
51[ -f $SOURCE ] && . $SOURCE
52
53# source user script if available
54SOURCE="/mnt/media0/rc.user"
55[ -f $SOURCE ] && . $SOURCE
56
57# finally call the entry point
58if [ -e $MAINFILE ]
59then
60 chmod 777 $MAINFILE
61 $MAINFILE Application AppMain
62 rm -f /mnt/media1/r0_media0
63 sync
64# sleep 5
65 reboot
66fi
diff --git a/utils/ypr0tools/pack-firmware.sh b/utils/ypr0tools/pack-firmware.sh
new file mode 100755
index 0000000000..f3b55548d9
--- /dev/null
+++ b/utils/ypr0tools/pack-firmware.sh
@@ -0,0 +1,132 @@
1#!/bin/bash
2
3######################################################################
4# __________ __ ___.
5# Open \______ \ ____ ____ | | _\_ |__ _______ ___
6# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
7# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
8# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9# \/ \/ \/ \/ \/
10#
11# * Script to generate a Samsung YP-R0 firmware file (R0.ROM) */
12######################################################################
13#
14# This file was oringally called NewPack.sh, its origin is the R0 open source
15# package from Samsung.
16#
17# Muon Platform
18# Copyright (c) 2004-2009 Samsung Electronics, Inc.
19# All rights reserved.
20#
21# Rom Packaging Script
22# It needs sudoer privilege of rm, mkdir, cp, mkcramfs.
23# You can configure it in the /etc/sudoer file.
24# This script is very dangerous. Be careful to use.
25#
26# SangMan Sim<sangman.sim@samsung.com>
27
28# bail out early
29set -e
30
31DIR=${2:-"."}
32DIR=${DIR%/}
33REVISION="$DIR/RevisionInfo.txt"
34CRAMFS="$DIR/cramfs-fsl.rom"
35SYSDATA="$DIR/SYSDATA.bin"
36MBOOT="$DIR/MBoot.bin"
37MBOOT_TMP="${TMP_DIR:-$DIR}/MBoot.tmp"
38LINUX="$DIR/zImage"
39R0ROM=$1
40
41# some sanity checks
42if [ $# -lt 1 ] || [ $# -gt 2 ]; then
43 echo "Usage $0 <rom file> [path to image files]"
44 exit 1
45fi
46
47if [ ! -f ./MuonEncrypt ]; then
48 echo "Couldn't find MuonEncrypt binary (try 'make')"
49 exit 1
50fi
51
52if [ ! -e $REVISION ]; then
53 cat >$REVISION <<EOF
54Version : V2.30
55Target : KR
56EOF
57fi
58
59
60function WriteImage {
61 echo "Adding $1 to $R0ROM"
62 #HEAD_STR=[`stat -c%s $1`/`md5sum $1 | cut -d " " -f 1`]
63 #HEAD_SIZE=`echo $HEAD_STR | wc -c`
64 #PACK_SIZE=`expr 44 - $HEAD_SIZE`
65
66 #while [ $PACK_SIZE -gt 0 ]
67 #do
68 #PACK_SIZE=`expr $PACK_SIZE - 1`
69 #echo -n 0
70 #done
71
72 ./MuonEncrypt $1 >> $R0ROM
73 #cat $MBOOT >> $R0ROM
74}
75
76function Pack4Byte {
77 FILE_SIZE=`stat -c%s $R0ROM`
78 PACK_SIZE=`expr 4 - $FILE_SIZE % 4`
79
80 if [ $PACK_SIZE != 4 ]
81 then
82 while [ $PACK_SIZE -gt 0 ]
83 do
84 PACK_SIZE=`expr $PACK_SIZE - 1` || true
85 echo -en $1 >> $R0ROM
86 done
87 fi
88
89}
90
91echo Make $R0ROM
92
93cat $REVISION > $R0ROM
94echo User : $USER >> $R0ROM
95echo Dir : $PWD >> $R0ROM
96echo BuildTime : `date "+%y/%m/%d %H:%M:%S"` >> $R0ROM
97echo MBoot : size\(`stat -c%s $MBOOT`\),checksum\(`md5sum $MBOOT | cut -d " " -f 1`\) >> $R0ROM
98echo Linux : size\(`stat -c%s $LINUX`\),checksum\(`md5sum $LINUX | cut -d " " -f 1`\) >> $R0ROM
99echo RootFS : size\(`stat -c%s $CRAMFS`\),checksum\(`md5sum $CRAMFS | cut -d " " -f 1`\) >> $R0ROM
100echo Sysdata : size\(`stat -c%s $SYSDATA`\),checksum\(`md5sum $SYSDATA | cut -d " " -f 1`\) >> $R0ROM
101
102Pack4Byte "\\n"
103
104
105dd if=$MBOOT of=$MBOOT_TMP bs=96 count=1 2> /dev/null
106
107echo `stat -c%s $MBOOT`:`md5sum $MBOOT | cut -d " " -f 1` >> $MBOOT_TMP
108echo `stat -c%s $LINUX`:`md5sum $LINUX | cut -d " " -f 1` >> $MBOOT_TMP
109echo `stat -c%s $CRAMFS`:`md5sum $CRAMFS | cut -d " " -f 1` >> $MBOOT_TMP
110echo `stat -c%s $SYSDATA`:`md5sum $SYSDATA | cut -d " " -f 1` >> $MBOOT_TMP
111
112dd if=$MBOOT of=$MBOOT_TMP bs=1088 skip=1 seek=1 2> /dev/null
113WriteImage $MBOOT_TMP
114
115#rm $MBOOT_TMP
116
117Pack4Byte "0"
118
119WriteImage $LINUX
120
121Pack4Byte "0"
122
123WriteImage $CRAMFS
124
125Pack4Byte "0"
126
127WriteImage $SYSDATA
128
129echo $R0ROM : `stat -c%s $R0ROM`, `md5sum $R0ROM | cut -d " " -f 1`
130#head -9 $R0ROM
131
132echo "Done"
diff --git a/utils/ypr0tools/patch-firmware.sh b/utils/ypr0tools/patch-firmware.sh
new file mode 100755
index 0000000000..879b3f879d
--- /dev/null
+++ b/utils/ypr0tools/patch-firmware.sh
@@ -0,0 +1,67 @@
1#!/bin/sh
2
3
4######################################################################
5# __________ __ ___.
6# Open \______ \ ____ ____ | | _\_ |__ _______ ___
7# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
8# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
9# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10# \/ \/ \/ \/ \/
11#
12# * Script to patch an unpacked Samsung YP-R0 firmware file */
13# Copyright (C) 2011 Thomas Martitz
14######################################################################
15# bail out early
16set -e
17
18if [ $# -lt 1 ] || [ $# -gt 2 ]; then
19 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 "\tonly the files to overwrite (plain cp -r is used)"
22 exit 1
23fi
24
25FILES=${1%/}
26FILES=${FILES:-"/"}
27DIR=${2:-"."}
28DIR=${DIR%/}
29ROOTFS=$DIR/rootfs
30CRAMFS=$DIR/cramfs-fsl.rom
31
32# sanity checks
33
34# this needs to be run as root!
35if [ $(whoami) != "root" ]
36then
37 echo "This needs to be run as root"
38 exit 1
39fi
40
41if [ ! -e $1 ] || [ ! -e $2 ]; then
42 echo "$1 or $2 does not exist"
43 exit 1
44fi
45
46if [ -z $ROOTFS ] || [ -z $FILES ]; then
47 echo "Invalid input directories"
48 exit 1
49fi
50
51if [ ! -e $CRAMFS ]; then
52 echo "Cramfs image not found (did you extract the firmware?)"
53 exit 1
54fi
55
56echo "Extracting cramfs image"
57
58[ ! -e $ROOTFS ] || rmdir -p $ROOTFS
59cramfs-1.1/cramfsck -x $ROOTFS $CRAMFS
60
61echo "Patching rootfs"
62echo "cp -r $FILES/* $ROOTFS/"
63cp -r $FILES/.rockbox $ROOTFS/
64cp -r $FILES/* $ROOTFS/
65
66echo "Packing new cramfs image"
67cramfs-1.1/mkcramfs $ROOTFS $CRAMFS
diff --git a/utils/ypr0tools/rockbox.sh b/utils/ypr0tools/rockbox.sh
new file mode 100755
index 0000000000..cbe54fd223
--- /dev/null
+++ b/utils/ypr0tools/rockbox.sh
@@ -0,0 +1,47 @@
1#!/bin/sh
2######################################################################
3# __________ __ ___.
4# Open \______ \ ____ ____ | | _\_ |__ _______ ___
5# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8# \/ \/ \/ \/ \/
9#
10# * Samsung YP-R0 Rockbox as an application loader *
11# Lorenzo Miori (C) 2011
12######################################################################
13
14# This is expected to be sourced by the shell, which is then
15# expected to run $MAINFILE
16
17# Check for menu button being pressed. Return immediately to launch the OF
18var=$(dd if=/dev/r0Btn bs=4 count=1)
19# Here a workaround to detect the byte
20var2=$(echo -e -n "\x07")
21
22if [[ "$var" = "$var2" ]]
23then
24 return
25fi
26
27
28# Blank-Unblank video to get rid of Samsung BootLogo, but turn off backlight before to hide these things :)
29echo -n "0" > /sys/devices/platform/afe.0/bli
30echo -n "1" > /sys/class/graphics/fb0/blank
31echo -n "0" >> /sys/class/graphics/fb0/blank
32
33amixer sset 'Soft Mute' 0
34amixer sset 'Master' 85%
35
36# We set-up various settings for the cpu governor: default are
37# Every 1,5 s the kernel evaluates if it's the case to down/up clocking the cpu
38echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
39echo "1" > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/ignore_nice_load
40echo "150000" > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate
41echo "95" > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold
42
43# bind these two to the root so that they're writable
44mount --bind /mnt/media0/.rockbox /.rockbox
45mount --bind /mnt/media0/Playlists /Playlists
46
47MAINFILE="/mnt/media0/.rockbox/rockbox"
diff --git a/utils/ypr0tools/unpack-firmware.sh b/utils/ypr0tools/unpack-firmware.sh
new file mode 100755
index 0000000000..ab80670c79
--- /dev/null
+++ b/utils/ypr0tools/unpack-firmware.sh
@@ -0,0 +1,90 @@
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
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