wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 1 | /* |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 2 | * (C) Copyright 2000-2010 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 5 | * (C) Copyright 2008 |
| 6 | * Stuart Wood, Lab X Technologies <stuart.wood@labxtechnologies.com> |
| 7 | * |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 8 | * (C) Copyright 2004 |
| 9 | * Jian Zhang, Texas Instruments, jzhang@ti.com. |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 10 | * |
| 11 | * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 12 | * Andreas Heppel <aheppel@sysgo.de> |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 13 | * |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 14 | * See file CREDITS for list of people who contributed to this |
| 15 | * project. |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or |
| 18 | * modify it under the terms of the GNU General Public License as |
| 19 | * published by the Free Software Foundation; either version 2 of |
| 20 | * the License, or (at your option) any later version. |
| 21 | * |
| 22 | * This program is distributed in the hope that it will be useful, |
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | * GNU General Public License for more details. |
| 26 | * |
| 27 | * You should have received a copy of the GNU General Public License |
| 28 | * along with this program; if not, write to the Free Software |
| 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 30 | * MA 02111-1307 USA |
| 31 | */ |
| 32 | |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 33 | #include <common.h> |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 34 | #include <command.h> |
| 35 | #include <environment.h> |
| 36 | #include <linux/stddef.h> |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 37 | #include <malloc.h> |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 38 | #include <nand.h> |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 39 | #include <search.h> |
| 40 | #include <errno.h> |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 41 | |
Mike Frysinger | 78dcaf4 | 2009-01-28 19:08:14 -0500 | [diff] [blame] | 42 | #if defined(CONFIG_CMD_SAVEENV) && defined(CONFIG_CMD_NAND) |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 43 | #define CMD_SAVEENV |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 44 | #elif defined(CONFIG_ENV_OFFSET_REDUND) |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 45 | #error CONFIG_ENV_OFFSET_REDUND must have CONFIG_CMD_SAVEENV & CONFIG_CMD_NAND |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 46 | #endif |
| 47 | |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 48 | #if defined(CONFIG_ENV_SIZE_REDUND) && \ |
| 49 | (CONFIG_ENV_SIZE_REDUND != CONFIG_ENV_SIZE) |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 50 | #error CONFIG_ENV_SIZE_REDUND should be the same as CONFIG_ENV_SIZE |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 51 | #endif |
| 52 | |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 53 | #ifndef CONFIG_ENV_RANGE |
| 54 | #define CONFIG_ENV_RANGE CONFIG_ENV_SIZE |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 55 | #endif |
| 56 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 57 | char *env_name_spec = "NAND"; |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 58 | |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 59 | #if defined(ENV_IS_EMBEDDED) |
Igor Grinberg | 23b54b9 | 2011-11-17 06:07:23 +0000 | [diff] [blame] | 60 | env_t *env_ptr = &environment; |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 61 | #elif defined(CONFIG_NAND_ENV_DST) |
| 62 | env_t *env_ptr = (env_t *)CONFIG_NAND_ENV_DST; |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 63 | #else /* ! ENV_IS_EMBEDDED */ |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 64 | env_t *env_ptr; |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 65 | #endif /* ENV_IS_EMBEDDED */ |
| 66 | |
Rob Herring | 04cae82 | 2013-03-22 11:26:21 +0000 | [diff] [blame] | 67 | DEFINE_CACHE_ALIGN_BUFFER(char, env_buf, CONFIG_ENV_SIZE); |
| 68 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 69 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 70 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 71 | /* |
| 72 | * This is called before nand_init() so we can't read NAND to |
| 73 | * validate env data. |
| 74 | * |
| 75 | * Mark it OK for now. env_relocate() in env_common.c will call our |
| 76 | * relocate function which does the real validation. |
Stefan Roese | bbfcbb7 | 2006-09-12 20:19:10 +0200 | [diff] [blame] | 77 | * |
| 78 | * When using a NAND boot image (like sequoia_nand), the environment |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 79 | * can be embedded or attached to the U-Boot image in NAND flash. |
| 80 | * This way the SPL loads not only the U-Boot image from NAND but |
| 81 | * also the environment. |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 82 | */ |
| 83 | int env_init(void) |
| 84 | { |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 85 | #if defined(ENV_IS_EMBEDDED) || defined(CONFIG_NAND_ENV_DST) |
Stefan Roese | bbfcbb7 | 2006-09-12 20:19:10 +0200 | [diff] [blame] | 86 | int crc1_ok = 0, crc2_ok = 0; |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 87 | env_t *tmp_env1; |
Stefan Roese | bbfcbb7 | 2006-09-12 20:19:10 +0200 | [diff] [blame] | 88 | |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 89 | #ifdef CONFIG_ENV_OFFSET_REDUND |
| 90 | env_t *tmp_env2; |
| 91 | |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 92 | tmp_env2 = (env_t *)((ulong)env_ptr + CONFIG_ENV_SIZE); |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 93 | crc2_ok = crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc; |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 94 | #endif |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 95 | tmp_env1 = env_ptr; |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 96 | crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc; |
Stefan Roese | bbfcbb7 | 2006-09-12 20:19:10 +0200 | [diff] [blame] | 97 | |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 98 | if (!crc1_ok && !crc2_ok) { |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 99 | gd->env_addr = 0; |
| 100 | gd->env_valid = 0; |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 101 | |
| 102 | return 0; |
| 103 | } else if (crc1_ok && !crc2_ok) { |
Stefan Roese | bbfcbb7 | 2006-09-12 20:19:10 +0200 | [diff] [blame] | 104 | gd->env_valid = 1; |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 105 | } |
| 106 | #ifdef CONFIG_ENV_OFFSET_REDUND |
| 107 | else if (!crc1_ok && crc2_ok) { |
Stefan Roese | bbfcbb7 | 2006-09-12 20:19:10 +0200 | [diff] [blame] | 108 | gd->env_valid = 2; |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 109 | } else { |
Stefan Roese | bbfcbb7 | 2006-09-12 20:19:10 +0200 | [diff] [blame] | 110 | /* both ok - check serial */ |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 111 | if (tmp_env1->flags == 255 && tmp_env2->flags == 0) |
Stefan Roese | bbfcbb7 | 2006-09-12 20:19:10 +0200 | [diff] [blame] | 112 | gd->env_valid = 2; |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 113 | else if (tmp_env2->flags == 255 && tmp_env1->flags == 0) |
Stefan Roese | bbfcbb7 | 2006-09-12 20:19:10 +0200 | [diff] [blame] | 114 | gd->env_valid = 1; |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 115 | else if (tmp_env1->flags > tmp_env2->flags) |
Stefan Roese | bbfcbb7 | 2006-09-12 20:19:10 +0200 | [diff] [blame] | 116 | gd->env_valid = 1; |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 117 | else if (tmp_env2->flags > tmp_env1->flags) |
Stefan Roese | bbfcbb7 | 2006-09-12 20:19:10 +0200 | [diff] [blame] | 118 | gd->env_valid = 2; |
| 119 | else /* flags are equal - almost impossible */ |
| 120 | gd->env_valid = 1; |
| 121 | } |
| 122 | |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 123 | if (gd->env_valid == 2) |
| 124 | env_ptr = tmp_env2; |
| 125 | else |
| 126 | #endif |
Stefan Roese | bbfcbb7 | 2006-09-12 20:19:10 +0200 | [diff] [blame] | 127 | if (gd->env_valid == 1) |
| 128 | env_ptr = tmp_env1; |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 129 | |
| 130 | gd->env_addr = (ulong)env_ptr->data; |
| 131 | |
| 132 | #else /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */ |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 133 | gd->env_addr = (ulong)&default_environment[0]; |
| 134 | gd->env_valid = 1; |
Guennadi Liakhovetski | fad2444 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 135 | #endif /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */ |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 136 | |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 137 | return 0; |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | #ifdef CMD_SAVEENV |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 141 | /* |
| 142 | * The legacy NAND code saved the environment in the first NAND device i.e., |
| 143 | * nand_dev_desc + 0. This is also the behaviour using the new NAND code. |
| 144 | */ |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 145 | int writeenv(size_t offset, u_char *buf) |
| 146 | { |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 147 | size_t end = offset + CONFIG_ENV_RANGE; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 148 | size_t amount_saved = 0; |
Guennadi Liakhovetski | 0c40ae94 | 2008-07-31 12:38:26 +0200 | [diff] [blame] | 149 | size_t blocksize, len; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 150 | u_char *char_ptr; |
| 151 | |
| 152 | blocksize = nand_info[0].erasesize; |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 153 | len = min(blocksize, CONFIG_ENV_SIZE); |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 154 | |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 155 | while (amount_saved < CONFIG_ENV_SIZE && offset < end) { |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 156 | if (nand_block_isbad(&nand_info[0], offset)) { |
| 157 | offset += blocksize; |
| 158 | } else { |
| 159 | char_ptr = &buf[amount_saved]; |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 160 | if (nand_write(&nand_info[0], offset, &len, char_ptr)) |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 161 | return 1; |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 162 | |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 163 | offset += blocksize; |
Guennadi Liakhovetski | 0c40ae94 | 2008-07-31 12:38:26 +0200 | [diff] [blame] | 164 | amount_saved += len; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 165 | } |
| 166 | } |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 167 | if (amount_saved != CONFIG_ENV_SIZE) |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 168 | return 1; |
| 169 | |
| 170 | return 0; |
| 171 | } |
Scott Wood | 00eed7f | 2011-02-08 15:25:02 -0600 | [diff] [blame] | 172 | |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 173 | #ifdef CONFIG_ENV_OFFSET_REDUND |
Scott Wood | 00eed7f | 2011-02-08 15:25:02 -0600 | [diff] [blame] | 174 | static unsigned char env_flags; |
| 175 | |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 176 | int saveenv(void) |
| 177 | { |
Rob Herring | 04cae82 | 2013-03-22 11:26:21 +0000 | [diff] [blame] | 178 | env_t *env_new = (env_t *)env_buf; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 179 | ssize_t len; |
| 180 | char *res; |
| 181 | int ret = 0; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 182 | nand_erase_options_t nand_erase_options; |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 183 | |
Daniel Hobi | 201e7a2 | 2011-05-18 15:21:08 +0200 | [diff] [blame] | 184 | memset(&nand_erase_options, 0, sizeof(nand_erase_options)); |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 185 | nand_erase_options.length = CONFIG_ENV_RANGE; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 186 | |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 187 | if (CONFIG_ENV_RANGE < CONFIG_ENV_SIZE) |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 188 | return 1; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 189 | |
Rob Herring | 04cae82 | 2013-03-22 11:26:21 +0000 | [diff] [blame] | 190 | res = (char *)env_new->data; |
Joe Hershberger | 79a905e | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 191 | len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 192 | if (len < 0) { |
| 193 | error("Cannot export environment: errno = %d\n", errno); |
| 194 | return 1; |
| 195 | } |
Rob Herring | 04cae82 | 2013-03-22 11:26:21 +0000 | [diff] [blame] | 196 | env_new->crc = crc32(0, env_new->data, ENV_SIZE); |
| 197 | env_new->flags = ++env_flags; /* increase the serial */ |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 198 | |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 199 | if (gd->env_valid == 1) { |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 200 | puts("Erasing redundant NAND...\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 201 | nand_erase_options.offset = CONFIG_ENV_OFFSET_REDUND; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 202 | if (nand_erase_opts(&nand_info[0], &nand_erase_options)) |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 203 | return 1; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 204 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 205 | puts("Writing to redundant NAND... "); |
Rob Herring | 04cae82 | 2013-03-22 11:26:21 +0000 | [diff] [blame] | 206 | ret = writeenv(CONFIG_ENV_OFFSET_REDUND, (u_char *)env_new); |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 207 | } else { |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 208 | puts("Erasing NAND...\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 209 | nand_erase_options.offset = CONFIG_ENV_OFFSET; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 210 | if (nand_erase_opts(&nand_info[0], &nand_erase_options)) |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 211 | return 1; |
| 212 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 213 | puts("Writing to NAND... "); |
Rob Herring | 04cae82 | 2013-03-22 11:26:21 +0000 | [diff] [blame] | 214 | ret = writeenv(CONFIG_ENV_OFFSET, (u_char *)env_new); |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 215 | } |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 216 | if (ret) { |
| 217 | puts("FAILED!\n"); |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 218 | return 1; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 219 | } |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 220 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 221 | puts("done\n"); |
| 222 | |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 223 | gd->env_valid = gd->env_valid == 2 ? 1 : 2; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 224 | |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 225 | return ret; |
| 226 | } |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 227 | #else /* ! CONFIG_ENV_OFFSET_REDUND */ |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 228 | int saveenv(void) |
| 229 | { |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 230 | int ret = 0; |
Rob Herring | 04cae82 | 2013-03-22 11:26:21 +0000 | [diff] [blame] | 231 | env_t *env_new = (env_t *)env_buf; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 232 | ssize_t len; |
| 233 | char *res; |
Philip Balister | 8c57e9a | 2008-06-16 08:58:07 -0400 | [diff] [blame] | 234 | nand_erase_options_t nand_erase_options; |
Wolfgang Denk | 41df50a | 2008-06-28 23:34:37 +0200 | [diff] [blame] | 235 | |
Daniel Hobi | 201e7a2 | 2011-05-18 15:21:08 +0200 | [diff] [blame] | 236 | memset(&nand_erase_options, 0, sizeof(nand_erase_options)); |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 237 | nand_erase_options.length = CONFIG_ENV_RANGE; |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 238 | nand_erase_options.offset = CONFIG_ENV_OFFSET; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 239 | |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 240 | if (CONFIG_ENV_RANGE < CONFIG_ENV_SIZE) |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 241 | return 1; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 242 | |
Rob Herring | 04cae82 | 2013-03-22 11:26:21 +0000 | [diff] [blame] | 243 | res = (char *)env_new->data; |
Joe Hershberger | 79a905e | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 244 | len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 245 | if (len < 0) { |
| 246 | error("Cannot export environment: errno = %d\n", errno); |
| 247 | return 1; |
| 248 | } |
Stephen Warren | 1150ff8 | 2012-07-30 07:38:38 +0000 | [diff] [blame] | 249 | env_new->crc = crc32(0, env_new->data, ENV_SIZE); |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 250 | |
| 251 | puts("Erasing Nand...\n"); |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 252 | if (nand_erase_opts(&nand_info[0], &nand_erase_options)) |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 253 | return 1; |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 254 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 255 | puts("Writing to Nand... "); |
Stephen Warren | 1150ff8 | 2012-07-30 07:38:38 +0000 | [diff] [blame] | 256 | if (writeenv(CONFIG_ENV_OFFSET, (u_char *)env_new)) { |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 257 | puts("FAILED!\n"); |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 258 | return 1; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 259 | } |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 260 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 261 | puts("done\n"); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 262 | return ret; |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 263 | } |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 264 | #endif /* CONFIG_ENV_OFFSET_REDUND */ |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 265 | #endif /* CMD_SAVEENV */ |
| 266 | |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 267 | int readenv(size_t offset, u_char *buf) |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 268 | { |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 269 | size_t end = offset + CONFIG_ENV_RANGE; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 270 | size_t amount_loaded = 0; |
Guennadi Liakhovetski | 0c40ae94 | 2008-07-31 12:38:26 +0200 | [diff] [blame] | 271 | size_t blocksize, len; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 272 | u_char *char_ptr; |
| 273 | |
| 274 | blocksize = nand_info[0].erasesize; |
Mike Frysinger | 3dc4ccd | 2010-08-11 23:42:26 -0400 | [diff] [blame] | 275 | if (!blocksize) |
| 276 | return 1; |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 277 | |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 278 | len = min(blocksize, CONFIG_ENV_SIZE); |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 279 | |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 280 | while (amount_loaded < CONFIG_ENV_SIZE && offset < end) { |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 281 | if (nand_block_isbad(&nand_info[0], offset)) { |
| 282 | offset += blocksize; |
| 283 | } else { |
| 284 | char_ptr = &buf[amount_loaded]; |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 285 | if (nand_read_skip_bad(&nand_info[0], offset, |
| 286 | &len, char_ptr)) |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 287 | return 1; |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 288 | |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 289 | offset += blocksize; |
Guennadi Liakhovetski | 0c40ae94 | 2008-07-31 12:38:26 +0200 | [diff] [blame] | 290 | amount_loaded += len; |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 291 | } |
| 292 | } |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 293 | |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 294 | if (amount_loaded != CONFIG_ENV_SIZE) |
Stuart Wood | 37e1144 | 2008-05-30 16:05:28 -0400 | [diff] [blame] | 295 | return 1; |
| 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
Ben Gardiner | 5fc8b7f | 2010-07-05 13:27:07 -0400 | [diff] [blame] | 300 | #ifdef CONFIG_ENV_OFFSET_OOB |
| 301 | int get_nand_env_oob(nand_info_t *nand, unsigned long *result) |
| 302 | { |
| 303 | struct mtd_oob_ops ops; |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 304 | uint32_t oob_buf[ENV_OFFSET_SIZE / sizeof(uint32_t)]; |
Ben Gardiner | 5fc8b7f | 2010-07-05 13:27:07 -0400 | [diff] [blame] | 305 | int ret; |
| 306 | |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 307 | ops.datbuf = NULL; |
| 308 | ops.mode = MTD_OOB_AUTO; |
| 309 | ops.ooboffs = 0; |
| 310 | ops.ooblen = ENV_OFFSET_SIZE; |
| 311 | ops.oobbuf = (void *)oob_buf; |
Ben Gardiner | 5fc8b7f | 2010-07-05 13:27:07 -0400 | [diff] [blame] | 312 | |
| 313 | ret = nand->read_oob(nand, ENV_OFFSET_SIZE, &ops); |
Scott Wood | 0268da0 | 2010-07-12 18:17:40 -0500 | [diff] [blame] | 314 | if (ret) { |
| 315 | printf("error reading OOB block 0\n"); |
| 316 | return ret; |
| 317 | } |
Ben Gardiner | 5fc8b7f | 2010-07-05 13:27:07 -0400 | [diff] [blame] | 318 | |
Scott Wood | 0268da0 | 2010-07-12 18:17:40 -0500 | [diff] [blame] | 319 | if (oob_buf[0] == ENV_OOB_MARKER) { |
| 320 | *result = oob_buf[1] * nand->erasesize; |
| 321 | } else if (oob_buf[0] == ENV_OOB_MARKER_OLD) { |
| 322 | *result = oob_buf[1]; |
Ben Gardiner | 5fc8b7f | 2010-07-05 13:27:07 -0400 | [diff] [blame] | 323 | } else { |
Scott Wood | 0268da0 | 2010-07-12 18:17:40 -0500 | [diff] [blame] | 324 | printf("No dynamic environment marker in OOB block 0\n"); |
| 325 | return -ENOENT; |
Ben Gardiner | 5fc8b7f | 2010-07-05 13:27:07 -0400 | [diff] [blame] | 326 | } |
Scott Wood | 0268da0 | 2010-07-12 18:17:40 -0500 | [diff] [blame] | 327 | |
| 328 | return 0; |
Ben Gardiner | 5fc8b7f | 2010-07-05 13:27:07 -0400 | [diff] [blame] | 329 | } |
| 330 | #endif |
| 331 | |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 332 | #ifdef CONFIG_ENV_OFFSET_REDUND |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 333 | void env_relocate_spec(void) |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 334 | { |
| 335 | #if !defined(ENV_IS_EMBEDDED) |
Phil Sutter | 190e58a | 2013-02-21 18:21:55 +0100 | [diff] [blame] | 336 | int read1_fail = 0, read2_fail = 0; |
Markus Klotzbuecher | ffe7ef5 | 2006-03-24 15:43:16 +0100 | [diff] [blame] | 337 | int crc1_ok = 0, crc2_ok = 0; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 338 | env_t *ep, *tmp_env1, *tmp_env2; |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 339 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 340 | tmp_env1 = (env_t *)malloc(CONFIG_ENV_SIZE); |
| 341 | tmp_env2 = (env_t *)malloc(CONFIG_ENV_SIZE); |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 342 | if (tmp_env1 == NULL || tmp_env2 == NULL) { |
Wolfgang Denk | be14eb1 | 2010-01-16 21:50:26 -0700 | [diff] [blame] | 343 | puts("Can't allocate buffers for environment\n"); |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 344 | set_default_env("!malloc() failed"); |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 345 | goto done; |
Wolfgang Denk | be14eb1 | 2010-01-16 21:50:26 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Phil Sutter | 190e58a | 2013-02-21 18:21:55 +0100 | [diff] [blame] | 348 | read1_fail = readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1); |
| 349 | read2_fail = readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2); |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 350 | |
Phil Sutter | 190e58a | 2013-02-21 18:21:55 +0100 | [diff] [blame] | 351 | if (read1_fail && read2_fail) |
| 352 | puts("*** Error - No Valid Environment Area found\n"); |
| 353 | else if (read1_fail || read2_fail) |
| 354 | puts("*** Warning - some problems detected " |
| 355 | "reading environment; recovered successfully\n"); |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 356 | |
Phil Sutter | 3c51a85 | 2013-02-21 18:21:56 +0100 | [diff] [blame] | 357 | crc1_ok = !read1_fail && |
| 358 | (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc); |
| 359 | crc2_ok = !read2_fail && |
| 360 | (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc); |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 361 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 362 | if (!crc1_ok && !crc2_ok) { |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 363 | set_default_env("!bad CRC"); |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 364 | goto done; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 365 | } else if (crc1_ok && !crc2_ok) { |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 366 | gd->env_valid = 1; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 367 | } else if (!crc1_ok && crc2_ok) { |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 368 | gd->env_valid = 2; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 369 | } else { |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 370 | /* both ok - check serial */ |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 371 | if (tmp_env1->flags == 255 && tmp_env2->flags == 0) |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 372 | gd->env_valid = 2; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 373 | else if (tmp_env2->flags == 255 && tmp_env1->flags == 0) |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 374 | gd->env_valid = 1; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 375 | else if (tmp_env1->flags > tmp_env2->flags) |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 376 | gd->env_valid = 1; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 377 | else if (tmp_env2->flags > tmp_env1->flags) |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 378 | gd->env_valid = 2; |
| 379 | else /* flags are equal - almost impossible */ |
| 380 | gd->env_valid = 1; |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | free(env_ptr); |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 384 | |
| 385 | if (gd->env_valid == 1) |
| 386 | ep = tmp_env1; |
| 387 | else |
| 388 | ep = tmp_env2; |
| 389 | |
Scott Wood | 00eed7f | 2011-02-08 15:25:02 -0600 | [diff] [blame] | 390 | env_flags = ep->flags; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 391 | env_import((char *)ep, 0); |
| 392 | |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 393 | done: |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 394 | free(tmp_env1); |
| 395 | free(tmp_env2); |
Markus Klotzbuecher | 5d113e0 | 2006-03-20 18:02:44 +0100 | [diff] [blame] | 396 | |
| 397 | #endif /* ! ENV_IS_EMBEDDED */ |
| 398 | } |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 399 | #else /* ! CONFIG_ENV_OFFSET_REDUND */ |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 400 | /* |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 401 | * The legacy NAND code saved the environment in the first NAND |
| 402 | * device i.e., nand_dev_desc + 0. This is also the behaviour using |
| 403 | * the new NAND code. |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 404 | */ |
Igor Grinberg | 90f2ca8 | 2011-11-07 01:14:10 +0000 | [diff] [blame] | 405 | void env_relocate_spec(void) |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 406 | { |
| 407 | #if !defined(ENV_IS_EMBEDDED) |
Wolfgang Denk | 7fa6e90 | 2006-03-11 22:53:33 +0100 | [diff] [blame] | 408 | int ret; |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 409 | |
Ben Gardiner | 5fc8b7f | 2010-07-05 13:27:07 -0400 | [diff] [blame] | 410 | #if defined(CONFIG_ENV_OFFSET_OOB) |
| 411 | ret = get_nand_env_oob(&nand_info[0], &nand_env_oob_offset); |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 412 | /* |
| 413 | * If unable to read environment offset from NAND OOB then fall through |
Ben Gardiner | 5fc8b7f | 2010-07-05 13:27:07 -0400 | [diff] [blame] | 414 | * to the normal environment reading code below |
| 415 | */ |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 416 | if (!ret) { |
Ben Gardiner | 5fc8b7f | 2010-07-05 13:27:07 -0400 | [diff] [blame] | 417 | printf("Found Environment offset in OOB..\n"); |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 418 | } else { |
| 419 | set_default_env("!no env offset in OOB"); |
| 420 | return; |
| 421 | } |
Ben Gardiner | 5fc8b7f | 2010-07-05 13:27:07 -0400 | [diff] [blame] | 422 | #endif |
| 423 | |
Rob Herring | 04cae82 | 2013-03-22 11:26:21 +0000 | [diff] [blame] | 424 | ret = readenv(CONFIG_ENV_OFFSET, (u_char *)env_buf); |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 425 | if (ret) { |
| 426 | set_default_env("!readenv() failed"); |
| 427 | return; |
| 428 | } |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 429 | |
Rob Herring | 04cae82 | 2013-03-22 11:26:21 +0000 | [diff] [blame] | 430 | env_import(env_buf, 1); |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 431 | #endif /* ! ENV_IS_EMBEDDED */ |
wdenk | 79b5937 | 2004-06-09 14:58:14 +0000 | [diff] [blame] | 432 | } |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 433 | #endif /* CONFIG_ENV_OFFSET_REDUND */ |