Wednesday, 25 August 2010

Beginning with Qt: Introduction, Installing Qt Framework, Qt Hello world

INTRODUCTION TO Qt

Qt is a complete development environment widely used to create GUI applications.

This cross-platform tool is also able to create non gui apps.

Qt is used in the KDE desktop environment, and in other projects like virtualbox.


Qt development environment provides: (version numbers when this article was written)

  • Qt libraries (version 4.6.3)
  • Qt Creator IDE (version 2.0.0)
  • Qt development tools


Qt is available under LGPL and GPL free software licenses. Nokia also provides the Qt commercial license to develop proprietary software.


Qt DEVELOPMENT TOOLS

Qt environment provides us with some development tools. e.g:

qmake
qmake tool helps us creating and managing .pro project files, and from them it creates Makefile files needed to build our projects.
qmake Manual
qmake Tutorial

Qt assistant
Qt assistant tool shows all available Qt help. It is a help browsing system.
Qt Assistant Manual

Saturday, 26 June 2010

Creating a TRIVIAL DEBIAN REPOSITORY

This howto shows the way to create a trivial debian repository. Just a simple collection of deb package files.

There are two debian repository types: automatic and trivial.

Automatic repos are more complex. We are going to deal with trivial ones.

A trivial repository is composed of a root directory and one or more subdirectories.
No database server is needed.

This trivial repository is good enough to host a few packages, e.g creating a repo with your /var/cache/apt/archives deb packages and burn a cd or store them in a removible drive.

Trivial repos do not follow the standard debian repo directory structure, so we will have to specify the exact path in sources.list file.


CREATING MY TRIVIAL REPO STRUCTURE:

Our repo will consist of MyRepo root directory with binary subdirectory.

$mkdir -p /path/to/MyRepo
$cd /path/to/MyRepo
$mkdir binary

We place there the deb packages our repo will provide.
I.e: we copy packages from the apt cache:
$rsync -vP /var/cache/apt/archives/*.deb /path/to/MyRepo/binary
$cd .. # we move to repo root directory.


CREATE PACKAGES CONFIGURATION FILE

Sunday, 2 May 2010

How to BUILD the LINUX KERNEL for the ANDROID EMULATOR (Eclair version)

DOWNLOAD THE KERNEL SOURCE CODE


First we download the kernel source code from https://android.googlesource.com

Within that page there are kernels for other platforms too. We choose to download kernel/goldfish project from there.

$ git clone https://android.googlesource.com/kernel/goldfish

A goldfish directory appears:
$ cd goldfish
This directory does not contain any source code in it.

We check which branch we have downloaded:
$ git branch
it shows * master , not the one we are searching for:

To list all remote available branches:
$ git branch -r
or
$ git remote show origin
origin/HEAD -> origin/master
  origin/android-goldfish-2.6.29
  origin/android-goldfish-3.4
  origin/linux-goldfish-3.0-wip
  origin/master


What does goldfish mean? (from android-kernel mail list)
Goldfish is the kernel hacked branch that supports the qemu based arm emulator for android, so it is the one we need.

Download GOLDFISH kernel version
Choose the version that suits you.
$ git checkout --track -b android-goldfish-2.6.29 origin/android-goldfish-2.6.29
$ git branch
* android-goldfish-2.6.29
  master


RUNNING THE EMULATOR


Within this link we will find how to get the android emulator, and launch it.
Building Android in Debian Sid

Showing the kernel version running in the emulator
$ adb shell
# cat /proc/version
Linux version 2.6.29-00261-g0097074 (digit@digit.mtv.corp.google.com) (gcc version 4.4.0 (GCC) ) #14 Tue Feb 2 15:49:02 PST 2010


OBTAINING KERNEL CONFIGURATION


We are going to obtain the kernel configuration .config file from within our running emulator.

$ cd /path/to/goldfish # we enter in the kernel source directory.
$ adb pull /proc/config.gz . # get compressed .config file from the emulator.

$ gunzip config.gz # uncompress it.
$ cp config .config # rename it into .config

Now you can edit .config file the way it suits you the most.


BUILDING AND COMPILING THE KERNEL


CROSS_COMPILE environment variable stores the path to the arm cross compiling toolchain. I use the one which comes with android source code.

$ ARCH=arm CROSS_COMPILE=/path/to/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- make

Executing make will build the kernel.

Last lines will show:
Kernel: arch/arm/boot/Image is ready
Kernel: arch/arm/boot/zImage is ready


So we have obtained Image and zImage kernel binary files.


RUN THE EMULATOR USING THE NEW COMPILED KERNEL IMAGE


We need -kernel option:
$ emulator -kernel /path/to/goldfish/arch/arm/boot/zImage -show-kernel -verbose

We can check now the kernel version:
$ adb shell
# cat /proc/version
Linux version 2.6.29-00262-gb0d93fb (user@myPC) (gcc version 4.4.0 (GCC) ) #1 Sun May 2 14:27:31 CEST 2010


If we do not specify kernel option it usually uses the prebuilt one:
$ emulator -show-kernel -verbose
emulator: argv[01] = "-kernel"
emulator: argv[02] = "/path/to/mydroid/prebuilt/android-arm/kernel/kernel-qemu"


ACTIVATING MODULE LOADING SUPPORT IN THE KERNEL


Module loading support is previously disabled in the kernel, if we want to load modules in the kernel we have to enable it:

edit .config file and set:
CONFIG_MODULES=y

$ ARCH=arm CROSS_COMPILE=/path/to/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- make

I am asked about some options when executing make. I ask yes for module related options.

After compiling I see several modules have been built.

MODPOST 6 modules
CC      drivers/video/fb_sys_fops.mod.o
LD [M]  drivers/video/fb_sys_fops.ko
CC      drivers/video/syscopyarea.mod.o
LD [M]  drivers/video/syscopyarea.ko
CC      drivers/video/sysfillrect.mod.o
LD [M]  drivers/video/sysfillrect.ko
CC      drivers/video/sysimgblt.mod.o
LD [M]  drivers/video/sysimgblt.ko
CC      drivers/video/vfb.mod.o
LD [M]  drivers/video/vfb.ko


We can upload the modules in the emulator and install them:
$ adb push drivers/video/fb_sys_fops.ko /data
$ adb shell
# insmod /data/fb_sys_fops.ko


REFERENCE


http://www.cianer.com/androidg1/28-building-android-kernel-images


YOU MAY ALSO BE INTERESTED IN:


Building Android in Debian Sid

Sunday, 25 April 2010

Building Android in Debian Sid

We are going to build and test Android in Debian Sid on x86 32 bits architecture.

As a requirement we need JDK 5.0, update 12 or higher. Java 6 is not supported, because of incompatibilities with @Override.

Debian Sid provides all packages we need except this one. We could install from source but instead we are going to install JDK 5.0 from Debian Stable (Lenny) repositories:

ADD DEBIAN STABLE (LENNY) REPOSITORIES


#echo "deb http://ftp.debian.org/debian/ stable main contrib non-free" >> /etc/apt/sources.list

#aptitude update

sun-java5-jdk package will now become available.


INSTALL ALL PACKAGES WE NEED:


#aptitude install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev


SELECT THE RIGHT JAVA VERSION:


$file /etc/alternatives/java* # To know which alternative files we have to update.
#update-alternatives --config java
#update-alternatives --config java_vm
#update-alternatives --config javaws


We also install valgrind, a tool that will help you find memory leaks, stack corruption, array bounds overflows, etc.
#aptitude install valgrind

Sunday, 28 March 2010

Connect to Internet using a Sony Ericsson K530i phone in Debian GNU/Linux via Bluetooth

Within this post we are going to explain how to connect to internet using a Sony Ericsson K530i mobile phone via bluetooth, in a Debian Sid system.

CONFIGURING OUR K530i PHONE


First step consists on configuring bluetooth settings in our phone.

Activate bluetooth in the phone:
Settings -> Connectivity -> Bluetooth -> Turn on

Set a name for your phone:
Settings -> Connectivity -> Bluetooth -> Phone name
We select a name for our phone, e.g: my_K530i

Make your phone visible to other bluetooth devices:
Settings -> Connectivity -> Bluetooth -> Visibility -> Show phone


INSTALLING BLUETOOTH SOFTWARE

Sunday, 28 February 2010

How to Create a GENTOO Distro CHROOT ENVIRONMENT

This article describes how to build a chroot environment for Gentoo distribution.

NOTE: Debian GNU/Linux will be our host system, but these steps should also work for most other Linux based distributions (e.g: Ubuntu).


DOWNLOAD A SMALL MINIMUM GENTOO SYSTEM

First we are going to download a minimal Gentoo system, called STAGE3.

We choose our architecture, in my case x86, and i686 specifically.
http://mirrors.kernel.org/gentoo/releases/x86/autobuilds/current-stage3/
$ wget http://mirrors.kernel.org/gentoo/releases/x86/autobuilds/current-stage3/stage3-i686-*.tar.bz2

There is a list of mirrors here: http://www.gentoo.org/main/en/mirrors.xml

We could download directly from gentoo page too:
$ wget ftp://distfiles.gentoo.org/pub/gentoo/releases/x86/current-stage3/stage3-i686-*.tar.bz2



BUILDING OUR GENTOO DIRECTORY

We create a directory where we will place Gentoo files:

Thursday, 7 January 2010

How to Show Network Speed in Emacs Mode Line

Copy this file as network-speed.el. Place it where emacs can find it (see load-path variable).

Configure your .emacs file:

;; network-speed configuration:
(add-to-list 'load-path "/path/to/network-speed.el")
(require 'network-speed)
(network-speed-start) 

Reload your .emacs file: M-x load-file RET /path/to/.emacs

To stop showing network speed in mode line execute:
M-x network-speed-stop

;;; network-speed.el --- display network speed information  -*- coding: mule-utf-8 -*-

;; Copyright (C) 2009 Vicente Hernando Ara

;; Author: Vicente Hernando Ara 

;; Created: 1 Jan 2010

;; Keywords: hardware

;; This file 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 3 of the License, or
;; (at your option) any later version.

;; This file 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 GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.



;;; Commentary:

;; network-speed.el package displays network speed in emacs mode line for the interfaces the user selects.


;; There are several configurable options:

;;   network-speed-update_interval: time interval after which speed is calculated.

;;   network-speed-interface-list: list containing all network interfaces we want to show data about.

;;   network-speed-precision: every floating point number will show this number of figures after decimal point.

;;   network-speed-format-string: customizable string to be shown in the mode line.
;;   There are several scape strings which will be sustituted by data.
;;     %NI == network interface
;;     %RX == received bytes speed 
;;     %TX == transmitted bytes speed
;;     %AX == received + transmitted bytes speed
;;     %RB == total received bytes
;;     %TB == total transmitted bytes
;;     %AB == total received plus transmitted bytes
;;     %%% == % character"

;; After this file is loaded, it is necessary to call `network-speed-start' function.
;; To stop network-speed working  you need to call `network-speed-stop' function.

;;      
;; A lot of ideas were taken from `battery.el.gz' file.


;;; NETWORK-SPEED CONFIGURATION
;;
;; Add something like this in your .emacs file:
;;
;; ;; Custom variables:
;;  '(network-speed-update-interval 2)   ; Shows network speed every 2 seconds.
;;  '(network-speed-interface-list (list "ppp0" "eth0"))  ; Network interfaces to be shown in mode line.
;;  '(network-speed-precision 1)  ; Number of figures after decimal point.
;;  '(network-speed-format-string " [%NI total: %AX] ") ; String format.
;;
;; ;; network-speed configuration:
;; (add-to-list 'load-path "/path/to/network-speed.el")
;; (require 'network-speed)
;; (network-speed-start) ; 
;;
;; ;; to stop network-speed, call "network-speed-stop" interactive function.
;; ;; (network-speed-stop)


;;; Code:

;;; CUSTOM VARIABLES:

;; Network interface list to be shown in mode line.  
;;   E.g: `(list "ppp0" "eth0" "ppp1")'
(defcustom network-speed-interface-list (list "eth0") "Network interface list to be shown in mode line."
:type '(repeat string) )

(defcustom network-speed-update-interval 1 "Network speed is calculated every network-speed-update-interval seconds."
:type 'number )

(defcustom network-speed-precision 2 "Number of digits after point in numbers shown in mode line."
:type 'integer )

;; String used to build the output string shown in emacs mode line.
(defcustom network-speed-format-string " [%NI rx:%RX tx:%TX] " "Format string. 
%NI == network interface
%RX == received bytes speed 
%TX == transmitted bytes speed
%AX == received + transmitted bytes speed
%RB == total received bytes
%TB == total transmitted bytes
%AB == total received plus transmitted bytes
%%% == % character"
:type 'string
)


(defvar network-speed-update-timer nil)

;; List that contains vectors like this: [ network-interface-string received-bytes transmitted-bytes rx-speed tx-speed ]
;; This variable is only for internal use.
(defvar network-speed-data-list nil) 

;; We will parse /proc/net/dev file using the returned regexp.
(defun network-speed-get-regex (network-interface)
"Returns the right regular expression needed to find received and transmitted bytes for NETWORK-INTERFACE."
(concat "^\\( *" network-interface ":[ ]*\\)"
"\\([0-9]+\\)" ; received bytes.
"\\( +[0-9]+\\)\\{7\\} +"
"\\([0-9]+\\)"))  ; transmitted bytes.


(defun network-speed-get-rx-tx-bytes ()
"Gets received and transmitted bytes for every required network interface and calculates received and transmitted speeds.
Received and transmitted bytes are read from `/proc/net/dev' file"
(mapc
(lambda (network-speed-data)
(with-temp-buffer
(ignore-errors (insert-file-contents "/proc/net/dev")) 
(cond ((re-search-forward (network-speed-get-regex (aref network-speed-data 0)) (point-max) t)
(let ((old-received-bytes (aref network-speed-data 1)) ; get old received bytes.
(old-transmitted-bytes (aref network-speed-data 2)) ; get old transmitted bytes.
(received-bytes (string-to-number (match-string 2))) ; get updated received bytes.
(transmitted-bytes (string-to-number (match-string 4)))) ; get updated transmitted bytes.

;; Save received and transmitted bytes.
(aset network-speed-data 1 received-bytes) 
(aset network-speed-data 2 transmitted-bytes)

;; Save received and transmitted speed.
(aset network-speed-data 3 (/ (float (- received-bytes old-received-bytes)) network-speed-update-interval))
(aset network-speed-data 4 (/ (float (- transmitted-bytes old-transmitted-bytes)) network-speed-update-interval))))
(t 
(aset network-speed-data 3 -1 ) ; There is no network interface available.
(aset network-speed-data 4 -1 ))))) ; There is no network interface available.

network-speed-data-list))


(defun network-speed-add-units (speed)
"Returns speed in adequate units e.g: B/s, KB/s or MB/s."
(cond 
((< speed 0) (format "*")) ; Network interface not available right now.
((< speed 1000) (format "%d B/s" speed))  
((< speed 1000000) (format (concat "%." (number-to-string network-speed-precision) "f KB/s") (/ speed 1000)))
(t (format (concat "%." (number-to-string network-speed-precision) "f MB/s") (/ speed 1000000)))))


(defun network-speed-parse-format (vector-data)
"Substitute %XX sequences in network-speed-format-string."
(replace-regexp-in-string 
;;;   "%NI\\|%RX\\|%TX\\|%AX\\|%RB\\|%TB\\|%%%"
"%\\(NI\\|RX\\|TX\\|AX\\|RB\\|TB\\|AB\\|%%\\)"
(lambda (str)
(cond 
((equal str "%NI") (aref vector-data 0))  ; network interface.
((equal str "%RX") (network-speed-add-units (aref vector-data 3)))  ; received bytes speed.
((equal str "%TX") (network-speed-add-units (aref vector-data 4)))  ; transmitted bytes speed.
((equal str "%AX") (network-speed-add-units (+ (aref vector-data 3) (aref vector-data 4)))) ; received + transmitted speed.
((equal str "%RB") (format "%d" (aref vector-data 1))) ; received bytes.
((equal str "%TB") (format "%d" (aref vector-data 2))) ; transmitted bytes.
((equal str "%AB") (format "%d" (+ (aref vector-data 1) (aref vector-data 2)))) ; received + transmitted bytes.
((equal str "%%%") "%") ; % character.
)
)
network-speed-format-string t t)
)


(defun network-speed-update-handler()
"This function is called every `network-speed-update-interval' seconds to calculate data and show network speed in modeline."
(network-speed-get-rx-tx-bytes)

(setq network-speed-mode-line-string "")
(mapc 
(lambda (network-speed-data)
(setq network-speed-mode-line-string 
(concat network-speed-mode-line-string 
(network-speed-parse-format network-speed-data))))  ; Obtains the string we will show.
network-speed-data-list)

(force-mode-line-update)
(sit-for 0))


(defun network-speed-start ()
"Shows network speed in mode line. 
This function initializes all needed data. 
Speed is not shown inmediately but after `network-speed-update-interval' seconds when first correct value is calculated."
(interactive)

;; Adding network-speed-mode-line-string to global mode line.
(setq network-speed-mode-line-string "")
(add-to-list 'global-mode-string 'network-speed-mode-line-string t)

;; Initialize all needed vectors in `network-speed-data-list'.
(setq network-speed-data-list ())
(mapc 
(lambda (x)
(add-to-list 'network-speed-data-list (vector x 0 0 0 0) t))  ; Initialices and element of network-speed-data list.
network-speed-interface-list)

;; Calculate speeds.
(network-speed-get-rx-tx-bytes)

;; Create network-speed-update-timer. 
(and network-speed-update-timer (cancel-timer network-speed-update-timer))
;; This does not inmediately show speeds but it waits `network-speed-update-interval' seconds to start showing it.
(setq network-speed-update-timer (run-at-time network-speed-update-interval network-speed-update-interval 'network-speed-update-handler)))


(defun network-speed-stop ()
"Stops displaying network speed in mode line."
(interactive)
;; Delete the text from global mode line.
(setq global-mode-string (delq 'network-speed-mode-line-string global-mode-string))

;; Cancel timer.
(and network-speed-update-timer (cancel-timer network-speed-update-timer)))


(provide 'network-speed)

;;; filename ends here