Is it possible to execute a binary from LittleFS on ESP8266?

I was looking at the datasheet for the ESP-8266, and noticed that there's only 1MB in flash for user programs. For an upcoming project, I'm not sure this will be enough. Would it be possible to execute pre-compiled binaries from the LittleFS partition in flash on an ESP-8266 chip? This would also be nice because I'd be able to easily load and offload programs from the chip (wirelessly), without having to set up something like OTA programming.

Only if the micro-controller chips are identical, the speed is identical and the io connections are identical.

1 Like

I do not see why that cannot be accomplished. I have never done it with this processor. It would be best if you studied the OTA (Over The Air) programing code so you understand how this works. In other systems we called it an overlay where sections of code would be loaded into RAM then executed. Take a look at this link: ESP_EEPROM is data persistent when flashing new rev or new program? - #4 by gilshultz

I think it could be possible, if the raw bites of the file were just loaded into memory, but now I'm worried about actually compiling the programs. They probably wouldn't compile in the Arduino IDE, because that would require things like the setup() and loop(), and probably variable definitions as well...

For those interested, my current plan is to have a sort of "base system" in place, and that can load smaller programs from pre-compiled binaries in the filesystem, which will sort of act like small tasks that can be easily modified; the filesystem binaries are not entire sketches, but smaller programs that will run.

My issue at this point is that I'm not sure if I'll be able to compile those binaries to work with the main program, at least not through the ardiuno IDE. Does anybody know of how I could potentially do this?

Are you suggesting you are going to use a "linker" to patch compiled code together? Will the code files have identical format?

1 Like

Not entirely clear on what you mean by identical format, but I'm planning to allow these binaries to interact with functions/variables in the main program. But as of now, I'm not entire sure how I could go about doing this.

73

Your "binaries" must have a format that first identifies the memory location and then the data that goes in that location, and possibly the length of the data for that location. Do you have documentation on the "binaries" you are referencing?

1 Like

The binaries are my own pre-compiled scripts, that can be dynamically loaded as files from a LittleFS filesystem. My plan is to read whatever file I'm trying to load from LittleFS, load the raw bytes into a memory address, and then run it through a function pointer. My problem is compiling these scripts to work with the main program, while still being separate .bin files.

I moved your topic to an appropriate forum category @tsel1209.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Can you report that works are you explained and the code will actually run as programmed?

Move to an ESP32.

1 Like

The 8266 has only 32Kb of instruction RAM, which is typically used for interrupt handlers and other critical functions. Where, exactly, would a "program" from LittleFS be moved to so it can be executed? The filesystem itself is in data space, and nothing contained in the fielsystem can be executed without first being copied to some form of instruction memory.

I am confident that it would be much easier to write a single program with the ability to carry out several different tasks (choice based on some user input) than to implement your code-swapping idea.

2 Likes

Bear with me here, as I'm used to more high-level programming. My idea is to read the data from the file, and allocate some memory for it. After storing it there, I could create a function pointer and run that function.

You are trying to reinvent the concept of overlays from the Jurassic period of computing.

Unfortunately you have several problems.

  1. It required an overlay link editor to map the overlays correctly
  2. It required a loader to resolve the addresses at load time
  3. It was a bitch to hand build the structure

The esp tools do not support user overlays.

In fact the system is already doing something like this because the program size can be larger than the executable instruction RAM space. Anything that does not fit in instruction RAM memory is paged in from flash for execution with a bunch of address remapping and a significant performance hit.

The instruction RAM is separate from data RAM, so you could not load code into data RAM and execute it there.

Write smaller code or get a processor with more executable RAM.

2 Likes

Yep, and boy, was that a pain in the butt to code (Fortran on a PDP-11).

2 Likes

ONLY if you have enough unused RAM remaining in the 32K instruction RAM to hold the code you are loading from the filesystem. You CANNOT execute code from data RAM, only from instruction RAM. The Tensilica has separate busses for instructions and data, not a single, global memory space like many other processors.

X-ray crystallography analysis on a 360/30. We used overlays for the
code and disc for large arrays. We read in the arrays in pieces for
processing. Run would take hours. The night shift loved us - 15-20 pages
of output in a couple of hours. They could go do other things and even
if the printer didn't stack the paper it wasn't a problem.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.