Skip to content

Commit eadc6f7

Browse files
author
Roland Takacs
committed
Modify the build method of NuttX target.
Modified the Makefile of the NuttX target to build only the application file (targets/nuttx-stm32f4/jerry-main.c) and not the whole project. It helps to build JerryScript separately and use the static libs when building NuttX. Also modified the README.md to describe the new build process. JerryScript-DCO-1.0-Signed-off-by: Roland Takacs [email protected]
1 parent a2d3ea6 commit eadc6f7

File tree

5 files changed

+72
-84
lines changed

5 files changed

+72
-84
lines changed

targets/nuttx-stm32f4/Kconfig

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,4 @@ config JERRYSCRIPT_STACKSIZE
2727
int "Jerryscript stack size"
2828
default 16384
2929

30-
config JERRYSCRIPT_HEAPSIZE
31-
int "Jerryscript heap size"
32-
default 107520
33-
34-
config JERRYSCRIPT_ERROR_MESSAGES
35-
bool "Enable error messages for builtin error objects"
36-
default n
37-
38-
config JERRYSCRIPT_MEM_STATS
39-
bool "Enable memory statistics"
40-
default n
41-
42-
config JERRYSCRIPT_SHOW_OPCODES
43-
bool "Enable parser byte-code dumps"
44-
default n
45-
46-
config JERRYSCRIPT_DEBUGGER
47-
bool "Jerryscript debugger"
48-
default n
49-
endif
30+
endif # JERRYSCRIPT

targets/nuttx-stm32f4/Makefile

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,48 @@
1414

1515
-include $(TOPDIR)/Make.defs
1616

17-
# Jerryscript built-in application info
18-
17+
# Jerryscript built-in application information.
1918
CONFIG_JERRYSCRIPT_PRIORITY ?= SCHED_PRIORITY_DEFAULT
19+
CONFIG_JERRYSCRIPT_PROGNAME ?= jerry$(EXEEXT)
2020
CONFIG_JERRYSCRIPT_STACKSIZE ?= 16384
21-
CONFIG_JERRYSCRIPT_HEAPSIZE ?= 107520
2221

23-
APPNAME = jerry
24-
# path to the project dir, "jerry-nuttx" by default
25-
ROOT_DIR = ../../..
22+
PROGNAME = $(CONFIG_JERRYSCRIPT_PROGNAME)
2623
PRIORITY = $(CONFIG_JERRYSCRIPT_PRIORITY)
2724
STACKSIZE = $(CONFIG_JERRYSCRIPT_STACKSIZE)
28-
CFLAGS += -std=c99 -DJERRY_NDEBUG '-DCONFIG_MEM_HEAP_AREA_SIZE=$(CONFIG_JERRYSCRIPT_HEAPSIZE)'
29-
CFLAGS += -I$(ROOT_DIR)/ $(shell find $(ROOT_DIR)/jerryscript/jerry-core -type d | sed -r -e 's/^/-I/g')
30-
CFLAGS += -I$(ROOT_DIR)/jerryscript/jerry-libm/include
31-
CFLAGS += -I$(ROOT_DIR)/jerryscript/jerry-ext/include
3225

33-
# Fill error messages for builtin error objects
34-
ifeq ($(CONFIG_JERRYSCRIPT_ERROR_MESSAGES),y)
35-
CFLAGS += -DJERRY_ENABLE_ERROR_MESSAGES
36-
endif
26+
# Path to the JerryScript project. If not specified, it is supposed
27+
# that JerryScript is located next to the nuttx-apps folder.
28+
JERRYSCRIPT_ROOT_DIR ?= ../../../jerryscript
3729

38-
ifeq ($(CONFIG_JERRYSCRIPT_MEM_STATS),y)
39-
CFLAGS += -DJMEM_STATS
40-
endif
30+
CFLAGS += -std=c99
31+
CFLAGS += -I$(JERRYSCRIPT_ROOT_DIR)/jerry-core/include
32+
CFLAGS += -I$(JERRYSCRIPT_ROOT_DIR)/jerry-ext/include
33+
CFLAGS += -I$(JERRYSCRIPT_ROOT_DIR)/jerry-libm/include
4134

42-
ifeq ($(CONFIG_JERRYSCRIPT_SHOW_OPCODES),y)
43-
CFLAGS += -DPARSER_DUMP_BYTE_CODE
44-
endif
35+
# These libs should be copied from the JerryScript project.
36+
LIBS = libjerry-core.a libjerry-ext.a libjerry-port-default.a libjerry-port-default-minimal.a libjerry-libm.a
4537

46-
ifeq ($(CONFIG_JERRYSCRIPT_DEBUGGER),y)
47-
CFLAGS += -DJERRY_DEBUGGER
48-
endif
38+
APPNAME = jerry
39+
ASRCS = setjmp.S
40+
MAINSRC = jerry_main.c
4941

50-
# Jerryscript
42+
.PHONY: copylibs
43+
copylibs:
44+
cp $(JERRYSCRIPT_ROOT_DIR)/build/lib/lib*.a .
5145

52-
.PHONY: jerry_core_allin.c
53-
jerry_core_allin.c:
54-
find $(ROOT_DIR)/jerryscript/jerry-core -name "*.c" | sed -r -e 's/(\.\.\/)*(.+)/#include "\2"/g' > jerry_core_allin.c
46+
$(LIBS): copylibs
47+
$(firstword $(AR)) x $@
5548

56-
.PHONY: jerry_libm_allin.c
57-
jerry_libm_allin.c:
58-
find $(ROOT_DIR)/jerryscript/jerry-libm -name "*.c" | sed -r -e 's/(\.\.\/)*(.+)/#include "\2"/g' > jerry_libm_allin.c
49+
.PHONY: updateobjs
50+
updateobjs:
51+
$(eval OBJS += $(shell find . -name "*.obj"))
5952

60-
.PHONY: jerry_ext_allin.c
61-
jerry_ext_allin.c:
62-
find $(ROOT_DIR)/jerryscript/jerry-ext/handler -name "*.c" | sed -r -e 's/(\.\.\/)*(.+)/#include "\2"/g' > jerry_ext_allin.c
53+
.PHONY: cleanlibs
54+
cleanlibs: updateobjs
55+
rm -f $(OBJS)
6356

64-
ASRCS = setjmp.S
65-
CSRCS = jerry_core_allin.c jerry_libm_allin.c jerry_ext_allin.c
66-
MAINSRC = jerry_main.c
57+
clean: cleanlibs
6758

68-
CONFIG_JERRYSCRIPT_PROGNAME ?= jerry$(EXEEXT)
69-
PROGNAME = $(CONFIG_JERRYSCRIPT_PROGNAME)
59+
.built: $(LIBS) updateobjs
7060

7161
include $(APPDIR)/Application.mk

targets/nuttx-stm32f4/Makefile.travis

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ install: install-apt-get-deps install-kconfig install-clone-nuttx
4646

4747
## Targets for building NuttX with JerryScript.
4848

49+
# Build JerryScript.
50+
script-build-jerryscript:
51+
tools/build.py --clean --toolchain cmake/toolchain_mcu_stm32f4.cmake --profile=es2015-subset --jerry-cmdline OFF --jerry-libc OFF --lto OFF --jerry-libm ON --all-in-one ON --mem-heap 70 --compile-flag='--sysroot=../nuttx'
52+
4953
# Link in the NuttX JerryScript target directory under the NuttX apps tree.
5054
script-add-jerryscript-app:
5155
ln -s ../../jerryscript/targets/nuttx-stm32f4 ../apps/interpreters/jerryscript
@@ -55,7 +59,7 @@ script-configure-usbnsh:
5559
cd ../nuttx/tools && PATH=$(LOCAL_INSTALL)/bin:$$PATH ./configure.sh stm32f4discovery/usbnsh
5660

5761
# Configure and build the firmware (NuttX with JerryScript).
58-
script: script-add-jerryscript-app script-configure-usbnsh
62+
script: script-build-jerryscript script-add-jerryscript-app script-configure-usbnsh
5963
echo 'CONFIG_HOST_LINUX=y' >> ../nuttx/.config
6064
echo 'CONFIG_ARCH_FPU=y' >> ../nuttx/.config
6165
echo 'CONFIG_JERRYSCRIPT=y'>> ../nuttx/.config

targets/nuttx-stm32f4/README.md

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ This folder contains files to run JerryScript on
55

66
### How to build
77

8-
#### 1. Setting up the build environment for STM32F4-Discovery board
8+
#### 1. Setup the build environment for STM32F4-Discovery board
99

10-
Clone JerryScript and NuttX into jerry-nuttx directory
10+
Clone the necessary projects into a jerry-nuttx directory:
1111

1212
```
13-
mkdir jerry-nuttx
14-
cd jerry-nuttx
13+
# Create a base folder for all the projects.
14+
mkdir jerry-nuttx && cd jerry-nuttx
15+
1516
git clone https://github.com/jerryscript-project/jerryscript.git
1617
git clone https://bitbucket.org/nuttx/nuttx.git
1718
git clone https://bitbucket.org/nuttx/apps.git
1819
git clone https://github.com/texane/stlink.git
1920
```
2021

21-
The following directory structure is created after these commands
22+
The following directory structure is created after these commands:
2223

2324
```
2425
jerry-nuttx
@@ -30,25 +31,36 @@ jerry-nuttx
3031
+ stlink
3132
```
3233

33-
#### 2. Adding JerryScript as an interpreter for NuttX
34+
#### 2. Build JerryScript for NuttX
35+
36+
Build JerryScript with the appropriate toolchain and use NuttX as sysroot:
3437

3538
```
36-
cd apps/interpreters
37-
mkdir jerryscript
38-
cp ../../jerryscript/targets/nuttx-stm32f4/* ./jerryscript/
39+
# Assuming you are in jerry-nuttx folder.
40+
cd jerryscript
41+
42+
tools/build.py --clean --toolchain cmake/toolchain_mcu_stm32f4.cmake --profile=es2015-subset --jerry-cmdline OFF --jerry-libc OFF --lto OFF --jerry-libm ON --all-in-one ON --mem-heap 70 --compile-flag='--sysroot=../nuttx'
3943
```
4044

41-
#### 3. Configure NuttX
45+
#### 3. Copy JerryScript's application files to NuttX
4246

4347
```
44-
# assuming you are in jerry-nuttx folder
48+
# Assuming you are in jerry-nuttx folder.
49+
mkdir -p apps/interpreters/jerryscript
50+
cp jerryscript/targets/nuttx-stm32f4/* apps/interpreters/jerryscript/
51+
```
52+
53+
#### 4. Configure NuttX
54+
55+
```
56+
# Assuming you are in jerry-nuttx folder.
4557
cd nuttx/tools
4658
47-
# configure NuttX USB console shell
59+
# Configure NuttX to use USB console shell.
4860
./configure.sh stm32f4discovery/usbnsh
4961
5062
cd ..
51-
# might require to run "make menuconfig" twice
63+
# Might be required to run "make menuconfig" twice.
5264
make menuconfig
5365
```
5466

@@ -61,9 +73,11 @@ We must set the following options:
6173
If you get `kconfig-mconf: not found` error when you run `make menuconfig` you may have to install kconfig-frontends:
6274

6375
```
64-
# assume you are in jerry-nuttx folder
6576
sudo apt-get install gperf flex bison libncurses-dev
77+
78+
# Assuming you are in jerry-nuttx folder.
6679
git clone https://github.com/jameswalmsley/kconfig-frontends.git
80+
6781
cd kconfig-frontends
6882
./bootstrap
6983
./configure --enable-mconf
@@ -72,24 +86,24 @@ sudo make install
7286
sudo ldconfig
7387
```
7488

75-
#### 4. Build JerryScript for NuttX
89+
#### 4. Build NuttX
7690

7791
```
78-
# assuming you are in jerry-nuttx folder
79-
cd nuttx/
92+
# Assuming you are in jerry-nuttx folder.
93+
cd nuttx
8094
make
8195
```
8296

83-
#### 5. Flashing
97+
#### 5. Flash the device
8498

8599
Connect Mini-USB for power supply and connect Micro-USB for `NSH` console.
86100

87101
To configure `stlink` utility for flashing, follow the instructions in the official [Stlink repository](https://github.com/texane/stlink).
88102

89103
To flash,
90104
```
91-
# assuming you are in nuttx folder
92-
sudo ../stlink/build/Release/st-flash write nuttx.bin 0x8000000
105+
# Assuming you are in jerry-nuttx folder.
106+
sudo stlink/build/Release/st-flash write nuttx/nuttx.bin 0x8000000
93107
```
94108

95109
### Running JerryScript

targets/nuttx-stm32f4/jerry_main.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "jerryscript.h"
2121
#include "jerryscript-ext/handler.h"
2222
#include "jerryscript-port.h"
23-
#include "jmem.h"
2423
#include "setjmp.h"
2524

2625
/**
@@ -94,7 +93,7 @@ read_file (const char *file_name, /**< source code */
9493

9594
rewind (file);
9695

97-
uint8_t *buffer = jmem_heap_alloc_block_null_on_error (script_len);
96+
uint8_t *buffer = (uint8_t *) malloc (script_len);
9897

9998
if (buffer == NULL)
10099
{
@@ -108,7 +107,7 @@ read_file (const char *file_name, /**< source code */
108107
if (!bytes_read || bytes_read != script_len)
109108
{
110109
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: failed to read file: %s\n", file_name);
111-
jmem_heap_free_block ((void*) buffer, script_len);
110+
free ((void*) buffer);
112111

113112
fclose (file);
114113
return NULL;
@@ -482,12 +481,12 @@ int jerry_main (int argc, char *argv[])
482481
if (jerry_value_has_error_flag (ret_value))
483482
{
484483
print_unhandled_exception (ret_value, source_p);
485-
jmem_heap_free_block ((void*) source_p, source_size);
484+
free ((void*) source_p);
486485

487486
break;
488487
}
489488

490-
jmem_heap_free_block ((void*) source_p, source_size);
489+
free ((void*) source_p);
491490

492491
jerry_release_value (ret_value);
493492
ret_value = jerry_create_undefined ();

0 commit comments

Comments
 (0)