Skip to content

Instantly share code, notes, and snippets.

@polaroi8d
Last active October 22, 2019 08:35
Show Gist options
  • Save polaroi8d/581ab41974f09afa837d to your computer and use it in GitHub Desktop.
Save polaroi8d/581ab41974f09afa837d to your computer and use it in GitHub Desktop.
How to build IoT.js

#How to build IoT.js

#####First of all you need to get the repositories. Source repositories

There is a script to help you build IoT.js called "build.py" in source repository. This document assumes 'harmony' as the root directory. JerryScript, libtuv and libuv are included as sub-modules in deps folder. Harmony? It's from initial code name of our project. (Sounds good, isn't it? :))

#####1. Build tools installation.

sudo apt-get install build-essential cmake

Where /.../nuttx/nuttx should be absolute path to nuttx where .config resides, please change to your system configuration. At the end of build, it'll copy libtuv.a and libtuvtester.a, tester in library form, to /.../nuttx/nuttx/lib folder.

#####2. Prepare nuttx folder in harmony.

mkdir harmony
cd harmony
mkdir nuttx
cd nuttx
git init

#####3. Add submodules.

git submodule add https://bitbucket.org/seanshpark/nuttx.git nuttx
git submodule add https://bitbucket.org/seanshpark/nuttx_apps.git apps

#####4. Checkout iotjs branch and update nuttx submodules.

cd apps
git checkout iotjs
cd ../nuttx
git checkout iotjs
git submodule update --init --recursive

#####5. Configure, in nutty folder where tools folder exist.

cd tools
./configure.sh stm32f4discovery/iotjs
cd ..
make menuconfig

If you get kconfig-mconf: not found error you may have to install kconfig-frontends. Assume you are in harmony folder.

sudo apt-get install gperf flex bison libncurses-dev
git clone https://github.com/jameswalmsley/kconfig-frontends.git
cd kconfig-frontends
./bootstrap
./configure --enable-mconf
make
sudo make install
sudo ldconfig

#####6. Setting network adress in menuconfig, this is needed only once in first build time.

CONFIG_NSH_IPADDR=0x0a000002
CONFIG_NSH_DRIPADDR=0x0a000001
CONFIG_NSH_MACADDR=0x1e000a000002

#####7. Update start-up script, you may need to install genromfs.

sudo apt-get install genromfs

#####8. Run script.

cd tools
./mkromfsimg.sh /home/../nuttx/nuttx

where nuttx absolute path where .config exist

Latest line in the script contains calling addroute to add route table for the network. Edit nsh_romfsimg.h file and add const so that it resides in text area, thus not eat up RAM.

const unsigned char romfs_img[] = { 
...
const unsigned int romfs_img_len = 1024;

#####9. Copy to apps folder.

cp nsh_romfsimg.h ../../apps/nshlib/nsh_romfsimg_iotjs.h
cd ..

#####10. Build for the first time:

make

When you see this error, goto iotjs build and come here after success .

make: *** No rule to make target `lib/libfdlibm.a', needed by `pass2deps'.  Stop.

Build IoT.js

#####11. You may need to install below packages as follows;

sudo apt-get install autoconf libtool gperf flex bison autoconf2.13 
sudo apt-get install libncurses-dev
sudo apt-get install libusb-1.0-0-dev
sudo apt-get install libsgutils2-dev
sudo apt-get install genromfs

#####12. To use menuconfig in NuttX, you may need to install kconfig frontend.

git clone https://github.com/jameswalmsley/kconfig-frontends.git
cd kconfig-frontends
./bootstrap
./configure --enable-mconf
make
sudo make install
sudo ldconfig

#####13. Assume harmony as a root folder so it may look like this;

git clone https://github.com/Samsung/iotjs.git

add .gitignore file with below contents. it's for the patch from old repository.

.depend
Make.dep
*.o
*.a
*.d
*.i
*~
.swp
.*.swp
core
.gdbinit
cscope.out

#####14. Build IoT.js with these parameters

cd iotjs
./tools/build.py --buildtype=release --target-arch=arm --target-os=nuttx --nuttx-home=/home/user/.../harmony/nuttx/nuttx --no-check-test

It will show errors that libuv.a cannot be found. It is ok for now. If you just want to try nuttx only before proceeding, please turn off three options in ".config" file. The .config file in /home/../nuttx/nuttx/ folder.

CONFIG_SYSTEM_IOTJS=n
CONFIG_LIBUV=n
CONFIG_LIBJERRY=n
CONFIG_DEV_GPIO=n

#####15. Copy libraries to nuttx/nuttx/lib folder. For the moment, lib files need to be copied manually.

cd iotjs
cp build/arm-nuttx/release/lib/libjerrycore.a ../nuttx/nuttx/lib/libjerry.a
cp build/arm-nuttx/release/lib/libtuv.a ../nuttx/nuttx/lib
cp build/arm-nuttx/release/iotjs/liblibiotjs.a ../nuttx/nuttx/lib/libiotjs.a
cp build/arm-nuttx/release/lib/libfdlibm.a ../nuttx/nuttx/lib/libfdlibm.a

#####16. After that go back to nuttx folder where the .config file is exist. And build it.

make

###Ready! Now you can flash the binary file to your board with st-link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment