From 3b52bb9c68665c6860c7da6f8ee0b3d8fe26d53d Mon Sep 17 00:00:00 2001 From: Miika Pekkarinen Date: Fri, 11 Aug 2006 10:13:16 +0000 Subject: [PATCH] Properly handle early USB mode, dircache and tagcache state files with flashed rockbox. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10525 a1c6a512-1295-4272-9138-f99709370657 --- apps/main.c | 14 +++++++++----- apps/tagcache.c | 2 +- apps/tree.c | 10 ++++++---- firmware/eeprom_settings.c | 18 +++++++++++------- firmware/system.c | 10 ++++++++++ 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/apps/main.c b/apps/main.c index d590790a85..a3fe8ef64f 100644 --- a/apps/main.c +++ b/apps/main.c @@ -338,9 +338,17 @@ void init(void) panicf("ata: %d", rc); } +#ifdef HAVE_EEPROM + eeprom_settings_init(); +#endif + usb_start_monitoring(); while (usb_detect()) - { /* enter USB mode early, before trying to mount */ + { +#ifdef HAVE_EEPROM + firmware_settings.disk_clean = false; +#endif + /* enter USB mode early, before trying to mount */ if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED) #ifdef HAVE_MMC if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED)) @@ -374,10 +382,6 @@ void init(void) } } -#ifdef HAVE_EEPROM - eeprom_settings_init(); -#endif - settings_calc_config_sector(); #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) diff --git a/apps/tagcache.c b/apps/tagcache.c index 4bcf25bad2..ec713e29a4 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -3300,7 +3300,7 @@ void tagcache_unload_ramcache(void) { stat.ramcache = false; /* Just to make sure there is no statefile present. */ - remove(TAGCACHE_STATEFILE); + // remove(TAGCACHE_STATEFILE); } #endif diff --git a/apps/tree.c b/apps/tree.c index 1dbe9223b9..0dd03779a5 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -1368,16 +1368,14 @@ void tree_flush(void) #ifdef HAVE_TC_RAMCACHE tagcache_unload_ramcache(); #endif - + #ifdef HAVE_DIRCACHE if (global_settings.dircache) { + global_settings.dircache_size = dircache_get_cache_size(); # 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(); } @@ -1395,6 +1393,10 @@ void tree_restore(void) firmware_settings.disk_clean = false; #endif +#ifdef HAVE_TC_RAMCACHE + remove(TAGCACHE_STATEFILE); +#endif + #ifdef HAVE_DIRCACHE remove(DIRCACHE_FILE); if (global_settings.dircache) diff --git a/firmware/eeprom_settings.c b/firmware/eeprom_settings.c index 450eff9623..ad2c9c848f 100644 --- a/firmware/eeprom_settings.c +++ b/firmware/eeprom_settings.c @@ -27,13 +27,20 @@ struct eeprom_settings firmware_settings; -static void reset_config(void) +static bool reset_config(void) { memset(&firmware_settings, 0, sizeof(struct eeprom_settings)); +#ifdef BOOTLOADER + /* Don't reset settings if we are inside bootloader. */ + firmware_settings.initialized = false; +#else firmware_settings.version = EEPROM_SETTINGS_VERSION; firmware_settings.initialized = true; firmware_settings.boot_disk = false; firmware_settings.bl_version = 0; +#endif + + return firmware_settings.initialized; } bool eeprom_settings_init(void) @@ -69,23 +76,20 @@ bool eeprom_settings_init(void) if (firmware_settings.version != EEPROM_SETTINGS_VERSION) { logf("Version mismatch"); - reset_config(); - return true; + return reset_config(); } if (firmware_settings.checksum != sum) { logf("Checksum mismatch"); - reset_config(); - return true; + return reset_config(); } #ifndef BOOTLOADER if (firmware_settings.bl_version < EEPROM_SETTINGS_BL_MINVER) { logf("Too old bootloader: %d", firmware_settings.bl_version); - reset_config(); - return true; + return reset_config(); } #endif diff --git a/firmware/system.c b/firmware/system.c index bb09dbcd59..c635254a8a 100644 --- a/firmware/system.c +++ b/firmware/system.c @@ -84,7 +84,17 @@ bool detect_flashed_rockbox(void) struct flash_header hdr; uint8_t *src = (uint8_t *)FLASH_ENTRYPOINT; +# ifndef BOOTLOADER + int oldmode; + oldmode = system_memory_guard(MEMGUARD_NONE); +# endif + memcpy(&hdr, src, sizeof(struct flash_header)); + +# ifndef BOOTLOADER + system_memory_guard(oldmode); +# endif + if (hdr.magic != FLASH_MAGIC) return false;