diff --git a/targets/zephyr/CMakeLists.txt b/targets/zephyr/CMakeLists.txt new file mode 100644 index 0000000000..d970e9625a --- /dev/null +++ b/targets/zephyr/CMakeLists.txt @@ -0,0 +1,47 @@ +# 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($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(NONE) + +target_sources(app PRIVATE src/main-zephyr.c src/jerry-port.c src/getline-zephyr.c) + +add_library(jerry-core STATIC IMPORTED) +add_library(jerry-ext STATIC IMPORTED) +set_target_properties(jerry-core PROPERTIES IMPORTED_LOCATION + ${CMAKE_CURRENT_BINARY_DIR}/../obj/lib/libjerry-core.a) +set_target_properties(jerry-core PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR}/../../jerry-core/include) +set_target_properties(jerry-ext PROPERTIES IMPORTED_LOCATION + ${CMAKE_CURRENT_BINARY_DIR}/../obj/lib/libjerry-ext.a) +set_target_properties(jerry-ext PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR}/../../jerry-ext/include) +target_link_libraries(app jerry-core jerry-ext) + +zephyr_get_include_directories_for_lang_as_string(C includes) +zephyr_get_system_include_directories_for_lang_as_string(C system_includes) +zephyr_get_compile_definitions_for_lang_as_string(C definitions) +zephyr_get_compile_options_for_lang_as_string(C options) + +add_custom_target( + outputexports + COMMAND echo CC="${CMAKE_C_COMPILER}" + COMMAND echo Z_CFLAGS=${system_includes} ${includes} ${definitions} ${options} + COMMAND echo NOSTDINC_FLAGS=${system_includes} + COMMAND echo ZEPHYRINCLUDE=${includes} + COMMAND echo KBUILD_CFLAGS=${definitions}${options} + VERBATIM + USES_TERMINAL +) + diff --git a/targets/zephyr/Makefile b/targets/zephyr/Makefile deleted file mode 100644 index f053626a30..0000000000 --- a/targets/zephyr/Makefile +++ /dev/null @@ -1,62 +0,0 @@ -# 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. - -# use TAB-8 -.DEFAULT_GOAL := all - -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) -TYPE ?= release -JERRYHEAP ?= 16 - -ZEPHYRINC = $(ZEPHYR_BASE)/include -ZEPHYRLIB = $(ZEPHYR_BASE)/lib - -TARGET_ZEPHYR ?= ./targets/zephyr -SOURCE_DIR = $(TARGET_ZEPHYR)/src - -export JERRY_INCLUDE = -I$(CURDIR)/jerry-core/include -I$(CURDIR)/jerry-ext/include - -MDEF_FILE = $(realpath $(SOURCE_DIR)/../prj.mdef) -CONF_FILE = $(realpath $(SOURCE_DIR)/../prj.conf) - -ifdef V -$(info Zephyr) -$(info SOURCE_DIR=$(SOURCE_DIR)) -$(info JERRY_INCLUDE=$(JERRY_INCLUDE)) -$(info CONF_FILE =$(CONF_FILE)) -endif - -KERNEL_TYPE = micro - -KBUILD_VERBOSE = $(V) - -APP = main-zephyr.c - -ALL_LIBS += $(USER_LIBS) -export ALL_LIBS -LDFLAGS_zephyr += $(USER_LIB_INCLUDE_DIR) -export LDFLAGS_zephyr - -include ${ZEPHYR_BASE}/Makefile.inc - -.PHONY = showconfig diff --git a/targets/zephyr/Makefile.travis b/targets/zephyr/Makefile.travis index 6685ce1e5f..5c195e4070 100644 --- a/targets/zephyr/Makefile.travis +++ b/targets/zephyr/Makefile.travis @@ -27,12 +27,15 @@ install-apt-get-deps: # Install Zephyr SDK. install-zephyr-sdk: - wget https://github.com/zephyrproject-rtos/meta-zephyr-sdk/releases/download/0.9.1/zephyr-sdk-0.9.1-setup.run -O ../zephyr-sdk-0.9.1-setup.run - sh ../zephyr-sdk-0.9.1-setup.run -- -y -d $(CURDIR)/../zephyr-sdk-0.9.1 + wget https://github.com/zephyrproject-rtos/meta-zephyr-sdk/releases/download/0.9.2/zephyr-sdk-0.9.2-setup.run -O ../zephyr-sdk-0.9.2-setup.run + sh ../zephyr-sdk-0.9.2-setup.run -- -y -d $(CURDIR)/../zephyr-sdk-0.9.2 + wget https://cmake.org/files/v3.8/cmake-3.8.2-Linux-x86_64.sh + sudo sh cmake-3.8.2-Linux-x86_64.sh --prefix=/usr/local --exclude-subdir + cmake --version # Fetch Zephyr Project repository and install python dependencies. install-zephyr: install-apt-get-deps - git clone https://github.com/zephyrproject-rtos/zephyr.git ../zephyr -b zephyr-v1.9.1 + git clone https://github.com/zephyrproject-rtos/zephyr.git ../zephyr -b v1.10.0 pip3 install --user -r ../zephyr/scripts/requirements.txt # Perform all the necessary (JerryScript-independent) installation steps. @@ -45,7 +48,6 @@ install: install-zephyr-sdk install-zephyr SHELL=bash script: export ZEPHYR_GCC_VARIANT=zephyr && \ - export ZEPHYR_SDK_INSTALL_DIR=$(CURDIR)/../zephyr-sdk-0.9.1 && \ + export ZEPHYR_SDK_INSTALL_DIR=$(CURDIR)/../zephyr-sdk-0.9.2 && \ source ../zephyr/zephyr-env.sh && \ - CC=$(CURDIR)/../zephyr-sdk-0.9.1/sysroots/x86_64-pokysdk-linux/usr/bin/i586-zephyr-elfiamcu/i586-zephyr-elfiamcu-gcc \ $(MAKE) -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101 diff --git a/targets/zephyr/Makefile.zephyr b/targets/zephyr/Makefile.zephyr index 54b1681ac5..01f5b6f829 100644 --- a/targets/zephyr/Makefile.zephyr +++ b/targets/zephyr/Makefile.zephyr @@ -18,7 +18,8 @@ ifeq ($(.DEFAULT_GOAL),) $(warning no default goal is set) endif -BOARD ?= arduino_101 +BOARD ?= qemu_x86 +CONF_FILE = prj.conf export BOARD TARGET_ZEPHYR ?= ./targets/zephyr @@ -41,7 +42,7 @@ ifndef ZEPHYR_BASE $(error Missing Zephyr base, did you source zephyr-env.sh? ) endif -INTERM = build/$(BOARD)/obj-$(BOARD) +INTERM = build/$(BOARD)/obj OUTPUT = build/$(BOARD)/zephyr include $(OUTPUT)/Makefile.export @@ -94,25 +95,24 @@ endif make -C $(INTERM) $(COMPONENTS) V=1 -$(OUTPUT)/Makefile.export: $(OUTPUT)/include/config/auto.conf - make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) outputexports +$(OUTPUT)/Makefile.export: $(OUTPUT)/Makefile + make --no-print-directory -C $(OUTPUT) outputexports CMAKE_COMMAND=: >$@ -$(OUTPUT)/include/config/auto.conf: - make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) initconfig +$(OUTPUT)/Makefile: + mkdir -p $(OUTPUT) && cmake -DBOARD=$(BOARD) -DCONF_FILE=$(CONF_FILE) -B$(OUTPUT) -Htargets/zephyr/ zephyr: jerry ifdef V @echo "- ZEPHYR -------------------------------------------------------" endif - +make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) + +make -C $(OUTPUT) @echo "Finished" - @file $(OUTPUT)/zephyr.strip - @size $(OUTPUT)/zephyr.strip + @size $(OUTPUT)/zephyr/zephyr.elf jerry: $(EXTERNAL_LIB) @touch $(EXTERNAL_LIB) -GENERIC_TARGETS = qemu qemugdb flash debug debugserver +GENERIC_TARGETS = run qemugdb flash debug debugserver KCONFIG_TARGETS = \ initconfig config nconfig menuconfig xconfig gconfig \ oldconfig silentoldconfig defconfig savedefconfig \ @@ -127,7 +127,7 @@ $(GENERIC_TARGETS) $(KCONFIG_TARGETS) $(CLEAN_TARGETS): ifdef V @echo "- ZEPHYR -------------------------------------------------------" endif - make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) $@ + make -C $(OUTPUT) $@ dfu-x86: all @- dfu-util -a x86_app -D build/$(BOARD)/zephyr/zephyr.bin; \ diff --git a/targets/zephyr/README.md b/targets/zephyr/README.md index 4f91ec91ae..8fed077d09 100644 --- a/targets/zephyr/README.md +++ b/targets/zephyr/README.md @@ -55,13 +55,13 @@ 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 +make -f ./targets/zephyr/Makefile.zephyr BOARD=qemu_x86 run ``` For ARM (Cortex-M) architecture: ``` -make -f ./targets/zephyr/Makefile.zephyr BOARD=qemu_cortex_m3 qemu +make -f ./targets/zephyr/Makefile.zephyr BOARD=qemu_cortex_m3 run ``` #### 4. Build for Arduino 101 diff --git a/targets/zephyr/prj.conf b/targets/zephyr/prj.conf index 29c933f09b..09f46d8da4 100644 --- a/targets/zephyr/prj.conf +++ b/targets/zephyr/prj.conf @@ -1,6 +1,8 @@ +CONFIG_BUILD_OUTPUT_BIN=y CONFIG_STDOUT_CONSOLE=y CONFIG_NEWLIB_LIBC=y CONFIG_FLOAT=y +CONFIG_MAIN_STACK_SIZE=2048 CONFIG_CONSOLE_HANDLER=y CONFIG_CONSOLE_HANDLER_SHELL=y CONFIG_ARC_INIT=n diff --git a/targets/zephyr/prj.mdef b/targets/zephyr/prj.mdef deleted file mode 100644 index c64ca80243..0000000000 --- a/targets/zephyr/prj.mdef +++ /dev/null @@ -1,5 +0,0 @@ -% Application : JerryScript Sample - -% TASK NAME PRIO ENTRY STACK GROUPS -% ================================== - TASK TASKA 7 main 2048 [EXE]