Most of the init() implementations just use the default environment.
Adjust env_init_new() to do this automatically, and drop the redundant
code.
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
CONFIG_ENV_SIZE);
}
-/*
- * Initialize environment use
- *
- * We are still running from ROM, so data use is limited.
- * Use a (moderately small) buffer on the stack
- */
-int env_dataflash_init(void)
-{
- /* use default */
- gd->env_addr = (ulong)&default_environment[0];
- gd->env_valid = ENV_VALID;
-
- return 0;
-}
-
U_BOOT_ENV_LOCATION(dataflash) = {
.location = ENVL_DATAFLASH,
.get_char = env_dataflash_get_char,
.load = env_dataflash_load,
.save = env_save_ptr(env_dataflash_save),
- .init = env_dataflash_init,
};
return rc;
}
-/*
- * Initialize Environment use
- *
- * We are still running from ROM, so data use is limited.
- * Use a (moderately small) buffer on the stack
- */
-static int env_eeprom_init(void)
-{
- gd->env_addr = (ulong)&default_environment[0];
- gd->env_valid = ENV_VALID;
- return 0;
-}
-
U_BOOT_ENV_LOCATION(eeprom) = {
.location = ENVL_EEPROM,
.get_char = env_eeprom_get_char,
.load = env_eeprom_load,
.save = env_save_ptr(env_eeprom_save),
- .init = env_eeprom_init,
};
int env_init_new(void)
{
struct env_driver *drv = env_driver_lookup_default();
- int ret;
+ int ret = -ENOENT;
if (!drv)
return -ENODEV;
- if (!drv->init)
- return -ENOSYS;
- ret = drv->init();
- if (ret) {
+ if (drv->init)
+ ret = drv->init();
+ if (ret == -ENOENT) {
+ gd->env_addr = (ulong)&default_environment[0];
+ gd->env_valid = 0;
+
+ return 0;
+ } else if (ret) {
debug("%s: Environment failed to init (err=%d)\n", __func__,
ret);
return ret;
DECLARE_GLOBAL_DATA_PTR;
-static int env_ext4_init(void)
-{
- /* use default */
- gd->env_addr = (ulong)&default_environment[0];
- gd->env_valid = ENV_VALID;
-
- return 0;
-}
-
#ifdef CONFIG_CMD_SAVEENV
static int env_ext4_save(void)
{
.location = ENVL_EXT4,
.load = env_ext4_load,
.save = env_save_ptr(env_ext4_save),
- .init = env_ext4_init,
};
DECLARE_GLOBAL_DATA_PTR;
-static int env_fat_init(void)
-{
- /* use default */
- gd->env_addr = (ulong)&default_environment[0];
- gd->env_valid = ENV_VALID;
-
- return 0;
-}
-
#ifdef CMD_SAVEENV
static int env_fat_save(void)
{
#ifdef CMD_SAVEENV
.save = env_save_ptr(env_fat_save),
#endif
- .init = env_fat_init,
};
return CONFIG_SYS_MMC_ENV_DEV;
}
-static int env_mmc_init(void)
-{
- /* use default */
- gd->env_addr = (ulong)&default_environment[0];
- gd->env_valid = ENV_VALID;
-
- return 0;
-}
-
#ifdef CONFIG_SYS_MMC_ENV_PART
__weak uint mmc_get_env_part(struct mmc *mmc)
{
#ifndef CONFIG_SPL_BUILD
.save = env_save_ptr(env_mmc_save),
#endif
- .init = env_mmc_init,
};
env_t *env_ptr;
-static void env_nowhere_load(void)
-{
-}
-
-/*
- * Initialize Environment use
- *
- * We are still running from ROM, so data use is limited
- */
-static int env_nowhere_init(void)
-{
- gd->env_addr = (ulong)&default_environment[0];
- gd->env_valid = 0;
-
- return 0;
-}
-
U_BOOT_ENV_LOCATION(nowhere) = {
.location = ENVL_NOWHERE,
- .load = env_nowhere_load,
- .init = env_nowhere_init,
};
return 0;
}
-static int env_onenand_init(void)
-{
- /* use default */
- gd->env_addr = (ulong)&default_environment[0];
- gd->env_valid = ENV_VALID;
-
- return 0;
-}
-
U_BOOT_ENV_LOCATION(onenand) = {
.location = ENVL_ONENAND,
.load = env_onenand_load,
.save = env_save_ptr(env_onenand_save),
- .init = env_onenand_init,
};
return 0;
}
- gd->env_addr = (ulong)default_environment;
- gd->env_valid = 0;
- return 0;
+ return -ENOENT;
}
#ifdef CONFIG_CMD_SAVEENV
return CONFIG_SYS_SATA_ENV_DEV;
}
-static int env_sata_init(void)
-{
- /* use default */
- gd->env_addr = (ulong)&default_environment[0];
- gd->env_valid = ENV_VALID;
-
- return 0;
-}
-
#ifdef CONFIG_CMD_SAVEENV
static inline int write_env(struct blk_desc *sata, unsigned long size,
unsigned long offset, void *buffer)
.location = ENVL_ESATA,
.load = env_sata_load,
.save = env_save_ptr(env_sata_save),
- .init = env_sata_init,
};
}
#endif
-static int env_sf_init(void)
-{
- /* SPI flash isn't usable before relocation */
- gd->env_addr = (ulong)&default_environment[0];
- gd->env_valid = ENV_VALID;
-
- return 0;
-}
-
U_BOOT_ENV_LOCATION(sf) = {
.location = ENVL_SPI_FLASH,
.load = env_sf_load,
#ifdef CMD_SAVEENV
.save = env_save_ptr(env_sf_save),
#endif
- .init = env_sf_init,
};
DECLARE_GLOBAL_DATA_PTR;
-static int env_ubi_init(void)
-{
- /* use default */
- gd->env_addr = (ulong)&default_environment[0];
- gd->env_valid = ENV_VALID;
-
- return 0;
-}
-
#ifdef CONFIG_CMD_SAVEENV
#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
static int env_ubi_save(void)
.location = ENVL_UBI,
.load = env_ubi_load,
.save = env_save_ptr(env_ubi_save),
- .init = env_ubi_init,
};
*
* This method is optional.
*
- * @return 0 if OK, -ve on error
+ * @return 0 if OK, -ENOENT if no initial environment could be found,
+ * other -ve on error
*/
int (*init)(void);
};