X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=env%2Fext4.c;h=1f6b1b5bd818ba674b8f828aa7c8af92e4b432c3;hb=5d336d1701567e5025c3010b325e633a677c30a2;hp=c6a84925d99186028ab54237606c063d9bf19e3a;hpb=4415f1d1f1c57d43f6bc8ff156554c2b2da45b52;p=oweals%2Fu-boot.git diff --git a/env/ext4.c b/env/ext4.c index c6a84925d9..1f6b1b5bd8 100644 --- a/env/ext4.c +++ b/env/ext4.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (c) Copyright 2016 by VRT Technology * @@ -15,14 +16,13 @@ * EXT4 filesystem implementation in Uboot by * Uma Shankar * Manjunatha C Achar - * - * SPDX-License-Identifier: GPL-2.0+ */ #include #include -#include +#include +#include #include #include #include @@ -31,37 +31,33 @@ #include #include -char *env_name_spec = "EXT4"; - -env_t *env_ptr; - -DECLARE_GLOBAL_DATA_PTR; - -int env_init(void) +__weak const char *env_ext4_get_intf(void) { - /* use default */ - gd->env_addr = (ulong)&default_environment[0]; - gd->env_valid = ENV_VALID; + return (const char *)CONFIG_ENV_EXT4_INTERFACE; +} - return 0; +__weak const char *env_ext4_get_dev_part(void) +{ + return (const char *)CONFIG_ENV_EXT4_DEVICE_AND_PART; } #ifdef CONFIG_CMD_SAVEENV -int saveenv(void) +static int env_ext4_save(void) { env_t env_new; struct blk_desc *dev_desc = NULL; disk_partition_t info; int dev, part; int err; + const char *ifname = env_ext4_get_intf(); + const char *dev_and_part = env_ext4_get_dev_part(); err = env_export(&env_new); if (err) return err; - part = blk_get_device_part_str(EXT4_ENV_INTERFACE, - EXT4_ENV_DEVICE_AND_PART, - &dev_desc, &info, 1); + part = blk_get_device_part_str(ifname, dev_and_part, + &dev_desc, &info, 1); if (part < 0) return 1; @@ -70,16 +66,17 @@ int saveenv(void) if (!ext4fs_mount(info.size)) { printf("\n** Unable to use %s %s for saveenv **\n", - EXT4_ENV_INTERFACE, EXT4_ENV_DEVICE_AND_PART); + ifname, dev_and_part); return 1; } - err = ext4fs_write(EXT4_ENV_FILE, (void *)&env_new, sizeof(env_t)); + err = ext4fs_write(CONFIG_ENV_EXT4_FILE, (void *)&env_new, + sizeof(env_t), FILETYPE_REG); ext4fs_close(); if (err == -1) { printf("\n** Unable to write \"%s\" from %s%d:%d **\n", - EXT4_ENV_FILE, EXT4_ENV_INTERFACE, dev, part); + CONFIG_ENV_EXT4_FILE, ifname, dev, part); return 1; } @@ -88,7 +85,7 @@ int saveenv(void) } #endif /* CONFIG_CMD_SAVEENV */ -void env_relocate_spec(void) +static int env_ext4_load(void) { ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); struct blk_desc *dev_desc = NULL; @@ -96,10 +93,16 @@ void env_relocate_spec(void) int dev, part; int err; loff_t off; + const char *ifname = env_ext4_get_intf(); + const char *dev_and_part = env_ext4_get_dev_part(); - part = blk_get_device_part_str(EXT4_ENV_INTERFACE, - EXT4_ENV_DEVICE_AND_PART, - &dev_desc, &info, 1); +#ifdef CONFIG_MMC + if (!strcmp(ifname, "mmc")) + mmc_initialize(NULL); +#endif + + part = blk_get_device_part_str(ifname, dev_and_part, + &dev_desc, &info, 1); if (part < 0) goto err_env_relocate; @@ -108,30 +111,31 @@ void env_relocate_spec(void) if (!ext4fs_mount(info.size)) { printf("\n** Unable to use %s %s for loading the env **\n", - EXT4_ENV_INTERFACE, EXT4_ENV_DEVICE_AND_PART); + ifname, dev_and_part); goto err_env_relocate; } - err = ext4_read_file(EXT4_ENV_FILE, buf, 0, CONFIG_ENV_SIZE, &off); + err = ext4_read_file(CONFIG_ENV_EXT4_FILE, buf, 0, CONFIG_ENV_SIZE, + &off); ext4fs_close(); if (err == -1) { printf("\n** Unable to read \"%s\" from %s%d:%d **\n", - EXT4_ENV_FILE, EXT4_ENV_INTERFACE, dev, part); + CONFIG_ENV_EXT4_FILE, ifname, dev, part); goto err_env_relocate; } - env_import(buf, 1); - return; + return env_import(buf, 1); err_env_relocate: - set_default_env(NULL); + env_set_default(NULL, 0); + + return -EIO; } U_BOOT_ENV_LOCATION(ext4) = { .location = ENVL_EXT4, - .get_char = env_get_char_spec, - .load = env_relocate_spec, - .save = env_save_ptr(saveenv), - .init = env_init, + ENV_NAME("EXT4") + .load = env_ext4_load, + .save = env_save_ptr(env_ext4_save), };