X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=env%2Fext4.c;h=1f6b1b5bd818ba674b8f828aa7c8af92e4b432c3;hb=0b23b0d9f969c4a587cb9ee75905d6f6f9d1d2ea;hp=65202213d3a80328f1117e5153c6178cc957ca8e;hpb=5619295995e3262bb5770e8b5e945ffdc5442145;p=oweals%2Fu-boot.git diff --git a/env/ext4.c b/env/ext4.c index 65202213d3..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,7 +31,15 @@ #include #include -DECLARE_GLOBAL_DATA_PTR; +__weak const char *env_ext4_get_intf(void) +{ + return (const char *)CONFIG_ENV_EXT4_INTERFACE; +} + +__weak const char *env_ext4_get_dev_part(void) +{ + return (const char *)CONFIG_ENV_EXT4_DEVICE_AND_PART; +} #ifdef CONFIG_CMD_SAVEENV static int env_ext4_save(void) @@ -41,14 +49,15 @@ static int env_ext4_save(void) 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; @@ -57,16 +66,17 @@ static int env_ext4_save(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; } @@ -83,10 +93,16 @@ static int env_ext4_load(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; @@ -95,24 +111,24 @@ static int env_ext4_load(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 0; + return env_import(buf, 1); err_env_relocate: - set_default_env(NULL); + env_set_default(NULL, 0); return -EIO; }