diff options
| author | Miika Pekkarinen <miipekk@ihme.org> | 2006-08-05 20:19:10 +0000 |
|---|---|---|
| committer | Miika Pekkarinen <miipekk@ihme.org> | 2006-08-05 20:19:10 +0000 |
| commit | 954b73265404075ec4d379ddea14e626113a8677 (patch) | |
| tree | 5c6ff0056ebd118aadb896856e7679a41c595cba /apps | |
| parent | 85ba65d2a3fa3d10799efadbe3a33f026bf354df (diff) | |
| download | rockbox-954b73265404075ec4d379ddea14e626113a8677.zip rockbox-954b73265404075ec4d379ddea14e626113a8677.tar.gz rockbox-954b73265404075ec4d379ddea14e626113a8677.tar.bz2 rockbox-954b73265404075ec4d379ddea14e626113a8677.tar.xz | |
Initial support and use for EEPROM memory on H120 & H140 players when
Rockbox firmware has been flashed over original firmware (not yet
possible to do). Dircache & tagcache serialization for fast bootup
without the need to scan disk when Rockbox is in flash.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10464 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/debug_menu.c | 18 | ||||
| -rw-r--r-- | apps/main.c | 46 | ||||
| -rw-r--r-- | apps/misc.c | 25 | ||||
| -rw-r--r-- | apps/tagcache.c | 109 | ||||
| -rw-r--r-- | apps/tagcache.h | 2 | ||||
| -rw-r--r-- | apps/tree.c | 9 |
6 files changed, 181 insertions, 28 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 724bab9..ce3140b 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -53,6 +53,8 @@ #include "tagcache.h" #include "lcd-remote.h" #include "crc32.h" +#include "eeprom_24cxx.h" +#include "logf.h" #ifdef HAVE_LCD_BITMAP #include "widgets.h" @@ -1952,6 +1954,22 @@ bool dbg_save_roms(void) close(fd); } system_memory_guard(oldmode); + +#ifdef HAVE_EEPROM + fd = creat("/internal_eeprom.bin", O_WRONLY); + if (fd >= 0) + { + char buf[EEPROM_SIZE]; + + if (!eeprom_24cxx_read(0, buf, sizeof buf)) + gui_syncsplash(HZ*3, true, "Eeprom read failure!"); + else + write(fd, buf, sizeof buf); + + close(fd); + } +#endif + return false; } #endif /* CPU */ diff --git a/apps/main.c b/apps/main.c index b725d02..907e112 100644 --- a/apps/main.c +++ b/apps/main.c @@ -65,6 +65,7 @@ #include "lang.h" #include "string.h" #include "splash.h" +#include "eeprom_settings.h" #if (CONFIG_CODEC == SWCODEC) #include "playback.h" @@ -108,35 +109,30 @@ void app_main(void) browse_root(); } -#ifdef HAVE_DIRCACHE -void init_dircache(void) +int init_dircache(void) { - int result; - bool clear = false; +#ifdef HAVE_DIRCACHE + int result = 0; dircache_init(); if (global_settings.dircache) { - if (global_settings.dircache_size == 0) +# ifdef HAVE_EEPROM + if (firmware_settings.initialized && firmware_settings.disk_clean) { - gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING)); - clear = true; + if (dircache_load(DIRCACHE_FILE) == 0) + return 0; } +# endif result = dircache_build(global_settings.dircache_size); - if (result < 0) - gui_syncsplash(0, true, "Failed! Result: %d", result); - - if (clear) - { - backlight_on(); - show_logo(); - } } -} + + return result; #else -# define init_dircache(...) + return 0; #endif +} void init_tagcache(void) { @@ -376,6 +372,10 @@ void init(void) } } +#ifdef HAVE_EEPROM + eeprom_settings_init(); +#endif + settings_calc_config_sector(); #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) @@ -395,11 +395,21 @@ void init(void) settings_load(SETTINGS_ALL); + init_dircache(); + gui_sync_wps_init(); settings_apply(); - init_dircache(); + //init_dircache(); init_tagcache(); +#ifdef HAVE_EEPROM + if (firmware_settings.initialized) + { + /* In case we crash. */ + firmware_settings.disk_clean = false; + eeprom_settings_store(); + } +#endif status_init(); playlist_init(); tree_init(); diff --git a/apps/misc.c b/apps/misc.c index ff05819..b0c315a 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -49,6 +49,7 @@ #include "ata_mmc.h" #endif #include "tree.h" +#include "eeprom_settings.h" #ifdef HAVE_LCD_BITMAP #include "bmp.h" @@ -484,13 +485,6 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter) #else int i; - if (tagcache_get_commit_step() > 0) - { - cancel_shutdown(); - gui_syncsplash(HZ, true, str(LANG_TAGCACHE_BUSY)); - return false; - } - #if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) if(!charger_inserted()) #endif @@ -498,11 +492,26 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter) FOR_NB_SCREENS(i) screens[i].clear_display(); gui_syncsplash(0, true, str(LANG_SHUTTINGDOWN)); + + if (!tagcache_prepare_shutdown()) + { + cancel_shutdown(); + gui_syncsplash(HZ, true, str(LANG_TAGCACHE_BUSY)); + return false; + } + if (callback != NULL) callback(parameter); system_flush(); - +#ifdef HAVE_EEPROM + if (firmware_settings.initialized) + { + firmware_settings.disk_clean = true; + firmware_settings.bl_version = 0; + eeprom_settings_store(); + } +#endif shutdown_hw(); } #endif diff --git a/apps/tagcache.c b/apps/tagcache.c index 1485ed8..4812198 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -70,6 +70,7 @@ #include "buffer.h" #include "atoi.h" #include "crc32.h" +#include "eeprom_settings.h" /* Tag Cache thread. */ static struct event_queue tagcache_queue; @@ -152,6 +153,13 @@ struct ramcache_header { int entry_count[TAG_COUNT]; /* Number of entries in the indices. */ }; +# ifdef HAVE_EEPROM +struct statefile_header { + struct ramcache_header *hdr; + struct tagcache_stat stat; +}; +# endif + /* Pointer to allocated ramcache_header */ static struct ramcache_header *hdr; #endif @@ -2795,6 +2803,85 @@ static bool allocate_tagcache(void) return true; } +# ifdef HAVE_EEPROM +static bool tagcache_dumpload(void) +{ + struct statefile_header shdr; + int fd, rc; + long offpos; + int i; + + fd = open(TAGCACHE_STATEFILE, O_RDONLY); + if (fd < 0) + { + logf("no tagcache statedump"); + return false; + } + + /* Check the statefile memory placement */ + hdr = buffer_alloc(0); + rc = read(fd, &shdr, sizeof(struct statefile_header)); + if (rc != sizeof(struct statefile_header) + /* || (long)hdr != (long)shdr.hdr */) + { + logf("incorrect statefile"); + hdr = NULL; + close(fd); + return false; + } + + offpos = (long)hdr - (long)shdr.hdr; + + /* Lets allocate real memory and load it */ + hdr = buffer_alloc(shdr.stat.ramcache_allocated); + rc = read(fd, hdr, shdr.stat.ramcache_allocated); + close(fd); + + if (rc != shdr.stat.ramcache_allocated) + { + logf("read failure!"); + hdr = NULL; + return false; + } + + memcpy(&stat, &shdr.stat, sizeof(struct tagcache_stat)); + + /* Now fix the pointers */ + hdr->indices = (struct index_entry *)((long)hdr->indices + offpos); + for (i = 0; i < TAG_COUNT; i++) + hdr->tags[i] += offpos; + + return true; +} + +static bool tagcache_dumpsave(void) +{ + struct statefile_header shdr; + int fd; + + if (!stat.ramcache) + return false; + + fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC); + if (fd < 0) + { + logf("failed to create a statedump"); + return false; + } + + /* Create the header */ + shdr.hdr = hdr; + memcpy(&shdr.stat, &stat, sizeof(struct tagcache_stat)); + write(fd, &shdr, sizeof(struct statefile_header)); + + /* And dump the data too */ + write(fd, hdr, stat.ramcache_allocated); + close(fd); + + return true; +} +# endif + static bool load_tagcache(void) { struct tagcache_header *tch; @@ -3250,8 +3337,15 @@ static void tagcache_thread(void) free_tempbuf(); #ifdef HAVE_TC_RAMCACHE +# ifdef HAVE_EEPROM + if (firmware_settings.initialized && firmware_settings.disk_clean) + check_done = tagcache_dumpload(); + + remove(TAGCACHE_STATEFILE); +# endif + /* Allocate space for the tagcache if found on disk. */ - if (global_settings.tagcache_ram) + if (global_settings.tagcache_ram && !stat.ramcache) allocate_tagcache(); #endif @@ -3330,6 +3424,19 @@ static void tagcache_thread(void) } } +bool tagcache_prepare_shutdown(void) +{ + if (tagcache_get_commit_step() > 0) + return false; + +#ifdef HAVE_EEPROM + if (stat.ramcache) + tagcache_dumpsave(); +#endif + + return true; +} + static int get_progress(void) { int total_count = -1; diff --git a/apps/tagcache.h b/apps/tagcache.h index 450c21c..d5ce772 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, #define TAGCACHE_FILE_MASTER ROCKBOX_DIR "/tagcache_idx.tcd" #define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/tagcache_%d.tcd" #define TAGCACHE_FILE_CHANGELOG ROCKBOX_DIR "/tagcache_changelog.txt" +#define TAGCACHE_STATEFILE ROCKBOX_DIR "/tagcache_state.tcd" /* Flags */ #define FLAG_DELETED 0x0001 /* Entry has been removed from db */ @@ -149,6 +150,7 @@ bool tagcache_modify_numeric_entry(struct tagcache_search *tcs, struct tagcache_stat* tagcache_get_stat(void); int tagcache_get_commit_step(void); +bool tagcache_prepare_shutdown(void); #ifdef HAVE_TC_RAMCACHE bool tagcache_is_ramcache(void); diff --git a/apps/tree.c b/apps/tree.c index 7543ceb..fde4da0 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -64,6 +64,7 @@ #include "tagcache.h" #include "yesno.h" #include "gwps-common.h" +#include "eeprom_settings.h" /* gui api */ #include "list.h" @@ -1367,8 +1368,13 @@ void tree_flush(void) #ifdef HAVE_DIRCACHE if (global_settings.dircache) { - if (dircache_is_enabled()) +# ifdef HAVE_EEPROM + if (dircache_is_enabled() && firmware_settings.initialized) + { global_settings.dircache_size = dircache_get_cache_size(); + dircache_save(DIRCACHE_FILE); + } +# endif dircache_disable(); } else @@ -1382,6 +1388,7 @@ void tree_flush(void) void tree_restore(void) { #ifdef HAVE_DIRCACHE + remove(DIRCACHE_FILE); if (global_settings.dircache) { /* Print "Scanning disk..." to the display. */ |