ef_cfg.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * This file is part of the EasyFlash Library.
  3. *
  4. * Copyright (c) 2015-2019, Armink, <armink.ztl@gmail.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * 'Software'), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  21. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. * Function: It is the configure head file for this library.
  26. * Created on: 2015-07-14
  27. */
  28. #ifndef EF_CFG_H_
  29. #define EF_CFG_H_
  30. #include <rtconfig.h>
  31. /* using ENV function */
  32. #ifdef PKG_EASYFLASH_ENV
  33. #define EF_USING_ENV
  34. #ifdef PKG_EASYFLASH_ENV_AUTO_UPDATE
  35. /* Auto update ENV to latest default when current ENV version number is changed. */
  36. #define EF_ENV_AUTO_UPDATE
  37. /**
  38. * ENV version number defined by user.
  39. * Please change it when your firmware add a new ENV to default_env_set.
  40. */
  41. #define EF_ENV_VER_NUM PKG_EASYFLASH_ENV_VER_NUM
  42. #endif
  43. #endif /* PKG_EASYFLASH_ENV */
  44. /* using IAP function */
  45. #ifdef PKG_EASYFLASH_IAP
  46. #define EF_USING_IAP
  47. #endif
  48. /* using save log function */
  49. #ifdef PKG_EASYFLASH_LOG
  50. #define EF_USING_LOG
  51. /* saved log area size */
  52. #define LOG_AREA_SIZE (PKG_EASYFLASH_LOG_AREA_SIZE)
  53. #endif
  54. /* the minimum size of flash erasure */
  55. #define EF_ERASE_MIN_SIZE PKG_EASYFLASH_ERASE_GRAN
  56. /* the flash write granularity, unit: bit
  57. * only support 1(nor flash)/ 8(stm32f4)/ 32(stm32f1)/ 64(stm32l4) */
  58. #define EF_WRITE_GRAN (PKG_EASYFLASH_WRITE_GRAN)
  59. /*
  60. *
  61. * This all Backup Area Flash storage index. All used flash area configure is under here.
  62. * |----------------------------| Storage Size
  63. * | Environment variables area | ENV area size @see ENV_AREA_SIZE
  64. * |----------------------------|
  65. * | Saved log area | Log area size @see LOG_AREA_SIZE
  66. * |----------------------------|
  67. * |(IAP)Downloaded application | IAP already downloaded application, unfixed size
  68. * |----------------------------|
  69. *
  70. * @note all area sizes must be aligned with EF_ERASE_MIN_SIZE
  71. *
  72. * The EasyFlash add the NG (Next Generation) mode start from V4.0. All old mode before V4.0, called LEGACY mode.
  73. *
  74. * - NG (Next Generation) mode is default mode from V4.0. It's easy to settings, only defined the ENV_AREA_SIZE.
  75. * - The LEGACY mode has been DEPRECATED. It is NOT RECOMMENDED to continue using.
  76. * Beacuse it will use ram to buffer the ENV and spend more flash erase times.
  77. * If you want use it please using the V3.X version.
  78. */
  79. /* backup area start address */
  80. #define EF_START_ADDR PKG_EASYFLASH_START_ADDR
  81. /* ENV area size. It's at least one empty sector for GC. So it's definition must more then or equal 2 flash sector size. */
  82. /* 2026-10-29:256 扇区(1MB) -> 16 扇区(64KB)。原因见 doc/readme.md 同日条目:
  83. * ef_load_env() 会遍历全部 SECTOR_NUM 个扇区(且走两遍),而 check_sec_hdr_cb()
  84. * 对每个"扇区头非法"的扇区当场 format_sector()(擦 4KB + 写头)。256 扇区时最坏
  85. * 256 × ~45ms ≈ 11.5s,表现为"开机 Flash 参数加载慢",且失败时静默重试、每次开机重来。
  86. * 本工程实际只用第 0 个扇区(默认 50 个 key ≈ 3KB),16 扇区(64KB) 足够 GC 周转,
  87. * 最坏耗时降到 ≈0.7s。
  88. * 警告:修改本值必须同步修改 param_mirror.h 的 MIRROR_BASE_OFFSET ——
  89. * ef_log.c:101 的日志区起始 = EF_START_ADDR + ENV_AREA_SIZE,会跟着前移。 */
  90. #define ENV_AREA_SIZE (EF_ERASE_MIN_SIZE * 16)
  91. /* print debug information of flash */
  92. #ifdef PKG_EASYFLASH_DEBUG
  93. #define PRINT_DEBUG
  94. #endif
  95. #endif /* EF_CFG_H_ */