* [PATCH 1/3] cmd: ubi: expose more APIs to public
2026-04-17 2:35 [PATCH 0/3] Add support for ubi environment to auto create volumes Weijie Gao
@ 2026-04-17 2:35 ` Weijie Gao
2026-04-18 0:47 ` Simon Glass
2026-04-17 2:35 ` [PATCH 2/3] cmd: ubi: allow creating volume with all free spaces in ubi_create_vol Weijie Gao
2026-04-17 2:35 ` [PATCH 3/3] env: ubi: add support to create environment volume if it does not exist Weijie Gao
2 siblings, 1 reply; 7+ messages in thread
From: Weijie Gao @ 2026-04-17 2:35 UTC (permalink / raw)
To: u-boot; +Cc: GSS_MTK_Uboot_upstream, Tom Rini, Marek Vasut, Weijie Gao
Export ubi_detach/ubi_create_vol/ubi_find_volume/ubi_remove_vol to
public for better ubi manipulation used by other modules.
Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
---
cmd/ubi.c | 10 +++++-----
include/ubi_uboot.h | 5 +++++
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/cmd/ubi.c b/cmd/ubi.c
index 93de6f3aea2..e7fd7165457 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -213,8 +213,8 @@ bad:
return err;
}
-static int ubi_create_vol(char *volume, int64_t size, int dynamic, int vol_id,
- bool skipcheck)
+int ubi_create_vol(char *volume, int64_t size, int dynamic, int vol_id,
+ bool skipcheck)
{
struct ubi_mkvol_req req;
int err;
@@ -247,7 +247,7 @@ static int ubi_create_vol(char *volume, int64_t size, int dynamic, int vol_id,
return ubi_create_volume(ubi, &req);
}
-static struct ubi_volume *ubi_find_volume(char *volume)
+struct ubi_volume *ubi_find_volume(char *volume)
{
struct ubi_volume *vol;
int i;
@@ -262,7 +262,7 @@ static struct ubi_volume *ubi_find_volume(char *volume)
return NULL;
}
-static int ubi_remove_vol(char *volume)
+int ubi_remove_vol(char *volume)
{
int err, reserved_pebs, i;
struct ubi_volume *vol;
@@ -635,7 +635,7 @@ static int ubi_set_skip_check(char *volume, bool skip_check)
return ubi_change_vtbl_record(ubi, vol->vol_id, &vtbl_rec);
}
-static int ubi_detach(void)
+int ubi_detach(void)
{
#ifdef CONFIG_CMD_UBIFS
/*
diff --git a/include/ubi_uboot.h b/include/ubi_uboot.h
index ea0db69c72a..36b5b69dbfd 100644
--- a/include/ubi_uboot.h
+++ b/include/ubi_uboot.h
@@ -47,9 +47,14 @@
extern int ubi_mtd_param_parse(const char *val, struct kernel_param *kp);
extern int ubi_init(void);
extern void ubi_exit(void);
+extern int ubi_detach(void);
extern int ubi_part(char *part_name, const char *vid_header_offset);
extern int ubi_volume_write(char *volume, void *buf, loff_t offset, size_t size);
extern int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t size);
+extern int ubi_create_vol(char *volume, int64_t size, int dynamic, int vol_id,
+ bool skipcheck);
+extern struct ubi_volume *ubi_find_volume(char *volume);
+extern int ubi_remove_vol(char *volume);
extern struct ubi_device *ubi_devices[];
int cmd_ubifs_mount(char *vol_name);
--
2.45.2
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 2/3] cmd: ubi: allow creating volume with all free spaces in ubi_create_vol
2026-04-17 2:35 [PATCH 0/3] Add support for ubi environment to auto create volumes Weijie Gao
2026-04-17 2:35 ` [PATCH 1/3] cmd: ubi: expose more APIs to public Weijie Gao
@ 2026-04-17 2:35 ` Weijie Gao
2026-04-18 0:47 ` Simon Glass
2026-04-17 2:35 ` [PATCH 3/3] env: ubi: add support to create environment volume if it does not exist Weijie Gao
2 siblings, 1 reply; 7+ messages in thread
From: Weijie Gao @ 2026-04-17 2:35 UTC (permalink / raw)
To: u-boot; +Cc: GSS_MTK_Uboot_upstream, Tom Rini, Marek Vasut, Weijie Gao
Although the ubi command itself supports creating volume with all
free spaces, the api ubi_create_vol() does not.
Since negative size in invalid, this patch replaces negative size
with all free space size in ubi_create_vol().
Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
---
cmd/ubi.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/cmd/ubi.c b/cmd/ubi.c
index e7fd7165457..3a1d47d1942 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -226,7 +226,11 @@ int ubi_create_vol(char *volume, int64_t size, int dynamic, int vol_id,
req.vol_id = vol_id;
req.alignment = 1;
- req.bytes = size;
+
+ if (size < 0)
+ req.bytes = ubi->avail_pebs * ubi->leb_size;
+ else
+ req.bytes = size;
strcpy(req.name, volume);
req.name_len = strlen(volume);
--
2.45.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] env: ubi: add support to create environment volume if it does not exist
2026-04-17 2:35 [PATCH 0/3] Add support for ubi environment to auto create volumes Weijie Gao
2026-04-17 2:35 ` [PATCH 1/3] cmd: ubi: expose more APIs to public Weijie Gao
2026-04-17 2:35 ` [PATCH 2/3] cmd: ubi: allow creating volume with all free spaces in ubi_create_vol Weijie Gao
@ 2026-04-17 2:35 ` Weijie Gao
2026-04-18 0:47 ` Simon Glass
2 siblings, 1 reply; 7+ messages in thread
From: Weijie Gao @ 2026-04-17 2:35 UTC (permalink / raw)
To: u-boot; +Cc: GSS_MTK_Uboot_upstream, Tom Rini, Marek Vasut, Weijie Gao
Add an option to allow environment volume being auto created if not
exist.
Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
---
env/Kconfig | 6 ++++++
env/ubi.c | 20 ++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/env/Kconfig b/env/Kconfig
index 7abd82ab6f3..cec1bf0bb11 100644
--- a/env/Kconfig
+++ b/env/Kconfig
@@ -716,6 +716,12 @@ config ENV_UBI_VOLUME_REDUND
help
Name of the redundant volume that you want to store the environment in.
+config ENV_UBI_VOLUME_CREATE
+ bool "Create UBI volume if not exist"
+ depends on ENV_IS_IN_UBI
+ help
+ Create the UBI volume if it does not exist.
+
config ENV_UBI_VID_OFFSET
int "ubi environment VID offset"
depends on ENV_IS_IN_UBI
diff --git a/env/ubi.c b/env/ubi.c
index e9865b45ebc..bbd86adf176 100644
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -103,6 +103,18 @@ static int env_ubi_save(void)
}
#endif /* CONFIG_ENV_REDUNDANT */
+int __weak env_ubi_volume_create(const char *volume)
+{
+ struct ubi_volume *vol;
+
+ vol = ubi_find_volume((char *)volume);
+ if (vol)
+ return 0;
+
+ return ubi_create_vol((char *)volume, CONFIG_ENV_SIZE, true,
+ UBI_VOL_NUM_AUTO, false);
+}
+
#ifdef CONFIG_ENV_REDUNDANT
static int env_ubi_load(void)
{
@@ -132,6 +144,11 @@ static int env_ubi_load(void)
return -EIO;
}
+ 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);
+ }
+
read1_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)tmp_env1, 0,
CONFIG_ENV_SIZE);
if (read1_fail)
@@ -169,6 +186,9 @@ static int env_ubi_load(void)
return -EIO;
}
+ if (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE))
+ env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME);
+
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);
--
2.45.2
^ permalink raw reply related [flat|nested] 7+ messages in thread