加载 spiffsimg 文件的正确地址是什么

What is the correct address for loading spiffsimg file

我已经使用 spiffsimg 创建了一个包含多个 lua 文件的文件:

# ./spiffsimg -f lua.img -c 262144 -r lua.script
f   4227 init.lua
f    413 cfg.lua
f   2233 setupWifi.lua
f   7498 configServer.lua
f    558 cfgForm.htm
f   4255 setupConfig.lua
f  14192 main.lua
#

然后我使用 esptool.py 将 NodeMCU 固件和包含 lua 文件的文件闪存到 esp8266(NodeMCU 开发套件):

c:\esptool-master>c:\Python27\python esptool.py -p COM7 write_flash -fs 32m -fm dio 0x00000 nodemcu-dev-9-modules-2016-07-18-12-06-36-integer.bin 0x78000 lua.img
esptool.py v1.0.2-dev
Connecting...
Running Cesanta flasher stub...
Flash params set to 0x0240
Writing 446464 @ 0x0... 446464 (100 %)
Wrote 446464 bytes at 0x0 in 38.9 seconds (91.9 kbit/s)...
Writing 262144 @ 0x78000... 262144 (100 %)
Wrote 262144 bytes at 0x78000 in 22.8 seconds (91.9 kbit/s)...
Leaving...

然后我 运行 ESPLorer 检查状态并得到:

PORT OPEN 115200

Communication with MCU..Got answer! AutoDetect firmware...

Can't autodetect firmware, because proper answer not received.


NodeMCU custom build by frightanic.com
    branch: dev
    commit: b21b3e08aad633ccfd5fd29066400a06bb699ae2
    SSL: true
    modules: file,gpio,http,net,node,rtctime,tmr,uart,wifi
 build  built on: 2016-07-18 12:05
 powered by Lua 5.1.4 on SDK 1.5.4(baaeaebb)
lua: cannot open init.lua
> 
----------------------------
No files found.
----------------------------
> 
Total : 3455015 bytes
Used  : 0 bytes
Remain: 3455015 bytes

NodeMCU 固件正确刷新,但无法找到 lua 文件。

我试过刷新到其他位置(0x84000、0x7c000),但我只是根据 github.

上的阅读线程猜测这些位置

我使用 NodeMCU file.fscfg() 例程来获取闪存地址和大小。如果我只刷新 NodeMCU 固件,我会得到以下信息:

print (file.fscfg())
524288  3653632

534288 是 0x80000,所以我尝试只将 spiffsimg 文件 (lua.img) 闪烁到 0x8000,然后 运行 相同的打印语句并得到:

print (file.fscfg())
786432  3391488

闪存地址增加了 lua.img 中的确切字节数——我不明白,为什么闪存地址会改变? file.fscfg返回的第一个数字不是flash起始地址,而是flash结束地址吗?

闪烁图像文件的正确地址是什么,包含由 spiffsimg 创建的 lua 个文件?

我自己从未这样做过,但我有理由相信可以从 the docs.

中提取正确答案

-f specifies the filename for the disk image. '%x' will be replaced by the calculated offset of the file system.

再往下一点

The disk image file is placed into the bin directory and it is named 0x<offset>-<size>.bin where the offset is the location where it should be flashed, and the size is the size of the flash part.

但是,这两个陈述之间存在轻微的不匹配。我们可能在文档中有错误。如果“'%x' 将被替换...”那么我预计最终名称将不再包含 0x

此外,可以在构建固件时定义固定的 SPIFFS 位置。

#define SPIFFS_FIXED_LOCATION 0x100000

This specifies that the SPIFFS filesystem starts at 1Mb from the start of the flash. Unless otherwise specified, it will run to the end of the flash (excluding the 16k of space reserved by the SDK).

找到的 spiffsimg 版本 here 将为闪烁包含 lua 个文件的图像文件提供正确的地址。

不要使用 this 版本的 spiffsimg,因为它已经过时了。

要安装 spiffsimg 实用程序,您需要下载并安装整个 nodemcu-firmware 包(进入 linux 环境,使用 make 进行安装 - 注意:在我的 debian linux 盒子上制作生成了一个错误,但我能够转到 ../tools/spiffsimg 子目录并在该目录中找到的 Makefile 上 运行 make 以创建实用程序)。

找到的spiffsimg指令here很清楚,有一个例外:你用-f参数指定的文件名需要包含字符%x。 %x 将替换为映像文件应闪存到的地址。

例如,命令

spiffsimage -f %x-luaFiles.img -S 4MB -U 465783 -r lua.script

将在本地目录中创建一个文件,其名称类似于:80000-luaFiles.img。这意味着您应该在 ESP8266 上的地址 0x80000 安装该图像文件。