Skip to content

Commit 12ff7a4

Browse files
committed
Store git version of the core in the compiled binary
1 parent 2f933e2 commit 12ff7a4

File tree

9 files changed

+67
-3
lines changed

9 files changed

+67
-3
lines changed

bootloaders/eboot/eboot.c

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stddef.h>
1010
#include <stdint.h>
1111
#include <stdbool.h>
12+
#include <string.h>
1213
#include "flash.h"
1314
#include "eboot_command.h"
1415

@@ -17,6 +18,20 @@
1718
extern void ets_wdt_enable(void);
1819
extern void ets_wdt_disable(void);
1920

21+
int print_version(const uint32_t flash_addr)
22+
{
23+
uint32_t ver;
24+
if (SPIRead(flash_addr + APP_START_OFFSET + sizeof(image_header_t) + sizeof(section_header_t), &ver, sizeof(ver))) {
25+
return 1;
26+
}
27+
const char* __attribute__ ((aligned (4))) fmtt = "v%08x\n\0\0";
28+
uint32_t fmt[2];
29+
fmt[0] = ((uint32_t*) fmtt)[0];
30+
fmt[1] = ((uint32_t*) fmtt)[1];
31+
ets_printf((const char*) fmt, ver);
32+
return 0;
33+
}
34+
2035
int load_app_from_flash_raw(const uint32_t flash_addr)
2136
{
2237
image_header_t image_header;
@@ -114,6 +129,8 @@ void main()
114129
{
115130
int res = 9;
116131
struct eboot_command cmd;
132+
133+
print_version(0);
117134

118135
if (eboot_command_read(&cmd) == 0) {
119136
// valid command was passed via RTC_MEM

bootloaders/eboot/eboot.elf

513 Bytes
Binary file not shown.

cores/esp8266/Esp.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ uint32_t EspClass::getChipId(void)
158158
return system_get_chip_id();
159159
}
160160

161+
extern "C" uint32_t core_version;
162+
extern "C" const char* core_release;
163+
164+
String EspClass::getCoreVersion()
165+
{
166+
if (core_release != NULL) {
167+
return String(core_release);
168+
}
169+
char buf[12];
170+
snprintf(buf, sizeof(buf), "%08x", core_version);
171+
return String(buf);
172+
}
173+
161174
const char * EspClass::getSdkVersion(void)
162175
{
163176
return system_get_sdk_version();

cores/esp8266/Esp.h

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class EspClass {
106106
uint32_t getChipId();
107107

108108
const char * getSdkVersion();
109+
String getCoreVersion();
109110

110111
uint8_t getBootVersion();
111112
uint8_t getBootMode();

cores/esp8266/core_esp8266_main.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,25 @@ extern "C" {
3131
#include "user_interface.h"
3232
#include "cont.h"
3333
}
34+
#include <core_version.h>
35+
3436
#define LOOP_TASK_PRIORITY 1
3537
#define LOOP_QUEUE_SIZE 1
3638

3739
#define OPTIMISTIC_YIELD_TIME_US 16000
3840

3941
struct rst_info resetInfo;
4042

43+
extern "C" {
44+
extern const uint32_t __attribute__((section(".ver_number"))) core_version = ARDUINO_ESP8266_GIT_VER;
45+
const char* core_release =
46+
#ifdef ARDUINO_ESP8266_RELEASE
47+
ARDUINO_ESP8266_RELEASE;
48+
#else
49+
NULL;
50+
#endif
51+
} // extern "C"
52+
4153
int atexit(void (*func)()) {
4254
return 0;
4355
}
@@ -134,6 +146,7 @@ void init_done() {
134146
system_set_os_print(1);
135147
gdb_init();
136148
do_global_ctors();
149+
printf("\n%08x\n", core_version);
137150
esp_schedule();
138151
}
139152

cores/esp8266/core_version.h

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#define ARDUINO_ESP8266_GIT_VER 0x00000000
2+
3+
// ARDUINO_ESP8266_RELEASE is defined for released versions as a string containing the version name, i.e. "2_3_0_RC1"
4+
// ARDUINO_ESP8266_RELEASE is used in the core internally. Please use ESP.getCoreVersion() function instead.
5+
6+
// ARDUINO_ESP8266_RELEASE_<version number> are defined for releases, for use in #ifdef... constructs

package/build_boards_manager_package.sh

+9-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ rm exclude.txt
4646

4747
# Get additional libraries (TODO: add them as git submodule or subtree?)
4848

49-
# SoftwareSerial version 2.2
50-
wget -q -O SoftwareSerial.zip https://github.com/plerup/espsoftwareserial/archive/097712eb07f5b3a70ef419b6e7a7ed2ada5aab85.zip
49+
# SoftwareSerial library
50+
wget -q -O SoftwareSerial.zip https://github.com/plerup/espsoftwareserial/archive/3.1.0.zip
5151
unzip -q SoftwareSerial.zip
5252
rm -rf SoftwareSerial.zip
5353
mv espsoftwareserial-* SoftwareSerial
@@ -69,6 +69,13 @@ $SED 's/tools.esptool.path={runtime.platform.path}\/tools\/esptool/tools.esptool
6969
$SED 's/tools.mkspiffs.path={runtime.platform.path}\/tools\/mkspiffs/tools.mkspiffs.path=\{runtime.tools.mkspiffs.path\}/g' \
7070
> $outdir/platform.txt
7171

72+
# Put core version and short hash of git version into core_version.h
73+
ver_define=`echo $ver | tr "[:lower:].-" "[:upper:]_"`
74+
echo Ver define: $ver_define
75+
echo \#define ARDUINO_ESP8266_GIT_VER 0x`git rev-parse --short=8 HEAD 2>/dev/null` >$outdir/cores/esp8266/core_version.h
76+
echo \#define ARDUINO_ESP8266_RELEASE_$ver_define >>$outdir/cores/esp8266/core_version.h
77+
echo \#define ARDUINO_ESP8266_RELEASE \"$ver_define\" >>$outdir/cores/esp8266/core_version.h
78+
7279
# Zip the package
7380
pushd package/versions/$ver
7481
echo "Making $package_name.zip"

platform.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ build.lwip_flags=-DLWIP_OPEN_SRC
2222

2323
compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/
2424
compiler.sdk.path={runtime.platform.path}/tools/sdk
25-
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/lwip/include"
25+
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"
2626

2727
compiler.c.cmd=xtensa-lx106-elf-gcc
2828
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=
6363
compiler.objcopy.eep.extra_flags=
6464
compiler.elf2hex.extra_flags=
6565

66+
## generate file with git version number
67+
## needs bash, git, and echo
68+
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"
69+
## windows-compatible version may be added later
70+
recipe.hooks.core.prebuild.1.pattern.windows=
71+
6672
## Compile c files
6773
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}"
6874

tools/sdk/ld/eagle.app.v6.common.ld

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ SECTIONS
152152
.irom0.text : ALIGN(4)
153153
{
154154
_irom0_text_start = ABSOLUTE(.);
155+
*(.ver_number)
155156
*.c.o( EXCLUDE_FILE (umm_malloc.c.o) .literal*, \
156157
EXCLUDE_FILE (umm_malloc.c.o) .text*)
157158
*.cpp.o(.literal*, .text*)

0 commit comments

Comments
 (0)