1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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"
30 struct eeprom_settings firmware_settings
;
32 static bool reset_config(void)
34 memset(&firmware_settings
, 0, sizeof(struct eeprom_settings
));
36 /* Don't reset settings if we are inside bootloader. */
37 firmware_settings
.initialized
= false;
39 firmware_settings
.version
= EEPROM_SETTINGS_VERSION
;
40 firmware_settings
.initialized
= true;
41 firmware_settings
.bootmethod
= BOOT_RECOVERY
;
42 firmware_settings
.bl_version
= 0;
45 return firmware_settings
.initialized
;
48 bool eeprom_settings_init(void)
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");
64 ret
= eeprom_24cxx_read(0, &firmware_settings
,
65 sizeof(struct eeprom_settings
));
69 memset(&firmware_settings
, 0, sizeof(struct eeprom_settings
));
70 firmware_settings
.initialized
= false;
74 sum
= crc_32(&firmware_settings
, sizeof(struct eeprom_settings
)-4,
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();
91 if (firmware_settings
.bl_version
< EEPROM_SETTINGS_BL_MINVER
)
93 logf("Too old bootloader: %d", firmware_settings
.bl_version
);
94 return reset_config();
101 bool eeprom_settings_store(void)
106 if (!firmware_settings
.initialized
|| detect_original_firmware())
108 logf("Rockbox in flash is required");
112 /* Update the checksum. */
113 sum
= crc_32(&firmware_settings
, sizeof(struct eeprom_settings
)-4,
115 firmware_settings
.checksum
= sum
;
116 ret
= eeprom_24cxx_write(0, &firmware_settings
,
117 sizeof(struct eeprom_settings
));
120 firmware_settings
.initialized
= false;