Although both jerry-libc and jerry-libm have configuration options that enable/disable their build, in practice, only jerry-libc can be replaced with the system (compiler-default) libc. If jerry-libm is disabled, the build of jerry-main fails, as there is no way to instruct the linker to link the system libm to the binary. (The build system does have a way to pass flags to the linker, but those flags are listed before the linked objects. For the references to get resolved correctly, the libraries to be linked have to be specified _after_ the objects.) This patch adds the EXTERNAL_LINK_LIBS configuration option to CMakeLists, which ensures that the specified libraries get correctly passed to the linker. (E.g, replacing jerry-libm with system libm becomes possible with `JERRY_LIBM=OFF EXTERNAL_LINK_LIBS='-lm'`.) Additionally, the patch also makes the following related changes: * Removes the COMPILER_DEFAULT_LIBC configuration option, as it is (almost) always the opposite of JERRY_LIBC. Moreover, its name is misleading: its only role is to add `-nostdlib` to the linker flags. * Makes use of transitive library dependencies: if a library has another library as dependency, and it is linked to a binary, its dependency is linked as well. Thus, jerry-libc, jerry-libm, and any external libraries are added to jerry-core as dependency, and then only jerry-core is linked to executables (cmake will take care of the rest). * build.py and run-tests.py follow up the changes, along with some minor syntax changes. * Moves static linking option to global CMakeLists, as unit test binaries should be linked the same way as jerry-main. * Adds EXTERNAL_COMPILER_FLAGS and EXTERNAL_LINKER_FLAGS as last to the flag list, to allow user override of (nearly) anything. The patch speculatively follows up the build system changes in the mbed, riot-stm32f4, and zephyr targets. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
About
This folder contains files to integrate JerryScript with Zephyr RTOS to run on a number of supported boards (like Arduino 101 / Genuino 101, Zephyr Arduino 101).
How to build
1. Preface
- Directory structure
Assume harmony as the path to the projects to build.
The folder tree related would look like this.
harmony
+ jerryscript
| + targets
| + zephyr
+ zephyr-project
- Target boards/emulations
Following Zephyr boards were tested: qemu_x86, qemu_cortex_m3, arduino_101, frdm_k64f.
2. Prepare Zephyr
Follow this page to get the Zephyr source and configure the environment.
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 as explained in the zephyr documenation:
cd zephyr-project
source zephyr-env.sh
export ZEPHYR_GCC_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=<sdk installation directory>
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 jerryscript
make -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101_factory
This will generate the following libraries:
./build/arduino_101_factory/librelease-cp_minimal.jerry-core.a
./build/arduino_101_factory/librelease-cp_minimal.jerry-libm.lib.a
./build/arduino_101_factory/librelease.external-cp_minimal-entry.a
The final Zephyr image will be located here:
./build/arduino_101_factory/zephyr/zephyr.strip
5. Flashing
Details on how to flash the image can be found here: Flashing image (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.
You will need a 3.3v TTL to RS232, please follow the zephyr documentation on it.
Some examples of building the software
make -f ./targets/zephyr/Makefile.zephyr BOARD=<board> clean
- Not using a Jtag and having a factory stock Arduino 101. You can follow the Zephyr instructions to flash using the dfu-util command or use this helper:
make -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101_factory dfu-x86
Make sure you have the factory bootloader in your device to use this method or it will not flash.
- Using JTAG
There is a helper function to flash using the JTAG and Flywatter2
make -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101_factory flash
Careful if you flash the BOARD arduino_101, you will lose the bootloader and you will have to follow the zephyr documentation to get it back from the backup we all know you did at the setup.
6. Serial terminal
Test command line in a serial terminal.
You should see something similar to this:
JerryScript build: Aug 12 2016 17:12:55
JerryScript API 1.0
Zephyr version 1.4.0
js>
Run the example javascript command test function
js> var test=0; for (t=100; t<1000; t++) test+=t; print ('Hi JS World! '+test);
Hi JS World! 494550
Try a more complex function:
js> function hello(t) {t=t*10;return t}; print("result"+hello(10.5));
