Flashing with custom files in default filesystem possible?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
Hyperion
Posts: 13
Joined: Wed Oct 16, 2019 9:34 am

Flashing with custom files in default filesystem possible?

Post by Hyperion » Tue Jan 28, 2020 1:38 am

Is it possible to compile the firmware with custom files already included in the filesystem, and how? By default only the boot.py gets created but I would like to include several other files aswell, so that they are already present in the filesystem when I flash the firmware.


I'm using the ESP32 in case it matters.

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: Flashing with custom files in default filesystem possible?

Post by russ_h » Tue Jan 28, 2020 5:08 am

You can create a file system image with files and flash that to the device. https://penfold.owt.com/turtleplotbot/s ... vfat-image

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Flashing with custom files in default filesystem possible?

Post by jimmo » Tue Jan 28, 2020 10:18 am

There was some discussion of this in this thread: viewtopic.php?f=16&t=6677

The basic idea is that on flash the filesystem follows the firmware, so if you add your own filesystem image to the end of the firmware (such that it ends up at the expected location) then it works.

If your goal is to add Python code or file resources to the firmware, then freezing may be a better option, (and for non-Python files, Peter's solution described here: https://github.com/micropython/micropyt ... -562918657 might be of interest)

User avatar
Hyperion
Posts: 13
Joined: Wed Oct 16, 2019 9:34 am

Re: Flashing with custom files in default filesystem possible?

Post by Hyperion » Tue Jan 28, 2020 4:55 pm

russ_h wrote:
Tue Jan 28, 2020 5:08 am
You can create a file system image with files and flash that to the device. https://penfold.owt.com/turtleplotbot/s ... vfat-image
Thanks, I followed the steps and it's working flawlessly! Exactly what I needed :).

@jimmo thanks for the other tips, the data_to_py utility looks particularly useful. But the problem is that I want to upload a 1MB webpage to the module, together with its file hierarchy, and make it working with MicroWebSrv2 which searches within the filesystem directory. Maybe there's a way to make it working with the frozen code but if everything was a .py file instead of .html or .js I would have to carefully reroute literally everything, and I don't really mind the 1MB wasted space as I'm not going to use it for anything else.

Post Reply