From e44e3482bdb4d0ebde2d8b41830ac2cdb07948fb Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Fri, 28 Aug 2015 09:58:54 +0800 Subject: Add qemu 2.4.0 Change-Id: Ic99cbad4b61f8b127b7dc74d04576c0bcbaaf4f5 Signed-off-by: Yang Zhang --- qemu/roms/u-boot/common/env_fat.c | 137 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 qemu/roms/u-boot/common/env_fat.c (limited to 'qemu/roms/u-boot/common/env_fat.c') diff --git a/qemu/roms/u-boot/common/env_fat.c b/qemu/roms/u-boot/common/env_fat.c new file mode 100644 index 000000000..aad0487c3 --- /dev/null +++ b/qemu/roms/u-boot/common/env_fat.c @@ -0,0 +1,137 @@ +/* + * (c) Copyright 2011 by Tigris Elektronik GmbH + * + * Author: + * Maximilian Schwerin + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +char *env_name_spec = "FAT"; + +env_t *env_ptr; + +DECLARE_GLOBAL_DATA_PTR; + +int env_init(void) +{ + /* use default */ + gd->env_addr = (ulong)&default_environment[0]; + gd->env_valid = 1; + + return 0; +} + +#ifdef CONFIG_CMD_SAVEENV +int saveenv(void) +{ + env_t env_new; + block_dev_desc_t *dev_desc = NULL; + int dev = FAT_ENV_DEVICE; + int part = FAT_ENV_PART; + int err; + + err = env_export(&env_new); + if (err) + return err; + +#ifdef CONFIG_MMC + if (strcmp(FAT_ENV_INTERFACE, "mmc") == 0) { + struct mmc *mmc = find_mmc_device(dev); + + if (!mmc) { + printf("no mmc device at slot %x\n", dev); + return 1; + } + + mmc->has_init = 0; + mmc_init(mmc); + } +#endif /* CONFIG_MMC */ + + dev_desc = get_dev(FAT_ENV_INTERFACE, dev); + if (dev_desc == NULL) { + printf("Failed to find %s%d\n", + FAT_ENV_INTERFACE, dev); + return 1; + } + + err = fat_register_device(dev_desc, part); + if (err) { + printf("Failed to register %s%d:%d\n", + FAT_ENV_INTERFACE, dev, part); + return 1; + } + + err = file_fat_write(FAT_ENV_FILE, (void *)&env_new, sizeof(env_t)); + if (err == -1) { + printf("\n** Unable to write \"%s\" from %s%d:%d **\n", + FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part); + return 1; + } + + puts("done\n"); + return 0; +} +#endif /* CONFIG_CMD_SAVEENV */ + +void env_relocate_spec(void) +{ + char buf[CONFIG_ENV_SIZE]; + block_dev_desc_t *dev_desc = NULL; + int dev = FAT_ENV_DEVICE; + int part = FAT_ENV_PART; + int err; + +#ifdef CONFIG_MMC + if (strcmp(FAT_ENV_INTERFACE, "mmc") == 0) { + struct mmc *mmc = find_mmc_device(dev); + + if (!mmc) { + printf("no mmc device at slot %x\n", dev); + set_default_env(NULL); + return; + } + + mmc->has_init = 0; + mmc_init(mmc); + } +#endif /* CONFIG_MMC */ + + dev_desc = get_dev(FAT_ENV_INTERFACE, dev); + if (dev_desc == NULL) { + printf("Failed to find %s%d\n", + FAT_ENV_INTERFACE, dev); + set_default_env(NULL); + return; + } + + err = fat_register_device(dev_desc, part); + if (err) { + printf("Failed to register %s%d:%d\n", + FAT_ENV_INTERFACE, dev, part); + set_default_env(NULL); + return; + } + + err = file_fat_read(FAT_ENV_FILE, (uchar *)&buf, CONFIG_ENV_SIZE); + if (err == -1) { + printf("\n** Unable to read \"%s\" from %s%d:%d **\n", + FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part); + set_default_env(NULL); + return; + } + + env_import(buf, 1); +} -- cgit 1.2.3-korg