summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/debug_menu.c18
-rw-r--r--apps/main.c46
-rw-r--r--apps/misc.c25
-rw-r--r--apps/tagcache.c109
-rw-r--r--apps/tagcache.h2
-rw-r--r--apps/tree.c9
6 files changed, 181 insertions, 28 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index 724bab90ab..ce3140be63 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -53,6 +53,8 @@
53#include "tagcache.h" 53#include "tagcache.h"
54#include "lcd-remote.h" 54#include "lcd-remote.h"
55#include "crc32.h" 55#include "crc32.h"
56#include "eeprom_24cxx.h"
57#include "logf.h"
56 58
57#ifdef HAVE_LCD_BITMAP 59#ifdef HAVE_LCD_BITMAP
58#include "widgets.h" 60#include "widgets.h"
@@ -1952,6 +1954,22 @@ bool dbg_save_roms(void)
1952 close(fd); 1954 close(fd);
1953 } 1955 }
1954 system_memory_guard(oldmode); 1956 system_memory_guard(oldmode);
1957
1958#ifdef HAVE_EEPROM
1959 fd = creat("/internal_eeprom.bin", O_WRONLY);
1960 if (fd >= 0)
1961 {
1962 char buf[EEPROM_SIZE];
1963
1964 if (!eeprom_24cxx_read(0, buf, sizeof buf))
1965 gui_syncsplash(HZ*3, true, "Eeprom read failure!");
1966 else
1967 write(fd, buf, sizeof buf);
1968
1969 close(fd);
1970 }
1971#endif
1972
1955 return false; 1973 return false;
1956} 1974}
1957#endif /* CPU */ 1975#endif /* CPU */
diff --git a/apps/main.c b/apps/main.c
index b725d0252f..907e1126cf 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -65,6 +65,7 @@
65#include "lang.h" 65#include "lang.h"
66#include "string.h" 66#include "string.h"
67#include "splash.h" 67#include "splash.h"
68#include "eeprom_settings.h"
68 69
69#if (CONFIG_CODEC == SWCODEC) 70#if (CONFIG_CODEC == SWCODEC)
70#include "playback.h" 71#include "playback.h"
@@ -108,35 +109,30 @@ void app_main(void)
108 browse_root(); 109 browse_root();
109} 110}
110 111
111#ifdef HAVE_DIRCACHE 112int init_dircache(void)
112void init_dircache(void)
113{ 113{
114 int result; 114#ifdef HAVE_DIRCACHE
115 bool clear = false; 115 int result = 0;
116 116
117 dircache_init(); 117 dircache_init();
118 if (global_settings.dircache) 118 if (global_settings.dircache)
119 { 119 {
120 if (global_settings.dircache_size == 0) 120# ifdef HAVE_EEPROM
121 if (firmware_settings.initialized && firmware_settings.disk_clean)
121 { 122 {
122 gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING)); 123 if (dircache_load(DIRCACHE_FILE) == 0)
123 clear = true; 124 return 0;
124 } 125 }
126# endif
125 127
126 result = dircache_build(global_settings.dircache_size); 128 result = dircache_build(global_settings.dircache_size);
127 if (result < 0)
128 gui_syncsplash(0, true, "Failed! Result: %d", result);
129
130 if (clear)
131 {
132 backlight_on();
133 show_logo();
134 }
135 } 129 }
136} 130
131 return result;
137#else 132#else
138# define init_dircache(...) 133 return 0;
139#endif 134#endif
135}
140 136
141void init_tagcache(void) 137void init_tagcache(void)
142{ 138{
@@ -376,6 +372,10 @@ void init(void)
376 } 372 }
377 } 373 }
378 374
375#ifdef HAVE_EEPROM
376 eeprom_settings_init();
377#endif
378
379 settings_calc_config_sector(); 379 settings_calc_config_sector();
380 380
381#if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) 381#if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD)
@@ -395,11 +395,21 @@ void init(void)
395 settings_load(SETTINGS_ALL); 395 settings_load(SETTINGS_ALL);
396 396
397 397
398 init_dircache();
399
398 gui_sync_wps_init(); 400 gui_sync_wps_init();
399 settings_apply(); 401 settings_apply();
400 init_dircache(); 402 //init_dircache();
401 init_tagcache(); 403 init_tagcache();
402 404
405#ifdef HAVE_EEPROM
406 if (firmware_settings.initialized)
407 {
408 /* In case we crash. */
409 firmware_settings.disk_clean = false;
410 eeprom_settings_store();
411 }
412#endif
403 status_init(); 413 status_init();
404 playlist_init(); 414 playlist_init();
405 tree_init(); 415 tree_init();
diff --git a/apps/misc.c b/apps/misc.c
index ff05819a4d..b0c315af98 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -49,6 +49,7 @@
49#include "ata_mmc.h" 49#include "ata_mmc.h"
50#endif 50#endif
51#include "tree.h" 51#include "tree.h"
52#include "eeprom_settings.h"
52 53
53#ifdef HAVE_LCD_BITMAP 54#ifdef HAVE_LCD_BITMAP
54#include "bmp.h" 55#include "bmp.h"
@@ -484,13 +485,6 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
484#else 485#else
485 int i; 486 int i;
486 487
487 if (tagcache_get_commit_step() > 0)
488 {
489 cancel_shutdown();
490 gui_syncsplash(HZ, true, str(LANG_TAGCACHE_BUSY));
491 return false;
492 }
493
494#if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) 488#if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
495 if(!charger_inserted()) 489 if(!charger_inserted())
496#endif 490#endif
@@ -498,11 +492,26 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
498 FOR_NB_SCREENS(i) 492 FOR_NB_SCREENS(i)
499 screens[i].clear_display(); 493 screens[i].clear_display();
500 gui_syncsplash(0, true, str(LANG_SHUTTINGDOWN)); 494 gui_syncsplash(0, true, str(LANG_SHUTTINGDOWN));
495
496 if (!tagcache_prepare_shutdown())
497 {
498 cancel_shutdown();
499 gui_syncsplash(HZ, true, str(LANG_TAGCACHE_BUSY));
500 return false;
501 }
502
501 if (callback != NULL) 503 if (callback != NULL)
502 callback(parameter); 504 callback(parameter);
503 505
504 system_flush(); 506 system_flush();
505 507#ifdef HAVE_EEPROM
508 if (firmware_settings.initialized)
509 {
510 firmware_settings.disk_clean = true;
511 firmware_settings.bl_version = 0;
512 eeprom_settings_store();
513 }
514#endif
506 shutdown_hw(); 515 shutdown_hw();
507 } 516 }
508#endif 517#endif
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 1485ed8e51..4812198167 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -70,6 +70,7 @@
70#include "buffer.h" 70#include "buffer.h"
71#include "atoi.h" 71#include "atoi.h"
72#include "crc32.h" 72#include "crc32.h"
73#include "eeprom_settings.h"
73 74
74/* Tag Cache thread. */ 75/* Tag Cache thread. */
75static struct event_queue tagcache_queue; 76static struct event_queue tagcache_queue;
@@ -152,6 +153,13 @@ struct ramcache_header {
152 int entry_count[TAG_COUNT]; /* Number of entries in the indices. */ 153 int entry_count[TAG_COUNT]; /* Number of entries in the indices. */
153}; 154};
154 155
156# ifdef HAVE_EEPROM
157struct statefile_header {
158 struct ramcache_header *hdr;
159 struct tagcache_stat stat;
160};
161# endif
162
155/* Pointer to allocated ramcache_header */ 163/* Pointer to allocated ramcache_header */
156static struct ramcache_header *hdr; 164static struct ramcache_header *hdr;
157#endif 165#endif
@@ -2795,6 +2803,85 @@ static bool allocate_tagcache(void)
2795 return true; 2803 return true;
2796} 2804}
2797 2805
2806# ifdef HAVE_EEPROM
2807static bool tagcache_dumpload(void)
2808{
2809 struct statefile_header shdr;
2810 int fd, rc;
2811 long offpos;
2812 int i;
2813
2814 fd = open(TAGCACHE_STATEFILE, O_RDONLY);
2815 if (fd < 0)
2816 {
2817 logf("no tagcache statedump");
2818 return false;
2819 }
2820
2821 /* Check the statefile memory placement */
2822 hdr = buffer_alloc(0);
2823 rc = read(fd, &shdr, sizeof(struct statefile_header));
2824 if (rc != sizeof(struct statefile_header)
2825 /* || (long)hdr != (long)shdr.hdr */)
2826 {
2827 logf("incorrect statefile");
2828 hdr = NULL;
2829 close(fd);
2830 return false;
2831 }
2832
2833 offpos = (long)hdr - (long)shdr.hdr;
2834
2835 /* Lets allocate real memory and load it */
2836 hdr = buffer_alloc(shdr.stat.ramcache_allocated);
2837 rc = read(fd, hdr, shdr.stat.ramcache_allocated);
2838 close(fd);
2839
2840 if (rc != shdr.stat.ramcache_allocated)
2841 {
2842 logf("read failure!");
2843 hdr = NULL;
2844 return false;
2845 }
2846
2847 memcpy(&stat, &shdr.stat, sizeof(struct tagcache_stat));
2848
2849 /* Now fix the pointers */
2850 hdr->indices = (struct index_entry *)((long)hdr->indices + offpos);
2851 for (i = 0; i < TAG_COUNT; i++)
2852 hdr->tags[i] += offpos;
2853
2854 return true;
2855}
2856
2857static bool tagcache_dumpsave(void)
2858{
2859 struct statefile_header shdr;
2860 int fd;
2861
2862 if (!stat.ramcache)
2863 return false;
2864
2865 fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC);
2866 if (fd < 0)
2867 {
2868 logf("failed to create a statedump");
2869 return false;
2870 }
2871
2872 /* Create the header */
2873 shdr.hdr = hdr;
2874 memcpy(&shdr.stat, &stat, sizeof(struct tagcache_stat));
2875 write(fd, &shdr, sizeof(struct statefile_header));
2876
2877 /* And dump the data too */
2878 write(fd, hdr, stat.ramcache_allocated);
2879 close(fd);
2880
2881 return true;
2882}
2883# endif
2884
2798static bool load_tagcache(void) 2885static bool load_tagcache(void)
2799{ 2886{
2800 struct tagcache_header *tch; 2887 struct tagcache_header *tch;
@@ -3250,8 +3337,15 @@ static void tagcache_thread(void)
3250 free_tempbuf(); 3337 free_tempbuf();
3251 3338
3252#ifdef HAVE_TC_RAMCACHE 3339#ifdef HAVE_TC_RAMCACHE
3340# ifdef HAVE_EEPROM
3341 if (firmware_settings.initialized && firmware_settings.disk_clean)
3342 check_done = tagcache_dumpload();
3343
3344 remove(TAGCACHE_STATEFILE);
3345# endif
3346
3253 /* Allocate space for the tagcache if found on disk. */ 3347 /* Allocate space for the tagcache if found on disk. */
3254 if (global_settings.tagcache_ram) 3348 if (global_settings.tagcache_ram && !stat.ramcache)
3255 allocate_tagcache(); 3349 allocate_tagcache();
3256#endif 3350#endif
3257 3351
@@ -3330,6 +3424,19 @@ static void tagcache_thread(void)
3330 } 3424 }
3331} 3425}
3332 3426
3427bool tagcache_prepare_shutdown(void)
3428{
3429 if (tagcache_get_commit_step() > 0)
3430 return false;
3431
3432#ifdef HAVE_EEPROM
3433 if (stat.ramcache)
3434 tagcache_dumpsave();
3435#endif
3436
3437 return true;
3438}
3439
3333static int get_progress(void) 3440static int get_progress(void)
3334{ 3441{
3335 int total_count = -1; 3442 int total_count = -1;
diff --git a/apps/tagcache.h b/apps/tagcache.h
index 450c21c26e..d5ce772904 100644
--- a/apps/tagcache.h
+++ b/apps/tagcache.h
@@ -64,6 +64,7 @@ enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title,
64#define TAGCACHE_FILE_MASTER ROCKBOX_DIR "/tagcache_idx.tcd" 64#define TAGCACHE_FILE_MASTER ROCKBOX_DIR "/tagcache_idx.tcd"
65#define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/tagcache_%d.tcd" 65#define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/tagcache_%d.tcd"
66#define TAGCACHE_FILE_CHANGELOG ROCKBOX_DIR "/tagcache_changelog.txt" 66#define TAGCACHE_FILE_CHANGELOG ROCKBOX_DIR "/tagcache_changelog.txt"
67#define TAGCACHE_STATEFILE ROCKBOX_DIR "/tagcache_state.tcd"
67 68
68/* Flags */ 69/* Flags */
69#define FLAG_DELETED 0x0001 /* Entry has been removed from db */ 70#define FLAG_DELETED 0x0001 /* Entry has been removed from db */
@@ -149,6 +150,7 @@ bool tagcache_modify_numeric_entry(struct tagcache_search *tcs,
149 150
150struct tagcache_stat* tagcache_get_stat(void); 151struct tagcache_stat* tagcache_get_stat(void);
151int tagcache_get_commit_step(void); 152int tagcache_get_commit_step(void);
153bool tagcache_prepare_shutdown(void);
152 154
153#ifdef HAVE_TC_RAMCACHE 155#ifdef HAVE_TC_RAMCACHE
154bool tagcache_is_ramcache(void); 156bool tagcache_is_ramcache(void);
diff --git a/apps/tree.c b/apps/tree.c
index 7543ceb3f7..fde4da0e04 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -64,6 +64,7 @@
64#include "tagcache.h" 64#include "tagcache.h"
65#include "yesno.h" 65#include "yesno.h"
66#include "gwps-common.h" 66#include "gwps-common.h"
67#include "eeprom_settings.h"
67 68
68/* gui api */ 69/* gui api */
69#include "list.h" 70#include "list.h"
@@ -1367,8 +1368,13 @@ void tree_flush(void)
1367#ifdef HAVE_DIRCACHE 1368#ifdef HAVE_DIRCACHE
1368 if (global_settings.dircache) 1369 if (global_settings.dircache)
1369 { 1370 {
1370 if (dircache_is_enabled()) 1371# ifdef HAVE_EEPROM
1372 if (dircache_is_enabled() && firmware_settings.initialized)
1373 {
1371 global_settings.dircache_size = dircache_get_cache_size(); 1374 global_settings.dircache_size = dircache_get_cache_size();
1375 dircache_save(DIRCACHE_FILE);
1376 }
1377# endif
1372 dircache_disable(); 1378 dircache_disable();
1373 } 1379 }
1374 else 1380 else
@@ -1382,6 +1388,7 @@ void tree_flush(void)
1382void tree_restore(void) 1388void tree_restore(void)
1383{ 1389{
1384#ifdef HAVE_DIRCACHE 1390#ifdef HAVE_DIRCACHE
1391 remove(DIRCACHE_FILE);
1385 if (global_settings.dircache) 1392 if (global_settings.dircache)
1386 { 1393 {
1387 /* Print "Scanning disk..." to the display. */ 1394 /* Print "Scanning disk..." to the display. */