2006-08-05 20:19:10 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Miika Pekkarinen
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-08-05 20:19:10 +00:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2006-08-09 12:04:13 +00:00
|
|
|
#include "system.h"
|
2006-08-05 20:19:10 +00:00
|
|
|
#include "string.h"
|
|
|
|
#include "logf.h"
|
|
|
|
|
|
|
|
struct eeprom_settings firmware_settings;
|
|
|
|
|
2006-08-11 10:13:16 +00:00
|
|
|
static bool reset_config(void)
|
2006-08-05 20:19:10 +00:00
|
|
|
{
|
|
|
|
memset(&firmware_settings, 0, sizeof(struct eeprom_settings));
|
2006-08-11 10:13:16 +00:00
|
|
|
#ifdef BOOTLOADER
|
|
|
|
/* Don't reset settings if we are inside bootloader. */
|
|
|
|
firmware_settings.initialized = false;
|
|
|
|
#else
|
2006-08-05 20:19:10 +00:00
|
|
|
firmware_settings.version = EEPROM_SETTINGS_VERSION;
|
|
|
|
firmware_settings.initialized = true;
|
2007-01-12 18:34:00 +00:00
|
|
|
firmware_settings.bootmethod = BOOT_RECOVERY;
|
2006-08-05 20:19:10 +00:00
|
|
|
firmware_settings.bl_version = 0;
|
2006-08-11 10:13:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return firmware_settings.initialized;
|
2006-08-05 20:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool eeprom_settings_init(void)
|
|
|
|
{
|
2006-08-07 22:30:12 +00:00
|
|
|
int ret;
|
2006-08-05 20:19:10 +00:00
|
|
|
uint32_t sum;
|
|
|
|
|
|
|
|
eeprom_24cxx_init();
|
|
|
|
|
|
|
|
/* Check if player has been flashed. */
|
2007-01-12 18:34:00 +00:00
|
|
|
if (detect_original_firmware())
|
2006-08-05 20:19:10 +00:00
|
|
|
{
|
|
|
|
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));
|
2007-01-12 18:34:00 +00:00
|
|
|
|
2006-08-07 22:30:12 +00:00
|
|
|
if (ret < 0)
|
2006-08-05 20:19:10 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2006-08-09 12:04:13 +00:00
|
|
|
logf("BL version: %d", firmware_settings.bl_version);
|
|
|
|
if (firmware_settings.version != EEPROM_SETTINGS_VERSION)
|
2006-08-05 20:19:10 +00:00
|
|
|
{
|
2006-08-09 12:04:13 +00:00
|
|
|
logf("Version mismatch");
|
2006-08-11 10:13:16 +00:00
|
|
|
return reset_config();
|
2006-08-05 20:19:10 +00:00
|
|
|
}
|
|
|
|
|
2006-08-09 12:04:13 +00:00
|
|
|
if (firmware_settings.checksum != sum)
|
2006-08-05 20:19:10 +00:00
|
|
|
{
|
2006-08-09 12:04:13 +00:00
|
|
|
logf("Checksum mismatch");
|
2006-08-11 10:13:16 +00:00
|
|
|
return reset_config();
|
2006-08-05 20:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef BOOTLOADER
|
|
|
|
if (firmware_settings.bl_version < EEPROM_SETTINGS_BL_MINVER)
|
|
|
|
{
|
|
|
|
logf("Too old bootloader: %d", firmware_settings.bl_version);
|
2006-08-11 10:13:16 +00:00
|
|
|
return reset_config();
|
2006-08-05 20:19:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool eeprom_settings_store(void)
|
|
|
|
{
|
2006-08-07 22:30:12 +00:00
|
|
|
int ret;
|
2006-08-05 20:19:10 +00:00
|
|
|
uint32_t sum;
|
|
|
|
|
2007-01-12 18:34:00 +00:00
|
|
|
if (!firmware_settings.initialized || detect_original_firmware())
|
2006-08-05 20:19:10 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
2006-08-07 22:30:12 +00:00
|
|
|
if (ret < 0)
|
2006-08-05 20:19:10 +00:00
|
|
|
firmware_settings.initialized = false;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|