Wednesday, March 31, 2010

Add wireless

auto wlan0
iface wlan0 inet dhcp
wireless-essid MYNETWOTK
wireless-key FEFEFEFEFE
wireless-channel 11
wireless-mode managed

Saturday, March 27, 2010

Bootup time.

There are a few links about reducing boot up time.

http://elinux.org/Boot_Time
http://free-electrons.com/docs/optimizations/
http://guvnr.com/pc/ubuntu-disable-services/

Splash Screen

The latest Karmic ubuntu use xsplash. All the pictures are in /usr/share/image/xplash.

Here is a link you want to check out if you want to change it.
http://georgia.ubuntuforums.org/showthread.php?t=1333683

To totally remove it to save time on boot.

cp /etc/dbus-1/system.d/xsplash.conf ~/xsplash.conf
sudo rm /etc/dbus-1/system.d/xsplash.conf
sudo touch /etc/dbus-1/system.d/xsplash.conf

Correct time

The wireless router does not allow NTP access to the ntp server. Other method need to be used to sync time. One thing I am going to use is the navy.mil timer. The following python code will set the system time to the time from navy.


#!/usr/bin/python
import urllib2, os
Time_Url="http://tycho.usno.navy.mil/cgi-bin/timer.pl"
fp = urllib2.urlopen(Time_Url)
data = fp.read().split()
Month=data[34][4:7]
Day=data[35][0:2]
Time=data[36]
Set_Date= Day+ " "+ Month+" 2010 "+ Time
print Set_Date
os.execlp("/bin/date", "date", "-s", Set_Date)
fp.close()

Auto login

To make auto login in runlevel 5, you can change /etc/gdm/gdm.conf.

To change your run level and auto login, you need to do the following.

in /etc/init/rc-sysinit.conf:
---------------
env DEFAULT_RUNLEVEL=3
---------------

in /etc/init/gdm.conf:
---------------
start on (filesystem
and started hal
and tty-device-added KERNEL=tty7
and (graphics-device-added or stopped udevtrigger)
and runlevel [!3])
stop on runlevel [016]
---------------


The default login is getty, which does not support auto login. You need install mingetty and change your /etc/init/tty1.conf as the following:

---------------
# tty1 - getty
#
# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]
respawn
#exec /sbin/getty -8 38400 tty1
exec /sbin/mingetty --autologin setup tty1
----------------

So the runlevel will enable you into runlevel 3,and mingetty will enable the autologin. The next thing you need to do is to auto start x-window.

.xinitrc
----------------
/usr/bin/python /home/setup/python/updated_V19.py
----------------

.profile add the following line to the end.
----------------
startx
----------------

\n

Friday, March 26, 2010

USB hub

If I need to create my own USB hub, here is the link I can check.

http://www.howtofixcomputers.com/forums/homebuilt-pc/make-usb-hub-27036.html

Wireless problem solved?

It appears that the wireless AP I connected to has "ping" disabled. Even though I can't ping anywhere, which was what I have been trying in the past few days, I can still browse the internet. I am not sure what other function has been disabled. I will figure it out tomorrow.


The Belkin wireless adapter uses rt73 driver. That can be installed from the kernel. Once installed. You can use a command line:

-------------
sudo iwconfig wlan0 essid "NDSU"
sudo dhclient wlan0
sudo ifconfig
-------------

That should work and make. If the wireless gets lost after reboot, you need change the interfaces and add dhclient to rc.local file.

Wireless on BB

There are 2 wireless adapter we are currently using. ASUS USB-N13 and Belkin F5D7050.

The ASUS is a new version that we can not find a working driver for it. I had trouble with the kernel 2.6.31. However, the latest 2.6.32 kernel solve the wireless problem.

The 2.6.32 kernel hasn't been put online yet. When I dig this deeper, I found the certain crypto need to be enabled. That's for the wireless communication. I will keep trying the 2.6.31 in the main time.

Wednesday, March 24, 2010

Python code to read GPIO

#!/usr/bin/python
import struct

Event_Device = "/dev/input/event0"
Event_Format = 'iihhi'

Event_File = open(Event_Device, "rb")
This_Event = Event_File.read(16)
while This_Event:
(stamp1, stamp2, type, code, value) = struct.unpack(Event_Format, This_Event)
if type == 1 and value == 1 and code == 275:
print " GPIO 133 button pressed! "
if code == 276:
Event_File.close()
print "exiting...."
exit(0)
This_Event = Event_File.read(16)
Event_File.close()

GPIO solution found!!!

First of all, thanks to Project Kennel.
http://www.projectkennel.com/phpBB3/viewtopic.php?f=4&t=3

There are 5 files you might need when using GPIO. They are
=========================
arch/arm/plat-omap/include/mach/mux.h
============================
This file defines the name of the GPIO. You can change your GPIO name in here. The name can be anything you want. The same reference name will be used thereafter. A good idea will be following the same pattern. For example GPIO133, the name should be: AH4_34XX_GPIO133_DOWN

Since you are switch the mux from MODE0 to MODE4, you have to comment out the AH4_3430_MMC2_DAT1 line in the same file.


=========================
arch/arm/mach-omap2/mux.c
=========================
This file defines the register of the GPIO. This is the most important file. It defines the register location, the MUX mode and I/O. For the GPIO133 example, you can use:

MUX_CFG_34XX("AH4_34XX_GPIO133_DOWN", 0x15e,
OMAP34XX_MUX_MODE4 | OMAP34XX_PIN_INPUT_PULLDOWN)

Once again, the MMC2_DAT1 should be commented out. If you forget this, the MUX will be set to MODE0 again somewhere.

//MUX_CFG_34XX("AH4_3430_MMC2_DAT1", 0x15e,
// OMAP34XX_MUX_MODE0 | OMAP34XX_PIN_INPUT_PULLUP)

=========================
include/linux/input.h
=========================
Key definitions. There is nothing you need to change here. This file is a reference file. You will need to map your GPIO input as a button. Each button has a name. The name is define in this file. For example:
#define BTN_BACK 0x116
BTN_BACK is the name we are going to use in the kernel file. 278, which is 0x116, will be used in the python code for identification. The USER button use BTN_EXTRA, code 276.



=========================
arch/arm/mach-omap2/devices.c
=========================
This file initializes several devices. If you are following the example so far, you are using GPIO133, which is MMC2_DAT1. Therefore, you have to commented out that line to remove the conflict.

=========================
arch/arm/mach-omap2/board-omap3beagle.c
=========================
This file init the board. All the additional extra key, led, and touch screens will be inited here. The line you want to add is. In this file, you also link the GPIO133 to a user button code 278

---------
static struct gpio_keys_button gpio_buttons[] = {
{
.code = BTN_EXTRA, // User button returns code BTN_EXTRA
.gpio = 7, //User button gpio 7
.desc = "user",
.wakeup = 1,
},

++++++++++++++

{
.code = BTN_SIDE, //give a mapped code name. Find the code in the input.h.
.gpio = 133, //The gpio number, someone said you need the full name.
.active_low = 1, //active low, refer the mux.c file (PULLDOWN)
.desc = "Side button 278", //description, used in the /proc/interrupts
.type = EV_KEY, //Not sure we need it. Indicate it's an event triggered key. The other type is EV_SW. check include/linux/gpio_keys.h for more info
.wakeup = 0,
},
++++++++++++++

};
----------------

I also add another line in:
----------------
static void __init omap3_beagle_init(void)
{
omap3_beagle_i2c_init();
+ omap_cfg_reg(AH4_34XX_GPIO133_DOWN); //I think it will be inited in the next line. well, just to be safe.
platform_add_devices(omap3_beagle_devices,
ARRAY_SIZE(omap3_beagle_devices));
----------------


So far, you should be ok to go. Your GPIO-133, expansion pin 15, will generate an event in /dev/input/event0 if you press the tie down button connected to it. The python code will be introduced later. Your /proc/interrupts file will record all the interrupts. Every time you tie down your GPIO133, the number increase twice.

Tuesday, March 23, 2010

Build the kernel again

Since all the methods I tried does not work with GPIO, I decide to change another kernel.

There are over 20 .bb file in the recipes/linux/ directory. When you build with bitbake linux-omap, the OE will find one file with the following line in it.

DEFAULT_PREFERENCE_beagleboard = "1"

The file with the line will be the default one to build. I am going to try the latest one. 2.6.31.

Monday, March 22, 2010

GPIO access

Based on my current knowledge, the access to GPIO is related to the following files.

arch/arm/plat-omap/include/mach/mux.h
####This file defines the name of the GPIO


arch/arm/mach-omap2/mux.c
####This file defines the register of the GPIO

include/linux/input.h
####Key definations

arch/arm/mach-omap2/board-omap3beagle.c
####This file init the board.


Sunday, March 21, 2010

GPIOs

I have been working on the GPIO pins. I can access from the file system.

I am tring to add it in the kernel so I can generate event from it. Here are some CODE, and files need to change.


http://www.mail-archive.com/freevo-devel@lists.sourceforge.net/msg13219.html
+        277:'BTN_FORWARD',
+ 278:'BTN_BACK',
+ 279:'BTN_TASK',


http://groups.google.com/group/0xlab-devel/browse_thread/thread/d7886b2a08e904a1

Wednesday, March 17, 2010

New idea about python

It seems in the wx frame, you can have "OnIdle" event. Your system trigger can be placed in there.

Another note about the python distribution. Check out the following.

http://wiki.openmoko.org/wiki/Customizing_the_Openmoko_Distribution#Adding_Python_scripts_as_applications

GPIO problem?

Certain u-boot + uImage combination can enable the GPIO.

the u-boot generated from OpenEmbedded has the USB disabled from a cold reboot. A good u-boot is in my ~/kernel/uBoot/git. That u-boot.bin is generated by the method I mention on my other blog.

The ~/kernel/uBoot/git works fine with USB (cold), GPIO, and USER button.

The good uImage has not been found yet.

The original defconfig DOES work. The defconfig_reset_clock works as well. Just make sure your connection are alright.

Tuesday, March 16, 2010

GPIO update

It seems the gpio 156 can be used as an output. That was given in both mux.c and board-omap3beagle.c.

The board-omap3beagle.c has many init subfunction. One of them enable the gpio.

Try the following code.

#include
// at setup time
result = gpio_request(158, "gpiotest");
allocated = (result >= 0);
if(allocated) gpio_direction_output(158, 1);
// to change the output
if(allocated) gpio_set_value(158, i & 1);
// at cleanup time
if(allocated) gpio_free(158);

Monday, March 15, 2010

Root file system.

A good way to generate root file system is to use the "rootstock" command.
sudo rootstock --fqdn BoardName --login UserName --password PassWord --imagesize 2G --dist karmic --serial ttyS2 \
--seed xfce4,gdm,xubuntu-gdm-theme,xubuntu-artwork \
--kernel-image Path_To_Kernel_Image

Other seed package you can include:
wget,nano,linux-firmware,wireless-tools,usbutils

The output is a tar file with the root file system.
sudo tar xpfv rootfs.tar -C /media/root

Once extract, you need modify the following file.
fstab
/dev/mmcblk0p2 / ext3 errors=remount-ro 0 1
-------------

e2fsck.conf


[problems]

# Superblock last mount time is in the future (PR_0_FUTURE_SB_LAST_MOUNT).
0x000031 = {
preen_ok = true
preen_nomessage = true
}

# Superblock last write time is in the future (PR_0_FUTURE_SB_LAST_WRITE).
0x000032 = {
preen_ok = true
preen_nomessage = true
}
---------------

network/interfaces
auto eth0
iface eth0 inet dhcp


---------------
Once you boot up, you might need

sudo apt-get install nano python-wxgtk2.8





GPIO

It's time to figure out how the GPIO works. A good start point is here.

http://orion.dherring.com/beagleTouchWiki/DebianRootfs

It seems the methods mentioned in the previous page doesn't work. If OMAP_MUX is set, kernel will have "kernel Panic - not syncing: VFS: unable to mount root fs on unknow-block(179.2).

maybe I have to read more.

Error message:
[ 317.434753] fbcvt: 1024x768@60: CVT Name - .786M3-R
[ 317.470184] Console: switching to colour frame buffer device 128x48
[ 317.490936] clock: clksel_round_rate_div: dpll4_m4_ck target_rate 48000000
[ 317.497863] clock: new_div = 9, new_rate = 48000000
[ 317.511779] Waiting for root device /dev/mmcblk0p2...
[ 318.064971] mmc0: new high speed SDHC card at address 1234
[ 318.071166] mmcblk0: mmc0:1234 SA08G 7.40 GiB (ro)
[ 318.076293] mmcblk0: p1 p2
[ 318.166931] VFS: Cannot open root device "mmcblk0p2" or unknown-block(179,2)
[ 318.174041] Please append a correct "root=" boot option; here are the available partitions:
[ 318.182525] 1f00 512 mtdblock0 (driver?)
[ 318.187530] 1f01 1920 mtdblock1 (driver?)
[ 318.192565] 1f02 128 mtdblock2 (driver?)
[ 318.197570] 1f03 4096 mtdblock3 (driver?)
[ 318.202606] 1f04 255488 mtdblock4 (driver?)
[ 318.207641] b300 7763968 mmcblk0 driver: mmcblk
[ 318.212890] b301 329301 mmcblk0p1
[ 318.217224] b302 7430062 mmcblk0p2
[ 318.221588] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,2)

Sunday, March 14, 2010

OpenEmbedded linux-omap Kernel

"bitbake linux-omap" will compile the latest kernel and deploy as uImage. However, if you have your own change, you have to follow the following steps. It is a summery from here.

bitbake linux-omap -c configure
cd tmp/work/beagle/linux-omap/git;
make menuconfig
cd $OETREE
bitbake linux-omap -c compile -f
bitbake linux-omap -c deploy

bitbake linux-omap -c configure : download all the source code, and put the source code in the tmp/work/linux-omap/git directory. If there is anything you need to change, you have to go to that directory and change it using make menuconfig.

bitbake will compile and deploy from the tmp directory. So all your changes you just made will be built into the kernel. However, if this build is permenent, you can save your kernel setup to your recipe. cp .config recipes/linux/linux-omap2-git/beagle/defconfig .

After that, you have to manually do the compile and deploy. There is not one line command to do that.

Saturday, March 13, 2010

More about OpenEmbedded

I have been using OpenEmbedded to develop the beagleboard. Here is a very good "tutorial" teaching people how to make your own image.

The tutorial ask you create another image in receipts/images. That's the location bitbake can find receipts from.

helloworld-console-image.bb
require console-image.bb
ANGSTROM_EXTRA_INSTALL += " helloworld "
export IMAGE_BASENAME = "helloworld-console-image"
----------------------

This bb file include the console-image first, and add the helloworld.bb. The exported image is called "helloworld-console-image". So, when you do bitbake, you will need the
"helloworld-console-image", that's the bb file in the image folder. The helloworld.bb file can be found in the receipt directory.

The helloworld.bb is the receipt to make the helloworld user app. The install part of the helloworld.bb is like the following:


helloworld.bb
do_install () {
install -d ${D}${bindir}
install -m 0755 helloworld ${D}${bindir}/
# /bin/init is on purpose, it is tried
# after /sbin/init and /etc/init

# so if a sysvinit is installed, it will be
# used instead of helloworld

install -d ${D}${base_bindir}
ln -sf ${bindir}/helloworld ${D}${base_bindir}/init
}
----------------------

The install -d command will check the directory. If the directory does not exists, it creates one. ${D} is your destination, in this case, the bitbake will put it in tmp first. ${bindir} is where you want to put your user app. It's /usr/bin by default. "-m" changes the user app' attribute to rwxr-x-r-x in this case. "base_bindir" is /bin.

The last line create a link from the /usr/bin/helloworld to /bin/init. Some distribution of linux use /bin/init as initial program. You may change this to your own distribution.

A good article talking about init can be found here and here.
A discussion about start a program can be found here.