Archive for July, 2013

How to use NodeJS to implement a webserver in Ubuntu?

If your Ubuntu is completely freshly installed, then it is necessary to install a lot of development-related accessories:

http://davidtsadler.com/archives/2012/05/06/installing-node-js-on-ubuntu/

Alternatively the fastest way to install NodeJS, is to get from the NodeJS development site:

git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install

And "node" will be installed into the /usr/local/bin directory by default.

In Ubuntu, as the following article described:

http://stackoverflow.com/questions/16302436/install-nodejs-on-ubuntu-12-10

You can also use "apt-get install nodejs" to install NodeJS – but it is not the latest version. Eg, for Ubuntu 32-bit 12.04.2 LTS, the version seemed to be 0.6.12, which is not able to install "express".

/usr/bin/node -v
v0.6.12

For /usr/local/bin/node -v:
v0.11.5-pre

And note that node is not nodejs:

http://superuser.com/questions/335273/installing-node-js-after-apt-get-install-node

(but /usr/local/bin/node binary is for NodeJS :-)).

Now install npm’s package called "express" by "npm install express" (npm is part of the NodeJS installation):

(More information is available here: https://npmjs.org/package/express)

...
...
npm http 200 https://registry.npmjs.org/qs/0.6.5
npm http GET https://registry.npmjs.org/qs/-/qs-0.6.5.tgz
npm http 200 https://registry.npmjs.org/bytes/0.2.0
npm http GET https://registry.npmjs.org/bytes/-/bytes-0.2.0.tgz
npm http 200 https://registry.npmjs.org/formidable/1.0.14
npm http GET https://registry.npmjs.org/formidable/-/formidable-1.0.14.tgz
npm http 200 https://registry.npmjs.org/uid2/0.0.2
npm http GET https://registry.npmjs.org/uid2/-/uid2-0.0.2.tgz
npm http 200 https://registry.npmjs.org/mime/-/mime-1.2.9.tgz
npm http 200 https://registry.npmjs.org/pause/-/pause-0.0.1.tgz
npm http 200 https://registry.npmjs.org/keypress/-/keypress-0.1.0.tgz
npm http 200 https://registry.npmjs.org/qs/-/qs-0.6.5.tgz
npm http 200 https://registry.npmjs.org/bytes/-/bytes-0.2.0.tgz
npm http 200 https://registry.npmjs.org/formidable/-/formidable-1.0.14.tgz
npm http 200 https://registry.npmjs.org/uid2/-/uid2-0.0.2.tgz
express@3.3.4 node_modules/express
├── methods@0.0.1
├── fresh@0.1.0
├── cookie-signature@1.0.1
├── cookie@0.1.0
├── debug@0.7.2
├── buffer-crc32@0.2.1
├── range-parser@0.0.4
├── mkdirp@0.3.5
├── send@0.1.3 (mime@1.2.9)
├── commander@1.2.0 (keypress@0.1.0)
└── connect@2.8.4 (uid2@0.0.2, pause@0.0.1, qs@0.6.5, bytes@0.2.0, formidable@1.0.14)

Next is to write the following script and named it as "server.js":

var fs = require(“fs”);
var host = “127.0.0.1”;
var port = 1337;
var express = require(“express”);

var app = express();
app.use(app.router); //use both root and other routes below
app.use(express.static(__dirname + “/public”)); //use static files in ROOT/public folder

app.get(“/”, function(request, response){ //root dir
response.send(“Hello!!”);
});

app.listen(port, host);

Or another alternative piece of code:

var http = require(‘http’);
http.createServer(function (req, res) {
res.writeHead(200, {‘Content-Type’: ‘text/plain’});
res.end(‘Hello World\n’);
}).listen(1337, ‘127.0.0.1’);
console.log(‘Server running at http://127.0.0.1:1337/’);

And then followed by "node server.js" to execute the javascript and a port at 1337 will be opened up. Use a browser to go to http://localhost:1337/ and you will be welcomed with a "Hello" message. (NOTE: both the piece of javascript code above are definitely not mine originally :-)).

Beagleboard XM running Ubertooth installation howto

For installing Ubuntu 12.10 on the Beagleboard-XM, goto:

http://www.brianhensley.net/2013/01/beagleboard-xm-how-to-install-ubuntu.html

Essentially using Linux PC, go to:

http://rcn-ee.net/deb/rootfs/quantal/

and get the latest image.

Untar the image ("xz -d" and followed by "tar xvf"):

xz -d ubuntu-12.10-console-armhf-2013-06-14.tar.xz
tar xvf ubuntu-12.10-console-armhf-2013-06-14.tar

and then insert an empty sdcard (or ready to be overwritten) into the Linux PC, and enter the following command at the directory where the image above has been untar:

(please read the script setup_sdcard.sh to confirm all the following inputs are correct)

./setup_sdcard.sh –mmc /dev/sdX –uboot beagle_xm

The /dev/sdX above should be virtual device disk where the sdcard has been recognized by the filesystem (discoverable via "dmesg"), should be at the whole disk level, not partition level, and the entire sdcard should not mounted into any directory. Be careful with this operation, as it will be over-writing the entire sdcard with one image that have two partition (after "setup_sdcard.sh" has complete formatted the sdcard):

fdisk -l /dev/sdb

Disk /dev/sdb: 3963 MB, 3963617280 bytes
4 heads, 16 sectors/track, 120960 cylinders, total 7741440 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e1939

Device Boot Start End Blocks Id System
/dev/sdb1 * 2048 133119 65536 e W95 FAT16 (LBA)
/dev/sdb2 133120 7741439 3804160 83 Linux

First partition is vfat-formatted, and second partition is ext4-formatted.

Remember, if "/dev/sdX" is supplied wrongly you may be over-writing the entire harddisk instead. But there will be a confirmation page before the actual image-writing operation.

After the sdcard image has been properly created, removed it and insert it into Beagleboard-XM, and now connect the USB power cable to the Beagleboard, and then the FTDI-USB cable to the DB9 serial port of the Beagleboard-XM to the USB port of the Linux PC.

Do a "lsusb" or "dmesg" to find out the device driver for the FTDI-USB cable (normally should be /dev/ttyUSB0). Then use "minicom" (or any other hyperterminal software) to connect to the port at /dev/ttyUSB0.

Serial interface setting is 115200, 8N1, no hardware and software flow control.

Through this minicom connection we can see how the system bootup:

http://pastebin.com/qFf6H0b5

and finally will be presented with a login screen:

login: ubuntu
Password:
Welcome to Ubuntu 12.10 (GNU/Linux 3.7.10-x12 armv7l)

The default password is "temppwd" as mentioned immediately after the image is created on the sdcard.

After login as root, we can see how the system is partitioned:

root@arm:~# df

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mmcblk0p2 3744336 581936 2972192 17% /
udev 233832 4 233828 1% /dev
tmpfs 97520 224 97296 1% /run
none 5120 0 5120 0% /run/lock
none 243792 0 243792 0% /run/shm
none 102400 0 102400 0% /run/user
/dev/mmcblk0p1 65390 11028 54362 17% /boot/uboot

root@arm:~# cat /etc/lsb-release

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.10
DISTRIB_CODENAME=quantal
DISTRIB_DESCRIPTION="Ubuntu 12.10"

Now is to connect up the ethernet cable to the network (with DHCP running somewhere):

dhclient eth0

The above will get an IP address, and do a "apt-get update" to update all the APT resource database, and then install the essential compilation utilities:

apt-get install build-essential
apt-get install

But before this can be done, I got consistent segfaulting of "apt-get install", so I suspect the APT database is corrupted post-installation, so perhaps clear the APT cache first:

cd /var/cache/apt
mv pkgcache.bin srcpkgcache.bin /tmp

and do a "apt-get update" to create a new cache.

Next: HOW TO INSTALL THE Ubertooth software?

We can follow the instructions given at:


http://www.geektheory.ca/blog/ubertooth-raspberry-pi-uberpi/

Essentially download the libbtbb-2012-10-R3.tar.xz and ubertooth-2012-10-R1.tar.xz from here:

http://sourceforge.net/projects/libbtbb/?source=directory
http://sourceforge.net/projects/ubertooth/?source=directory

xz -d libbtbb-2012-10-R3.tar.xz
tar tvf libbtbb-2012-10-R3.tar
cd libbtbb-2012-10-R3
make
make install

And I did install into another directory as well:

INSTALL_DIR=/usr/local/lib INCLUDE_DIR=/usr/local/include make install

After untaring the "ubertooth-2012-10-R1.tgz, cd to "host", and move the "bluetooth_rxtx" to the "/usr/src" directory:

cd ubertooth-2012-10-R1
cd host/
mv bluetooth_rxtx/ /usr/src/
cd /usr/src/bluetooth_rxtx/
make

cc -O2 -Wall -fPIC -c ubertooth.c ubertooth_control.c
In file included from ubertooth.h:25:0,
from ubertooth.c:31:
ubertooth_control.h:28:31: fatal error: libusb-1.0/libusb.h: No such file or diy
compilation terminated.
In file included from ubertooth_control.c:24:0:
ubertooth_control.h:28:31: fatal error: libusb-1.0/libusb.h: No such file or diy
compilation terminated.
make: *** [libubertooth.so.0.1] Error 1

The above error can be corrected by:

apt-get install libusb-dev libusb-1.0.0-dev

apt-get install libftdi1 libftdi-dev

After the Ubertooth has been installed, test out the utilities:

ubertooth-dump etc etc.

References:

https://wiki.ubuntu.com/ARM/OmapDesktopInstall

http://elinux.org/BeagleBoardUbuntu

http://www.brianhensley.net/2013/01/beagleboard-xm-how-to-install-ubuntu.html

Running bare metal blinker code on Raspberry Pi

Instead of running Linux on RPi, it is better to write the smallest code to run on RPi, so that we can learn how to control the individual CPU feature directly, or learn about the internal clocking mechanism on RPi, or how to do direct I/O via DMA on RPi etc etc.

Steps are as follows (all steps described here are based on Ubuntu 12.04 environment):

1. Make a primary partition on an SD Card via “fdisk /dev/sdX” if the SD Card is mounted as /dev/sdX, for myself the partition is sized at 40MB, too small seemed to have problem being automatically mounted in Ubuntu environment.

2. “mkfs.vfat /dev/sdX1” to format the newly created partition (from step 1) as vfat.

*** BE CARE HERE, running “mkfs.vfat /dev/your_hard_disk” and you will destroy your harddisk.***

3. “fdisk /dev/sdX” and change the “partition system id” to “c”, which is ” W95 FAT32 (LBA)”. This part is crucial, without which the RPi never seemed to automatically recognize the SDcard?

fdisk /dev/sdb

Command (m for help): p

Disk /dev/sdb: 3959 MB, 3959422976 bytes
37 heads, 8 sectors/track, 26125 cylinders, total 7733248 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdaed00d7

Device Boot Start End Blocks Id System
/dev/sdb1 2048 83967 40960 c W95 FAT32 (LBA)

Command (m for help):

4. Copy the following files into the new partition:

bootcode.bin
fixup_cd.dat
fixup_x.dat
kernel_emergency.img
kernel.img
start_cd.elf
start.elf
start_x.elf

these files can be downloaded from below:

https://github.com/Hexxeh/rpi-firmware

https://github.com/raspberrypi/firmware/tree/master/boot

And for the bare metal codes, it is derived from here below:

https://github.com/dwelch67/raspberrypi

These files come as binary + source. If recompilation is desired, then just make sure that the ARM toolchain (eg, Code Sourcery from Mentor Graphics) is in the PATH environment variable.

For example:

which arm-none-eabi-ld

and the output:

/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/arm-none-eabi-ld

For the first blinker01:

make clean

and output:

rm -f *.o
rm -f *.bin
rm -f *.hex
rm -f *.elf
rm -f *.list
rm -f *.img
rm -f *.bc
rm -f *.clang.opt.s

After downloading and unpacking, “cd” to one of the sample directory and attempt compilation:

cd raspberrypi-master/blinker01>make

and output:

arm-none-eabi-as vectors.s -o vectors.o
arm-none-eabi-gcc -Wall -O2 -nostdlib -nostartfiles -ffreestanding -c blinker01.c -o blinker01.o
arm-none-eabi-ld vectors.o blinker01.o -T memmap -o blinker01.elf
arm-none-eabi-objdump -D blinker01.elf > blinker01.list
arm-none-eabi-objcopy blinker01.elf -O ihex blinker01.hex
arm-none-eabi-objcopy blinker01.elf -O binary blinker01.bin

Just copying “blinker01.bin” over to the SD card’s partition as “kernel.img” as the new filename, and you will be able to see the green ACT light blinking non-stop on the RPi.

Next target is to flash the ChibiOS on the SD card over-riding kernel.img:

http://www.stevebate.net/chibios-rpi/GettingStarted.html

Downloading and compiling the ChibiOS-RPi/demos/ARM11-BCM2835-GCC/

make
Compiler Options
arm-none-eabi-gcc -c -mcpu=arm1176jz-s -O2 -ggdb -fomit-frame-pointer -ffunction-sections -fdata-sections -Wall -Wextra -Wstrict-prototypes -Wa,-alms=build/lst/ -mno-thumb-interwork -MD -MP -MF .dep/build.d -I. -I../../os/ports/GCC/ARM -I../../os/ports/GCC/ARM/BCM2835 -I../../os/kernel/include -I../../test -I../../os/hal/include -I../../os/hal/platforms/BCM2835 -I../../boards/RASPBERRYPI_MODB -I../../os/various main.c -o main.o

mkdir -p build/obj
mkdir -p build/lst
Compiling ../../os/ports/GCC/ARM/crt0.s
Compiling ../../os/ports/GCC/ARM/chcoreasm.s
Compiling ../../os/ports/GCC/ARM/BCM2835/vectors.s
Compiling ../../os/ports/GCC/ARM/chcore.c
Compiling ../../os/kernel/src/chsys.c
Compiling ../../os/kernel/src/chdebug.c
Compiling ../../os/kernel/src/chlists.c
Compiling ../../os/kernel/src/chvt.c
Compiling ../../os/kernel/src/chschd.c
Compiling ../../os/kernel/src/chthreads.c
Compiling ../../os/kernel/src/chdynamic.c
Compiling ../../os/kernel/src/chregistry.c
Compiling ../../os/kernel/src/chsem.c
Compiling ../../os/kernel/src/chmtx.c
Compiling ../../os/kernel/src/chcond.c
Compiling ../../os/kernel/src/chevents.c
Compiling ../../os/kernel/src/chmsg.c
Compiling ../../os/kernel/src/chmboxes.c
Compiling ../../os/kernel/src/chqueues.c
Compiling ../../os/kernel/src/chmemcore.c
Compiling ../../os/kernel/src/chheap.c
Compiling ../../os/kernel/src/chmempools.c
Compiling ../../test/test.c
Compiling ../../test/testthd.c
Compiling ../../test/testsem.c
Compiling ../../test/testmtx.c
Compiling ../../test/testmsg.c
Compiling ../../test/testmbox.c
Compiling ../../test/testevt.c
Compiling ../../test/testheap.c
Compiling ../../test/testpools.c
Compiling ../../test/testdyn.c
Compiling ../../test/testqueues.c
Compiling ../../test/testbmk.c
Compiling ../../os/hal/src/hal.c
Compiling ../../os/hal/src/adc.c
Compiling ../../os/hal/src/can.c
Compiling ../../os/hal/src/ext.c
Compiling ../../os/hal/src/gpt.c
Compiling ../../os/hal/src/i2c.c
Compiling ../../os/hal/src/icu.c
Compiling ../../os/hal/src/mac.c
Compiling ../../os/hal/src/mmc_spi.c
Compiling ../../os/hal/src/mmcsd.c
Compiling ../../os/hal/src/pal.c
Compiling ../../os/hal/src/pwm.c
Compiling ../../os/hal/src/rtc.c
Compiling ../../os/hal/src/sdc.c
Compiling ../../os/hal/src/serial.c
Compiling ../../os/hal/src/serial_usb.c
Compiling ../../os/hal/src/spi.c
Compiling ../../os/hal/src/tm.c
Compiling ../../os/hal/src/uart.c
Compiling ../../os/hal/src/usb.c
Compiling ../../os/hal/platforms/BCM2835/hal_lld.c
Compiling ../../os/hal/platforms/BCM2835/pal_lld.c
Compiling ../../os/hal/platforms/BCM2835/serial_lld.c
Compiling ../../os/hal/platforms/BCM2835/i2c_lld.c
Compiling ../../os/hal/platforms/BCM2835/spi_lld.c
Compiling ../../os/hal/platforms/BCM2835/gpt_lld.c
Compiling ../../os/hal/platforms/BCM2835/pwm_lld.c
Compiling ../../os/hal/platforms/BCM2835/bcm2835.c
Compiling ../../boards/RASPBERRYPI_MODB/board.c
Compiling ../../os/various/shell.c
Compiling ../../os/various/chprintf.c
Compiling main.c
Linking build/ch.elf
Creating build/ch.hex
Creating build/ch.bin
Creating build/ch.dmp
Done

Now go to the subdirectory “build” and “ls -l”

20 -rwxrwxr-x 1 tthtlc tthtlc 17204 Jul 7 09:14 ch.bin
1340 -rw-rw-r– 1 tthtlc tthtlc 1371159 Jul 7 09:14 ch.dmp
140 -rwxrwxr-x 1 tthtlc tthtlc 169545 Jul 7 09:14 ch.elf
48 -rw-rw-r– 1 tthtlc tthtlc 48430 Jul 7 09:14 ch.hex
160 -rw-rw-r– 1 tthtlc tthtlc 163487 Jul 7 09:14 ch.map
4 drwxrwxr-x 2 tthtlc tthtlc 4096 Jul 7 09:14 lst
4 drwxrwxr-x 2 tthtlc tthtlc 4096 Jul 7 09:14 obj

Copy the “ch.bin” into SDcard’s and override the “kernel.img” and you should see another infinitely blinking ACT green light (on the RPi Model B).

Vickblöm

Research scattered with thoughts, ideas, and dreams

Penetration Testing Lab

Offensive Techniques & Methodologies

Astr0baby's not so random thoughts _____ rand() % 100;

@astr0baby on Twitter for fresh randomness

The Data Explorer

playing around with open data to learn some cool stuff about data analysis and the world

Conorsblog

Data | ML | NLP | Python | R

quyv

Just a thought

IFT6266 - H2017 Deep Learning

A Graduate Course Offered at Université de Montréal

Deep Learning IFT6266-H2017 UdeM

Philippe Paradis - My solutions to the image inpainting problem

IFT6266 – H2017 DEEP LEARNING

Pulkit's thoughts on the course project

Thomas Dinsmore's Blog

No man but a blockhead ever wrote except for money -- Samuel Johnson

the morning paper

a random walk through Computer Science research, by Adrian Colyer

The Spectator

Shakir's Machine Learning Blog