From d0f58daec169224c1433815874820a705c2a4920 Mon Sep 17 00:00:00 2001 From: dongheng Date: Fri, 20 Sep 2019 14:35:28 +0800 Subject: [PATCH] feat(esp8266): add system version Bootloader can get the version of application for specific section, and then check if some features are supported. Developers can use the macro "ESP_IDF_VERSION" to limite some function like following: include "esp_idf_version.h" if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(3, 4, 0) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 0, 0) // 3.4 <= ver < 4.0 do_xxx_process(); endif --- components/esp8266/component.mk | 1 + components/esp8266/include/esp_idf_version.h | 58 +++++++++++++++++++ components/esp8266/include/esp_system.h | 9 +-- .../include/internal/esp_system_internal.h | 10 ++++ components/esp8266/ld/esp8266.project.ld.in | 2 +- components/esp8266/source/system_api.c | 5 ++ 6 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 components/esp8266/include/esp_idf_version.h diff --git a/components/esp8266/component.mk b/components/esp8266/component.mk index d68b2373..75f35156 100644 --- a/components/esp8266/component.mk +++ b/components/esp8266/component.mk @@ -34,6 +34,7 @@ COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/lib \ -T $(COMPONENT_BUILD_DIR)/esp8266.project.ld \ -Wl,--no-check-sections \ -u call_user_start \ + -u g_esp_sys_info \ $(addprefix -T ,$(LINKER_SCRIPTS)) ALL_LIB_FILES := $(patsubst %,$(COMPONENT_PATH)/lib/lib%.a,$(LIBS)) diff --git a/components/esp8266/include/esp_idf_version.h b/components/esp8266/include/esp_idf_version.h new file mode 100644 index 00000000..68730cd1 --- /dev/null +++ b/components/esp8266/include/esp_idf_version.h @@ -0,0 +1,58 @@ +// Copyright 2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +/** Major version number (X.x.x) */ +#define ESP_IDF_VERSION_MAJOR 3 +/** Minor version number (x.X.x) */ +#define ESP_IDF_VERSION_MINOR 3 +/** Patch version number (x.x.X) */ +#define ESP_IDF_VERSION_PATCH 0 + +/** + * Macro to convert IDF version number into an integer + * + * To be used in comparisons, such as ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) + */ +#define ESP_IDF_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) + +/** + * Current IDF version, as an integer + * + * To be used in comparisons, such as ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) + */ +#define ESP_IDF_VERSION ESP_IDF_VERSION_VAL(ESP_IDF_VERSION_MAJOR, \ + ESP_IDF_VERSION_MINOR, \ + ESP_IDF_VERSION_PATCH) + +/** + * Return full IDF version string, same as 'git describe' output. + * + * @note If you are printing the ESP-IDF version in a log file or other information, + * this function provides more information than using the numerical version macros. + * For example, numerical version macros don't differentiate between development, + * pre-release and release versions, but the output of this function does. + * + * @return constant string from IDF_VER + */ +const char* esp_get_idf_version(void); + +#ifdef __cplusplus +} +#endif diff --git a/components/esp8266/include/esp_system.h b/components/esp8266/include/esp_system.h index e8e6b4c3..30c78033 100644 --- a/components/esp8266/include/esp_system.h +++ b/components/esp8266/include/esp_system.h @@ -21,6 +21,8 @@ #include "sdkconfig.h" +#include "esp_idf_version.h" + #ifdef __cplusplus extern "C" { #endif @@ -181,13 +183,6 @@ uint32_t esp_get_minimum_free_heap_size( void ); */ uint32_t esp_random(void); -/** - * Get IDF version - * - * @return constant string from IDF_VER - */ -const char* esp_get_idf_version(void); - typedef enum { FLASH_SIZE_4M_MAP_256_256 = 0, /**< Flash size : 4Mbits. Map : 256KBytes + 256KBytes */ FLASH_SIZE_2M, /**< Flash size : 2Mbits. Map : 256KBytes */ diff --git a/components/esp8266/include/internal/esp_system_internal.h b/components/esp8266/include/internal/esp_system_internal.h index b90f19ac..37702e77 100644 --- a/components/esp8266/include/internal/esp_system_internal.h +++ b/components/esp8266/include/internal/esp_system_internal.h @@ -52,6 +52,16 @@ struct _rtc_sys_info { if your bootloader is older than v3.2, please don't use this */ }; +/** + * @brief System information + */ +typedef struct esp_sys_info { + uint32_t version; //!< system version + uint32_t reserved[3]; //!< reserved data +} esp_sys_info_t; + +_Static_assert(sizeof(esp_sys_info_t) == 16, "esp_sys_info_t should be 16 bytes"); + extern struct _rtc_sys_info rtc_sys_info; /** diff --git a/components/esp8266/ld/esp8266.project.ld.in b/components/esp8266/ld/esp8266.project.ld.in index 557329a4..063bc45a 100644 --- a/components/esp8266/ld/esp8266.project.ld.in +++ b/components/esp8266/ld/esp8266.project.ld.in @@ -48,7 +48,7 @@ SECTIONS _iram_start = ABSOLUTE(.); /* Vectors go to IRAM */ _init_start = ABSOLUTE(.); - LONG(_iram_start) + KEEP(*(.SystemInfoVector.text)); . = 0x10; KEEP(*(.DebugExceptionVector.text)); . = 0x20; diff --git a/components/esp8266/source/system_api.c b/components/esp8266/source/system_api.c index f3527845..c3c0402c 100644 --- a/components/esp8266/source/system_api.c +++ b/components/esp8266/source/system_api.c @@ -33,6 +33,11 @@ static const char* TAG = "system_api"; static uint8_t base_mac_addr[6] = { 0 }; +// Bootloader can get this information +const __attribute__((section(".SystemInfoVector.text"))) esp_sys_info_t g_esp_sys_info = { + .version = ESP_IDF_VERSION +}; + esp_err_t esp_base_mac_addr_set(uint8_t *mac) { if (mac == NULL) {