2011年9月15日 星期四

Avoid zombie process

在某些應用中常會需要執行其他的程式,這時候就會需要呼叫fork產生child process並在此執行其他程式.
而當被呼叫的程式執行結束child process也就跟著結束,這時child process就成為zombie process.

if(fork() == 0) { /* Child process*/
  /* Run program */
  execl("/bin/ntpdate", "ntpdate", "tick.stdtime.gov.tw", "tock.stdtime.gov.tw", (char *)0);
  exit(0);
  /* zombie process */
}

/* Parent process or error */
 
wait(0);

zombie process存在的意義是等待parent process來處理child process結束後的事情,例如程式的傳回值.

有兩種方式來避免zombie process
1.明確指出parent process不需要知道child process的結束狀態
在parent process 程式碼中加上

signal(SIGCHLD, SIG_IGN); /*  Do not wait for child process */

2.連續fork兩次,藉由結束first child process的方式讓second child process的parent process為pid 1  (通常是 init)

pid_t pid;
if((pid = fork()) == 0)  { /*First child process*/
  if((pid = fork()) > 0)
      exit(0); /* Terminate first child process */
  /* Second child process. Run program */
  execl("/bin/ntpdate", "ntpdate", "tick.stdtime.gov.tw", "tock.stdtime.gov.tw", (char *)0);
  exit(0);
}
 
/* Parent process or error */



2011年8月5日 星期五

Embedded Linux IPv6 ready logo phase-2

The past month I'm working on IPv6 ready test on an embedded linux platform.
Since the kernel is really old 2.6.10 and I have to do some porting from newer kernel to get IPv6 ready test pass. Last week I finally all pass and below are some tips.

1.The test node (TN) is FreeBSD 7.4 release with v6eval-3.3.2 / v6eval-remotes-3.0 / Self_Test_5.0.0

It's very important that to disable ipv6 autoconfiguration on TN, because the testing suit needs clean ipv6 environment.

To disable ipv6 autoconfiguration, edit /etc/rc.conf and set

ipv6_enable="NO"

then after TN boot, the ipv6 link local address (fe80:X) won't be exist.

2./usr/local/v6eval/etc/tn.def

#
# tn.def
#
#  Information about the Tester Node (TN)
#

#
# Remote Controal Configuration
#
RemoteDevice    cuad0
RemoteDebug     0
RemoteIntDebug  0
RemoteLog       1
RemoteSpeed     0
RemoteLogout    0
RemoteMethod    serial
#filter ipv6

#linkname       interface       BOGUS ether source address
#               name            of the Tester Interface
Link0           rl0             00:00:00:00:01:00
#Link1          de1             00:00:00:00:01:01
#Link2          de2             00:00:00:00:01:02
#Link3          de4             00:00:00:00:01:03

3./usr/local/v6eval/etc/nut.def

#
# nut.def
#
#  Information about the Node Under Test (NUT)
#

# System type
System          linux-v6

# System information
TargetName      FreeBSD/i386 4.9-RELEASE + kame-20040726-freebsd49-snap

# Name
HostName        HL200

# Type
#   host, router, special
Type            host

# Super user name and it's password
# if you select manual as "System", you don't care "User" and "Password"
#
User            root
Password        1234

#linkname       interface       The EXACT ether source address
#               name            of the Interface Under Test
Link0           eth0            00:AE:45:BC:84:1E
#Link0          eth0            00:60:37:c0:ff:ee
#Link1          fxp1            00:00:92:a7:6d:f6
#Link2          de0             00:c0:f6:b0:aa:ef
#Link3          de1             00:00:92:a7:6d:f8
#Link4          de2             00:90:27:14:ce:e3

4./usr/local/lib/perl5/site_perl/5.10.1/V6evalRemote.pm
This file is really important for self test. It makes the TN to communicate NUT through serial RS232 port. TN can login / logout NUT system even more reboot NUT.

So, find key words below in this file and get it right

    $Type="linux-v6";
    $Device="cuad0";
    $User="root";
    $Password="1234";

The TN will detect message from NUT to login / logout. For example "login: " and "Password: ". Also get it right for your NUT's Behavior

    # login prompt
    %prompt_user = (
           ...
           'linux-v6',         'login: ',
           ...
    );

    # password prompt
    %prompt_password = (
       ...
        'linux-v6',             'Password: ',
        ...
    );

    # command prompt
    %prompt_command = (
        ...
        'linux-v6',              '(\$|#) ',
        ...
    );

    and so on

5.Test TN <-RS232-> NUT
If you can see login screen or promopt, it works

touch /var/log/aculog
chown uucp:dialer /var/log/aculog
chmod 660 /var/log/aculog
cu -l /dev/cuad0
Connected

[root@HL200 ~]$

6.Remote test
To test if TN can login then logout NUT

/usr/local/v6eval/bin/linux-v6/loginout.rmt -o1

HL200 login: root
Password:


BusyBox v1.2.2 (2011.07.20-06:33+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

[root@HL200 ~]$
[root@HL200 ~]$ exit

7.Run self test

cd Self_Test_5-0-0
make clean
make ipv6ready_p2_host

8.Run parts of self test

There are 5 test sections, you can test separated.

cd nd.p2/
make clean
make ipv6ready_p2_host

Also can test only few items, for example test items 10 to 20

make AROPT="-s 10 -e 20" ipv6ready_p2_host

9.Embedded linux setup.
There are some sysctl for ipv6 need to be set correct.

echo 0 > /proc/sys/net/ipv6/conf/default/forwarding
echo 2 > /proc/sys/net/ipv6/conf/default/dad_transmits
echo 1 > /proc/sys/net/ipv6/conf/default/use_tempaddr
echo 2 > /proc/sys/net/ipv6/conf/default/accept_dad
echo 1 > /proc/sys/net/ipv6/conf/default/optimistic_dad
echo 1 > /proc/sys/net/ipv6/conf/default/accept_redirects

Remember to set promisc and allmulti to ethernet port.
Another tip is to sleep 10 seconds after the ethernet up then go login screen

ip -6 link set lo up
#ip -6 link set eth0 up
ifconfig eth0 up promisc allmulti

echo "Wait 10 secs..."            
sleep 10                          

10.Finally, fix /usr/local/v6eval/bin/unknown/ping6.rmt

########################################################################
use V6evalRemote;

rOpen() || goto error;

$NUTif = $rOpt_if;
$dstaddress = $rOpt_addr;
$rOpt_timeout = 5 if ! defined $rOpt_timeout;

if($rOpt_size < 1) {
    $rOpt_size = 2;
}

$pingpath = "ping6";
$pingopt  = "-n -c 1 -i 1 -s $rOpt_size -p 00 -w 2 -M want";
$ifopt    = "-I $NUTif" if $NUTif ne "";

rLogin($rOpt_timeout) || goto error;
rCommand("$pingpath $pingopt $ifopt $dstaddress", 15) || goto error;
rLogout($rOpt_timeout) || goto error;

rClose();
exit($V6evalRemote::exitPass);

error:
    rClose();
    exit($V6evalRemote::exitFail);

########################################################################





2011年6月20日 星期一

LeopardBoard DM368 ffmpeg

For the HD video I need libraries to support video / audio file mux. The ffmpeg is a good choice. With ffmpeg I can save H.264 raw data into mp4 file then play video on PC.

1.Download ffmpeg-0.6.1
Download ffmpeg-0.6.1 and put it in ~/LeopardBoard/DM368

2.Cross compile ffmpeg
I will install ffmpeg into the toolchain sub directory for convenience. My toolchain locate at /opt/arm-2009q1

$ cd ~/LeopardBoard/DM368/ffmpeg-0.6.1
$ mkdir build
$ cd build
$ ../configure --target-os=linux --arch=armv --cpu=armv5te --enable-cross-compile --cross-prefix=arm-none-linux-gnueabi- --prefix=/opt/arm-2009q1/arm-none-linux-gnueabi/libc/usr
$ make
$ sudo PATH=$PATH:/opt/arm-2009q1/bin make install

3.Apply patch to fix Makefile to prevent application link error and add new application video_encode_mp4.

ti-dvsdk_dm368-evm_4_02_00_06_dmai_2_20_00_15_ffmpeg.patch

There will be link error while compile application, so I did some modify to dmai_2_20_00_15/packages/ti/sdo/dmai/apps/Makefile.app

The new application is capable to record HD video and save it into mp4 file

4.Recompile DMAI

$ cd ~/LeopardBoard/DM368/original/ti-dvsdk_dm368-evm_4_02_00_06
$ make dmai

The new application video_encode_mp4 is located at dmai_2_20_00_15/packages/ti/sdo/dmai/apps/video_encode_mp4/linux/video_encode_mp4_dm368.x470MV

5.Running
Save 720p video into SD card with file name video_encode.mp4

$ cd /usr/share/ti/ti-dmai-apps
$ ./video_encode_mp4_dm368.x470MV -I camera -y 4 -c h264enc -i /dev/video0 -o /media/mmcblk0p2/video_encode.mp4 -e encode -b 2000000

6.Running with benchmark

$ ./video_encode_mp4_dm368.x470MV -I ca
mera -y 4 -c h264enc -i /dev/video0 -o /media/mmcblk0p2/video_encode.mp4 -e encode -b 8000000 --benchmark
Starting application...
davinci_resizer davinci_resizer.2: RSZ_G_CONFIG:0:1:124
vpfe-capture vpfe-capture: IPIPE Chained
vpfe-capture vpfe-capture: Resizer present
Leopard: switch to HD imager-MT9P031 video input
-----Exposure time = 2f2
-----Exposure time = 2f2
vpfe-capture vpfe-capture: width = 1280, height = 720, bpp = 1
vpfe-capture vpfe-capture: adjusted width = 1280, height = 720, bpp = 1, bytesperline = 1280, sizeimage = 1382400
vpfe-capture vpfe-capture: width = 1280, height = 720, bpp = 1
vpfe-capture vpfe-capture: adjusted width = 1280, height = 720, bpp = 1, bytesperline = 1280, sizeimage = 1382400
Output #0, mp4, to '/media/mmcblk0p2/video_encode.mp4':
    Stream #0.0: Video: 0x0000, yuv420p, 1280x720, q=2-31, 8000 kb/s, 90k tbn, 15 tbc
No frame read ...
...

Frame 26: Read time: 8431us
[27] Encode: 19808us
File write time: 3915us
Total: 32414us

 Frame 27: Read time: 9166us
[28] Encode: 19778us
File write time: 4592us
Total: 33793us

 Frame 28: Read time: 8517us
[29] Encode: 19796us
File write time: 5055us
Total: 33621us

 Frame 29: Read time: 8097us
[30] Encode: 28264us
File write time: 18042us
Total: 54664us

 Frame 30: Read time: 19820us
[31] Encode: 26007us
File write time: 18879us
Total: 64968us

 Frame 31: Read time: 21273us
[32] Encode: 19804us
File write time: 2930us
Total: 44265us

 Frame 32: Read time: 10147us
[33] Encode: 19743us
File write time: 2517us
Total: 32662us
...

Write file time about 2 ~ 5 ms, there's no need to write file in another thread.



2011年6月14日 星期二

LeopardBoard DM368 HD H.264 encode

With DVSDK working on LeopardBoard DM368, Now let's trying video encode function.

1.Check kernel log to see if the dsplink related modules are loaded.

CMEMK module: built on Jun 14 2011 at 18:02:26
  Reference Linux version 2.6.32
  File /home/gigijoe/LeopardBoard/DM368/original/ti-dvsdk_dm368-evm_4_02_00_06/linuxutils_2_26_01_02/packages/ti/sdo/linuxutils/cmem/src/module/cmemk.c
allocated heap buffer 0xc6000000 of size 0x4400000
heap fallback enabled - will try heap if pool buffer is not available
CMEM Range Overlaps Kernel Physical - allowing overlap
CMEM phys_start (0x1000) overlaps kernel (0x80000000 -> 0x83c00000)
cmemk initialized
IRQK module: built on Jun 14 2011 at 18:02:29
  Reference Linux version 2.6.32
  File /home/gigijoe/LeopardBoard/DM368/original/ti-dvsdk_dm368-evm_4_02_00_06/linuxutils_2_26_01_02/packages/ti/sdo/linuxutils/irq/src/module/irqk.c
irqk initialized
EDMAK module: built on Jun 14 2011 at 18:02:30
  Reference Linux version 2.6.32
  File /home/gigijoe/LeopardBoard/DM368/original/ti-dvsdk_dm368-evm_4_02_00_06/linuxutils_2_26_01_02/packages/ti/sdo/linuxutils/edma/src/module/edmak.c

2.If there are errors check /etc/init.d/loadmodule-rc. Below is mine

#!/bin/sh

# Default DM368 EVM Memory Map
#
# Start Addr    Size    Description
# -------------------------------------------
# 0x00001000    32K     ARM TCM memory
# 0x80000000    48 MB   Linux
# 0x83000000    12 MB   Video driver memory (Linux)
# 0x83C00000    68 MB   CMEM
# 0x88000000    BOTTOM  ADDRESS

load () {
    modprobe cmemk phys_start=0x83C00000 phys_end=0x88000000 allowOverlap=1 phys_start_1=0x00001000 phys_end_1=0x00008000 pools_1=1x28672 useHeapIfPoolUnavai
lable=1
    modprobe irqk
    modprobe edmak
    modprobe dm365mmap
    mknod /dev/dm365mmap c `awk "\\$2==\"dm365mmap\" {print \\$1}" /proc/devices` 0
}

unload () {
    rmmod cmemk 2>/dev/null
    rmmod irqk  2>/dev/null
    rmmod edmak 2>/dev/null
    rmmod dm365mmap 2>/dev/null
    rm -f /dev/dm365mmap
}

case "$1" in
      start)
            load
             ;;
       stop)
            unload          
             ;;
       restart)
            unload          
            load
             ;;
        *)
             echo "$0 "
             ;;
esac

3.Decode test to verify if DSP works.

$ cd /usr/share/ti/ti-dmai-apps
$ ./video_decode_io2_dm368.x470MV -c h264dec -e decode -i /usr/share/ti/data/videos/davincieffect.264 -n 30 -o output.yuv
Starting application...
Loader created and primed, entering main loop..
Loaded Frame 1: frame size 401
Loaded Frame 2: frame size 36
Loaded Frame 3: frame size 804
Loaded Frame 4: frame size 844
Loaded Frame 5: frame size 863
Loaded Frame 6: frame size 933
Loaded Frame 7: frame size 1189
Loaded Frame 8: frame size 1253
Loaded Frame 9: frame size 1509
Display Frame 1: Wrote 420P frame size 1382400 (1280x720) to disk
Loaded Frame 10: frame size 1573
Display Frame 2: Wrote 420P frame size 1382400 (1280x720) to disk
Loaded Frame 11: frame size 1829

4.Now, it's time to encode video from camera. I got mt9p031 (LI-BCM5M03).
If you got kernel log below, the camera is ready

...
Leopard: switch to HD imager-MT9P031 video input
mt9p031 1-0048: Detected a MT9P031 chip ID 1801
mt9p031 1-0048: mt9p031 1-0048 decoder driver registered !!
vpfe-capture vpfe-capture: v4l2 sub device mt9p031 registered
...

5.Test if camera works

$ cd /usr/share/ti/ti-dmai-apps
$ ./video_loopback_dm368.x470MV -O component -I camera -y5
davinci_resizer davinci_resizer.2: RSZ_G_CONFIG:0:1:124
vpfe-capture vpfe-capture: IPIPE Chained
vpfe-capture vpfe-capture: Resizer present
Leopard: switch to HD imager-MT9P031 video input
-----Exposure time = 456
-----Exposure time = 456
vpfe-capture vpfe-capture: width = 1920, height = 1080, bpp = 1
vpfe-capture vpfe-capture: adjusted width = 1920, height = 1080, bpp = 1, bytesperline = 1920, sizeimage = 3110400
vpfe-capture vpfe-capture: width = 1920, height = 1080, bpp = 1
vpfe-capture vpfe-capture: adjusted width = 1920, height = 1080, bpp = 1, bytesperline = 1920, sizeimage = 3110400
davinci_v4l2 davinci_v4l2.1: Before finishing with S_FMT:
layer.pix_fmt.bytesperline = 1920,
 layer.pix_fmt.width = 1920,
 layer.pix_fmt.height = 1080,
 layer.pix_fmt.sizeimage =3110400
davinci_v4l2 davinci_v4l2.1: pixfmt->width = 1920,
 layer->layer_info.config.line_length= 1920

6.There's a application can do H.264 RTP which included in my dmai_2_20_00_15 patch called video_encode_rtp.

This application get frames from camera through VPFE then encoded in H.264 format packeted with H264RTP packet then send to network.

From LeopardBoard DM368

$ cd /usr/share/ti/ti-dmai-apps
$ ./video_encode_rtp_dm368.x470MV -I camera -y 4 -c h264enc -i /dev/video0 -o 192.168.168.72 -p 1234 -e encode -b 2000000

-I camera = camera input
-y 4 = 720P,
-o 192.168.168.72 = Send to 192.168.168.72
-p 1234 = port 1234
-b 2000000 = Bit rate 2000000

I'm decoding the video stream with gstreamer on PC Ubuntu.

$ gst-launch udpsrc port=1234 caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264" ! gstrtpjitterbuffer latency=100 ! rtph264depay ! ffdec_h264 ! xvimagesink

If the video frame sometimes droped, try larger gstrtpjitterbuffer latency = 200 / 300 / 500.

7.Full HD

From LeopardBoard DM368

-y 5 = 1080P

$ ./video_encode_rtp_dm368.x470MV -I camera -y 5 -c h264enc -i /dev/video0 -o 192.168.168.72 -p 1234 -e encode -b 2000000



LeopardBoard DM368 running with TI DVSDK

I got LeopardBoard DM368 for a while and get it work with TI DVSDK.
The mt9p031 camera also works and capable of Full HD H.264 encode.
Boot device is SD card.
Below I will show how to do it.

0.Install toolchain
CodeSourcery arm 2009-q3.
See DVSDK download page for detail.
http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/dvsdk/DVSDK_4_00/latest/index_FDS.html

1.Download TI DVSDK 4_02_00_06
http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/dvsdk/DVSDK_4_00/latest/exports/dvsdk_dm368-evm_4_02_00_06_setuplinux

2.Install DVSDK 4_02_00_06 into ~/LeopardBoard/DM368/original/

3.Download patch for LeopardBoard DM368
$ cd ~/LeopardBoard/DM368/original/ti-dvsdk_dm368-evm_4_02_00_06

ti-dvsdk_dm368-evm_4_02_00_06_leopardboard.patch
ti-dvsdk_dm368-evm_4_02_00_06_Makefile.patch
ti-dvsdk_dm368-evm_4_02_00_06_dmai_2_20_00_15.patch

patch

$ patch -p1 < ../../ti-dvsdk_dm368-evm_4_02_00_06_leopardboard.patch
$ patch -p1 < ../../ti-dvsdk_dm368-evm_4_02_00_06_Makefile.patch
$ patch -p1 < ../../ti-dvsdk_dm368-evm_4_02_00_06_dmai_2_20_00_15.patch

4.Build everything

$ make

5.Create symbolic link of uImage & u-boot

$ cd psp/prebuilt-images/
$ rm -rf ./*
$ ln -s ../u-boot-2010.12-rc2-psp03.01.01.39/u-boot.bin u-boot-dm368-evm.bin
$ ln -s ../linux-2.6.32.17-psp03.01.01.39/arch/arm/boot/uImage uImage-dm368-evm.bin
$ cd ../..

6.Build SD card
Make sure your SD card device node. For me it's /dev/sdb

$ sudo bin/mksdboot.sh --device /dev/sdb --sdk ${PWD}

The process could be a few minutes...
After the process complete, the SD card is unmount automatically.

7.Fix DVSDK install location
Edit Rules.make

Change this one
EXEC_DIR=$(HOME)/install/$(PLATFORM)
to
EXEC_DIR=/media/ROOTFS

8.Do install everything in root file system
Insert SD card again

$ make install

9.Modify boot.cmd & boot.scr

Edit /media/BOOT/boot.cmd as below

mmc rescan 0
setenv bootargs 'console=ttyS0,115200n8  root=/dev/mmcblk0p2 rw ip=off mem=60M davinci_enc_mngr.ch0_output=COMPONENT davinci_enc_mngr.ch0_mode=720P-60 davinci_display.cont2_bufsize=6291456 vpfe_capture.cont_bufoffset=6291456 vpfe_capture.cont_bufsize=6291456 video=davincifb:vid0=off:vid1=off:osd1=off dm365_imp.oper_mode=0 davinci_capture.device_type=4 vpfe_capture.interface=1 rootwait'
fatload mmc 0 80700000 uImage
bootm 80700000

Create boot.scr

$ cd /media/BOOT
$ mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n 'Execute Boot Script' -d boot.cmd boot.scr

10.Umount SD card and insert to LeopardBoard DM368
Make sure the DIPSW is SD card boot.
1:off 2:on 3:off

Boot log

TI UBL Version: 1.50
Booting Catalog Boot Loader
BootMode = SD/MMC
Starting SDMMC Copy...
   DONE
Jumping to entry point at 0x81080000.


U-Boot 2010.12-rc2 (Jun 14 2011 - 18:14:16)

Cores: ARM 432 MHz
DDR:   340 MHz
I2C:   ready
DRAM:  128 MiB
NAND:  256 MiB
MMC:   davinci: 0, davinci: 1
Bad block table found at page 131008, version 0x01
Bad block table found at page 130944, version 0x01
nand_bbt: ECC error while reading bad block table
nand_read_bbt: Bad block at 0x000001f60000
nand_read_bbt: Bad block at 0x000003780000
nand_read_bbt: Bad block at 0x000005000000
nand_read_bbt: Bad block at 0x0000050e0000
nand_read_bbt: Bad block at 0x00000f780000
NAND read from offset 3c0000 failed -74
*** Warning - readenv() failed, using default environment

Net:   Ethernet PHY: GENERIC @ 0x00
DaVinci-EMAC
Hit any key to stop autoboot:  0
reading boot.scr

519 bytes read
## Executing script at 80600000
reading uImage

2146316 bytes read
## Booting kernel from Legacy Image at 80700000 ...
   Image Name:   Linux-2.6.32.17-davinci1
   Created:      2011-06-14  11:25:19 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    2146252 Bytes = 2 MiB
   Load Address: 80008000
   Entry Point:  80008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux..........................................................................................................................................
.. done, booting the kernel.
Linux version 2.6.32.17-davinci1 (gigijoe@gigijoe-laptop) (gcc version 4.3.3 (Sourcery G++ Lite 2009q1-203) ) #1 PREEMPT Tue Jun 14 19:25:14 CST 2011
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177
CPU: VIVT data cache, VIVT instruction cache
Machine: DM365 Leopard
Memory policy: ECC disabled, Data cache writeback
DaVinci dm36x_rev1.2 variant 0x8
Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 15240
Kernel command line: console=ttyS0,115200n8  root=/dev/mmcblk0p2 rw ip=off mem=60M davinci_enc_mngr.ch0_output=COMPONENT davinci_enc_mngr.ch0_mode=720P-60 da
vinci_display.cont2_bufsize=6291456 vpfe_capture.cont_bufoffset=6291456 vpfe_capture.cont_bufsize=6291456 video=davincifb:vid0=off:vid1=off:osd1=off dm365_im
p.oper_mode=0 davinci_capture.device_type=4 vpfe_capture.interface=1 rootwait
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 60MB = 60MB total
Memory: 56220KB available (4020K code, 392K data, 144K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:245
Console: colour dummy device 80x30
Calibrating delay loop... 215.44 BogoMIPS (lpj=1077248)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
DaVinci: 8 gpio irqs
NET: Registered protocol family 16
davinci_serial_init:97: failed to get UART2 clock
bio: create slab at 0
DM365 IPIPE initialized in Continuous mode
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
vpss vpss: dm365_vpss vpss probed
vpss vpss: dm365_vpss vpss probe success
dm365_afew_hw_init
ch0 default output "COMPONENT", mode "720P-60"
VPBE Encoder Initialized
cfg80211: Using static regulatory domain info
cfg80211: Regulatory domain: US
        (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)
        (2402000 KHz - 2472000 KHz @ 40000 KHz), (600 mBi, 2700 mBm)
        (5170000 KHz - 5190000 KHz @ 40000 KHz), (600 mBi, 2300 mBm)
        (5190000 KHz - 5210000 KHz @ 40000 KHz), (600 mBi, 2300 mBm)
        (5210000 KHz - 5230000 KHz @ 40000 KHz), (600 mBi, 2300 mBm)
        (5230000 KHz - 5330000 KHz @ 40000 KHz), (600 mBi, 2300 mBm)
        (5735000 KHz - 5835000 KHz @ 40000 KHz), (600 mBi, 3000 mBm)
cfg80211: Calling CRDA for country: US
LogicPD encoder initialized
Switching to clocksource timer0_1
musb_hdrc: version 6.0, cppi-dma, host, debug=0
musb_hdrc: USB Host mode controller at fec64000 using DMA, IRQ 12
musb_hdrc musb_hdrc: MUSB HDRC host driver
musb_hdrc musb_hdrc: new USB bus registered, assigned bus number 1
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
JFFS2 version 2.2. (NAND) �© 2001-2006 Red Hat, Inc.
msgmni has been set to 109
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered (default)
Console: switching to colour frame buffer device 160x45
davincifb davincifb.0: dm_osd0_fb: 1280x720x16@0,0 with framebuffer size 1800KB
davincifb davincifb.0: dm_osd1_fb: 1280x720x4@0,0 with framebuffer size 1800KB
DM365 IPIPEIF probed
imp serializer initialized
davinci_previewer initialized
davinci_resizer initialized
Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled
serial8250.0: ttyS0 at MMIO 0x1c20000 (irq = 40) is a 16550A
console [ttyS0] enabled
serial8250.0: ttyS1 at MMIO 0x1d06000 (irq = 41) is a 16550A
brd: module loaded
console [netcon0] enabled
netconsole: network logging started
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usbcore: registered new interface driver usbtest
mice: PS/2 mouse device common for all mice
i2c /dev entries driver
Linux video capture interface: v2.00
ths7303 1-002c: chip found @ 0x58 (DaVinci I2C adapter)
vpfe_init
vpfe-capture: vpss clock vpss_master enabled
vpfe-capture vpfe-capture: v4l2 device registered
vpfe-capture vpfe-capture: video device registered
Leopard: switch to HD imager-MT9P031 video input
mt9p031 1-0048: Detected a MT9P031 chip ID 1801
mt9p031 1-0048: mt9p031 1-0048 decoder driver registered !!
vpfe-capture vpfe-capture: v4l2 sub device mt9p031 registered
vpfe_register_ccdc_device: DM365 ISIF
DM365 ISIF is registered with vpfe.
af major#: 252, minor# 0
AF Driver initialized
aew major#: 251, minor# 0
AEW Driver initialized
Trying to register davinci display video device.
layer=c2142800,layer->video_dev=c2142970
Trying to register davinci display video device.
layer=c2142c00,layer->video_dev=c2142d70
davinci_init:DaVinci V4L2 Display Driver V1.0 loaded
watchdog watchdog: heartbeat 60 sec
davinci_mmc davinci_mmc.0: Using DMA, 4-bit mode
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.21.
No device for DAI tlv320aic3x
No device for DAI davinci-i2s
asoc: tlv320aic3x <-> davinci-i2s mapping ok
ALSA device list:
  #0: DaVinci EVM (tlv320aic3x)
TCP cubic registered
NET: Registered protocol family 17
lib80211: common routines for IEEE802.11 drivers
Clocks: disable unused mmcsd1
Clocks: disable unused spi0
Clocks: disable unused spi1
Clocks: disable unused spi2
Clocks: disable unused spi3
Clocks: disable unused spi4
Clocks: disable unused aemif
Clocks: disable unused pwm0
Clocks: disable unused pwm1
Clocks: disable unused pwm2
Clocks: disable unused pwm3
Clocks: disable unused timer1
Clocks: disable unused timer3
Clocks: disable unused emac
Clocks: disable unused voice_codec
Clocks: disable unused rto
Clocks: disable unused mjcp
davinci_emac_probe: using random MAC addr: fe:06:51:2c:4d:aa
emac-mii: probed
Waiting for root device /dev/mmcblk0p2...
mmc0: host does not support reading read-only switch. assuming write-enable.
mmc0: new SDHC card at address a37d
mmcblk0: mmc0:a37d SD04G 3.69 GiB
 mmcblk0: p1 p2
kjournald starting.  Commit interval 5 seconds
EXT3 FS on mmcblk0p2, internal journal
EXT3-fs: recovery complete.
EXT3-fs: mounted filesystem with writeback data mode.
VFS: Mounted root (ext3 filesystem) on device 179:2.
Freeing init memory: 144K
INIT: version 2.86 booting
Please wait: booting...
Starting udev
udev: starting version 141
Remounting root file system...
Caching udev devnodes
Populating dev cachemv: cannot rename '/tmp/devices': No such file or directory
/etc/init.d/rc: eval: line 1: syntax error: EOF in backquote substitution
ALSA: Restoring mixer settings...
Configuring network interfaces... No state is present for card EVM
Unknown hardware: "tlv320aic3x" "" "" "" ""
Hardware is initialized using a guess method
No state is present for card EVM
udhcpc (v1.13.2) started
Sending discover...
Sending discover...
Sending discover...
No lease, forking to background
done.
Setting up IP spoofing protection: rp_filter.
hwclock: can't open '/dev/misc/rtc': No such file or directory
Thu Mar 24 19:02:00 UTC 2011
hwclock: can't open '/dev/misc/rtc': No such file or directory
INIT: Entering runlevel: 5
chown: unknown user messagebus
Starting telnet daemon.
Starting syslogd/klogd: done
Starting thttpdNET: Registered protocol family 10
.
CMEMK module: built on Jun 14 2011 at 18:02:26
  Reference Linux version 2.6.32
  File /home/gigijoe/LeopardBoard/DM368/original/ti-dvsdk_dm368-evm_4_02_00_06/linuxutils_2_26_01_02/packages/ti/sdo/linuxutils/cmem/src/module/cmemk.c
allocated heap buffer 0xc6000000 of size 0x4400000
heap fallback enabled - will try heap if pool buffer is not available
CMEM Range Overlaps Kernel Physical - allowing overlap
CMEM phys_start (0x1000) overlaps kernel (0x80000000 -> 0x83c00000)
cmemk initialized
IRQK module: built on Jun 14 2011 at 18:02:29
  Reference Linux version 2.6.32
  File /home/gigijoe/LeopardBoard/DM368/original/ti-dvsdk_dm368-evm_4_02_00_06/linuxutils_2_26_01_02/packages/ti/sdo/linuxutils/irq/src/module/irqk.c
irqk initialized
EDMAK module: built on Jun 14 2011 at 18:02:30
  Reference Linux version 2.6.32
  File /home/gigijoe/LeopardBoard/DM368/original/ti-dvsdk_dm368-evm_4_02_00_06/linuxutils_2_26_01_02/packages/ti/sdo/linuxutils/edma/src/module/edmak.c
Calibrating touchscreen (first time only)ts_open: No such file or directory
.
Starting Matrix GUI application.

 _____                    _____           _         _  
|  _  |___ ___ ___ ___   |  _  |___ ___  |_|___ ___| |_
|     |  _| .'| . | . |  |   __|  _| . | | | -_|  _|  _|
|__|__|_| |__,|_  |___|  |__|  |_| |___|_| |___|___|_| 
              |___|                    |___|           

Arago Project http://arago-project.org dm368-evm ttyS0

Arago 2011.02 dm368-evm ttyS0

dm368-evm login:


11.Fix Alsa probleam

ALSA: Restoring mixer settings...
Configuring network interfaces... No state is present for card EVM
Unknown hardware: "tlv320aic3x" "" "" "" ""
Hardware is initialized using a guess method
No state is present for card EVM

The problem is due to wrong /etc/asound.state
While booting /etc/init.d/alsa-state loads /etc/asound.state if it exist

To fix it, just do

$ rm -rf /etc/asound.state






2011年6月3日 星期五

Linux 3.0.0 rc1 released

Linux 終於在5月30日邁入新的重大版本 3.0
根據Linus的說法,這次的進版並沒有任何架構或API的重大變革,
而是Linus本人對於2.6.40以上的版本編號不認同以及2.X版本已歷經接近20年故有此進版動作.

回想Linux 2.2時代我才剛接觸Linux,
對Unix系統完全陌生還活在微軟帝國的勢力範圍,

而Linux 2.4時代進入職場開始真正使用並學習Linux.

時間過的真快啊,呵呵呵.

留一段 linux-omap 3.0.0-rc1 kernel build log 紀念這個重大的時刻.

  GEN     /home/gigijoe/BeagleBoard/build-linux-omap-2.6/Makefile
scripts/kconfig/conf --silentoldconfig Kconfig
  Using /home/gigijoe/BeagleBoard/linux-omap-2.6 as source for kernel
  GEN     /home/gigijoe/BeagleBoard/build-linux-omap-2.6/Makefile
make[2]: Nothing to be done for `all'.
  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
make[2]: `include/generated/mach-types.h' is up to date.
  CALL    /home/gigijoe/BeagleBoard/linux-omap-2.6/scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  GZIP    kernel/config_data.gz
  IKCFG   kernel/config_data.h
  CC      kernel/configs.o
  LD      kernel/built-in.o
  LD      drivers/usb/storage/built-in.o
  LD      drivers/usb/built-in.o
  LD      drivers/built-in.o
  LD      vmlinux.o
  MODPOST vmlinux.o
  GEN     .version
  CHK     include/generated/compile.h
  UPD     include/generated/compile.h
  CC      init/version.o
  LD      init/built-in.o
  LD      .tmp_vmlinux1
  KSYM    .tmp_kallsyms1.S
  AS      .tmp_kallsyms1.o
  LD      .tmp_vmlinux2
  KSYM    .tmp_kallsyms2.S
  AS      .tmp_kallsyms2.o
  LD      vmlinux
  SYSMAP  System.map
  SYSMAP  .tmp_System.map
  OBJCOPY arch/arm/boot/Image
  Kernel: arch/arm/boot/Image is ready
  GZIP    arch/arm/boot/compressed/piggy.gzip
  AS      arch/arm/boot/compressed/piggy.gzip.o
  SHIPPED arch/arm/boot/compressed/lib1funcs.S
  AS      arch/arm/boot/compressed/lib1funcs.o
  LD      arch/arm/boot/compressed/vmlinux
  OBJCOPY arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready
  UIMAGE  arch/arm/boot/uImage
Image Name:   Linux-3.0.0-rc1-next-20110530-11
Created:      Sat Jun  4 04:59:29 2011
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    2830748 Bytes = 2764.40 kB = 2.70 MB
Load Address: 0x80008000
Entry Point:  0x80008000
  Image arch/arm/boot/uImage is ready
gigijoe@gigijoe-laptop:~/BeagleBoard/linux-omap-2.6$ ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- make O=~/BeagleBoard/build-linux-omap-2.6 modules
  Using /home/gigijoe/BeagleBoard/linux-omap-2.6 as source for kernel
  GEN     /home/gigijoe/BeagleBoard/build-linux-omap-2.6/Makefile
make[2]: Nothing to be done for `all'.
  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
make[2]: `include/generated/mach-types.h' is up to date.
  CALL    /home/gigijoe/BeagleBoard/linux-omap-2.6/scripts/checksyscalls.sh
  Building modules, stage 2.
  MODPOST 2 modules


2011年5月13日 星期五

Beagleboard xM - Camera board LI-5M03

玩了一陣子LI-BCM3M1 camera board發現不管什麼解析度都只能達到5~8fps.數據相當的難看,主要原因是driver限制住了.
到chip vendor Aptina網站找mt9t112 datasheet 竟然還要簽 NDA,發信去也不鳥我...Shit.

因此轉而試試五百萬畫素的LI-5M03, Aptina 有提供datasheet
http://www.aptina.com/products/image_sensors/mt9p031i12stc/
此外更提供給BeagleBoard XM driver source code放在github,我clone了一份.
https://github.com/gigijoe/BeagleBoard-xM

mt9p031 driver我有做一些修改
其中值得一提的是Camera輸出的影像非常暗,所以我把analog gain調高

@@ -538,12 +538,19 @@
     mdelay(200);
 
     ret |= mt9p031_set_params(priv->client, pix->width, pix->height);
-   
+#if 0   
     ret |= mt9p031_reg_write(client, REG_MT9P031_GREEN_1_GAIN, 0x0051);      //Green1_gain_reg
     ret |= mt9p031_reg_write(client, REG_MT9P031_BLUE_GAIN, 0x0051);      //Blue_gain_reg
     ret |= mt9p031_reg_write(client, REG_MT9P031_RED_GAIN, 0x0051);      //Red_gain_reg
     ret |= mt9p031_reg_write(client, REG_MT9P031_GREEN_2_GAIN, 0x0051);      //Green2_gain_reg
     ret |= mt9p031_reg_write(client, REG_MT9P031_GLOBAL_GAIN, 0x0008);        //Analog Gain
+#endif
+  ret |= mt9p031_reg_write(client, REG_MT9P031_GREEN_1_GAIN, 0x0079);   //Green1_gain_reg
+  ret |= mt9p031_reg_write(client, REG_MT9P031_BLUE_GAIN, 0x0079);    //Blue_gain_reg
+  ret |= mt9p031_reg_write(client, REG_MT9P031_RED_GAIN, 0x0079);   //Red_gain_reg
+  ret |= mt9p031_reg_write(client, REG_MT9P031_GREEN_2_GAIN, 0x0079);   //Green2_gain_reg
+  ret |= mt9p031_reg_write(client, REG_MT9P031_GLOBAL_GAIN, 0x0026);    //Analog Gain



這份driver source code 要自行擺放檔案到正確的位置,以及部份檔案需要手動剪貼.
基本上不困難,我就不在此詳述.更動檔案如下

arch/arm/mach-omap2/board-omap3beagle.c
arch/arm/mach-omap2/board-omap3beagle-camera.c
drivers/media/video/mt9p031.c
drivers/media/video/mt9p031.h
drivers/media/video/Makefile
drivers/media/video/Kconfig

設定mt9p031 kernel config 為
接著重新compile kernel及module並安裝至root file system.

如果driver 順利掛上,在kernel log會看到

mt9p031 2-0048: mt9p031 chip ID 1801

根據driver source 中 README提到可以透過sysfs更改camera 參數.我實際測試卻出現錯誤@@

# cd /sys/devices/platform/i2c_omap.2/i2c-2/2-0048/
# cat gain_val 24
# echo "40" > gain_val
[ 2209.002258] mt9p031 2-0048: Error setting gain.-121
[ 2209.006988] mt9p031: Global gain write failed

Camera 測試的可用gstreamer.
不過實際測試frame rate還是無法到達30fps應該是gstreamer效率的關係,
因此我修改TI提供的demo程式來讀取camera確實就能達到30fps.
接著再把以前曾經實做過的以TI DSP encode H.264加上去,最後再輸出打包為H264RTP封包.
source code放在github

https://github.com/gigijoe/BeagleBoard-xM-video_encode_v4l2_rtp

將project抓下來後請搬到
$DVSDK/dmai_2_20_00_14/packages/ti/sdo/dmai/apps/
cd $DVSDK
make dmai

執行檔位在
dmai_2_20_00_14/packages/ti/sdo/dmai/apps/video_encode_v4l2_rtp/linux/video_encode_v4l2_rtp_dm3730.x470MV

將它複製到root filesystem中 /usr/share/ti/ti-dmai-apps/

萬事具備,執行吧

BeagleBoard xM

cd /usr/share/ti/ti-dmai-apps/
./video_encode_v4l2_rtp_dm3730.x470MV -b 2000000 -c h264enc -i /dev/video0 -o 192.168.168.93 -p 1234 -r 640x480 --benchmark

PC : IP 192.168.168.93

gst-launch udpsrc port=1234 caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264" ! rtph264depay ! ffdec_h264 ! xvimagesink


最後在透過usb ethernet 傳送影像會hang住,網路上有人發生過但還沒有答案.

http://groups.google.com/group/beagleboard/browse_thread/thread/375026c833e1308b/528751f3690c7d5b?lnk=raot

[  103.995117] ------------[ cut here ]------------
[  103.999908] WARNING: at net/sched/sch_generic.c:255 dev_watchdog+0x17c/0x280()
[  104.007202] NETDEV WATCHDOG: usb0 (smsc95xx): transmit queue 0 timed out
[  104.014099] Modules linked in: sdmak lpm_omap3530 dsplinkk cmemk bufferclass_ti omaplfb pvrsrvkm ipv6 rtc_twl rtc_core mt9p031
[  104.025756] [ ] (unwind_backtrace+0x0/0xdc) from [ ] (warn_slowpath_common+0x48/0x60)
[  104.035247] [ ] (warn_slowpath_common+0x48/0x60) from [ ] (warn_slowpath_fmt+0x24/0x30)
[  104.044921] [ ] (warn_slowpath_fmt+0x24/0x30) from [ ] (dev_watchdog+0x17c/0x280)
[  104.054199] [ ] (dev_watchdog+0x17c/0x280) from [ ] (run_timer_softirq+0x268/0x378)
[  104.063568] [ ] (run_timer_softirq+0x268/0x378) from [ ] (__do_softirq+0xf0/0x1ec)
[  104.072784] [ ] (__do_softirq+0xf0/0x1ec) from [ ] (irq_exit+0x48/0x9c)
[  104.081024] [ ] (irq_exit+0x48/0x9c) from [ ] (asm_do_IRQ+0x74/0x90)
[  104.089019] [ ] (asm_do_IRQ+0x74/0x90) from [ ] (__irq_svc+0x44/0xa8)
[  104.097076] Exception stack(0xc0603f88 to 0xc0603fd0)
[  104.102172] 3f80:                   00000000 80000013 00f9982c 00000000 c0602000 c064db9c
[  104.110412] 3fa0: c002f014 c0605e68 8002cc0c 413fc082 0000001f 00000000 c06085b8 c0603fd0
[  104.118774] 3fc0: c0045450 c0036f1c 60000013 ffffffff
[  104.123962] [ ] (__irq_svc+0x44/0xa8) from [ ] (cpu_idle+0x78/0xbc)
[  104.131866] [ ] (cpu_idle+0x78/0xbc) from [ ] (start_kernel+0x260/0x2c0)
[  104.140197] [ ] (start_kernel+0x260/0x2c0) from [<80008034>] (0x80008034)
[  104.147827] ---[ end trace 640b83e4eff706c8 ]---

我猜應該是hardware的問題,因為我用USB Wifi也會當.
目前的解法是從USB otg port接USB hub再接USB wifi.
這樣,網路就不會斷了...

Reference :
http://maxgalemin.blogspot.com/2011/04/li-5m03-camera-on-beagleboard-xm.html

http://gitorious.org/rowboat/hardware-ti-omap3/blobs/e82865bd56a086480972fecdecc6f38308c05c35/liboverlay/v4l2_utils.c

http://blogold.chinaunix.net/u/19273/showart_2254379.html

http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/100/t/7826.aspx

http://e2e.ti.com/support/dsp/omap_applications_processors/f/447/p/87922/303994.aspx






2011年5月5日 星期四

BeagleBoard Uart Level Shift

There are three Uart port can be use on BeagleBoard, while Uart 3 as default console port, Uart 1 & 2 are free to use. There are many devices can be connect to Uart, such as GPS module, blue tooth module and PWM controller.

But, there's a serious problem. The BeagleBoard I/O works at 1.8v and for most of devices 1.8v is not "High" enough. So, I'm trying to higher the 1.8v signal to 5v signal.
Google this issue, I found the procdure is called "Level Shift" and can be done with two n-channel FET. The actual electronic circuit as below.

http://www-g.eng.cam.ac.uk/mmg/teaching/linearcircuits/mosfet.html

 

The n-channel FET is 2N7000
http://www.fairchildsemi.com/ds/2N/2N7000.pdf

According to BeagleBoard SRM (System Reference Manual), Uart 2 pins can be found on the expansion header.

PIN 6 - UART2_TX

Make sure the pin mux is correct configured. It should be work.




2011年5月4日 星期三

BeagleBoard i2c SRF08 example code

According to http://www.robot-electronics.co.uk/htm/srf08tech.shtml


i2c_srf08.h



/*
 * i2c_srf08.h : SRF08 ultra sonic range finder
 *
 *  (C) 2011 by Steve Chang
 *  stevegigijoe@yahoo.com.tw
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef _I2C_SRF08_H
#define _I2C_SRF08_H

#include "bool.h"

typedef struct I2cSrf08 I2cSrf08;

I2cSrf08 *I2cSrf08_DefaultInstance(char *device);
int I2cSrf08_Open(I2cSrf08 *is);
void I2cSrf08_Close(I2cSrf08 *is);
void I2cSrf08_SetMaxRange(I2cSrf08 *is, unsigned char range);
void I2cSrf08_SetMaxGain(I2cSrf08 *is, unsigned char gain);
int I2cSrf08_BlockRangeInCentimeters(I2cSrf08 *is);
int I2cSrf08_RangingInCentimeters(I2cSrf08 *is);
int I2cSrf08_GetRange(I2cSrf08 *is);

#endif


i2c_srf08.c


/*
 * i2c_srf08.c : SRF08 ultra sonic range finder
 *
 *  (C) 2011 by Steve Chang
 *  stevegigijoe@yahoo.com.tw
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include
#include
#include
#include
#include
#include
#include

#include "i2c_srf08.h"

struct I2cSrf08  {
  int fd;
  char *device;
  unsigned char range;
  unsigned char gain;
  bool ranging;
};

I2cSrf08 *I2cSrf08_DefaultInstance(char *device)
{
  static I2cSrf08 i2csrf08;
 
  if(!device)
    return 0;

  memset(&i2csrf08, 0, sizeof(I2cSrf08));
 
  i2csrf08.device = strdup(device);
#if 0 
  i2csrf08.range = 0xff; /*  11 m : default */
  i2csrf08.range = 0x8c; /*  6 m */
  i2csrf08.range = 0x18; /*  1 m */
  i2csrf08.range = 0x1;  /*  86 mm */
  i2csrf08.range = 0x0;  /*  43 mm */
#endif
  i2csrf08.range = 0xff; /*  11 m : default */

#if 0
  i2csrf08.gain = 0x0; /*  min 94 */
  i2csrf08.gain = 0x1f; /* default & max 1025 */
#endif
  i2csrf08.gain = 0x1f;
 
  return &i2csrf08;
}

#define SRF08_I2C_ADDR  0x70

int I2cSrf08_Open(I2cSrf08 *is)
{
  is->fd = open(is->device, O_RDWR);
  if(is->fd == -1)
    return -1;
 
  if(ioctl(is->fd, I2C_SLAVE, SRF08_I2C_ADDR) < 0)  {
    printf("[SRF08] None exist device address 0x%x\n", SRF08_I2C_ADDR);
    close(is->fd);
    is->fd = 0;
    return -1;
  }
 
  unsigned char buf[2];
 
  buf[0] = 0x1; /*  Register 1  */
  buf[1] = is->gain;  /*  Gain */
  if(write(is->fd, buf, 2) != 2)
    return -1;

  buf[0] = 0x2; /*  Register 2  */
  buf[1] = is->range;  /*  Range */
  if(write(is->fd, buf, 2) != 2)
    return -1;
 
  return is->fd;
}

void I2cSrf08_Close(I2cSrf08 *is)
{
  if(is->fd)
    close(is->fd);
  is->fd = 0;
}

void I2cSrf08_SetMaxRange(I2cSrf08 *is, unsigned char range)
{
  is->range = range;
 
  unsigned char buf[2];
 
  buf[0] = 0x2; /*  Register 2  */
  buf[1] = is->range;  /*  Range */
  if(write(is->fd, buf, 2) != 2)
    printf("[SRF08] Fail to write !!!\n");
 
  return;
}

void I2cSrf08_SetMaxGain(I2cSrf08 *is, unsigned char gain)
{
  if(gain > 0x1f)
    gain = 0x1f;
 
  is->gain = gain;
 
  unsigned char buf[2];
 
  buf[0] = 0x1; /*  Register 1  */
  buf[1] = is->gain;  /*  Gain */
  if(write(is->fd, buf, 2) != 2)
    printf("[SRF08] Fail to write !!!\n");
 
  return;
}

int I2cSrf08_BlockRangeInCentimeters(I2cSrf08 *is)
{
  unsigned char buf[2];
 
  buf[0] = 0x0; /*  Register 0  */
  buf[1] = 81;  /*  Range in centimeters */
  if(write(is->fd, buf, 2) != 2)
    return -1;
 
  while(1)  {
    usleep(65000);

    buf[0] = 0x0; /*  Register 0 : software reversion */
    if(write(is->fd, buf, 1) != 1)  {
      usleep(100);
      continue;
    }
   
    if(read(is->fd, buf, 1) != 1)  {
      usleep(100);
      continue;
    }
   
    if(buf[0] != 0xff)  /*  While ranging it returns 0xff */
      break;  /*  Range data ready now  */
  }
 
  int i;
  char hb, lb;
  unsigned short r = 0;
  for(i=0;i<17;i++) { /*  There are 17 echo buffers */
    buf[0] = 2 + (i << 1); /*  Register 2, 4, 6 ...  */
    if(write(is->fd, buf, 1) != 1)
      return -1;
    if(read(is->fd, buf, 1) != 1)
      return -1;
    hb = buf[0];

   
    buf[0] = 3 + (i << 1); /*  Register 3, 5, 7 ...  */
    if(write(is->fd, buf, 1) != 1)
      return -1;
    if(read(is->fd, buf, 1) != 1)
      return -1;
    lb = buf[0];

    if(hb == 0 && lb == 0)
      break;
/*   
    printf("High byte : %d\n", hb);
    printf("Low byte : %d\n", lb);
*/
    r = (hb << 8) + lb;
    printf("[SRF08] %dst echo range = %u\n", i, r);
  }
 
  return 0;
}

int I2cSrf08_RangingInCentimeters(I2cSrf08 *is)
{
  if(is->ranging == true)
    return 0;

  unsigned char buf[2];

  buf[0] = 0x0; /*  Register 0  */
  buf[1] = 81;  /*  Range in centimeters */
  if(write(is->fd, buf, 2) != 2)
    return -1;
 
  is->ranging = true;
 
  return 0;
}

int I2cSrf08_GetRange(I2cSrf08 *is)
{
  if(is->ranging == false)
    return 0;

  unsigned char buf[1];

  char hb, lb;

  buf[0] = 0x0; /*  Register 0 : software reversion */
  if(write(is->fd, buf, 1) != 1)
    return -1;
  if(read(is->fd, buf, 1) != 1) {
    printf("[SRF08] Fail to read !!!\n");
    return -1;
  }

  if(buf[0] == 0xff)  {
    printf("[SRF08] Range data not ready !!!\n");
    return -1;
  }

  buf[0] = 2; /*  Register 2, 4, 6 ...  */
  if(write(is->fd, buf, 1) != 1)
    return -1;

  if(read(is->fd, buf, 1) != 1)
    return -1;

  hb = buf[0];

  buf[0] = 3; /*  Register 3, 5, 7 ...  */
  if(write(is->fd, buf, 1) != 1)
    return -1;

  if(read(is->fd, buf, 1) != 1)
    return -1;

  lb = buf[0];

  is->ranging = false;
 
  if(hb == 0 && lb == 0)  {
    printf("[SRF08] Fail to get range !!!\n");
    return -1;
  }

  unsigned short r = (hb << 8) + lb;
 
  return (int)r;
}


ultra_sonic.c


/*
 * ultra_sonic.c : SRF08 ultra sonic range finder sample program
 *
 *  (C) 2011 by Steve Chang
 *  stevegigijoe@yahoo.com.tw
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include

#include "i2c_srf08.h"

#define I2C_SRF08_DEVICE  "/dev/i2c-2"

int main(int argc, char **argv)
{
  I2cSrf08 *is = I2cSrf08_DefaultInstance(I2C_SRF08_DEVICE);
 
  int r = I2cSrf08_Open(is);
  if(r == -1) {
    printf("Fail to open %s\n", I2C_SRF08_DEVICE);
    goto leave;
  }

  while(1)
    I2cSrf08_BlockRangeInCentimeters(is);

leave:
  I2cSrf08_Close(is);

  return r;
}


The result as below

# ./ultra_sonic
[  851.740844] i2c_omap i2c_omap.2: Transmit error
[SRF08] 0st echo range = 32
[SRF08] 1st echo range = 86
[SRF08] 2st echo range = 150
[SRF08] 3st echo range = 216
[SRF08] 4st echo range = 280
[SRF08] 5st echo range = 344
[SRF08] 6st echo range = 410
[SRF08] 7st echo range = 474
[SRF08] 8st echo range = 560
[SRF08] 9st echo range = 795
[SRF08] 10st echo range = 926
[SRF08] 11st echo range = 1050
[SRF08] 0st echo range = 33
[SRF08] 1st echo range = 87
[SRF08] 2st echo range = 151
[SRF08] 3st echo range = 217
[SRF08] 4st echo range = 281
[SRF08] 5st echo range = 346
[SRF08] 6st echo range = 410
[SRF08] 7st echo range = 474
[SRF08] 8st echo range = 563
[SRF08] 9st echo range = 630
[SRF08] 10st echo range = 795





2011年4月27日 星期三

BeagleBoard i2c SRF08

SRF08 is an ultra sonic range finder, I'm trying to connect it to BeagleBoard. The hardware interface is i2c and we need to do some modify to kernel & u-boot to get it work.

http://www.robot-electronics.co.uk/htm/srf08tech.shtml

Reference
http://yetanotherhackersblog.wordpress.com/2011/04/07/interfacing-the-beagleboard-with-an-srf08-ultrasonic-ranger-over-i2c/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+BeagleBoard+%28BeagleBoard.org%29&utm_content=FaceBook

1.Hardware interface
BeagleBoard i2c interface runs at 1.8v and SRF08 i2c interface runs at 5v. In order to get it work, we need i2c level shift. There are some chips can do it, what I got is PCA9517.
http://elinux.org/BeagleBoard_Hardware_Interfacing

http://ics.nxp.com/support/documents/interface/pdf/an97055.pdf

2.The circuit


We are planing to use BeagleBoard I2C2 interface, which pins are at expansion connector pin 23 and 24.

Be attention ! all the 10k resisters are rquired.
http://groups.google.com/group/beagleboard/browse_thread/thread/a6c42ef56c6a2da2/1608e6c0f0207a8d?lnk=raot

3.u-boot
First, make sure the pin mux is correct.

boards/ti/beagle/beagle.h

-MUX_VAL((CP(I2C2_SCL), (IEN | PTU | EN | M4) \
-MUX_VAL((CP(I2C2_SDA), (IEN | PTU | EN | M4) \
+MUX_VAL((CP(I2C2_SCL), (IEN | PTU | EN | M0) \
+MUX_VAL((CP(I2C2_SDA), (IEN | PTU | EN | M0) \


Then enable pull-up internal resister on i2c2
http://groups.google.com/group/beagleboard/browse_thread/thread/f5d308f24b27bb38/21febf1a98e0be0c?lnk=raot


4.kernel
Enable I2C2 interface

static int __init omap3_beagle_i2c_init(void)
{
        omap_register_i2c_bus(1, 2600, beagle_i2c_boardinfo,
                        ARRAY_SIZE(beagle_i2c_boardinfo));

+#if defined CONFIG_INPUT_ST_MOTION_SENSOR
        omap_cfg_reg(AE4_34XX_GPIO136);
        omap_register_i2c_bus(2, 400, beagle_i2c2_boardinfo,
                        ARRAY_SIZE(beagle_i2c2_boardinfo));
+#else
+       omap_register_i2c_bus(2, 100, NULL, 0);
+#endif
        /* Bus 3 is attached to the DVI port where devices like the pico DLP
         * projector don't work reliably with 400kHz */
        omap_register_i2c_bus(3, 100, NULL, 0);
        return 0;
}

Then you can find /dev/i2c-2 device node

5.Testing

# ls /dev/i2c-2 -al
crw-rw----    1 root     root      89,   2 Jan  1 00:00 /dev/i2c-2

# i2cdetect -r 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2 using read byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: 70 -- -- -- -- -- -- --                        


Get range in centimeters

# i2cset 2 112 0 81
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will write to device file /dev/i2c-2, chip address 0x70, data address
0x00, data 0x51, mode byte.
Continue? [Y/n] y
# i2cget 2 112 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-2, chip address 0x70, data address
0x02, using read byte data.
Continue? [Y/n] y
0x00
# i2cget 2 112 3
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-2, chip address 0x70, data address
0x03, using read byte data.
Continue? [Y/n] y
0x25

We got 0x25 = 37 cm




2011年4月8日 星期五

Beagleboard xM - Camera board

延續之前 DVSDK ,接著來看DSP Multimedia的應用

1.Beagleboard XM camera board
Leopard imaging inc 有一系列camera board支援BeagleBoard XM.
https://www.leopardimaging.com/Beagle_Board_xM_Camera.html\



有1.3M / 3M / 5M (百萬畫素) 鏡頭.其中 1.3M / 3M camera board 在 DVSDK 上已有driver.
我手邊有 LI-LBCM3M1 三百萬畫素 CMOS sensor mt9t111 (相容 mt9t112), DVSDK PSP linux已經包含mt9t112 driver.
載入camera driver需要修改bootloader 環境變數.
首先將SD card 連接至PC, 新增檔案BOOT/boot_dvi_lbcm3m1.cmd 如下

setenv bootargs 'console=ttyS2,115200n8 root=/dev/mmcblk0p2 rw ip=off mem=55M@0x80000000 mpurate=1000  omap_vout.vid1_static_vrfb_alloc=y omapfb.vram=0:8M mem=384M@0x88000000 omapfb.mode=dvi:hd720 omapdss.def_disp=dvi rootwait vram=8M camera=lbcm3m1'
fatload mmc 0 80200000 uImage
bootm 80200000

接著產生 boot_dvi_lbcm3m1.scr

gigijoe@gigijoe-laptop:/media/BOOT$ mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n 'Execute Boot Script' -d boot_dvi_lbcm3m1.cmd boot_dvi_lbcm3m1.scr
Image Name:   Execute Boot Script
Created:      Tue Mar 29 20:19:04 2011
Image Type:   ARM Linux Script (uncompressed)
Data Size:    304 Bytes = 0.30 kB = 0.00 MB
Load Address: 0x00000000
Entry Point:  0x00000000
Contents:
   Image 0:      296 Bytes =    0 kB = 0 MB

增加camera=lbcm3m1,使相對應的driver會被自動載入.

root@beagleboard-dvsdk:~# lsmod
Module                  Size  Used by
sdmak                   3759  0
lpm_omap3530            6537  0
dsplinkk              124358  1 lpm_omap3530
cmemk                  21358  0
bufferclass_ti          4838  0
omaplfb                 8770  0
pvrsrvkm              129682  2 bufferclass_ti,omaplfb
ipv6                  249320  14
rtc_twl                 4263  0
rtc_core               12531  1 rtc_twl
mt9t112                 9329  0

2.Test camera board
首先先測試camera影像是否正常,最方便的方式是使用DVSDK built-in gstreamer
Camera device node 是 /dev/video0

gst-launch v4l2src always_copy=FALSE ! video/x-raw-yuv,width=640,height=480 ! queue max-size-buffers=8000 max-size-time=0 max-size-bytes=0 ! TIDmaiVideoSink videoStd=720P_60 videoOutput=AUTO numBufs=5

應該會在DVI output上看到影像



3.Play with camera board

現在來看實際上的應用,場景是將Camera board得到的影像透過DSP 壓縮成H.264格式,接著以RTP H.264封裝透過網路傳送到PC端,接著PC端將影像解壓縮並顯示在銀幕上

BeagleBoard XM : 192.168.168.89

gst-launch v4l2src always_copy=FALSE ! video/x-raw-yuv,width=640,height=480 ! queue max-size-buffers=8000 max-size-time=0 max-size-bytes=0 ! TIVidenc1 codecName=h264enc engineName=codecServer ! rtp264pay pt=96 ! multiudpsink client="192.168.168.56:1234"

PC : 192.168.168.56

gst-launch udpsrc port=1234 caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264" ! gstrtpjitterbuffer latency=100 ! rtph264depay ! ffdec_h264 ! xvimagesink



2011年3月30日 星期三

Beagleboard xM with TI DVSDK 4_01_00_09

Beagleboard xM 跟之前的 Beagleboard有相當多的差異,除了CPU / DSP 時脈的提昇,週邊也多了Ethernet, USB Hub 及 Camera interface.
不過 Nand flash 據說是因為成本的因素而拿掉了.因此Beagleboard xM只能經由 SD card boot.

TI DVSDK 提供很完整的多媒體展示,包含Media encode / decode, OpenGL 3D demo.
接下來將試著將Beagleboard xM DVSDK 安裝至 SD card.

1.參考DVSDK FAQ
http://processors.wiki.ti.com/index.php/DVSDK_4.x_FAQ#How_to_build_and_install_DVSDK_4.01_on_BeagleBoard-xM

根據DVSDK FAQ得知所需要的必要環境是 Ubuntu 10.04. Cross compile 為 CodeSourcery ARM 2009q1

2.Download DM3730 DVSDK 4.01 from TI
http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/dvsdk/DVSDK_4_00/latest/index_FDS.html
下載 dvsdk_dm3730-evm_4_01_00_09_setuplinux,大小約為1.5G.
下載時 TI 會要求帳號密碼,請自行註冊登入.注意帳號的Email 不能是yahoo之類的免費帳號.

下載完成後先變更檔案權限為可執行
$ chmod 755 dvsdk_dm3730-evm_4_01_00_09_setuplinux

執行安裝
$ ./dvsdk_dm3730-evm_4_01_00_09_setuplinux

3.Download patch script for DVSDK 4.01 to support BeagleBoard XM

http://processors.wiki.ti.com/images/5/5b/Setup-dvsdk-4-01-beaglexm-110126.zip

TI DVSDK並沒有支援Beagleboard xM,因此必須要做一些patch.
解開zip檔後會得到檔案 setup-dvsdk-4-01-beaglexm-110126.sh.
將它放在DVSDK root目錄,再依照以下內容修改 setup-dvsdk-4-01-beaglexm-110126.sh.



--- ../setup-dvsdk-4-01-beaglexm-110126.sh    2011-02-04 06:53:32.000000000 +0800
+++ setup-dvsdk-4-01-beaglexm-110126-fix.sh    2011-03-28 21:14:21.206840024 +0800
@@ -67,10 +67,10 @@
 
 # Comment out these 4 lines if you have direct internet connection
 
-PROXYHOST="foo.com"
-PROXYPORT="80"
-export http_proxy="http://${PROXYHOST}:${PROXYPORT}"
-export GIT_PROXY_COMMAND=./git-proxy.sh
+#PROXYHOST="foo.com"
+#PROXYPORT="80"
+#export http_proxy="http://${PROXYHOST}:${PROXYPORT}"
+#export GIT_PROXY_COMMAND=./git-proxy.sh
 
 # Generate git proxy command config script
 cat > git-proxy.sh <<_EOF
@@ -128,7 +128,9 @@
 
 # Apply the patches to the local repository
 for patchfile in ${XLOADPATCHESSTRIPPED} ; do
-    git am oepatches/$patchfile
+    git am --abort
+#    git am oepatches/$patchfile
+    git apply oepatches/$patchfile
 done
 
 cd ..



這個修改是為了可直接連上internet及修正 git am 所造成的 bug

4.變更權限並執行
$ chmod 755 setup-dvsdk-4-01-beaglexm-110126.sh
$ ./setup-dvsdk-4-01-beaglexm-110126.sh
這時這個script會自動去抓許多patch檔,並更新至DVSDK

5.編譯DVSDK
至DVSDK root目錄下

make clean
make all

6.安裝DVSDK 至 SD card

將SD card 連接至PC, 再來弄清楚device node為何 (用dmesg)
以我來說是 /dev/sdd

$ sudo bin/mksdboot.sh --device /dev/sdd --sdk ${PWD}
************************************************************
*         THIS WILL DELETE ALL THE DATA ON /dev/sdd        *
*                                                          *
*         WARNING! Make sure your computer does not go     *
*                  in to idle mode while this script is    *
*                  running. The script will complete,      *
*                  but your SD card may be corrupted.      *
*                                                          *
*         Press to confirm....                     *
************************************************************

unmounting device '/dev/sdd1'
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.904471 s, 1.2 MB/s
Disk /dev/sdd doesn't contain a valid partition table
Checking that no-one is using this disk right now ...
OK

Disk /dev/sdd: 1949 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature
 /dev/sdd: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sdd1   *      0+      4       5-     40131    c  W95 FAT32 (LBA)
/dev/sdd2          5    1948    1944   15615180   83  Linux
/dev/sdd3          0       -       0          0    0  空
/dev/sdd4          0       -       0          0    0  空
Successfully wrote the new partition table

Re-reading the partition table ...

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
Formating /dev/sdd1 ...
Formating /dev/sdd2 ...
mke2fs 1.41.11 (14-Mar-2010)
Image Name:   Execute uImage.bin
Created:      Mon Mar 28 20:31:49 2011
Image Type:   ARM Linux Script (uncompressed)
Data Size:    238 Bytes = 0.23 kB = 0.00 MB
Load Address: 0x00000000
Entry Point:  0x00000000
Contents:
   Image 0:      230 Bytes =    0 kB = 0 MB
Image Name:   Execute uImage.bin
Created:      Mon Mar 28 20:31:50 2011
Image Type:   ARM Linux Script (uncompressed)
Data Size:    289 Bytes = 0.28 kB = 0.00 MB
Load Address: 0x00000000
Entry Point:  0x00000000
Contents:
   Image 0:      281 Bytes =    0 kB = 0 MB
Select Primary display output:
 1: LCD
 2: DVI

Copying u-boot/mlo/uImage on /dev/sdd1
unmounting /dev/sdd1
Extracting filesystem on /dev/sdd2 ...
Creating matrix-gui-e symbolic link...done
unmounting /dev/sdd2
completed!
Updating FS with modified beagleboard-xM files
unmounting /dev/sdd2
Done



到這裡SD card已經準備好了

7.以SD card boot Beagleboard xM

boot成功最後會看到以下登入畫面,請以root登入,無須密碼.

Escape character is '^]'.

 _____                    _____           _         _  
|  _  |___ ___ ___ ___   |  _  |___ ___  |_|___ ___| |_
|     |  _| .'| . | . |  |   __|  _| . | | | -_|  _|  _|
|__|__|_| |__,|_  |___|  |__|  |_| |___|_| |___|___|_| 
              |___|                    |___|           

Arago Project http://arago-project.org beagleboard-dvsdk

Arago 2010.11 beagleboard-dvsdk

login: root
Last login: Thu Jan 13 23:28:57 on pts/0

來看看一些系統基本資訊

CPU跑1G Hz

root@beagleboard-dvsdk:~# cat /proc/cpuinfo
Processor       : ARMv7 Processor rev 2 (v7l)
BogoMIPS        : 996.74
Features        : swp half thumb fastmult vfp edsp thumbee neon vfpv3
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x3
CPU part        : 0xc08
CPU revision    : 2

Hardware        : OMAP3 Beagle Board
Revision        : 0020
Serial          : 0000000000000000


dsplink driver已經掛上,DSP可以使用了

root@beagleboard-dvsdk:~# lsmod
Module                  Size  Used by
sdmak                   3759  0
lpm_omap3530            6537  0
dsplinkk              124358  1 lpm_omap3530
cmemk                  21358  0
bufferclass_ti          4838  0
omaplfb                 8770  0
pvrsrvkm              129682  2 bufferclass_ti,omaplfb
ipv6                  249320  14
rtc_twl                 4263  0
rtc_core               12531  1 rtc_twl


將DVI 接頭接到 monitor 會看到 Demo 畫面,



Video encode / decode, OpenGL 3D Demo




還有一個Qt base browser



2011年3月14日 星期一

MySQL Setup

After compile & install MySQL there still something need to do.
In this case, MySQL install to /media/disk/usr/mysql
So, the $BASEDIR is /media/disk/usr/mysql

1.Create $BASEDIR/etc/my.cnf

# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password    = your_password
port        = 3306
socket        = /tmp/mysqld.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
user    = mysql
port        = 3306
socket        = /tmp/mysqld.sock
datadir        = /media/disk/usr/mysql/var
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
character-set-server=utf8
collation-server=utf8_general_ci


# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (using the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
server-id    = 1

# Uncomment the following if you want to log updates
#log-bin=mysql-bin

# binary logging format - mixed recommended
#binlog_format=mixed

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /media/disk/usr/mysql/var
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /media/disk/usr/mysql/var
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout

2.Create user mysql & group mysql

3.Change owner to user & group mysql
chown -R mysql:mysql /media/disk/usr/mysql/*

4.Install database
The datadir in my.cnf is the path to install database which is /media/disk/usr/mysql/var

Execute

# mysql_install_db --defaults-file=/media/disk/usr/mysql/etc/my.cnf --user=mysql

Installing MySQL system tables...
700101  0:34:10 [Warning] option 'myisam_max_extra_sort_file_size': unsigned value 2147483648 adjusted to 2147483647
OK
Filling help tables...
700101  0:34:10 [Warning] option 'myisam_max_extra_sort_file_size': unsigned value 2147483648 adjusted to 2147483647
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/media/disk/usr/mysql/bin/mysqladmin -u root password 'new-password'
/media/disk/usr/mysql/bin/mysqladmin -u root -h localhost password 'new-password'

Alternatively you can run:
/media/disk/usr/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /media/disk/usr/mysql ; /media/disk/usr/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /media/disk/usr/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /media/disk/usr/mysql/bin/mysqlbug script!

The latest information about MySQL is available at http://www.mysql.com/
Support MySQL by buying support/licenses from http://shop.mysql.com/

5.Setup MySQL user root password

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

# mysql -u root mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.4.2-beta Source distribution

No entry for terminal type "vt102";
using dumb terminal settings.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> UPDATE user SET Password=PASSWORD('1234') where USER='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> exit
Bye

# killall -9 mysqld_safe mysqld
[2] - Killed                     bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking

6.Run MySQL server
# mysqld_safe --defaults-file=/media/disk/usr/mysql/etc/my.cnf &

7.Login MySQL

# mysql -u root -p

8.Example MySQL & php

mysql_connect.php

mysql_connect("localhost", "root", "1234") or die(mysql_error());
echo "Connected to MySQL
";
?>

mysql_select_db.php

mysql_connect("localhost", "root", "1234") or die(mysql_error());
echo "Connected to MySQL
";
mysql_select_db("test") or die(mysql_error());
echo "Connected to Database";
?>

Reference
http://amzshar.blogspot.com/2007/11/dba-mysqlsql.html



2011年1月28日 星期五

Cross Compile Lighttpd + PHP + MySQL for ARM (2)

5.Cross compile libiconv-1.13.1

$ CC=arm-none-linux-gnueabi-gcc AR=arm-none-linux-gnueabi-ar CXX=arm-none-linux-gnueabi-g++ ./configure --host=arm-linux --target=arm-linux --prefix=/opt/arm-2008q1/arm-none-linux-gnueabi/libc/usr --cache-file=/dev/null

$ make
$ sudo PATH=$PATH:/opt/arm-2008q1/bin make install

6.Cross compile libxml2-2.7.8

$ CC=arm-none-linux-gnueabi-gcc AR=arm-none-linux-gnueabi-ar CXX=arm-none-linux-gnueabi-g++ ./configure --host=arm-linux --target=arm-linux --prefix=/opt/arm-2008q1/arm-none-linux-gnueabi/libc/usr --cache-file=/dev/null

$ make
$ sudo PATH=$PATH:/opt/arm-2008q1/bin make install

7.Cross compile php-5.2.17

$ ac_cv_lib_mysqlclient_mysql_close=yes ac_cv_lib_mysqlclient_mysql_stmt_field_count=yes ac_cv_lib_mysqlclient_mysql_set_server_option=yes ac_cv_lib_mysqlclient_mysql_errno=yes ac_cv_func_iconv=yes CC=arm-none-linux-gnueabi-gcc AR=arm-none-linux-gnueabi-ar CXX=arm-none-linux-gnueabi-g++ ./configure --host=arm-linux --target=arm-linux --prefix=/home/gigijoe/BeagleBoard/rootfs/usr/local --disable-all --with-config-file-path=/rootfs/usr/local/etc --with-mysql=/home/gigijoe/BeagleBoard/rootfs/usr/local/mysql --with-mysqli=/home/gigijoe/BeagleBoard/rootfs/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysqld.sock --disable-rpath --enable-discard-path --enable-safe-mode --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-fastcgi --enable-force-cgi-redirect --enable-embedded-mysqli --with-libxml-dir=/opt/arm-2008q1/arm-none-linux-gnueabi/libc/usr --cache-file=/dev/null

$ make
$ make install

8.Cross compile lighttpd-1.4.28

$ CFLAGS="-I/home/gigijoe/BeagleBoard/rootfs/usr/local/mysql/include" CC=arm-none-linux-gnueabi-gcc AR=arm-none-linux-gnueabi-ar CXX=arm-none-linux-gnueabi-g++ ./configure --host=arm-linux --target=arm-linux --prefix=/home/gigijoe/BeagleBoard/rootfs/usr/local --with-mysql=/home/gigijoe/BeagleBoard/rootfs/usr/local/mysql --without-pcre --without-bzip2 --disable-ipv6 --cache-file=/dev/null

$ make
$ make install

9.ARM Target setup

記的將以上相關安裝到/opt/arm-2008q1/arm-none-linux-gnueabi/libc/usr的libraries複製到ARM target.

指定library搜尋路徑
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/mysql/lib

10.Reference

http://wiki.huihoo.com/index.php?title=FreeBSD_Lighttpd_PHP_MySQL

http://www.cmake.org/Wiki/CMake_Cross_Compiling

http://forge.mysql.com/wiki/Autotools_to_CMake_Transition_Guide

http://forge.mysql.com/wiki/CMake

http://redmine.lighttpd.net/wiki/1/TutorialConfiguration

http://www.memorybbs.com/cgi-bin/topic.cgi?forum=77&topic=92