aboutsummaryrefslogtreecommitdiff
path: root/targets/baremetal-sdk
diff options
context:
space:
mode:
Diffstat (limited to 'targets/baremetal-sdk')
-rw-r--r--targets/baremetal-sdk/curie-bsp/README.md120
-rw-r--r--targets/baremetal-sdk/curie-bsp/image/connect.pngbin0 -> 588451 bytes
-rw-r--r--targets/baremetal-sdk/curie-bsp/include/inttypes.h18
-rw-r--r--targets/baremetal-sdk/curie-bsp/include/setjmp.h25
-rw-r--r--targets/baremetal-sdk/curie-bsp/jerry_app/arc/defconfig16
-rw-r--r--targets/baremetal-sdk/curie-bsp/jerry_app/arc/main.c35
-rw-r--r--targets/baremetal-sdk/curie-bsp/jerry_app/arc/memory_pool_list.def36
-rw-r--r--targets/baremetal-sdk/curie-bsp/jerry_app/include/project_mapping.h30
-rw-r--r--targets/baremetal-sdk/curie-bsp/jerry_app/quark/defconfig35
-rw-r--r--targets/baremetal-sdk/curie-bsp/jerry_app/quark/main.c172
-rw-r--r--targets/baremetal-sdk/curie-bsp/jerry_app/quark/memory_pool_list.def36
-rwxr-xr-xtargets/baremetal-sdk/curie-bsp/setup.py251
-rw-r--r--targets/baremetal-sdk/curie-bsp/source/curie-bsp-port.c72
-rw-r--r--targets/baremetal-sdk/curie-bsp/source/setjmp.S77
-rw-r--r--targets/baremetal-sdk/esp-idf/CMakeLists.txt.example16
-rw-r--r--targets/baremetal-sdk/esp-idf/README.md28
-rw-r--r--targets/baremetal-sdk/esp-idf/jerry_module.c293
-rw-r--r--targets/baremetal-sdk/esp-idf/jerry_port.c283
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/LICENSE56
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/Makefile162
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp826688
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.travis46
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/docs/ESP-PREREQUISITES.md120
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/include/jerry_extapi.h30
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/include/jerry_run.h32
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/include/user_config.h24
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/js/blink.js30
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/js/main.js20
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/ld/eagle.app.v6.ld32
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/readme.md88
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/user/Makefile44
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/user/jerry_extapi.c182
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/user/jerry_port.c73
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/user/jerry_run.c109
-rw-r--r--targets/baremetal-sdk/esp8266-rtos-sdk/user/user_main.c147
-rw-r--r--targets/baremetal-sdk/particle/Makefile.particle63
-rw-r--r--targets/baremetal-sdk/particle/README.md92
-rw-r--r--targets/baremetal-sdk/particle/source/main.cpp146
38 files changed, 3127 insertions, 0 deletions
diff --git a/targets/baremetal-sdk/curie-bsp/README.md b/targets/baremetal-sdk/curie-bsp/README.md
new file mode 100644
index 00000000..051e5f0a
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/README.md
@@ -0,0 +1,120 @@
+### About Curie BSP port
+[Intel® Curie BSP](https://github.com/CurieBSP/main/blob/master/README.rst) is the SDK that will help you developing software on Curie based boards, for example with the [Arduino 101 board (AKA Genuino 101)](https://www.arduino.cc/en/Main/ArduinoBoard101).
+
+This folder contains necessary files to integrate JerryScript with Intel® Curie BSP, so that JavaScript can run on Arduino 101 board (AKA Genuino 101).
+
+### How to build
+#### 1. Preface
+
+Curie BSP only support Ubuntu GNU/Linux as host OS environment.
+
+Necessary hardwares
+* [FlySwatter2 JTAG debugger](https://www.tincantools.com/wiki/Flyswatter2)
+* [ARM-JTAG-20-10](https://www.amazon.com/PACK-ARM-JTAG-20-10-Micro-JTAG-adapter/dp/B010ATK9OC/ref=sr_1_1?ie=UTF8&qid=1469635131&sr=8-1&keywords=ARM+Micro+JTAG+Connector)
+* [USB to TTL Serial Cable](https://www.adafruit.com/products/954)
+
+#### 2. Prepare Curie BSP
+
+You can refer to a detailed document [Curie BSP](https://github.com/CurieBSP/main/releases). But, we summary the main steps below:
+
+##### 1. Get repo:
+```
+mkdir ~/bin
+wget http://commondatastorage.googleapis.com/git-repo-downloads/repo -O ~/bin/repo
+chmod a+x ~/bin/repo
+```
+
+##### 2. In ``~/.bashrc`` add:
+```
+PATH=$PATH:~/bin
+```
+
+##### 3. Create your directory for CurieBSP (eg. Curie_BSP):
+```
+mkdir Curie_BSP && cd $_
+```
+
+##### 4. Initialize your repo:
+```
+repo init -u https://github.com/CurieBSP/manifest
+```
+
+##### 5. Download the sources files:
+```
+repo sync -j 5 -d
+```
+
+##### 6. Get toolchain (compilation/debug):
+Download [issm-toolchain-linux-2016-05-12.tar.gz](https://software.intel.com/en-us/articles/issm-toolchain-only-download), and uncompress it.
+**TOOLCHAIN_DIR** environment variable needs to match the toolchain destination folder
+You can use the command:``export TOOLCHAIN_DIR='path to files of the toolchain'``
+
+Or you can just uncompress the toolchain tarball and copy the contents (`licensing readme.txt tools version.txt`) into `wearable_device_sw/external/toolchain`.
+
+##### 7. Get BLE firmware:
+Download [curie-ble-v3.1.1.tar.gz]( https://registrationcenter.intel.com/en/forms/?productid=2783) and uncompress the retrieved package into ``wearable_device_sw/packages`` folder
+
+You will first register in the web page. Then you will receive an email where is a download link. Click the link in the mail, choose the `curie-ble-v3.1.1.tar.gz (118 KB)` and download.
+
+##### 8. Get tools to flash the device:
+[https://01.org/android-ia/downloads/intel-platform-flash-tool-lite](https://01.org/android-ia/downloads/intel-platform-flash-tool-lite)
+
+
+#### 3. Build JerryScript and Curie BSP
+##### 1. Generate makefiles
+Run the Python script ``setup.py`` in ``jerryscript/targets/baremetal-sdk/curie-bsp/`` with the full path or relative path of the ``Curie_BSP``:
+```
+python setup.py <path of Curie_BSP>
+```
+
+##### 2. One time setup. It will check/download/install the necessary tools, and must be run only once.
+In the directory ``Curie_BSP``
+```
+make -C wearable_device_sw/projects/curie_bsp_jerry/ one_time_setup
+```
+
+##### 3. In the directory ``Curie_BSP``
+```
+mkdir out && cd $_
+make -f ../wearable_device_sw/projects/curie_bsp_jerry/Makefile setup
+make image
+```
+
+##### 4. Connect JTAG Debugger and TTL Serial Cable to Arduino 101 as below:
+![](./image/connect.png)
+
+##### 5. Flash the firmware
+```
+make flash FLASH_CONFIG=jtag_full
+```
+
+
+#### 4. Serial terminal
+Assume the serial port is ``ttyUSB0`` in ``/dev`` directory, we can type command ``screen ttyUSB0 115200`` to open a serial terminal.
+
+After the board boot successfully, you should see something like this:
+```
+Quark SE ID 16 Rev 0 A0
+ARC Core state: 0000400
+BOOT TARGET: 0
+ 6135|QRK| CFW| INFO| GPIO service init in progress..
+ 6307|ARC|MAIN| INFO| BSP init done
+ 6315|ARC| CFW| INFO| ADC service init in progress..
+ 6315|ARC| CFW| INFO| GPIO service init in progress...
+ 6315|ARC| CFW| INFO| GPIO service init in progress...
+ 6315|ARC|MAIN| INFO| CFW init done
+```
+To test the JavaScript command, you should add characters ``js e `` to the beginning of the JavaScript command, like this:
+``js e print ('Hello World!');``
+
+It is the uart command format of Curie BSP. `js` is cmd group, `e` is cmd name, which is short for eval, and `print ('Hello World!');` is the cmd parameters, which is the JavaScript code we want to run.
+
+You can see the result through the screen:
+```
+js e print ('Hello World!');js e 1 ACK
+Hello World!
+undefined
+js e 1 OK
+```
+
+`js e 1 ACK` and `js e 1 OK` are debug info of Curie BSP uart commands, which mean it receive and execute the command successfully. `Hello World!` is the printed content. `undefined` is the return value of the statement `print ('Hello World!')`.
diff --git a/targets/baremetal-sdk/curie-bsp/image/connect.png b/targets/baremetal-sdk/curie-bsp/image/connect.png
new file mode 100644
index 00000000..da484935
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/image/connect.png
Binary files differ
diff --git a/targets/baremetal-sdk/curie-bsp/include/inttypes.h b/targets/baremetal-sdk/curie-bsp/include/inttypes.h
new file mode 100644
index 00000000..9b0ba43a
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/include/inttypes.h
@@ -0,0 +1,18 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef INTTYPES_H
+#define INTTYPES_H
+
+#endif /* !INTTYPES_H */
diff --git a/targets/baremetal-sdk/curie-bsp/include/setjmp.h b/targets/baremetal-sdk/curie-bsp/include/setjmp.h
new file mode 100644
index 00000000..aad7f934
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/include/setjmp.h
@@ -0,0 +1,25 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef SETJMP_H
+#define SETJMP_H
+
+#include <stdint.h>
+
+typedef uint64_t jmp_buf[14];
+
+int setjmp (jmp_buf env);
+void longjmp (jmp_buf env, int val);
+
+#endif /* !SETJMP_H */
diff --git a/targets/baremetal-sdk/curie-bsp/jerry_app/arc/defconfig b/targets/baremetal-sdk/curie-bsp/jerry_app/arc/defconfig
new file mode 100644
index 00000000..92e3eaca
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/jerry_app/arc/defconfig
@@ -0,0 +1,16 @@
+CONFIG_AUTO_SERVICE_INIT=y
+CONFIG_CFW_PROXY=y
+CONFIG_CFW_QUARK_SE_HELPERS=y
+CONFIG_LOG_SLAVE=y
+CONFIG_MEM_POOL_DEF_PATH="$(PROJECT_PATH)/arc"
+CONFIG_OS_ZEPHYR=y
+CONFIG_SERVICES_QUARK_SE_ADC_IMPL=y
+CONFIG_SERVICES_QUARK_SE_GPIO_IMPL=y
+CONFIG_SOC_GPIO_AON=y
+CONFIG_SOC_GPIO=y
+CONFIG_SS_ADC=y
+CONFIG_SS_GPIO=y
+CONFIG_TCMD_SLAVE=y
+CONFIG_TCMD=y
+CONFIG_ZEPHYR_BOARD="arduino_101_sss"
+CONFIG_CONSOLE_HANDLER_SHELL=y
diff --git a/targets/baremetal-sdk/curie-bsp/jerry_app/arc/main.c b/targets/baremetal-sdk/curie-bsp/jerry_app/arc/main.c
new file mode 100644
index 00000000..6042e44b
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/jerry_app/arc/main.c
@@ -0,0 +1,35 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/* infra */
+#include "infra/log.h"
+#include "infra/bsp.h"
+#include "infra/xloop.h"
+#include "cfw/cfw.h"
+
+static xloop_t loop;
+
+void main (void)
+{
+ T_QUEUE queue = bsp_init ();
+
+ pr_info (LOG_MODULE_MAIN, "BSP init done");
+
+ cfw_init (queue);
+ pr_info (LOG_MODULE_MAIN, "CFW init done");
+
+ xloop_init_from_queue (&loop, queue);
+
+ xloop_run (&loop);
+}
diff --git a/targets/baremetal-sdk/curie-bsp/jerry_app/arc/memory_pool_list.def b/targets/baremetal-sdk/curie-bsp/jerry_app/arc/memory_pool_list.def
new file mode 100644
index 00000000..e06b5931
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/jerry_app/arc/memory_pool_list.def
@@ -0,0 +1,36 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Definition of the memory pools used by balloc/bfree:
+ * DECLARE_MEMORY_POOL( <index>, <size>, <count>, <align> )
+ * <index> : must start at 0 and be of consecutive values *
+ * <size> : size in bytes of each block from the pool
+ * <count> : number of blocks in the pool
+ *
+ * * Pool definitions must be sorted according the block size
+ * value: pool with <index> 0 must have the smallest <size>.
+ */
+
+DECLARE_MEMORY_POOL(0,8,32)
+DECLARE_MEMORY_POOL(1,16,32)
+DECLARE_MEMORY_POOL(2,32,48)
+DECLARE_MEMORY_POOL(3,64,16)
+DECLARE_MEMORY_POOL(4,96,24)
+DECLARE_MEMORY_POOL(5,128,6)
+DECLARE_MEMORY_POOL(6,256,5)
+DECLARE_MEMORY_POOL(7,512,1)
+
+#undef DECLARE_MEMORY_POOL
diff --git a/targets/baremetal-sdk/curie-bsp/jerry_app/include/project_mapping.h b/targets/baremetal-sdk/curie-bsp/jerry_app/include/project_mapping.h
new file mode 100644
index 00000000..2182d88b
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/jerry_app/include/project_mapping.h
@@ -0,0 +1,30 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Allow project to override this partition scheme
+ * The following variables are allowed to be defined:
+ *
+ * QUARK_START_PAGE the first page where the QUARK code is located
+ * QUARK_NB_PAGE the number of pages reserved for the QUARK. The ARC gets the
+ * remaining pages (out of 148).
+ */
+#ifndef PROJECT_MAPPING_H
+#define PROJECT_MAPPING_H
+
+#define QUARK_NB_PAGE 125
+#include "machine/soc/intel/quark_se/quark_se_mapping.h"
+
+#endif /* !PROJECT_MAPPING_H */
diff --git a/targets/baremetal-sdk/curie-bsp/jerry_app/quark/defconfig b/targets/baremetal-sdk/curie-bsp/jerry_app/quark/defconfig
new file mode 100644
index 00000000..efc47757
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/jerry_app/quark/defconfig
@@ -0,0 +1,35 @@
+CONFIG_AUTO_SERVICE_INIT=y
+CONFIG_CFW_QUARK_SE_HELPERS=y
+CONFIG_CONSOLE_MANAGER=y
+CONFIG_DEBUG_PANIC_TCMD=y
+CONFIG_FACTORY_DATA_WRITE=y
+CONFIG_FACTORY_DATA=y
+CONFIG_INTEL_QRK_AON_PT=y
+CONFIG_INTEL_QRK_RTC=y
+CONFIG_INTEL_QRK_SPI=y
+CONFIG_INTEL_QRK_WDT=y
+CONFIG_LOG_CBUFFER_SIZE=2048
+CONFIG_LOG_CBUFFER=y
+CONFIG_MEMORY_POOLS_BALLOC_STATISTICS=y
+CONFIG_MEMORY_POOLS_BALLOC_TRACK_OWNER=y
+CONFIG_MEM_POOL_DEF_PATH="$(PROJECT_PATH)/quark"
+CONFIG_OS_ZEPHYR=y
+CONFIG_PANIC_ON_BUS_ERROR=y
+CONFIG_QUARK_SE_PROPERTIES_STORAGE=y
+CONFIG_QUARK=y
+CONFIG_SERVICES_QUARK_SE_ADC=y
+CONFIG_SERVICES_QUARK_SE_GPIO_IMPL=y
+CONFIG_SERVICES_QUARK_SE_GPIO=y
+CONFIG_SOC_FLASH=y
+CONFIG_SOC_GPIO_32=y
+CONFIG_SOC_GPIO=y
+CONFIG_SOC_ROM=y
+CONFIG_SPI_FLASH_W25Q16DV=y
+CONFIG_STORAGE_TASK=y
+CONFIG_TCMD_CONSOLE=y
+CONFIG_TCMD_MASTER=y
+CONFIG_TCMD=y
+CONFIG_UART_NS16550=y
+CONFIG_UART_PM_NS16550=y
+CONFIG_ZEPHYR_BOARD="arduino_101"
+CONFIG_CONSOLE_HANDLER_SHELL=y
diff --git a/targets/baremetal-sdk/curie-bsp/jerry_app/quark/main.c b/targets/baremetal-sdk/curie-bsp/jerry_app/quark/main.c
new file mode 100644
index 00000000..293ddbb4
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/jerry_app/quark/main.c
@@ -0,0 +1,172 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "jerryscript-port.h"
+#include "jerryscript.h"
+
+#include "cfw/cfw.h"
+#include "infra/bsp.h"
+#include "infra/log.h"
+#include "infra/reboot.h"
+#include "infra/system_events.h"
+#include "infra/tcmd/handler.h"
+#include "infra/time.h"
+#include "infra/wdt_helper.h"
+#include "microkernel/task.h"
+#include "misc/printk.h"
+#include "os/os.h"
+#include "string.h"
+#include "zephyr.h"
+
+static T_QUEUE queue;
+
+jerry_value_t print_function;
+
+void
+jerry_resolve_error (jerry_value_t ret_value)
+{
+ if (jerry_value_is_exception (ret_value))
+ {
+ ret_value = jerry_exception_value (ret_value, true);
+ jerry_value_t err_str_val = jerry_value_to_string (ret_value);
+ jerry_size_t err_str_size = jerry_string_size (err_str_val, JERRY_ENCODING_UTF8);
+ jerry_char_t *err_str_buf = (jerry_char_t *) balloc (err_str_size, NULL);
+ jerry_size_t sz = jerry_string_to_buffer (err_str_val, JERRY_ENCODING_UTF8, err_str_buf, err_str_size);
+ err_str_buf[sz] = 0;
+ printk ("Script Error: unhandled exception: %s\n", err_str_buf);
+ bfree (err_str_buf);
+ jerry_value_free (err_str_val);
+ }
+}
+
+void
+help ()
+{
+ printk ("Usage:\n");
+ printk ("js e 'JavaScript Command'\n");
+ printk ("eg. js e print ('Hello World');\n");
+}
+
+void
+eval_jerry_script (int argc, char *argv[], struct tcmd_handler_ctx *ctx)
+{
+ if (argc < 3)
+ {
+ TCMD_RSP_ERROR (ctx, NULL);
+ help ();
+ return;
+ }
+ else
+ {
+ OS_ERR_TYPE err;
+ size_t str_total_length = 0;
+ size_t *str_lens = (size_t *) balloc ((argc - 2) * sizeof (size_t), &err);
+ if (str_lens == NULL || err != E_OS_OK)
+ {
+ printk ("%s: allocate memory failed!", __func__);
+ TCMD_RSP_ERROR (ctx, NULL);
+ return;
+ }
+ for (int i = 2; i < argc; ++i)
+ {
+ str_lens[i - 2] = strlen (argv[i]);
+ str_total_length += str_lens[i - 2] + 1;
+ }
+ err = E_OS_OK;
+ char *buffer = (char *) balloc (str_total_length, &err);
+ if (buffer == NULL || err != E_OS_OK)
+ {
+ printk ("%s: allocate memory failed!", __func__);
+ TCMD_RSP_ERROR (ctx, NULL);
+ return;
+ }
+
+ char *p = buffer;
+ for (int i = 2; i < argc; ++i)
+ {
+ for (int j = 0; j < str_lens[i - 2]; ++j)
+ {
+ *p = argv[i][j];
+ ++p;
+ }
+ *p = ' ';
+ ++p;
+ }
+ *p = '\0';
+
+ jerry_value_t eval_ret = jerry_eval (buffer, str_total_length - 1, JERRY_PARSE_NO_OPTS);
+
+ if (jerry_value_is_exception (eval_ret))
+ {
+ jerry_resolve_error (eval_ret);
+ TCMD_RSP_ERROR (ctx, NULL);
+ }
+ else
+ {
+ jerry_value_t args[] = { eval_ret };
+ jerry_value_t ret_val_print = jerry_call (print_function, jerry_undefined (), args, 1);
+ jerry_value_free (ret_val_print);
+ TCMD_RSP_FINAL (ctx, NULL);
+ }
+ jerry_value_free (eval_ret);
+ bfree (buffer);
+ bfree (str_lens);
+ }
+}
+
+void
+jerry_start ()
+{
+ union
+ {
+ double d;
+ unsigned u;
+ } now = { .d = jerry_port_get_current_time () };
+ srand (now.u);
+ jerry_init (JERRY_INIT_EMPTY);
+ jerry_value_t global_obj_val = jerry_current_realm ();
+ jerry_value_t print_func_name_val = jerry_string_sz ("print");
+ print_function = jerry_object_get (global_obj_val, print_func_name_val);
+ jerry_value_free (print_func_name_val);
+ jerry_value_free (global_obj_val);
+}
+
+/* Application main entry point */
+void
+main_task (void *param)
+{
+ /* Init BSP (also init BSP on ARC core) */
+ queue = bsp_init ();
+ /* start Quark watchdog */
+ wdt_start (WDT_MAX_TIMEOUT_MS);
+ /* Init the CFW */
+ cfw_init (queue);
+ jerry_start ();
+ /* Loop to process message queue */
+ while (1)
+ {
+ OS_ERR_TYPE err = E_OS_OK;
+ /* Process message with a given timeout */
+ queue_process_message_wait (queue, 5000, &err);
+ /* Acknowledge the system watchdog to prevent panic and reset */
+ wdt_keepalive ();
+ }
+}
+
+DECLARE_TEST_COMMAND (js, e, eval_jerry_script);
diff --git a/targets/baremetal-sdk/curie-bsp/jerry_app/quark/memory_pool_list.def b/targets/baremetal-sdk/curie-bsp/jerry_app/quark/memory_pool_list.def
new file mode 100644
index 00000000..7f6a571a
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/jerry_app/quark/memory_pool_list.def
@@ -0,0 +1,36 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Definition of the memory pools used by balloc/bfree:
+ * DECLARE_MEMORY_POOL( <index>, <size>, <count>, <align> )
+ * <index> : must start at 0 and be of consecutive values *
+ * <size> : size in bytes of each block from the pool
+ * <count> : number of blocks in the pool
+ *
+ * * Pool definitions must be sorted according the block size
+ * value: pool with <index> 0 must have the smallest <size>.
+ */
+
+DECLARE_MEMORY_POOL(0,8,32)
+DECLARE_MEMORY_POOL(1,16,64)
+DECLARE_MEMORY_POOL(2,32,64)
+DECLARE_MEMORY_POOL(3,64,48)
+DECLARE_MEMORY_POOL(4,128,8)
+DECLARE_MEMORY_POOL(5,256,4)
+DECLARE_MEMORY_POOL(6,512,3)
+DECLARE_MEMORY_POOL(7,4096,1)
+
+#undef DECLARE_MEMORY_POOL
diff --git a/targets/baremetal-sdk/curie-bsp/setup.py b/targets/baremetal-sdk/curie-bsp/setup.py
new file mode 100755
index 00000000..fe6109ed
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/setup.py
@@ -0,0 +1,251 @@
+#!/usr/bin/env python
+
+# Copyright JS Foundation and other contributors, http://js.foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import fnmatch
+import os
+
+def build_soft_links(project_path, jerry_path):
+ """ Creates soft links into the @project_path. """
+
+ if not os.path.exists(project_path):
+ os.makedirs(project_path)
+
+ links = [
+ { # arc
+ 'src': os.path.join('targets', 'baremetal-sdk', 'curie-bsp', 'jerry_app', 'arc'),
+ 'link_name': 'arc'
+ },
+ { # include
+ 'src': os.path.join('targets', 'baremetal-sdk', 'curie-bsp', 'jerry_app', 'include'),
+ 'link_name': 'include'
+ },
+ { # quark
+ 'src': os.path.join('targets', 'baremetal-sdk', 'curie-bsp', 'jerry_app', 'quark'),
+ 'link_name': 'quark'
+ },
+ { # quark/jerryscript
+ 'src': jerry_path,
+ 'link_name': os.path.join('quark', 'jerryscript')
+ }
+ ]
+
+ for link in links:
+ src = os.path.join(jerry_path, link['src'])
+ link_name = os.path.join(project_path, link['link_name'])
+ if not os.path.islink(link_name):
+ os.symlink(src, link_name)
+ print("Created symlink '{link_name}' -> '{src}'".format(src=src, link_name=link_name))
+
+
+def find_sources(root_dir, sub_dir):
+ """
+ Find .c and .S files inside the @root_dir/@sub_dir directory.
+ Note: the returned paths will be relative to the @root_dir directory.
+ """
+ src_dir = os.path.join(root_dir, sub_dir)
+
+ matches = []
+ for root, dirnames, filenames in os.walk(src_dir):
+ for filename in fnmatch.filter(filenames, '*.[c|S]'):
+ file_path = os.path.join(root, filename)
+ relative_path = os.path.relpath(file_path, root_dir)
+ matches.append(relative_path)
+
+ return matches
+
+
+def build_jerry_data(jerry_path):
+ """
+ Build up a dictionary which contains the following items:
+ - sources: list of JerryScript sources which should be built.
+ - dirs: list of JerryScript dirs used.
+ - cflags: CFLAGS for the build.
+ """
+ jerry_sources = []
+ jerry_dirs = set()
+ for sub_dir in ['jerry-core', 'jerry-math', os.path.join('targets', 'baremetal-sdk', 'curie-bsp', 'source')]:
+ for file in find_sources(os.path.normpath(jerry_path), sub_dir):
+ path = os.path.join('jerryscript', file)
+ jerry_sources.append(path)
+ jerry_dirs.add(os.path.split(path)[0])
+
+ jerry_cflags = [
+ '-DJERRY_GLOBAL_HEAP_SIZE=10',
+ '-DJERRY_NDEBUG',
+ '-DJERRY_DISABLE_HEAVY_DEBUG',
+ '-DJERRY_BUILTIN_NUMBER=0',
+ '-DJERRY_BUILTIN_STRING=0',
+ '-DJERRY_BUILTIN_BOOLEAN=0',
+ #'-DJERRY_BUILTIN_ERRORS=0',
+ '-DJERRY_BUILTIN_ARRAY=0',
+ '-DJERRY_BUILTIN_MATH=0',
+ '-DJERRY_BUILTIN_JSON=0',
+ '-DJERRY_BUILTIN_DATE=0',
+ '-DJERRY_BUILTIN_REGEXP=0',
+ '-DJERRY_BUILTIN_ANNEXB=0',
+ '-DJERRY_ESNEXT=0',
+ '-DJERRY_LCACHE=0',
+ '-DJERRY_PROPERTY_HASHMAP=0',
+ ]
+
+ return {
+ 'sources': jerry_sources,
+ 'dirs': jerry_dirs,
+ 'cflags': jerry_cflags,
+ }
+
+
+def write_file(path, content):
+ """ Writes @content into the file at specified by the @path. """
+ norm_path = os.path.normpath(path)
+ with open(norm_path, "w+") as f:
+ f.write(content)
+ print("Wrote file '{0}'".format(norm_path))
+
+
+def build_obj_y(source_list):
+ """
+ Build obj-y additions from the @source_list.
+ Note: the input sources should have their file extensions.
+ """
+ return '\n'.join(['obj-y += {0}.o'.format(os.path.splitext(fname)[0]) for fname in source_list])
+
+
+def build_cflags_y(cflags_list):
+ """
+ Build cflags-y additions from the @cflags_list.
+ Note: the input sources should have their file extensions.
+ """
+ return '\n'.join(['cflags-y += {0}'.format(cflag) for cflag in cflags_list])
+
+
+def build_mkdir(dir_list):
+ """ Build mkdir calls for each dir in the @dir_list. """
+ return '\n'.join(['\t$(AT)mkdir -p {0}'.format(os.path.join('$(OUT_SRC)', path)) for path in dir_list])
+
+
+def create_root_kbuild(project_path):
+ """ Creates @project_path/Kbuild.mk file. """
+
+ root_kbuild_path = os.path.join(project_path, 'Kbuild.mk')
+ root_kbuild_content = '''
+obj-$(CONFIG_QUARK_SE_ARC) += arc/
+obj-$(CONFIG_QUARK_SE_QUARK) += quark/
+'''
+ write_file(root_kbuild_path, root_kbuild_content)
+
+
+def create_root_makefile(project_path):
+ """ Creates @project_path/Makefile file. """
+
+ root_makefile_path = os.path.join(project_path, 'Makefile')
+ root_makefile_content = '''
+THIS_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
+T := $(abspath $(THIS_DIR)/../..)
+PROJECT := {project_name}
+BOARD := curie_101
+ifeq ($(filter curie_101, $(BOARD)),)
+$(error The curie jerry sample application can only run on the curie_101 Board)
+endif
+BUILDVARIANT ?= debug
+quark_DEFCONFIG = $(PROJECT_PATH)/quark/defconfig
+arc_DEFCONFIG = $(PROJECT_PATH)/arc/defconfig
+
+# Optional: set the default version
+VERSION_MAJOR := 1
+VERSION_MINOR := 0
+VERSION_PATCH := 0
+include $(T)/build/project.mk
+'''.format(project_name=project_name)
+
+ write_file(root_makefile_path, root_makefile_content)
+
+
+def create_arc_kbuild(project_path):
+ """ Creates @project_path/arc/Kbuild.mk file. """
+
+ arc_path = os.path.join(project_path, 'arc')
+ arc_kbuild_path = os.path.join(arc_path, 'Kbuild.mk')
+ arc_sources = find_sources(arc_path, '.')
+ arc_kbuild_content = build_obj_y(arc_sources)
+
+ write_file(arc_kbuild_path, arc_kbuild_content)
+
+
+def create_quark_kbuild(project_path, jerry_path):
+ """ Creates @project_path/quark/Kbuild.mk file. """
+ quark_kbuild_path = os.path.join(project_path, 'quark', 'Kbuild.mk')
+
+ # Extract a few JerryScript related data
+ jerry_data = build_jerry_data(jerry_path)
+ jerry_objects = build_obj_y(jerry_data['sources'])
+ jerry_defines = jerry_data['cflags']
+ jerry_build_dirs = build_mkdir(jerry_data['dirs'])
+
+ quark_include_paths = [
+ 'include',
+ 'jerryscript',
+ os.path.join('jerryscript', 'jerry-math', 'include'),
+ os.path.join('jerryscript', 'targets', 'baremetal-sdk', 'curie-bsp', 'include')
+ ] + list(jerry_data['dirs'])
+
+ quark_includes = [
+ '-Wno-error',
+ ] + ['-I%s' % os.path.join(project_path, 'quark', path) for path in quark_include_paths]
+
+ quark_cflags = build_cflags_y(jerry_defines + quark_includes)
+
+ quark_kbuild_content = '''
+{cflags}
+
+obj-y += main.o
+{objects}
+
+build_dirs:
+{dirs}
+
+$(OUT_SRC): build_dirs
+'''.format(objects=jerry_objects, cflags=quark_cflags, dirs=jerry_build_dirs)
+
+ write_file(quark_kbuild_path, quark_kbuild_content)
+
+
+def main(curie_path, project_name, jerry_path):
+ project_path = os.path.join(curie_path, 'wearable_device_sw', 'projects', project_name)
+
+ build_soft_links(project_path, jerry_path)
+
+ create_root_kbuild(project_path)
+ create_root_makefile(project_path)
+ create_arc_kbuild(project_path)
+ create_quark_kbuild(project_path, jerry_path)
+
+
+if __name__ == '__main__':
+ import sys
+
+ if len(sys.argv) != 2:
+ print('Usage:')
+ print('{script_name} [full or relative path of Curie_BSP]'.format(script_name=sys.argv[0]))
+ sys.exit(1)
+
+ project_name = 'curie_bsp_jerry'
+
+ file_dir = os.path.dirname(os.path.abspath(__file__))
+ jerry_path = os.path.join(file_dir, "..", "..", "..")
+ curie_path = os.path.join(os.getcwd(), sys.argv[1])
+
+ main(curie_path, project_name, jerry_path)
diff --git a/targets/baremetal-sdk/curie-bsp/source/curie-bsp-port.c b/targets/baremetal-sdk/curie-bsp/source/curie-bsp-port.c
new file mode 100644
index 00000000..1def05e2
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/source/curie-bsp-port.c
@@ -0,0 +1,72 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <infra/time.h>
+#include <misc/printk.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include "jerryscript-port.h"
+
+/**
+ * Provide log message implementation for the engine.
+ * Curie BSP implementation
+ */
+void
+jerry_port_log (jerry_log_level_t level, /**< log level */
+ const char *format, /**< format string */
+ ...) /**< parameters */
+{
+ if (level <= JERRY_LOG_LEVEL_ERROR)
+ {
+ char buf[256];
+ int length = 0;
+ va_list args;
+ va_start (args, format);
+ length = vsnprintf (buf, 256, format, args);
+ buf[length] = '\0';
+ printk ("%s", buf);
+ va_end (args);
+ }
+} /* jerry_port_log */
+
+/**
+ * Curie BSP implementation of jerry_port_fatal.
+ */
+void jerry_port_fatal (jerry_fatal_code_t code)
+{
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Jerry Fatal Error!\n");
+ while (true);
+} /* jerry_port_fatal */
+
+/**
+ * Curie BSP implementation of jerry_port_get_local_time_zone_adjustment.
+ */
+double jerry_port_get_local_time_zone_adjustment (double unix_ms, bool is_utc)
+{
+ //EMPTY implementation
+ return 0;
+} /* jerry_port_get_local_time_zone_adjustment */
+
+/**
+ * Curie BSP implementation of jerry_port_get_current_time.
+ */
+double jerry_port_get_current_time (void)
+{
+ uint32_t uptime_ms = get_uptime_ms ();
+ uint32_t epoch_time = uptime_to_epoch (uptime_ms);
+
+ return ((double) epoch_time) * 1000.0;
+} /* jerry_port_get_current_time */
diff --git a/targets/baremetal-sdk/curie-bsp/source/setjmp.S b/targets/baremetal-sdk/curie-bsp/source/setjmp.S
new file mode 100644
index 00000000..f1f87ecf
--- /dev/null
+++ b/targets/baremetal-sdk/curie-bsp/source/setjmp.S
@@ -0,0 +1,77 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+.macro func _name
+.global \_name
+.type \_name, %function
+\_name:
+.endm
+.macro endfunc _name
+.size \_name, .-\_name
+.endm
+
+/**
+ * setjmp (jmp_buf env)
+ *
+ * See also:
+ * longjmp
+ *
+ * @return 0 - if returns from direct call,
+ * nonzero - if returns after longjmp.
+ */
+func setjmp
+ mov %eax,(%eax);
+ mov %ebx,0x4(%eax);
+ mov %ecx,0x8(%eax);
+ mov %edx,0xc(%eax);
+ mov %esi,0x10(%eax);
+ mov %edi,0x14(%eax);
+ mov %ebp,0x18(%eax);
+ mov %esp,0x1c(%eax);
+ push %edx;
+ mov 0x4(%esp),%edx;
+ mov %edx,0x20(%eax);
+ pop %edx;
+ xor %eax,%eax;
+ ret
+endfunc setjmp
+
+/**
+ * longjmp (jmp_buf env, int val)
+ *
+ * Note:
+ * if val is not 0, then it would be returned from setjmp,
+ * otherwise - 0 would be returned.
+ *
+ * See also:
+ * setjmp
+ */
+func longjmp
+ test %edx, %edx;
+ jne . + 0x3;
+ inc %edx;
+ mov 0x4(%eax),%ebx;
+ mov 0x8(%eax),%ecx;
+ mov 0x10(%eax),%esi;
+ mov 0x14(%eax),%edi;
+ mov 0x18(%eax),%ebp;
+ mov 0x1c(%eax),%esp;
+ push %edx;
+ mov 0x20(%eax),%edx;
+ mov %edx,0x4(%esp);
+ mov 0xc(%eax),%edx;
+ pop %eax;
+ ret
+endfunc longjmp
diff --git a/targets/baremetal-sdk/esp-idf/CMakeLists.txt.example b/targets/baremetal-sdk/esp-idf/CMakeLists.txt.example
new file mode 100644
index 00000000..e7e9d7c0
--- /dev/null
+++ b/targets/baremetal-sdk/esp-idf/CMakeLists.txt.example
@@ -0,0 +1,16 @@
+# assumes there is a component with this the following
+# - set the JERRY_DIR wherever the jerryscript source code (the include files) is
+# - a "lib" directory with the 2 libraries below
+
+set(JERRY_DIR ${PROJECT_DIR}/../../../jerryscript/)
+
+idf_component_register(
+ SRC_DIRS ${JERRY_DIR}/targets/baremetal-sdk/esp-idf
+ INCLUDE_DIRS ${JERRY_DIR}/jerry-core/include ${JERRY_DIR}/jerry-ext/include
+)
+
+add_prebuilt_library(libjerry-core lib/libjerry-core.a REQUIRES newlib PRIV_REQUIRES ${COMPONENT_NAME})
+add_prebuilt_library(libjerry-ext lib/libjerry-ext.a PRIV_REQUIRES ${COMPONENT_NAME})
+
+target_link_libraries(${COMPONENT_LIB} INTERFACE libjerry-core)
+target_link_libraries(${COMPONENT_LIB} INTERFACE libjerry-ext)
diff --git a/targets/baremetal-sdk/esp-idf/README.md b/targets/baremetal-sdk/esp-idf/README.md
new file mode 100644
index 00000000..ec29ca60
--- /dev/null
+++ b/targets/baremetal-sdk/esp-idf/README.md
@@ -0,0 +1,28 @@
+This is a port for espressif's esp-idf (esp32). The MATH, LTO and STRIP options should be disabled, so to build under the IDF toolchain, just run the following command
+
+```
+python tools\build.py --toolchain=cmake/toolchain-esp32.cmake --cmake-param "-GUnix Makefiles" --jerry-cmdline=OFF --jerry-port-default=OFF --lto=OFF --strip=OFF
+```
+
+NB: the MATH, STRIP and LTO might be disabled by platform as well. I strongly suggest limiting heap memory with '--mem-heap=128' but that really depends on the SRAM available on your esp32.
+
+Then copy the artifacts 'build/lib/\*.a' in an esp-idf component named 'jerryscript' (eg) and use a 'CMakeLists.txt' like this one
+
+```
+# assumes there is a component with this the following
+# - set the JERRY_DIR wherever the jerryscript source code (the include files) is
+# - a "lib" directory with the 2 libraries below
+
+set(JERRY_DIR ${PROJECT_DIR}/../../jerryscript/)
+
+idf_component_register(
+ SRC_DIRS ${JERRY_DIR}/targets/baremetal-sdk/esp-idf
+ INCLUDE_DIRS ${JERRY_DIR}/jerry-core/include ${JERRY_DIR}/jerry-ext/include
+)
+
+add_prebuilt_library(libjerry-core lib/libjerry-core.a REQUIRES newlib PRIV_REQUIRES ${COMPONENT_NAME})
+add_prebuilt_library(libjerry-ext lib/libjerry-ext.a PRIV_REQUIRES ${COMPONENT_NAME})
+
+target_link_libraries(${COMPONENT_LIB} INTERFACE libjerry-core)
+target_link_libraries(${COMPONENT_LIB} INTERFACE libjerry-ext)
+```
diff --git a/targets/baremetal-sdk/esp-idf/jerry_module.c b/targets/baremetal-sdk/esp-idf/jerry_module.c
new file mode 100644
index 00000000..6a623d26
--- /dev/null
+++ b/targets/baremetal-sdk/esp-idf/jerry_module.c
@@ -0,0 +1,293 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "jerryscript-port.h"
+#include "jerryscript.h"
+
+/**
+ * Computes the end of the directory part of a path.
+ *
+ * @return end of the directory part of a path.
+ */
+static size_t
+jerry_port_get_directory_end (const jerry_char_t *path_p) /**< path */
+{
+ const jerry_char_t *end_p = path_p + strlen ((const char *) path_p);
+
+ while (end_p > path_p)
+ {
+ if (end_p[-1] == '/')
+ {
+ return (size_t) (end_p - path_p);
+ }
+
+ end_p--;
+ }
+
+ return 0;
+} /* jerry_port_get_directory_end */
+
+/**
+ * Normalize a file path.
+ *
+ * @return a newly allocated buffer with the normalized path if the operation is successful,
+ * NULL otherwise
+ */
+static jerry_char_t *
+jerry_port_normalize_path (const jerry_char_t *in_path_p, /**< path to the referenced module */
+ size_t in_path_length, /**< length of the path */
+ const jerry_char_t *base_path_p, /**< base path */
+ size_t base_path_length) /**< length of the base path */
+{
+ char *path_p;
+
+ if (base_path_length > 0)
+ {
+ path_p = (char *) malloc (base_path_length + in_path_length + 1);
+
+ if (path_p == NULL)
+ {
+ return NULL;
+ }
+
+ memcpy (path_p, base_path_p, base_path_length);
+ memcpy (path_p + base_path_length, in_path_p, in_path_length);
+ path_p[base_path_length + in_path_length] = '\0';
+ }
+ else
+ {
+ path_p = (char *) malloc (in_path_length + 1);
+
+ if (path_p == NULL)
+ {
+ return NULL;
+ }
+
+ memcpy (path_p, in_path_p, in_path_length);
+ path_p[in_path_length] = '\0';
+ }
+
+ return (jerry_char_t *) path_p;
+} /* jerry_port_normalize_path */
+
+/**
+ * A module descriptor.
+ */
+typedef struct jerry_port_module_t
+{
+ struct jerry_port_module_t *next_p; /**< next_module */
+ jerry_char_t *path_p; /**< path to the module */
+ size_t base_path_length; /**< base path length for relative difference */
+ jerry_value_t realm; /**< the realm of the module */
+ jerry_value_t module; /**< the module itself */
+} jerry_port_module_t;
+
+/**
+ * Native info descriptor for modules.
+ */
+static const jerry_object_native_info_t jerry_port_module_native_info = {
+ .free_cb = NULL,
+};
+
+/**
+ * Default module manager.
+ */
+typedef struct
+{
+ jerry_port_module_t *module_head_p; /**< first module */
+} jerry_port_module_manager_t;
+
+/**
+ * Release known modules.
+ */
+static void
+jerry_port_module_free (jerry_port_module_manager_t *manager_p, /**< module manager */
+ const jerry_value_t realm) /**< if this argument is object, release only those modules,
+ * which realm value is equal to this argument. */
+{
+ jerry_port_module_t *module_p = manager_p->module_head_p;
+
+ bool release_all = !jerry_value_is_object (realm);
+
+ jerry_port_module_t *prev_p = NULL;
+
+ while (module_p != NULL)
+ {
+ jerry_port_module_t *next_p = module_p->next_p;
+
+ if (release_all || module_p->realm == realm)
+ {
+ free (module_p->path_p);
+ jerry_value_free (module_p->realm);
+ jerry_value_free (module_p->module);
+
+ free (module_p);
+
+ if (prev_p == NULL)
+ {
+ manager_p->module_head_p = next_p;
+ }
+ else
+ {
+ prev_p->next_p = next_p;
+ }
+ }
+ else
+ {
+ prev_p = module_p;
+ }
+
+ module_p = next_p;
+ }
+} /* jerry_port_module_free */
+
+/**
+ * Initialize the default module manager.
+ */
+static void
+jerry_port_module_manager_init (void *user_data_p)
+{
+ ((jerry_port_module_manager_t *) user_data_p)->module_head_p = NULL;
+} /* jerry_port_module_manager_init */
+
+/**
+ * Deinitialize the default module manager.
+ */
+static void
+jerry_port_module_manager_deinit (void *user_data_p) /**< context pointer to deinitialize */
+{
+ jerry_value_t undef = jerry_undefined ();
+ jerry_port_module_free ((jerry_port_module_manager_t *) user_data_p, undef);
+ jerry_value_free (undef);
+} /* jerry_port_module_manager_deinit */
+
+/**
+ * Declare the context data manager for modules.
+ */
+static const jerry_context_data_manager_t jerry_port_module_manager = { .init_cb = jerry_port_module_manager_init,
+ .deinit_cb = jerry_port_module_manager_deinit,
+ .bytes_needed =
+ sizeof (jerry_port_module_manager_t) };
+
+/**
+ * Default module resolver.
+ *
+ * @return a module object if resolving is successful, an error otherwise
+ */
+jerry_value_t
+jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier string */
+ const jerry_value_t referrer, /**< parent module */
+ void *user_p) /**< user data */
+{
+ (void) user_p;
+
+ const jerry_char_t *base_path_p = NULL;
+ size_t base_path_length = 0;
+ jerry_port_module_t *module_p = jerry_object_get_native_ptr (referrer, &jerry_port_module_native_info);
+
+ if (module_p != NULL)
+ {
+ base_path_p = module_p->path_p;
+ base_path_length = module_p->base_path_length;
+ }
+
+ jerry_size_t in_path_length = jerry_string_size (specifier, JERRY_ENCODING_UTF8);
+ jerry_char_t *in_path_p = (jerry_char_t *) malloc (in_path_length + 1);
+ jerry_string_to_buffer (specifier, JERRY_ENCODING_UTF8, in_path_p, in_path_length);
+ in_path_p[in_path_length] = '\0';
+
+ jerry_char_t *path_p = jerry_port_normalize_path (in_path_p, in_path_length, base_path_p, base_path_length);
+
+ if (path_p == NULL)
+ {
+ return jerry_throw_sz (JERRY_ERROR_COMMON, "Out of memory");
+ }
+
+ jerry_value_t realm = jerry_current_realm ();
+
+ jerry_port_module_manager_t *manager_p;
+ manager_p = (jerry_port_module_manager_t *) jerry_context_data (&jerry_port_module_manager);
+
+ module_p = manager_p->module_head_p;
+
+ while (module_p != NULL)
+ {
+ if (module_p->realm == realm && strcmp ((const char *) module_p->path_p, (const char *) path_p) == 0)
+ {
+ free (path_p);
+ free (in_path_p);
+ jerry_value_free (realm);
+ return jerry_value_copy (module_p->module);
+ }
+
+ module_p = module_p->next_p;
+ }
+
+ size_t source_size;
+ uint8_t *source_p = jerry_port_read_source ((const char *) path_p, &source_size);
+
+ if (source_p == NULL)
+ {
+ free (path_p);
+ free (in_path_p);
+ jerry_value_free (realm);
+ return jerry_throw_sz (JERRY_ERROR_SYNTAX, "Module file not found");
+ }
+
+ jerry_parse_options_t parse_options;
+ parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME;
+ parse_options.source_name = jerry_string ((const jerry_char_t *) in_path_p, in_path_length, JERRY_ENCODING_UTF8);
+
+ jerry_value_t ret_value = jerry_parse (source_p, source_size, &parse_options);
+
+ jerry_value_free (parse_options.source_name);
+ jerry_port_release_source (source_p);
+ free (in_path_p);
+
+ if (jerry_value_is_exception (ret_value))
+ {
+ free (path_p);
+ jerry_value_free (realm);
+ return ret_value;
+ }
+
+ module_p = (jerry_port_module_t *) malloc (sizeof (jerry_port_module_t));
+
+ module_p->next_p = manager_p->module_head_p;
+ module_p->path_p = path_p;
+ module_p->base_path_length = jerry_port_get_directory_end (module_p->path_p);
+ module_p->realm = realm;
+ module_p->module = jerry_value_copy (ret_value);
+
+ jerry_object_set_native_ptr (ret_value, &jerry_port_module_native_info, module_p);
+ manager_p->module_head_p = module_p;
+
+ return ret_value;
+} /* jerry_port_module_resolve */
+
+/**
+ * Release known modules.
+ */
+void
+jerry_port_module_release (const jerry_value_t realm) /**< if this argument is object, release only those modules,
+ * which realm value is equal to this argument. */
+{
+ jerry_port_module_free ((jerry_port_module_manager_t *) jerry_context_data (&jerry_port_module_manager), realm);
+} /* jerry_port_module_release */
diff --git a/targets/baremetal-sdk/esp-idf/jerry_port.c b/targets/baremetal-sdk/esp-idf/jerry_port.c
new file mode 100644
index 00000000..2c0e7b47
--- /dev/null
+++ b/targets/baremetal-sdk/esp-idf/jerry_port.c
@@ -0,0 +1,283 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <limits.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+
+#include "esp_log.h"
+#include "esp_system.h"
+
+#include "jerryscript.h"
+#include "jerryscript-port.h"
+
+static const char TAG[] = "JS";
+
+static esp_log_level_t crosslog(jerry_log_level_t level)
+{
+ switch(level)
+ {
+ case JERRY_LOG_LEVEL_ERROR: return ESP_LOG_ERROR;
+ case JERRY_LOG_LEVEL_WARNING: return ESP_LOG_WARN;
+ case JERRY_LOG_LEVEL_DEBUG: return ESP_LOG_DEBUG;
+ case JERRY_LOG_LEVEL_TRACE: return ESP_LOG_VERBOSE;
+ }
+
+ return ESP_LOG_NONE;
+}
+
+/**
+ * Actual log level
+ */
+static jerry_log_level_t jerry_port_default_log_level = JERRY_LOG_LEVEL_ERROR;
+
+/**
+ * Get the log level
+ *
+ * @return current log level
+ */
+jerry_log_level_t
+jerry_port_default_get_log_level (void)
+{
+ return jerry_port_default_log_level;
+} /* jerry_port_default_get_log_level */
+
+/**
+ * Set the log level
+ */
+void
+jerry_port_default_set_log_level (jerry_log_level_t level) /**< log level */
+{
+ jerry_port_default_log_level = level;
+} /* jerry_port_default_set_log_level */
+
+/**
+ * Default implementation of jerry_port_log. Prints log message to the standard
+ * error with 'vfprintf' if message log level is less than or equal to the
+ * current log level.
+ *
+ * If debugger support is enabled, printing happens first to an in-memory buffer,
+ * which is then sent both to the standard error and to the debugger client.
+ */
+void
+jerry_port_log (jerry_log_level_t level, /**< message log level */
+ const char *format, /**< format string */
+ ...) /**< parameters */
+{
+ if (level <= jerry_port_default_log_level)
+ {
+ va_list args;
+ va_start (args, format);
+#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
+ int length = vsnprintf (NULL, 0, format, args);
+ va_end (args);
+ va_start (args, format);
+
+ JERRY_VLA (char, buffer, length + 1);
+ vsnprintf (buffer, (size_t) length + 1, format, args);
+
+ esp_log_write(crosslog(level), TAG, buffer);
+ jerry_debugger_send_log (level, (jerry_char_t *) buffer, (jerry_size_t) length);
+#else /* If jerry-debugger isn't defined, libc is turned on */
+ esp_log_writev(crosslog(level), TAG, format, args);
+#endif /* defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1) */
+ va_end (args);
+ }
+} /* jerry_port_log */
+
+#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
+
+#define DEBUG_BUFFER_SIZE (256)
+static char debug_buffer[DEBUG_BUFFER_SIZE];
+static int debug_buffer_index = 0;
+
+#endif /* defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1) */
+
+/**
+ * Default implementation of jerry_port_print_char. Uses 'putchar' to
+ * print a single character to standard output.
+ */
+void
+jerry_port_print_char (char c) /**< the character to print */
+{
+ putchar(c);
+
+#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
+ debug_buffer[debug_buffer_index++] = c;
+
+ if ((debug_buffer_index == DEBUG_BUFFER_SIZE) || (c == '\n'))
+ {
+ jerry_debugger_send_output ((jerry_char_t *) debug_buffer, (jerry_size_t) debug_buffer_index);
+ debug_buffer_index = 0;
+ }
+#endif /* defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1) */
+} /* jerry_port_print_char */
+
+/**
+ * Default implementation of jerry_port_fatal. Calls 'abort' if exit code is
+ * non-zero, 'exit' otherwise.
+ */
+void jerry_port_fatal (jerry_fatal_code_t code) /**< cause of error */
+{
+ ESP_LOGE(TAG, "Fatal error %d", code);
+ vTaskSuspend(NULL);
+ abort();
+} /* jerry_port_fatal */
+
+/**
+ * Pointer to the current context.
+ * Note that it is a global variable, and is not a thread safe implementation.
+ * But I don't see how jerryscript can make that thread-safe, only the appication can
+ */
+static jerry_context_t *current_context_p = NULL;
+
+/**
+ * Set the current_context_p as the passed pointer.
+ */
+void
+jerry_port_default_set_current_context (jerry_context_t *context_p) /**< points to the created context */
+{
+ current_context_p = context_p;
+} /* jerry_port_default_set_current_context */
+
+/**
+ * Get the current context.
+ *
+ * @return the pointer to the current context
+ */
+jerry_context_t *
+jerry_port_get_current_context (void)
+{
+ return current_context_p;
+} /* jerry_port_get_current_context */
+
+/**
+ * Default implementation of jerry_port_sleep. Uses 'nanosleep' or 'usleep' if
+ * available on the system, does nothing otherwise.
+ */
+void jerry_port_sleep (uint32_t sleep_time) /**< milliseconds to sleep */
+{
+ vTaskDelay( sleep_time / portTICK_PERIOD_MS);
+} /* jerry_port_sleep */
+
+/**
+ * Opens file with the given path and reads its source.
+ * @return the source of the file
+ */
+uint8_t *
+jerry_port_read_source (const char *file_name_p, /**< file name */
+ size_t *out_size_p) /**< [out] read bytes */
+{
+ FILE *file_p = fopen (file_name_p, "rb");
+
+ if (file_p == NULL)
+ {
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: Failed to open file: %s\n", file_name_p);
+ return NULL;
+ }
+
+ struct stat info = { };
+ fstat(fileno(file_p), &info);
+ uint8_t *buffer_p = (uint8_t *) malloc (info.st_size);
+
+ if (buffer_p == NULL)
+ {
+ fclose (file_p);
+
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: Failed to allocate memory for file: %s\n", file_name_p);
+ return NULL;
+ }
+
+ size_t bytes_read = fread (buffer_p, 1u, info.st_size, file_p);
+ if (bytes_read != info.st_size)
+ {
+ fclose (file_p);
+ free (buffer_p);
+
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: Failed to read file: %s\n", file_name_p);
+ return NULL;
+ }
+
+ fclose (file_p);
+ *out_size_p = bytes_read;
+
+ return buffer_p;
+} /* jerry_port_read_source */
+
+/**
+ * Release the previously opened file's content.
+ */
+void
+jerry_port_release_source (uint8_t *buffer_p) /**< buffer to free */
+{
+ free (buffer_p);
+} /* jerry_port_release_source */
+
+/**
+ * Default implementation of jerry_port_get_local_time_zone_adjustment. Uses the 'tm_gmtoff' field
+ * of 'struct tm' (a GNU extension) filled by 'localtime_r' if available on the
+ * system, does nothing otherwise.
+ *
+ * @return offset between UTC and local time at the given unix timestamp, if
+ * available. Otherwise, returns 0, assuming UTC time.
+ */
+double jerry_port_get_local_time_zone_adjustment (double unix_ms, /**< ms since unix epoch */
+ bool is_utc) /**< is the time above in UTC? */
+{
+ struct tm tm;
+ char buf[8];
+ time_t now = (time_t) (unix_ms / 1000);
+
+ localtime_r (&now, &tm);
+
+ if (!is_utc)
+ {
+ strftime(buf, 8, "%z", &tm);
+ now -= -atof(buf) * 3600 * 1000 / 100;
+ localtime_r (&now, &tm);
+ }
+
+ strftime(buf, 8, "%z", &tm);
+
+ return -atof(buf) * 3600 * 1000 / 100;
+} /* jerry_port_get_local_time_zone_adjustment */
+
+/**
+ * Default implementation of jerry_port_get_current_time. Uses 'gettimeofday' if
+ * available on the system, does nothing otherwise.
+ *
+ * @return milliseconds since Unix epoch - if 'gettimeofday' is available and
+ * executed successfully,
+ * 0 - otherwise.
+ */
+double jerry_port_get_current_time (void)
+{
+ struct timeval tv;
+
+ if (gettimeofday (&tv, NULL) == 0)
+ {
+ return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
+ }
+ return 0.0;
+} /* jerry_port_get_current_time */
+
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/LICENSE b/targets/baremetal-sdk/esp8266-rtos-sdk/LICENSE
new file mode 100644
index 00000000..31c1f3f1
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/LICENSE
@@ -0,0 +1,56 @@
+Copyright 2015 Samsung Electronics Co., Ltd.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+================================================================================
+
+ESPRSSIF MIT License
+
+Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
+
+Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
+it is free of charge, to any person obtaining a copy of this software and associated
+documentation files (the ¡°Software¡±), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED ¡°AS IS¡±, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+
+ÀÖöÎ MIT Ðí¿ÉÖ¤
+
+°æȨ (c) 2015 <ÀÖöÎÐÅÏ¢¿Æ¼¼£¨ÉϺ££©ÓÐÏÞ¹«Ë¾>
+
+¸ÃÐí¿ÉÖ¤ÊÚȨ½öÏÞÓÚÀÖöÎÐÅÏ¢¿Æ¼¼ ESP8266 ²úÆ·µÄÓ¦Óÿª·¢¡£ÔÚ´ËÇé¿öÏ£¬¸ÃÐí¿ÉÖ¤Ãâ·ÑÊÚȨÈκλñµÃ¸Ã
+Èí¼þ¼°ÆäÏà¹ØÎĵµ£¨Í³³ÆΪ¡°Èí¼þ¡±£©µÄÈËÎÞÏÞÖƵؾ­Óª¸ÃÈí¼þ£¬°üÀ¨ÎÞÏÞÖƵÄʹÓᢸ´ÖÆ¡¢Ð޸ġ¢ºÏ²¢¡¢
+³ö°æ·¢ÐС¢É¢²¼¡¢ÔÙÊÚȨ¡¢¼°··ÊÛÈí¼þ¼°Èí¼þ¸±±¾µÄȨÀû¡£±»ÊÚȨÈËÔÚÏíÊÜÕâЩȨÀûµÄͬʱ£¬Ðè·þ´ÓÏÂÃæ
+µÄÌõ¼þ£º
+
+ÔÚÈí¼þºÍÈí¼þµÄËùÓи±±¾Öж¼±ØÐë°üº¬ÒÔÉϵİæȨÉùÃ÷ºÍÊÚȨÉùÃ÷¡£
+
+¸ÃÈí¼þ°´±¾À´µÄÑù×ÓÌṩ£¬Ã»ÓÐÈκÎÃ÷È·»ò°µº¬µÄµ£±££¬°üÀ¨µ«²»½öÏÞÓÚ¹ØÓÚÊÔÏúÐÔ¡¢ÊʺÏijһÌض¨ÓÃ;
+ºÍ·ÇÇÖȨµÄ±£Ö¤¡£×÷ÕߺͰæȨ³ÖÓÐÈËÔÚÈκÎÇé¿öϾù²»¾ÍÓÉÈí¼þ»òÈí¼þʹÓÃÒýÆðµÄÒÔºÏͬÐÎʽ¡¢ÃñÊÂÇÖȨ
+»òÆäËü·½Ê½Ìá³öµÄÈκÎË÷Åâ¡¢Ë𺦻òÆäËüÔðÈθºÔð¡£
+
+
+
+
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/Makefile b/targets/baremetal-sdk/esp8266-rtos-sdk/Makefile
new file mode 100644
index 00000000..fe9ab8cd
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/Makefile
@@ -0,0 +1,162 @@
+# Copyright JS Foundation and other contributors, http://js.foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#############################################################
+# Required variables for each makefile
+# Discard this section from all parent makefiles
+# Expected variables (with automatic defaults):
+# CSRCS (all "C" files in the dir)
+# SUBDIRS (all subdirs with a Makefile)
+# GEN_LIBS - list of libs to be generated ()
+# GEN_IMAGES - list of object file images to be generated ()
+# GEN_BINS - list of binaries to be generated ()
+# COMPONENTS_xxx - a list of libs/objs in the form
+# subdir/lib to be extracted and rolled up into
+# a generated lib/image xxx.a ()
+#
+# Tabsize : 8
+#
+TARGET = eagle
+FLAVOR = release
+#FLAVOR = debug
+
+#EXTRA_CCFLAGS += -u
+
+ifndef PDIR # {
+GEN_IMAGES= eagle.app.v6.out
+GEN_BINS= eagle.app.v6.bin
+SPECIAL_MKTARGETS=$(APP_MKTARGETS)
+SUBDIRS= user
+endif # } PDIR
+
+# path to the JERRYSCRIPT directory
+JERRYDIR ?= $(CURDIR)/../../../..
+
+LDDIR = $(SDK_PATH)/ld
+
+#############################################################
+# JerryScript requires a modified linker script with specified alignments
+# so we use it instead of the original one from SDK.
+JERRY_LD_FILE = $(CURDIR)/ld/eagle.app.v6.ld
+
+CCFLAGS += -Os -std=c99
+#CCFLAGS += -O0
+
+TARGET_LDFLAGS = \
+ -nostdlib \
+ -Wl,-EL \
+ --longcalls \
+ --text-section-literals
+
+ifeq ($(FLAVOR),debug)
+ TARGET_LDFLAGS += -O0 -g
+endif
+
+ifeq ($(FLAVOR),release)
+ TARGET_LDFLAGS += -Os
+endif
+
+COMPONENTS_eagle.app.v6 = \
+ user/libuser.a
+
+LINKFLAGS_eagle.app.v6 = \
+ -L$(SDK_PATH)/lib \
+ -Wl,--gc-sections \
+ -Wl,-Map,output.map \
+ -nostdlib \
+ -T$(JERRY_LD_FILE) \
+ -Wl,--no-check-sections \
+ -u call_user_start \
+ -Wl,-static \
+ -Wl,--start-group \
+ -lcirom \
+ -lcrypto \
+ -lespconn \
+ -lespnow \
+ -lfreertos \
+ -lgcc \
+ -lhal \
+ -ljson \
+ -llwip \
+ -ldriver \
+ -lmain \
+ -lmirom \
+ -lnet80211 \
+ -lnopoll \
+ -lphy \
+ -lpp \
+ -lpwm \
+ -lsmartconfig \
+ -lspiffs \
+ -lssl \
+ -lwpa \
+ -lwps \
+ -L./libs \
+ -ljerry-core \
+ -ljerry-math \
+ $(DEP_LIBS_eagle.app.v6) \
+ -Wl,--end-group
+
+DEPENDS_eagle.app.v6 = \
+ $(JERRY_LD_FILE) \
+ $(LDDIR)/eagle.rom.addr.v6.ld \
+ ./include/jerry-targetjs.h \
+ ./libs/libjerry-core.a \
+ ./libs/libjerry-math.a
+
+
+#############################################################
+# Configuration i.e. compile options etc.
+# Target specific stuff (defines etc.) goes in here!
+# Generally values applying to a tree are captured in the
+# makefile at its root level - these are then overridden
+# for a subtree within the makefile rooted therein
+#
+
+#UNIVERSAL_TARGET_DEFINES = \
+
+# Other potential configuration flags include:
+# -DTXRX_TXBUF_DEBUG
+# -DTXRX_RXBUF_DEBUG
+# -DWLAN_CONFIG_CCX
+CONFIGURATION_DEFINES = -DICACHE_FLASH
+
+DEFINES += \
+ $(UNIVERSAL_TARGET_DEFINES) \
+ $(CONFIGURATION_DEFINES)
+
+DDEFINES += \
+ $(UNIVERSAL_TARGET_DEFINES) \
+ $(CONFIGURATION_DEFINES)
+
+
+#############################################################
+# Recursion Magic - Don't touch this!!
+#
+# Each subtree potentially has an include directory
+# corresponding to the common APIs applicable to modules
+# rooted at that subtree. Accordingly, the INCLUDE PATH
+# of a module can only contain the include directories up
+# its parent path, and not its siblings
+#
+# Required for each makefile to inherit from the parent
+#
+
+INCLUDES := -I $(JERRYDIR)/jerry-core/include
+INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)source
+sinclude $(SDK_PATH)/Makefile
+
+.PHONY: FORCE
+
+FORCE:
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266 b/targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266
new file mode 100644
index 00000000..f2958399
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266
@@ -0,0 +1,88 @@
+# Copyright JS Foundation and other contributors, http://js.foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+CURDIR = `pwd`
+ESP_LIB = $(SDK_PATH)/lib
+BUILD_DIR = build/obj-esp8266
+COPYTARGET = targets/baremetal-sdk/esp8266-rtos-sdk/libs
+USBDEVICE ?= /dev/ttyUSB0
+JERRYHEAP ?= 20
+ESPTOOL ?= $(ESPTOOL_PATH)/esptool.py
+
+# compile flags
+ESP_CFLAGS := -D__TARGET_ESP8266 -D__attr_always_inline___=
+
+MFORCE32 = $(shell xtensa-lx106-elf-gcc --help=target | grep mforce-l32)
+
+ifneq ($(MFORCE32),)
+ # Your compiler supports the -mforce-l32 flag which means that
+ # constants can be placed in ROM to free additional RAM
+ ESP_CFLAGS += -DJERRY_ATTR_CONST_DATA="__attribute__((aligned(4))) __attribute__((section(\".irom.text\")))"
+ ESP_CFLAGS += -mforce-l32
+endif
+
+ESP_CFLAGS += -Wl,-EL -fno-inline-functions
+ESP_CFLAGS += -ffunction-sections -fdata-sections
+ESP_CFLAGS += -mlongcalls -mtext-section-literals -mno-serialize-volatile
+
+.PHONY: jerry js2c mkbin check-env flash clean
+
+all: check-env jerry js2c mkbin
+
+jerry:
+ mkdir -p $(BUILD_DIR)
+ mkdir -p $(COPYTARGET)
+ cmake -B$(BUILD_DIR) -H./ \
+ -DCMAKE_SYSTEM_NAME=MCU \
+ -DCMAKE_SYSTEM_PROCESSOR=xtensia-lx106 \
+ -DCMAKE_C_COMPILER=xtensa-lx106-elf-gcc \
+ -DCMAKE_C_COMPILER_WORKS=TRUE \
+ -DENABLE_LTO=OFF \
+ -DENABLE_AMALGAM=ON \
+ -DJERRY_MATH=ON \
+ -DJERRY_CMDLINE=OFF \
+ -DJERRY_PROFILE="es5.1" \
+ -DEXTERNAL_COMPILE_FLAGS="$(ESP_CFLAGS)" \
+ -DJERRY_GLOBAL_HEAP_SIZE=$(JERRYHEAP)
+
+ make -C$(BUILD_DIR) jerry-core jerry-math
+ cp $(BUILD_DIR)/lib/libjerry-core.a $(COPYTARGET)/
+ cp $(BUILD_DIR)/lib/libjerry-math.a $(COPYTARGET)/
+
+js2c:
+ tools/js2c.py --dest targets/baremetal-sdk/esp8266-rtos-sdk/include --js-source targets/baremetal-sdk/esp8266-rtos-sdk/js
+
+mkbin:
+ make -Ctargets/baremetal-sdk/esp8266-rtos-sdk clean
+ make -Ctargets/baremetal-sdk/esp8266-rtos-sdk BOOT=new APP=0 SPI_SPEED=40 SPI_MODE=DIO SPI_SIZE_MAP=4
+
+check-env:
+ifndef SDK_PATH
+ $(error SDK_PATH is undefined for ESP8266)
+endif
+ifndef BIN_PATH
+ $(error BIN_PATH is undefined for ESP8266)
+endif
+
+flash:
+ $(ESPTOOL) --port $(USBDEVICE) write_flash \
+ 0x00000 $(BIN_PATH)/eagle.flash.bin \
+ 0x20000 $(BIN_PATH)/eagle.irom0text.bin \
+ 0x3FC000 $(SDK_PATH)/bin/esp_init_data_default.bin
+
+erase_flash:
+ $(ESPTOOL) --port $(USBDEVICE) erase_flash
+
+clean:
+ rm -rf $(BUILD_DIR)
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.travis b/targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.travis
new file mode 100644
index 00000000..c2fe5858
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.travis
@@ -0,0 +1,46 @@
+# Copyright JS Foundation and other contributors, http://js.foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# Default target for running the build test outside the Travis CI environment.
+all:
+ $(MAKE) install
+ $(MAKE) script
+
+
+## Targets for installing build dependencies of the ESP8266 JerryScript target.
+
+# Install tools via apt.
+install-apt-get-deps:
+ sudo apt-get install -q -y wget
+
+# Fetch and build crosstool-NG with support for Xtensa.
+install-xtensa-kx106-gcc:
+ wget https://dl.espressif.com/dl/xtensa-lx106-elf-linux64-1.22.0-88-gde0bdc1-4.8.5.tar.gz -O ../xtensa-lx106-elf-linux64-1.22.0-88-gde0bdc1-4.8.5.tar.gz --no-check-certificate
+ cd .. && tar xvfz xtensa-lx106-elf-linux64-1.22.0-88-gde0bdc1-4.8.5.tar.gz
+
+# Fetch Espressif SDK and Xtensa libraries.
+install-espressif-sdk:
+ git clone https://github.com/espressif/ESP8266_RTOS_SDK.git ../ESP8266_RTOS_SDK -b v2.1.0
+
+# Perform all the necessary (JerryScript-independent) installation steps.
+install-noapt: install-xtensa-kx106-gcc install-espressif-sdk
+install: install-apt-get-deps install-noapt
+
+
+## Targets for building ESP8266 with JerryScript.
+
+# Build the firmware (ESP8266 with JerryScript).
+script:
+ PATH=$(CURDIR)/../xtensa-lx106-elf/bin:$$PATH $(MAKE) -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266 BIN_PATH=build/obj-esp8266 SDK_PATH=$(CURDIR)/../ESP8266_RTOS_SDK
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/docs/ESP-PREREQUISITES.md b/targets/baremetal-sdk/esp8266-rtos-sdk/docs/ESP-PREREQUISITES.md
new file mode 100644
index 00000000..de7bb4a8
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/docs/ESP-PREREQUISITES.md
@@ -0,0 +1,120 @@
+#### Preparation
+
+##### Accessories
+
+You need,
+* 3.3V power supply. You can use bread board power (+5V, +3.3V). I used LM317 like this;
+ * Use [LM317](http://www.ti.com/lit/ds/symlink/lm317.pdf)
+ * R1 = 330 Ohm, R2 = 545 Ohm (1K + 1.2K in parallel)
+ * 5V 2A adaptor
+* USB to RS-232 Serial + RS-232 Serial to Digital or USB-to-RS232 TTL converter
+
+#### Tools
+
+The rest of this document will assume that you download all necessary tools into
+a common directory structure. For the sake of simplicity, `$HOME/Espressif` will
+be used as the root of this structure. Feel free to deviate from this but then
+adapt all the paths accordingly.
+
+```
+mkdir $HOME/Espressif
+```
+
+##### Toolchain
+
+Download the [toolchain](https://github.com/espressif/ESP8266_RTOS_SDK/tree/v3.0.1#get-toolchain)
+pre-built for your development platform to `$HOME/Espressif` and untar it. E.g.,
+on Linux/x86-64:
+
+```
+cd $HOME/Espressif
+tar xvfz xtensa-lx106-elf-linux64-1.22.0-88-gde0bdc1-4.8.5.tar.gz
+```
+
+##### Espressif SDK: use Espressif official
+
+```
+cd $HOME/Esprissif
+git clone https://github.com/espressif/ESP8266_RTOS_SDK.git -b v2.1.0
+```
+
+This version is tested and works properly.
+
+##### ESP image tool
+```
+cd $HOME/Espressif
+wget -O esptool_0.0.2-1_i386.deb https://github.com/esp8266/esp8266-wiki/raw/master/deb/esptool_0.0.2-1_i386.deb
+sudo dpkg -i esptool_0.0.2-1_i386.deb
+```
+
+##### ESP upload tool
+```
+cd $HOME/Espressif
+git clone https://github.com/themadinventor/esptool
+```
+
+##### Set environment variables
+
+Set environment variables, might also go in your `.profile`:
+```
+export PATH=$HOME/Espressif/xtensa-lx106-elf/bin:$PATH
+export SDK_PATH=$HOME/Espressif/ESP8266_RTOS_SDK
+export ESPTOOL_PATH=$HOME/Espressif/esptool
+export BIN_PATH=(to output folder path)
+```
+
+#### Test writing with Blinky example
+
+##### Get the source
+
+found one example that works with SDK V1.2 (which is based on FreeRTOS, as of writing)
+
+* https://github.com/mattcallow/esp8266-sdk/tree/master/rtos_apps/01blinky
+
+
+##### Compile
+
+Read `2A-ESP8266__IOT_SDK_User_Manual_EN` document in
+[this](http://bbs.espressif.com/viewtopic.php?f=51&t=1024) link.
+
+It's configured 2048KB flash
+```
+BOOT=new APP=1 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=5 make
+BOOT=new APP=2 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=5 make
+```
+
+or old way... this works not sure this is ok.
+```
+make BOOT=new APP=0 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=2
+```
+
+##### Flashing
+
+* power off ESP8266 board
+* connect GPIO0 to GND, connect GPIO2 to VCC
+* power on
+* write
+
+```
+sudo $HOME/Espressif/esptool/esptool.py \
+ --port /dev/ttyUSB0 write_flash \
+ 0x00000 $SDK_PATH/bin/"boot_v1.7.bin" \
+ 0x01000 $BIN_PATH/upgrade/user1.2048.new.5.bin \
+ 0x101000 $BIN_PATH/upgrade/user2.2048.new.5.bin \
+ 0x3FE000 $SDK_PATH/bin/blank.bin \
+ 0x3FC000 $SDK_PATH/bin/esp_init_data_default.bin
+```
+_change `/dev/ttyUSB1` to whatever you have._
+
+or the old way...this works not sure this is ok.
+```
+cd $BIN_PATH
+sudo $HOME/Espressif/esptool/esptool.py \
+--port /dev/ttyUSB0 write_flash \
+0x00000 eagle.flash.bin 0x40000 eagle.irom0text.bin
+```
+
+* power off
+* disconnect GPIO0 so that it is floating
+* connect GPIO2 with serial of 470 Ohm + LED and to GND
+* power On
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/include/jerry_extapi.h b/targets/baremetal-sdk/esp8266-rtos-sdk/include/jerry_extapi.h
new file mode 100644
index 00000000..5c0c4e5b
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/include/jerry_extapi.h
@@ -0,0 +1,30 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __JERRY_EXTAPI_H__
+#define __JERRY_EXTAPI_H__
+
+#define JERRY_STANDALONE_EXIT_CODE_OK (0)
+#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
+
+#include "jerryscript.h"
+
+JERRY_C_API_BEGIN
+
+void js_register_functions (void);
+
+JERRY_C_API_END
+
+#endif /* __JERRY_EXTAPI_H__ */
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/include/jerry_run.h b/targets/baremetal-sdk/esp8266-rtos-sdk/include/jerry_run.h
new file mode 100644
index 00000000..51bc136c
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/include/jerry_run.h
@@ -0,0 +1,32 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __JERRY_RUN_H__
+#define __JERRY_RUN_H__
+
+#include <stdint.h>
+
+#include "jerryscript.h"
+
+JERRY_C_API_BEGIN
+
+void js_entry (void);
+int js_eval (const char *source_p, const size_t source_size);
+int js_loop (uint32_t ticknow);
+void js_exit (void);
+
+JERRY_C_API_END
+
+#endif /* __JERRY_RUN_H__ */
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/include/user_config.h b/targets/baremetal-sdk/esp8266-rtos-sdk/include/user_config.h
new file mode 100644
index 00000000..dd948fe5
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/include/user_config.h
@@ -0,0 +1,24 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __USER_CONFIG_H__
+#define __USER_CONFIG_H__
+
+
+/* number of stack items, x4 for bytes */
+#define JERRY_STACK_SIZE 2000
+
+
+#endif /* __USER_CONFIG_H__ */
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/js/blink.js b/targets/baremetal-sdk/esp8266-rtos-sdk/js/blink.js
new file mode 100644
index 00000000..d3c6d827
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/js/blink.js
@@ -0,0 +1,30 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var check = 1;
+
+function blink() {
+ var inp = gpio_get(0);
+ var blk = (check > 8) ? 1 - inp : inp;
+ gpio_set(2, blk);
+ check = check >= 10 ? 1 : check+1;
+}
+
+// GPIO 0 as input
+// GPIO 2 as output
+gpio_dir(0, 0);
+gpio_dir(2, 1);
+
+print("blink js OK");
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/js/main.js b/targets/baremetal-sdk/esp8266-rtos-sdk/js/main.js
new file mode 100644
index 00000000..a25cf064
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/js/main.js
@@ -0,0 +1,20 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+function sysloop(ticknow) {
+ blink();
+};
+print("Random generated number: ", Math.random());
+print("main js OK");
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/ld/eagle.app.v6.ld b/targets/baremetal-sdk/esp8266-rtos-sdk/ld/eagle.app.v6.ld
new file mode 100644
index 00000000..07942c68
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/ld/eagle.app.v6.ld
@@ -0,0 +1,32 @@
+/* eagle.flash.bin @ 0x00000 */
+/* eagle.irom0text.bin @ 0x20000 */
+
+/* Flash Map, support 512KB/1MB/2MB/4MB SPI Flash */
+/* |......|..............................|..........................|.....|....| */
+/* ^ ^ ^ ^ ^ */
+/* |_flash.bin start(0x00000) |_irom0text.bin start(0x20000) | */
+/* |_flash.bin end |_irom0text.bin end */
+/* |_system param area(0x7b000) */
+
+/* NOTICE: */
+/* 1. You can change irom0 org, but MUST make sure irom0text.bin start not overlap flash.bin end. */
+/* 2. You can change irom0 len, but MUST make sure irom0text.bin end not overlap system param area. */
+/* 3. Space between flash.bin end and irom0text.bin start can be used as user param area. */
+/* 4. Space between irom0text.bin end and system param area can be used as user param area. */
+/* 5. Make sure irom0text.bin end < 0x100000 */
+/* 6. system param area: */
+/* 1>. 512KB--->0x07b000 */
+/* 2>. 1MB----->0x0fb000 */
+/* 3>. 2MB----->0x1fb000 */
+/* 4>. 4MB----->0x3fb000 */
+/* 7. Don't change any other seg. */
+
+MEMORY
+{
+ dport0_0_seg : org = 0x3FF00000, len = 0x10
+ dram0_0_seg : org = 0x3FFE8000, len = 0x18000
+ iram1_0_seg : org = 0x40100000, len = 0x8000
+ irom0_0_seg : org = 0x40220000, len = 0x7C000
+}
+
+INCLUDE ../ld/eagle.app.v6.common.ld
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/readme.md b/targets/baremetal-sdk/esp8266-rtos-sdk/readme.md
new file mode 100644
index 00000000..264a0c91
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/readme.md
@@ -0,0 +1,88 @@
+### About
+
+Files in this folder (targets/baremetal-sdk/esp8266-rtos-sdk) are copied from
+`examples/project_template` of `esp_iot_rtos_sdk` and modified for JerryScript.
+You can view online from
+[this](https://github.com/espressif/esp_iot_rtos_sdk/tree/master/examples/project_template) page.
+
+
+### How to build JerryScript for ESP8266
+
+#### 1. SDK
+
+Follow [this](./docs/ESP-PREREQUISITES.md) page to setup build environment
+
+
+#### 2. Building JerryScript
+
+```
+# assume you are in jerryscript folder
+make -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266
+```
+
+Output files should be placed at $BIN_PATH
+
+#### 3. Flashing for ESP8266 12E
+Follow
+[this](http://www.kloppenborg.net/images/blog/esp8266/esp8266-esp12e-specs.pdf) page to get details about this board.
+
+```
+make -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266 flash
+```
+
+Default USB device is `/dev/ttyUSB0`. If you have different one, give with `USBDEVICE`, like;
+
+```
+USBDEVICE=/dev/ttyUSB1 make -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266 flash
+```
+
+### 4. Running
+
+* power off
+* connect GPIO2 with serial of 470 Ohm + LED and to GND
+* power On
+
+LED should blink on and off every second
+
+#### 5. Cleaning
+
+To clean the build result:
+
+```
+make -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266 clean
+```
+
+To clean the board's flash memory:
+```
+make -f ./targets/baremetal-sdk/esp8266-rtos-sdk/Makefile.esp8266 erase_flash
+```
+
+
+### 6. Optimizing initial RAM usage (ESP8266 specific)
+The existing open source gcc compiler with Xtensa support stores const(ants) in
+the same limited RAM where our code needs to run.
+
+It is possible to force the compiler to store a constant into ROM and also read it from there thus saving RAM.
+The only requirement is to add `JERRY_ATTR_CONST_DATA` attribute to your constant.
+
+For example:
+
+```C
+static const lit_magic_size_t lit_magic_string_sizes[] =
+```
+
+can be modified to
+
+```C
+static const lit_magic_size_t lit_magic_string_sizes[] JERRY_ATTR_CONST_DATA =
+```
+
+That is already done to some constants in jerry-core. E.g.:
+
+- vm_decode_table
+- ecma_property_hashmap_steps
+- lit_magic_string_sizes
+- unicode_letter_interv_sps
+- unicode_letter_interv_len
+- unicode_non_letter_ident_
+- unicode_letter_chars
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/user/Makefile b/targets/baremetal-sdk/esp8266-rtos-sdk/user/Makefile
new file mode 100644
index 00000000..76aea693
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/user/Makefile
@@ -0,0 +1,44 @@
+
+#############################################################
+# Required variables for each makefile
+# Discard this section from all parent makefiles
+# Expected variables (with automatic defaults):
+# CSRCS (all "C" files in the dir)
+# SUBDIRS (all subdirs with a Makefile)
+# GEN_LIBS - list of libs to be generated ()
+# GEN_IMAGES - list of images to be generated ()
+# COMPONENTS_xxx - a list of libs/objs in the form
+# subdir/lib to be extracted and rolled up into
+# a generated lib/image xxx.a ()
+#
+ifndef PDIR
+GEN_LIBS = libuser.a
+endif
+
+
+#############################################################
+# Configuration i.e. compile options etc.
+# Target specific stuff (defines etc.) goes in here!
+# Generally values applying to a tree are captured in the
+# makefile at its root level - these are then overridden
+# for a subtree within the makefile rooted therein
+#
+#DEFINES +=
+
+#############################################################
+# Recursion Magic - Don't touch this!!
+#
+# Each subtree potentially has an include directory
+# corresponding to the common APIs applicable to modules
+# rooted at that subtree. Accordingly, the INCLUDE PATH
+# of a module can only contain the include directories up
+# its parent path, and not its siblings
+#
+# Required for each makefile to inherit from the parent
+#
+
+
+INCLUDES := $(INCLUDES) -I $(PDIR)include
+INCLUDES += -I ./
+PDIR := ../$(PDIR)
+sinclude $(PDIR)Makefile
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/user/jerry_extapi.c b/targets/baremetal-sdk/esp8266-rtos-sdk/user/jerry_extapi.c
new file mode 100644
index 00000000..5cccce4d
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/user/jerry_extapi.c
@@ -0,0 +1,182 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "jerry_extapi.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "jerryscript.h"
+
+#include "c_types.h"
+#include "gpio.h"
+
+#define __UNUSED__ __attribute__ ((unused))
+
+#define DELCARE_HANDLER(NAME) \
+ static jerry_value_t NAME##_handler (const jerry_call_info_t *call_info_p __UNUSED__, \
+ const jerry_value_t args_p[], \
+ const jerry_length_t args_cnt)
+
+#define REGISTER_HANDLER(NAME) register_native_function (#NAME, NAME##_handler)
+
+DELCARE_HANDLER (assert)
+{
+ if (args_cnt == 1 && jerry_value_is_true (args_p[0]))
+ {
+ printf (">> Jerry assert true\r\n");
+ return jerry_boolean (true);
+ }
+ printf ("Script assertion failed\n");
+ exit (JERRY_STANDALONE_EXIT_CODE_FAIL);
+ return jerry_boolean (false);
+} /* assert */
+
+DELCARE_HANDLER (print)
+{
+ if (args_cnt)
+ {
+ for (jerry_length_t cc = 0; cc < args_cnt; cc++)
+ {
+ if (jerry_value_is_string (args_p[cc]))
+ {
+ jerry_size_t size = jerry_string_size (args_p[0], JERRY_ENCODING_UTF8);
+ char *buffer;
+ buffer = (char *) malloc (size + 1);
+
+ if (!buffer)
+ {
+ // not enough memory for this string.
+ printf ("[<too-long-string>]");
+ continue;
+ }
+
+ jerry_string_to_buffer (args_p[cc], JERRY_ENCODING_UTF8, (jerry_char_t *) buffer, size);
+ buffer[size] = '\0';
+ printf ("%s ", buffer);
+ free (buffer);
+ }
+ else if (jerry_value_is_number (args_p[cc]))
+ {
+ double number = jerry_value_as_number (args_p[cc]);
+ if ((int) number == number)
+ {
+ printf ("%d", (int) number);
+ }
+ else
+ {
+ char buff[50];
+ sprintf (buff, "%.10f", number);
+ printf ("%s", buff);
+ }
+ }
+ }
+ printf ("\r\n");
+ }
+ return jerry_boolean (true);
+} /* print */
+
+DELCARE_HANDLER (gpio_dir)
+{
+ if (args_cnt < 2)
+ {
+ return jerry_boolean (false);
+ }
+
+ int port = (int) jerry_value_as_number (args_p[0]);
+ int value = (int) jerry_value_as_number (args_p[1]);
+
+ if (value)
+ {
+ GPIO_AS_OUTPUT (1 << port);
+ }
+ else
+ {
+ GPIO_AS_INPUT (1 << port);
+ }
+
+ return jerry_boolean (true);
+} /* gpio_dir */
+
+DELCARE_HANDLER (gpio_set)
+{
+ if (args_cnt < 2)
+ {
+ return jerry_boolean (false);
+ }
+
+ int port = (int) jerry_value_as_number (args_p[0]);
+ int value = (int) jerry_value_as_number (args_p[1]);
+
+ GPIO_OUTPUT_SET (port, value);
+
+ return jerry_boolean (true);
+} /* gpio_set */
+
+DELCARE_HANDLER (gpio_get)
+{
+ if (args_cnt < 1)
+ {
+ return jerry_boolean (false);
+ }
+
+ int port = (int) jerry_value_as_number (args_p[0]);
+ int value = GPIO_INPUT_GET (port) ? 1 : 0;
+
+ return jerry_number ((double) value);
+} /* gpio_get */
+
+static bool
+register_native_function (const char *name, jerry_external_handler_t handler)
+{
+ jerry_value_t global_obj_val = jerry_current_realm ();
+ jerry_value_t reg_func_val = jerry_function_external (handler);
+
+ if (!(jerry_value_is_function (reg_func_val) && jerry_value_is_constructor (reg_func_val)))
+ {
+ printf ("!!! create_external_function failed !!!\r\n");
+ jerry_value_free (reg_func_val);
+ jerry_value_free (global_obj_val);
+ return false;
+ }
+
+ jerry_value_t prop_name_val = jerry_string_sz (name);
+ jerry_value_t res = jerry_object_set (global_obj_val, prop_name_val, reg_func_val);
+
+ jerry_value_free (reg_func_val);
+ jerry_value_free (global_obj_val);
+ jerry_value_free (prop_name_val);
+
+ if (jerry_value_is_exception (res))
+ {
+ printf ("!!! register_native_function failed: [%s]\r\n", name);
+ jerry_value_free (res);
+ return false;
+ }
+
+ jerry_value_free (res);
+
+ return true;
+} /* register_native_function */
+
+void
+js_register_functions (void)
+{
+ REGISTER_HANDLER (assert);
+ REGISTER_HANDLER (print);
+ REGISTER_HANDLER (gpio_dir);
+ REGISTER_HANDLER (gpio_set);
+ REGISTER_HANDLER (gpio_get);
+} /* js_register_functions */
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/user/jerry_port.c b/targets/baremetal-sdk/esp8266-rtos-sdk/user/jerry_port.c
new file mode 100644
index 00000000..f4d58769
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/user/jerry_port.c
@@ -0,0 +1,73 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <sys/time.h>
+
+#include "esp_common.h"
+
+#include "jerryscript-port.h"
+
+/**
+ * Provide log message implementation for the engine.
+ */
+void
+jerry_port_log (jerry_log_level_t level, /**< log level */
+ const char *format, /**< format string */
+ ...) /**< parameters */
+{
+ (void) level; /* ignore log level */
+
+ va_list args;
+ va_start (args, format);
+ vfprintf (stderr, format, args);
+ va_end (args);
+} /* jerry_port_log */
+
+/**
+ * Provide fatal message implementation for the engine.
+ */
+void
+jerry_port_fatal (jerry_fatal_code_t code)
+{
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Jerry Fatal Error!\n");
+ while (true);
+} /* jerry_port_fatal */
+
+/**
+ * Implementation of jerry_port_get_current_time.
+ *
+ * @return current timer's counter value in milliseconds
+ */
+double
+jerry_port_get_current_time (void)
+{
+ uint32_t rtc_time = system_rtc_clock_cali_proc();
+ return (double) rtc_time;
+} /* jerry_port_get_current_time */
+
+/**
+ * Dummy function to get the time zone adjustment.
+ *
+ * @return 0
+ */
+double
+jerry_port_get_local_time_zone_adjustment (double unix_ms, bool is_utc)
+{
+ /* We live in UTC. */
+ return 0;
+} /* jerry_port_get_local_time_zone_adjustment */
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/user/jerry_run.c b/targets/baremetal-sdk/esp8266-rtos-sdk/user/jerry_run.c
new file mode 100644
index 00000000..b3205bac
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/user/jerry_run.c
@@ -0,0 +1,109 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "jerry_run.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "jerryscript-port.h"
+#include "jerryscript.h"
+
+#include "jerry_extapi.h"
+
+static const char *fn_sys_loop_name = "sysloop";
+
+void
+js_entry ()
+{
+ union
+ {
+ double d;
+ unsigned u;
+ } now = { .d = jerry_port_get_current_time () };
+ srand (now.u);
+
+ jerry_init (JERRY_INIT_EMPTY);
+ js_register_functions ();
+}
+
+int
+js_eval (const char *source_p, const size_t source_size)
+{
+ jerry_value_t res = jerry_eval ((jerry_char_t *) source_p, source_size, JERRY_PARSE_NO_OPTS);
+ if (jerry_value_is_exception (res))
+ {
+ jerry_value_free (res);
+ return -1;
+ }
+
+ jerry_value_free (res);
+
+ return 0;
+}
+
+int
+js_loop (uint32_t ticknow)
+{
+ jerry_value_t global_obj_val = jerry_current_realm ();
+ jerry_value_t prop_name_val = jerry_string_sz (fn_sys_loop_name);
+ jerry_value_t sysloop_func = jerry_object_get (global_obj_val, prop_name_val);
+ jerry_value_free (prop_name_val);
+
+ if (jerry_value_is_exception (sysloop_func))
+ {
+ printf ("Error: '%s' not defined!!!\r\n", fn_sys_loop_name);
+ jerry_value_free (sysloop_func);
+ jerry_value_free (global_obj_val);
+ return -1;
+ }
+
+ if (!jerry_value_is_function (sysloop_func))
+ {
+ printf ("Error: '%s' is not a function!!!\r\n", fn_sys_loop_name);
+ jerry_value_free (sysloop_func);
+ jerry_value_free (global_obj_val);
+ return -2;
+ }
+
+ jerry_value_t val_args[] = { jerry_number (ticknow) };
+ uint16_t val_argv = sizeof (val_args) / sizeof (jerry_value_t);
+
+ jerry_value_t res = jerry_call (sysloop_func, global_obj_val, val_args, val_argv);
+
+ for (uint16_t i = 0; i < val_argv; i++)
+ {
+ jerry_value_free (val_args[i]);
+ }
+
+ jerry_value_free (sysloop_func);
+ jerry_value_free (global_obj_val);
+
+ if (jerry_value_is_exception (res))
+ {
+ jerry_value_free (res);
+ return -3;
+ }
+
+ jerry_value_free (res);
+
+ return 0;
+}
+
+void
+js_exit (void)
+{
+ jerry_cleanup ();
+}
diff --git a/targets/baremetal-sdk/esp8266-rtos-sdk/user/user_main.c b/targets/baremetal-sdk/esp8266-rtos-sdk/user/user_main.c
new file mode 100644
index 00000000..48fd2631
--- /dev/null
+++ b/targets/baremetal-sdk/esp8266-rtos-sdk/user/user_main.c
@@ -0,0 +1,147 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/******************************************************************************
+ * Copyright 2013-2014 Espressif Systems (Wuxi)
+ *
+ * FileName: user_main.c
+ *
+ * Description: entry file of user application
+ *
+ * Modification history:
+ * 2014/12/1, v1.0 create this file.
+*******************************************************************************/
+
+#include "esp_common.h"
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "uart.h"
+
+#include "user_config.h"
+#include "jerry_run.h"
+#include "jerry-targetjs.h"
+
+static void show_free_mem(int idx) {
+ size_t res = xPortGetFreeHeapSize();
+ printf("dbg free memory(%d): %d\r\n", idx, res);
+}
+
+static int jerry_task_init(void) {
+ DECLARE_JS_CODES;
+
+ js_entry();
+
+ /* run rest of the js files first */
+ show_free_mem(2);
+ for (int src = 1; js_codes[src].source; src++) {
+ int retcode = js_eval(js_codes[src].source, js_codes[src].length);
+ if (retcode != 0) {
+ printf("js_eval failed code(%d) [%s]\r\n", retcode, js_codes[src].name);
+ return -1;
+ }
+ }
+
+ /* run main.js */
+ int retcode = js_eval(js_codes[0].source, js_codes[0].length);
+ if (retcode != 0) {
+ printf("js_eval failed code(%d) [%s]\r\n", retcode, js_codes[0].name);
+ return -2;
+ }
+ show_free_mem(3);
+ return 0;
+}
+
+static void jerry_task(void *pvParameters) {
+ if (jerry_task_init() == 0) {
+ const portTickType xDelay = 100 / portTICK_RATE_MS;
+ uint32_t ticknow = 0;
+
+ for (;;) {
+ vTaskDelay(xDelay);
+ js_loop(ticknow);
+ if (!ticknow) {
+ show_free_mem(4);
+ }
+ ticknow++;
+ }
+ }
+ js_exit();
+}
+
+/*
+ * This is entry point for user code
+ */
+void ICACHE_FLASH_ATTR user_init(void)
+{
+ UART_SetBaudrate(UART0, BIT_RATE_115200);
+
+ show_free_mem(0);
+ wifi_softap_dhcps_stop();
+ show_free_mem(1);
+
+ PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); // GPIO 0
+ PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); // GPIO 2
+
+ xTaskCreate(jerry_task, "jerry", JERRY_STACK_SIZE, NULL, 2, NULL);
+}
+
+/*
+ * FunctionName : user_rf_cal_sector_set
+ * Description : SDK just reserved 4 sectors, used for rf init data and Parameters.
+ * We add this function to force users to set rf cal sector, since
+ * we don't know which sector is free in user's application.
+ * sector map for last several sectors : ABCCC
+ * A : rf cal
+ * B : rf init data
+ * C : sdk parameters
+ * Parameters : none
+ * Returns : rf cal sector
+ */
+uint32 user_rf_cal_sector_set(void)
+{
+ flash_size_map size_map = system_get_flash_size_map();
+ uint32 rf_cal_sec = 0;
+
+ switch (size_map) {
+ case FLASH_SIZE_4M_MAP_256_256:
+ rf_cal_sec = 128 - 5;
+ break;
+
+ case FLASH_SIZE_8M_MAP_512_512:
+ rf_cal_sec = 256 - 5;
+ break;
+
+ case FLASH_SIZE_16M_MAP_512_512:
+ case FLASH_SIZE_16M_MAP_1024_1024:
+ rf_cal_sec = 512 - 5;
+ break;
+
+ case FLASH_SIZE_32M_MAP_512_512:
+ case FLASH_SIZE_32M_MAP_1024_1024:
+ rf_cal_sec = 1024 - 5;
+ break;
+ case FLASH_SIZE_64M_MAP_1024_1024:
+ rf_cal_sec = 2048 - 5;
+ break;
+ case FLASH_SIZE_128M_MAP_1024_1024:
+ rf_cal_sec = 4096 - 5;
+ break;
+ default:
+ rf_cal_sec = 0;
+ break;
+ }
+
+ return rf_cal_sec;
+}
diff --git a/targets/baremetal-sdk/particle/Makefile.particle b/targets/baremetal-sdk/particle/Makefile.particle
new file mode 100644
index 00000000..aae19783
--- /dev/null
+++ b/targets/baremetal-sdk/particle/Makefile.particle
@@ -0,0 +1,63 @@
+# Copyright JS Foundation and other contributors, http://js.foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+PARTICLE_FIRMWARE := $(CURDIR)/../particle/firmware
+
+JERRYDIR ?= $(CURDIR)
+JERRYHEAP ?= 16
+
+BUILD_DIR ?= $(JERRYDIR)/build/particle
+
+EXT_CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
+EXT_CFLAGS += -Wno-error=format=
+
+.PHONY: jerrycore jerry-main flash clean
+
+PARTICLE_BUILD_CONFIG = \
+ INCLUDE_DIRS=$(JERRYDIR)/jerry-core/include \
+ LIBS=jerry-core \
+ PLATFORM=photon \
+ LIB_DIRS=$(BUILD_DIR)/lib \
+ APPDIR=$(JERRYDIR)/targets/baremetal-sdk/particle/source \
+ TARGET_FILE=jerry_main \
+ TARGET_DIR=$(BUILD_DIR) \
+ LDFLAGS=--specs=nano.specs
+
+all: jerrycore jerry-main
+
+jerrycore:
+ mkdir -p $(BUILD_DIR)
+ cmake -B$(BUILD_DIR) -H./ \
+ -DCMAKE_SYSTEM_NAME=MCU \
+ -DCMAKE_SYSTEM_PROCESSOR=armv7l \
+ -DCMAKE_C_COMPILER=arm-none-eabi-gcc \
+ -DCMAKE_C_COMPILER_WORKS=TRUE \
+ -DENABLE_LTO=ON \
+ -DJERRY_CMDLINE=OFF \
+ -DJERRY_PROFILE=minimal \
+ -DENABLE_STRIP=OFF \
+ -DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
+ -DJERRY_GLOBAL_HEAP_SIZE=$(JERRYHEAP)
+
+ make -C$(BUILD_DIR) jerry-core
+
+jerry-main: jerrycore
+ $(PARTICLE_BUILD_CONFIG) make -C$(PARTICLE_FIRMWARE) -f $(PARTICLE_FIRMWARE)/makefile
+
+flash:
+ $(PARTICLE_BUILD_CONFIG) make -C$(PARTICLE_FIRMWARE)/main -f $(PARTICLE_FIRMWARE)/main/makefile program-dfu
+
+clean:
+ $(PARTICLE_BUILD_CONFIG) make -C$(PARTICLE_FIRMWARE) -f $(PARTICLE_FIRMWARE)/makefile clean
+ rm -rf $(BUILD_DIR)
diff --git a/targets/baremetal-sdk/particle/README.md b/targets/baremetal-sdk/particle/README.md
new file mode 100644
index 00000000..21dc7df0
--- /dev/null
+++ b/targets/baremetal-sdk/particle/README.md
@@ -0,0 +1,92 @@
+### About
+
+This folder contains files to run JerryScript beside Particle Device Firmware on Photon board.
+It runs a mini example, blinking an LED which is the "Hello World" example of the microcontroller universe.
+
+### How to build
+
+#### 1. Preface / Directory structure
+
+Assume `root` as the path to the projects to build.
+The folder tree related would look like this.
+
+```
+root
+ + jerryscript
+ | + targets
+ | + os
+ | + particle
+ + particle
+ | + firmware
+```
+
+
+#### 2, Update/Install the Particle Firmware
+
+For detailed descriptions please visit the official website of the firmware: https://www.particle.io/
+
+You can checkout the firmware with the following command:
+
+```
+# assume you are in root folder
+git clone https://github.com/spark/firmware.git particle/firmware
+````
+
+The Photon’s latest firmware release is hosted in the latest branch of the firmware repo.
+
+```
+# assume you are in root folder
+cd particle/firmware
+git checkout latest
+```
+
+Before you type any commands, put your Photon in DFU mode: hold down both the SETUP and RESET buttons. Then release RESET, but hold SETUP until you see the RGB blink yellow. That means the Photon is in DFU mode. To verify that the Photon is in DFU mode and dfu-util is installed properly, try the dfu-util -l command. You should see the device, and the important parts there are the hex values inside the braces – the USB VID and PID, which should be 2b04 and d006 for the Photon.
+
+To build and flash the firmware: switch to the modules directory then call make with a few parameters to build and upload the firmware:
+
+```
+cd modules
+make PLATFORM=photon clean all program-dfu
+```
+
+#### 3. Build JerryScript
+
+```
+# assume you are in root folder
+cd jerryscript
+make -f ./targets/baremetal-sdk/particle/Makefile.particle
+```
+
+This will create a binary file in the `/build/particle/` folder:
+```
+jerry_main.bin
+```
+
+That’s the binary what we’ll be flashing with dfu-util.
+
+
+#### 4. Flashing
+
+Make sure you put your Photon in DFU mode.
+Alternatively, you can make your life a bit easier by using the make command to invoke dfu-util:
+
+```
+make -f targets/baremetal-sdk/particle/Makefile.particle flash
+```
+
+You can also use this dfu-util command directly to upload your BIN file to the Photon’s application memory:
+
+```
+dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x80A0000:leave -D build/particle/jerry_main.bin
+```
+
+#### 5. Cleaning
+
+To clean the build result:
+```
+make -f targets/baremetal-sdk/particle/Makefile.particle clean
+```
+
+### Running the example
+
+The example program will blinks the D7 led periodically after the flash. \ No newline at end of file
diff --git a/targets/baremetal-sdk/particle/source/main.cpp b/targets/baremetal-sdk/particle/source/main.cpp
new file mode 100644
index 00000000..b5cd6ceb
--- /dev/null
+++ b/targets/baremetal-sdk/particle/source/main.cpp
@@ -0,0 +1,146 @@
+/* Copyright JS Foundation and other contributors, http://js.foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "application.h"
+#include "jerryscript.h"
+
+SYSTEM_MODE (MANUAL);
+
+/**
+ * Set led value
+ */
+static jerry_value_t
+set_led (const jerry_value_t func_value, /**< function object */
+ const jerry_value_t this_value, /**< this arg */
+ const jerry_value_t *args_p, /**< function arguments */
+ const jerry_length_t args_cnt) /**< number of function arguments */
+{
+ if (args_cnt != 2)
+ {
+ Serial.println ("Wrong arguments count in 'test.setLed' function.");
+ return jerry_boolean (false);
+ }
+
+ int ledPin = jerry_value_as_number (args_p[0]);
+ bool value = jerry_value_is_true (args_p[1]);
+
+ pinMode (ledPin, OUTPUT);
+ digitalWrite (ledPin, value);
+
+ return jerry_boolean (true);
+} /* set_led */
+
+/**
+ * Delay function
+ */
+static jerry_value_t
+js_delay (const jerry_value_t func_value, /**< function object */
+ const jerry_value_t this_value, /**< this arg */
+ const jerry_value_t *args_p, /**< function arguments */
+ const jerry_length_t args_cnt) /**< number of function arguments */
+{
+ if (args_cnt != 1)
+ {
+ Serial.println ("Wrong arguments count in 'test.delay' function.");
+ return jerry_boolean (false);
+ }
+
+ int millisec = jerry_value_as_number (args_p[0]);
+
+ delay (millisec);
+
+ return jerry_boolean (true);
+} /* js_delay */
+
+/*
+ * Init available js functions
+ */
+static void
+init_jerry ()
+{
+ jerry_init (JERRY_INIT_EMPTY);
+
+ /* Create an empty JS object */
+ jerry_value_t object = jerry_object ();
+
+ jerry_value_t func_obj;
+ jerry_value_t prop_name;
+
+ func_obj = jerry_function_external (set_led);
+ prop_name = jerry_string_sz ("setLed");
+ jerry_value_free (jerry_object_set (object, prop_name, func_obj));
+ jerry_value_free (prop_name);
+ jerry_value_free (func_obj);
+
+ func_obj = jerry_function_external (js_delay);
+ prop_name = jerry_string_sz ("delay");
+ jerry_value_free (jerry_object_set (object, prop_name, func_obj));
+ jerry_value_free (prop_name);
+ jerry_value_free (func_obj);
+
+ /* Wrap the JS object (not empty anymore) into a jerry api value */
+ jerry_value_t global_object = jerry_current_realm ();
+
+ /* Add the JS object to the global context */
+ prop_name = jerry_string_sz ("test");
+ jerry_value_free (jerry_object_set (global_object, prop_name, object));
+ jerry_value_free (prop_name);
+ jerry_value_free (object);
+ jerry_value_free (global_object);
+} /* init_jerry */
+
+/**
+ * Jerryscript simple test
+ */
+static void
+test_jerry ()
+{
+ const jerry_char_t script[] = " \
+ test.setLed(7, true); \
+ test.delay(250); \
+ test.setLed(7, false); \
+ test.delay(250); \
+ ";
+
+ jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
+
+ /* Free JavaScript value, returned by eval */
+ jerry_value_free (eval_ret);
+} /* test_jerry */
+
+/**
+ * Setup code for particle firmware
+ */
+void
+setup ()
+{
+ Serial.begin (9600);
+ delay (2000);
+ Serial.println ("Beginning Listening mode test!");
+} /* setup */
+
+/**
+ * Loop code for particle firmware
+ */
+void
+loop ()
+{
+ init_jerry ();
+
+ /* Turn on and off the D7 LED */
+ test_jerry ();
+
+ jerry_cleanup ();
+} /* loop */