configs: Resync with savedefconfig
[platform/kernel/u-boot.git] / env / ext4.c
index 0a10a5e..9f65afb 100644 (file)
@@ -31,6 +31,7 @@
 #include <errno.h>
 #include <ext4fs.h>
 #include <mmc.h>
+#include <asm/global_data.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -41,7 +42,21 @@ __weak const char *env_ext4_get_intf(void)
 
 __weak const char *env_ext4_get_dev_part(void)
 {
+#ifdef CONFIG_MMC
+       static char *part_str;
+
+       if (!part_str) {
+               part_str = CONFIG_ENV_EXT4_DEVICE_AND_PART;
+               if (!strcmp(CONFIG_ENV_EXT4_INTERFACE, "mmc") && part_str[0] == ':') {
+                       part_str = "0" CONFIG_ENV_EXT4_DEVICE_AND_PART;
+                       part_str[0] += mmc_get_env_dev();
+               }
+       }
+
+       return part_str;
+#else
        return (const char *)CONFIG_ENV_EXT4_DEVICE_AND_PART;
+#endif
 }
 
 static int env_ext4_save_buffer(env_t *env_new)
@@ -99,6 +114,23 @@ static int env_ext4_save(void)
        return 0;
 }
 
+static int env_ext4_erase(void)
+{
+       env_t env_new;
+       int err;
+
+       memset(&env_new, 0, sizeof(env_t));
+
+       err = env_ext4_save_buffer(&env_new);
+       if (err)
+               return err;
+
+       gd->env_valid = ENV_INVALID;
+       puts("done\n");
+
+       return 0;
+}
+
 static int env_ext4_load(void)
 {
        ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
@@ -139,7 +171,7 @@ static int env_ext4_load(void)
                goto err_env_relocate;
        }
 
-       err = env_import(buf, 1);
+       err = env_import(buf, 1, H_EXTERNAL);
        if (!err)
                gd->env_valid = ENV_VALID;
 
@@ -156,4 +188,5 @@ U_BOOT_ENV_LOCATION(ext4) = {
        ENV_NAME("EXT4")
        .load           = env_ext4_load,
        .save           = ENV_SAVE_PTR(env_ext4_save),
+       .erase          = ENV_ERASE_PTR(env_ext4_erase),
 };