From 40914440166b6a2fa7dc7356db2488aeed51f49e Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 17 Jun 2016 02:14:30 +0300 Subject: [PATCH] targets/zephyr: Rename from arduino_101, with more targets supported. - Add preliminary support for ARC architecture. Using "em_starterkit" board supported by Zephyr. Only build for this board is tested, not booted on a real device due to lack of access. There's no QEMU emulation support for ARC in Zephyr (yet) either. - Update README to cover different Zephyr architectures/boards. - Changed the arduino_101 paths to something more generic and adaptable - Made sure it compiles and runs on Arduino 101 JerryScript-DCO-1.0-Signed-off-by: Sergio Martinez sergio.martinez.rodriguez@intel.com JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org --- targets/{arduino_101 => zephyr}/Makefile | 7 ++- .../Makefile.zephyr} | 34 +++++----- targets/{arduino_101 => zephyr}/README.md | 59 +++++++++++------- .../docs/arduino_101.jpg | Bin targets/{arduino_101 => zephyr}/prj.conf | 0 targets/{arduino_101 => zephyr}/prj.mdef | 0 targets/{arduino_101 => zephyr}/src/Makefile | 0 .../{arduino_101 => zephyr}/src/jerry-entry.c | 0 .../{arduino_101 => zephyr}/src/main-zephyr.c | 0 9 files changed, 59 insertions(+), 41 deletions(-) rename targets/{arduino_101 => zephyr}/Makefile (95%) mode change 100644 => 100755 rename targets/{arduino_101/Makefile.arduino_101 => zephyr/Makefile.zephyr} (87%) mode change 100644 => 100755 rename targets/{arduino_101 => zephyr}/README.md (66%) rename targets/{arduino_101 => zephyr}/docs/arduino_101.jpg (100%) rename targets/{arduino_101 => zephyr}/prj.conf (100%) rename targets/{arduino_101 => zephyr}/prj.mdef (100%) rename targets/{arduino_101 => zephyr}/src/Makefile (100%) rename targets/{arduino_101 => zephyr}/src/jerry-entry.c (100%) rename targets/{arduino_101 => zephyr}/src/main-zephyr.c (100%) diff --git a/targets/arduino_101/Makefile b/targets/zephyr/Makefile old mode 100644 new mode 100755 similarity index 95% rename from targets/arduino_101/Makefile rename to targets/zephyr/Makefile index d4746afc6..48d6233f1 --- a/targets/arduino_101/Makefile +++ b/targets/zephyr/Makefile @@ -18,10 +18,10 @@ ifndef ZEPHYR_BASE $(error Missing zephyr base) endif - + # For testing without real hardware use qemu_x86 instead of arduino_101 BOARD ?= arduino_101 - + O ?= $(PROJECT_BASE)/outdir ZEPHYR ?= $(ZEPHYR_BASE) @@ -31,7 +31,8 @@ JERRYHEAP ?= 16 ZEPHYRINC = $(ZEPHYR_BASE)/include ZEPHYRLIB = $(ZEPHYR_BASE)/lib -SOURCE_DIR = ./targets/arduino_101/src +TARGET_ZEPHYR ?= ./targets/zephyr +SOURCE_DIR = $(TARGET_ZEPHYR)/src export JERRY_INCLUDE = $(CURDIR)/jerry-core/ diff --git a/targets/arduino_101/Makefile.arduino_101 b/targets/zephyr/Makefile.zephyr old mode 100644 new mode 100755 similarity index 87% rename from targets/arduino_101/Makefile.arduino_101 rename to targets/zephyr/Makefile.zephyr index f3ac05208..55016a470 --- a/targets/arduino_101/Makefile.arduino_101 +++ b/targets/zephyr/Makefile.zephyr @@ -29,6 +29,9 @@ ifeq ($(BOARD),qemu_x86) BOARD_NAME ?= qemu_x86 endif +TARGET_ZEPHYR ?= ./targets/zephyr +SOURCE_DIR = $(TARGET_ZEPHYR)/src + TYPE ?= release JERRYHEAP ?= 16 @@ -68,6 +71,11 @@ else ifeq ($(BOARD),qemu_cortex_m3) CONFIG_TOOLCHAIN_VARIANT = arm CPU = arm7-m EXT_CFLAGS += -march=armv7-m -mthumb -mcpu=cortex-m3 -mabi=aapcs +else ifeq ($(BOARD),em_starterkit) +# TODO: Tested only to build, untested to boot +CONFIG_TOOLCHAIN_VARIANT = arc +CPU = arc +EXT_CFLAGS += -mARCv2EM -mav2em -mno-sdata else CONFIG_TOOLCHAIN_VARIANT = iamcu CPU = lakemont @@ -97,10 +105,7 @@ ZEPHYR_BIN = $(OUTPUT)/zephyr/zephyr.strip PREFIX = $(TYPE)$(VARIETY) LIBS = $(TYPE).external$(VARIETY)-entry $(PREFIX).jerry-core $(PREFIX).jerry-libm.lib -# TODO @sergioamr Change how we link the library to USER_LDFLAGS -# https://gerrit.zephyrproject.org/r/#/c/2048/ - -BUILD_CONFIG = O="$(OUTPUT)/zephyr" V=$(V) USER_LIBS="$(LIBS)" USER_LIB_INCLUDE_DIR="-L $(CURDIR)/$(OUTPUT)" +BUILD_CONFIG = O="$(OUTPUT)/zephyr" V=$(V) USER_LIBS="$(LIBS)" USER_LIB_INCLUDE_DIR="-L $(CURDIR)/$(OUTPUT)" TARGET_ZEPHYR=$(TARGET_ZEPHYR) .PHONY: all all: jerry zephyr @@ -124,7 +129,7 @@ endif -DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=lakemont \ -DEXTERNAL_LIBC_INTERFACE="$(ZEPHYR_LIBC_INC)" \ -DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_external.cmake \ - -DEXTERNAL_BUILD_ENTRY_FILE=./targets/arduino_101/src/jerry-entry.c + -DEXTERNAL_BUILD_ENTRY_FILE=$(SOURCE_DIR)/jerry-entry.c make -C $(INTERM) $(TYPE).external$(VARIETY) V=1 cp `cat $(INTERM)/$(TYPE).external$(VARIETY)/list` $(OUTPUT)/. @@ -134,7 +139,7 @@ $(ZEPHYR_BIN): ifdef V @echo "- ZEPHYR -------------------------------------------------------" endif - make -f ./targets/arduino_101/Makefile $(BUILD_CONFIG) + make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) @echo "Finished" @file $(OUTPUT)/zephyr/zephyr.strip @size $(OUTPUT)/zephyr/zephyr.strip @@ -146,10 +151,10 @@ zephyr: $(EXTERNAL_LIB) $(ZEPHYR_BIN) @touch $(ZEPHYR_BIN) qemu: $(EXTERNAL_LIB) $(ZEPHYR_BIN) - make -f ./targets/arduino_101/Makefile $(BUILD_CONFIG) qemu + make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) qemu flash: $(EXTERNAL_LIB) $(OUTPUT)/zephyr/zephyr.strip - make -f ./targets/arduino_101/Makefile $(BUILD_CONFIG) flash + make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) flash usage: help: @@ -171,7 +176,7 @@ showconfig: @echo "LIBS = $(LIBS) " @echo "LIB_INCLUDE_DIR = $(LIB_INCLUDE_DIR) " @echo "BUILD_CONFIG = $(BUILD_CONFIG) " - make -f ./targets/arduino_101/Makefile $(BUILD_CONFIG) showconfig + make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) showconfig # TODO @sergioamr Temporal cleanup before finding why Zephyr is ignoring my # outdir for the project @@ -179,11 +184,12 @@ clean: @echo "Clearing Jerryscript" @rm -rf $(OUTPUT) @rm -rf $(INTERM) - @rm -f ./targets/arduino_101/src/.*.o.cmd - @rm -f ./targets/arduino_101/src/*.o + @rm -f $(SOURCE_DIR)/.*.o.cmd + @rm -f $(SOURCE_DIR)/*.o @echo "Clearing Zephyr" - make -f ./targets/arduino_101/Makefile clean - make -f ./targets/arduino_101/Makefile pristine + make -f $(TARGET_ZEPHYR)/Makefile clean + make -f $(TARGET_ZEPHYR)/Makefile pristine mrproper: - make -f ./targets/arduino_101/Makefile mrproper + make -f $(TARGET_ZEPHYR)/Makefile mrproper + diff --git a/targets/arduino_101/README.md b/targets/zephyr/README.md similarity index 66% rename from targets/arduino_101/README.md rename to targets/zephyr/README.md index 7f4282993..0de041f65 100644 --- a/targets/arduino_101/README.md +++ b/targets/zephyr/README.md @@ -1,33 +1,31 @@ ### About -This folder contains files to run JerryScript on Zephyr with -[Arduino 101 / Genuino 101](https://www.arduino.cc/en/Main/ArduinoBoard101) - -Zephyr project arduino 101 -[Zephyr Arduino 101](https://www.zephyrproject.org/doc/board/arduino_101.html) +This folder contains files to integrate JerryScript with Zephyr RTOS to +run on a number of supported boards (like +[Arduino 101 / Genuino 101](https://www.arduino.cc/en/Main/ArduinoBoard101), +[Zephyr Arduino 101](https://www.zephyrproject.org/doc/board/arduino_101.html)). ### How to build #### 1. Preface -1, Directory structure +1. Directory structure Assume `harmony` as the path to the projects to build. The folder tree related would look like this. ``` harmony - + jerry + + jerryscript | + targets - | + arduino_101 + | + zephyr + zephyr ``` -2, Target board +2. Target boards/emulations -Assume [Arduino 101 / Genuino 101](https://www.arduino.cc/en/Main/ArduinoBoard101) -as the target board. +Following Zephyr boards were tested: qemu_x86, qemu_cortex_m3, arduino_101. #### 2. Prepare Zephyr @@ -35,9 +33,11 @@ as the target board. Follow [this](https://www.zephyrproject.org/doc/getting_started/getting_started.html) page to get the Zephyr source and configure the environment. -Follow "Building a Sample Application" and check that you can flash the Arduino 101 +If you just start with Zephyr, you may want to follow "Building a Sample +Application" section in the doc above and check that you can flash your +target board. -Remember to source the zephyr environment. +Remember to source the Zephyr environment: ``` source zephyr-env.sh @@ -49,10 +49,26 @@ export ZEPHYR_SDK_INSTALL_DIR= #### 3. Build JerryScript for Zephyr +The easiest way is to build and run on a QEMU emulator: + +For x86 architecture: + +``` +make -f ./targets/zephyr/Makefile.zephyr BOARD=qemu_x86 qemu +``` + +For ARM (Cortex-M) architecture: + +``` +make -f ./targets/zephyr/Makefile.zephyr BOARD=qemu_cortex_m3 qemu +``` + +#### 4. Build for Arduino 101 + ``` # assume you are in harmony folder cd jerry -make -f ./targets/arduino_101/Makefile.arduino_101 +make -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101 ``` This will generate the following libraries: @@ -71,6 +87,7 @@ The final Zephyr image will be located here: Details on how to flash the image can be found here: [Flashing image](https://www.zephyrproject.org/doc/board/arduino_101.html) +(or similar page for other supported boards). To be able to use this demo in hardware you will need the serial console which will be generating output to Pins 0 & 1 @@ -78,13 +95,13 @@ which will be generating output to Pins 0 & 1 Some examples of building the software ``` -make -f ./targets/arduino_101/Makefile.arduino_101 clean +make -f ./targets/zephyr/Makefile.zephyr clean ``` - Not using a Jtag and having a factory stock Arduino 101. ``` -make -f ./targets/arduino_101/Makefile.arduino_101 BOARD=arduino_101_factory +make -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101_factory ``` Follow the Zephyr instructions to flash using the dfu-util command. @@ -96,16 +113,10 @@ There is a helper function to flash using the JTAG and Flywatter2 ![alt tag](docs/arduino_101.jpg?raw=true "Example") ``` -make -f ./targets/arduino_101/Makefile.arduino_101 BOARD=arduino_101 flash +make -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101 flash ``` -- Compiling and running with the emulator -``` -make -f ./targets/arduino_101/Makefile.arduino_101 BOARD=qemu_x86 qemu -``` - - #### 6. Serial terminal Test command line in a serial terminal. @@ -137,4 +148,4 @@ Help will provide a list of commands > help ``` -This program, is built in top of the Zephyr command line, so there is a limit of 10 spaces. \ No newline at end of file +This program, is built in top of the Zephyr command line, so there is a limit of 10 spaces. diff --git a/targets/arduino_101/docs/arduino_101.jpg b/targets/zephyr/docs/arduino_101.jpg similarity index 100% rename from targets/arduino_101/docs/arduino_101.jpg rename to targets/zephyr/docs/arduino_101.jpg diff --git a/targets/arduino_101/prj.conf b/targets/zephyr/prj.conf similarity index 100% rename from targets/arduino_101/prj.conf rename to targets/zephyr/prj.conf diff --git a/targets/arduino_101/prj.mdef b/targets/zephyr/prj.mdef similarity index 100% rename from targets/arduino_101/prj.mdef rename to targets/zephyr/prj.mdef diff --git a/targets/arduino_101/src/Makefile b/targets/zephyr/src/Makefile similarity index 100% rename from targets/arduino_101/src/Makefile rename to targets/zephyr/src/Makefile diff --git a/targets/arduino_101/src/jerry-entry.c b/targets/zephyr/src/jerry-entry.c similarity index 100% rename from targets/arduino_101/src/jerry-entry.c rename to targets/zephyr/src/jerry-entry.c diff --git a/targets/arduino_101/src/main-zephyr.c b/targets/zephyr/src/main-zephyr.c similarity index 100% rename from targets/arduino_101/src/main-zephyr.c rename to targets/zephyr/src/main-zephyr.c