Android: Fix black display after unzipping libmisc.so.
[kugel-rb.git] / firmware / eeprom_settings.c
blob6972edf2c53d30e39798935be17eb4be72e154b1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Miika Pekkarinen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "eeprom_settings.h"
23 #include "eeprom_24cxx.h"
24 #include "crc32.h"
26 #include "system.h"
27 #include "string.h"
28 #include "logf.h"
30 struct eeprom_settings firmware_settings;
32 static bool reset_config(void)
34 memset(&firmware_settings, 0, sizeof(struct eeprom_settings));
35 #ifdef BOOTLOADER
36 /* Don't reset settings if we are inside bootloader. */
37 firmware_settings.initialized = false;
38 #else
39 firmware_settings.version = EEPROM_SETTINGS_VERSION;
40 firmware_settings.initialized = true;
41 firmware_settings.bootmethod = BOOT_RECOVERY;
42 firmware_settings.bl_version = 0;
43 #endif
45 return firmware_settings.initialized;
48 bool eeprom_settings_init(void)
50 int ret;
51 uint32_t sum;
53 eeprom_24cxx_init();
55 /* Check if player has been flashed. */
56 if (detect_original_firmware())
58 memset(&firmware_settings, 0, sizeof(struct eeprom_settings));
59 firmware_settings.initialized = false;
60 logf("Rockbox in flash is required");
61 return false;
64 ret = eeprom_24cxx_read(0, &firmware_settings,
65 sizeof(struct eeprom_settings));
67 if (ret < 0)
69 memset(&firmware_settings, 0, sizeof(struct eeprom_settings));
70 firmware_settings.initialized = false;
71 return false;
74 sum = crc_32(&firmware_settings, sizeof(struct eeprom_settings)-4,
75 0xffffffff);
77 logf("BL version: %d", firmware_settings.bl_version);
78 if (firmware_settings.version != EEPROM_SETTINGS_VERSION)
80 logf("Version mismatch");
81 return reset_config();
84 if (firmware_settings.checksum != sum)
86 logf("Checksum mismatch");
87 return reset_config();
90 #ifndef BOOTLOADER
91 if (firmware_settings.bl_version < EEPROM_SETTINGS_BL_MINVER)
93 logf("Too old bootloader: %d", firmware_settings.bl_version);
94 return reset_config();
96 #endif
98 return true;
101 bool eeprom_settings_store(void)
103 int ret;
104 uint32_t sum;
106 if (!firmware_settings.initialized || detect_original_firmware())
108 logf("Rockbox in flash is required");
109 return false;
112 /* Update the checksum. */
113 sum = crc_32(&firmware_settings, sizeof(struct eeprom_settings)-4,
114 0xffffffff);
115 firmware_settings.checksum = sum;
116 ret = eeprom_24cxx_write(0, &firmware_settings,
117 sizeof(struct eeprom_settings));
119 if (ret < 0)
120 firmware_settings.initialized = false;
122 return ret;