1 From fc0c70a7c6a088072d0c77e5a59d5e9b7754c6db Mon Sep 17 00:00:00 2001
2 From: Weijie Gao <weijie.gao@mediatek.com>
3 Date: Mon, 25 Jul 2022 17:01:20 +0800
4 Subject: [PATCH 61/71] env: ubi: add support to create environment volume if
7 Add an option to allow environment volume being auto created if not exist.
9 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
11 env/Kconfig | 6 ++++++
12 env/ubi.c | 20 ++++++++++++++++++++
13 2 files changed, 26 insertions(+)
17 @@ -665,6 +665,12 @@ config ENV_UBI_VOLUME_REDUND
19 Name of the redundant volume that you want to store the environment in.
21 +config ENV_UBI_VOLUME_CREATE
22 + bool "Create UBI volume if not exist"
23 + depends on ENV_IS_IN_UBI
25 + Create the UBI volume if it does not exist.
27 config ENV_UBI_VID_OFFSET
28 int "ubi environment VID offset"
29 depends on ENV_IS_IN_UBI
32 @@ -100,6 +100,18 @@ static int env_ubi_save(void)
33 #endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
34 #endif /* CONFIG_CMD_SAVEENV */
36 +int __weak env_ubi_volume_create(const char *volume)
38 + struct ubi_volume *vol;
40 + vol = ubi_find_volume((char *)volume);
44 + return ubi_create_vol((char *)volume, CONFIG_ENV_SIZE, true,
45 + UBI_VOL_NUM_AUTO, false);
48 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
49 static int env_ubi_load(void)
51 @@ -129,6 +141,11 @@ static int env_ubi_load(void)
55 + if (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE)) {
56 + env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME);
57 + env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME_REDUND);
60 read1_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)tmp_env1,
63 @@ -166,6 +183,9 @@ static int env_ubi_load(void)
67 + if (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE))
68 + env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME);
70 if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, CONFIG_ENV_SIZE)) {
71 printf("\n** Unable to read env from %s:%s **\n",
72 CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);