ESP8266: Say ‘hello’ to Frankenstein

Since I’ve got some homebrew development boards ready, it’s time to get hacking.
I stocked on coffee and gave esp8266 SDK a deep dive this weekend. The code is really weird, lots of things are unknown, API is shitty, blobs all around the place. First of all, to make things clear – I’m not going to fix or do anything with AT-command firmware. It sucks. Period. Sucks so much it can’t even prove useful as a reference most of the times. So… we need a replacement.

This is what I’m working on and that is now, after a weekend of hacking is in early alpha stage.

Say hello to Frankenstein Firmware for ESP8266.

 

As you might have guessed by now, my buildsystem of choice for embedded mcu things – Antares, now supports ESP8266. Not the library for AT commands like arduino, but supports compiling code for ESP8266 itself. Nothing really to say, besides the fact that it’s hacky as hell, and there are proprietary blobs all around the place. The SDK itself is a hell of a mess, so to say. But at least I managed to make some sense out of it. esp8266 support will not be present in antares master any time soon, just stay in experimental until community gets rid of the blobs. Mostly all the Antares features, like INIT_ and ATOMIC macros are missing, we just have the buildsystem and kconfig for now.

Now for the firmware. I called it Frankenstein because it has been tailored from different bits and pieces and brought to life by coffeine in the most ugly way possible.

Unlike AT commands firmware, Frankenstein offers a fullblown command line interface with line editing, history and command completion.  That’s all thanks to that awesome opensource microrl (Micro Readline) library I’ve merged into antares.

It looks slightly similar to u-boot or busybox shell, and provides some nice features. I guess the best description here will be the terminal log with help messages and me playing around with different modes.

So far you can connect to wireless networks, scan for wireless networks, setup access point mode, play with GPIO lines, reboot or enter deep sleep mode.

Frankenstein ESP8266 Firmware
Powered by Antares 0.2-rc1, Insane Mushroom
(c) Andrew 'Necromant' Andrianov 2014 
This is free software (where possible), published under the terms of GPLv2

Memory Layout:
data  : 0x3ffe8000 ~ 0x3ffe8aa8, len: 2728
rodata: 0x3ffe8ab0 ~ 0x3ffea254, len: 6052
bss   : 0x3ffea258 ~ 0x3fff1688, len: 29744
heap  : 0x3fff1688 ~ 0x3fffc000, len: 43384

 === Press enter to activate this console === 

blackblade > help

help       - Show this message
apconfig   - Setup Access Point. 
             apconfig name OPEN/WEP/WPA_PSK/WPA2_PSK/WPA_WPA2_PSK [password]
iwconnect  - Join a network/Display connection status. 
             iwconnect ssid password
iwmode     - Get/set wireless mode. Available modes: NONE, STA, AP, APSTA
             iwmode STA
iwscan     - Scan for available stations
ifconfig   - Show/setup network interfaces
             ifconfig [iface] [ipaddr] [netmask] [gateway]
             ifconfig sta0 192.168.0.1 255.255.255.0 192.168.0.8
argtest    - Print out argc/argv
deepsleep  - Enter deep sleep for some microseconds
             deepsleep 10000
reset      - Soft-reboot the device 
meminfo    - Display memory information
version    - Display version information and copyright
gpio       - Control gpio lines. gpio mode line [value] 
             gpio in 0
             gpio out 0 1
spi_dump   - Hexdump flash contents
             spi_dump start len
spi_wipe   - Wipe the whole spi flash blank
             wipe
listen     - Listen for incoming data ona port
             listen 8080


blackblade > iwscan
BSSID a8:15:1d:0c:b1:0c channel 03 rssi -54 auth WPA2_PSK     shadowgate
BSSID 1a:e6:e4:0c:f3:e4 channel 03 rssi -61 auth WPA2_PSK     frostgate


blackblade > ifconfig
sta0: WiFi Client Interface
     state: Connected
     inet addr:192.168.0.198 Mask:255.255.255.0 Gateway:192.168.0.20 

blackblade > iwmode AP
Wireless mode change: STA -> AP
blackblade > ifconfig
ap0: WiFi Access Point Interface
     state: Running
     inet addr:192.168.4.1 Mask:255.255.255.0 Gateway:192.168.4.1 

blackblade > iwmode APSTA
Wireless mode change: AP -> APSTA
blackblade > ifconfig
sta0: WiFi Client Interface
     state: Connected
     inet addr:192.168.0.198 Mask:255.255.255.0 Gateway:192.168.0.20 
ap0: WiFi Access Point Interface
     state: Running
     inet addr:192.168.4.1 Mask:255.255.255.0 Gateway:192.168.4.1 

blackblade > apconfig 
SSID: dummy AUTH 0 BSSID: 1a:fe:34:98:dc:9e
blackblade > apconfig test WPA2_PKS 12345678
Invalid encryption mode: WPA2_PKS. See help.

blackblade > apconfig test WPA2_PSK 12345678

blackblade > apconfig
SSID: test AUTH 3 BSSID: 1a:fe:34:98:dc:9e
blackblade > 

Networking itself is still WiP, we don’t even support ping. Yet. The action plan right now is:

  1. Figure out SPI flash layout and implement u-boot like environment variables and getenv/saveenv. That should take care of some remaining problems. blobs DO store some configuration internally somewhere in flash, and and it’s best to find out how and where. Really annoying.
  2. Done.

  3. Find out if we can make the board supply a DHCP hostname when obtaining an IP lease. Having to manually add hostnames to your router is annoying as hell.
  4. DHCP server for AP mode. Code available in SDK, shouldn’t be hard.
  5. Network commands. Ping is a good start, code available in SDK.
  6. Listening for incoming connections is already implemented.

  7. Network console with ssl and authorisation, so that we can free up uart for other things.
  8. TCP2UART Trasparent bridge with SSL
  9. cleanup
  10. PROFIT

If you want to help out – grab the source at github and drop me an email, I’ll tell you how to set up development environment. It might be tricky and there’s no documentation. Yet.

EDIT: Networking’s up & running, I managed to get a dumb ‘listen’ command working that will dump incoming data on a port of your choice. Network console’s next.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.