+// SPDX-License-Identifier: GPL-2.0+
/*
* (C) Copyright 2000-2010
*
* (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
- *
- * SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <command.h>
-#include <environment.h>
+#include <eeprom.h>
+#include <env.h>
+#include <env_internal.h>
+#include <asm/global_data.h>
#include <linux/stddef.h>
+#include <u-boot/crc.h>
#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
#include <i2c.h>
#endif
return rcode;
}
-/** Call this function from overridden env_get_char_spec() if you need
- * this functionality.
- */
-int env_eeprom_get_char(int index)
-{
- uchar c;
- unsigned int off = CONFIG_ENV_OFFSET;
-
-#ifdef CONFIG_ENV_OFFSET_REDUND
- if (gd->env_valid == ENV_REDUND)
- off = CONFIG_ENV_OFFSET_REDUND;
-#endif
- eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR,
- off + index + offsetof(env_t, data), &c, 1);
-
- return c;
-}
-
static int env_eeprom_load(void)
{
char buf_env[CONFIG_ENV_SIZE];
for (i = 0; i < 2; i++) {
/* read CRC */
- eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR,
+ eeprom_bus_read(CONFIG_SYS_I2C_EEPROM_ADDR,
off_env[i] + offsetof(env_t, crc),
(uchar *)&crc[i], sizeof(ulong));
/* read FLAGS */
- eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR,
+ eeprom_bus_read(CONFIG_SYS_I2C_EEPROM_ADDR,
off_env[i] + offsetof(env_t, flags),
(uchar *)&flags[i], sizeof(uchar));
while (len > 0) {
int n = (len > sizeof(rdbuf)) ? sizeof(rdbuf) : len;
- eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, off,
+ eeprom_bus_read(CONFIG_SYS_I2C_EEPROM_ADDR, off,
rdbuf, n);
crc_tmp = crc32(crc_tmp, rdbuf, n);
gd->env_valid = ENV_REDUND;
} else {
/* both ok - check serial */
- if (flags[0] == ACTIVE_FLAG && flags[1] == OBSOLETE_FLAG)
+ if (flags[0] == ENV_REDUND_ACTIVE &&
+ flags[1] == ENV_REDUND_OBSOLETE)
gd->env_valid = ENV_VALID;
- else if (flags[0] == OBSOLETE_FLAG && flags[1] == ACTIVE_FLAG)
+ else if (flags[0] == ENV_REDUND_OBSOLETE &&
+ flags[1] == ENV_REDUND_ACTIVE)
gd->env_valid = ENV_REDUND;
else if (flags[0] == 0xFF && flags[1] == 0)
gd->env_valid = ENV_REDUND;
eeprom_init(-1); /* prepare for EEPROM read/write */
/* read old CRC */
- eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR,
+ eeprom_bus_read(CONFIG_SYS_I2C_EEPROM_ADDR,
CONFIG_ENV_OFFSET + offsetof(env_t, crc),
(uchar *)&crc, sizeof(ulong));
while (len > 0) {
int n = (len > sizeof(rdbuf)) ? sizeof(rdbuf) : len;
- eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR,
+ eeprom_bus_read(CONFIG_SYS_I2C_EEPROM_ADDR,
CONFIG_ENV_OFFSET + off, rdbuf, n);
new = crc32(new, rdbuf, n);
len -= n;
off = CONFIG_ENV_OFFSET_REDUND;
#endif
- eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR,
+ eeprom_bus_read(CONFIG_SYS_I2C_EEPROM_ADDR,
off, (uchar *)buf_env, CONFIG_ENV_SIZE);
- return env_import(buf_env, 1);
+ return env_import(buf_env, 1, H_EXTERNAL);
}
static int env_eeprom_save(void)
unsigned int off = CONFIG_ENV_OFFSET;
#ifdef CONFIG_ENV_OFFSET_REDUND
unsigned int off_red = CONFIG_ENV_OFFSET_REDUND;
- char flag_obsolete = OBSOLETE_FLAG;
+ char flag_obsolete = ENV_REDUND_OBSOLETE;
#endif
rc = env_export(&env_new);
off_red = CONFIG_ENV_OFFSET;
}
- env_new.flags = ACTIVE_FLAG;
+ env_new.flags = ENV_REDUND_ACTIVE;
#endif
- rc = eeprom_bus_write(CONFIG_SYS_DEF_EEPROM_ADDR,
+ rc = eeprom_bus_write(CONFIG_SYS_I2C_EEPROM_ADDR,
off, (uchar *)&env_new, CONFIG_ENV_SIZE);
#ifdef CONFIG_ENV_OFFSET_REDUND
if (rc == 0) {
- eeprom_bus_write(CONFIG_SYS_DEF_EEPROM_ADDR,
+ eeprom_bus_write(CONFIG_SYS_I2C_EEPROM_ADDR,
off_red + offsetof(env_t, flags),
(uchar *)&flag_obsolete, 1);