[PATCH v2 8/8] env: ubi: add support to create environment volume if it does not exist

Simon Glass sjg at chromium.org
Wed Apr 22 00:48:13 CEST 2026


Hi Weijie,

On 2026-04-21T08:35:39, Weijie Gao <weijie.gao at mediatek.com> wrote:
> env: ubi: add support to create environment volume if it does not exist
>
> Add an option to allow environment volume being auto created if not
> exist.
>
> Signed-off-by: Weijie Gao <weijie.gao at mediatek.com>
>
> env/Kconfig | 11 +++++++++++
>  env/ubi.c   | 30 ++++++++++++++++++++++++++++++
>  2 files changed, 41 insertions(+)

> diff --git a/env/ubi.c b/env/ubi.c
> @@ -105,6 +105,23 @@ static int env_ubi_save(void)
> +static int env_ubi_volume_create(const char *volume)
> +{
> +     struct ubi_volume *vol;
> +     int ret;
> +
> +     vol = ubi_find_volume(volume);
> +     if (vol)
> +             return 0;

You might need __maybe_unused for this function?

> diff --git a/env/ubi.c b/env/ubi.c
> @@ -134,6 +151,14 @@ static int env_ubi_load(void)
> +     if (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE)) {
> +             read1_fail = env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME);
> +             read2_fail = env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME_REDUND);
> +
> +             if (read1_fail && read2_fail)
> +                     return -ENODEV;
> +     }

Re-using read1_fail and read2_fail for volume creation is confusing.
Please can you use separate variables (e.g. create1_fail).

Also, when both volumes fail to create, you return -ENODEV without
calling env_set_default(), but the other error paths in this function
all call env_set_default() before returning.

> diff --git a/env/ubi.c b/env/ubi.c
> @@ -171,6 +196,11 @@ static int env_ubi_load(void)
> +     if (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE)) {
> +             if (env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME))
> +                     return -ENODEV;
> +     }

same here, env_set_default() should be called before returning -ENODEV

Regards,
Simon


More information about the U-Boot mailing list