X-Git-Url: https://git.kernelconcepts.de/?p=karo-tx-uboot.git;a=blobdiff_plain;f=common%2Fenv_eeprom.c;h=905d39ac9868357657a03ff458d71f709c2389fe;hp=f5882bcfcf49c7f12e816ab35b276fb70d5eadb1;hb=97842e1ee9f04e8a5a54c3dcbbd048bd581ad09c;hpb=1a4596601fd395f3afb8f82f3f840c5e00bdd57a diff --git a/common/env_eeprom.c b/common/env_eeprom.c index f5882bcfcf..905d39ac98 100644 --- a/common/env_eeprom.c +++ b/common/env_eeprom.c @@ -5,7 +5,7 @@ * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH * Andreas Heppel * - * SPDX-License-Identifier: GPL-2.0+ + * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -24,7 +24,6 @@ DECLARE_GLOBAL_DATA_PTR; env_t *env_ptr; char *env_name_spec = "EEPROM"; -int env_eeprom_bus = -1; static int eeprom_bus_read(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt) @@ -33,32 +32,16 @@ static int eeprom_bus_read(unsigned dev_addr, unsigned offset, #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); - } + if (old_bus != CONFIG_I2C_ENV_EEPROM_BUS) + i2c_set_bus_num(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); + i2c_set_bus_num(old_bus); #endif + return rcode; } @@ -69,12 +52,16 @@ static int eeprom_bus_write(unsigned dev_addr, unsigned offset, #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); + if (old_bus != CONFIG_I2C_ENV_EEPROM_BUS) + i2c_set_bus_num(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; } @@ -111,8 +98,6 @@ void env_relocate_spec(void) int saveenv(void) { env_t env_new; - ssize_t len; - char *res; int rc; unsigned int off = CONFIG_ENV_OFFSET; #ifdef CONFIG_ENV_OFFSET_REDUND @@ -122,13 +107,9 @@ int saveenv(void) BUG_ON(env_ptr != NULL); - res = (char *)&env_new.data; - len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); - if (len < 0) { - error("Cannot export environment: errno = %d\n", errno); - return 1; - } - env_new.crc = crc32(0, env_new.data, ENV_SIZE); + rc = env_export(&env_new); + if (rc) + return rc; #ifdef CONFIG_ENV_OFFSET_REDUND if (gd->env_valid == 1) { @@ -166,6 +147,7 @@ int saveenv(void) #ifdef CONFIG_ENV_OFFSET_REDUND int env_init(void) { +#ifdef ENV_IS_EMBEDDED ulong len, crc[2], crc_tmp; unsigned int off, off_env[2]; uchar buf[64], flags[2]; @@ -231,12 +213,16 @@ int env_init(void) gd->env_addr = off_env[1] + offsetof(env_t, data); else if (gd->env_valid == 1) gd->env_addr = off_env[0] + offsetof(env_t, data); - +#else + gd->env_addr = (ulong)&default_environment[0]; + gd->env_valid = 1; +#endif return 0; } #else int env_init(void) { +#ifdef ENV_IS_EMBEDDED ulong crc, len, new; unsigned off; uchar buf[64]; @@ -269,7 +255,10 @@ int env_init(void) gd->env_addr = 0; gd->env_valid = 0; } - +#else + gd->env_addr = (ulong)&default_environment[0]; + gd->env_valid = 1; +#endif return 0; } #endif