blob: 5de4a458171c283abab35fabf345ab6dcebdb300 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Terry Lvb4eceac2010-05-17 10:57:01 +08002/*
Mingkai Hua55fce32011-01-24 17:09:55 +00003 * (C) Copyright 2008-2011 Freescale Semiconductor, Inc.
Terry Lvb4eceac2010-05-17 10:57:01 +08004 */
5
6/* #define DEBUG */
7
8#include <common.h>
9
10#include <command.h>
Simon Glass97385862019-08-01 09:47:00 -060011#include <env.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060012#include <env_internal.h>
Philipp Tomsich8ab507b2017-05-16 00:16:31 +020013#include <fdtdec.h>
Terry Lvb4eceac2010-05-17 10:57:01 +080014#include <linux/stddef.h>
15#include <malloc.h>
Simon Glass2dd337a2015-09-02 17:24:58 -060016#include <memalign.h>
Terry Lvb4eceac2010-05-17 10:57:01 +080017#include <mmc.h>
Jorge Ramirez-Ortiz03ab46c2017-11-06 14:16:37 +010018#include <part.h>
Lei Wen9f84f212010-11-10 07:39:23 +080019#include <search.h>
Lei Wenff833ed2010-10-13 11:07:21 +080020#include <errno.h>
Terry Lvb4eceac2010-05-17 10:57:01 +080021
Jorge Ramirez-Ortiz03ab46c2017-11-06 14:16:37 +010022#define __STR(X) #X
23#define STR(X) __STR(X)
24
Terry Lvb4eceac2010-05-17 10:57:01 +080025DECLARE_GLOBAL_DATA_PTR;
26
Patrick Delaunay530cb452020-06-15 10:38:55 +020027#if !defined(CONFIG_SYS_MMC_ENV_DEV)
28#define CONFIG_SYS_MMC_ENV_DEV 0
29#endif
30
31__weak int mmc_get_env_dev(void)
32{
33 return CONFIG_SYS_MMC_ENV_DEV;
34}
35
Philipp Tomsich8ab507b2017-05-16 00:16:31 +020036#if CONFIG_IS_ENABLED(OF_CONTROL)
Jorge Ramirez-Ortiz03ab46c2017-11-06 14:16:37 +010037static inline int mmc_offset_try_partition(const char *str, s64 *val)
38{
Simon Glassc1c4a8f2020-05-10 11:39:57 -060039 struct disk_partition info;
Jorge Ramirez-Ortiz03ab46c2017-11-06 14:16:37 +010040 struct blk_desc *desc;
41 int len, i, ret;
Patrick Delaunay530cb452020-06-15 10:38:55 +020042 char dev_str[4];
Jorge Ramirez-Ortiz03ab46c2017-11-06 14:16:37 +010043
Patrick Delaunay530cb452020-06-15 10:38:55 +020044 snprintf(dev_str, sizeof(dev_str), "%d", mmc_get_env_dev());
45 ret = blk_get_device_by_str("mmc", dev_str, &desc);
Jorge Ramirez-Ortiz03ab46c2017-11-06 14:16:37 +010046 if (ret < 0)
47 return (ret);
48
49 for (i = 1;;i++) {
50 ret = part_get_info(desc, i, &info);
51 if (ret < 0)
52 return ret;
53
54 if (!strncmp((const char *)info.name, str, sizeof(str)))
55 break;
56 }
57
58 /* round up to info.blksz */
Patrick Delaunay66fba3a2020-06-15 10:38:56 +020059 len = DIV_ROUND_UP(CONFIG_ENV_SIZE, info.blksz);
Jorge Ramirez-Ortiz03ab46c2017-11-06 14:16:37 +010060
61 /* use the top of the partion for the environment */
Patrick Delaunay66fba3a2020-06-15 10:38:56 +020062 *val = (info.start + info.size - len) * info.blksz;
Jorge Ramirez-Ortiz03ab46c2017-11-06 14:16:37 +010063
64 return 0;
65}
66
Philipp Tomsich8ab507b2017-05-16 00:16:31 +020067static inline s64 mmc_offset(int copy)
68{
Jorge Ramirez-Ortiz03ab46c2017-11-06 14:16:37 +010069 const struct {
70 const char *offset_redund;
71 const char *partition;
72 const char *offset;
73 } dt_prop = {
74 .offset_redund = "u-boot,mmc-env-offset-redundant",
75 .partition = "u-boot,mmc-env-partition",
76 .offset = "u-boot,mmc-env-offset",
77 };
Philipp Tomsich745d8de2017-11-21 23:29:40 +010078 s64 val = 0, defvalue;
Jorge Ramirez-Ortiz03ab46c2017-11-06 14:16:37 +010079 const char *propname;
80 const char *str;
81 int err;
82
83 /* look for the partition in mmc CONFIG_SYS_MMC_ENV_DEV */
84 str = fdtdec_get_config_string(gd->fdt_blob, dt_prop.partition);
85 if (str) {
86 /* try to place the environment at end of the partition */
87 err = mmc_offset_try_partition(str, &val);
88 if (!err)
89 return val;
90 }
91
92 defvalue = CONFIG_ENV_OFFSET;
93 propname = dt_prop.offset;
Philipp Tomsich8ab507b2017-05-16 00:16:31 +020094
95#if defined(CONFIG_ENV_OFFSET_REDUND)
96 if (copy) {
Philipp Tomsich8ab507b2017-05-16 00:16:31 +020097 defvalue = CONFIG_ENV_OFFSET_REDUND;
Jorge Ramirez-Ortiz03ab46c2017-11-06 14:16:37 +010098 propname = dt_prop.offset_redund;
Philipp Tomsich8ab507b2017-05-16 00:16:31 +020099 }
100#endif
Philipp Tomsich8ab507b2017-05-16 00:16:31 +0200101 return fdtdec_get_config_int(gd->fdt_blob, propname, defvalue);
102}
103#else
104static inline s64 mmc_offset(int copy)
Mingkai Hua55fce32011-01-24 17:09:55 +0000105{
Philipp Tomsich8ab507b2017-05-16 00:16:31 +0200106 s64 offset = CONFIG_ENV_OFFSET;
Stephen Warren24dc2032013-06-11 15:14:02 -0600107
Philipp Tomsich8ab507b2017-05-16 00:16:31 +0200108#if defined(CONFIG_ENV_OFFSET_REDUND)
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000109 if (copy)
Stephen Warren24dc2032013-06-11 15:14:02 -0600110 offset = CONFIG_ENV_OFFSET_REDUND;
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000111#endif
Philipp Tomsich8ab507b2017-05-16 00:16:31 +0200112 return offset;
113}
114#endif
115
116__weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
117{
118 s64 offset = mmc_offset(copy);
Stephen Warren24dc2032013-06-11 15:14:02 -0600119
120 if (offset < 0)
121 offset += mmc->capacity;
122
123 *env_addr = offset;
124
Mingkai Hua55fce32011-01-24 17:09:55 +0000125 return 0;
126}
Mingkai Hua55fce32011-01-24 17:09:55 +0000127
Tom Rinic929f822014-03-28 12:03:34 -0400128#ifdef CONFIG_SYS_MMC_ENV_PART
Dmitry Lifshitz97d2fb92014-07-30 13:19:06 +0300129__weak uint mmc_get_env_part(struct mmc *mmc)
130{
131 return CONFIG_SYS_MMC_ENV_PART;
132}
133
Stephen Warren1e0f92a2015-12-07 11:38:49 -0700134static unsigned char env_mmc_orig_hwpart;
135
Dmitry Lifshitz97d2fb92014-07-30 13:19:06 +0300136static int mmc_set_env_part(struct mmc *mmc)
137{
138 uint part = mmc_get_env_part(mmc);
Clemens Gruberf7b61442016-01-20 15:43:37 +0100139 int dev = mmc_get_env_dev();
Dmitry Lifshitz97d2fb92014-07-30 13:19:06 +0300140 int ret = 0;
Tom Rinic929f822014-03-28 12:03:34 -0400141
Simon Glass11f2bb62016-05-01 13:52:29 -0600142 env_mmc_orig_hwpart = mmc_get_blk_desc(mmc)->hwpart;
143 ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part);
Stephen Warren1e0f92a2015-12-07 11:38:49 -0700144 if (ret)
145 puts("MMC partition switch failed\n");
Dmitry Lifshitz97d2fb92014-07-30 13:19:06 +0300146
147 return ret;
148}
149#else
150static inline int mmc_set_env_part(struct mmc *mmc) {return 0; };
Tom Rinic929f822014-03-28 12:03:34 -0400151#endif
152
Tim Harveyeda75c32015-05-08 14:52:09 -0700153static const char *init_mmc_for_env(struct mmc *mmc)
Dmitry Lifshitz97d2fb92014-07-30 13:19:06 +0300154{
Tim Harveyeda75c32015-05-08 14:52:09 -0700155 if (!mmc)
Yaniv Levinskyb2bb9bc2018-06-24 19:16:57 +0300156 return "No MMC card found";
Terry Lvb4eceac2010-05-17 10:57:01 +0800157
Sjoerd Simons5e4546d2018-03-22 22:53:50 +0100158#if CONFIG_IS_ENABLED(BLK)
Simon Glass1d9907c2017-05-27 11:37:18 -0600159 struct udevice *dev;
160
161 if (blk_get_from_parent(mmc->dev, &dev))
Yaniv Levinskyb2bb9bc2018-06-24 19:16:57 +0300162 return "No block device";
Simon Glass1d9907c2017-05-27 11:37:18 -0600163#else
Tim Harveyeda75c32015-05-08 14:52:09 -0700164 if (mmc_init(mmc))
Yaniv Levinskyb2bb9bc2018-06-24 19:16:57 +0300165 return "MMC init failed";
Simon Glass86d78c72017-04-23 20:02:04 -0600166#endif
Tim Harveyeda75c32015-05-08 14:52:09 -0700167 if (mmc_set_env_part(mmc))
Yaniv Levinskyb2bb9bc2018-06-24 19:16:57 +0300168 return "MMC partition switch failed";
Tim Harveyeda75c32015-05-08 14:52:09 -0700169
170 return NULL;
Terry Lvb4eceac2010-05-17 10:57:01 +0800171}
172
Stephen Warren27ee0f32012-07-30 10:55:44 +0000173static void fini_mmc_for_env(struct mmc *mmc)
174{
175#ifdef CONFIG_SYS_MMC_ENV_PART
Clemens Gruberf7b61442016-01-20 15:43:37 +0100176 int dev = mmc_get_env_dev();
Tom Rinic929f822014-03-28 12:03:34 -0400177
Simon Glass11f2bb62016-05-01 13:52:29 -0600178 blk_select_hwpart_devnum(IF_TYPE_MMC, dev, env_mmc_orig_hwpart);
Stephen Warren27ee0f32012-07-30 10:55:44 +0000179#endif
180}
181
Simon Glass082af922017-08-03 12:22:01 -0600182#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_SPL_BUILD)
Igor Grinbergecbfb622011-11-07 01:14:05 +0000183static inline int write_env(struct mmc *mmc, unsigned long size,
184 unsigned long offset, const void *buffer)
Terry Lvb4eceac2010-05-17 10:57:01 +0800185{
186 uint blk_start, blk_cnt, n;
Simon Glassda898922016-05-14 14:03:03 -0600187 struct blk_desc *desc = mmc_get_blk_desc(mmc);
Terry Lvb4eceac2010-05-17 10:57:01 +0800188
Igor Grinbergecbfb622011-11-07 01:14:05 +0000189 blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
190 blk_cnt = ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
Terry Lvb4eceac2010-05-17 10:57:01 +0800191
Simon Glassda898922016-05-14 14:03:03 -0600192 n = blk_dwrite(desc, blk_start, blk_cnt, (u_char *)buffer);
Terry Lvb4eceac2010-05-17 10:57:01 +0800193
194 return (n == blk_cnt) ? 0 : -1;
195}
196
Simon Glass082af922017-08-03 12:22:01 -0600197static int env_mmc_save(void)
Terry Lvb4eceac2010-05-17 10:57:01 +0800198{
Tom Rinia840b8e2013-04-05 14:55:21 -0400199 ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
Clemens Gruberf7b61442016-01-20 15:43:37 +0100200 int dev = mmc_get_env_dev();
201 struct mmc *mmc = find_mmc_device(dev);
Igor Grinbergecbfb622011-11-07 01:14:05 +0000202 u32 offset;
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000203 int ret, copy = 0;
Tim Harveyeda75c32015-05-08 14:52:09 -0700204 const char *errmsg;
Terry Lvb4eceac2010-05-17 10:57:01 +0800205
Tim Harveyeda75c32015-05-08 14:52:09 -0700206 errmsg = init_mmc_for_env(mmc);
207 if (errmsg) {
208 printf("%s\n", errmsg);
Terry Lvb4eceac2010-05-17 10:57:01 +0800209 return 1;
Tim Harveyeda75c32015-05-08 14:52:09 -0700210 }
Terry Lvb4eceac2010-05-17 10:57:01 +0800211
Marek Vasutd73c1292014-03-05 19:59:50 +0100212 ret = env_export(env_new);
213 if (ret)
Stephen Warren27ee0f32012-07-30 10:55:44 +0000214 goto fini;
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000215
216#ifdef CONFIG_ENV_OFFSET_REDUND
Simon Glass4bc2ad22017-08-03 12:21:56 -0600217 if (gd->env_valid == ENV_VALID)
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000218 copy = 1;
219#endif
220
221 if (mmc_get_env_addr(mmc, copy, &offset)) {
222 ret = 1;
223 goto fini;
224 }
225
Clemens Gruberf7b61442016-01-20 15:43:37 +0100226 printf("Writing to %sMMC(%d)... ", copy ? "redundant " : "", dev);
Stephen Warren42a3c442012-05-24 11:38:33 +0000227 if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)env_new)) {
Terry Lvb4eceac2010-05-17 10:57:01 +0800228 puts("failed\n");
Stephen Warren27ee0f32012-07-30 10:55:44 +0000229 ret = 1;
230 goto fini;
Terry Lvb4eceac2010-05-17 10:57:01 +0800231 }
232
Stephen Warren27ee0f32012-07-30 10:55:44 +0000233 ret = 0;
234
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000235#ifdef CONFIG_ENV_OFFSET_REDUND
Simon Glass4bc2ad22017-08-03 12:21:56 -0600236 gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : ENV_REDUND;
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000237#endif
238
Stephen Warren27ee0f32012-07-30 10:55:44 +0000239fini:
240 fini_mmc_for_env(mmc);
241 return ret;
Terry Lvb4eceac2010-05-17 10:57:01 +0800242}
Frank Wunderlich81f087e2019-06-29 11:36:20 +0200243
244#if defined(CONFIG_CMD_ERASEENV)
245static inline int erase_env(struct mmc *mmc, unsigned long size,
246 unsigned long offset)
247{
248 uint blk_start, blk_cnt, n;
249 struct blk_desc *desc = mmc_get_blk_desc(mmc);
250
251 blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
252 blk_cnt = ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
253
254 n = blk_derase(desc, blk_start, blk_cnt);
255 printf("%d blocks erased: %s\n", n, (n == blk_cnt) ? "OK" : "ERROR");
256
257 return (n == blk_cnt) ? 0 : 1;
258}
259
260static int env_mmc_erase(void)
261{
262 int dev = mmc_get_env_dev();
263 struct mmc *mmc = find_mmc_device(dev);
264 int ret, copy = 0;
265 u32 offset;
266 const char *errmsg;
267
268 errmsg = init_mmc_for_env(mmc);
269 if (errmsg) {
270 printf("%s\n", errmsg);
271 return 1;
272 }
273
274 if (mmc_get_env_addr(mmc, copy, &offset))
275 return CMD_RET_FAILURE;
276
277 ret = erase_env(mmc, CONFIG_ENV_SIZE, offset);
278
279#ifdef CONFIG_ENV_OFFSET_REDUND
280 copy = 1;
281
282 if (mmc_get_env_addr(mmc, copy, &offset))
283 return CMD_RET_FAILURE;
284
285 ret |= erase_env(mmc, CONFIG_ENV_SIZE, offset);
286#endif
287
288 return ret;
289}
290#endif /* CONFIG_CMD_ERASEENV */
Simon Glass082af922017-08-03 12:22:01 -0600291#endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */
Terry Lvb4eceac2010-05-17 10:57:01 +0800292
Igor Grinbergecbfb622011-11-07 01:14:05 +0000293static inline int read_env(struct mmc *mmc, unsigned long size,
294 unsigned long offset, const void *buffer)
Terry Lvb4eceac2010-05-17 10:57:01 +0800295{
296 uint blk_start, blk_cnt, n;
Simon Glassda898922016-05-14 14:03:03 -0600297 struct blk_desc *desc = mmc_get_blk_desc(mmc);
Terry Lvb4eceac2010-05-17 10:57:01 +0800298
Igor Grinbergecbfb622011-11-07 01:14:05 +0000299 blk_start = ALIGN(offset, mmc->read_bl_len) / mmc->read_bl_len;
300 blk_cnt = ALIGN(size, mmc->read_bl_len) / mmc->read_bl_len;
Terry Lvb4eceac2010-05-17 10:57:01 +0800301
Simon Glassda898922016-05-14 14:03:03 -0600302 n = blk_dread(desc, blk_start, blk_cnt, (uchar *)buffer);
Terry Lvb4eceac2010-05-17 10:57:01 +0800303
304 return (n == blk_cnt) ? 0 : -1;
305}
306
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000307#ifdef CONFIG_ENV_OFFSET_REDUND
Simon Glass99778492017-08-03 12:22:17 -0600308static int env_mmc_load(void)
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000309{
310#if !defined(ENV_IS_EMBEDDED)
Tom Rinic929f822014-03-28 12:03:34 -0400311 struct mmc *mmc;
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000312 u32 offset1, offset2;
313 int read1_fail = 0, read2_fail = 0;
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000314 int ret;
Clemens Gruberf7b61442016-01-20 15:43:37 +0100315 int dev = mmc_get_env_dev();
Tim Harveyeda75c32015-05-08 14:52:09 -0700316 const char *errmsg = NULL;
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000317
Markus Niebel6ef41fd2013-10-04 15:48:03 +0200318 ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env1, 1);
319 ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env2, 1);
320
Faiz Abbasaae518f2018-02-12 19:24:31 +0530321 mmc_initialize(NULL);
322
Tom Rinic929f822014-03-28 12:03:34 -0400323 mmc = find_mmc_device(dev);
324
Tim Harveyeda75c32015-05-08 14:52:09 -0700325 errmsg = init_mmc_for_env(mmc);
326 if (errmsg) {
Simon Glass99778492017-08-03 12:22:17 -0600327 ret = -EIO;
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000328 goto err;
329 }
330
331 if (mmc_get_env_addr(mmc, 0, &offset1) ||
332 mmc_get_env_addr(mmc, 1, &offset2)) {
Simon Glass99778492017-08-03 12:22:17 -0600333 ret = -EIO;
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000334 goto fini;
335 }
336
337 read1_fail = read_env(mmc, CONFIG_ENV_SIZE, offset1, tmp_env1);
338 read2_fail = read_env(mmc, CONFIG_ENV_SIZE, offset2, tmp_env2);
339
Simon Goldschmidte07096e2018-01-31 14:47:11 +0100340 ret = env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2,
341 read2_fail);
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000342
343fini:
344 fini_mmc_for_env(mmc);
345err:
346 if (ret)
Simon Glass97385862019-08-01 09:47:00 -0600347 env_set_default(errmsg, 0);
Simon Glass99778492017-08-03 12:22:17 -0600348
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000349#endif
Simon Glass99778492017-08-03 12:22:17 -0600350 return ret;
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000351}
352#else /* ! CONFIG_ENV_OFFSET_REDUND */
Simon Glass99778492017-08-03 12:22:17 -0600353static int env_mmc_load(void)
Terry Lvb4eceac2010-05-17 10:57:01 +0800354{
355#if !defined(ENV_IS_EMBEDDED)
Tom Rinia840b8e2013-04-05 14:55:21 -0400356 ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
Tom Rinic929f822014-03-28 12:03:34 -0400357 struct mmc *mmc;
Mingkai Hua55fce32011-01-24 17:09:55 +0000358 u32 offset;
Stephen Warren27ee0f32012-07-30 10:55:44 +0000359 int ret;
Clemens Gruberf7b61442016-01-20 15:43:37 +0100360 int dev = mmc_get_env_dev();
Tim Harveyeda75c32015-05-08 14:52:09 -0700361 const char *errmsg;
Pankit Gargc2342f62019-11-19 09:49:31 +0000362 env_t *ep = NULL;
Tom Rinic929f822014-03-28 12:03:34 -0400363
Tom Rinic929f822014-03-28 12:03:34 -0400364 mmc = find_mmc_device(dev);
Stephen Warren27ee0f32012-07-30 10:55:44 +0000365
Tim Harveyeda75c32015-05-08 14:52:09 -0700366 errmsg = init_mmc_for_env(mmc);
367 if (errmsg) {
Simon Glass99778492017-08-03 12:22:17 -0600368 ret = -EIO;
Stephen Warren27ee0f32012-07-30 10:55:44 +0000369 goto err;
370 }
Terry Lvb4eceac2010-05-17 10:57:01 +0800371
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000372 if (mmc_get_env_addr(mmc, 0, &offset)) {
Simon Glass99778492017-08-03 12:22:17 -0600373 ret = -EIO;
Stephen Warren27ee0f32012-07-30 10:55:44 +0000374 goto fini;
375 }
Terry Lvb4eceac2010-05-17 10:57:01 +0800376
Tom Rinia840b8e2013-04-05 14:55:21 -0400377 if (read_env(mmc, CONFIG_ENV_SIZE, offset, buf)) {
Tim Harveyeda75c32015-05-08 14:52:09 -0700378 errmsg = "!read failed";
Simon Glass99778492017-08-03 12:22:17 -0600379 ret = -EIO;
Stephen Warren27ee0f32012-07-30 10:55:44 +0000380 goto fini;
381 }
Terry Lvb4eceac2010-05-17 10:57:01 +0800382
Simon Goldschmidt35b4c322018-01-31 14:47:12 +0100383 ret = env_import(buf, 1);
Pankit Gargc2342f62019-11-19 09:49:31 +0000384 if (!ret) {
385 ep = (env_t *)buf;
386 gd->env_addr = (ulong)&ep->data;
387 }
Stephen Warren27ee0f32012-07-30 10:55:44 +0000388
389fini:
390 fini_mmc_for_env(mmc);
391err:
392 if (ret)
Simon Glass97385862019-08-01 09:47:00 -0600393 env_set_default(errmsg, 0);
Terry Lvb4eceac2010-05-17 10:57:01 +0800394#endif
Simon Glass99778492017-08-03 12:22:17 -0600395 return ret;
Terry Lvb4eceac2010-05-17 10:57:01 +0800396}
Michael Heimpolda1d25a32013-04-10 10:36:19 +0000397#endif /* CONFIG_ENV_OFFSET_REDUND */
Simon Glassc10a88e2017-08-03 12:21:58 -0600398
399U_BOOT_ENV_LOCATION(mmc) = {
400 .location = ENVL_MMC,
Simon Glassd8273ed2017-08-03 12:22:03 -0600401 ENV_NAME("MMC")
Simon Glass082af922017-08-03 12:22:01 -0600402 .load = env_mmc_load,
Simon Glassc10a88e2017-08-03 12:21:58 -0600403#ifndef CONFIG_SPL_BUILD
Simon Glass082af922017-08-03 12:22:01 -0600404 .save = env_save_ptr(env_mmc_save),
Frank Wunderlich81f087e2019-06-29 11:36:20 +0200405#if defined(CONFIG_CMD_ERASEENV)
406 .erase = env_mmc_erase,
407#endif
Simon Glassc10a88e2017-08-03 12:21:58 -0600408#endif
Simon Glassc10a88e2017-08-03 12:21:58 -0600409};