Monthly Archives: January 2017

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

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 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.

Märklin Z steam locomotives

I have a Märklin Z model railroad layout and I have found Ebay a good place to buy locomotives. Märklin has a limited number of models available brand new, and the line changes every year. For different reasons you might want to buy a locomotive that is not available from Märklin this year. This is quite fine because the locomotives last very long (if not mistreated), old models are even available (on Ebay) brand new, and since they are small shipping is trivial and cheap.

However, when I was browsing available items on Ebay I got confused after a while! What was that model I liked? What item number did it have? Are there other item numbers that look the same? That made me put together a simple list and I used my Märklin catalogues from 1996-2016 (I have about half of them) as information source. I have limited myself to steam locomotives and Z scale.

Märklin manufacturing and tooling
When Märklin wants to offer a new model they invest in tooling for it. That obviously cost money. They then use that tooling to produce different versions of that locomotive for a shorter or longer period of time. Typically a standard (black BR/DR/DRG) version made available for several years. Then there are special versions (Insider members only, anniversary editions, or other company versions: Baden, Prussia, Bavaria and so on) available just a year or two. Finally, the tooling is retired, and the model is withdrawn unless new tooling is developed.

My List
My list is based on locomotive types. Look at the DRG 18.1: it has been available as different Märklin items for BR and Bavaria (as S3/6) for most of the time. During a few years, there was also a Wurtenburg edition (88180).

Model numbers prefixed with S are Start sets (coming with transformer, tracks and wagons).
Model numbers prefixed with T are Train sets (coming with matching wagons).

Disclaimers
I am confused with this BR/DR/DRG thing! I understand the German national railway company has had different names over the 20th century, but Märklin is not using BR/DR/DRG consistently over the years for the same models, so my list is also a mess. I am thinking about just writing BR or “German Black” everywhere. Feel free to suggest how to deal with this!

I have not had access to every catalogue since 1996, so there are definitely items missing.

Some models have been coming and going over the years. If my list says 1998-2016 it does not mean the model was available every single year. It just means that during the period of time this locomotive model was available as different Märklin items (many of them just a single year). Märklin had some bad years when they went bancrupt, the Z scale was rumoured to be eliminiated, production was moved to China, and eventually it was moved back again. These years very few items were available.

The purpose of the list is not to follow individual item numbers (when they were introduced and discontinued) but rather to show what steam locomotives have been made available as a Märklin Z item, the time it was available, and relevant item numbers.

Model Wheels Arrangement Available Märklin Items
Passenger tender
BR 001 4-6-2+8 2012 88010
BR 003 4-6-2+8 1994-2012 8885 88851 88852 88854 88855
DR 03.10 4-6-2+8 1994-1998 8886 8890 88861
BR 10 4-6-2+8 1994-2006 8889 8888 88892 88893
DRG 18.1
S 3/6 Bav
Wurt
4-6-2+8 1996-2016
1994-2016
1996-2000
88181 88183 88184 T:81426
8892 88921 88923 S:81781
88180
DRG 18.4 4-6-2+8 1994-1998 2003 T:8833 T:8108 T:81331
BR 24 2-6-0+6 1994-2012 8803 88030 S:81560
BR 38
P8 Baden
4-6-0+6 1994-2002
2000 2010-2011
8899 88991
88999 T:81420
BR 39
P10 Prus
2-8-2+8 2005-2006 2012
2003 2007
88090 88092 T:81362
88091 88093
Freight tender
BR 41 2-8-2+8 1994-2012 8827 88271 88274 S:81780 T:81361
DB 042 4-6-2+8 2006 88272
BR 42.90 2-10-0+8 2003-2006 88040 88041
BR 44 2-10-0+8 2010-2012 88972 88973
BR 50 2-10-0+8 1994-2016 8884 8154 88841 88842 88843 S:81863 S:81864
BR 52 2-10-0+8 1998-2016 8883 88830 88831 88836
DGR 53.0 0-6-8-0+6-4 2007 88053
DB 55.25
G 8.1 Prus
0-8-0+6 1998-2000 2014
1998-2002
88980 88984
88981 88982
DB 58
G 12 Prus
G 12 Wurt
G 12 Baden
0-10-0+6 2005-2010
2006
2006
2010-2011
88121 88123
88122
88120
88124
Passenger tank
BR 61 4-6-4 2010-2011 88610
DRG 64 2-6-2 2016 88740 88741
BR 74
T 9 Wurt
2-6-0 1994-2016
2005-2006
8895 88951 88593 S:8158 S:81562
88952
BR 78 4-6-4 1994-2012 8806 88062 T:81191
T 18 Prus
T 18 Wurt
4-6-4 1994
1998-2000
T:8119
88061
Freight tank
BR 80 0-6-0 2016 81352
BR 85 2-10-2 2002-2006 88885 88886 88887
BR 86 2-8-2 1994-2012 8896 88961 T:81001
BR 89 0-6-0 1994-2016 8805 88051 S:8150 S:8180 S:81520 S:81521 S:81522 S:88569 T:8138
DRG 94
T 16.1 Prus
0-10-0 2010-2012
2010-2012
88942 88943
88941
DRG 96 0-8-8-0 2005-2016 88290 88291 88294
USA
Mogul 2-6-0+8 2005-2006 88035
Mikado 2-8-2+8 1994-2012 8807 S:81461 S:81466 S:81830 T:88812
Pacific 4-6-2+8 1994-2006 8810 T:8881 T:8882 T:88811 S:81530
Belgium
81 (BR55) 0-8-0+6 2002 88983
96 (BR74) 2-6-0 2016 88964
France
SNCF 130 (BR74) 2-6-0 2016 88956
SNCF 150 2-10-0+8 1998 88833
SNCF 232 4-6-4 2003-2005 88063
Switzerland
A3/5 4-6-0+6 2005-2007 88992 T:81035

Please comment below if you want this list to be corrected!