Skip to content

Commit 7583b63

Browse files
committed
Added target to compile zephyr against jerryscript.
This patch contains a project in which you can run a small js test inside the Arduino101. Follows the Nuttx implementation to replicate a command line in the Quark SE Lakemont architecture. Everything is self contained in the targets/arduino_101 folder. It has only been tested with the arduino 101 at the moment. Check the README.md for a more detailed explanation of how to compile and run it. - Command line javascript run test. Use test to get a default test. Write any valid javascript in the shell and get it resolved and executed - Support for qemu - Added extra verbose mode on the demo function - Support to build factory images that can be flashed with dfu-util - Added a few extra examples on the README about commands that work. Small fixes to readme and libc_support.c (#1) - Added a few more instructions to the README.md for arduino_101 - Added the stdint.h include in libc_support.c - Added parameter to check-vera.sh to check a specific folder - Cleared the libc function duplication JerryScript-DCO-1.0-Signed-off-by: Sergio Martinez [email protected]
1 parent 308bb3c commit 7583b63

File tree

10 files changed

+629
-1
lines changed

10 files changed

+629
-1
lines changed

targets/arduino_101/Makefile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright © 2016 Intel Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# use TAB-8
16+
.DEFAULT_GOAL := all
17+
18+
ifndef ZEPHYR_BASE
19+
$(error Missing zephyr base)
20+
endif
21+
22+
# For testing without real hardware use qemu_x86 instead of arduino_101
23+
BOARD ?= arduino_101
24+
25+
O ?= $(PROJECT_BASE)/outdir
26+
27+
ZEPHYR ?= $(ZEPHYR_BASE)
28+
TYPE ?= release
29+
JERRYHEAP ?= 16
30+
31+
ZEPHYRINC = $(ZEPHYR_BASE)/include
32+
ZEPHYRLIB = $(ZEPHYR_BASE)/lib
33+
34+
SOURCE_DIR = ./targets/arduino_101/src
35+
36+
export JERRY_INCLUDE = $(CURDIR)/jerry-core/
37+
38+
MDEF_FILE = $(realpath $(SOURCE_DIR)/../prj.mdef)
39+
CONF_FILE = $(realpath $(SOURCE_DIR)/../prj.conf)
40+
41+
ifdef V
42+
$(info Zephyr)
43+
$(info SOURCE_DIR=$(SOURCE_DIR))
44+
$(info JERRY_INCLUDE=$(JERRY_INCLUDE))
45+
$(info CONF_FILE =$(CONF_FILE))
46+
endif
47+
48+
KERNEL_TYPE = micro
49+
50+
KBUILD_VERBOSE = $(V)
51+
52+
APP = main-zephyr.c
53+
54+
include ${ZEPHYR_BASE}/Makefile.inc
55+
56+
.PHONY = showconfig
57+
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Copyright © 2016 Intel Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
.DEFAULT_GOAL := all
16+
17+
ifeq ($(.DEFAULT_GOAL),)
18+
$(warning no default goal is set)
19+
endif
20+
21+
ifeq ($(MAKECMDGOALS),qemu)
22+
BOARD ?= qemu_x86
23+
else
24+
BOARD ?= arduino_101
25+
BOARD_NAME ?= arduino_101
26+
endif
27+
28+
ifeq ($(BOARD),qemu_x86)
29+
BOARD_NAME ?= qemu_x86
30+
endif
31+
32+
TYPE ?= release
33+
JERRYHEAP ?= 16
34+
35+
# Include functionality like regular expressions
36+
# check Jerry script documentation
37+
#
38+
# -cp
39+
# -cp_minimal
40+
# -cp_minimal-mem_stats
41+
# -mem_stats
42+
# -mem_stress_test
43+
44+
ifndef ZEPHYR_BASE
45+
$(error Missing Zephyr base, did you source zephyr-env.sh? )
46+
endif
47+
48+
VARIETY ?= -cp_minimal
49+
50+
INTERM = build/$(BOARD)/obj-$(BOARD)
51+
OUTPUT = build/$(BOARD)
52+
53+
CC = $(CROSS_COMPILE)gcc
54+
55+
EXT_CFLAGS := -fno-asynchronous-unwind-tables -fno-omit-frame-pointer
56+
EXT_CFLAGS += -fno-stack-protector -fno-strict-overflow -ffreestanding
57+
EXT_CFLAGS += -fno-reorder-functions -fno-defer-pop -fdata-sections
58+
EXT_CFLAGS += -ffunction-sections -fno-inline-functions
59+
60+
# TODO @sergioamr Read the arch and cflags from zephyr
61+
62+
ifeq ($(BOARD),qemu_x86)
63+
CONFIG_TOOLCHAIN_VARIANT = x86
64+
EXT_CFLAGS += -march=pentium
65+
else
66+
CONFIG_TOOLCHAIN_VARIANT = iamcu
67+
EXT_CFLAGS += -march=lakemont -mtune=lakemont -miamcu -msoft-float
68+
endif
69+
70+
EXT_CFLAGS += -mpreferred-stack-boundary=2 -mno-sse
71+
72+
EXT_CFLAGS += -Wall -Wno-format-zero-length -Wno-pointer-sign
73+
EXT_CFLAGS += -Werror=format -Werror=implicit-int -Wno-unused-but-set-variable
74+
EXT_CFLAGS += -Wno-main -Wno-strict-aliasing
75+
EXT_CFLAGS += -Wno-error=format=
76+
77+
EXT_CFLAGS += $(TOOLCHAIN_CFLAGS)
78+
EXT_CFLAGS += $(LIB_INCLUDE_DIR)
79+
EXT_CFLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
80+
EXT_CFLAGS += -isystem $(shell $(CC) -print-file-name=include-fixed)
81+
82+
-include $(ZEPHYR_BASE)/boards/$(BOARD_NAME)/Makefile.board
83+
-include $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT)
84+
85+
ZEPHYR_LIBC_INC = $(subst -I,,$(TOOLCHAIN_CFLAGS))
86+
LIB_INCLUDE_DIR += -L $(CURDIR)/$(OUTPUT)
87+
88+
EXTERNAL_LIB = $(INTERM)/lib$(TYPE).external$(VARIETY)-entry.a
89+
ZEPHYR_BIN = $(OUTPUT)/zephyr/zephyr.strip
90+
91+
PREFIX = $(TYPE)$(VARIETY)
92+
LIBS = $(TYPE).external$(VARIETY)-entry $(PREFIX).jerry-core $(PREFIX).jerry-libm.lib $(TOOLCHAIN_LIBS) c
93+
94+
# TODO @sergioamr Change how we link the library to USER_LDFLAGS
95+
# https://gerrit.zephyrproject.org/r/#/c/2048/
96+
97+
BUILD_CONFIG = O="$(OUTPUT)/zephyr" V=$(V) TOOLCHAIN_LIBS="$(LIBS)" LIB_INCLUDE_DIR="$(LIB_INCLUDE_DIR)"
98+
99+
.PHONY: all
100+
all: jerry zephyr
101+
102+
$(EXTERNAL_LIB):
103+
ifdef V
104+
@echo "- JERRY SCRIPT -------------------------------------------------"
105+
endif
106+
mkdir -p $(INTERM)
107+
mkdir -p $(OUTPUT)
108+
cmake -B$(INTERM) -H./ \
109+
-DENABLE_LTO=OFF \
110+
-DENABLE_VALGRIND=OFF \
111+
-DCMAKE_BUILD_TYPE=Release \
112+
-DCMAKE_VERBOSE_MAKEFILE=$(V) \
113+
-DEXTERNAL_CMAKE_C_COMPILER=$(CC) \
114+
-DEXTERNAL_CMAKE_C_COMPILER_ID=GNU \
115+
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=x86 \
116+
-DEXTERNAL_MEM_HEAP_SIZE_KB=$(JERRYHEAP) \
117+
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
118+
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=lakemont \
119+
-DEXTERNAL_LIBC_INTERFACE="$(ZEPHYR_LIBC_INC)" \
120+
-DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_external.cmake \
121+
-DEXTERNAL_BUILD_ENTRY_FILE=./targets/arduino_101/src/jerry-entry.c
122+
123+
make -C $(INTERM) $(TYPE).external$(VARIETY) V=1
124+
cp `cat $(INTERM)/$(TYPE).external$(VARIETY)/list` $(OUTPUT)/.
125+
cp $(EXTERNAL_LIB) $(OUTPUT)/.
126+
127+
$(ZEPHYR_BIN):
128+
ifdef V
129+
@echo "- ZEPHYR -------------------------------------------------------"
130+
endif
131+
make -f ./targets/arduino_101/Makefile $(BUILD_CONFIG)
132+
@echo "Finished"
133+
@file $(OUTPUT)/zephyr/zephyr.strip
134+
@size $(OUTPUT)/zephyr/zephyr.strip
135+
136+
jerry: $(EXTERNAL_LIB)
137+
@touch $(EXTERNAL_LIB)
138+
139+
zephyr: $(EXTERNAL_LIB) $(ZEPHYR_BIN)
140+
@touch $(ZEPHYR_BIN)
141+
142+
qemu: $(EXTERNAL_LIB) $(ZEPHYR_BIN)
143+
make -f ./targets/arduino_101/Makefile $(BUILD_CONFIG) qemu
144+
145+
flash: $(EXTERNAL_LIB) $(OUTPUT)/zephyr/zephyr.strip
146+
make -f ./targets/arduino_101/Makefile $(BUILD_CONFIG) flash
147+
148+
usage:
149+
help:
150+
@echo Usage:
151+
@echo showconfig Show parameters and configuration
152+
@echo flash Flash into board
153+
@echo all Compile jerryscript and zephyr
154+
155+
showconfig:
156+
@echo "- CONFIGURATION ------------------------------------------------"
157+
@echo "INTERM = $(INTERM)"
158+
@echo "OUTPUT = $(OUTPUT)"
159+
@echo "CC = $(CC) "
160+
@echo "BOARD = $(ZEPHYR_BASE)/boards/$(BOARD)/Makefile.board "
161+
@echo "TOOLCHAIN = $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT) "
162+
@echo "TOOLCHAIN_CFLAGS = $(TOOLCHAIN_CFLAGS) "
163+
@echo "CROSS_COMPILE = $(CROSS_COMPILE) "
164+
@echo "TOOLCHAIN_LIBS = $(TOOLCHAIN_LIBS) "
165+
@echo "LIBS = $(LIBS) "
166+
@echo "LIB_INCLUDE_DIR = $(LIB_INCLUDE_DIR) "
167+
@echo "BUILD_CONFIG = $(BUILD_CONFIG) "
168+
make -f ./targets/arduino_101/Makefile $(BUILD_CONFIG) showconfig
169+
170+
# TODO @sergioamr Temporal cleanup before finding why Zephyr is ignoring my
171+
# outdir for the project
172+
clean:
173+
@echo "Clearing Jerryscript"
174+
@rm -rf $(OUTPUT)
175+
@rm -rf $(INTERM)
176+
@rm -f ./targets/arduino_101/src/.*.o.cmd
177+
@rm -f ./targets/arduino_101/src/*.o
178+
@echo "Clearing Zephyr"
179+
make -f ./targets/arduino_101/Makefile clean
180+
make -f ./targets/arduino_101/Makefile pristine
181+
182+
mrproper:
183+
make -f ./targets/arduino_101/Makefile mrproper

targets/arduino_101/README.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
### About
2+
3+
This folder contains files to run JerryScript on Zephyr with
4+
[Arduino 101 / Genuino 101](https://www.arduino.cc/en/Main/ArduinoBoard101)
5+
6+
Zephyr project arduino 101
7+
[Zephyr Arduino 101](https://www.zephyrproject.org/doc/board/arduino_101.html)
8+
9+
### How to build
10+
11+
#### 1. Preface
12+
13+
1, Directory structure
14+
15+
Assume `harmony` as the path to the projects to build.
16+
The folder tree related would look like this.
17+
18+
```
19+
harmony
20+
+ jerry
21+
| + targets
22+
| + arduino_101
23+
+ zephyr
24+
```
25+
26+
27+
2, Target board
28+
29+
Assume [Arduino 101 / Genuino 101](https://www.arduino.cc/en/Main/ArduinoBoard101)
30+
as the target board.
31+
32+
33+
#### 2. Prepare Zephyr
34+
35+
Follow [this](https://www.zephyrproject.org/doc/getting_started/getting_started.html) page to get
36+
the Zephyr source and configure the environment.
37+
38+
Follow "Building a Sample Application" and check that you can flash the Arduino 101
39+
40+
Remember to source the zephyr environment.
41+
42+
```
43+
source zephyr-env.sh
44+
45+
export ZEPHYR_GCC_VARIANT=zephyr
46+
47+
export ZEPHYR_SDK_INSTALL_DIR=<sdk installation directory>
48+
```
49+
50+
#### 3. Build JerryScript for Zephyr
51+
52+
```
53+
# assume you are in harmony folder
54+
cd jerry
55+
make -f ./targets/arduino_101/Makefile.arduino_101
56+
```
57+
58+
This will generate the following libraries:
59+
```
60+
./build/arduino_101/librelease-cp_minimal.jerry-core.a
61+
./build/arduino_101/librelease-cp_minimal.jerry-libm.lib.a
62+
./build/arduino_101/librelease.external-cp_minimal-entry.a
63+
```
64+
65+
The final Zephyr image will be located here:
66+
```
67+
./build/arduino_101/zephyr/zephyr.strip
68+
```
69+
70+
#### 5. Flashing
71+
72+
Details on how to flash the image can be found here:
73+
[Flashing image](https://www.zephyrproject.org/doc/board/arduino_101.html)
74+
75+
To be able to use this demo in hardware you will need the serial console
76+
which will be generating output to Pins 0 & 1
77+
78+
Some examples of building the software
79+
80+
```
81+
make -f ./targets/arduino_101/Makefile.arduino_101 clean
82+
```
83+
84+
- Not using a Jtag and having a factory stock Arduino 101.
85+
86+
```
87+
make -f ./targets/arduino_101/Makefile.arduino_101 BOARD=arduino_101_factory
88+
```
89+
90+
Follow the Zephyr instructions to flash using the dfu-util command.
91+
92+
93+
- Using JTAG
94+
95+
There is a helper function to flash using the JTAG and Flywatter2
96+
97+
![alt tag](docs/arduino_101.jpg?raw=true "Example")
98+
```
99+
make -f ./targets/arduino_101/Makefile.arduino_101 BOARD=arduino_101 flash
100+
101+
```
102+
103+
- Compiling and running with the emulator
104+
```
105+
make -f ./targets/arduino_101/Makefile.arduino_101 BOARD=qemu_x86 qemu
106+
```
107+
108+
109+
#### 6. Serial terminal
110+
111+
Test command line in a serial terminal.
112+
113+
114+
You should see something similar to this:
115+
```
116+
Jerry Compilation May 26 2016 13:37:50
117+
js>
118+
```
119+
120+
121+
Run the example javascript command test function
122+
```
123+
js> test
124+
Script [var test=0; for (t=100; t<1000; t++) test+=t; print ('Hi JS World! '+test);]
125+
Hi JS World! 494550
126+
```
127+
128+
129+
Try more complex functions:
130+
```
131+
js>function hello(t){t=t*10;return t}; print("result"+hello(10.5));
132+
```
133+
134+
135+
Help will provide a list of commands
136+
```
137+
> help
138+
```
139+
140+
This program, is built in top of the Zephyr command line, so there is a limit of 10 spaces.
21.6 KB
Loading

targets/arduino_101/prj.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CONFIG_STDOUT_CONSOLE=y
2+
CONFIG_NEWLIB_LIBC=y
3+
CONFIG_FLOAT=y
4+
CONFIG_CONSOLE_HANDLER=y
5+
CONFIG_CONSOLE_HANDLER_SHELL=y
6+
7+

targets/arduino_101/prj.mdef

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
% Application : JerryScript Sample
2+
3+
% TASK NAME PRIO ENTRY STACK GROUPS
4+
% ==================================
5+
TASK TASKA 7 main 2048 [EXE]

0 commit comments

Comments
 (0)