当前仅介绍生成带程序固件的方法,如何编译自定义固件不在本文介绍。
固件可以为自主编译也可为公开固件,
获取spiflash的起始地址,执行lua脚本:
do
local s,p={},node.getpartitiontable()
for _,k in ipairs{'lfs_addr','lfs_size','spiffs_addr','spiffs_size'} do
s[#s+1] ='%s = 0x%06x' % {k, p[k]}
end
print ('{ %s }' % table.concat(s,', '))
end
得到spiffs_addr
0x088000
第二步:./spiffsimg -f 88000.img -S 1MB -U 557056 -r lua.script
lua.script文件内容为:需要生成的文件
import /root/nodemcu-firmware/local/fs/init.lua init.lua
import /root/nodemcu-firmware/local/fs/index.html.gz index.html.gz
import /root/nodemcu-firmware/local/fs/LFS.img LFS.img
ls
其中557056是0x088000的十进制。
得到flash内容为88000.img的文件。
在linux环境中,将nodemcu的固件合并为烧录文件的方法:
srec_cat -output “temp.bin” -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000
srec_cat -output “nodemcu_32mb.bin” -binary temp.bin -binary -fill 0xff 0x00000 0x088000 lua.img -binary -offset 0x088000
在windows中,https://srecord.sourceforge.net/download.html 下载安装软件
cd C:\Program Files\srecord\bin
srec_cat.exe -output "nodemcu_32mb.bin" -binary temp.bin -binary -fill 0xff 0x00000 0x088000 lua.img -binary -offset 0x088000
得到的nodemcu_32mb.bin烧录到MCU即可。