]> Git Repo - J-u-boot.git/blobdiff - env/ubi.c
Merge patch series "Add Android 14 bootflow support for AM62X and AM62P board"
[J-u-boot.git] / env / ubi.c
index 1dfdf0a8c8a41f768d07023d430d0eafe90acc63..2f4ca571edb544a9989def8fd9863b41ef0e2da6 100644 (file)
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -4,10 +4,11 @@
  *        Joe Hershberger <[email protected]>
  */
 
-#include <common.h>
+#include <asm/global_data.h>
 
 #include <command.h>
-#include <environment.h>
+#include <env.h>
+#include <env_internal.h>
 #include <errno.h>
 #include <malloc.h>
 #include <memalign.h>
 #include <ubi_uboot.h>
 #undef crc32
 
+#define _QUOTE(x) #x
+#define QUOTE(x) _QUOTE(x)
+
+#if (CONFIG_ENV_UBI_VID_OFFSET == 0)
+ #define UBI_VID_OFFSET NULL
+#else
+ #define UBI_VID_OFFSET QUOTE(CONFIG_ENV_UBI_VID_OFFSET)
+#endif
+
 DECLARE_GLOBAL_DATA_PTR;
 
+#if CONFIG_SYS_REDUNDAND_ENVIRONMENT
+#define ENV_UBI_VOLUME_REDUND CONFIG_ENV_UBI_VOLUME_REDUND
+#else
+#define ENV_UBI_VOLUME_REDUND "invalid"
+#endif
+
 #ifdef CONFIG_CMD_SAVEENV
 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
 static int env_ubi_save(void)
@@ -28,7 +44,7 @@ static int env_ubi_save(void)
        if (ret)
                return ret;
 
-       if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) {
+       if (ubi_part(CONFIG_ENV_UBI_PART, UBI_VID_OFFSET)) {
                printf("\n** Cannot find mtd partition \"%s\"\n",
                       CONFIG_ENV_UBI_PART);
                return 1;
@@ -37,7 +53,7 @@ static int env_ubi_save(void)
        if (gd->env_valid == ENV_VALID) {
                puts("Writing to redundant UBI... ");
                if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME_REDUND,
-                                    (void *)env_new, CONFIG_ENV_SIZE)) {
+                                    (void *)env_new, 0, CONFIG_ENV_SIZE)) {
                        printf("\n** Unable to write env to %s:%s **\n",
                               CONFIG_ENV_UBI_PART,
                               CONFIG_ENV_UBI_VOLUME_REDUND);
@@ -46,7 +62,7 @@ static int env_ubi_save(void)
        } else {
                puts("Writing to UBI... ");
                if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME,
-                                    (void *)env_new, CONFIG_ENV_SIZE)) {
+                                    (void *)env_new, 0, CONFIG_ENV_SIZE)) {
                        printf("\n** Unable to write env to %s:%s **\n",
                               CONFIG_ENV_UBI_PART,
                               CONFIG_ENV_UBI_VOLUME);
@@ -70,13 +86,13 @@ static int env_ubi_save(void)
        if (ret)
                return ret;
 
-       if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) {
+       if (ubi_part(CONFIG_ENV_UBI_PART, UBI_VID_OFFSET)) {
                printf("\n** Cannot find mtd partition \"%s\"\n",
                       CONFIG_ENV_UBI_PART);
                return 1;
        }
 
-       if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME, (void *)env_new,
+       if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME, (void *)env_new, 0,
                             CONFIG_ENV_SIZE)) {
                printf("\n** Unable to write env to %s:%s **\n",
                       CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
@@ -111,27 +127,27 @@ static int env_ubi_load(void)
        tmp_env1 = (env_t *)env1_buf;
        tmp_env2 = (env_t *)env2_buf;
 
-       if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) {
+       if (ubi_part(CONFIG_ENV_UBI_PART, UBI_VID_OFFSET)) {
                printf("\n** Cannot find mtd partition \"%s\"\n",
                       CONFIG_ENV_UBI_PART);
-               set_default_env(NULL, 0);
+               env_set_default(NULL, 0);
                return -EIO;
        }
 
-       read1_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)tmp_env1,
+       read1_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)tmp_env1, 0,
                                     CONFIG_ENV_SIZE);
        if (read1_fail)
                printf("\n** Unable to read env from %s:%s **\n",
                       CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
 
        read2_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME_REDUND,
-                                    (void *)tmp_env2, CONFIG_ENV_SIZE);
+                                    (void *)tmp_env2, 0, CONFIG_ENV_SIZE);
        if (read2_fail)
                printf("\n** Unable to read redundant env from %s:%s **\n",
                       CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME_REDUND);
 
        return env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2,
-                                                        read2_fail);
+                                read2_fail, H_EXTERNAL);
 }
 #else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */
 static int env_ubi_load(void)
@@ -148,27 +164,61 @@ static int env_ubi_load(void)
         */
        memset(buf, 0x0, CONFIG_ENV_SIZE);
 
-       if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) {
+       if (ubi_part(CONFIG_ENV_UBI_PART, UBI_VID_OFFSET)) {
                printf("\n** Cannot find mtd partition \"%s\"\n",
                       CONFIG_ENV_UBI_PART);
-               set_default_env(NULL, 0);
+               env_set_default(NULL, 0);
                return -EIO;
        }
 
-       if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, CONFIG_ENV_SIZE)) {
+       if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, 0, CONFIG_ENV_SIZE)) {
                printf("\n** Unable to read env from %s:%s **\n",
                       CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
-               set_default_env(NULL, 0);
+               env_set_default(NULL, 0);
                return -EIO;
        }
 
-       return env_import(buf, 1);
+       return env_import(buf, 1, H_EXTERNAL);
 }
 #endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
 
+static int env_ubi_erase(void)
+{
+       ALLOC_CACHE_ALIGN_BUFFER(char, env_buf, CONFIG_ENV_SIZE);
+       int ret = 0;
+
+       if (ubi_part(CONFIG_ENV_UBI_PART, UBI_VID_OFFSET)) {
+               printf("\n** Cannot find mtd partition \"%s\"\n",
+                      CONFIG_ENV_UBI_PART);
+               return 1;
+       }
+
+       memset(env_buf, 0x0, CONFIG_ENV_SIZE);
+
+       if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME,
+                            (void *)env_buf, 0, CONFIG_ENV_SIZE)) {
+               printf("\n** Unable to erase env to %s:%s **\n",
+                      CONFIG_ENV_UBI_PART,
+                      CONFIG_ENV_UBI_VOLUME);
+               ret = 1;
+       }
+       if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
+               if (ubi_volume_write(ENV_UBI_VOLUME_REDUND,
+                                    (void *)env_buf, 0, CONFIG_ENV_SIZE)) {
+                       printf("\n** Unable to erase env to %s:%s **\n",
+                              CONFIG_ENV_UBI_PART,
+                              ENV_UBI_VOLUME_REDUND);
+                       ret = 1;
+               }
+       }
+
+       return ret;
+}
+
 U_BOOT_ENV_LOCATION(ubi) = {
        .location       = ENVL_UBI,
        ENV_NAME("UBI")
        .load           = env_ubi_load,
        .save           = env_save_ptr(env_ubi_save),
+       .erase          = ENV_ERASE_PTR(env_ubi_erase),
 };
This page took 0.032466 seconds and 4 git commands to generate.