micropython自行編譯可直接運行的固件

micropython+ESP8266直接做些小玩具是很簡單的。但是如果每次都要上傳mian.py就很不理想了

而不是編譯出一個通用的玩意,而是一個直接啓動功能的固件,需要自行編譯micropython,然後改改mian.c

main.py is a proper place to put your start code in. That resides in the flash file system. If you prefer to have it in the scripts folder, which moves into the frozen files space, then you have to change esp8266/main.c and rebuild.
But bothing prevents you from putting your startup code in _boot.py. If you look into main.c, you'll see:
CODE: SELECT ALL

#if MICROPY_MODULE_FROZEN
    pyexec_frozen_module("_boot.py");
    pyexec_file("boot.py");
    pyexec_file("main.py");
#endif
which means, that _boot.py, boot.py and main.py are simply executed one after another.

B.T.W.: I'm not sure whether boot.py and main.py should only be execute whan MICROPY_MODULE_FROZEN is set. Maybe that's just a leftover from an earlier development phase.
If you are compiling your own firmware this was the solution offered to me and I think the most useable at the moment.

https://forum.micropython.org/viewtopic.php?f=15&t=2114&e=1&view=unread#unread

Basically you just put the code you want executed into the scripts/ folder and edit main.c to add:

pyexec_frozen_module("myscript.py");

或者改 _boot.py

Thanks for that, which pointed me to this solution. I modified the _boot.py in my project's frozen directory to read
CODE: SELECT ALL

# Existing code omitted up to here:
    inisetup.setup()

try:
    uos.stat('/main.py')
except OSError:
    with open("/main.py", "w") as f:
        f.write("""\
import mqtt
""")

gc.collect()
Erase the flash before installing the firmware.

 再或者給bin加一段。。。

You can also drop a dos-fs image (must have a sector size=4096) at offset 561152. This image can contain boot.py and whatever other Python or data files you need.

That's what I'm doing.

But this is really not well documented, and I suspect that this offset may be subject to future change.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章