Archive for September, 2011

Generating Debian FS directly into iMXT


Generating Debian FS directly into iMXT

This how to will show you how to build a Debian FS into iMXT SDCARD.

Requirements:

- iMXT running android from NAND with rooting capabilities
- Busybox
- Internet connection
- 2GB SDcard

Steps:

* Resize you SDcard, leave at least the first 8 cylinders free to host uboot and kernel
* Format the the SDcard as ext3 ie: mkfs.ext3 /dev/sdd1
* Download Debian bootstrap

sudo apt-get install debootstrap

mkdir $HOME/debootstrap

sudo debootstrap --arch armel --foreign squeeze $HOME/debootstrap http://ftp.us.debian.org/debian

#This may take a while

I: Retrieving Release
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Found additional required dependencies: insserv libbz2-1.0 libdb4.8 libslang2
I: Found additional base dependencies: libnfnetlink0 libsqlite3-0
I: Checking component main on http://ftp.us.debian.org/debian...
I: Retrieving libacl1
I: Validating libacl1
I: Retrieving adduser
I: Validating adduser
I: Retrieving apt-utils
I: Validating apt-utils
I: Retrieving apt
I: Validating apt
I: Retrieving aptitude
I: Validating aptitude
I: Retrieving libattr1
I: Validating libattr1
I: Retrieving base-files
I: Validating base-files
I: Retrieving base-passwd
I: Validating base-passwd
I: Retrieving bash
I: Validating bash
I: Retrieving libboost-iostreams1.42.0
I: Validating libboost-iostreams1.42.0
I: Retrieving bsdmainutils
I: Validating bsdmainutils
I: Retrieving libbz2-1.0
I: Validating libbz2-1.0
I: Retrieving coreutils
I: Validating coreutils
I: Retrieving cpio
...

*Copy all files from $HOME/debootstrap/ to your SDcard ext3 partition

*Insert the SDcard into your Android device

*Mount the SDcard, example

adb shell
mkdir -p /data/local/mnt
mount -t ext3 /dev/block/mmcblk0p1 /data/local/mnt

*Change root (takes a while)

export PATH=/usr/bin:/usr/sbin:/bin:$PATH

chroot /data/local/mnt/ /debootstrap/debootstrap --second-stage
I: Installing core packages...
I: Unpacking required packages...
I: Unpacking libacl1...
I: Unpacking libattr1...
I: Unpacking base-files...
I: Unpacking base-passwd...
I: Unpacking bash...
I: Unpacking libbz2-1.0...
I: Unpacking coreutils...
I: Unpacking dash...
I: Unpacking libdb4.8...
I: Unpacking debconf-i18n...
I: Unpacking debconf...
I: Unpacking debianutils...
I: Unpacking diffutils...
I: Unpacking dpkg...
I: Unpacking e2fslibs...
I: Unpacking e2fsprogs...
I: Unpacking libcomerr2...

... It takes a while

*After rooting

echo 'nameserver 8.8.8.8' > /data/local/mnt/etc/resolv.conf
mkdir -p /data/local/mnt/etc/firmware
cp /system/etc/firmware/fw_bcm4329.bin /data/local/mnt/etc/firmware/
cp /system/etc/firmware/nvram.txt /data/local/mnt/etc/firmware/
cp /sbin/adbd /data/local/mnt/sbin/adbd
sysctl -w net.ipv4.ip_forward=1
export PATH=/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root

Setup mount points:

chroot /data/local/mnt /bin/bash
mount -t devpts devpts /dev/pts
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mkdir -p /system/bin/
ln -s /bin/bash /system/bin/sh
echo 'deb http://ftp.us.debian.org/debian squeeze main' >> /etc/apt/sources.list

#U-boot configuration

bootdelay=1
baudrate=115200
netdev=eth0
ethprime=FEC0
fbparts=2m@0(boot)hwecc,4m@2m(kernel)i|hwecc,1m@6m(ramdisk)i|hwecc,170m@7m(system)i|hwecc,196m@177m(userdata)i|hwecc,94m@373m(cache)i|hwecc,45m@467m(recovery)i|hwecc
mtdparts=mtdparts=mxc_nand:2m@0(boot),4m@2m(kernel),1m@6m(ramdisk),170m@7m(system),196m@177m(userdata),94m@373m(cache),45m@467m(recovery)
loadaddr=0x90800000
rd_loadaddr=0x90C00000
loadkernel=nand read ${loadaddr} 0x200000 0x400000
loadrd=nand read ${rd_loadaddr} 0x600000 0x80000
ethact=FEC0
loadaddr=0x90800000
mtdids=nand0=mxc_nand
bootcmd=mmc read 0 0x90800000 0x800 1800 ; bootm
bootargs=console=ttymxc0,115200 root=/dev/mmcblk0p1 rootwait init=/sbin/init di1_primary calibration loglevel=7
kernel_nand_offset=0x200000
kernel_nand_size=0x2f0000
stdin=serial
stdout=serial
stderr=serial
partition=nand0,5
mtddevnum=5
mtddevname=cache

Done

Advertisements

Leave a comment

Discover vl4 camera properties

Checking my friend’s Alan blog http://acassis.wordpress.com/2009/06/19/listing-video-formats-supported-by-your-webcam/ I was headed to http://blogs.adobe.com/penguinswf/2008/07/paparazzi_v2_1.html. Unfortunately the application source code is not available at Adobe site, here goes the source code.


/*
* V4L2 camera query program
*
* This program is loosely based on the sample application found at:
* http://www.linuxtv.org/downloads/video4linux/API/V4L2_API/spec-single/v4l2.html#CAPTURE-EXAMPLE
* which bears the notice: "This program can be used and distributed without restrictions."
*
* Compile with:
* gcc -Wall v4l2-formats.c -o v4l2-formats
*
* Copyright (c) 2008 Adobe Systems Incorporated
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include
#include
#include /* low-level i/o */
#include
#include
#include
#include

#include

typedef struct {
unsigned int format;
char *format_string;
} format_record;

/* copied out of the videodev2.h header */
format_record pixel_formats[] = {
{ V4L2_PIX_FMT_RGB332, "V4L2_PIX_FMT_RGB332" },
{ V4L2_PIX_FMT_RGB555, "V4L2_PIX_FMT_RGB555" },
{ V4L2_PIX_FMT_RGB565, "V4L2_PIX_FMT_RGB565" },
{ V4L2_PIX_FMT_RGB555X, "V4L2_PIX_FMT_RGB555X" },
{ V4L2_PIX_FMT_RGB565X, "V4L2_PIX_FMT_RGB565X" },
{ V4L2_PIX_FMT_BGR24, "V4L2_PIX_FMT_BGR24" },
{ V4L2_PIX_FMT_RGB24, "V4L2_PIX_FMT_RGB24" },
{ V4L2_PIX_FMT_BGR32, "V4L2_PIX_FMT_BGR32" },
{ V4L2_PIX_FMT_RGB32, "V4L2_PIX_FMT_RGB32" },
{ V4L2_PIX_FMT_GREY, "V4L2_PIX_FMT_GREY" },
{ V4L2_PIX_FMT_YVU410, "V4L2_PIX_FMT_YVU410" },
{ V4L2_PIX_FMT_YVU420, "V4L2_PIX_FMT_YVU420" },
{ V4L2_PIX_FMT_YUYV, "V4L2_PIX_FMT_YUYV" },
{ V4L2_PIX_FMT_UYVY, "V4L2_PIX_FMT_UYVY" },
{ V4L2_PIX_FMT_YUV422P, "V4L2_PIX_FMT_YUV422P" },
{ V4L2_PIX_FMT_YUV411P, "V4L2_PIX_FMT_YUV411P" },
{ V4L2_PIX_FMT_Y41P, "V4L2_PIX_FMT_Y41P" },
{ V4L2_PIX_FMT_NV12, "V4L2_PIX_FMT_NV12" },
{ V4L2_PIX_FMT_NV21, "V4L2_PIX_FMT_NV21" },
{ V4L2_PIX_FMT_YUV410, "V4L2_PIX_FMT_YUV410" },
{ V4L2_PIX_FMT_YUV420, "V4L2_PIX_FMT_YUV420" },
{ V4L2_PIX_FMT_YYUV, "V4L2_PIX_FMT_YYUV" },
{ V4L2_PIX_FMT_HI240, "V4L2_PIX_FMT_HI240" },
{ V4L2_PIX_FMT_HM12, "V4L2_PIX_FMT_HM12" },
{ V4L2_PIX_FMT_RGB444, "V4L2_PIX_FMT_RGB444" },
{ V4L2_PIX_FMT_SBGGR8, "V4L2_PIX_FMT_SBGGR8" },
{ V4L2_PIX_FMT_MJPEG, "V4L2_PIX_FMT_MJPEG" },
{ V4L2_PIX_FMT_JPEG, "V4L2_PIX_FMT_JPEG" },
{ V4L2_PIX_FMT_DV, "V4L2_PIX_FMT_DV" },
{ V4L2_PIX_FMT_MPEG, "V4L2_PIX_FMT_MPEG" },
{ V4L2_PIX_FMT_WNVA, "V4L2_PIX_FMT_WNVA" },
{ V4L2_PIX_FMT_SN9C10X, "V4L2_PIX_FMT_SN9C10X" },
{ V4L2_PIX_FMT_PWC1, "V4L2_PIX_FMT_PWC1" },
{ V4L2_PIX_FMT_PWC2, "V4L2_PIX_FMT_PWC2" },
{ V4L2_PIX_FMT_ET61X251, "V4L2_PIX_FMT_ET61X251" }
};

int format_count = sizeof(pixel_formats) / sizeof(format_record);

int main(int argc, char *argv[])
{
struct stat st;
int fd;
char *dev_name;
int i;
int format_index;
int error;
struct v4l2_capability cap;
struct v4l2_fmtdesc format;

if (argc < 2)
{
printf("USAGE: v4l2-formats \n");
return 1;
}
dev_name = argv[1];

/* check if file exists */
if (-1 == stat (dev_name, &st)) {
fprintf (stderr, "Cannot identify '%s': %d, %s\n",
dev_name, errno, strerror (errno));
return 2;
}

/* check if file is a character device file */
if (!S_ISCHR (st.st_mode)) {
fprintf (stderr, "%s is not a character device file\n", dev_name);
return 2;
}

/* open the device */
fd = open (dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);
if (-1 == fd) {
fprintf (stderr, "Cannot open '%s': %d, %s\n",
dev_name, errno, strerror (errno));
return 2;
}

/* check capabilities */
if (-1 == ioctl (fd, VIDIOC_QUERYCAP, &cap)) {
if (EINVAL == errno) {
fprintf (stderr, "%s is not a V4L2 device\n",
dev_name);
return 2;
} else {
return 2;
}
}
printf("%s is a V4L2 device named '%s'\n", dev_name, cap.card);

/* video capture? */
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
fprintf (stderr, "%s is not a video capture device\n",
dev_name);
return 2;
}
printf("%s is capable of video capture\n", dev_name);

/* streaming? */
if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
fprintf (stderr, "%s does not support streaming i/o\n",
dev_name);
return 2;
}
printf("%s is capable of streaming capture\n", dev_name);

/* ask for a pixel format enumeration */
error = 0;
format_index = 0;
format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
while (error == 0) {
format.index = format_index++;
error = ioctl (fd, VIDIOC_ENUM_FMT, &format);
if (error == 0) {
for (i = 0; i < format_count; i++) {
if (format.pixelformat == pixel_formats[i].format) {
printf("%s supports '%s' (%s format, %s)\n",
dev_name,
format.description,
(format.flags & V4L2_FMT_FLAG_COMPRESSED) ? "compressed" : "raw",
pixel_formats[i].format_string);
break;
}
}
}
}

close (fd);

return 0;
}

Leave a comment

Get / find hard disk UUID

ls -l /dev/disk/by-uuid

or

blkid /dev/sda1

Leave a comment

locale: Cannot set LC_CTYPE to default locale

Sometimes I used to got this problem when installing packages into arm devices

apt-get install locales

dpkg-reconfigure locales

Leave a comment

Debian list installed packages


dpkg --get-selections

List packages files

dpkg -L package_name

Search package:

dpkg-query -l string

Leave a comment

Ubuntu initramfs boot problem

Sometimes Ubuntu refuses to boot correctly when you have another OS (usually windows) in the same HD.
You can see that problem when after GRUB stage you get a iniramfs (busybox) prompt.
To make things work again, log in into your windows OS and execute:

chkdsk c: /f

Try this at least 3 times, before give up

Leave a comment

VLC tips


- Streaming a mp4 video

Server side:
vlc -vvv -I rc "file:////tmp/simpson.mp4" --sout '#rtp{dst=192.168.0.76,port=1234,sdp=rtsp://192.168.0.76:8080/test.sdp}'

- Sending camera streaming

vlc -vvv v4l2:///dev/video0 --sout '#transcode{vcodec=mp2v,vb=800,scale=1,acodec=mpga ,ab=128,channels=2,samplerate=44100}:std{access=udp,mux=ts,dst=192.168.0.76:1234}'

or

cvlc -vvv v4l2:///dev/video0 width=320,height=240 --sout \
'#transcode{vcodec=mp2v,vb=800,scale=1,acodec=mpga}:\
std{access=udp,mux=ts,dst=192.168.1.44:1234}'

Client

vlc udp://@192.168.1.44:1234 :udp-caching=0

- Using RTP

Server side:

cvlc -vvv v4l2:///dev/video0 --sout \
'#transcode{vcodec=mp2v,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:rtp{mux=ts,port=1234,sdp=rtsp://0.0.0.0:8080/camera1.sdp}'

Client side:

vlc rtsp://192.168.1.43:8080/camera1.sdp

1 Comment

U-Boot Boot Debian from SDCARD

Basically

setenv loadaddr 0x90800000
setenv bootcmd 'mmc read 0 0x90800000 0x800 1800 ; bootm '
setenv bootargs 'console=ttymxc0,115200 root=/dev/mmcblk0p1 rootwait init=/sbin/init di1_primary calibration loglevel=7'
saveenv

The full script is:

Net: FEC0 [PRIME]
Hit any key to stop autoboot: 0
BBG U-Boot (SD) > printenv
bootdelay=1
baudrate=115200
loadaddr=0x90800000
netdev=eth0
ethprime=FEC0
bootcmd=mmc read 0 0x90800000 0x800 1800 ; bootm
ethact=FEC0
bootargs=console=ttymxc0,115200 root=/dev/mmcblk0p1 rootwait init=/sbin/init di1_primary calibration loglevel=7
stdin=serial
stdout=serial
stderr=serial

Leave a comment

Linux: Adding swap after partition

Create a file size (size*1024), we are using 512MB:
dd if=/dev/zero of=/swapfile1 bs=1024 count=524288

Create swap:
mkswap /swapfile

Turn on swap:
swapon /swapfile

Edit swap file:
vi /etc/fstab
/swapfile swap swap defaults 0 0

Leave a comment

Using Gstreamer to send a USB camera streaming


Usb Camera device: /dev/video0

Start video streaming

gst-launch v4l2src ! video/x-raw-yuv,width=320,height=240,framerate=\(fraction\)5/1 ! ffmpegcolorspace ! jpegenc ! multipartmux ! tcpserversink host=192.168.0.76 port=5000

Receive the stream using VLC

vlc tcp://192.168.0.76:5000

Server:
gst-launch v4l2src device=/dev/video1 ! video/x-raw-yuv,width=320,height=240,framerate=\(fraction\)30/1 ! ffmpegcolorspace ! smokeenc keyframe=8 qmax=40 ! udpsink host=192.168.0.84 port=5000

Client:
gst-launch udpsrc port=5000 ! smokedec ! autovideosink

1 Comment