Skip to content

Instantly share code, notes, and snippets.

@evantahler
Last active June 3, 2016 22:28
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save evantahler/1574158 to your computer and use it in GitHub Desktop.
Build Node on Phidget (ARMv4tl + emdebian)

For more information, you can read a related blog post on this topic


You can now simply do:

# (turn on full debian repo; turn on ssh)

# be root
sudo su

# update your packages
apt-get update
apt-get upgrade
apt-get dist-upgrade

# get the main depian repo
echo deb ftp://ftp.dk.debian.org/debian/ sid main > /etc/apt/sources.list.d/sid.list
apt-get update

# install the new hotness
apt-get install apt
apt-get install nodejs npm curl wget htop git rsync less screen

# remove so no mangled packages get installed
rm /etc/apt/sources.list.d/sid.list
apt-get update
exit

This info is now out of date. but left for refrence

Install Node.js on an ARMv4tl Phidget Board (SBC2)

What is a Phidget SBC2?

Node is awesome, Phidgets are awesome. Syngergy. All I wanted to do was tweet the temperature of my house automatically…

What you will need:

  • A computer (or a virtual machine) running a full version of the Debian operating system
    • I used Debian 6.0.3, 64bit
  • A 1GB (or more) USB memory stick
    • The phidgetsbc2 doesn't have enough ram to compile node, so we will be using this memory stick as swap space… which is likely to destroy the memory stick
  • Internet connectivity for both your Debian computer and the Phidget board

Cross-Compile V8 Locally

The v8 stack simply won't compile on the fidget board. I think that it has to do with floating point precision, but I can't be sure. Either way, we are going to compile an ARM binary on our "big" Debian computer and copy it over:

Get codesourcery

SSH to your Debian machine, and su root

sudo mkdir /opt/codesourcery
cd /opt/codesourcery
wget http://www.codesourcery.com/sgpp/lite/arm/portal/package4571/public/arm-none-linux-gnueabi/arm-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
tar -xvf arm-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2

Get Node and build it for the Phidget board

wget http://nodejs.org/dist/v0.6.7/node-v0.6.7.tar.gz
tar -xvf node-v0.6.7.tar.gz
cd node-v0.6.7/deps/v8
export TOOL_PREFIX=/opt/codesourcery/arm-2009q1/bin/arm-none-linux-gnueabi
export CXX=$TOOL_PREFIX-g++
export AR=$TOOL_PREFIX-ar
export RANLIB=$TOOL_PREFIX-ranlib
export CC=$TOOL_PREFIX-gcc
export LD=$TOOL_PREFIX-ld
export CCFLAGS="-march=armv4 -mno-thumb-interwork"
OR>> export CCFLAGS="-march=armv4 -mno-thumb-interwork -mtune=xscale -mno-thumb -mfloat-abi=soft -mfpu=maverick"
export ARM_TARGET_LIB=/opt/codesourcery/arm-2009q1/arm-none-linux-gnueabi/libc

scons armeabi=soft wordsize=32 snapshot=off arch=arm library=shared mode=release 
scons armeabi=soft wordsize=32 snapshot=off arch=arm library=shared mode=release sample=shell

Copy the entire v8 directory to the memory stick I was running Debian in a virtual machine on my OSX machine, so I rSync'ed it

  • rsync -avz root@{remote_host_ip}:/root/node-v0.6.7/deps/v8 /Volumes/{memory_stick}/node

Update the Phidget Board

New Firmware

Config (via web interface)

Local Configuration (via SSH) on the Phidget board

ssh root@phidgetsbc.local
apt-get update
apt-get -u upgrade
apt-get install gcc wget python openssl make scons libssl-dev libax25 libfile-copy-recursive-perl openbsd-inetd tcpd update-inetd python-software-properties pkg-config htop git subversion

Copy over and configure V8

Plug in the USB drive. I kept the now-compiled V8 source in /node/v8 on the memory stick

export PATH=$PATH:/opt/bin
echo "/opt/lib" >> /etc/ld.so.conf
ldconfig
mkdir /opt/share/v8
cp -a /media/{usb_stick_usb_path}/node/v8 /opt/share/.
echo "/opt/share/v8" >> /etc/ld.so.conf
ldconfig

##Add more RAM This is likely to destroy the memory stick after a lot of use (USB hates random I/O). Create a swap file and configure it (will take ~10 min)

dd if=/dev/zero of=/media/usb0/swapfile bs=1M count=256
mkswap /media/usb0/swapfile
swapon /media/usb0/swapfile

Node.js

export JOBS=1
export CC='gcc -march=armv4 -mfloat-abi=soft'
export CCFLAGS='-march=armv4 -mfloat-abi=soft'
export CXX='g++ -march=armv4 -mfloat-abi=soft'
export GCC='-march=armv4 -mfloat-abi=soft'
wget http://nodejs.org/dist/v0.6.7/node-v0.6.7.tar.gz
tar -xvf node-v0.6.7.tar.gz
rm node-v0.6.7.tar.gz
cd node-v0.6.7
./configure --shared-v8 --shared-v8-libpath=/opt/share/v8 --shared-v8-includes=/opt/share/v8/include --without-snapshot 
	## If the configuration isn't all green, something is wrong
make
make install

Note: For me, a few times various parts of the 35 steps make preforms will crash with a segmentation fault. I guess this has to do with ram? Make will resume where you left off last, so just run it again

NPM

  • curl http://npmjs.org/install.sh | sh

##Contributors to this guide:

@WarheadsSE
Copy link

We used this as a pointer to build v8 & then use shared v8 in nodejs on Arch Linux ARM. Thanks for this! (v8 scons via node's waf hates hardfloat ;) )

@evantahler
Copy link
Author

Happy to help!

@RIAEvangelist
Copy link

Very cool, I can't wait to try with my fork of your original InterfaceKit code.
https://github.com/RIAEvangelist/nodePhidgetAPI

@evantahler
Copy link
Author

Hey @RIAEvangelist - want to merge our branches and update the published repo on NPM? http://search.npmjs.org/#/phidgets

@RIAEvangelist
Copy link

I would love to, but I am not sure about the npm process and how to best merge our stuff, because of how much I changed your original code. This would be my first time doing this sort of thing. Gosh, I forgot what it feels like to be a noob.

@evantahler
Copy link
Author

evantahler commented Jun 11, 2012 via email

@RIAEvangelist
Copy link

RIAEvangelist commented Jun 11, 2012 via email

@jamesfolk
Copy link

Hello! I successfully followed your steps to install npm, thanks!
I am trying to install bleno (https://github.com/sandeepmistry/bleno)

I am getting the following errors....

root@phidgetsbc:/usr/bin# npm install bleno
npm WARN optional dep failed, continuing xpc-connection@0.1.4
|

usb@1.0.6 install /usr/bin/node_modules/bleno/node_modules/bluetooth-hci-socket/node_modules/usb
node-pre-gyp install --fallback-to-build

/usr/bin/env: node: No such file or directory
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm WARN optional dep failed, continuing usb@1.0.6

bluetooth-hci-socket@0.3.3 install /usr/bin/node_modules/bleno/node_modules/bluetooth-hci-socket
node-gyp rebuild

/bin/sh: 1: node: not found
gyp: Call to 'node -e "require('nan')"' returned exit status 127. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: gyp failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/share/node-gyp/lib/configure.js:344:16)
gyp ERR! stack at ChildProcess.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:820:12)
gyp ERR! System Linux 3.14.27
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /usr/bin/node_modules/bleno/node_modules/bluetooth-hci-socket
gyp ERR! node -v v0.10.38
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm WARN optional dep failed, continuing bluetooth-hci-socket@0.3.3
bleno@0.2.1 node_modules/bleno
├── bplist-parser@0.0.6
└── debug@2.2.0 (ms@0.7.1)

Do you have any suggestions? Thanks!

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