How to freeze non-code/assets files into firmware and access later. #10707
-
I'm looking for help, or a pointer to some documentation on how to "freeze" non-python files in firmware such as images, sounds, or other compressed assets into the firmware. I currently have a built toolchain setup in WSL, and can build custom images for my board. I can create .mpy, or add .py files to be frozen into firmware but I don't see documentation on how to freeze other things like graphics, or sounds into firmware, or how those assets would be accessed. I also can't seem to find how I would modify the default file system with additional files, like settings files along side the current defaults of main.py and boot.py. Is there a way to add additional default files to the file system, like boot.py and main.py are added automatically now? I'm dreading the idea that I might have to convert all my assets to some sort of .py file containing binary data. Has anyone done this, knows how to do this, or can you point me to documentation specifically on these questions? Thanks all! |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 10 replies
-
Credits to Peter https://github.com/peterhinch/micropython_data_to_py There are more gems where this came from. |
Beta Was this translation helpful? Give feedback.
-
I guess I just wanted to know what was available before I spent my time writing a library to do the same as Peter. @Josverl, thanks again for this link; most of the leg work is done for the creation, and I think I can extend this to behave a bit more like a file system being able to keep track of original/relative virtual file paths as well as allowing the file data to be flagged and compressed when building, and then decompressed with zlib to save some space if desired. I assume there would be a need to check and modify the partition sizes if the firmware size grew too large due to the added static data. I'm not sure if there is a hard cap on the firmware size. |
Beta Was this translation helpful? Give feedback.
-
@Josverl you have my attention 😄 |
Beta Was this translation helpful? Give feedback.
-
You may want to read up on mapfs in PR #8381. It's had a lot of effort and looks very promising - but probably won't land on mainline for a little while as it's quite a large feature. |
Beta Was this translation helpful? Give feedback.
-
Seems that PR #8381 made progress. I do not completely understand how vfs-map could help me in practice to bundle also asset files into one single firmware.bin that I can deploy? |
Beta Was this translation helpful? Give feedback.
-
Until #8381 is ready, take a look at https://github.com/bixb922/freezefs That utility archives files and folders into a .py file. You freeze that file into a MicroPython image. When you import that file, the files/folders get mounted as a readonly vfs file system with little RAM overhead. |
Beta Was this translation helpful? Give feedback.
Credits to Peter
https://github.com/peterhinch/micropython_data_to_py
There are more gems where this came from.