Update the nuttx-stm32f4 target

Related issue: #1202

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
This commit is contained in:
Zsolt Borbély
2016-08-26 07:45:52 +02:00
parent e93e32635f
commit 1e82ae1eb5
6 changed files with 267 additions and 245 deletions
+34
View File
@@ -0,0 +1,34 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config JERRYSCRIPT
bool "Jerryscript"
default n
---help---
Enable Jerryscript ECMAScript 5.1 interpreter
if JERRYSCRIPT
config JERRYSCRIPT_PROGNAME
string "Program name"
default "jerry"
depends on BUILD_KERNEL
---help---
This is the name of the program that will be
use when the NSH ELF program is installed.
config JERRYSCRIPT_PRIORITY
int "Jerryscript task priority"
default 100
config JERRYSCRIPT_STACKSIZE
int "Jerryscript stack size"
default 16384
config JERRYSCRIPT_HEAPSIZE
int "Jerryscript heap size"
default 107520
endif
+18
View File
@@ -0,0 +1,18 @@
# Copyright 2016 Samsung Electronics Co., Ltd.
# Copyright 2016 University of Szeged
#
# 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.
ifeq ($(CONFIG_JERRYSCRIPT),y)
CONFIGURED_APPS += interpreters/jerryscript
endif
+46
View File
@@ -0,0 +1,46 @@
# Copyright 2016 Samsung Electronics Co., Ltd.
# Copyright 2016 University of Szeged
#
# 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 $(TOPDIR)/Make.defs
# Jerryscript built-in application info
CONFIG_JERRYSCRIPT_PRIORITY ?= SCHED_PRIORITY_DEFAULT
CONFIG_JERRYSCRIPT_STACKSIZE ?= 16384
CONFIG_JERRYSCRIPT_HEAPSIZE ?= 107520
APPNAME = jerry
# path to the project dir, "jerry-nuttx" by default
ROOT_DIR = ../../..
PRIORITY = $(CONFIG_JERRYSCRIPT_PRIORITY)
STACKSIZE = $(CONFIG_JERRYSCRIPT_STACKSIZE)
CFLAGS += -std=c99 -DJERRY_NDEBUG '-DCONFIG_MEM_HEAP_AREA_SIZE=$(CONFIG_JERRYSCRIPT_HEAPSIZE)'
CFLAGS += -I$(ROOT_DIR)/ $(shell find $(ROOT_DIR)/jerryscript/jerry-core -type d | sed -r -e 's/^/-I/g')
# Jerryscript
.PHONY: jerry_core_allin.c
jerry_core_allin.c:
echo '#include "jerryscript/jerry-libm/nextafter.c"' > jerry_core_allin.c
find $(ROOT_DIR)/jerryscript/jerry-core -name "*.c" | sed -r -e 's/(\.\.\/)*(.+)/#include "\2"/g' >> jerry_core_allin.c
ASRCS =
CSRCS = jerry_core_allin.c
MAINSRC = jerry_main.c
CONFIG_JERRYSCRIPT_PROGNAME ?= jerry$(EXEEXT)
PROGNAME = $(CONFIG_JERRYSCRIPT_PROGNAME)
include $(APPDIR)/Application.mk
-68
View File
@@ -1,68 +0,0 @@
# Copyright 2016 Samsung Electronics Co., Ltd.
#
# 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
CURDIR = `pwd`
NUTTX ?= $(CURDIR)/../nuttx/nuttx
TYPE ?= release
JERRYHEAP ?= 64
STFLASH ?= ../../stlink/st-flash
NUTTXINC = $(NUTTX)/include
NUTTXLIB = $(NUTTX)/lib
INTERM = build/obj-nuttx-stm32f4
OUTPUT = build/bin/$(TYPE).nuttx-stm32f4
COPYTARGET = $(NUTTXLIB)
EXT_CFLAGS := -mlittle-endian -mthumb -mcpu=cortex-m4 -march=armv7e-m
EXT_CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Wno-conversion
.PHONY: nutx flash clean
all:
mkdir -p $(INTERM)
mkdir -p $(OUTPUT)
cmake -B$(INTERM) -H./ \
-DENABLE_LTO=OFF \
-DENABLE_VALGRIND=OFF \
-DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_external.cmake \
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=armv7l \
-DEXTERNAL_CMAKE_C_COMPILER=arm-none-eabi-gcc \
-DEXTERNAL_CMAKE_C_COMPILER_ID=GNU \
-DEXTERNAL_BUILD_ENTRY_FILE=./targets/nuttx-stm32f4/main-nuttx.c \
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
-DEXTERNAL_LIBC_INTERFACE=$(NUTTXINC) \
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=arm \
-DEXTERNAL_MEM_HEAP_SIZE_KB=$(JERRYHEAP)
make -C $(INTERM) $(TYPE).external
cp `cat $(INTERM)/$(TYPE).external/list` $(OUTPUT)/.
cp $(OUTPUT)/lib$(TYPE).jerry-core.a $(COPYTARGET)/libjerrycore.a
cp $(OUTPUT)/lib$(TYPE).jerry-libm.lib.a $(COPYTARGET)/libjerrylibm.a
cp $(INTERM)/lib$(TYPE).external-entry.a $(OUTPUT)/.
cp $(OUTPUT)/lib$(TYPE).external-entry.a $(COPYTARGET)/libjerryentry.a
nuttx:
cd $(NUTTX); make
flash:
cd $(NUTTX); $(STFLASH) write nuttx.bin 0x8000000
clean:
rm -rf $(INTERM)
rm -rf $(OUTPUT)
+54 -117
View File
@@ -1,143 +1,91 @@
### About ### About
This folder contains files to run JerryScript on NuttX with This folder contains files to run JerryScript on
[STM32F4-Discovery with BB](http://www.st.com/web/en/catalog/tools/FM116/SC959/SS1532/LN1199/PF255417) [STM32F4-Discovery board](http://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-eval-tools/stm32-mcu-eval-tools/stm32-mcu-discovery-kits/stm32f4discovery.html) with [NuttX](http://nuttx.org/)
### How to build ### How to build
#### 1. Preface #### 1. Setting up the build environment for STM32F4-Discovery board
1, Directory structure Clone JerryScript and NuttX into jerry-nuttx directory
Assume `harmony` as the root folder to the projects to build.
The folder tree related would look like this.
``` ```
harmony mkdir jerry-nuttx
cd jerry-nuttx
git clone https://github.com/Samsung/jerryscript.git
git clone https://bitbucket.org/nuttx/nuttx.git
git clone https://bitbucket.org/nuttx/apps.git
git clone https://github.com/texane/stlink.git
```
The following directory structure is created after these commands
```
jerry-nuttx
+ apps
+ jerryscript + jerryscript
| + targets | + targets
| + nuttx-stm32f4 | + nuttx-stm32f4
+ nuttx + nuttx
| + nuttx + stlink
| + lib
+ st-link
``` ```
#### 2. Adding JerryScript as an interpreter for NuttX
2, Target board
Assume [STM32F4-Discovery with BB](http://www.st.com/web/en/catalog/tools/FM116/SC959/SS1532/LN1199/PF255417)
as the target board.
3, Micro SD-Card memory for Script source files
#### 2. Prepare NuttX
Follow [this](https://bitbucket.org/seanshpark/nuttx/wiki/Home) page to get
NuttX source and do the first build. When it stops with and error,
change default project from `IoT.js` to `JerryScript` as follows;
2-1) run menuconfig
``` ```
# assume you are in nuttx folder where .config exist cd apps/interpreters
mkdir jerryscript
cp ../../jerryscript/targets/nuttx-stm32f4/* ./jerryscript/
```
#### 3. Configure NuttX
```
# assuming you are in jerry-nuttx folder
cd nuttx/tools
# configure NuttX USB console shell
./configure.sh stm32f4discovery/usbnsh
cd ..
# might require to run "make menuconfig" twice
make menuconfig make menuconfig
``` ```
2-2) Select `Application Configuration` --> `Interpreters`
2-3) Check `[*] JerryScript interpreter` (Move cursor to the line and press `Space`) Change "Build Setup" -> "Build Host Platform" from "Windows" to "Linux"
Enable "System Type" -> "FPU support"
Enable "Library Routines" -> "Standard Math library"
Enable "Application Configuration" -> "Interpreters->JerryScript"
2-4) `< Exit >` once on the bottom of the sceen (Press `Right arrow` and `Enter`) #### 4. Build JerryScript for NuttX
2-5) Select `System Libraries and NSH Add-Ons`
2-6) Un-Check `[ ] iotjs program` (Move cursor to the line and press `Space`)
2-7) `< Exit >` till `menuconfig` ends. Save new configugation when asked.
2-7) `make` again
``` ```
# assuming you are in jerry-nuttx folder
cd nuttx/
make make
``` ```
It'll show the last error but it's ok. Nows the time to build JerryScript.
#### 3. Build JerryScript for NuttX
```
# assume you are in harmony folder
cd jerryscript
make -f ./targets/nuttx-stm32f4/Makefile.nuttx
```
If you have NuttX at another path than described above, you can give the
absolute path with `NUTTX` variable , for example,
```
NUTTX=/home/user/work/nuttx make -f ./targets/nuttx-stm32f4/Makefile.nuttx
```
Make will copy three library files to `nuttx/nuttx/lib` folder
```
libjerryentry.a
libjerrycore.a
libjerrylibm.a
```
In NuttX, if you run `make clean`, above library files are also removed so you
may have to build JerryScript again.
#### 4. Continue build NuttX
```
# asssume you are in harmony folder
cd nuttx/nuttx
make
```
#### 5. Flashing #### 5. Flashing
Connect Mini-USB for power supply and connect Micro-USB for `NSH` console. Connect Mini-USB for power supply and connect Micro-USB for `NSH` console.
Please refer [this](https://github.com/Samsung/iotjs/wiki/Build-for-NuttX#prepare-flashing-to-target-board) To configure `stlink` utility for flashing, follow the instructions [here](https://github.com/texane/stlink#build-from-sources).
link to prepare `stlink` utility.
To flash,
To flash with `Makefile.nuttx`,
``` ```
# assume you are in jerryscript folder # assuming you are in nuttx folder
make -f ./targets/nuttx-stm32f4/Makefile.nuttx flash sudo ../stlink/build/st-flash write nuttx.bin 0x8000000
``` ```
#### 6. Cleaning
To clean the build result,
```
make -f ./targets/nuttx-stm32f4/Makefile.nuttx clean
```
### Running JerryScript ### Running JerryScript
Prepare a micro SD-card and prepare `hello.js` like this in the root directory of SD-card. You can use `minicom` for terminal program, or any other you may like, but set
```
print("Hello JerryScript!");
```
Power Off(unplug both USB cables), plug the memory card to BB, and power on again.
You can use `minicom` for terminal program, or any other you may like, but match
baud rate to `115200`. baud rate to `115200`.
``` ```
minicom --device=/dev/ttyACM0 --baud=115200 sudo minicom --device=/dev/ttyACM0 --baud=115200
``` ```
You may have to press `RESET` on the board and press `Enter` keys on the console You may have to press `RESET` on the board and press `Enter` keys on the console
several times to make `nsh` prompt to appear. several times to make `nsh` prompt to appear.
@@ -152,27 +100,16 @@ please set `Add Carriage Ret` option by `CTRL-A` > `Z` > `U` at the console,
if you're using `minicom`. if you're using `minicom`.
Run `jerryscript` with `hello.js` Run `jerry` with javascript file(s)
``` ```
NuttShell (NSH) NuttShell (NSH)
nsh> nsh> jerry full_path/any.js
nsh>
nsh> jerryscript /mnt/sdcard/hello.js
PARAM 1 : [/mnt/sdcard/hello.js]
Hello JerryScript!
``` ```
Please give absolute path of the script file or may get an error like this. Without argument it prints:
``` ```
nsh> cd /mnt/sdcard nsh> jerry
nsh> jerryscript ./hello.js No input files, running a hello world demo:
PARAM 1 : [./hello.js] Hello world 5 times from JerryScript
Failed to fopen [./hello.js]
JERRY_STANDALONE_EXIT_CODE_FAIL
nsh>
nsh>
nsh> jerryscript /mnt/sdcard/hello.js
PARAM 1 : [/mnt/sdcard/hello.js]
Hello JerryScript!
``` ```
@@ -17,30 +17,31 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <setjmp.h>
#include "jerry.h" #include "jerry-api.h"
#include "jerry-port.h" #include "jerry-port.h"
#include "jerry-port-default.h"
/** /**
* The module interface routine * Maximum command line arguments number.
*/
extern "C" int jerryscript_entry (int argc, char *argv[]);
/**
* Maximum command line arguments number
*/ */
#define JERRY_MAX_COMMAND_LINE_ARGS (16) #define JERRY_MAX_COMMAND_LINE_ARGS (16)
/** /**
* Standalone Jerry exit codes * Standalone Jerry exit codes.
*/ */
#define JERRY_STANDALONE_EXIT_CODE_OK (0) #define JERRY_STANDALONE_EXIT_CODE_OK (0)
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1) #define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
static char* read_sources (const char *script_file_names[], /**
int files_count, * Read source files.
size_t *out_source_size_p) *
* @return concatenated source files
*/
static char*
read_sources (const char *script_file_names[],
int files_count,
size_t *out_source_size_p)
{ {
int i; int i;
char* source_buffer = NULL; char* source_buffer = NULL;
@@ -75,7 +76,7 @@ static char* read_sources (const char *script_file_names[],
break; break;
} }
total_length += (size_t)script_len; total_length += (size_t) script_len;
fclose (file); fclose (file);
file = NULL; file = NULL;
@@ -83,17 +84,17 @@ static char* read_sources (const char *script_file_names[],
if (total_length <= 0) if (total_length <= 0)
{ {
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Theres noting to read\n"); jerry_port_log (JERRY_LOG_LEVEL_ERROR, "There's nothing to read\n");
return NULL; return NULL;
} }
source_buffer = (char*)malloc(total_length); source_buffer = (char*) malloc (total_length);
if (source_buffer == NULL) if (source_buffer == NULL)
{ {
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Out of memory error\n"); jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Out of memory error\n");
return NULL; return NULL;
} }
memset(source_buffer, 0, sizeof(char)*total_length); memset (source_buffer, 0, sizeof (char) * total_length);
source_buffer_tail = source_buffer; source_buffer_tail = source_buffer;
for (i = 0; i < files_count; i++) for (i = 0; i < files_count; i++)
@@ -123,7 +124,7 @@ static char* read_sources (const char *script_file_names[],
rewind (file); rewind (file);
const size_t current_source_size = (size_t)script_len; const size_t current_source_size = (size_t) script_len;
size_t bytes_read = fread (source_buffer_tail, 1, current_source_size, file); size_t bytes_read = fread (source_buffer_tail, 1, current_source_size, file);
if (bytes_read < current_source_size) if (bytes_read < current_source_size)
{ {
@@ -145,16 +146,30 @@ static char* read_sources (const char *script_file_names[],
if (i < files_count) if (i < files_count)
{ {
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Failed to read script N%d\n", i + 1); jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Failed to read script N%d\n", i + 1);
free(source_buffer); free (source_buffer);
return NULL; return NULL;
} }
*out_source_size_p = (size_t)total_length; *out_source_size_p = (size_t) total_length;
return source_buffer; return source_buffer;
} } /* read_sources */
int jerryscript_entry (int argc, char *argv[]) /**
* JerryScript debug level (0-3).
*/
static int jerry_debug_level;
/**
* Main program.
*
* @return 0 if success, error code otherwise
*/
#ifdef CONFIG_BUILD_KERNEL
int main (int argc, FAR char *argv[])
#else
int jerry_main (int argc, char *argv[])
#endif
{ {
if (argc >= JERRY_MAX_COMMAND_LINE_ARGS) if (argc >= JERRY_MAX_COMMAND_LINE_ARGS)
{ {
@@ -169,44 +184,24 @@ int jerryscript_entry (int argc, char *argv[])
int i; int i;
int files_counter = 0; int files_counter = 0;
for (i = 1; i < argc; i++) jerry_init_flag_t flags = JERRY_INIT_EMPTY;
{
printf ("PARAM %d : [%s]\n", i, argv[i]);
}
jerry_flag_t flags = JERRY_FLAG_EMPTY;
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
if (!strcmp ("-v", argv[i])) if (!strcmp ("--mem-stats", argv[i]))
{ {
printf ("Build date: \t%s\n", jerry_build_date); flags |= JERRY_INIT_MEM_STATS;
printf ("Commit hash:\t%s\n", jerry_commit_hash);
printf ("Branch name:\t%s\n", jerry_branch_name);
}
else if (!strcmp ("--mem-stats", argv[i]))
{
flags |= JERRY_FLAG_MEM_STATS;
} }
else if (!strcmp ("--mem-stats-separate", argv[i])) else if (!strcmp ("--mem-stats-separate", argv[i]))
{ {
flags |= JERRY_FLAG_MEM_STATS_SEPARATE; flags |= JERRY_INIT_MEM_STATS_SEPARATE;
}
else if (!strcmp ("--parse-only", argv[i]))
{
flags |= JERRY_FLAG_PARSE_ONLY;
} }
else if (!strcmp ("--show-opcodes", argv[i])) else if (!strcmp ("--show-opcodes", argv[i]))
{ {
flags |= JERRY_FLAG_SHOW_OPCODES; flags |= JERRY_INIT_SHOW_OPCODES | JERRY_INIT_SHOW_REGEXP_OPCODES;
}
else if (!strcmp ("--abort-on-fail", argv[i]))
{
jerry_port_default_set_abort_on_fail (true);
} }
else if (!strcmp ("--log-level", argv[i])) else if (!strcmp ("--log-level", argv[i]))
{ {
flags |= JERRY_FLAG_ENABLE_LOG;
if (++i < argc && strlen (argv[i]) == 1 && argv[i][0] >='0' && argv[i][0] <= '3') if (++i < argc && strlen (argv[i]) == 1 && argv[i][0] >='0' && argv[i][0] <= '3')
{ {
jerry_debug_level = argv[i][0] - '0'; jerry_debug_level = argv[i][0] - '0';
@@ -225,8 +220,11 @@ int jerryscript_entry (int argc, char *argv[])
if (files_counter == 0) if (files_counter == 0)
{ {
printf ("Jerry: file count 0\n"); jerry_port_console ("No input files, running a hello world demo:\n");
return JERRY_STANDALONE_EXIT_CODE_OK; char *source_p = "var a = 3.5; print('Hello world ' + (a + 1.5) + ' times from JerryScript')";
jerry_run_simple ((jerry_char_t *) source_p, strlen (source_p), flags);
return 0;
} }
size_t source_size; size_t source_size;
@@ -238,18 +236,24 @@ int jerryscript_entry (int argc, char *argv[])
return JERRY_STANDALONE_EXIT_CODE_FAIL; return JERRY_STANDALONE_EXIT_CODE_FAIL;
} }
jerry_completion_code_t ret_code; bool success = jerry_run_simple ((jerry_char_t *) source_p, source_size, flags);
ret_code = jerry_run_simple ((jerry_api_char_t *) source_p, source_size, flags); free (source_p);
free(source_p); if (!success)
if (ret_code != JERRY_COMPLETION_CODE_OK)
{ {
return JERRY_STANDALONE_EXIT_CODE_FAIL; return JERRY_STANDALONE_EXIT_CODE_FAIL;
} }
return JERRY_STANDALONE_EXIT_CODE_OK; return JERRY_STANDALONE_EXIT_CODE_OK;
} } /* main */
/**
* Aborts the program.
*/
void jerry_port_fatal (jerry_fatal_code_t code)
{
exit (1);
} /* jerry_port_fatal */
/** /**
* Provide console message implementation for the engine. * Provide console message implementation for the engine.
@@ -272,10 +276,61 @@ jerry_port_log (jerry_log_level_t level, /**< log level */
const char *format, /**< format string */ const char *format, /**< format string */
...) /**< parameters */ ...) /**< parameters */
{ {
(void) level; /* ignore the log level */ if (level >= jerry_debug_level)
{
va_list args; va_list args;
va_start (args, format); va_start (args, format);
vfprintf (stderr, format, args); vfprintf (stderr, format, args);
va_end (args); va_end (args);
}
} /* jerry_port_log */ } /* jerry_port_log */
/**
* Dummy function to get the time zone.
*
* @return false
*/
bool
jerry_port_get_time_zone (jerry_time_zone_t *tz_p)
{
tz_p->offset = 0;
tz_p->daylight_saving_time = 0;
return false;
} /* jerry_port_get_time_zone */
/**
* Dummy function to get the current time.
*
* @return 0
*/
double
jerry_port_get_current_time ()
{
return 0;
} /* jerry_port_get_current_time */
/**
* Compiler built-in setjmp function.
*
* @return 0 when called the first time
* 1 when returns from a longjmp call
*/
int
setjmp (jmp_buf buf)
{
return __builtin_setjmp (buf);
} /* setjmp */
/**
* Compiler built-in longjmp function.
*
* Note:
* ignores value argument
*/
void
longjmp (jmp_buf buf, int value)
{
/* Must be called with 1. */
__builtin_longjmp (buf, 1);
} /* longjmp */