summaryrefslogtreecommitdiffstats
path: root/firmware/eeprom_settings.c
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-08-05 20:19:10 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-08-05 20:19:10 +0000
commit954b73265404075ec4d379ddea14e626113a8677 (patch)
tree5c6ff0056ebd118aadb896856e7679a41c595cba /firmware/eeprom_settings.c
parent85ba65d2a3fa3d10799efadbe3a33f026bf354df (diff)
downloadrockbox-954b73265404075ec4d379ddea14e626113a8677.tar.gz
rockbox-954b73265404075ec4d379ddea14e626113a8677.tar.bz2
rockbox-954b73265404075ec4d379ddea14e626113a8677.zip
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 'firmware/eeprom_settings.c')
-rw-r--r--firmware/eeprom_settings.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/firmware/eeprom_settings.c b/firmware/eeprom_settings.c
new file mode 100644
index 0000000000..43f519d3fa
--- /dev/null
+++ b/firmware/eeprom_settings.c
@@ -0,0 +1,116 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2006 by Miika Pekkarinen
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "eeprom_settings.h"
+#include "eeprom_24cxx.h"
+#include "crc32.h"
+
+#include "string.h"
+#include "logf.h"
+
+struct eeprom_settings firmware_settings;
+
+static void reset_config(void)
+{
+ memset(&firmware_settings, 0, sizeof(struct eeprom_settings));
+ firmware_settings.version = EEPROM_SETTINGS_VERSION;
+ firmware_settings.initialized = true;
+ firmware_settings.boot_disk = false;
+ firmware_settings.bl_version = 0;
+}
+
+bool eeprom_settings_init(void)
+{
+ bool ret;
+ uint32_t sum;
+
+ eeprom_24cxx_init();
+
+ /* Check if player has been flashed. */
+ if (!detect_flashed_rockbox())
+ {
+ memset(&firmware_settings, 0, sizeof(struct eeprom_settings));
+ firmware_settings.initialized = false;
+ logf("Rockbox in flash is required");
+ return false;
+ }
+
+ ret = eeprom_24cxx_read(0, &firmware_settings,
+ sizeof(struct eeprom_settings));
+
+ if (!ret)
+ {
+ memset(&firmware_settings, 0, sizeof(struct eeprom_settings));
+ firmware_settings.initialized = false;
+ return false;
+ }
+
+ sum = crc_32(&firmware_settings, sizeof(struct eeprom_settings)-4,
+ 0xffffffff);
+
+ if (firmware_settings.checksum != sum)
+ {
+ logf("Checksum mismatch");
+ reset_config();
+ return true;
+ }
+
+ if (firmware_settings.version != EEPROM_SETTINGS_VERSION)
+ {
+ logf("Version mismatch");
+ reset_config();
+ return true;
+ }
+
+#ifndef BOOTLOADER
+ if (firmware_settings.bl_version < EEPROM_SETTINGS_BL_MINVER)
+ {
+ logf("Too old bootloader: %d", firmware_settings.bl_version);
+ reset_config();
+ return true;
+ }
+#endif
+
+ return true;
+}
+
+bool eeprom_settings_store(void)
+{
+ bool ret;
+ uint32_t sum;
+
+ if (!firmware_settings.initialized || !detect_flashed_rockbox())
+ {
+ logf("Rockbox in flash is required");
+ return false;
+ }
+
+ /* Update the checksum. */
+ sum = crc_32(&firmware_settings, sizeof(struct eeprom_settings)-4,
+ 0xffffffff);
+ firmware_settings.checksum = sum;
+ ret = eeprom_24cxx_write(0, &firmware_settings,
+ sizeof(struct eeprom_settings));
+
+ if (!ret)
+ firmware_settings.initialized = false;
+
+ return ret;
+}
+