Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sming Host Emulator #1692

Merged
merged 19 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions .appveyor/build.cmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
REM Appveyor Windows build script
REM Windows build script

SET SMING_HOME=%APPVEYOR_BUILD_FOLDER%\Sming
SET ESP_HOME=c:\Espressif
SET PATH=%PATH%;%ESP_HOME%/utils

IF "%SMING_ARCH%" == "Esp8266" SET ESP_HOME=c:\Espressif

cd %SMING_HOME%
gcc -v

Expand All @@ -12,27 +13,27 @@ make list-config
REM Compile the tools first
make tools V=1 || goto :error

IF "%SDK_VERSION%" == "2.0.0" (
REM Build Host Emulator and run basic tests
set SMING_ARCH=Host
cd %SMING_HOME%
make STRICT=1 || goto :error
make Basic_Serial || goto :error
make Basic_ProgMem || goto :error
cd %SMING_HOME%\..\samples\HostTests
make flash || goto :error
)

REM Build library and test sample apps
set SMING_ARCH=Esp8266
cd %SMING_HOME%
make STRICT=1 || goto :error
cd %SMING_HOME%\..\samples\Basic_Blink
make V=1 || goto :error
cd %SMING_HOME%\..\samples\Basic_Ssl
make || goto :error
cd %SMING_HOME%\..\samples\Basic_SmartConfig
make || goto :error


if "%SMING_ARCH%" == "Host" (

REM Build a couple of basic applications
make Basic_Serial || goto :error
make Basic_ProgMem || goto :error

REM Run basic tests
cd %SMING_HOME%\..\tests\HostTests
make flash || goto :error

) ELSE (

make Basic_Blink V=1 || goto :error
make Basic_Ssl || goto :error
make Basic_SmartConfig || goto :error

)

goto :EOF

Expand Down
26 changes: 26 additions & 0 deletions .appveyor/install.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
REM Windows install script

goto :%SMING_ARCH%

:Esp8266

IF "%SDK_VERSION%" == "1.5.0" (
choco install esp8266-udk --source https://www.myget.org/F/kireevco-chocolatey/ -y --no-progress
mkdir c:\Espressif\utils\ESP8266
copy /b c:\Espressif\utils\memanalyzer.exe c:\Espressif\utils\ESP8266\memanalyzer.exe
copy /b c:\Espressif\utils\esptool.exe c:\Espressif\utils\ESP8266\esptool.exe
) ELSE (
choco install esp8266-udk --source https://www.myget.org/F/sming/ -y --no-progress
)

goto :EOF


:Host

REM Ensure MinGW installation is up to date
mingw-get update
mingw-get upgrade

goto :EOF

70 changes: 32 additions & 38 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,34 @@ env:
global:
- SDK_BUILD=258
- secure: D/cPk+sL2MNHLtfuU/rMiVN63+CTFpo9Chqa39LEH5VloGqC5f7RyIi2Maa3C/U2JQfM01HlsNR7E5bB0W8DQYbtzBDTqbZ4C7ppZRU5jCQ+L51ERKJ0EAV3KkaravQCRbWt3tlgOp6Xk6xaRMBaHEGrdbFjHYgEMPVteUQNr0A=
matrix:
jobs:
include:
- os: linux
env: SDK_VERSION=1.5.0
- os: linux
env: SDK_VERSION=2.0.0
- os: linux
- stage: test
os: linux
dist: xenial
env: SDK_VERSION=3.0.0
addons:
apt:
packages:
- clang-format-6.0
- gcc-multilib
- g++-multilib
env: SMING_ARCH=Host

- stage: build
os: linux
env: SMING_ARCH=Esp8266 SDK_VERSION=1.5.0

- stage: build
os: linux
env: SMING_ARCH=Esp8266 SDK_VERSION=2.0.0

- stage: build
os: linux
env: SMING_ARCH=Esp8266 SDK_VERSION=3.0.0

git:
submodules: false

addons:
apt:
sources:
Expand All @@ -28,42 +45,19 @@ addons:
- doxygen-gui
- graphviz
- xmlstarlet
- clang-format-6.0
- gcc-multilib
- g++-multilib
install:
- sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-6.0 100
- if [ "$SDK_VERSION" == "1.5.0" ] && [ "$TRAVIS_OS_NAME" == "osx" ]; then
export SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-macos-x86_64.zip";
fi
- if [ "$SDK_VERSION" == "1.5.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then
export SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-linux-x86_64.tar.gz";
fi
- mkdir -p $TRAVIS_BUILD_DIR/opt/esp-alt-sdk
- if [ "$SDK_VERSION" == "1.5.0" ]; then
wget https://bintray.com/artifact/download/kireevco/generic/${SDK_FILE_NAME};
fi
- if [ "$SDK_VERSION" == "1.5.0" ]; then
bsdtar -xf ${SDK_FILE_NAME} -C $TRAVIS_BUILD_DIR/opt/esp-alt-sdk;
fi
- if [[ "$SDK_VERSION" != "1.5.0" && "$TRAVIS_OS_NAME" == "linux" ]]; then
wget https://github.com/nodemcu/nodemcu-firmware/raw/2d958750b56fc60297f564b4ec303e47928b5927/tools/esp-open-sdk.tar.xz;
tar -Jxvf esp-open-sdk.tar.xz; ln -s `pwd`/esp-open-sdk/xtensa-lx106-elf $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/.;
fi
- if [ "$SDK_VERSION" == "2.0.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then
wget https://www.espressif.com/sites/default/files/sdks/esp8266_nonos_sdk_v2.0.0_16_08_10.zip -O sdk.zip;
unzip sdk.zip;
ln -s `pwd`/ESP8266_NONOS_SDK/ $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/sdk;
export DEPLOY='true';
fi
script: sh $TRAVIS_BUILD_DIR/.travis/build.sh

install: .travis/install.sh

script: .travis/build.sh

deploy:
provider: script
script: sh $TRAVIS_BUILD_DIR/.travis/deploy.sh $TRAVIS_TAG
script: .travis/deploy.sh $TRAVIS_TAG
skip_cleanup: true
on:
tags: true
condition: "$DEPLOY == true"
condition: "$SDK_VERSION==2.0.0"

notifications:
webhooks:
urls:
Expand Down
59 changes: 33 additions & 26 deletions .travis/build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
#!/bin/bash
set -e # exit with nonzero exit code if anything fails
set -ex # exit with nonzero exit code if anything fails

env
unset SPIFFY
unset ESPTOOL2

export SMING_HOME=$TRAVIS_BUILD_DIR/Sming
export ESP_HOME=$TRAVIS_BUILD_DIR/opt/esp-alt-sdk
if [ "$SDK_VERSION" = "3.0.0" ]; then
export SDK_BASE=$SMING_HOME/third-party/ESP8266_NONOS_SDK

# Check coding style
if [ "$TRAVIS_BUILD_STAGE_NAME" == "Test" ]; then
.travis/tools/clang/format-pr.sh;
fi

cd $SMING_HOME
# Setup ARCH SDK paths
if [ "$SMING_ARCH" == "Esp8266" ]; then
export ESP_HOME=$TRAVIS_BUILD_DIR/opt/esp-alt-sdk
if [ "$SDK_VERSION" == "3.0.0" ]; then
export SDK_BASE=$SMING_HOME/third-party/ESP8266_NONOS_SDK
fi

export PATH=$PATH:$ESP_HOME/xtensa-lx106-elf/bin:$ESP_HOME/utils/:$SMING_HOME/../.travis/tools
if [ "$SDK_VERSION" = "2.0.0" ]; then
../.travis/tools/clang/format-pr.sh;
export PATH=$PATH:$ESP_HOME/xtensa-lx106-elf/bin:$ESP_HOME/utils/
fi

if [ "$SDK_VERSION" = "3.0.0" ]; then
export SMING_ARCH=Host
export STRICT=1
make help
make list-config
make
make Basic_Blink Basic_DateTime Basic_Delegates Basic_Interrupts Basic_ProgMem Basic_Serial Basic_Servo LiveDebug DEBUG_VERBOSE_LEVEL=3
cd ../samples/HostTests
make flash
cd $SMING_HOME
fi
# Full compile checks please
export STRICT=1

export SMING_ARCH=Esp8266
# Diagnostic info
cd $SMING_HOME
make help
make list-config
make STRICT=1
make samples
make clean samples-clean
make ENABLE_CUSTOM_HEAP=1 STRICT=1
make Basic_Blink ENABLE_CUSTOM_HEAP=1 DEBUG_VERBOSE_LEVEL=3
make dist-clean; make HttpServer_ConfigNetwork ENABLE_CUSTOM_LWIP=2 STRICT=1

# Build the framework
make
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could try also parallel build splitting this command to the following two:

make submodules
make -j

Copy link
Contributor Author

@mikee47 mikee47 May 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could.... I gave it a brief try with appveyor but after one initial failure didn't bother any further as I figured what we really need is a clear and accurate log for when it goes wrong. I had a hell of a job with the initial CI updates on appveyor, had to remote terminal into the server to find out how to fix things so really rather not have to do that if poss.!

The --output-sync option might help but haven't tried it - I have make 3.81 under MinGW which doesn't have the option anyway. I use parallel building all the time under Windows, on an 8-core system it kind of speeds things up just a teeny bit :-)

I suspect on a VM parallel builds wouldn't help much anyway. My Linux install is running under VirtualBox and really doesn't like parallel builds at all, but that's my problem!

I suspect we'd also need lwip:

make submodules
make lwip
make -j


if [ "$TRAVIS_BUILD_STAGE_NAME" == "Test" ]; then
make Basic_Blink Basic_DateTime Basic_Delegates Basic_Interrupts Basic_ProgMem Basic_Serial Basic_Servo LiveDebug DEBUG_VERBOSE_LEVEL=3
cd ../tests/HostTests
make flash
else
make samples
make clean samples-clean
make ENABLE_CUSTOM_HEAP=1 STRICT=1
make Basic_Blink ENABLE_CUSTOM_HEAP=1 DEBUG_VERBOSE_LEVEL=3

make dist-clean
make HttpServer_ConfigNetwork ENABLE_CUSTOM_LWIP=2 STRICT=1
fi
2 changes: 1 addition & 1 deletion .travis/deploy.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e # exit with nonzero exit code if anything fails
set -ex # exit with nonzero exit code if anything fails

TAG=$1
if [ -z $TAG ]; then
Expand Down
34 changes: 34 additions & 0 deletions .travis/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
set -ex # exit with nonzero exit code if anything fails

if [ "$TRAVIS_BUILD_STAGE_NAME" == "Test" ]; then
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-6.0 100
fi

if [ "$SMING_ARCH" == "Esp8266" ]; then
if [ "$SDK_VERSION" == "1.5.0" ] && [ "$TRAVIS_OS_NAME" == "osx" ]; then
SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-macos-x86_64.zip"
fi

if [ "$SDK_VERSION" == "1.5.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then
SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-linux-x86_64.tar.gz"
fi

mkdir -p $TRAVIS_BUILD_DIR/opt/esp-alt-sdk

if [ "$SDK_VERSION" == "1.5.0" ]; then
wget --no-verbose https://bintray.com/artifact/download/kireevco/generic/${SDK_FILE_NAME}
bsdtar -xf ${SDK_FILE_NAME} -C $TRAVIS_BUILD_DIR/opt/esp-alt-sdk
fi

if [ "$SDK_VERSION" != "1.5.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then
wget --no-verbose https://github.com/nodemcu/nodemcu-firmware/raw/2d958750b56fc60297f564b4ec303e47928b5927/tools/esp-open-sdk.tar.xz
tar -Jxvf esp-open-sdk.tar.xz; ln -s `pwd`/esp-open-sdk/xtensa-lx106-elf $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/.
fi

if [ "$SDK_VERSION" == "2.0.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then
wget --no-verbose https://www.espressif.com/sites/default/files/sdks/esp8266_nonos_sdk_v2.0.0_16_08_10.zip -O sdk.zip
unzip sdk.zip
ln -s `pwd`/ESP8266_NONOS_SDK/ $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/sdk
fi
fi # Esp8266
6 changes: 0 additions & 6 deletions Sming/Arch/Esp8266/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ endif
## MacOS / Linux:
# ESP_HOME = /opt/esp-open-sdk

#ifeq ($(OS),Windows_NT)
# # Convert Windows paths to POSIX paths
# ESP_HOME := $(subst \,/,$(addprefix /,$(subst :,,$(ESP_HOME))))
# ESP_HOME := $(subst //,/,$(ESP_HOME))
#endif

CONFIG_VARS += ESP_HOME
ESP_HOME := $(call FixPath,$(ESP_HOME))
export ESP_HOME
Expand Down
21 changes: 16 additions & 5 deletions Sming/Arch/Host/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,25 @@ At present the emulator just writes output to the console. Inputs all return 0.

Support is provided via TAP network interface (a virtual network layer operating at the ethernet frame level). A TAP interface must be created first, and requires root priviledge:

```
sudo ip tuntap add dev tap0 mode tap user `whoami`
sudo ip a a dev tap0 192.168.13.1/24
sudo ifconfig tap0 up
```
sudo ip tuntap add dev tap0 mode tap user `whoami`
sudo ip a a dev tap0 192.168.13.1/24
sudo ifconfig tap0 up

This creates the `tap0` interface, and is persistent across OS reboots. The emulator will automatically select the first `tap` interface found. To override this, use the `--ifname` option. An IP address will be assigned, but can be changed using the `--ipaddr` option.
slaff marked this conversation as resolved.
Show resolved Hide resolved

If your application needs to access the internet, additional setup is required:

sudo sysctl net.ipv4.ip_forward=1
sudo sysctl net.ipv6.conf.default.forwarding=1
sudo sysctl net.ipv6.conf.all.forwarding=1

export INTERNET_IF=wlan0 # <!--- Make sure to replace wlan0 with the network interface connected to Internet

sudo iptables -t nat -A POSTROUTING -o $INTERNET_IF -j MASQUERADE
sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i tap0 -o $INTERNET_IF -j ACCEPT


#### Windows

Requires [NPCAP](https://nmap.org/npcap/) library to be installed. Provided with current (3.0.2) version of [Wireshark](https://www.wireshark.org/download.html).
Expand Down
2 changes: 1 addition & 1 deletion Sming/Makefile-windows.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SDK_BASE ?= $(ESP_HOME)/ESP8266_SDK
SDK_TOOLS ?= $(ESP_HOME)/utils

# Other tools mappings
ESPTOOL ?= $(SDK_TOOLS)/ESP8266/esptool.exe
ESPTOOL ?= $(SDK_TOOLS)/esptool/esptool.py
KILL_TERM ?= taskkill.exe -f -im Terminal.exe || exit 0
GET_FILESIZE ?= stat --printf="%s"
TERMINAL ?= $(SDK_TOOLS)/Terminal.exe $(COM_PORT) $(COM_SPEED_SERIAL) $(COM_OPTS)
26 changes: 10 additions & 16 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
os: Windows Server 2012 R2

environment:
PATH: C:\MinGW\msys\1.0\bin;C:\MinGW\bin;C:\Program Files (x86)\Mono-3.2.3\bin;C:\Python27\scripts;%PATH%
PATH: C:\MinGW\msys\1.0\bin;C:\MinGW\bin;C:\Python27\scripts;%PATH%
SDK_BUILD: 258
matrix:
- build_platform: "x86"
build_compiler: "mingw"
build_bindings: 1
SMING_ARCH: Host

- build_platform: "x86"
build_compiler: "mingw"
SMING_ARCH: Esp8266
SDK_VERSION: 2.0.0

- build_platform: "x86"
build_compiler: "mingw"
build_bindings: 1
SMING_ARCH: Esp8266
SDK_VERSION: 1.5.0

# cache:
# - src/ # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified
install:
- ps: >-
if($env:SDK_VERSION -eq '1.5.0') {
choco install esp8266-udk --source https://www.myget.org/F/kireevco-chocolatey/ -y --no-progress
mkdir c:\Espressif\utils\ESP8266
cp c:\Espressif\utils\memanalyzer.exe c:\Espressif\utils\ESP8266\memanalyzer.exe
cp c:\Espressif\utils\esptool.exe c:\Espressif\utils\ESP8266\esptool.exe
}
else {
choco install esp8266-udk --source https://www.myget.org/F/sming/ -y --no-progress
}
- cmd: mingw-get update
- cmd: mingw-get upgrade
- cmd: .appveyor/install.cmd

build_script:
- cmd: .appveyor/build.cmd
Loading