diff --git a/bootloaders/eboot/eboot.c b/bootloaders/eboot/eboot.c index f53d3c912..69bc692e9 100644 --- a/bootloaders/eboot/eboot.c +++ b/bootloaders/eboot/eboot.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "flash.h" #include "eboot_command.h" @@ -17,6 +18,20 @@ extern void ets_wdt_enable(void); extern void ets_wdt_disable(void); +int print_version(const uint32_t flash_addr) +{ + uint32_t ver; + if (SPIRead(flash_addr + APP_START_OFFSET + sizeof(image_header_t) + sizeof(section_header_t), &ver, sizeof(ver))) { + return 1; + } + const char* __attribute__ ((aligned (4))) fmtt = "v%08x\n\0\0"; + uint32_t fmt[2]; + fmt[0] = ((uint32_t*) fmtt)[0]; + fmt[1] = ((uint32_t*) fmtt)[1]; + ets_printf((const char*) fmt, ver); + return 0; +} + int load_app_from_flash_raw(const uint32_t flash_addr) { image_header_t image_header; @@ -114,6 +129,8 @@ void main() { int res = 9; struct eboot_command cmd; + + print_version(0); if (eboot_command_read(&cmd) == 0) { // valid command was passed via RTC_MEM diff --git a/bootloaders/eboot/eboot.elf b/bootloaders/eboot/eboot.elf index aa61b97f0..1ccbe25fc 100755 Binary files a/bootloaders/eboot/eboot.elf and b/bootloaders/eboot/eboot.elf differ diff --git a/cores/esp8266/Esp.cpp b/cores/esp8266/Esp.cpp index 0ea0fef1d..cd0786a08 100644 --- a/cores/esp8266/Esp.cpp +++ b/cores/esp8266/Esp.cpp @@ -158,6 +158,19 @@ uint32_t EspClass::getChipId(void) return system_get_chip_id(); } +extern "C" uint32_t core_version; +extern "C" const char* core_release; + +String EspClass::getCoreVersion() +{ + if (core_release != NULL) { + return String(core_release); + } + char buf[12]; + snprintf(buf, sizeof(buf), "%08x", core_version); + return String(buf); +} + const char * EspClass::getSdkVersion(void) { return system_get_sdk_version(); diff --git a/cores/esp8266/Esp.h b/cores/esp8266/Esp.h index 83f4b1b73..c506a525f 100644 --- a/cores/esp8266/Esp.h +++ b/cores/esp8266/Esp.h @@ -106,6 +106,7 @@ class EspClass { uint32_t getChipId(); const char * getSdkVersion(); + String getCoreVersion(); uint8_t getBootVersion(); uint8_t getBootMode(); diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index f63fe24f5..634eb7902 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -31,6 +31,8 @@ extern "C" { #include "user_interface.h" #include "cont.h" } +#include + #define LOOP_TASK_PRIORITY 1 #define LOOP_QUEUE_SIZE 1 @@ -38,6 +40,16 @@ extern "C" { struct rst_info resetInfo; +extern "C" { +extern const uint32_t __attribute__((section(".ver_number"))) core_version = ARDUINO_ESP8266_GIT_VER; +const char* core_release = +#ifdef ARDUINO_ESP8266_RELEASE + ARDUINO_ESP8266_RELEASE; +#else + NULL; +#endif +} // extern "C" + int atexit(void (*func)()) { return 0; } @@ -134,6 +146,7 @@ void init_done() { system_set_os_print(1); gdb_init(); do_global_ctors(); + printf("\n%08x\n", core_version); esp_schedule(); } diff --git a/cores/esp8266/core_version.h b/cores/esp8266/core_version.h new file mode 100644 index 000000000..09e384c1f --- /dev/null +++ b/cores/esp8266/core_version.h @@ -0,0 +1,6 @@ +#define ARDUINO_ESP8266_GIT_VER 0x00000000 + +// ARDUINO_ESP8266_RELEASE is defined for released versions as a string containing the version name, i.e. "2_3_0_RC1" +// ARDUINO_ESP8266_RELEASE is used in the core internally. Please use ESP.getCoreVersion() function instead. + +// ARDUINO_ESP8266_RELEASE_ are defined for releases, for use in #ifdef... constructs diff --git a/package/build_boards_manager_package.sh b/package/build_boards_manager_package.sh index f713b1c69..8859603d8 100755 --- a/package/build_boards_manager_package.sh +++ b/package/build_boards_manager_package.sh @@ -46,8 +46,8 @@ rm exclude.txt # Get additional libraries (TODO: add them as git submodule or subtree?) -# SoftwareSerial version 2.2 -wget -q -O SoftwareSerial.zip https://github.com/plerup/espsoftwareserial/archive/097712eb07f5b3a70ef419b6e7a7ed2ada5aab85.zip +# SoftwareSerial library +wget -q -O SoftwareSerial.zip https://github.com/plerup/espsoftwareserial/archive/3.1.0.zip unzip -q SoftwareSerial.zip rm -rf SoftwareSerial.zip mv espsoftwareserial-* SoftwareSerial @@ -66,9 +66,17 @@ cat $srcdir/platform.txt | \ $SED 's/runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}\/tools\/xtensa-lx106-elf//g' | \ $SED 's/runtime.tools.esptool.path={runtime.platform.path}\/tools\/esptool//g' | \ $SED 's/tools.esptool.path={runtime.platform.path}\/tools\/esptool/tools.esptool.path=\{runtime.tools.esptool.path\}/g' | \ -$SED 's/tools.mkspiffs.path={runtime.platform.path}\/tools\/mkspiffs/tools.mkspiffs.path=\{runtime.tools.mkspiffs.path\}/g' \ +$SED 's/tools.mkspiffs.path={runtime.platform.path}\/tools\/mkspiffs/tools.mkspiffs.path=\{runtime.tools.mkspiffs.path\}/g' |\ +$SED 's/recipe.hooks.core.prebuild.1.pattern.*//g' \ > $outdir/platform.txt +# Put core version and short hash of git version into core_version.h +ver_define=`echo $ver | tr "[:lower:].-" "[:upper:]_"` +echo Ver define: $ver_define +echo \#define ARDUINO_ESP8266_GIT_VER 0x`git rev-parse --short=8 HEAD 2>/dev/null` >$outdir/cores/esp8266/core_version.h +echo \#define ARDUINO_ESP8266_RELEASE_$ver_define >>$outdir/cores/esp8266/core_version.h +echo \#define ARDUINO_ESP8266_RELEASE \"$ver_define\" >>$outdir/cores/esp8266/core_version.h + # Zip the package pushd package/versions/$ver echo "Making $package_name.zip" diff --git a/platform.txt b/platform.txt index d1bce473a..209a4c8c3 100644 --- a/platform.txt +++ b/platform.txt @@ -22,7 +22,7 @@ build.lwip_flags=-DLWIP_OPEN_SRC compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/ compiler.sdk.path={runtime.platform.path}/tools/sdk -compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/lwip/include" +compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/lwip/include" "-I{build.path}/core" compiler.c.cmd=xtensa-lx106-elf-gcc compiler.c.flags=-c {compiler.warning_flags} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections @@ -63,6 +63,12 @@ compiler.ar.extra_flags= compiler.objcopy.eep.extra_flags= compiler.elf2hex.extra_flags= +## generate file with git version number +## needs bash, git, and echo +recipe.hooks.core.prebuild.1.pattern=bash -c "mkdir -p {build.path}/core && echo \#define ARDUINO_ESP8266_GIT_VER 0x`git --git-dir {runtime.platform.path}/.git rev-parse --short=8 HEAD 2>/dev/null || echo ffffffff` >{build.path}/core/core_version.h" +## windows-compatible version may be added later +recipe.hooks.core.prebuild.1.pattern.windows= + ## Compile c files recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" diff --git a/tools/sdk/ld/eagle.app.v6.common.ld b/tools/sdk/ld/eagle.app.v6.common.ld index 90d9fc18c..ac03c8987 100644 --- a/tools/sdk/ld/eagle.app.v6.common.ld +++ b/tools/sdk/ld/eagle.app.v6.common.ld @@ -152,6 +152,7 @@ SECTIONS .irom0.text : ALIGN(4) { _irom0_text_start = ABSOLUTE(.); + *(.ver_number) *.c.o( EXCLUDE_FILE (umm_malloc.c.o) .literal*, \ EXCLUDE_FILE (umm_malloc.c.o) .text*) *.cpp.o(.literal*, .text*)