bc164f4dd5d3ef583502028e49f6b7c566d5dece
[openwrt/staging/dangole.git] /
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
5 it does not exist
6
7 Add an option to allow environment volume being auto created if not exist.
8
9 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
10 ---
11 env/Kconfig | 6 ++++++
12 env/ubi.c | 20 ++++++++++++++++++++
13 2 files changed, 26 insertions(+)
14
15 --- a/env/Kconfig
16 +++ b/env/Kconfig
17 @@ -665,6 +665,12 @@ config ENV_UBI_VOLUME_REDUND
18 help
19 Name of the redundant volume that you want to store the environment in.
20
21 +config ENV_UBI_VOLUME_CREATE
22 + bool "Create UBI volume if not exist"
23 + depends on ENV_IS_IN_UBI
24 + help
25 + Create the UBI volume if it does not exist.
26 +
27 config ENV_UBI_VID_OFFSET
28 int "ubi environment VID offset"
29 depends on ENV_IS_IN_UBI
30 --- a/env/ubi.c
31 +++ b/env/ubi.c
32 @@ -100,6 +100,18 @@ static int env_ubi_save(void)
33 #endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
34 #endif /* CONFIG_CMD_SAVEENV */
35
36 +int __weak env_ubi_volume_create(const char *volume)
37 +{
38 + struct ubi_volume *vol;
39 +
40 + vol = ubi_find_volume((char *)volume);
41 + if (vol)
42 + return 0;
43 +
44 + return ubi_create_vol((char *)volume, CONFIG_ENV_SIZE, true,
45 + UBI_VOL_NUM_AUTO, false);
46 +}
47 +
48 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
49 static int env_ubi_load(void)
50 {
51 @@ -129,6 +141,11 @@ static int env_ubi_load(void)
52 return -EIO;
53 }
54
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);
58 + }
59 +
60 read1_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)tmp_env1,
61 CONFIG_ENV_SIZE);
62 if (read1_fail)
63 @@ -166,6 +183,9 @@ static int env_ubi_load(void)
64 return -EIO;
65 }
66
67 + if (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE))
68 + env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME);
69 +
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);