diff --git a/.gitignore b/.gitignore index abca1f1738..736ae691be 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ local/ user_config.h server-ca.crt luac.cross +luac.cross.int uz_unzip uz_zip tools/toolchains/ @@ -15,3 +16,6 @@ tools/toolchains/ .project .settings/ .vscode + +#ignore temp file for build infos +buildinfo.h diff --git a/Makefile b/Makefile index 4e796ed2c6..67ff4ece2f 100644 --- a/Makefile +++ b/Makefile @@ -274,7 +274,7 @@ endif # TARGET # ifndef TARGET -all: toolchain sdk_pruned pre_build .subdirs +all: toolchain sdk_pruned pre_build buildinfo .subdirs else all: .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS) endif @@ -412,6 +412,11 @@ pre_build: @-rm -f $(APP_DIR)/modules/server-ca.crt.h endif +.PHONY: buildinfo + +buildinfo: + tools/update_buildinfo.sh + ifdef TARGET $(OBJODIR)/%.o: %.c @mkdir -p $(dir $@); diff --git a/app/include/user_version.h b/app/include/user_version.h index f8ba27dba8..33817c5c30 100644 --- a/app/include/user_version.h +++ b/app/include/user_version.h @@ -2,6 +2,7 @@ #define __USER_VERSION_H__ #include "version.h" /* ESP firmware header */ +#include #define NODE_VERSION_MAJOR ESP_SDK_VERSION_MAJOR #define NODE_VERSION_MINOR ESP_SDK_VERSION_MINOR @@ -11,7 +12,9 @@ #define NODE_VERSION_STR(x) #x #define NODE_VERSION_XSTR(x) NODE_VERSION_STR(x) -#define NODE_VERSION "NodeMCU " ESP_SDK_VERSION_STRING "." NODE_VERSION_XSTR(NODE_VERSION_INTERNAL) +# define NODE_VERSION "NodeMCU " ESP_SDK_VERSION_STRING "." NODE_VERSION_XSTR(NODE_VERSION_INTERNAL) " " NODE_VERSION_LONG +// Leave the space after # in the line above. It busts replacement of NODE_VERSION in the docker build which is not needed anymore with this PR. +// Can be removed when the script is adapted #ifndef BUILD_DATE #define BUILD_DATE "unspecified" diff --git a/app/modules/node.c b/app/modules/node.c index a44f3fa43c..167b8b21db 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -120,15 +120,71 @@ static int node_sleep( lua_State* L ) #endif //PMSLEEP_ENABLE static int node_info( lua_State* L ) { - lua_pushinteger(L, NODE_VERSION_MAJOR); - lua_pushinteger(L, NODE_VERSION_MINOR); - lua_pushinteger(L, NODE_VERSION_REVISION); - lua_pushinteger(L, system_get_chip_id()); // chip id - lua_pushinteger(L, spi_flash_get_id()); // flash id - lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB - lua_pushinteger(L, flash_rom_get_mode()); - lua_pushinteger(L, flash_rom_get_speed()); - return 8; + const char* options[] = {"hw", "sw_version", "build_config", "legacy", NULL}; + int option = luaL_checkoption (L, 1, options[3], options); + + switch (option) { + case 0: { // hw + lua_createtable (L, 0, 5); + int table_index = lua_gettop(L); + lua_pushinteger(L, system_get_chip_id()); // chip id + lua_setfield(L, table_index, "chip_id"); + lua_pushinteger(L, spi_flash_get_id()); // flash id + lua_setfield(L, table_index, "flash_id"); + lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB + lua_setfield(L, table_index, "flash_size"); + lua_pushinteger(L, flash_rom_get_mode()); + lua_setfield(L, table_index, "flash_mode"); + lua_pushinteger(L, flash_rom_get_speed()); + lua_setfield(L, table_index, "flash_speed"); + return 1; + } + case 1: { // sw_version + lua_createtable (L, 0, 7); + int table_index = lua_gettop(L); + lua_pushinteger(L, NODE_VERSION_MAJOR); + lua_setfield(L, table_index, "node_version_major"); + lua_pushinteger(L, NODE_VERSION_MINOR); + lua_setfield(L, table_index, "node_version_minor"); + lua_pushinteger(L, NODE_VERSION_REVISION); + lua_setfield(L, table_index, "node_version_revision"); + lua_pushstring(L, BUILDINFO_BRANCH); + lua_setfield(L, table_index, "git_branch"); + lua_pushstring(L, BUILDINFO_COMMIT_ID); + lua_setfield(L, table_index, "git_commit_id"); + lua_pushstring(L, BUILDINFO_RELEASE); + lua_setfield(L, table_index, "git_release"); + lua_pushstring(L, BUILDINFO_RELEASE_DTS); + lua_setfield(L, table_index, "git_commit_dts"); + return 1; + } + case 2: { // build_config + lua_createtable (L, 0, 4); + int table_index = lua_gettop(L); + lua_pushboolean(L, BUILDINFO_SSL); + lua_setfield(L, table_index, "ssl"); + lua_pushnumber(L, BUILDINFO_LFS); + lua_setfield(L, table_index, "lfs_size"); + lua_pushstring(L, BUILDINFO_MODULES); + lua_setfield(L, table_index, "modules"); + lua_pushstring(L, BUILDINFO_BUILD_TYPE); + lua_setfield(L, table_index, "number_type"); + return 1; + } + default: + { + platform_print_deprecation_note("node.info() without parameter", "in the next version"); + lua_pushinteger(L, NODE_VERSION_MAJOR); + lua_pushinteger(L, NODE_VERSION_MINOR); + lua_pushinteger(L, NODE_VERSION_REVISION); + lua_pushinteger(L, system_get_chip_id()); // chip id + lua_pushinteger(L, spi_flash_get_id()); // flash id + lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB + lua_pushinteger(L, flash_rom_get_mode()); + lua_pushinteger(L, flash_rom_get_speed()); + return 8; + } + } } // Lua: chipid() diff --git a/app/user/user_main.c b/app/user/user_main.c index 9afb1fb8d1..2b9e97b1c7 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -103,7 +103,7 @@ extern void _ResetHandler(void); * the use of a partition table (PT) to control flash allocation. The NodeMCU uses * this PT for overall allocation of its flash resources. The non_OS SDK calls the * user_pre_init() entry to do all of this startup configuration. Note that this - * runs with Icache enabled -- that is the IROM0 partition is already mapped the + * runs with Icache enabled -- that is the IROM0 partition is already mapped to the * address space at 0x40210000 and so that most SDK services are available, such * as system_get_flash_size_map() which returns the valid flash size (including the * 8Mb and 16Mb variants). diff --git a/docs/build.md b/docs/build.md index 206f9dd9ae..dc1ddabc45 100644 --- a/docs/build.md +++ b/docs/build.md @@ -93,12 +93,14 @@ make EXTRA_CCFLAGS="-DLUA_NUMBER_INTEGRAL .... ``` ### Tag Your Build -Identify your firmware builds by editing `app/include/user_version.h` +Identify your firmware builds by setting the environment variable `USER_PROLOG`. +You may also edit `app/include/user_version.h`. The variable `USER_PROLOG` will be included in `NODE_VERSION_LONG`. ```c -#define NODE_VERSION "NodeMCU " ESP_SDK_VERSION_STRING "." NODE_VERSION_XSTR(NODE_VERSION_INTERNAL) +#define NODE_VERSION "NodeMCU " ESP_SDK_VERSION_STRING "." NODE_VERSION_XSTR(NODE_VERSION_INTERNAL) " " NODE_VERSION_LONG + #ifndef BUILD_DATE -#define BUILD_DATE "YYYYMMDD" +#define BUILD_DATE "unspecified" #endif ``` diff --git a/docs/modules/node.md b/docs/modules/node.md index deaa007e83..1db3196483 100644 --- a/docs/modules/node.md +++ b/docs/modules/node.md @@ -250,13 +250,17 @@ Get the current LFS and SPIFFS partition information. none #### Returns -An array containing entries for `lfs_addr`, `lfs_size`, `spiffs_addr` and `spiffs_size`. The address values are offsets relative to the startof the Flash memory. +An array containing entries for `lfs_addr`, `lfs_size`, `spiffs_addr` and `spiffs_size`. The address values are offsets relative to the start of the Flash memory. #### Example ```lua print("The LFS size is " .. node.getpartitiontable().lfs_size) ``` +#### See also +[`node.setpartitiontable()`](#nodesetpartitiontable) + + ## node.heap() Returns the current available heap size in bytes. Note that due to fragmentation, actual allocations of this size may not be possible. @@ -272,23 +276,50 @@ system heap size left in bytes (number) ## node.info() -Returns NodeMCU version, chipid, flashid, flash size, flash mode, flash speed, and Lua File Store (LFS) usage statics. +Returns information about hardware, software version and build configuration. + #### Syntax -`node.info()` +`node.info([group])` #### Parameters -none +`group` group of information (optional, if ommited return legacy information). May be one of `"hw"`, `"sw_version"`, `"build_config"`. #### Returns - - `majorVer` (number) - - `minorVer` (number) - - `devVer` (number) - - `chipid` (number) - - `flashid` (number) - - `flashsize` (number) - - `flashmode` (number) - - `flashspeed` (number) + if a `group` is given the return value will be a table containing the following elements: + - for `group` = `"hw"` + - `chip_id` (number) + - `flash_id` (number) + - `flash_size` (number) + - `flash_mode` (number) QIO = 0, QOUT = 1, DIO = 2, DOUT = 15. + - `flash_speed` (number) + - for `group` = `"sw_version"` + - `git_branch` (string) + - `git_commit_id` (string) + - `git_release` (string) Release name +additional commits e.g. "2.0.0-master_20170202 +403" + - `git_commit_dts` (string) in an ordering format. e.g. "201908111200" + - `node_verion_major` (number) + - `node_verion_minor` (number) + - `node_verion_revision` (number) + - for `group` = `"build_config"` + - `ssl` (boolean) + - `lfs_size` (number) as defined at build time + - `modules` (string) comma separated list + - `number_type` (string) `integer` or `float` + +!!! attention + +This interface is deprecated and will be removed in one of the next releases. Use the above calls instead. + + - for no `group` given: --deprecated + - `majorVer` (number) + - `minorVer` (number) + - `devVer` (number) + - `chipid` (number) + - `flashid` (number) + - `flashsize` (number) + - `flashmode` (number) + - `flashspeed` (number) #### Example ```lua @@ -296,6 +327,17 @@ majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = print("NodeMCU "..majorVer.."."..minorVer.."."..devVer) ``` +```lua +for k,v in pairs(node.info("build_config")) do +print (k,v) +end +``` + +```lua +print(node.info("sw_version").git_release) +``` + + ## node.input() Submits a string to the Lua interpreter. Similar to `pcall(loadstring(str))`, but without the single-line limitation. @@ -436,7 +478,7 @@ Sets the current LFS and / or SPIFFS partition information. This function is typically only used once during initial provisioning after first flashing the firmware. It does some consistency checks to validate the specified parameters, and it then reboots the ESP module to load the new partition table. If the LFS or SPIFFS regions have changed then you will need to reload LFS, reformat the SPIFSS and reload its contents. #### Parameters -An array containing one or more of the following enties. The address values are byte offsets relative to the startof the Flash memory. The size values are in bytes. Note that these parameters must be a multiple of 8Kb to align to Flash page boundaries. +An array containing one or more of the following enties. The address values are byte offsets relative to the start of the Flash memory. The size values are in bytes. Note that these parameters must be a multiple of 8Kb to align to Flash page boundaries. - `lfs_addr`. The base address of the LFS region. - `lfs_size`. The size of the LFS region. - `spiffs_addr`. The base address of the SPIFFS region. @@ -450,6 +492,10 @@ Not applicable. The ESP module will be rebooted for a valid new set, or a Lua e node.setpartitiontable{lfs_size = 0x20000, spiffs_addr = 0x120000, spiffs_size = 0x20000} ``` +#### See also +[`node.getpartitiontable()`](#nodegetpartitiontable) + + ## node.sleep() diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh new file mode 100755 index 0000000000..99a376f993 --- /dev/null +++ b/tools/update_buildinfo.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +USER_MODULES_H=app/include/user_modules.h + +COMMIT_ID="$(git rev-parse HEAD)" +BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -E 's/[\/\\]+/_/g')" +RELEASE="$(git describe --tags --long | sed -E 's/(.*)-(.*)-.*/\1 +\2/g' | sed 's/ +0$//')" +RELEASE_DTS=$(TZ=UTC git show --quiet --date=format-local:"%Y%m%d%H%M" --format="%cd" HEAD) + +MODULES=$(awk '/^[ \t]*#define LUA_USE_MODULES/{modules=modules sep tolower(substr($2,17));sep=","}END{if(length(modules)==0)modules="-";print modules}' $USER_MODULES_H | tr -d '\r') + +# create temp buildinfo +TEMPFILE=/tmp/buildinfo.h +cat > $TEMPFILE << EndOfMessage +#ifndef __BUILDINFO_H__ +#define __BUILDINFO_H__ + +#include "user_config.h" + +#define BUILDINFO_STR_HELPER(x) #x +#define BUILDINFO_TO_STR(x) BUILDINFO_STR_HELPER(x) + +#ifdef LUA_FLASH_STORE +#define BUILDINFO_LFS LUA_FLASH_STORE +#else +#define BUILDINFO_LFS 0 +#endif + +#ifdef CLIENT_SSL_ENABLE +#define BUILDINFO_SSL true +#define BUILDINFO_SSL_STR "true" +#else +#define BUILDINFO_SSL false +#define BUILDINFO_SSL_STR "false" +#endif + +#ifdef LUA_NUMBER_INTEGRAL +#define BUILDINFO_BUILD_TYPE "integer" +#else +#define BUILDINFO_BUILD_TYPE "float" +#endif + +#define USER_PROLOG "$USER_PROLOG" +#define BUILDINFO_BRANCH "$BRANCH" +#define BUILDINFO_COMMIT_ID "$COMMIT_ID" +#define BUILDINFO_RELEASE "$RELEASE" +#define BUILDINFO_RELEASE_DTS "$RELEASE_DTS" +#define BUILDINFO_MODULES "$MODULES" + +#define NODE_VERSION_LONG \\ + USER_PROLOG "\n" \\ + "\tbranch: " BUILDINFO_BRANCH "\n" \\ + "\tcommit: " BUILDINFO_COMMIT_ID "\n" \\ + "\trelease: " BUILDINFO_RELEASE "\n" \\ + "\trelease DTS: " BUILDINFO_RELEASE_DTS "\n" \\ + "\tSSL: " BUILDINFO_SSL_STR "\n" \\ + "\tbuild type: " BUILDINFO_BUILD_TYPE "\n" \\ + "\tLFS: " BUILDINFO_TO_STR(BUILDINFO_LFS) "\n" \\ + "\tmodules: " BUILDINFO_MODULES "\n" + +EndOfMessage + +echo "#endif /* __BUILDINFO_H__ */" >> $TEMPFILE + +diff -q $TEMPFILE app/include/buildinfo.h || cp $TEMPFILE app/include/buildinfo.h +rm $TEMPFILE