diff options
Diffstat (limited to 'env/ubi.c')
| -rw-r--r-- | env/ubi.c | 65 |
1 files changed, 54 insertions, 11 deletions
diff --git a/env/ubi.c b/env/ubi.c index e9865b45ebc..810faaf7744 100644 --- a/env/ubi.c +++ b/env/ubi.c @@ -103,12 +103,30 @@ static int env_ubi_save(void) } #endif /* CONFIG_ENV_REDUNDANT */ +static int env_ubi_volume_create(const char *volume) +{ + bool dynamic = !IS_ENABLED(CONFIG_ENV_UBI_VOLUME_STATIC); + struct ubi_volume *vol; + int ret; + + vol = ubi_find_volume(volume); + if (vol) + return 0; + + ret = ubi_create_vol(volume, CONFIG_ENV_SIZE, dynamic, UBI_VOL_NUM_AUTO, + false); + if (ret) + printf("Failed to create environment volume '%s'\n", volume); + + return ret; +} + #ifdef CONFIG_ENV_REDUNDANT static int env_ubi_load(void) { ALLOC_CACHE_ALIGN_BUFFER(char, env1_buf, CONFIG_ENV_SIZE); ALLOC_CACHE_ALIGN_BUFFER(char, env2_buf, CONFIG_ENV_SIZE); - int read1_fail, read2_fail; + int read1_fail, read2_fail, create1_fail = 0, create2_fail = 0; env_t *tmp_env1, *tmp_env2; /* @@ -132,17 +150,35 @@ static int env_ubi_load(void) return -EIO; } - 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); + if (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE)) { + create1_fail = env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME); + create2_fail = env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME_REDUND); + if (create1_fail && create2_fail) { + env_set_default(NULL, 0); + return -ENODEV; + } + } - read2_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME_REDUND, - (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); + if (!create1_fail) { + read1_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME, 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); + } else { + read1_fail = create1_fail; + } + + if (!create2_fail) { + read2_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME_REDUND, + 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); + } else { + read2_fail = create2_fail; + } return env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2, read2_fail, H_EXTERNAL); @@ -169,6 +205,13 @@ static int env_ubi_load(void) return -EIO; } + if (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE)) { + if (env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME)) { + env_set_default(NULL, 0); + return -ENODEV; + } + } + 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); |
