2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-03-12 23:57:50 +00:00
|
|
|
/*
|
|
|
|
* (c) Copyright 2011 by Tigris Elektronik GmbH
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Maximilian Schwerin <mvs@tigris.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2012-03-12 23:57:50 +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>
|
2012-03-12 23:57:50 +00:00
|
|
|
#include <linux/stddef.h>
|
|
|
|
#include <malloc.h>
|
2015-09-02 23:24:58 +00:00
|
|
|
#include <memalign.h>
|
2012-03-12 23:57:50 +00:00
|
|
|
#include <search.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fat.h>
|
|
|
|
#include <mmc.h>
|
|
|
|
|
2017-08-03 18:21:58 +00:00
|
|
|
#ifdef CONFIG_SPL_BUILD
|
|
|
|
/* TODO(sjg@chromium.org): Figure out why this is needed */
|
|
|
|
# if !defined(CONFIG_TARGET_AM335X_EVM) || defined(CONFIG_SPL_OS_BOOT)
|
|
|
|
# define LOADENV
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# define LOADENV
|
|
|
|
#endif
|
|
|
|
|
2017-08-03 18:22:01 +00:00
|
|
|
static int env_fat_save(void)
|
2012-03-12 23:57:50 +00:00
|
|
|
{
|
2018-02-07 20:01:54 +00:00
|
|
|
env_t __aligned(ARCH_DMA_MINALIGN) env_new;
|
2016-02-29 22:25:34 +00:00
|
|
|
struct blk_desc *dev_desc = NULL;
|
2020-05-10 17:39:57 +00:00
|
|
|
struct disk_partition info;
|
2014-06-24 09:31:02 +00:00
|
|
|
int dev, part;
|
2012-09-23 05:25:21 +00:00
|
|
|
int err;
|
2014-11-17 22:39:35 +00:00
|
|
|
loff_t size;
|
2012-03-12 23:57:50 +00:00
|
|
|
|
2014-03-05 18:59:50 +00:00
|
|
|
err = env_export(&env_new);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2012-03-12 23:57:50 +00:00
|
|
|
|
2017-07-27 01:48:00 +00:00
|
|
|
part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
|
|
|
|
CONFIG_ENV_FAT_DEVICE_AND_PART,
|
2014-06-24 09:31:02 +00:00
|
|
|
&dev_desc, &info, 1);
|
|
|
|
if (part < 0)
|
2012-03-12 23:57:50 +00:00
|
|
|
return 1;
|
2012-09-23 05:25:21 +00:00
|
|
|
|
2016-02-29 22:25:51 +00:00
|
|
|
dev = dev_desc->devnum;
|
2014-06-24 09:31:02 +00:00
|
|
|
if (fat_set_blk_dev(dev_desc, &info) != 0) {
|
2018-01-23 20:16:55 +00:00
|
|
|
/*
|
|
|
|
* This printf is embedded in the messages from env_save that
|
|
|
|
* will calling it. The missing \n is intentional.
|
|
|
|
*/
|
|
|
|
printf("Unable to use %s %d:%d... ",
|
2017-07-27 01:48:00 +00:00
|
|
|
CONFIG_ENV_FAT_INTERFACE, dev, part);
|
2012-03-12 23:57:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:48:00 +00:00
|
|
|
err = file_fat_write(CONFIG_ENV_FAT_FILE, (void *)&env_new, 0, sizeof(env_t),
|
2014-11-17 22:39:35 +00:00
|
|
|
&size);
|
2012-09-23 05:25:21 +00:00
|
|
|
if (err == -1) {
|
2018-01-23 20:16:55 +00:00
|
|
|
/*
|
|
|
|
* This printf is embedded in the messages from env_save that
|
|
|
|
* will calling it. The missing \n is intentional.
|
|
|
|
*/
|
|
|
|
printf("Unable to write \"%s\" from %s%d:%d... ",
|
2017-07-27 01:48:00 +00:00
|
|
|
CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
|
2012-03-12 23:57:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-03 18:21:58 +00:00
|
|
|
#ifdef LOADENV
|
2017-08-03 18:22:17 +00:00
|
|
|
static int env_fat_load(void)
|
2012-03-12 23:57:50 +00:00
|
|
|
{
|
2014-08-01 17:59:10 +00:00
|
|
|
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
|
2016-02-29 22:25:34 +00:00
|
|
|
struct blk_desc *dev_desc = NULL;
|
2020-05-10 17:39:57 +00:00
|
|
|
struct disk_partition info;
|
2014-06-24 09:31:02 +00:00
|
|
|
int dev, part;
|
2012-09-23 05:25:21 +00:00
|
|
|
int err;
|
2012-03-12 23:57:50 +00:00
|
|
|
|
2018-04-14 13:41:00 +00:00
|
|
|
#ifdef CONFIG_MMC
|
2018-02-12 13:54:31 +00:00
|
|
|
if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc"))
|
|
|
|
mmc_initialize(NULL);
|
2018-04-14 13:41:00 +00:00
|
|
|
#endif
|
2018-02-12 13:54:31 +00:00
|
|
|
|
2017-07-27 01:48:00 +00:00
|
|
|
part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
|
|
|
|
CONFIG_ENV_FAT_DEVICE_AND_PART,
|
2014-06-24 09:31:02 +00:00
|
|
|
&dev_desc, &info, 1);
|
|
|
|
if (part < 0)
|
|
|
|
goto err_env_relocate;
|
|
|
|
|
2016-02-29 22:25:51 +00:00
|
|
|
dev = dev_desc->devnum;
|
2014-06-24 09:31:02 +00:00
|
|
|
if (fat_set_blk_dev(dev_desc, &info) != 0) {
|
2018-01-23 20:16:55 +00:00
|
|
|
/*
|
|
|
|
* This printf is embedded in the messages from env_save that
|
|
|
|
* will calling it. The missing \n is intentional.
|
|
|
|
*/
|
|
|
|
printf("Unable to use %s %d:%d... ",
|
2017-07-27 01:48:00 +00:00
|
|
|
CONFIG_ENV_FAT_INTERFACE, dev, part);
|
2014-06-24 09:31:02 +00:00
|
|
|
goto err_env_relocate;
|
2012-03-12 23:57:50 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 01:48:00 +00:00
|
|
|
err = file_fat_read(CONFIG_ENV_FAT_FILE, buf, CONFIG_ENV_SIZE);
|
2012-09-23 05:25:21 +00:00
|
|
|
if (err == -1) {
|
2018-01-23 20:16:55 +00:00
|
|
|
/*
|
|
|
|
* This printf is embedded in the messages from env_save that
|
|
|
|
* will calling it. The missing \n is intentional.
|
|
|
|
*/
|
|
|
|
printf("Unable to read \"%s\" from %s%d:%d... ",
|
2017-07-27 01:48:00 +00:00
|
|
|
CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
|
2014-06-24 09:31:02 +00:00
|
|
|
goto err_env_relocate;
|
2012-03-12 23:57:50 +00:00
|
|
|
}
|
|
|
|
|
2018-01-31 13:47:12 +00:00
|
|
|
return env_import(buf, 1);
|
2014-06-24 09:31:02 +00:00
|
|
|
|
|
|
|
err_env_relocate:
|
2019-08-01 15:47:00 +00:00
|
|
|
env_set_default(NULL, 0);
|
2017-08-03 18:22:17 +00:00
|
|
|
|
|
|
|
return -EIO;
|
2012-03-12 23:57:50 +00:00
|
|
|
}
|
2017-08-03 18:21:58 +00:00
|
|
|
#endif /* LOADENV */
|
|
|
|
|
|
|
|
U_BOOT_ENV_LOCATION(fat) = {
|
|
|
|
.location = ENVL_FAT,
|
2017-08-03 18:22:03 +00:00
|
|
|
ENV_NAME("FAT")
|
2017-08-03 18:21:58 +00:00
|
|
|
#ifdef LOADENV
|
2017-08-03 18:22:01 +00:00
|
|
|
.load = env_fat_load,
|
2017-08-03 18:21:58 +00:00
|
|
|
#endif
|
2020-02-19 09:47:41 +00:00
|
|
|
.save = ENV_SAVE_PTR(env_fat_save),
|
2017-08-03 18:21:58 +00:00
|
|
|
};
|