wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 1 | /* |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 2 | * (C) Copyright 2000-2010 |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 6 | * Andreas Heppel <aheppel@sysgo.de> |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 7 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 12 | #include <command.h> |
| 13 | #include <environment.h> |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 14 | #include <linux/stddef.h> |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 15 | #if defined(CONFIG_I2C_ENV_EEPROM_BUS) |
| 16 | #include <i2c.h> |
| 17 | #endif |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 18 | #include <search.h> |
| 19 | #include <errno.h> |
| 20 | #include <linux/compiler.h> /* for BUG_ON */ |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 21 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 24 | env_t *env_ptr; |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 25 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 26 | char *env_name_spec = "EEPROM"; |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 27 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 28 | static int eeprom_bus_read(unsigned dev_addr, unsigned offset, |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 29 | uchar *buffer, unsigned cnt) |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 30 | { |
| 31 | int rcode; |
| 32 | #if defined(CONFIG_I2C_ENV_EEPROM_BUS) |
| 33 | int old_bus = i2c_get_bus_num(); |
| 34 | |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 35 | if (old_bus != CONFIG_I2C_ENV_EEPROM_BUS) |
| 36 | i2c_set_bus_num(CONFIG_I2C_ENV_EEPROM_BUS); |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 37 | #endif |
| 38 | |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 39 | rcode = eeprom_read(dev_addr, offset, buffer, cnt); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 40 | |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 41 | #if defined(CONFIG_I2C_ENV_EEPROM_BUS) |
Alexey Brodkin | 6d001e7 | 2013-12-11 18:04:40 +0400 | [diff] [blame] | 42 | i2c_set_bus_num(old_bus); |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 43 | #endif |
Heiko Schocher | 9a2accb | 2012-10-25 10:32:14 +0200 | [diff] [blame] | 44 | |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 45 | return rcode; |
| 46 | } |
| 47 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 48 | static int eeprom_bus_write(unsigned dev_addr, unsigned offset, |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 49 | uchar *buffer, unsigned cnt) |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 50 | { |
| 51 | int rcode; |
| 52 | #if defined(CONFIG_I2C_ENV_EEPROM_BUS) |
| 53 | int old_bus = i2c_get_bus_num(); |
| 54 | |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 55 | if (old_bus != CONFIG_I2C_ENV_EEPROM_BUS) |
| 56 | i2c_set_bus_num(CONFIG_I2C_ENV_EEPROM_BUS); |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 57 | #endif |
Heiko Schocher | 9a2accb | 2012-10-25 10:32:14 +0200 | [diff] [blame] | 58 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 59 | rcode = eeprom_write(dev_addr, offset, buffer, cnt); |
Heiko Schocher | 9a2accb | 2012-10-25 10:32:14 +0200 | [diff] [blame] | 60 | |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 61 | #if defined(CONFIG_I2C_ENV_EEPROM_BUS) |
| 62 | i2c_set_bus_num(old_bus); |
| 63 | #endif |
Alexey Brodkin | 6d001e7 | 2013-12-11 18:04:40 +0400 | [diff] [blame] | 64 | |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 65 | return rcode; |
| 66 | } |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 67 | |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 68 | uchar env_get_char_spec(int index) |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 69 | { |
| 70 | uchar c; |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 71 | unsigned int off = CONFIG_ENV_OFFSET; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 72 | |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 73 | #ifdef CONFIG_ENV_OFFSET_REDUND |
| 74 | if (gd->env_valid == 2) |
| 75 | off = CONFIG_ENV_OFFSET_REDUND; |
| 76 | #endif |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 77 | eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 78 | off + index + offsetof(env_t, data), &c, 1); |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 79 | |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 80 | return c; |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 83 | void env_relocate_spec(void) |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 84 | { |
Tom Rini | cd0f4fa | 2013-04-05 14:55:21 -0400 | [diff] [blame] | 85 | char buf[CONFIG_ENV_SIZE]; |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 86 | unsigned int off = CONFIG_ENV_OFFSET; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 87 | |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 88 | #ifdef CONFIG_ENV_OFFSET_REDUND |
| 89 | if (gd->env_valid == 2) |
| 90 | off = CONFIG_ENV_OFFSET_REDUND; |
| 91 | #endif |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 92 | eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 93 | off, (uchar *)buf, CONFIG_ENV_SIZE); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 94 | |
| 95 | env_import(buf, 1); |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | int saveenv(void) |
| 99 | { |
Tom Rini | cd0f4fa | 2013-04-05 14:55:21 -0400 | [diff] [blame] | 100 | env_t env_new; |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 101 | int rc; |
| 102 | unsigned int off = CONFIG_ENV_OFFSET; |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 103 | #ifdef CONFIG_ENV_OFFSET_REDUND |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 104 | unsigned int off_red = CONFIG_ENV_OFFSET_REDUND; |
| 105 | char flag_obsolete = OBSOLETE_FLAG; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 106 | #endif |
| 107 | |
| 108 | BUG_ON(env_ptr != NULL); |
| 109 | |
Marek Vasut | 7ce1526 | 2014-03-05 19:59:50 +0100 | [diff] [blame^] | 110 | rc = env_export(&env_new); |
| 111 | if (rc) |
| 112 | return rc; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 113 | |
| 114 | #ifdef CONFIG_ENV_OFFSET_REDUND |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 115 | if (gd->env_valid == 1) { |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 116 | off = CONFIG_ENV_OFFSET_REDUND; |
| 117 | off_red = CONFIG_ENV_OFFSET; |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Tom Rini | cd0f4fa | 2013-04-05 14:55:21 -0400 | [diff] [blame] | 120 | env_new.flags = ACTIVE_FLAG; |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 121 | #endif |
| 122 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 123 | rc = eeprom_bus_write(CONFIG_SYS_DEF_EEPROM_ADDR, |
Tom Rini | cd0f4fa | 2013-04-05 14:55:21 -0400 | [diff] [blame] | 124 | off, (uchar *)&env_new, CONFIG_ENV_SIZE); |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 125 | |
| 126 | #ifdef CONFIG_ENV_OFFSET_REDUND |
| 127 | if (rc == 0) { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 128 | eeprom_bus_write(CONFIG_SYS_DEF_EEPROM_ADDR, |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 129 | off_red + offsetof(env_t, flags), |
| 130 | (uchar *)&flag_obsolete, 1); |
| 131 | |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 132 | if (gd->env_valid == 1) |
| 133 | gd->env_valid = 2; |
| 134 | else |
| 135 | gd->env_valid = 1; |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 136 | } |
| 137 | #endif |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 138 | return rc; |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 141 | /* |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 142 | * Initialize Environment use |
| 143 | * |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 144 | * We are still running from ROM, so data use is limited. |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 145 | * Use a (moderately small) buffer on the stack |
| 146 | */ |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 147 | #ifdef CONFIG_ENV_OFFSET_REDUND |
| 148 | int env_init(void) |
| 149 | { |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 150 | ulong len, crc[2], crc_tmp; |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 151 | unsigned int off, off_env[2]; |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 152 | uchar buf[64], flags[2]; |
| 153 | int i, crc_ok[2] = {0, 0}; |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 154 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 155 | eeprom_init(); /* prepare for EEPROM read/write */ |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 156 | |
| 157 | off_env[0] = CONFIG_ENV_OFFSET; |
| 158 | off_env[1] = CONFIG_ENV_OFFSET_REDUND; |
| 159 | |
| 160 | for (i = 0; i < 2; i++) { |
| 161 | /* read CRC */ |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 162 | eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 163 | off_env[i] + offsetof(env_t, crc), |
| 164 | (uchar *)&crc[i], sizeof(ulong)); |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 165 | /* read FLAGS */ |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 166 | eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 167 | off_env[i] + offsetof(env_t, flags), |
| 168 | (uchar *)&flags[i], sizeof(uchar)); |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 169 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 170 | crc_tmp = 0; |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 171 | len = ENV_SIZE; |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 172 | off = off_env[i] + offsetof(env_t, data); |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 173 | while (len > 0) { |
| 174 | int n = (len > sizeof(buf)) ? sizeof(buf) : len; |
| 175 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 176 | eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, off, |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 177 | buf, n); |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 178 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 179 | crc_tmp = crc32(crc_tmp, buf, n); |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 180 | len -= n; |
| 181 | off += n; |
| 182 | } |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 183 | |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 184 | if (crc_tmp == crc[i]) |
| 185 | crc_ok[i] = 1; |
| 186 | } |
| 187 | |
| 188 | if (!crc_ok[0] && !crc_ok[1]) { |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 189 | gd->env_addr = 0; |
| 190 | gd->env_valid = 0; |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 191 | |
| 192 | return 0; |
| 193 | } else if (crc_ok[0] && !crc_ok[1]) { |
| 194 | gd->env_valid = 1; |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 195 | } else if (!crc_ok[0] && crc_ok[1]) { |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 196 | gd->env_valid = 2; |
| 197 | } else { |
| 198 | /* both ok - check serial */ |
| 199 | if (flags[0] == ACTIVE_FLAG && flags[1] == OBSOLETE_FLAG) |
| 200 | gd->env_valid = 1; |
| 201 | else if (flags[0] == OBSOLETE_FLAG && flags[1] == ACTIVE_FLAG) |
| 202 | gd->env_valid = 2; |
| 203 | else if (flags[0] == 0xFF && flags[1] == 0) |
| 204 | gd->env_valid = 2; |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 205 | else if (flags[1] == 0xFF && flags[0] == 0) |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 206 | gd->env_valid = 1; |
| 207 | else /* flags are equal - almost impossible */ |
| 208 | gd->env_valid = 1; |
| 209 | } |
| 210 | |
| 211 | if (gd->env_valid == 2) |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 212 | gd->env_addr = off_env[1] + offsetof(env_t, data); |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 213 | else if (gd->env_valid == 1) |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 214 | gd->env_addr = off_env[0] + offsetof(env_t, data); |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 215 | |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 216 | return 0; |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 217 | } |
| 218 | #else |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 219 | int env_init(void) |
| 220 | { |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 221 | ulong crc, len, new; |
| 222 | unsigned off; |
| 223 | uchar buf[64]; |
| 224 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 225 | eeprom_init(); /* prepare for EEPROM read/write */ |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 226 | |
| 227 | /* read old CRC */ |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 228 | eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 229 | CONFIG_ENV_OFFSET + offsetof(env_t, crc), |
| 230 | (uchar *)&crc, sizeof(ulong)); |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 231 | |
| 232 | new = 0; |
| 233 | len = ENV_SIZE; |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 234 | off = offsetof(env_t, data); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 235 | |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 236 | while (len > 0) { |
| 237 | int n = (len > sizeof(buf)) ? sizeof(buf) : len; |
| 238 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 239 | eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 240 | CONFIG_ENV_OFFSET + off, buf, n); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 241 | new = crc32(new, buf, n); |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 242 | len -= n; |
| 243 | off += n; |
| 244 | } |
| 245 | |
| 246 | if (crc == new) { |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 247 | gd->env_addr = offsetof(env_t, data); |
| 248 | gd->env_valid = 1; |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 249 | } else { |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 250 | gd->env_addr = 0; |
| 251 | gd->env_valid = 0; |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Igor Grinberg | dd2a233 | 2011-11-07 01:14:07 +0000 | [diff] [blame] | 254 | return 0; |
wdenk | 0bc4a1a | 2002-09-18 11:09:59 +0000 | [diff] [blame] | 255 | } |
Heiko Schocher | 1567b59 | 2010-01-07 08:55:44 +0100 | [diff] [blame] | 256 | #endif |