Sunday, January 15, 2012

Testing beagleboard GPIO

Note: Beagleboard C2 use 1.8V for the expansion socket. Do not use higher voltage it may break your processor.

We will use expansion pin 22 (GPIO 157, see Beagleboard reference manual). Connect positive pin of led (long leg) to this port, and then the negative pin led (short leg) to expansion pin 28.
Goto folder /sys/class/gpio/export. There shouldn't be a folder named gpio157.

We need to open the GPIO:
$ echo 157 > /sys/class/gpio/export

Then set the gpio high
$ echo 1 > /sys/class/gpio157/value

or set the gpio low
$ echo 0 > /sys/class/gpio157/value

Finally close the GPIO
$ echo 157 > /sys/class/gpio157/unexport


More reading: http://blog.makezine.com/2009/02/03/blinking-leds-with-the-beagle-board/

Create Minimal Linux 3.2

Create minimal Linux 3.2 with Buildroot 2011.11 for Beagleboard rev C2
1. Get Linux kernel 3.2 from www.kernel.org
2. Get Buildroot 2011.11 from www.buildroot.net
Unpack both package.

Build Buildroot:

$ make menuconfig

1. Target architechture arm, Variant cortex A-8
2. Toolchain Type external arm-none-linux-gnueabi gcc version 4.5.2 (Sourcery G++ Lite 2011.03-41)
3. System Configuration -> /dev management use devtmpfs ( Kernel should also enable DEV_TMPFS=y and DEV_TMPFS_MOUNT=y). This is a must otherwise you may got boot error "can't open /dev/ttyO2: No such file or directory"
4. Change serial port from ttyS2 to ttyO2 (this is for Omap processor)
5. Then select package.

After finish in configuration run:
$ make

Toolchain will be downloaded to output/host/usr/bin You must add this in your PATH before compiling the kernel
$ export PATH=${BUILDROOT}/output/host/usr/bin:$PATH

BUILDROOT: This is your buildroot installation folder.

Build kernel:

$make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi omap2plus_defconfig
$make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi menuconfig
$make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi -j2 uImage
$make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi modules
$make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi modules_install INSTALL_MOD_PATH=/home/user/kernel_dev/buildroot-2011.11/output/target

after that copy your rootfs to your sd card.
$cd /home/user/kernel_dev/buildroot-2011.11/output/target
$rsync -avr * /media/rootfs

Note:
You must change your buildroot folder and your rootfs partition in your sd card.


Note: When configuring kernel don't forget to change ttyS2 to ttyO2.
after running make menuconfig. edit .config and modify DEV_TMPFS and DEV_TMPFS_MOUNT. You have to enable it.

Thursday, January 12, 2012

How to create swap file

Create 1 GB swapfile

dd if=/dev/null of=/swapfile/swapfile.1 bs=1024 count=1048576
mkswap /swapfile/swapfile.1
swapon /swapfile/swapfile.1


To turnoff swap file use


swapoff /swapfile/swapfile.1


Check your memory:
free -m

Use swapon -s to list swapfile in your sytem

You can also add entry in /etc/fstab
/swapfile       none    swap    sw      0       0

and use swapon -a to activate all swapfile


change the /swapfile/swapfile.1 permissions
sudo chmod utgo+rw /swapfile/swapfile.1

Basic NAT with iptables

Assume: eth0 is going to Internet (public), eth1 is going to LAN (internal)

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_froward"


# Masquerade will alter ip address
# /sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# Only related and established packet allowed to internal network
# /sbin/iptables -A FORWARD -i eth0 -o eth1 -m state
   --state RELATED,ESTABLISHED -j ACCEPT

# Allow all packet (new connection) from internal to public network
# /sbin/iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT




More iptables script from http://ubuntuforums.org/showthread.php?t=1905018





PATH=/usr/sbin:/sbin:/bin:/usr/bin

#
# delete all existing rules.
#
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

# Always accept loopback traffic
iptables -A INPUT -i lo -j ACCEPT


# Allow established connections, and those not coming from the outside
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i ethwan -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i ethwan -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow services
iptables -A INPUT -p tcp --dport 22 -j ACCEPT                #ssh
iptables -A INPUT -p udp -i eth0 --dport 53 -j ACCEPT        #dns
iptables -A INPUT -p udp -i eth1 --dport 53 -j ACCEPT        #dns
iptables -A INPUT -p udp -i eth0 --dport 67 -j ACCEPT        #dhcp
iptables -A INPUT -p udp -i eth1 --dport 67 -j ACCEPT        #dhcp
iptables -A INPUT -p tcp -s 128.173.14.84 --dport 137 -j ACCEPT
iptables -A INPUT -p tcp -s 128.173.14.84 --dport 138 -j ACCEPT
iptables -A INPUT -p tcp -s 128.173.14.84 --dport 139 -j ACCEPT
iptables -A INPUT -p tcp -s 128.173.14.84 --dport 445 -j ACCEPT

# Setup Forwarding between interfaces (all none listed are blocked)
iptables -A FORWARD -i eth0 -o ethwan -j ACCEPT
iptables -A FORWARD -i eth1 -o ethwan -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

# Masquerade.
iptables -t nat -A POSTROUTING -o ethwan -j MASQUERADE

# Don't forward from the outside to the inside.
iptables -A INPUT -j DROP
iptables -A FORWARD -j DROP

# Save the new rules
iptables-save > /etc/iptables.rules

Monday, January 9, 2012

Pandaboard ES as Master Mode (AP) not working

I was happy yesterday because I can set my Pandaboard ES as wireless router, but when I tried to send large file, it stopped without crash. Then I plugged my usb host with Ralink rt2800 chipset, it looks like working fine. I will test it further.

Currently I think the WiFi driver is the problem.
I'll share the software information later.

Cross Compile CCNx to Pandaboard ES

I'm trying to cross compile CCNx-0.4.2 but still having difficulty, I think I need to run init-key-helper but it always fail.  I cannot run ccnput too, it always fail encode ccnb.
To cut unnecessary overhead in this work, I compiled CCNx code directly in my pandaboard using ubuntu :)

Anyway this is the steps I have done so far:

1. Download CCNx 0.4.2 from http://www.ccnx.org
2. Dowload openssl-1.0.0d from http://www.openssl.org
3. Download expat-2.0.1

Unzip CCNx and create new folder 'external':
Unzip openssl and expat to this external folder, it will become like this:
CCNx-0.4.2/
-external/
--openssl--0.4.2/
--expat-2.0.1/

create a target folder in ccnx root folder:

mkdir -p target/arm/usr/local


Cross compile each external components:
1. Cross compile openssl



./config no-asm
make CC=arm-linux-gnueabi-gcc AR="arm-linux-gnueabi-ar r" RANLIB="arm-linux-gnueabi-ranlib"
make INSTALL_PREFIX=/home/yeffry/ccnx-0.4.2/target/arm/usr/local


or



./config no-asm --openssldir=$HOME/ccnx-0.4.2/target/arm/usr/local
make CC=arm-linux-gnueabi-gcc AR="arm-linux-gnueabi-ar r" RANLIB="arm-linux-gnueabi-ranlib"
make install


If you got problem compiling ccnx with error from openssl dso, try config openssl with no-dso options.

You could also modify the CC, AR and RANLIB in Makefile

Now openssl will be installed in your $HOME/ccnx-0.4.2/target/arm

2. Cross compile expat



./configure --host=arm-linux-gnueabi --prefix=$HOME/ccnx-0.4.2/target/arm/usr/local
make
make install


3. Cross compile libpcap



./configure --host=arm-linux-gnueabi --prefix=$HOME/ccnx-0.4.2/target/arm/usr/local --with-pcap=linux
make
make install


Now let's compile ccnx:
in ccnx root folder run:


./configure
./make

Create A WiFi Router

Package needed:

hostapd
dhcp server
ip tables

Get hostapd:
sudo apt-get install hostapd

Edit or create /etc/hostapd/hostapd.conf
ctrl_interface=/var/run/hostapd
#ctrl_interface_group=wheel

# Some usable default settings...
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0

# Uncomment these for base WPA & WPA2 support with a pre-shared key
#wpa=3
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP
#rsn_pairwise=CCMP

# DO NOT FORGET TO SET A WPA PASSPHRASE!!
#wpa_passphrase=YourPassPhrase

# Most modern wireless drivers in the kernel need driver=nl80211
driver=nl80211

# Customize these for your local configuration...
interface=wlan0
hw_mode=g
channel=1
ssid=LinuxReaders

macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=linuxreaderscom
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

To start hostapd:
sudo hostapd -d /etc/hostapd/hostapd.conf

Get Dhcp server:
sudo apt-get install isc-dhcp-server

Edit or create dhcpd.conf
sudo nano /etc/dhcp/dhcpd.conf
option subnet-mask 255.255.255.0;
default-lease-time 360000;
max-lease-time 720000;

option domain-name-servers 8.8.8.8;
subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.10 192.168.1.254;
  option broadcast-address 192.168.1.255;
  option routers 192.168.1.1;
}


Edit or create /etc/default/isc-dhcp-server and add wlan0 in INTERFACES
sudo nano /etc/default/isc-dhcp-server

INTERFACES="wlan0"

Assign IP Address to wlan0
sudo ifconfig wlan0 192.168.1.1 netmask 255.255.255.0

Edit /etc/rc.local to get wifi working on every reboot

echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
ifconfig wlan0 inet 192.168.1.1 netmask 255.255.255.0
hostapd -d /etc/hostapd/hostapd.conf &
/etc/init.d/isc-dhcp-server restart

Add WiFi Connectivity

Connect my pandaboard wifi (STA) to an Access Point.

Create wpa_supplicant.conf if it's not being created.


mkdir -p /etc/wpa_supplicant
sudo nano -w /etc/wpa_supplicant/wpa_supplicant.conf


ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=root
network={
    ssid="ap_name"
    key_mgmt=WPA-PSK
    psk="ap_password"
    id_str="home"
}


Test your wpa_supplicant.conf:
wpa_supplicant -BW -Dwext -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf

edit your /etc/network/interfaces

auto wlan0
iface wlan0 inet dhcp
    wireless_essid ap_name
    pre-up wpa_supplicant -BW -Dwext -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf
    post-down killall -q wpa_supplicant


iface home inet dhcp

Friday, January 6, 2012

CCNx Common Problem

1. When running CCNx Services on Android Smartphone, repo status hangs on ... INITIALIZING.
Work around: You need SD Card or Memory Card installed on your smartphone, CCNx repo need this SD Card.

2. ccnputfile and ccngetfile doesn't work.
Work around: You need to run ccn_repo first. Make sure you run ccndstart before running ccn_repo
ccn_repo REPO_DIR

3. If you still have problem with ccnputfile, try different REPO_DIR. ccn_repo only support one prefix, you can use policy_xml if you need more then one prefix.

4. If you're running ccn on two host and can't get file or content from other host try add a FIB entry.

ccndc add ccnx:/ tcp 192.168.1.2

Note:
I'm using / (root) for the ccnx uri.
192.168.1.2 is the other host ip address

4. Can't run make install for android on Linux Ubuntu 32bit. Android tools complain that awk is out of date.
Solution: install gawk

sudo apt-get install gawk
export HOST_AWK=gawk

and
delete or rename awk filename in {android-ndk-r7}/prebuilt/linux-x86/bin

5. Can't install android package using adb. After plugging android devices run 'adb devices' you only get ???????? no permissions
Solution:
with sudo run:
sudo adb kill-server
sudo adb start-server
sudo adb devices

More problems coming soon ..


Thursday, January 5, 2012

Pandaboard ES Android

I tried Android 4.0.1 prebuilt images from Linaro and it works. However WiFi still not working.

Build: https://android-build.linaro.org/builds/~linaro-android/panda-11.12-release/#build=1

Install instructions:

# Get artifacts
wget http://releases.linaro.org/11.11/android/images-ics-preview/mainline-panda/boot.tar.bz2 http://releases.linaro.org/11.11/android/images-ics-preview/mainline-panda/system.tar.bz2 http://releases.linaro.org/11.11/android/images-ics-preview/mainline-panda/userdata.tar.bz2

# Get the latest linaro image tools
bzr branch lp:linaro-image-tools

# Insert SD card and note the assigned '/dev/sdX' or '/dev/mmcblk0'
dmesg

# Create media
sudo ./linaro-image-tools/linaro-android-media-create --mmc /dev/sdX --dev panda --system system.tar.bz2 --boot boot.tar.bz2 --userdata userdata.tar.bz2

For more information on how to use this builds please see the Linaro wiki at:

https://wiki.linaro.org/Platform/Android/ImageInstallation



http://releases.linaro.org/11.11/android/images-ics-preview/mainline-panda/

Compile CCNX For Android

Get the latest Android SDK and NDK. Current Android SDK is r16 and NDK is r7.
Get the latest ccnx project from http://www.ccnx.org. Current release is 0.4.2

Set the ANDROID_SDK and ANDROID_NDK folder.


export ANDROID_SDK=~/android_tools/android-sdk-mac_x86-r16
export ANDROID_NDK=~/android_tools/android-ndk-r7
export PATH=${ANDROID_SDK}/platform-tools:$PATH


run:
${ANDROID_SDK}/tools/android

Install the android platform you want to use, currently ccnx support until Android 2.3.3.

In ccnx root folder run make, this should build wihout complaint.
goto android folder in ccnx and run make. I got error android-7 is in not my android target list. I want to compile for android 2.3.3 this is API 10. So modify all makefile under ccnx/android folder from android-7 to android-10 and recompile.

run 'make install' to install ccnx in android client or emulator. You must connect your device or run android emulator before installing.

Cross compile for ARM in Ubuntu

Dari linux machine Ubuntu download ARM toolchain:

$ sudo apt-get install gcc-arm-linux-gnueabi

Untuk Ubuntu 10.04 jalankan ini:

sudo add-apt-repository ppa:linaro-maintainers/toolchain
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabi


Test toolchain:
$ arm-linux-gnueabi-gcc -v

Sekarang buat aplikasi sederhana hello-world.c


#include
int main()
{
printf("Hello world for ARM\n");
return 0;
}


Sekarang buat Makefile:



CC=$(CROSS_COMPILE)gcc

all: hello-world.c
$(CC) -o hello-world hello-world.c

clean: rm hello-world



Note: Tab di Makefile harus benar-benar karakter tab bukan spaces. Kalau ada compile error Missing separator ... berarti Makefile menggunakan spaces.

Sekarang compile program diatas:
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-

jalankan hello-world
$ chmod u+x hello-world
$ ./hello-world

Hasil:
/lib/ld-linux.so.3: No such file or directory

Ini karena hasil binary hanya jalan untuk ARM architecture.

Copy hello-world ke folder rootfs di SD Card
$ sudo cp hello-world /media/rootfs/home/ubuntu

Sekarang booting lagi ARM di development board.

$ /home/ubuntu/hello-world

Hasil:
Hello world for ARM