Skip to content

LFS example not working #3299

@Sparkxxx

Description

@Sparkxxx

Expected behavior

Obtain output as in docs example: https://nodemcu.readthedocs.io/en/dev/getting-started/#minimal-lfs-example

Actual behavior

node.flashreload("lfs.img")
Warning, deprecated API! node.flashreload. It will be removed soon. Use node.LFS interface instead. See documentation for details.
LFS region updated. Restarting.

print(LFS)
table: 0x3fff08a0 <<<--- In example we have NIL but I think this is here because of #define LUA_INIT_STRING "pcall(function() node.flashindex'_init'() end)"

node.flashindex("_init")()

print(LFS._list)
nil <<<--- this SHOULD NOT be NIL it sould return like in the example a table: 3fff0728

Test code

Starting from scratch just now 28-sep-2020 with
git clone --recurse-submodules https://github.com/nodemcu/nodemcu-firmware.git

BUILD NodeMCU
Modify user_config.h
#define LUA_NUMBER_INTEGRAL
#define LUA_FLASH_STORE 0x40000
#define LUA_INIT_STRING "pcall(function() node.flashindex'_init'() end)"
#define BUILD_SPIFFS
#define SPIFFS_CACHE 1 // Enable if you use you SPIFFS in R/W mode
//#define SPIFFS_MAX_FILESYSTEM_SIZE 0x20000
#define SPIFFS_MAX_OPEN_FILES 4 // maximum number of open files for SPIFFS
#define FS_OBJ_NAME_LEN 31 // maximum length of a filename

#define NODEMCU_EAGLEROM_PARTITION        1
#define NODEMCU_IROM0TEXT_PARTITION       2
#define NODEMCU_LFS0_PARTITION            3
#define NODEMCU_LFS1_PARTITION            4
#define NODEMCU_TLSCERT_PARTITION         5
#define NODEMCU_SPIFFS0_PARTITION         6
#define NODEMCU_SPIFFS1_PARTITION         7

#ifndef LUA_FLASH_STORE
#  define LUA_FLASH_STORE                 0x0
#endif

#ifndef SPIFFS_FIXED_LOCATION
  #define SPIFFS_FIXED_LOCATION           0x0
  // You'll rarely need to customize this, because nowadays
  // it's usually overruled by the partition table anyway.
#endif
#ifndef SPIFFS_MAX_FILESYSTEM_SIZE
#  define SPIFFS_MAX_FILESYSTEM_SIZE      0xFFFFFFFF
#endif
#define SPIFFS_SIZE_1M_BOUNDARY

docker run --rm -ti -v pwd/nodemcu-firmware:/opt/nodemcu-firmware marcelstoer/nodemcu-build build

Use NodeMCU PyFlasher to flash the image on ESP-12e

Command: esptool.py --port COM4 --baud 115200 --after no_reset write_flash --flash_mode dio 0x00000 D:\_NodeMCU LUA\dumps\nodemcu_integer_release_20200928-0829.bin --erase-all

esptool.py v2.6
Serial port COM4
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
MAC: 18:fe:34:f4:ed:44
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Erasing flash (this may take a while)...
Chip erase completed successfully in 9.0s
Flash params set to 0x0240
Compressed 659456 bytes to 443592...
Wrote 659456 bytes (443592 compressed) at 0x00000000 in 39.2 seconds (effective 134.6 kbit/s)...
Hash of data verified.

Leaving...
Staying in bootloader.

Firmware successfully flashed. Unplug/replug or reset device 
to switch back to normal boot mode.

Using ESPlorer v0.2.0
Formatting file system. Please wait...
..................................................
NodeMCU 3.0.0.0 built with Docker provided by frightanic.com
branch: release
commit: 64bbf00
release: 3.0-master_20200910
release DTS: 202009090323
SSL: true
build type: integer
LFS: 0x40000 bytes total capacity
modules: crypto,dht,file,gpio,http,mdns,mqtt,net,node,pwm2,rtctime,sjson,sntp,softuart,tmr,uart,wifi
build 2020-09-28 08:29 powered by Lua 5.1.4 on SDK 3.0.1-dev(fce080e)

----------------------------
No files found.
----------------------------
> 
Total : 3073746 bytes
Used  : 0 bytes
Remain: 3073746 bytes

Build LFS from lua_examples/lfs/
docker run --rm -ti -v pwd/nodemcu-firmware:/opt/nodemcu-firmware -v pwd/nodemcu-firmware/lua_examples/lfs/:/opt/lua marcelstoer/nodemcu-build lfs-image
Adding files: ./lfs_fragments.lua ./HTTP_OTA.lua ./_init.lua ./dummy_strings.lua
creating LFS_float_20200928-0840.img
creating LFS_integer_20200928-0840.img

Uploading to ESP file LFS_integer_20200928-0840.img...Success
>
----------------------------
LFS_integer_20200928-0840.img : 5670 bytes
----------------------------
Total file(s) : 1
Total size : 5670 bytes

Total : 3073746 bytes
Used  : 6024 bytes
Remain: 3067722 bytes

file.rename("LFS_integer_20200928-0840.img","lfs.img")
>
----------------------------
lfs.img : 5670 bytes
----------------------------
Total file(s) : 1
Total size : 5670 bytes

Total : 3073746 bytes
Used  : 6024 bytes
Remain: 3067722 bytes

Now using the guide https://nodemcu.readthedocs.io/en/dev/getting-started/#minimal-lfs-example
node.flashreload("lfs.img")
Warning, deprecated API! node.flashreload. It will be removed soon. Use node.LFS interface instead. See documentation for details.
LFS region updated. Restarting.

print(LFS)
table: 0x3fff08a0 **<<<--- In example we have NIL but I think this is here because of #define LUA_INIT_STRING "pcall(function() node.flashindex'_init'() end)"**

node.flashindex("_init")()

print(LFS._list)
nil **<<<--- this SHOULD NOT be NIL it sould return like in the example a table: 3fff0728**

Example is broken, maybe it's the lfs_addr, spiffs_addr ???

Create getinfo.lua in SPIFFS with content
print("The LFS addr is " .. node.getpartitiontable().lfs_addr)
print("The LFS size is " .. node.getpartitiontable().lfs_size)
print("The SPIFFS addr is " .. node.getpartitiontable().spiffs_addr)
print("The SPIFFS size is " .. node.getpartitiontable().spiffs_size)
> =node.heap()
43368
>
----------------------------
getinfo.lua : 264 bytes
lfs.img : 5670 bytes
----------------------------
Total file(s) : 2
Total size : 5934 bytes

Total : 3073746 bytes
Used  : 6777 bytes
Remain: 3066969 bytes

**> dofile("getinfo.lua")
Lua error: 	/opt/lua/_init.lua:97: attempt to call a nil value
stack traceback:
	/opt/lua/_init.lua:97: in function 'dofile'
	stdin:1: in main chunk
	[C]: ?
	[C]: ?**

With command line
>
print("The LFS addr is " .. node.getpartitiontable().lfs_addr)
The LFS addr is 663552
>
print("The LFS size is " .. node.getpartitiontable().lfs_size)
The LFS size is 262144
>
print("The SPIFFS addr is " .. node.getpartitiontable().spiffs_addr)
The SPIFFS addr is 925696
>
print("The SPIFFS size is " .. node.getpartitiontable().spiffs_size)
The SPIFFS size is 3256320

Tried to build also with default init.lua from SPIFFS //#define LUA_INIT_STRING "pcall(function() node.flashindex'_init'() end)" and the same thing happens, print(LFS._list) returns NIL
Tried building LFS with https://blog.ellisons.org.uk/article/nodemcu/a-lua-cross-compile-web-service/ with REMOTE LUAC.CROSS.INT (MASTER) but always get No zip file uploaded in Firefox and Chrome

NodeMCU startup banner

NodeMCU 3.0.0.0 built with Docker provided by frightanic.com
branch: release
commit: 64bbf00
release: 3.0-master_20200910
release DTS: 202009090323
SSL: true
build type: integer
LFS: 0x40000 bytes total capacity
modules: crypto,dht,file,gpio,http,mdns,mqtt,net,node,pwm2,rtctime,sjson,sntp,softuart,tmr,uart,wifi
build 2020-09-28 08:29 powered by Lua 5.1.4 on SDK 3.0.1-dev(fce080e)

Hardware

ESP-12e barebone

Thank you,

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions