Archive for category Linux

Reboot Linux box after a kernel panic

To reboot 10 seconds after a kernel panic

vi /etc/sysctl.conf
kernel.panic = 10

or

echo 10 > /proc/sys/kernel/panic

Leave a Comment

Compile OpenCV

Install packages:

sudo apt-get install build-essential libgtk2.0-dev libjpeg62-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev

Download FFmpeg:

cd /usr/local/src

wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xvfj ffmpeg-snapshot.tar.bz2
cd ffmpeg
./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libxvid --enable-x11grab --enable-swscale --enable-shared
make
make install
ldconfig

cd /usr/local/src

wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2/
tar xvfj OpenCV-2.3.1a.tar.bz2
cd OpenCV-2.3.1
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON .
make
make install

Leave a Comment

Using scratchbox2 and Ubuntu 11.10


Local machine environment:
- Ubuntu 11.10 64bits

Emulated environment:
- Debian Squeeze armel

Install in local machine:

sudo apt-get install scratchbox2 fakeroot
sudo apt-get install qemu-user qemu
sudo apt-get install gcc-arm-linux-gnueabi
sudo apt-get install cpp-4.4-arm-linux-gnueabi gcc-4.4-arm-linux-gnueabi gcc-4.4-arm-linux-gnueabi-base
sudo apt-get install cpp-4.5-arm-linux-gnueabi g++-4.5-arm-linux-gnueabi gcc-4.5-arm-linux-gnueabi

Init scratchbox configuration:

fakeroot debootstrap --variant=scratchbox --foreign --arch armel squeeze /path/root_fs http://ftp.br.debian.org/debian
sb2-init -n -c /usr/bin/qemu-arm MACHINE_NAME "arm-linux-gnueabi-gcc"

Install into emulated system:

apt-get install g++ rpm zlib1g-dev m4 bison libncurses5-dev gettext build-essential intltool libxml2-dev libtool

Compile outside the box:

cd source
sb2 ./configure
sb2 make -jN
sb2 make install DESTDIR=/path/root_fs

To change the crosscompiler toolchain install the script /usr/local/bin/switch_arm-linux-gnueabi.sh:

#!/bin/bash

if [ -z $1 ]; then
echo -e "\n Error: you need to define the arm-linux-gnueabi version"
echo -e " Usage: switch_arm-linux-gnueabi.sh \n"
exit
fi

if [ ! -f /usr/bin/arm-linux-gnueabi-cpp-$1 ]; then
echo -e "\n Error: arm-linux-gnueabi version $1 do not exist\n"
exit
fi

# Unlink symbolic links
sudo unlink /usr/bin/arm-linux-gnueabi-cpp
sudo unlink /usr/bin/arm-linux-gnueabi-gcc
sudo unlink /usr/bin/arm-linux-gnueabi-gcov

#Define new links for arm-linux-gnueabi
sudo ln -s /usr/bin/arm-linux-gnueabi-cpp-$1 /usr/bin/arm-linux-gnueabi-cpp
sudo ln -s /usr/bin/arm-linux-gnueabi-gcc-$1 /usr/bin/arm-linux-gnueabi-gcc
sudo ln -s /usr/bin/arm-linux-gnueabi-gcov-$1 /usr/bin/arm-linux-gnueabi-gcov
#EOF

Leave a Comment

Fixing problem The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY

gpg –keyserver pgpkeys.mit.edu –recv-key KEY
gpg -a –export KEY | sudo apt-key add -

Example:

gpg –keyserver pgpkeys.mit.edu –recv-key B5B7720097BB3B58
gpg -a –export B5B7720097BB3B58 | sudo apt-key add -

Leave a Comment

Emulate ARM in Qemu

#Download Kernel and initrd

wget http://ftp.debian.org/debian/dists/testing/main/installer-armel/current/images/versatile/netboot/vmlinuz-2.6.32-5-versatile
wget http://ftp.debian.org/debian/dists/testing/main/installer-armel/current/images/versatile/netboot/initrd.gz

#Create disk

qemu-img create -f raw debian.img 5G

#Start qemu
qemu-system-arm -m 256 -M versatilepb -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.gz -hda debian.img -append “root=/dev/rasudo kpartx -av debian.img

#Mount filesystem after install and copy kernel and initrd
sudo mount /dev/mapper/loop1p1 ./mnt/ -o loopm”
sudo kpartx -av debian.img
sudo mount /dev/mapper/loop1p1 ./mnt/ -o loop

#Start qemu again
qemu-system-arm -m 256 -M versatilepb -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.img -hda debian.img -append “root=/dev/sda1″

More reliable information at http://richizo.wordpress.com/2010/11/15/installing-debian-arm-under-qemu

Leave a Comment

Generating “random” passwords

dd if=/dev/random bs=2 count=6 | base64 -

Leave a Comment

Fixing or replacing notebook’s keyboard / keys

Great reference and guides

http://www.laptopkey.com/

Leave a Comment

Creating kernel header/include files

Sometimes when cross-compiling a kernel, the host machine requires the header files to compile programs locally.

To create them, go to your kernel source and:

make headers_install INSTALL_HDR_PATH=/destination

For example:

mkdir /tmp/header
make headers_install ARCH=arm INSTALL_HDR_PATH=/tmp/header

More information is available at your_kernel_source/Documentation/make/headers_install.txt

2 Comments

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

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

Follow

Get every new post delivered to your Inbox.