esp_app_desc.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2017-2018 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include <assert.h>
  14. #include <sys/param.h>
  15. #include "esp_ota_ops.h"
  16. #include "esp_attr.h"
  17. #include "sdkconfig.h"
  18. // Application version info
  19. const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
  20. .magic_word = ESP_APP_DESC_MAGIC_WORD,
  21. #ifdef CONFIG_APP_EXCLUDE_PROJECT_VER_VAR
  22. .version = "",
  23. #else
  24. .version = PROJECT_VER,
  25. #endif
  26. #ifdef CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR
  27. .project_name = "",
  28. #else
  29. .project_name = PROJECT_NAME,
  30. #endif
  31. .idf_ver = IDF_VER,
  32. #ifdef CONFIG_BOOTLOADER_APP_SECURE_VERSION
  33. .secure_version = CONFIG_BOOTLOADER_APP_SECURE_VERSION,
  34. #else
  35. .secure_version = 0,
  36. #endif
  37. #ifdef CONFIG_APP_COMPILE_TIME_DATE
  38. .time = __TIME__,
  39. .date = __DATE__,
  40. #else
  41. .time = "",
  42. .date = "",
  43. #endif
  44. };
  45. #ifndef CONFIG_APP_EXCLUDE_PROJECT_VER_VAR
  46. _Static_assert(sizeof(PROJECT_VER) <= sizeof(esp_app_desc.version), "PROJECT_VER is longer than version field in structure");
  47. #endif
  48. _Static_assert(sizeof(IDF_VER) <= sizeof(esp_app_desc.idf_ver), "IDF_VER is longer than idf_ver field in structure");
  49. #ifndef CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR
  50. _Static_assert(sizeof(PROJECT_NAME) <= sizeof(esp_app_desc.project_name), "PROJECT_NAME is longer than project_name field in structure");
  51. #endif
  52. const esp_app_desc_t *esp_ota_get_app_description(void)
  53. {
  54. return &esp_app_desc;
  55. }
  56. /* The following two functions may be called from the panic handler
  57. * or core dump, hence IRAM_ATTR.
  58. */
  59. static inline char IRAM_ATTR to_hex_digit(unsigned val)
  60. {
  61. return (val < 10) ? ('0' + val) : ('a' + val - 10);
  62. }
  63. int IRAM_ATTR esp_ota_get_app_elf_sha256(char* dst, size_t size)
  64. {
  65. size_t n = MIN((size - 1) / 2, sizeof(esp_app_desc.app_elf_sha256));
  66. const uint8_t* src = esp_app_desc.app_elf_sha256;
  67. for (size_t i = 0; i < n; ++i) {
  68. dst[2*i] = to_hex_digit(src[i] >> 4);
  69. dst[2*i + 1] = to_hex_digit(src[i] & 0xf);
  70. }
  71. dst[2*n] = 0;
  72. return 2*n + 1;
  73. }