Correct DEV_TIMING for CPUFREQ_DEFAULT. Was changed by fault in former power manageme...
[kugel-rb.git] / firmware / eeprom_settings.c
blobf3be2ec2b397bcddb6db9b99b503e4e94e49b1ce
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Miika Pekkarinen
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "eeprom_settings.h"
21 #include "eeprom_24cxx.h"
22 #include "crc32.h"
24 #include "system.h"
25 #include "string.h"
26 #include "logf.h"
28 struct eeprom_settings firmware_settings;
30 static bool reset_config(void)
32 memset(&firmware_settings, 0, sizeof(struct eeprom_settings));
33 #ifdef BOOTLOADER
34 /* Don't reset settings if we are inside bootloader. */
35 firmware_settings.initialized = false;
36 #else
37 firmware_settings.version = EEPROM_SETTINGS_VERSION;
38 firmware_settings.initialized = true;
39 firmware_settings.bootmethod = BOOT_RECOVERY;
40 firmware_settings.bl_version = 0;
41 #endif
43 return firmware_settings.initialized;
46 bool eeprom_settings_init(void)
48 int ret;
49 uint32_t sum;
51 eeprom_24cxx_init();
53 /* Check if player has been flashed. */
54 if (detect_original_firmware())
56 memset(&firmware_settings, 0, sizeof(struct eeprom_settings));
57 firmware_settings.initialized = false;
58 logf("Rockbox in flash is required");
59 return false;
62 ret = eeprom_24cxx_read(0, &firmware_settings,
63 sizeof(struct eeprom_settings));
65 if (ret < 0)
67 memset(&firmware_settings, 0, sizeof(struct eeprom_settings));
68 firmware_settings.initialized = false;
69 return false;
72 sum = crc_32(&firmware_settings, sizeof(struct eeprom_settings)-4,
73 0xffffffff);
75 logf("BL version: %d", firmware_settings.bl_version);
76 if (firmware_settings.version != EEPROM_SETTINGS_VERSION)
78 logf("Version mismatch");
79 return reset_config();
82 if (firmware_settings.checksum != sum)
84 logf("Checksum mismatch");
85 return reset_config();
88 #ifndef BOOTLOADER
89 if (firmware_settings.bl_version < EEPROM_SETTINGS_BL_MINVER)
91 logf("Too old bootloader: %d", firmware_settings.bl_version);
92 return reset_config();
94 #endif
96 return true;
99 bool eeprom_settings_store(void)
101 int ret;
102 uint32_t sum;
104 if (!firmware_settings.initialized || detect_original_firmware())
106 logf("Rockbox in flash is required");
107 return false;
110 /* Update the checksum. */
111 sum = crc_32(&firmware_settings, sizeof(struct eeprom_settings)-4,
112 0xffffffff);
113 firmware_settings.checksum = sum;
114 ret = eeprom_24cxx_write(0, &firmware_settings,
115 sizeof(struct eeprom_settings));
117 if (ret < 0)
118 firmware_settings.initialized = false;
120 return ret;