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

Weijie Gao weijie.gao at mediatek.com
Mon Apr 20 09:27:52 CEST 2026


On Sat, 2026-04-18 at 12:47 +1200, Simon Glass wrote:
> Hi Weijie,
> 
> On 2026-04-17T02:35:14, 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 |  6 ++++++
> >  env/ubi.c   | 20 ++++++++++++++++++++
> >  2 files changed, 26 insertions(+)
> 
> Could you beef up the Kconfig help text for ENV_UBI_VOLUME_CREATE -
> e.g. mention when users might want to enable this, such as on first
> boot of a fresh device where the UBI partition exists but no volumes
> have been created yet.

OK.

> 
> > diff --git a/env/ubi.c b/env/ubi.c
> > @@ -105,6 +105,18 @@ static int env_ubi_save(void)
> > +int __weak env_ubi_volume_create(const char *volume)
> > +{
> > +     struct ubi_volume *vol;
> > +
> > +     vol = ubi_find_volume((char *)volume);
> 
> Does this function need to be weak?

Is unnecessary at all. I added in my early test.

> 
> ubi_find_volume() prints "Volume %s not found!" when the volume does
> not exist. Since the whole point of this function is to handle
> missing
> volumes, this message will appear every time auto-creation is used.
> Please can you either add a quiet variant of ubi_find_volume(), or
> suppress the message here?

As I replied in 2/3, I'll move these messages into the main command
function.

> 
> > diff --git a/env/ubi.c b/env/ubi.c
> > @@ -134,6 +146,11 @@ static int env_ubi_load(void)
> > +     if (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE)) {
> > +             env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME);
> > +             env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME_REDUND);
> > +     }
> 
> The return value from env_ubi_volume_create() is not checked. If
> volume creation fails (e.g. no space left), the subsequent
> ubi_volume_read() will also fail, but the error message will not
> indicate the underlying problem. Please can you check the return
> value
> and print an appropriate message if creation fails?

OK.

> 
> Regards,
> Simon



More information about the U-Boot mailing list