Update NuttX target to releases/10.2 (#4822)

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs roland.takacs@h-lab.eu
This commit is contained in:
Roland Takacs 2021-11-23 13:21:24 +01:00 committed by GitHub
parent 2899582080
commit 3737a28eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 234 additions and 129 deletions

View File

@ -3,28 +3,18 @@
# see the file kconfig-language.txt in the NuttX tools repository.
#
config JERRYSCRIPT
bool "Jerryscript"
config INTERPRETERS_JERRYSCRIPT
bool "Jerryscript JavaScript engine"
default n
---help---
Enable Jerryscript ECMAScript 5.1 interpreter
if JERRYSCRIPT
if INTERPRETERS_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"
config INTERPRETERS_JERRYSCRIPT_PRIORITY
int "Jerryscript priority"
default 100
config JERRYSCRIPT_STACKSIZE
config INTERPRETERS_JERRYSCRIPT_STACKSIZE
int "Jerryscript stack size"
default 16384
endif # JERRYSCRIPT
endif # INTERPRETERS_JERRYSCRIPT

View File

@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
ifeq ($(CONFIG_JERRYSCRIPT),y)
CONFIGURED_APPS += interpreters/jerryscript
ifeq ($(CONFIG_INTERPRETERS_JERRYSCRIPT),y)
CONFIGURED_APPS += $(APPDIR)/interpreters/jerryscript
endif

View File

@ -12,20 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Jerryscript built-in application information.
CONFIG_JERRYSCRIPT_PRIORITY ?= SCHED_PRIORITY_DEFAULT
CONFIG_JERRYSCRIPT_PROGNAME ?= jerry$(EXEEXT)
CONFIG_JERRYSCRIPT_STACKSIZE ?= 16384
PROGNAME = jerry
PRIORITY = $(CONFIG_INTERPRETERS_JERRYSCRIPT_PRIORITY)
STACKSIZE = $(CONFIG_INTERPRETERS_JERRYSCRIPT_STACKSIZE)
PROGNAME = $(CONFIG_JERRYSCRIPT_PROGNAME)
PRIORITY = $(CONFIG_JERRYSCRIPT_PRIORITY)
STACKSIZE = $(CONFIG_JERRYSCRIPT_STACKSIZE)
# Path to the JerryScript project. If not specified, it is supposed
# that JerryScript is located next to the nuttx-apps folder.
# Path to the JerryScript and NuttX projects. If not specified, it is
# supposed that JerryScript is located next to the nuttx folder.
JERRYSCRIPT_ROOT_DIR ?= ../../../jerryscript
NUTTX_ROOT_DIR ?= $(JERRYSCRIPT_ROOT_DIR)/../nuttx
CFLAGS += -std=c99
CFLAGS += -I$(JERRYSCRIPT_ROOT_DIR)/jerry-core/include
@ -35,7 +32,6 @@ CFLAGS += -I$(JERRYSCRIPT_ROOT_DIR)/jerry-math/include
# These libs should be copied from the JerryScript project.
LIBS = libjerry-core.a libjerry-ext.a libjerry-math.a
APPNAME = jerry
ASRCS = setjmp.S
CSRCS = jerry_port.c jerry_module.c
MAINSRC = jerry_main.c
@ -55,8 +51,21 @@ updateobjs:
cleanlibs: updateobjs
rm -f $(OBJS)
.PHONY: libjerry
libjerry:
$(JERRYSCRIPT_ROOT_DIR)/tools/build.py \
--clean \
--lto=OFF \
--jerry-cmdline=OFF \
--jerry-math=ON \
--amalgam=ON \
--mem-heap=70 \
--profile=es.next \
--compile-flag="--sysroot=${NUTTX_ROOT_DIR}" \
--toolchain=$(abspath $(JERRYSCRIPT_ROOT_DIR)/cmake/toolchain_mcu_stm32f4.cmake)
clean:: cleanlibs
.built: $(LIBS) updateobjs
archive: libjerry $(LIBS) updateobjs
include $(APPDIR)/Application.mk

View File

@ -39,8 +39,8 @@ install-kconfig:
# Fetch nuttx/{apps,nuttx} repositories.
install-clone-nuttx:
git clone https://github.com/apache/incubator-nuttx-apps.git ../apps -b releases/9.0
git clone https://github.com/apache/incubator-nuttx.git ../nuttx -b releases/9.0
git clone https://github.com/apache/incubator-nuttx-apps.git ../apps -b releases/10.2
git clone https://github.com/apache/incubator-nuttx.git ../nuttx -b releases/10.2
# Perform all the necessary (JerryScript-independent) installation steps.
install-noapt: install-kconfig install-clone-nuttx
@ -49,22 +49,17 @@ install: install-apt-get-deps install-noapt
## Targets for building NuttX with JerryScript.
# Build JerryScript.
script-build-jerryscript:
tools/build.py --clean --toolchain cmake/toolchain_mcu_stm32f4.cmake --profile=es.next --jerry-cmdline OFF --lto OFF --jerry-math ON --amalgam ON --jerry-port-default OFF --mem-heap 70 --compile-flag='--sysroot=../nuttx'
# Link in the NuttX JerryScript target directory under the NuttX apps tree.
script-add-jerryscript-app:
ln -s ../../jerryscript/targets/nuttx-stm32f4 ../apps/interpreters/jerryscript
# Configure USB shell.
script-configure-usbnsh:
cd ../nuttx/tools && PATH=$(LOCAL_INSTALL)/bin:$$PATH ./configure.sh stm32f4discovery/usbnsh
cd ../nuttx/tools && PATH=$(LOCAL_INSTALL)/bin:$$PATH ./configure.sh stm32f4discovery:usbnsh
# Configure and build the firmware (NuttX with JerryScript).
script: script-build-jerryscript script-add-jerryscript-app script-configure-usbnsh
echo 'CONFIG_HOST_LINUX=y' >> ../nuttx/.config
script: script-add-jerryscript-app script-configure-usbnsh
echo 'CONFIG_ARCH_FPU=y' >> ../nuttx/.config
echo 'CONFIG_JERRYSCRIPT=y'>> ../nuttx/.config
echo 'CONFIG_INTERPRETERS_JERRYSCRIPT=y'>> ../nuttx/.config
PATH=$(LOCAL_INSTALL)/bin:$$PATH $(MAKE) -C ../nuttx olddefconfig
PATH=$(LOCAL_INSTALL)/bin:$$PATH $(MAKE) -C ../nuttx

View File

@ -1,21 +1,25 @@
### About
This folder contains files to run JerryScript on
[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/)
[STM32F4-Discovery board](https://www.st.com/en/evaluation-tools/stm32f4discovery.html) with
[NuttX](https://nuttx.apache.org/).
The document had been validated on Ubuntu 20.04 operating system.
### How to build
#### 1. Setup the build environment for STM32F4-Discovery board
Clone the necessary projects into a `jerry-nuttx` directory. The last tested working version of NuttX is 9.0.
Clone the necessary projects into a `jerry-nuttx` directory.
The latest tested working version of NuttX is 10.2.
```sh
# Create a base folder for all the projects.
mkdir jerry-nuttx && cd jerry-nuttx
git clone https://github.com/jerryscript-project/jerryscript.git
git clone https://bitbucket.org/nuttx/nuttx.git -b releases/9.0
git clone https://bitbucket.org/nuttx/apps.git -b releases/9.0
git clone https://github.com/apache/incubator-nuttx.git nuttx -b releases/10.2
git clone https://github.com/apache/incubator-nuttx-apps.git apps -b releases/10.2
git clone https://bitbucket.org/nuttx/tools.git tools
git clone https://github.com/texane/stlink.git -b v1.5.1-patch
```
@ -23,35 +27,38 @@ The following directory structure is created after these commands:
```
jerry-nuttx
+ apps
+ jerryscript
| + targets
| + nuttx-stm32f4
| + nuttx-stm32f4
+ nuttx
+ apps
+ tools
+ stlink
```
#### 2. Build JerryScript for NuttX
Build JerryScript as a static library using the NuttX folder as sysroot. The created static libraries will be used later by NuttX.
#### 2. Install dependencies of the projects
```sh
# Assuming you are in jerry-nuttx folder.
jerryscript/tools/build.py \
--clean \
--lto=OFF \
--jerry-cmdline=OFF \
--jerry-math=ON \
--amalgam=ON \
--mem-heap=70 \
--profile=es.next \
--compile-flag="--sysroot=${PWD}/nuttx" \
--toolchain=${PWD}/jerryscript/cmake/toolchain_mcu_stm32f4.cmake
jerryscript/tools/apt-get-install-deps.sh
# Toolchain dependencies of NuttX.
sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi
# Tool dependencies of NuttX.
sudo apt install \
bison flex gettext texinfo libncurses5-dev libncursesw5-dev \
gperf automake libtool pkg-config build-essential gperf genromfs \
libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \
libexpat-dev gcc-multilib g++-multilib picocom u-boot-tools util-linux
# ST-Link and serial communication dependencies.
sudo apt install libusb-1.0-0-dev minicom
```
#### 3. Copy JerryScript's application files to NuttX
After creating the static libs (see previous step), it is needed to move the JerryScript application files to the NuttX's interpreter path.
Move JerryScript application files to `apps/interpreters/jerryscript` folder.
```sh
# Assuming you are in jerry-nuttx folder.
@ -62,47 +69,13 @@ cp jerryscript/targets/nuttx-stm32f4/* apps/interpreters/jerryscript/
# ln -s jerryscript/targets/nuttx-stm32f4 apps/interpreters/jerryscript
```
#### 4. Configure NuttX
#### 4. Build kconfig-frontend to configure NuttX
NuttX requires configuration first. The configuration creates a `.config` file in the root folder of NuttX that has all the necessary options for the build.
Skip this section if `kconfig-frontends` had alrady been installed by package manager.
```sh
# Assuming you are in jerry-nuttx folder.
cd nuttx/tools
# Configure NuttX to use USB console shell.
./configure.sh stm32f4discovery/usbnsh
```
By default, JerryScript is not enabled, so it is needed to modify the configuration file.
##### 4.1 Enable JerryScript without user interaction
```sh
# Assuming you are in jerry-nuttx folder.
sed --in-place "s/CONFIG_HOST_WINDOWS/# CONFIG_HOST_WINDOWS/g" nuttx/.config
sed --in-place "s/CONFIG_WINDOWS_CYGWIN/# CONFIG_WINDOWS_CYGWIN/g" nuttx/.config
sed --in-place "s/CONFIG_TOOLCHAIN_WINDOWS/# CONFIG_TOOLCHAIN_WINDOWS/g" nuttx/.config
cat >> nuttx/.config << EOL
CONFIG_HOST_LINUX=y
CONFIG_ARCH_FPU=y
CONFIG_JERRYSCRIPT=y
CONFIG_JERRYSCRIPT_PRIORITY=100
CONFIG_JERRYSCRIPT_STACKSIZE=16384
EOL
```
##### 4.2 Enable JerryScript using kconfig-frontend
`kconfig-frontend` could be useful if there are another options that should be enabled or disabled in NuttX.
###### 4.2.1 Install kconfig-frontend
```sh
# Assuming you are in jerry-nuttx folder.
git clone https://bitbucket.org/nuttx/tools.git nuttx-tools
cd nuttx-tools/kconfig-frontends
cd tools/kconfig-frontends
./configure \
--disable-nconf \
@ -113,33 +86,160 @@ cd nuttx-tools/kconfig-frontends
--prefix=${PWD}/install
make
sudo make install
# Add the install folder to PATH
PATH=$PATH:${PWD}/install/bin
make install
# Add install folder to PATH
PATH=${PWD}/install/bin:$PATH
```
###### 4.2.2 Enable JerryScript
#### 5. Configure NuttX
Configure NuttX for serial communication. A `.config` file contains all the options for the build.
```sh
# Assuming you are in jerry-nuttx folder.
cd nuttx/tools
# Configure NuttX to use USB console shell.
./configure.sh stm32f4discovery:usbnsh
```
By default, JerryScript is disabled so it is needed to modify the configuration file. It can
be done by using menuconfig (section 5.1) or modifying the `.config` file directly (section 5.2).
##### 5.1 Enable JerryScript using menuconfig
```sh
# Assuming you are in jerry-nuttx folder.
# Might be required to run `make menuconfig` twice.
make -C nuttx menuconfig
```
* Change `Build Setup -> Build Host Platform` to Linux
* Enable `System Type -> FPU support`
* Enable JerryScript `Application Configuration -> Interpreters -> JerryScript`
* Enable `Application Configuration -> Interpreters -> JerryScript`
#### 5. Build NuttX
[Optional] Enabling ROMFS helps to flash JavaScript input files to the device's flash memory.
* Enable `File systems -> ROMFS file system`
* Enable `Application configuration -> NSH library -> Scripting Support -> Support ROMFS start-up script`
[Optional] Enabling MMCSD helps to mount sd card on the device.
Note: These options are for the micro-sd card slot of STM32F4-Discovery base-board.
* Enable `System Type -> STM32 Peripheral Support -> SDIO`
* Enable `RTOS Features -> Work queue support -> High priority (kernel) worker thread`
* Enable `RTOS Features -> RTOS hooks -> Custom board late initialization`
* Enable `Driver Support -> MMC/SD Driver Support`
* Disable `Driver Support -> MMC/SD Driver Support -> MMC/SD write protect pin`
* Disable `Driver Support -> MMC/SD Driver Support -> MMC/SD SPI transfer support`
* Enable `Driver Support -> MMC/SD Driver Support -> MMC/SD SDIO transfer support`
* Enable `File systems -> FAT file system`
* Enable `File systems -> FAT file system -> FAT upper/lower names`
* Enable `File systems -> FAT file system -> FAT long file names`
##### 5.2 Enable JerryScript without user interaction
A simpler solution is to append the necessary content to the `.config` configuration file:
```sh
# Assuming you are in jerry-nuttx folder.
cat >> nuttx/.config << EOL
CONFIG_ARCH_FPU=y
CONFIG_INTERPRETERS_JERRYSCRIPT=y
CONFIG_INTERPRETERS_JERRYSCRIPT_PRIORITY=100
CONFIG_INTERPRETERS_JERRYSCRIPT_STACKSIZE=16384
EOL
```
[Optional] Enable ROM File System
```sh
# Assuming you are in jerry-nuttx folder.
cat >> nuttx/.config << EOL
CONFIG_BOARDCTL_ROMDISK=y
CONFIG_FS_ROMFS=y
CONFIG_NSH_ROMFSETC=y
CONFIG_NSH_ROMFSMOUNTPT="/etc"
CONFIG_NSH_INITSCRIPT="init.d/rcS"
CONFIG_NSH_ROMFSDEVNO=0
CONFIG_NSH_ROMFSSECTSIZE=64
CONFIG_NSH_DEFAULTROMFS=y
EOL
```
[Optional] Enable MMCSD driver and FAT File System
Note: These options are for the micro-sd card slot of STM32F4-Discovery base-board.
```sh
# Assuming you are in jerry-nuttx folder.
cat >> nuttx/.config << EOL
CONFIG_STM32_SDIO=y
CONFIG_STM32_SDIO_DMAPRIO=0x00010000
CONFIG_MMCSD_HAVE_CARDDETECT=y
CONFIG_BOARD_LATE_INITIALIZE=y
CONFIG_BOARD_INITTHREAD_STACKSIZE=2048
CONFIG_BOARD_INITTHREAD_PRIORITY=240
CONFIG_SIG_SIGWORK=17
CONFIG_SCHED_WORKQUEUE=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPNTHREADS=1
CONFIG_SCHED_HPWORKPRIORITY=224
CONFIG_SCHED_HPWORKSTACKSIZE=2048
CONFIG_BCH=y
CONFIG_ARCH_HAVE_SDIO=y
CONFIG_ARCH_HAVE_SDIOWAIT_WRCOMPLETE=y
CONFIG_ARCH_HAVE_SDIO_PREFLIGHT=y
CONFIG_MMCSD=y
CONFIG_MMCSD_NSLOTS=1
CONFIG_MMCSD_MMCSUPPORT=y
CONFIG_MMCSD_SDIO=y
CONFIG_FS_FAT=y
CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y
CONFIG_FAT_MAXFNAME=32
CONFIG_FAT_LFN_ALIAS_TRAILCHARS=0
CONFIG_FSUTILS_MKFATFS=y
CONFIG_NSH_MMCSDSLOTNO=0
EOL
```
#### 6. Provide JavaScript files for STM32F4 device
##### 6.1. Create ROMFS image from a custom folder
Skip this section if MMCSD is used. Otherwise, generate a C header file from a custom folder.
Try to minimize the size of the folder due to the limited capacity of flash memory.
```sh
# Assuming you are in jerry-nuttx folder.
mkdir jerry-example
# Let hello.js be a possible JavaScript input for JerryScript.
cp jerryscript/tests/hello.js jerry-example
# Generate ROMFS image from a custom folder.
genromfs -f romfs_img -d jerry-example
# Dump image as C header file and override NuttX's default ROMFS file.
xxd -i romfs_img apps/nshlib/nsh_romfsimg.h
# Add const modifier to place the content to flash memory.
sed -i "s/unsigned/const\ unsigned/g" apps/nshlib/nsh_romfsimg.h
```
##### 6.2. Copy files to memory card
Skip this section if ROMFS is used. Otherwise, copy your files to a FAT32 formatted memory card.
#### 7. Build NuttX (with JerryScript)
```sh
# Assuming you are in jerry-nuttx folder.
make -C nuttx
```
#### 6. Flash the device
#### 8. Flash the device
Connect Mini-USB for power supply and connect Micro-USB for `NSH` console.
Connect Mini-USB for charging and flasing the device.
```sh
# Assuming you are in jerry-nuttx folder.
@ -148,39 +248,49 @@ make -C stlink release
sudo stlink/build/Release/st-flash write nuttx/nuttx.bin 0x8000000
```
### Running JerryScript
#### 9. Connect to the device
You can use `minicom` for terminal program, or any other you may like, but set
baud rate to `115200`.
Connect Micro-USB for serial communication. The device should be visible as `/dev/ttyACM0` on the host.
You can use `minicom` communication program with `115200` baud rate.
```sh
sudo minicom --device=/dev/ttyACM0 --baud=115200
```
You may have to press `RESET` on the board and press `Enter` keys on the console
several times to make `nsh` prompt to appear.
If the prompt shows like this,
```
NuttShell (NSH)
nsh>
nsh>
nsh>
```
please set `Add Carriage Ret` option by `CTRL-A` > `Z` > `U` at the console,
if you're using `minicom`.
Run `jerry` with javascript file(s)
Set `Add Carriage Ret` option in `minicom` by `CTRL-A -> Z -> U` key combinations.
You may have to press `RESET` on the board and press `Enter` key on the console several times to make `nsh` prompt visible.
NuttShell (NSH) prompt looks like as follows:
```
NuttShell (NSH)
nsh> jerry full_path/any.js
NuttShell (NSH) NuttX-10.2.0
nsh>
```
Without argument it prints:
#### 10. Run JerryScript
##### 10.1 Run `jerry` without input
```
NuttShell (NSH) NuttX-10.2.0
nsh> jerry
No input files, running a hello world demo:
Hello world 5 times from JerryScript
```
##### 10.2 Run `jerry` with files from ROMFS
```
NuttShell (NSH) NuttX-10.2.0
nsh> jerry /etc/hello.js
```
##### 10.3 Run `jerry` with files from memory card
After NuttX has initialized, the card reader should be visible as `/dev/mmcsd0` on the device.
Mount it to be JavaScript files reachable.
```
NuttShell (NSH) NuttX-10.2.0
nsh> mount -t vfat /dev/mmcsd0 /mnt
nsh> jerry /mnt/hello.js
```

View File

@ -13,6 +13,7 @@
* limitations under the License.
*/
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>