Files
jerryscript/targets/mbed
Akos Kiss d38ab71140 Improve the linking of libraries (#1338)
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
2016-09-15 13:07:01 +02:00
..
2016-05-06 13:33:26 +02:00
2016-05-06 13:33:26 +02:00

This folder contains files to run JerryScript in mbed / for:

  • Freedom-K64F (k64)
  • Discovery-STM32F4 (stm32f4)
  • Discovery-STM32F429ZI (stm32f429i)
  • Nucleo-F401RE (nucleo)

####Yotta You need to install yotta before proceeding. Please visit Yotta docs page.

####Cross-compiler For cross-compilation the GCC 5.2.1 is suggested to be used. All the supported targets were tested with this version. If you don't have any GCC compiler installed, please visit this page to download GCC 5.2.1.

####How to build a target Navigate to your JerryScript root folder (after you cloned this repository into the targets folder) and use the following command:

make -f targets/mbed/Makefile.mbed board=$(TARGET)

Where the $(TARGET) is one of the following options: k64f, stm32f4, stm32f429i or nucleo. This command will create a new folder for your target and build the jerryscript and mbed OS into that folder.

####How to build a completely new target If you want to build a new target (which is not available in this folder) you have to modify the makefile. You have to add the new board name to the TARGET_LIST and you have to add a new branch with the new YOTTA_TARGET and a new TARGET_DIR path (if it neccessary) to the if at the top in the Makefile (just as you see right now). There is a little code snippet:

ifeq ($(TARGET), k64f)
  YOTTA_TARGET  = frdm-k64f-gcc
  TARGET_DIR   ?= /media/$(USER)/MBED
else ifeq ($(TARGET), stm32f4)
  YOTTA_TARGET  = 

Basically, you can create a new target in this way (If the mbed OS support your board).

#####Let's get into the details!

  1. The next rule is the jerry rule. This rule builds the JerryScript and copy the output files into the target libjerry folder. Two files will be generated at targets/mbed/libjerry:
  • libjerrycore.a
  • libfdlibm.a

You can run this rule with the following command:

  • make -f targets/mbed/Makefile.mbed board=$(TARGET) jerry
  1. The next rule is the js2c. This rule calls a js2c.py python script from the jerryscript/targets/tools and creates the JavaScript builtin file into the targets/mbed/source/ folder. This file is the jerry_targetjs.h. You can run this rule with the follwoing command:
  • make -f targets/mbed/Makefile.mbed board=$(TARGET) js2c
  1. The last rule is the yotta. This rule sets the yotta target and install the mbed-drivers module, install the dependencies for the mbed OS and finaly creates the mbed binary file. The binary file will be genrated at targets/mbed/build/$(YOTTA_TARGET)/source/jerry.bin. You can run this rule with the following command:
  • make -f targets/mbed/Makefile.mbed board=$(TARGET) yotta
  1. Optional rule: clean. It removes the build folder from the mbed and jerry. You can run this rule with this command:
  • make -f targets/mbed/Makefile.mbed board=$(TARGET) clean

#####Flashing When the build is finished you can flash the binary into your board if you want. In case of ST boards you have to install the st-link software. Please visit this page to install STLink-v2. You can flash your binary into your board with the following command:

make -f targets/mbed/Makefile.mbed board=$(TARGET) flash

The flash rule grabs the binary and copies it to the mounted board or use the STLink-v2 to flash. When the status LED of the board stops blinking, press RESET button on the board to execute JerryScript led flashing sample program in js folder.

###Note If you use an STM32F4 board your build will stop with missing header errors. To fix this error please visit to this page and read about the fix in the New target for STM32F4 block.