Merge pull request #2830 from HHHartmann/Extend-node.info
Extend node.info
This commit is contained in:
commit
15afa7fd2e
|
@ -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
|
||||
|
|
7
Makefile
7
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 $@);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define __USER_VERSION_H__
|
||||
|
||||
#include "version.h" /* ESP firmware header */
|
||||
#include <buildinfo.h>
|
||||
|
||||
#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"
|
||||
|
|
|
@ -120,6 +120,60 @@ static int node_sleep( lua_State* L )
|
|||
#endif //PMSLEEP_ENABLE
|
||||
static int node_info( lua_State* L )
|
||||
{
|
||||
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);
|
||||
|
@ -130,6 +184,8 @@ static int node_info( lua_State* L )
|
|||
lua_pushinteger(L, flash_rom_get_speed());
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Lua: chipid()
|
||||
static int node_chipid( lua_State* L )
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
||||
|
|
|
@ -257,6 +257,10 @@ An array containing entries for `lfs_addr`, `lfs_size`, `spiffs_addr` and `spiff
|
|||
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,15 +276,42 @@ 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
|
||||
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)
|
||||
|
@ -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.
|
||||
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue