- CONFIG_SYS_EEPROM_SIZE:
The size in bytes of the EEPROM device.
+ - CONFIG_ENV_EEPROM_IS_ON_I2C
+ define this, if you have I2C and SPI activated, and your
+ EEPROM, which holds the environment, is on the I2C bus.
+
+ - CONFIG_I2C_ENV_EEPROM_BUS
+ if you have an Environment on an EEPROM reached over
+ I2C muxes, you can define here, how to reach this
+ EEPROM. For example:
+
+ #define CONFIG_I2C_ENV_EEPROM_BUS "pca9547:70:d\0"
+
+ EEPROM which holds the environment, is reached over
+ a pca9547 i2c mux with address 0x70, channel 3.
- CONFIG_ENV_IS_IN_DATAFLASH:
ulong cnt = simple_strtoul (argv[4], NULL, 16);
#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
-# ifndef CONFIG_SPI
+# if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
eeprom_init ();
# endif /* !CONFIG_SPI */
* 0x00000nxx for EEPROM address selectors and page number at n.
*/
-#ifndef CONFIG_SPI
+#if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN) || CONFIG_SYS_I2C_EEPROM_ADDR_LEN < 1 || CONFIG_SYS_I2C_EEPROM_ADDR_LEN > 2
#error CONFIG_SYS_I2C_EEPROM_ADDR_LEN must be 1 or 2
#endif
len = maxlen;
#endif
-#ifdef CONFIG_SPI
+#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
spi_read (addr, alen, buffer, len);
#else
if (i2c_read (addr[0], offset, alen-1, buffer, len) != 0)
len = maxlen;
#endif
-#ifdef CONFIG_SPI
+#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
spi_write (addr, alen, buffer, len);
#else
#if defined(CONFIG_SYS_EEPROM_X40430)
return rcode;
}
-#ifndef CONFIG_SPI
+#if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
int
eeprom_probe (unsigned dev_addr, unsigned offset)
{
void eeprom_init (void)
{
-#if defined(CONFIG_SPI)
+
+#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
spi_init_f ();
#endif
#if defined(CONFIG_HARD_I2C) || \
i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
#endif
}
+
/*-----------------------------------------------------------------------
*/
#include <command.h>
#include <environment.h>
#include <linux/stddef.h>
+#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
+#include <i2c.h>
+#endif
DECLARE_GLOBAL_DATA_PTR;
env_t *env_ptr = NULL;
char * env_name_spec = "EEPROM";
+int env_eeprom_bus = -1;
+
+static int eeprom_bus_read (unsigned dev_addr, unsigned offset, uchar *buffer,
+ unsigned cnt)
+{
+ int rcode;
+#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
+ int old_bus = i2c_get_bus_num();
+
+ if (gd->flags & GD_FLG_RELOC) {
+ if (env_eeprom_bus == -1) {
+ I2C_MUX_DEVICE *dev = NULL;
+ dev = i2c_mux_ident_muxstring(
+ (uchar *)CONFIG_I2C_ENV_EEPROM_BUS);
+ if (dev != NULL) {
+ env_eeprom_bus = dev->busid;
+ } else
+ printf ("error adding env eeprom bus.\n");
+ }
+ if (old_bus != env_eeprom_bus) {
+ i2c_set_bus_num(env_eeprom_bus);
+ old_bus = env_eeprom_bus;
+ }
+ } else {
+ rcode = i2c_mux_ident_muxstring_f(
+ (uchar *)CONFIG_I2C_ENV_EEPROM_BUS);
+ }
+#endif
+
+ rcode = eeprom_read (dev_addr, offset, buffer, cnt);
+#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
+ if (old_bus != env_eeprom_bus)
+ i2c_set_bus_num(old_bus);
+#endif
+ return rcode;
+}
+
+static int eeprom_bus_write (unsigned dev_addr, unsigned offset, uchar *buffer,
+ unsigned cnt)
+{
+ int rcode;
+#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
+ int old_bus = i2c_get_bus_num();
+
+ rcode = i2c_mux_ident_muxstring_f((uchar *)CONFIG_I2C_ENV_EEPROM_BUS);
+#endif
+ rcode = eeprom_write (dev_addr, offset, buffer, cnt);
+#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
+ i2c_set_bus_num(old_bus);
+#endif
+ return rcode;
+}
uchar env_get_char_spec (int index)
{
uchar c;
- eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR,
+ eeprom_bus_read (CONFIG_SYS_DEF_EEPROM_ADDR,
CONFIG_ENV_OFFSET+index+offsetof(env_t,data),
&c, 1);
void env_relocate_spec (void)
{
- eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR,
+ eeprom_bus_read (CONFIG_SYS_DEF_EEPROM_ADDR,
CONFIG_ENV_OFFSET,
(uchar*)env_ptr,
CONFIG_ENV_SIZE);
int saveenv(void)
{
- return eeprom_write (CONFIG_SYS_DEF_EEPROM_ADDR,
+ return eeprom_bus_write (CONFIG_SYS_DEF_EEPROM_ADDR,
CONFIG_ENV_OFFSET,
(uchar *)env_ptr,
CONFIG_ENV_SIZE);
eeprom_init (); /* prepare for EEPROM read/write */
/* read old CRC */
- eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR,
+ eeprom_bus_read (CONFIG_SYS_DEF_EEPROM_ADDR,
CONFIG_ENV_OFFSET+offsetof(env_t,crc),
(uchar *)&crc, sizeof(ulong));
while (len > 0) {
int n = (len > sizeof(buf)) ? sizeof(buf) : len;
- eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, buf, n);
+ eeprom_bus_read (CONFIG_SYS_DEF_EEPROM_ADDR,
+ CONFIG_ENV_OFFSET + off, buf, n);
new = crc32 (new, buf, n);
len -= n;
off += n;