1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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"
28 struct eeprom_settings firmware_settings
;
30 static bool reset_config(void)
32 memset(&firmware_settings
, 0, sizeof(struct eeprom_settings
));
34 /* Don't reset settings if we are inside bootloader. */
35 firmware_settings
.initialized
= false;
37 firmware_settings
.version
= EEPROM_SETTINGS_VERSION
;
38 firmware_settings
.initialized
= true;
39 firmware_settings
.boot_disk
= false;
40 firmware_settings
.bl_version
= 0;
43 return firmware_settings
.initialized
;
46 bool eeprom_settings_init(void)
53 /* Check if player has been flashed. */
54 if (!detect_flashed_rockbox())
56 memset(&firmware_settings
, 0, sizeof(struct eeprom_settings
));
57 firmware_settings
.initialized
= false;
58 logf("Rockbox in flash is required");
62 ret
= eeprom_24cxx_read(0, &firmware_settings
,
63 sizeof(struct eeprom_settings
));
67 memset(&firmware_settings
, 0, sizeof(struct eeprom_settings
));
68 firmware_settings
.initialized
= false;
72 sum
= crc_32(&firmware_settings
, sizeof(struct eeprom_settings
)-4,
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();
89 if (firmware_settings
.bl_version
< EEPROM_SETTINGS_BL_MINVER
)
91 logf("Too old bootloader: %d", firmware_settings
.bl_version
);
92 return reset_config();
99 bool eeprom_settings_store(void)
104 if (!firmware_settings
.initialized
|| !detect_flashed_rockbox())
106 logf("Rockbox in flash is required");
110 /* Update the checksum. */
111 sum
= crc_32(&firmware_settings
, sizeof(struct eeprom_settings
)-4,
113 firmware_settings
.checksum
= sum
;
114 ret
= eeprom_24cxx_write(0, &firmware_settings
,
115 sizeof(struct eeprom_settings
));
118 firmware_settings
.initialized
= false;