afnid / espsim

ESP8266 Simulator (Allows Native Code to Link/Run on Linux)
GNU General Public License v2.0
65 stars 12 forks source link

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.

The Bad

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

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