2014-02-02 16:48:18 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 INRIA
|
|
|
|
*
|
|
|
|
* The source code is licensed under the LGPLv2 license,
|
|
|
|
* See the file LICENSE for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup boards
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief msba2 common config module functions
|
|
|
|
*
|
2014-02-03 00:47:38 +01:00
|
|
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
2014-02-02 16:48:18 +01:00
|
|
|
* @author Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-12-01 16:26:48 +01:00
|
|
|
#include <stdint.h>
|
2010-12-06 17:17:19 +01:00
|
|
|
#include <string.h>
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "flashrom.h"
|
2010-12-01 16:26:48 +01:00
|
|
|
|
2013-09-19 16:53:35 +02:00
|
|
|
void config_load(void) {
|
2010-12-06 13:19:31 +01:00
|
|
|
extern char configmem[];
|
2012-01-05 17:42:44 +01:00
|
|
|
/* cast it here for strict-aliasing */
|
2013-09-19 16:53:35 +02:00
|
|
|
uint16_t* tmp = (uint16_t*) configmem;
|
2012-01-05 17:42:44 +01:00
|
|
|
if (*tmp == CONFIG_KEY) {
|
|
|
|
memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
config_save();
|
|
|
|
}
|
2010-12-06 13:19:31 +01:00
|
|
|
}
|
|
|
|
|
2013-09-19 16:53:35 +02:00
|
|
|
uint8_t config_save(void) {
|
2010-12-01 16:26:48 +01:00
|
|
|
configmem_t mem = { CONFIG_KEY, sysconfig };
|
2013-09-19 16:53:35 +02:00
|
|
|
return (flashrom_erase((uint8_t*) &configmem) && flashrom_write((uint8_t*) &configmem, (char*) &mem, sizeof(mem)));
|
2010-12-01 16:26:48 +01:00
|
|
|
}
|