100-26-env-ubi-add-support-to-create-environment-volume-if-.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. From fc0c70a7c6a088072d0c77e5a59d5e9b7754c6db Mon Sep 17 00:00:00 2001
  2. From: Weijie Gao <[email protected]>
  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. Add an option to allow environment volume being auto created if not exist.
  7. Signed-off-by: Weijie Gao <[email protected]>
  8. ---
  9. env/Kconfig | 6 ++++++
  10. env/ubi.c | 20 ++++++++++++++++++++
  11. 2 files changed, 26 insertions(+)
  12. --- a/env/Kconfig
  13. +++ b/env/Kconfig
  14. @@ -689,6 +689,12 @@ config ENV_UBI_VOLUME_REDUND
  15. help
  16. Name of the redundant volume that you want to store the environment in.
  17. +config ENV_UBI_VOLUME_CREATE
  18. + bool "Create UBI volume if not exist"
  19. + depends on ENV_IS_IN_UBI
  20. + help
  21. + Create the UBI volume if it does not exist.
  22. +
  23. config ENV_UBI_VID_OFFSET
  24. int "ubi environment VID offset"
  25. depends on ENV_IS_IN_UBI
  26. --- a/env/ubi.c
  27. +++ b/env/ubi.c
  28. @@ -106,6 +106,18 @@ static int env_ubi_save(void)
  29. #endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
  30. #endif /* CONFIG_CMD_SAVEENV */
  31. +int __weak env_ubi_volume_create(const char *volume)
  32. +{
  33. + struct ubi_volume *vol;
  34. +
  35. + vol = ubi_find_volume((char *)volume);
  36. + if (vol)
  37. + return 0;
  38. +
  39. + return ubi_create_vol((char *)volume, CONFIG_ENV_SIZE, true,
  40. + UBI_VOL_NUM_AUTO, false);
  41. +}
  42. +
  43. #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
  44. static int env_ubi_load(void)
  45. {
  46. @@ -135,6 +147,11 @@ static int env_ubi_load(void)
  47. return -EIO;
  48. }
  49. + if (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE)) {
  50. + env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME);
  51. + env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME_REDUND);
  52. + }
  53. +
  54. read1_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)tmp_env1,
  55. CONFIG_ENV_SIZE);
  56. if (read1_fail)
  57. @@ -172,6 +189,9 @@ static int env_ubi_load(void)
  58. return -EIO;
  59. }
  60. + if (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE))
  61. + env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME);
  62. +
  63. if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, CONFIG_ENV_SIZE)) {
  64. printf("\n** Unable to read env from %s:%s **\n",
  65. CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);