From c4a59a290b81cae137f8b3c2b709c9c565701eb9 Mon Sep 17 00:00:00 2001 From: Peter D'Hoye Date: Tue, 15 Aug 2006 22:54:06 +0000 Subject: eeprom driver for the h3x0 series, cleaned up the h1x0 series driver a bit, added debug entry for h3x0 that allows to write to the eeprom git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10597 a1c6a512-1295-4272-9138-f99709370657 --- apps/debug_menu.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++---- apps/main.c | 8 ++++---- apps/misc.c | 2 +- apps/tagcache.c | 8 ++++---- apps/tree.c | 4 ++-- 5 files changed, 67 insertions(+), 15 deletions(-) (limited to 'apps') diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 0141c77fbe..1527e8abe7 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -1891,13 +1891,22 @@ bool dbg_save_roms(void) fd = creat("/internal_eeprom.bin", O_WRONLY); if (fd >= 0) { + int old_irq_level; char buf[EEPROM_SIZE]; - - if (eeprom_24cxx_read(0, buf, sizeof buf)) - gui_syncsplash(HZ*3, true, "Eeprom read failure!"); + int err; + + old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL); + + err = eeprom_24cxx_read(0, buf, sizeof buf); + if (err) + gui_syncsplash(HZ*3, true, "Eeprom read failure (%d)",err); else + { write(fd, buf, sizeof buf); - + } + + set_irq_level(old_irq_level); + close(fd); } #endif @@ -1976,6 +1985,46 @@ bool dbg_set_memory_guard(void) } #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */ +#if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) +bool dbg_write_eeprom(void) +{ + int fd; + int rc; + int old_irq_level; + char buf[EEPROM_SIZE]; + int err; + + fd = open("/internal_eeprom.bin", O_RDONLY); + + if (fd >= 0) + { + rc = read(fd, buf, EEPROM_SIZE); + + if(rc == EEPROM_SIZE) + { + old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL); + + err = eeprom_24cxx_write(0, buf, sizeof buf); + if (err) + gui_syncsplash(HZ*3, true, "Eeprom write failure (%d)",err); + + set_irq_level(old_irq_level); + } + else + { + gui_syncsplash(HZ*3, true, "File read error (%d)",rc); + } + close(fd); + } + else + { + gui_syncsplash(HZ*3, true, "Failed to open 'internal_eeprom.bin'"); + } + + return false; +} +#endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */ + bool debug_menu(void) { int m; @@ -2023,6 +2072,9 @@ bool debug_menu(void) #ifdef CONFIG_TUNER { "FM Radio", dbg_fm_radio }, #endif +#if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) + { "Write back EEPROM", dbg_write_eeprom }, +#endif #ifdef ROCKBOX_HAS_LOGF {"logf", logfdisplay }, {"logfdump", logfdump }, diff --git a/apps/main.c b/apps/main.c index c50af865fc..90bd13ee32 100644 --- a/apps/main.c +++ b/apps/main.c @@ -120,7 +120,7 @@ int init_dircache(bool preinit) if (global_settings.dircache) { -# ifdef HAVE_EEPROM +# ifdef HAVE_EEPROM_SETTINGS if (firmware_settings.initialized && firmware_settings.disk_clean && preinit) { @@ -371,14 +371,14 @@ void init(void) panicf("ata: %d", rc); } -#ifdef HAVE_EEPROM +#ifdef HAVE_EEPROM_SETTINGS eeprom_settings_init(); #endif usb_start_monitoring(); while (usb_detect()) { -#ifdef HAVE_EEPROM +#ifdef HAVE_EEPROM_SETTINGS firmware_settings.disk_clean = false; #endif /* enter USB mode early, before trying to mount */ @@ -444,7 +444,7 @@ void init(void) init_dircache(false); init_tagcache(); -#ifdef HAVE_EEPROM +#ifdef HAVE_EEPROM_SETTINGS if (firmware_settings.initialized) { /* In case we crash. */ diff --git a/apps/misc.c b/apps/misc.c index ffacf7ed82..19cee60993 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -507,7 +507,7 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter) callback(parameter); system_flush(); -#ifdef HAVE_EEPROM +#ifdef HAVE_EEPROM_SETTINGS if (firmware_settings.initialized) { firmware_settings.disk_clean = true; diff --git a/apps/tagcache.c b/apps/tagcache.c index 179218ab1f..191c245597 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -153,7 +153,7 @@ struct ramcache_header { int entry_count[TAG_COUNT]; /* Number of entries in the indices. */ }; -# ifdef HAVE_EEPROM +# ifdef HAVE_EEPROM_SETTINGS struct statefile_header { struct ramcache_header *hdr; struct tagcache_stat stat; @@ -2829,7 +2829,7 @@ static bool allocate_tagcache(void) return true; } -# ifdef HAVE_EEPROM +# ifdef HAVE_EEPROM_SETTINGS static bool tagcache_dumpload(void) { struct statefile_header shdr; @@ -3370,7 +3370,7 @@ static void tagcache_thread(void) free_tempbuf(); #ifdef HAVE_TC_RAMCACHE -# ifdef HAVE_EEPROM +# ifdef HAVE_EEPROM_SETTINGS if (firmware_settings.initialized && firmware_settings.disk_clean) check_done = tagcache_dumpload(); @@ -3462,7 +3462,7 @@ bool tagcache_prepare_shutdown(void) if (tagcache_get_commit_step() > 0) return false; -#ifdef HAVE_EEPROM +#ifdef HAVE_EEPROM_SETTINGS if (stat.ramcache) tagcache_dumpsave(); #endif diff --git a/apps/tree.c b/apps/tree.c index 1bbb5f8ca3..75562b30c8 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -1336,7 +1336,7 @@ void tree_flush(void) if (global_settings.dircache) { global_settings.dircache_size = dircache_get_cache_size(); -# ifdef HAVE_EEPROM +# ifdef HAVE_EEPROM_SETTINGS if (dircache_is_enabled() && firmware_settings.initialized) dircache_save(DIRCACHE_FILE); # endif @@ -1352,7 +1352,7 @@ void tree_flush(void) void tree_restore(void) { -#ifdef HAVE_EEPROM +#ifdef HAVE_EEPROM_SETTINGS firmware_settings.disk_clean = false; #endif -- cgit v1.2.3