Skip to content

Commit

Permalink
Store git version of the core in the compiled binary (esp8266#2099)
Browse files Browse the repository at this point in the history
* Store git version of the core in the compiled binary

* Don't update version number when using boards manager package
  • Loading branch information
igrr committed Jun 6, 2016
1 parent dbef28d commit 32bd42b
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 4 deletions.
17 changes: 17 additions & 0 deletions bootloaders/eboot/eboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "flash.h"
#include "eboot_command.h"

Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Binary file modified bootloaders/eboot/eboot.elf
Binary file not shown.
13 changes: 13 additions & 0 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class EspClass {
uint32_t getChipId();

const char * getSdkVersion();
String getCoreVersion();

uint8_t getBootVersion();
uint8_t getBootMode();
Expand Down
13 changes: 13 additions & 0 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,25 @@ extern "C" {
#include "user_interface.h"
#include "cont.h"
}
#include <core_version.h>

#define LOOP_TASK_PRIORITY 1
#define LOOP_QUEUE_SIZE 1

#define OPTIMISTIC_YIELD_TIME_US 16000

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;
}
Expand Down Expand Up @@ -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();
}

Expand Down
6 changes: 6 additions & 0 deletions cores/esp8266/core_version.h
Original file line number Diff line number Diff line change
@@ -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_<version number> are defined for releases, for use in #ifdef... constructs
14 changes: 11 additions & 3 deletions package/build_boards_manager_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"

Expand Down
1 change: 1 addition & 0 deletions tools/sdk/ld/eagle.app.v6.common.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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*)
Expand Down

0 comments on commit 32bd42b

Please sign in to comment.