jonasfsilva / espsim

ESP8266 Simulator (Allows Native Code to Link/Run on Linux)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

espsim

ESP8266 Simulator (Allows Native Code to Link/Run on Linux)

Allows native esp8266 code to be be cross-compiled to run native 32 bit executable on a host computer (currently linux) .. not to be confused with using the xtensa cross-compiler to create a native esp8266 image that can only be run on an esp8266 cpu.

I am releasing this because it has proven useful for me and has become integral to my development process because I can run a native Linux executable that will communicate with actual esp8266 processors.

  1. Note, this was only used against a single application and it was done quick & dirty to get it to bootstrap and run. Mileage will vary.
  2. This is not production level code, there are likely gaps and potential differences in my implementation relative to embedded code.
  3. If your not that experienced with C/C++, you might want to wait and see if this project matures some before trying to get it to port.
  4. Porting to other platforms may be a little involved (network.cpp), I will likely do a mac port, not too motivated on cygwin.
  5. Looking for contributions, with a little work and more testing, this could become useful for a lot more people.

The Good

I was able to use this to do some unit/stress testing on some embedded code using valgrind. Later I added the espconn networking support so I could again use valgrind with much further coverage. Currently I use this for networking/application code before flashing to an embedded device.

  • Allows esp8266 code to be run with native tools like gdb and valgrind.
  • Networking is implemented allowing a native esp8266 process to blend with networked devices.
  • Emulation of flash and rtc memory storage implemented in a way to fail fast on boundary errors.
  • Limited options for setting the heap size, tracking memory allocations/frees, and tracing network.
  • Provides an esp.h header file that works on Linux and for esp8266 c++ code
  • Was developed using the 1.2.0 sdk, and works equally well with 1.3.0.
  • A C++ compliant esp.h that has all the missing prototypes I ran into so far

The Bad

There are some issues getting this to work, mostly because this needs to be built using a 32-bit environment..

  • The esp8266 is 32 bit, so compiling on a 64-bit host caused several issues with sizes of longs and pointers.
  • The system task post arg is defined as a 32 bit value, you can set it to a pointer since they are also 32 bits, not on 64-bit os.
  • Definitely does not handle simulation of off-chip devices, more suited for testing systems programming code.
  • Had to make a couple of manual changes to the esp8266 header files to make this work correctly.
  • Has not been ported to any other platforms other than a 64-bit ubuntu/mint installation.
  • Need to add this function to your code in order to get tty input: void uart_hook(char ch) {}
  • valgrind reports some issues in my networking code at shutdown, should clean that up.
  • Probably needs a ton more options to set/override runtime defaults.

The Ugly

I run 64-bit Ubuntu/Mint environment system, and has had a lot of packages already installed at this point. You could use virtualbox to run a 32-bit environment, or what I did was carefully add i386 libraries until I got it to link. Looking through packages installed I see libc6-dev-i386, libc6-i386, g++-4.8-multilib, valgrind-i386 (removes the 64 bit version!).

Be careful of anything that wants to replace all of your shared libraries with 32 bit versions.

Maybe it can work on a 64-bit install but the required changes looked a little more daunting.

The following headers were changed:

eagle_soc.h

Around line 45, change the following to stop the gpio calls from segfaulting:

#define ETS_UNCACHED_ADDR(addr) (addr)
#define ETS_CACHED_ADDR(addr) (addr)

with:

// LINUX
#ifndef ETS_UNCACHED_ADDR
#define ETS_UNCACHED_ADDR(addr) (addr)
#endif

#ifndef ETS_CACHED_ADDR #define ETS_CACHED_ADDR(addr) (addr) #endif

c_types.h

Replace

typedef signed long         int32_t;

with:

#ifndef __uint32_t_defined
typedef signed long         int32_t;
#endif

About

ESP8266 Simulator (Allows Native Code to Link/Run on Linux)

License:GNU General Public License v2.0


Languages

Language:C++ 86.2%Language:C 11.5%Language:Makefile 2.3%