2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2010-05-17 02:57:01 +00:00
|
|
|
/*
|
2011-01-24 17:09:55 +00:00
|
|
|
* (C) Copyright 2008-2011 Freescale Semiconductor, Inc.
|
2010-05-17 02:57:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* #define DEBUG */
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2010-05-17 02:57:01 +00:00
|
|
|
|
|
|
|
#include <command.h>
|
2019-08-01 15:47:00 +00:00
|
|
|
#include <env.h>
|
2019-08-02 15:44:25 +00:00
|
|
|
#include <env_internal.h>
|
2017-05-15 22:16:31 +00:00
|
|
|
#include <fdtdec.h>
|
2010-05-17 02:57:01 +00:00
|
|
|
#include <linux/stddef.h>
|
|
|
|
#include <malloc.h>
|
2015-09-02 23:24:58 +00:00
|
|
|
#include <memalign.h>
|
2010-05-17 02:57:01 +00:00
|
|
|
#include <mmc.h>
|
2017-11-06 13:16:37 +00:00
|
|
|
#include <part.h>
|
2010-11-09 23:39:23 +00:00
|
|
|
#include <search.h>
|
2010-10-13 03:07:21 +00:00
|
|
|
#include <errno.h>
|
2021-08-07 13:24:01 +00:00
|
|
|
#include <dm/ofnode.h>
|
2010-05-17 02:57:01 +00:00
|
|
|
|
2017-11-06 13:16:37 +00:00
|
|
|
#define __STR(X) #X
|
|
|
|
#define STR(X) __STR(X)
|
|
|
|
|
2010-05-17 02:57:01 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2017-05-15 22:16:31 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
2020-06-15 08:38:57 +00:00
|
|
|
static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
|
2017-11-06 13:16:37 +00:00
|
|
|
{
|
2020-05-10 17:39:57 +00:00
|
|
|
struct disk_partition info;
|
2017-11-06 13:16:37 +00:00
|
|
|
struct blk_desc *desc;
|
|
|
|
int len, i, ret;
|
2020-06-15 08:38:55 +00:00
|
|
|
char dev_str[4];
|
2017-11-06 13:16:37 +00:00
|
|
|
|
2020-06-15 08:38:55 +00:00
|
|
|
snprintf(dev_str, sizeof(dev_str), "%d", mmc_get_env_dev());
|
|
|
|
ret = blk_get_device_by_str("mmc", dev_str, &desc);
|
2017-11-06 13:16:37 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
for (i = 1;;i++) {
|
|
|
|
ret = part_get_info(desc, i, &info);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2020-11-17 03:32:08 +00:00
|
|
|
if (!strncmp((const char *)info.name, str, sizeof(info.name)))
|
2017-11-06 13:16:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* round up to info.blksz */
|
2020-06-15 08:38:56 +00:00
|
|
|
len = DIV_ROUND_UP(CONFIG_ENV_SIZE, info.blksz);
|
2017-11-06 13:16:37 +00:00
|
|
|
|
|
|
|
/* use the top of the partion for the environment */
|
2020-06-15 08:38:57 +00:00
|
|
|
*val = (info.start + info.size - (1 + copy) * len) * info.blksz;
|
2017-11-06 13:16:37 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-15 22:16:31 +00:00
|
|
|
static inline s64 mmc_offset(int copy)
|
|
|
|
{
|
2017-11-06 13:16:37 +00:00
|
|
|
const struct {
|
|
|
|
const char *offset_redund;
|
|
|
|
const char *partition;
|
|
|
|
const char *offset;
|
|
|
|
} dt_prop = {
|
|
|
|
.offset_redund = "u-boot,mmc-env-offset-redundant",
|
|
|
|
.partition = "u-boot,mmc-env-partition",
|
|
|
|
.offset = "u-boot,mmc-env-offset",
|
|
|
|
};
|
2017-11-21 22:29:40 +00:00
|
|
|
s64 val = 0, defvalue;
|
2017-11-06 13:16:37 +00:00
|
|
|
const char *propname;
|
|
|
|
const char *str;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* look for the partition in mmc CONFIG_SYS_MMC_ENV_DEV */
|
2021-08-07 13:24:01 +00:00
|
|
|
str = ofnode_conf_read_str(dt_prop.partition);
|
2017-11-06 13:16:37 +00:00
|
|
|
if (str) {
|
|
|
|
/* try to place the environment at end of the partition */
|
2020-06-15 08:38:57 +00:00
|
|
|
err = mmc_offset_try_partition(str, copy, &val);
|
2017-11-06 13:16:37 +00:00
|
|
|
if (!err)
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
defvalue = CONFIG_ENV_OFFSET;
|
|
|
|
propname = dt_prop.offset;
|
2017-05-15 22:16:31 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_ENV_OFFSET_REDUND)
|
|
|
|
if (copy) {
|
|
|
|
defvalue = CONFIG_ENV_OFFSET_REDUND;
|
2017-11-06 13:16:37 +00:00
|
|
|
propname = dt_prop.offset_redund;
|
2017-05-15 22:16:31 +00:00
|
|
|
}
|
|
|
|
#endif
|
2021-08-07 13:24:01 +00:00
|
|
|
return ofnode_conf_read_int(propname, defvalue);
|
2017-05-15 22:16:31 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline s64 mmc_offset(int copy)
|
2011-01-24 17:09:55 +00:00
|
|
|
{
|
2017-05-15 22:16:31 +00:00
|
|
|
s64 offset = CONFIG_ENV_OFFSET;
|
2013-06-11 21:14:02 +00:00
|
|
|
|
2017-05-15 22:16:31 +00:00
|
|
|
#if defined(CONFIG_ENV_OFFSET_REDUND)
|
2013-04-10 10:36:19 +00:00
|
|
|
if (copy)
|
2013-06-11 21:14:02 +00:00
|
|
|
offset = CONFIG_ENV_OFFSET_REDUND;
|
2013-04-10 10:36:19 +00:00
|
|
|
#endif
|
2017-05-15 22:16:31 +00:00
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
|
|
|
|
{
|
|
|
|
s64 offset = mmc_offset(copy);
|
2013-06-11 21:14:02 +00:00
|
|
|
|
|
|
|
if (offset < 0)
|
|
|
|
offset += mmc->capacity;
|
|
|
|
|
|
|
|
*env_addr = offset;
|
|
|
|
|
2011-01-24 17:09:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-28 16:03:34 +00:00
|
|
|
#ifdef CONFIG_SYS_MMC_ENV_PART
|
2014-07-30 10:19:06 +00:00
|
|
|
__weak uint mmc_get_env_part(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
return CONFIG_SYS_MMC_ENV_PART;
|
|
|
|
}
|
|
|
|
|
2015-12-07 18:38:49 +00:00
|
|
|
static unsigned char env_mmc_orig_hwpart;
|
|
|
|
|
2014-07-30 10:19:06 +00:00
|
|
|
static int mmc_set_env_part(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
uint part = mmc_get_env_part(mmc);
|
2016-01-20 14:43:37 +00:00
|
|
|
int dev = mmc_get_env_dev();
|
2014-07-30 10:19:06 +00:00
|
|
|
int ret = 0;
|
2014-03-28 16:03:34 +00:00
|
|
|
|
2016-05-01 19:52:29 +00:00
|
|
|
env_mmc_orig_hwpart = mmc_get_blk_desc(mmc)->hwpart;
|
|
|
|
ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part);
|
2015-12-07 18:38:49 +00:00
|
|
|
if (ret)
|
|
|
|
puts("MMC partition switch failed\n");
|
2014-07-30 10:19:06 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline int mmc_set_env_part(struct mmc *mmc) {return 0; };
|
2014-03-28 16:03:34 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-08 21:52:09 +00:00
|
|
|
static const char *init_mmc_for_env(struct mmc *mmc)
|
2014-07-30 10:19:06 +00:00
|
|
|
{
|
2015-05-08 21:52:09 +00:00
|
|
|
if (!mmc)
|
2018-06-24 16:16:57 +00:00
|
|
|
return "No MMC card found";
|
2010-05-17 02:57:01 +00:00
|
|
|
|
2018-03-22 21:53:50 +00:00
|
|
|
#if CONFIG_IS_ENABLED(BLK)
|
2017-05-27 17:37:18 +00:00
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
if (blk_get_from_parent(mmc->dev, &dev))
|
2018-06-24 16:16:57 +00:00
|
|
|
return "No block device";
|
2017-05-27 17:37:18 +00:00
|
|
|
#else
|
2015-05-08 21:52:09 +00:00
|
|
|
if (mmc_init(mmc))
|
2018-06-24 16:16:57 +00:00
|
|
|
return "MMC init failed";
|
2017-04-24 02:02:04 +00:00
|
|
|
#endif
|
2015-05-08 21:52:09 +00:00
|
|
|
if (mmc_set_env_part(mmc))
|
2018-06-24 16:16:57 +00:00
|
|
|
return "MMC partition switch failed";
|
2010-05-17 02:57:01 +00:00
|
|
|
|
2015-05-08 21:52:09 +00:00
|
|
|
return NULL;
|
2010-05-17 02:57:01 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 10:55:44 +00:00
|
|
|
static void fini_mmc_for_env(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SYS_MMC_ENV_PART
|
2016-01-20 14:43:37 +00:00
|
|
|
int dev = mmc_get_env_dev();
|
2014-03-28 16:03:34 +00:00
|
|
|
|
2016-05-01 19:52:29 +00:00
|
|
|
blk_select_hwpart_devnum(IF_TYPE_MMC, dev, env_mmc_orig_hwpart);
|
2012-07-30 10:55:44 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-08-03 18:22:01 +00:00
|
|
|
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_SPL_BUILD)
|
2011-11-07 01:14:05 +00:00
|
|
|
static inline int write_env(struct mmc *mmc, unsigned long size,
|
|
|
|
unsigned long offset, const void *buffer)
|
2010-05-17 02:57:01 +00:00
|
|
|
{
|
|
|
|
uint blk_start, blk_cnt, n;
|
2016-05-14 20:03:03 +00:00
|
|
|
struct blk_desc *desc = mmc_get_blk_desc(mmc);
|
2010-05-17 02:57:01 +00:00
|
|
|
|
2011-11-07 01:14:05 +00:00
|
|
|
blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
|
|
|
|
blk_cnt = ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
|
2010-05-17 02:57:01 +00:00
|
|
|
|
2016-05-14 20:03:03 +00:00
|
|
|
n = blk_dwrite(desc, blk_start, blk_cnt, (u_char *)buffer);
|
2010-05-17 02:57:01 +00:00
|
|
|
|
|
|
|
return (n == blk_cnt) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2017-08-03 18:22:01 +00:00
|
|
|
static int env_mmc_save(void)
|
2010-05-17 02:57:01 +00:00
|
|
|
{
|
2013-04-05 18:55:21 +00:00
|
|
|
ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
|
2016-01-20 14:43:37 +00:00
|
|
|
int dev = mmc_get_env_dev();
|
|
|
|
struct mmc *mmc = find_mmc_device(dev);
|
2011-11-07 01:14:05 +00:00
|
|
|
u32 offset;
|
2013-04-10 10:36:19 +00:00
|
|
|
int ret, copy = 0;
|
2015-05-08 21:52:09 +00:00
|
|
|
const char *errmsg;
|
2010-05-17 02:57:01 +00:00
|
|
|
|
2015-05-08 21:52:09 +00:00
|
|
|
errmsg = init_mmc_for_env(mmc);
|
|
|
|
if (errmsg) {
|
|
|
|
printf("%s\n", errmsg);
|
2011-01-24 17:09:55 +00:00
|
|
|
return 1;
|
2015-05-08 21:52:09 +00:00
|
|
|
}
|
2011-01-24 17:09:55 +00:00
|
|
|
|
2014-03-05 18:59:50 +00:00
|
|
|
ret = env_export(env_new);
|
|
|
|
if (ret)
|
2012-07-30 10:55:44 +00:00
|
|
|
goto fini;
|
2013-04-10 10:36:19 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_ENV_OFFSET_REDUND
|
2017-08-03 18:21:56 +00:00
|
|
|
if (gd->env_valid == ENV_VALID)
|
2013-04-10 10:36:19 +00:00
|
|
|
copy = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mmc_get_env_addr(mmc, copy, &offset)) {
|
|
|
|
ret = 1;
|
|
|
|
goto fini;
|
|
|
|
}
|
|
|
|
|
2016-01-20 14:43:37 +00:00
|
|
|
printf("Writing to %sMMC(%d)... ", copy ? "redundant " : "", dev);
|
2012-05-24 11:38:33 +00:00
|
|
|
if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)env_new)) {
|
2010-05-17 02:57:01 +00:00
|
|
|
puts("failed\n");
|
2012-07-30 10:55:44 +00:00
|
|
|
ret = 1;
|
|
|
|
goto fini;
|
2010-05-17 02:57:01 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 10:55:44 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2013-04-10 10:36:19 +00:00
|
|
|
#ifdef CONFIG_ENV_OFFSET_REDUND
|
2017-08-03 18:21:56 +00:00
|
|
|
gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : ENV_REDUND;
|
2013-04-10 10:36:19 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-30 10:55:44 +00:00
|
|
|
fini:
|
|
|
|
fini_mmc_for_env(mmc);
|
|
|
|
return ret;
|
2010-05-17 02:57:01 +00:00
|
|
|
}
|
2019-06-29 09:36:20 +00:00
|
|
|
|
|
|
|
static inline int erase_env(struct mmc *mmc, unsigned long size,
|
|
|
|
unsigned long offset)
|
|
|
|
{
|
|
|
|
uint blk_start, blk_cnt, n;
|
|
|
|
struct blk_desc *desc = mmc_get_blk_desc(mmc);
|
|
|
|
|
|
|
|
blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
|
|
|
|
blk_cnt = ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
|
|
|
|
|
|
|
|
n = blk_derase(desc, blk_start, blk_cnt);
|
|
|
|
printf("%d blocks erased: %s\n", n, (n == blk_cnt) ? "OK" : "ERROR");
|
|
|
|
|
|
|
|
return (n == blk_cnt) ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int env_mmc_erase(void)
|
|
|
|
{
|
|
|
|
int dev = mmc_get_env_dev();
|
|
|
|
struct mmc *mmc = find_mmc_device(dev);
|
|
|
|
int ret, copy = 0;
|
|
|
|
u32 offset;
|
|
|
|
const char *errmsg;
|
|
|
|
|
|
|
|
errmsg = init_mmc_for_env(mmc);
|
|
|
|
if (errmsg) {
|
|
|
|
printf("%s\n", errmsg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mmc_get_env_addr(mmc, copy, &offset))
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
|
|
|
ret = erase_env(mmc, CONFIG_ENV_SIZE, offset);
|
|
|
|
|
|
|
|
#ifdef CONFIG_ENV_OFFSET_REDUND
|
|
|
|
copy = 1;
|
|
|
|
|
|
|
|
if (mmc_get_env_addr(mmc, copy, &offset))
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
|
|
|
ret |= erase_env(mmc, CONFIG_ENV_SIZE, offset);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2017-08-03 18:22:01 +00:00
|
|
|
#endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */
|
2010-05-17 02:57:01 +00:00
|
|
|
|
2011-11-07 01:14:05 +00:00
|
|
|
static inline int read_env(struct mmc *mmc, unsigned long size,
|
|
|
|
unsigned long offset, const void *buffer)
|
2010-05-17 02:57:01 +00:00
|
|
|
{
|
|
|
|
uint blk_start, blk_cnt, n;
|
2016-05-14 20:03:03 +00:00
|
|
|
struct blk_desc *desc = mmc_get_blk_desc(mmc);
|
2010-05-17 02:57:01 +00:00
|
|
|
|
2011-11-07 01:14:05 +00:00
|
|
|
blk_start = ALIGN(offset, mmc->read_bl_len) / mmc->read_bl_len;
|
|
|
|
blk_cnt = ALIGN(size, mmc->read_bl_len) / mmc->read_bl_len;
|
2010-05-17 02:57:01 +00:00
|
|
|
|
2016-05-14 20:03:03 +00:00
|
|
|
n = blk_dread(desc, blk_start, blk_cnt, (uchar *)buffer);
|
2010-05-17 02:57:01 +00:00
|
|
|
|
|
|
|
return (n == blk_cnt) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2013-04-10 10:36:19 +00:00
|
|
|
#ifdef CONFIG_ENV_OFFSET_REDUND
|
2017-08-03 18:22:17 +00:00
|
|
|
static int env_mmc_load(void)
|
2013-04-10 10:36:19 +00:00
|
|
|
{
|
|
|
|
#if !defined(ENV_IS_EMBEDDED)
|
2014-03-28 16:03:34 +00:00
|
|
|
struct mmc *mmc;
|
2013-04-10 10:36:19 +00:00
|
|
|
u32 offset1, offset2;
|
|
|
|
int read1_fail = 0, read2_fail = 0;
|
|
|
|
int ret;
|
2016-01-20 14:43:37 +00:00
|
|
|
int dev = mmc_get_env_dev();
|
2015-05-08 21:52:09 +00:00
|
|
|
const char *errmsg = NULL;
|
2013-04-10 10:36:19 +00:00
|
|
|
|
2013-10-04 13:48:03 +00:00
|
|
|
ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env1, 1);
|
|
|
|
ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env2, 1);
|
|
|
|
|
2018-02-12 13:54:31 +00:00
|
|
|
mmc_initialize(NULL);
|
|
|
|
|
2014-03-28 16:03:34 +00:00
|
|
|
mmc = find_mmc_device(dev);
|
|
|
|
|
2015-05-08 21:52:09 +00:00
|
|
|
errmsg = init_mmc_for_env(mmc);
|
|
|
|
if (errmsg) {
|
2017-08-03 18:22:17 +00:00
|
|
|
ret = -EIO;
|
2013-04-10 10:36:19 +00:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mmc_get_env_addr(mmc, 0, &offset1) ||
|
|
|
|
mmc_get_env_addr(mmc, 1, &offset2)) {
|
2017-08-03 18:22:17 +00:00
|
|
|
ret = -EIO;
|
2013-04-10 10:36:19 +00:00
|
|
|
goto fini;
|
|
|
|
}
|
|
|
|
|
|
|
|
read1_fail = read_env(mmc, CONFIG_ENV_SIZE, offset1, tmp_env1);
|
|
|
|
read2_fail = read_env(mmc, CONFIG_ENV_SIZE, offset2, tmp_env2);
|
|
|
|
|
2018-01-31 13:47:11 +00:00
|
|
|
ret = env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2,
|
2020-07-07 18:51:35 +00:00
|
|
|
read2_fail, H_EXTERNAL);
|
2013-04-10 10:36:19 +00:00
|
|
|
|
|
|
|
fini:
|
|
|
|
fini_mmc_for_env(mmc);
|
|
|
|
err:
|
|
|
|
if (ret)
|
2019-08-01 15:47:00 +00:00
|
|
|
env_set_default(errmsg, 0);
|
2017-08-03 18:22:17 +00:00
|
|
|
|
2013-04-10 10:36:19 +00:00
|
|
|
#endif
|
2017-08-03 18:22:17 +00:00
|
|
|
return ret;
|
2013-04-10 10:36:19 +00:00
|
|
|
}
|
|
|
|
#else /* ! CONFIG_ENV_OFFSET_REDUND */
|
2017-08-03 18:22:17 +00:00
|
|
|
static int env_mmc_load(void)
|
2010-05-17 02:57:01 +00:00
|
|
|
{
|
|
|
|
#if !defined(ENV_IS_EMBEDDED)
|
2013-04-05 18:55:21 +00:00
|
|
|
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
|
2014-03-28 16:03:34 +00:00
|
|
|
struct mmc *mmc;
|
2011-01-24 17:09:55 +00:00
|
|
|
u32 offset;
|
2012-07-30 10:55:44 +00:00
|
|
|
int ret;
|
2016-01-20 14:43:37 +00:00
|
|
|
int dev = mmc_get_env_dev();
|
2015-05-08 21:52:09 +00:00
|
|
|
const char *errmsg;
|
2019-11-19 09:49:31 +00:00
|
|
|
env_t *ep = NULL;
|
2014-03-28 16:03:34 +00:00
|
|
|
|
|
|
|
mmc = find_mmc_device(dev);
|
2010-05-17 02:57:01 +00:00
|
|
|
|
2015-05-08 21:52:09 +00:00
|
|
|
errmsg = init_mmc_for_env(mmc);
|
|
|
|
if (errmsg) {
|
2017-08-03 18:22:17 +00:00
|
|
|
ret = -EIO;
|
2012-07-30 10:55:44 +00:00
|
|
|
goto err;
|
|
|
|
}
|
2010-05-17 02:57:01 +00:00
|
|
|
|
2013-04-10 10:36:19 +00:00
|
|
|
if (mmc_get_env_addr(mmc, 0, &offset)) {
|
2017-08-03 18:22:17 +00:00
|
|
|
ret = -EIO;
|
2012-07-30 10:55:44 +00:00
|
|
|
goto fini;
|
|
|
|
}
|
|
|
|
|
2013-04-05 18:55:21 +00:00
|
|
|
if (read_env(mmc, CONFIG_ENV_SIZE, offset, buf)) {
|
2015-05-08 21:52:09 +00:00
|
|
|
errmsg = "!read failed";
|
2017-08-03 18:22:17 +00:00
|
|
|
ret = -EIO;
|
2012-07-30 10:55:44 +00:00
|
|
|
goto fini;
|
|
|
|
}
|
2010-05-17 02:57:01 +00:00
|
|
|
|
2020-07-07 18:51:35 +00:00
|
|
|
ret = env_import(buf, 1, H_EXTERNAL);
|
2019-11-19 09:49:31 +00:00
|
|
|
if (!ret) {
|
|
|
|
ep = (env_t *)buf;
|
|
|
|
gd->env_addr = (ulong)&ep->data;
|
|
|
|
}
|
2012-07-30 10:55:44 +00:00
|
|
|
|
|
|
|
fini:
|
|
|
|
fini_mmc_for_env(mmc);
|
|
|
|
err:
|
|
|
|
if (ret)
|
2019-08-01 15:47:00 +00:00
|
|
|
env_set_default(errmsg, 0);
|
2010-05-17 02:57:01 +00:00
|
|
|
#endif
|
2017-08-03 18:22:17 +00:00
|
|
|
return ret;
|
2010-05-17 02:57:01 +00:00
|
|
|
}
|
2013-04-10 10:36:19 +00:00
|
|
|
#endif /* CONFIG_ENV_OFFSET_REDUND */
|
2017-08-03 18:21:58 +00:00
|
|
|
|
|
|
|
U_BOOT_ENV_LOCATION(mmc) = {
|
|
|
|
.location = ENVL_MMC,
|
2017-08-03 18:22:03 +00:00
|
|
|
ENV_NAME("MMC")
|
2017-08-03 18:22:01 +00:00
|
|
|
.load = env_mmc_load,
|
2017-08-03 18:21:58 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
2017-08-03 18:22:01 +00:00
|
|
|
.save = env_save_ptr(env_mmc_save),
|
2021-02-09 10:48:50 +00:00
|
|
|
.erase = ENV_ERASE_PTR(env_mmc_erase)
|
2017-08-03 18:21:58 +00:00
|
|
|
#endif
|
|
|
|
};
|