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

Monday, 7 December 2009

MANIFESTO on the RIGHTS of INTERNET USERS

1 . Copyright should not be placed above citizens' fundamental rights to privacy, security, presumption of innocence, effective judicial protection and freedom of expression.

2 . Suspension of fundamental rights is and must remain an exclusive competence of judges. This blueprint, contrary to the provisions of Article 20.5 of the Spanish Constitution, places in the hands of the executive the power to keep Spanish citizens from accessing certain websites.

3 . The proposed laws would create legal uncertainty across Spanish IT companies, damaging one of the few areas of development and future of our economy, hindering the creation of startups, introducing barriers to competition and slowing down its international projection.

4 . The proposed laws threaten creativity and hinder cultural development. The Internet and new technologies have democratized the creation and publication of all types of content, which no longer depends on an old small industry but on multiple and different sources.

5 . Authors, like all workers, are entitled to live out of their creative ideas, business models and activities linked to their creations. Trying to hold an obsolete industry with legislative changes is neither fair nor realistic. If their business model was based on controlling copies of any creation and this is not possible any more on the Internet, they should look for a new business model.

6 . We believe that cultural industries need modern, effective, credible and affordable alternatives to survive. They also need to adapt to new social practices.

7 . The Internet should be free and not have any interference from groups that seek to perpetuate obsolete business models and stop the free flow of human knowledge.

8 . We ask the Government to guarantee net neutrality in Spain, as it will act as a framework in which a sustainable economy may develop.

9 . We propose a real reform of intellectual property rights in order to ensure a society of knowledge, promote the public domain and limit abuses from copyright organizations.

10 . In a democracy, laws and their amendments should only be adopted after a timely public debate and consultation with all involved parties. Legislative changes affecting fundamental rights can only be made in a Constitutional law.


REFERENCE

Facebook group supporting the manifesto

Manifesto Signing Petition

Dangerous Anti-Sharing Law in Spain | La Quadrature du net

Saturday, 21 November 2009

Install and Configure quickly a DHCP Server

NOTE: These commands have been tested in Debian version unstable.

DHCP stands for Dynamick Host Configuration Protocol. This protocol allows to automatically obtain an IP address and set the network configuration.

We install a DHCP server:
#aptitude install dhcp3-server

Next step is configuring the DHCP server:
We have to set correcty the /etc/dhcp3/dhcpd.conf file.

There is a configuration file example at:
/usr/share/doc/dhcp3-server/examples/dhcpd.conf

e.g: I added these lines to my /etc/dhcp3/dhcpd.conf


subnet 192.168.1.0 netmask 255.255.255.252 {
range 192.168.1.2 192.168.1.3;
option routers 192.168.1.1;
option domain-name-servers 212.73.32.3, 212.73.32.67;
}


subnet and netmask indicate the network addresses of our network:
e.g: subnet 192.168.1.0 netmask 255.255.255.252 match 192.168.1.0, 192.168.1.1, 192.168.1.2 and 192.168.1.3 IP addresses.

range means which addresses can be returned by our dhcp server, here, it can return 192.168.1.2 and 192.168.1.3

routers indicates the gateway

domain-name-servers shows all dns addresses separated by commas.


Once we have correctly set dhcpd.conf file we restart the dhcp daemon:
#/etc/init.d/dhcp3-server restart


If everything has gone fine, we will execute in a client computer:
$sudo dhclient eth0

and the dhcp server will associate an IP adress to eth0 interface.

NOTE: dhcp3-client package provides dhclient command.
#aptitude install dhcp3-client

Sunday, 1 November 2009

Shell Script that shows Network Speed

The following shell script shows current download and upload speeds for the network interface you choose.

Copy the shell script in a file named, i.e: net_speed.sh

Then after setting execution permissions:
$ chmod a+x net_speed.sh

You can run the shell script passing as the first argument the network interface you want to monitor:
$ ./net_speed.sh eth0


You will get a line like that:
ppp0 DOWN:15 KB/s UP:880 B/s

This script works parsing /proc/net/dev file and calculating the difference between current transmitted or received bytes and their values one second ago.

Sunday, 11 October 2009

How to Compile the Linux Kernel in GNU/Debian and Ubuntu

NOTE: Tested in GNU/Debian Sid. Ubuntu versions should also work.


OBTAIN KERNEL SOURCE CODE:

Obviously the first step is obtaining the source code.

It is recommended to place and build linux kernel source code in /usr/src directory, although it is not required.

We create our "Linux_Kernel_Source" directory for this task.
$mkdir Linux_Kernel_Source
$cd Linux_Kernel_Source


Linux kernel source code is freely available in Internet:
http://www.kernel.org
specifically, version 2.6:
http://www.kernel.org/pub/linux/kernel/v2.6

We download and uncompress latest source code (2.6.31 when this article was written):
#aptitude install wget bzip2 # packages needed to get the kernel source code and uncompress it.
$wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2

Uncompress the source:
$tar xvjf linux-2.6.31.tar.bz2

/usr/src/linux is a symlink to linux sources or at least linux kernel headers. It is required.
#ln -s linux-2.6.31 /usr/src/linux

$cd linux-2.6.31


KERNEL CONFIGURATION: