X-Git-Url: https://git.kernelconcepts.de/?p=karo-tx-uboot.git;a=blobdiff_plain;f=common%2Fenv_eeprom.c;h=490ac731b31da018a4c3e12d0941e71a35011ec9;hp=b136f04ebe1bb17dafbad0cf44bfb9a9593e138c;hb=d2a3e911390f9fc4d8c0ee4b3c7fc75f4fd3fd19;hpb=60d7d5a63189c9f77a190c9965861dc15482c2d0 diff --git a/common/env_eeprom.c b/common/env_eeprom.c index b136f04ebe..490ac731b3 100644 --- a/common/env_eeprom.c +++ b/common/env_eeprom.c @@ -5,23 +5,7 @@ * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH * Andreas Heppel * - * See file CREDITS for list of people who contributed to this - * project. - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -38,10 +22,8 @@ DECLARE_GLOBAL_DATA_PTR; env_t *env_ptr; -static char env_buf[CONFIG_ENV_SIZE]; char *env_name_spec = "EEPROM"; -int env_eeprom_bus = -1; static int eeprom_bus_read(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt) @@ -50,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; } @@ -86,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; } @@ -112,7 +82,7 @@ uchar env_get_char_spec(int index) void env_relocate_spec(void) { - char *buf = env_buf; + char buf[CONFIG_ENV_SIZE]; unsigned int off = CONFIG_ENV_OFFSET; #ifdef CONFIG_ENV_OFFSET_REDUND @@ -127,9 +97,7 @@ void env_relocate_spec(void) int saveenv(void) { - env_t *env_new = (env_t *)env_buf; - ssize_t len; - char *res; + env_t env_new; int rc; unsigned int off = CONFIG_ENV_OFFSET; #ifdef CONFIG_ENV_OFFSET_REDUND @@ -139,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) { @@ -153,11 +117,11 @@ int saveenv(void) off_red = CONFIG_ENV_OFFSET; } - env_new->flags = ACTIVE_FLAG; + env_new.flags = ACTIVE_FLAG; #endif rc = eeprom_bus_write(CONFIG_SYS_DEF_EEPROM_ADDR, - off, (uchar *)env_new, CONFIG_ENV_SIZE); + off, (uchar *)&env_new, CONFIG_ENV_SIZE); #ifdef CONFIG_ENV_OFFSET_REDUND if (rc == 0) {