Node.js 6 on OpenWrt

I have managed to produce a working Node.js 6 binary for OpenWrt and RPi (brcm2708/brcm2709).

Binaries

15.05.1: brcm2708 6.9.5
15.05.1: brcm2709 6.9.5
15.05.1: mvebu 6.9.5 Please test (on WRT1x00AC router) and get back to me with feedback
15.05.1: x86 6.9.5 Please test and get back to me with feedback

Note: all the binaries work with equal performance on RPi v2 (brcm2709). For practical purposes the brcm2708 may be the only binary needed.

How to build 6.9.5 brcm2708/brcm2709
The procudure is:

  1. Set PATH and STAGING_DIR
  2. Set a few compiler flags and run configure with not so few options
  3. Fix nearbyint/nearbyintf
  4. Fix config.gypi
  5. make

1. I have a little script to set my toolchain variables.

# file:  env-15.05.1-brcm2709.sh
# usage: $ source ./env-15.05.1-brcm2709.sh

PATH=/path/to/staging_dir/bin:$PATH
export PATH

STAGING_DIR=/path/to/staging_dir
export STAGING_DIR

Your path should now contain arm-openwrt-linux-uclibcgnueabi-g++ and other binaries.

2. (brcm2709 / mvebu) I have another script to run configure:

#!/bin/sh -e

#Tools
export CSTOOLS="$STAGING_DIR"
export CSTOOLS_INC=${CSTOOLS}/include
export CSTOOLS_LIB=${CSTOOLS}/lib

export CC="arm-openwrt-linux-uclibcgnueabi-gcc"
export CXX="arm-openwrt-linux-uclibcgnueabi-g++"
export LD="arm-openwrt-linux-uclibcgnueabi-ld"

export CFLAGS="-isystem${CSTOOLS_INC} -mfloat-abi=softfp"
export CPPFLAGS="-isystem${CSTOOLS_INC} -mfloat-abi=softfp"

export PATH="${CSTOOLS}/bin:$PATH"

./configure --without-snapshot --dest-cpu=arm --dest-os=linux --without-npm --without-ssl --without-intl --without-inspector

bash --norc

Please not that this script was the first one that worked. It may not be the best. Some things may not be needed. –without-intl and –without-inspector helped me avoid build errors. If you need those features you have more work to do.

2. (brcm2708)

#!/bin/sh -e

#Tools
export CSTOOLS="$STAGING_DIR"
export CSTOOLS_INC=${CSTOOLS}/include
export CSTOOLS_LIB=${CSTOOLS}/lib

export CC="arm-openwrt-linux-uclibcgnueabi-gcc"
export CXX="arm-openwrt-linux-uclibcgnueabi-g++"
export LD="arm-openwrt-linux-uclibcgnueabi-ld"

export CFLAGS="-isystem${CSTOOLS_INC} -march=armv6j -mfloat-abi=softfp"
export CPPFLAGS="-isystem${CSTOOLS_INC} -march=armv6j -mfloat-abi=softfp"

export PATH="${CSTOOLS}/bin:$PATH"

./configure --without-snapshot --dest-cpu=arm --dest-os=linux --without-npm --without-ssl --without-intl --without-inspector

bash --norc

3. Use “grep -nR nearbyint” to find and replace:

  nearbyint => round
  nearbyintf => roundf

This may not be a good idea! However, nearbyint(f) is not supported in OpenWrt, and with the above replacements Node.js builds and it passes the octane benchmark – so it is not that broken. I suppose there is correct way to replace nearbyint(f).

4. Add to config.gypi:

{ 'target_defaults': {
    'cflags': [ '-D__STDC_LIMIT_MACROS' ,'-D__STDC_CONSTANT_MACROS'],
    'ldflags': [ '-Wl,-rpath,/path/to/staging_dir/lib/' ]},

These are just compilation error workarounds.

This works for me.

Dependencies
You need to install dependencies in OpenWrt:

# opkg update
# opkg install librt
# opkg install libstdcpp

Performance
My initial tests indicate that Node.js v6 is a little (~2%) slower than Node.js 4 on ARM v7 (RPi v2).

Other targets
mvebu: I will build a binary, but I need help to test
x86/x86_64: This shall be easy, but I see little need/use. Let me know if you want a binary.
mpc85xx: The chip is quite capable, but the PowerPC port of Node.js will most likely never support it.

Most MIPS architectures lack FPU and are truly unsuitable for running Node.js.

std::snprintf
It seems the OpenWrt C++ std library does not support std::snprintf. You can replace it with just snprintf and add #include <stdio.h> in the file:
deps/v8_inspector/third_party/v8_inspector/platform/inspector_protocol/String16_cpp.template
However, this is not needed when –without-inspector is applied.

Node.js 6.12.2
I have failed building Node.js 6.12.2 on x86 with some openssl error.

Node.js 7
I have failed building Node.js 7 before. But perhaps I will give it a try sometime that Node.js 6 is working.

Older versions of Node.js
I have previously built and distributed Node.js 4 for OpenWrt.

Leave a comment ?

29 Comments.

  1. magische_vogel

    Hi,
    I’ll be thankfull if you can provide me with more informations about which routers models that support openwrt + FPU + node.js 4.
    Best regards.

  2. It is not very good 🙁
    I think you will have success with the WRT1900AC (and the WRT1200AC) since they have modern ARM cpus.
    Most routers have MIPS (without FPU) which is obviously a bad idea.
    Very few routers have Intel (or x86) CPUs.

  3. magische_vogel

    Thank you very much for taking time to answer my question. Please can you share nodejs 4 binaries for WRTxxxxAC and a guide how to cross compile node.js? What about the model WRT3200ACM (RAM 512 MO, FLASH 256 MO)?
    Best regards.

  4. WRT3200ACM +1

  5. Try the binaries for mvebu! They should work, I think. Otherwise let me know and I can try to make binaries that work.
    http://techfindings.one/archives/2175 (v4)

    Edit: and version 6 above.

  6. magische_vogel

    Hi again,
    by the way the router hardware revesion is: device::hw_revision=1 (Mamba).

  7. magische_vogel

    Hi zo0ok,

    nodejs v4.7.3 working good on CC 15.05.1. but 6.9.5 give seg fault err.

    I can’t thank you for the hard work you are done.

    Best regards.

  8. magische_vogel

    Hi zo0ok,

    Sorry, my brain is seg faulting :), the downloaded file was corrupted. Now nodejs v6.9.5 is working without issues.

    Please delete the previous posts to keep TechFindings clean.

    Thank you.

  9. Thank you for your feedback! Glad that v6.9.5 works on WRT-1900AC and CC 15.05.1!

  10. Cheikh BOUDRAA

    Hi zo0ok,

    Do you have npm binary compiled for openwrt ?

    Thank you so much.

  11. I dont.

    In the future when I make another build I can consider it. I have just actively used –without-npm because I want to reduce complexiy of my build (it can be hard enough to build node) and because I have seen no real need for npm on OpenWRT.

    In many cases, you can just copy your entire node_modules/ folder from another computer.
    And if that doesn’t work, I don’t think npm will succeed either.

  12. Thank you so much for your answer.
    I got your hint.
    Thank you again for considering my request in your future buils.
    You have already done a good job.

    Best regards

  13. I want to compile Node.js 6 for MediTek Mt7688 module, having OpenWRT 15.05.01. Could you please guide me?

  14. Hi beparas… I think the Mt7688 does not have an FPU.

    I once built for Mt7620 and I wrote about it here:
    http://techfindings.one/archives/2175

    Short version: Node.js 0.10 works. Later versions require FPU. OpenWRT is (for good reasons) built without FPU kernel emulation. So building Node.js (4) for Mt7620 was not so hard, but it required me to buid my own OpenWRT version… and I don’t think it is worth it. And Node.js performance with FPU emulation is horrible.

    But I spent some time with this because I found it interesting so feel free to comment/ask more and perhaps we can find something interesting for Mt7688.

  15. Hello zo0ok… Sorry for let replay.
    My objective is to install Node-RED on MT7688.
    how can I help you to install Node.js on MT7688?

  16. I’m trying to crosscompile from ubuntu to openwrt x86 but I can’t, lots of errors. Could you please provide a binary or at least the script you use?

    Thanks.

  17. Ahn’Desu, you need to be more clear about what exactly you try to do.

    This is a starting point:
    https://techfindings.one/archives/1487

    Start making sure you get a simple hello_world.c program to compile and run properly.

  18. I’m trying use docker-openwrt-buildroot to build x86 Node.js, but failed with some messages:

    —-
    Download failed.
    –2017-11-04 11:19:06– http://downloads.openwrt.org/sources/linux-3.10.49.tar.xz
    Resolving downloads.openwrt.org (downloads.openwrt.org)… 78.24.191.177
    Connecting to downloads.openwrt.org (downloads.openwrt.org)|78.24.191.177|:80… connected.
    HTTP request sent, awaiting response… 404 Not Found
    2017-11-04 11:19:07 ERROR 404: Not Found.

    Download failed.
    No more mirrors to try – giving up.
    Makefile:108: recipe for target ‘/home/openwrt/openwrt/dl/linux-3.10.49.tar.xz’ failed
    make[3]: *** [/home/openwrt/openwrt/dl/linux-3.10.49.tar.xz] Error 2
    make[3]: Leaving directory ‘/home/openwrt/openwrt/toolchain/kernel-headers’
    toolchain/Makefile:86: recipe for target ‘toolchain/kernel-headers/prepare’ failed
    make[2]: *** [toolchain/kernel-headers/prepare] Error 2
    make[2]: Leaving directory ‘/home/openwrt/openwrt’
    toolchain/Makefile:85: recipe for target ‘/home/openwrt/openwrt/staging_dir/toolchain-i386_i486_gcc-4.8-linaro_uClibc-0.9.33.2/stamp/.toolchain_install’ failed
    make[1]: *** [/home/openwrt/openwrt/staging_dir/toolchain-i386_i486_gcc-4.8-linaro_uClibc-0.9.33.2/stamp/.toolchain_install] Error 2
    make[1]: Leaving directory ‘/home/openwrt/openwrt’
    /home/openwrt/openwrt/include/toplevel.mk:171: recipe for target ‘world’ failed
    make: *** [world] Error 2
    —-

    Could you please provide a binary?

    Thanks.

  19. Did you try the official Node.js binary?
    https://nodejs.org/en/download/

    It was a while since I tried to build/run Node.js on x86-OpenWrt. I could be wrong, but I thing the official binary could work.

    Otherwise, when it comes to building, I don’t know what you did but it seems your build process is downloading the linux kernel source. That seems unnecessary.

    Try the official binary. If it does not work lets talk about how to build one ourselves.

  20. I’m try the official Node.js binary but get error:

    —-
    root@X-WRT:/mnt/sda3/node-v6.11.5-linux-x86/bin# uname -a
    Linux X-WRT 3.18.29 #1 SMP Fri May 20 04:15:12 CST 2016 i686 GNU/Linux
    root@X-WRT:/mnt/sda3/node-v6.11.5-linux-x86/bin# pwd
    /mnt/sda3/node-v6.11.5-linux-x86/bin
    root@X-WRT:/mnt/sda3/node-v6.11.5-linux-x86/bin# ./node -v
    -ash: ./node: not found
    —-

  21. I download another binary, get new error:

    —-

    root@X-WRT:/mnt/sda3/node-v6.11.5-linux-x64/bin# ./node -v
    ./node: line 2: ?6?X???p??NM: not found
    ./node: ./nodeline 3: : line syntax error: unexpected “(“2:
    can’t create T?{@??@@$@@@@@?@@@@ff ff?f??w?? ?g?g??g?0@@DDP?tdd)bd)?d)?\?\?Q?td/lib64/ld-linux-x86-64.so.2GNU GNUu
    ??%?CZ$???nx???v “???A?3G

    4? ??0?”@`$???LhJ”?$??H?? (?/p??GHD?0???B?a
    E??8A& L?Ph??
    $ ??”????bI?!?P@??@??A+? J!`?A?? H@ ?
    hBL?3?(???H ? ????@ @0?cH1{
    ??: nonexistent directory
    ./node: line 2: ELF: not found

  22. Sorry for late reply mi!

    The first binary (./node not found), did you make it executable?
    $ chmod +x node

    It seems you have i686 system (32 bit), so the the first binary (./node not found) seems better than the second one (which should really not work).

  23. Yes, it executable.

    —-
    root@X-WRT:/mnt/sda3/node-v6.11.5-linux-x86/bin# pwd
    /mnt/sda3/node-v6.11.5-linux-x86/bin
    root@X-WRT:/mnt/sda3/node-v6.11.5-linux-x86/bin# ls -l
    -rwxrwxr-x 1 500 500 28770353 Oct 25 02:45 node
    lrwxrwxrwx 1 root root 38 Nov 5 11:16 npm -> ../lib/node_modules/npm/bin/npm-cli.js
    root@X-WRT:/mnt/sda3/node-v6.11.5-linux-x86/bin# ./node -v
    -ash: ./node: not found

  24. mi, indeed it is (executable).

    I think that it is either
    a) Something very stupid (like it is not executable, but I am running out of ideas)
    b) That the official exectutable really is not valid on OpenWRT

    When it comes to ARM there are different ABIs, hardfloat, softfloat, little endian, big endian and so on.

    But when it comes to x86 everything is usually very standardised since long.

    Your output from “uname -a” earlier indicated that OpenWRT is i686. And node just says x86, so it should not be a problem.

    Did you try Node 4 from here:
    https://techfindings.one/archives/2175

    I can try to build a recent (6 or 8) Node.js for OpenWRT for you, if you want?
    Anyway, try the 4.1.0 above anyway because I am curious.

    What exact version of OpenWRT (or LEDE, its so confusing) do you have?

  25. Hi zo0ok, Thanks to relay.

    I tested your built node 4.1.0 it is wroking. 😆

    —-
    root@OpenWrt:~/node/bin# ./node -v
    v4.1.0
    —-

    And my platform info:

    CPU: Intel(R) Xeon(R) CPU E3-1220 v3 @ 3.10GHz
    Firmware Version: OpenWrt Chaos Calmer 15.05.1 Built on Mar 30 2016 r49087 / LuCI for-15.05 branch (git-16.086.65079-f2ffa30)
    Kernel Version: 3.18.27

  26. mi, try 6.9.5!

  27. Sorry for late reply,

    is works for me, thanks. 😀

    —-
    root@OpenWrt:~/node/bin# ./node -v
    v6.9.5

  28. Hello,

    I’ve been trying to use node on my router. I can install this with opkg (opkg install node), node -v gives v6.11.2. But whenever I try to run a .js I get illegal instruction, no matter what I write in the code/javascript.

    something as simple as:
    console.log(‘test’)

    fails with illegal instruction.

    The router-device is an archer c7 running LEDE, mips arch -is it an ARM7-router i need?

  29. jonatan, I think you are kind of out of luck.

    I wrote about it here (read from “Building ramips/mt7620 (Archer C20i)” to the end
    https://techfindings.one/archives/2175

    And even if you could make it work, performance would be horrible.

    I can suggest (although I have not tested myself):
    – A WRT1900AC (or the same family), those should have compatible ARM chips
    – Luvit (which is much like Node, but Lua instead of JavaScript) for your device

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.