Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Saturday, February 16, 2008

My problems with wireless linux

It is a very simple solution for a very strange problem. Googling also did not help me much in solving this. So, it should be useful for some one.

I was using ubuntu 7.10 Linux distribution with 2.6.22-14 kernel for the last 5 months in my Dell Inspiron 1420. My laptop is having intel 3945 ABG wireless card. Wireless networking was working fine with ipw3945 driver from intel. But for someother purpose, i installed one more kernel. But after rebooting, the wireless card itself was not detected by ubuntu. Checking with dmesg (This command will show the debug messages), i could able to see that it is giving error code -2 (File missing) for the firmware file for the driver ipw3945.
ipw3945: Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux
ipw3945: Copyright(c) 2003-2007 Intel Corporation
ipw3945: Detected Intel PRO/Wireless 3945ABG Network Connection
sda:<3>ipw3945: ipw3945.ucode firmware file req failed: Reason -2
ipw3945: Could not read microcode: -2
ipw3945: probe of 0000:03:00.0 failed with error -2
When i searched google for the solutions, most of the places three solutions was given

1. change the microcode firmware version. Means Get some other version of ipw3945.ucode file and replace the current one.

2. Install iwl3945 driver and corresponding firmware from http://intellinuxwireless.org

3. Try installing compat wireless package.

But none of these, solved my problem. Because all of these solutions are for driver and the corresponding firmware. For the problem was different. The udev version was wrong for the current kernel. udev is the device manager for the Linux 2.6 kernel series. Its primary function is managing device nodes in /dev. It is the successor of devfs and hotplug which means that it handles the /dev directory and all user space actions when adding/removing devices, including firmware load. The reason for this version mismatch was simple. During kernel compilation, i had to install one package from ubuntu. But it changed the dependency packages including udev also.

After installing the latest udev package in my system, wireless started working without any problem...:)

This link also will be useful, when you are getting any errors in linux. These are the common error codes in linux. http://lxr.linux.no/linux/include/asm-generic/errno-base.h#L5

Saturday, February 2, 2008

Linux loadable kernel moduels

Linux uses a monolithic architecture with file systems, device drivers, and other modules statically linked into the kernel image to be used at boot time. The use of dynamic kernel modules allows you to write portions of the kernel as separate objects that can be loaded and unloaded on a running system.

A kernel module is simply an object file containing routines and/or data to load into a running kernel. When loaded, the module code resides in the kernel's address space and executes entirely within the context of the kernel. Technically, a module can be any set of routines, with the one restriction that two functions, init_module() and cleanup_module(), must be provided. The first is executed once the module is loaded, and the second, before the module is unloaded from the kernel.The main functions to use to load /unload and inspect kernel modules are contained in the modutils package. They are:

/sbin/insmod (insert a module into the running kernel)

/sbin/rmmod (remove a module from the running kernel)

/sbin/lsmod (inspect modules in the running codes)

Note that to manage with kernel modules you have to be root. Use sudo command in ubuntu.

Once a module is loaded, it passes to form part of the operating system, hence it can use all the functions and access all variables and structures of the kernel. Similarly the global symbols created are made available or exported to other modules. If you don't want to share some symbol (variable or function), you have to declare it as static.

A module is built from a "C" source. Here is the simplest example of a kernel module, say hello.c

#include        /* Needed by all modules */
#include /* Needed for KERN_INFO */
#include /* Needed for the macros */

static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}

static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}

module_init(hello_start);
module_exit(hello_end);

The compilation of the kernel module is different for Linux kernel 2.4 and 2.6. For checking Kernel versin
use the 'uname' command. The procedure given below is for 2.6 kernel.
Then we can create a makefile for compiling this with the following text.

obj-m = hello.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

Compile the hello.c file by using the command : make

Here , it may give error "Nothing to be done for all". The problem is you did not compile the Linux kernel till now.
So, compile the linux kernel by following the procedure given here:


http://embeddedbox.blogspot.com/2008/02/linux-26-kernel-compilation-for-ubuntu.html

After that make should generate hello.ko. This is the kernel module.
Now, we can insert the kernel module to Kernel using
insmode hello.ko


Check whether it is loaded properly with lsmod.

Note: Kernel offers a different version of printf() called printk().This works almost identically to the first except that it sends the output to a kernel ring buffer.
At any istant you can examine the contents of the buffer using the command dmesg.

You can get more information about linux kernel module programming from tldp.

Friday, February 1, 2008

Real Time Application Interface for Linux

A real time system can be defined as a "system capable of guaranteeing timing requirements of the processes under its control". Real time system can be broadly classified into soft real time systems and hard real time systems. In hard real time systems, the completion of an operation after its deadline is considered useless - ultimately, this may lead to a critical failure of the complete system. A soft real-time system on the other hand will tolerate such latency, and may respond with decreased service quality (e.g., dropping frames while displaying a video).

RTAI is not a real time operating system, such as RTLinux, VXworks or pSOS. It is based on the Linux kernel, providing the ability to make it fully pre-emptable. RTAI offers the same services of the Linux kernel core, adding the features of an industrial real time operating system. It consists basically of an interrupt dispatcher: RTAI mainly traps the peripherals interrupts and if necessary re-routes them to Linux. It is not an intrusive modification of the kernel; it uses the concept of HAL (hardware abstraction layer) to get information from Linux and to trap some fundamental functions. RTAI considers Linux as a background task running when no real time activity occurs.

How to install RTAI in Linux:

RTAI is module oriented approach. To understand about the linux loadable kernel modules read this post.

http://embeddedbox.blogspot.com/2008/02/linux-loadable-kernel-moduels.html

The installation for ubuntu hardy is explained very well here : https://woc.uc.pt/deec/getFile.do?tipo=2&id=5690 . Basically the installation for any distribution, this procedure is same.

These are some good links about RTAI:

1. https://www.rtai.org/

2. http://rtportal.upv.es/comparative/rtl_vs_rtai.html

3. http://www.captain.at/rtai.php

Monday, January 21, 2008

Building a cross compiler for AVR Microcontrollers

Why we need a cross -compiler? Cross-compilers enable us to develop on one platform( host) while actually building for another platform( target). For building this what we need is a compiler that knows how to write machine code for our target.

Giving a basic introduction about what compiler does, what are the components of a compiler it will be easy to understand the build process. The basic goal of a compiler is to produce the bytecode for target CPU or microcontroller. The main components of a compiler are

parser: converts the language source code (eg: C, C++) into the target assembly langauge. So, Parser needs to know the target assembly langauage.

Assembler: converts the assembly language code into the bytecode (object file) that the CPU executes.

Linker: combines the object files into an executable application. Different operating system and CPu combinations generally use different encapsulation mechanism.
Eg: Executable Link Format(ELF) - usually used by PowerPC processors.

Standard C Library: If we are using functions from the C library( eg, printf) , we have to use some standard C library. Newlib and Glibc are the most common one. Newlib was developed by redhat and Glibc is GNU C library.

So, we need to build three components from the GNU tools available.

1. Binutils - includes the basic binary utilities such as the assembler, the linker, the strip utility etc..Strip utility is used for removing the unwanted information from object file and executable such as symbol table, debugging information.

2. GCC - have C preprocessor and assembly translator.

3. glibc or newlibc

Now, we can start building the cross compiler for AVR. For that first we have to create an installation folder in our linux system. We can use /usr/local/AVR

Now go to this link : http://www.nongnu.org/avr-libc/user-manual/install_tools.html

Downlaod the Binutils source, GCC source and AVR Libc source(Three Zip files )from the links provided there to /usr/local/AVR folder. Untar that Zip in the same folders. Now you will get 3 folders inside the /usr/local/AVR

binutils-x.xx
gcc-x.x.x
avr-libc-x.x.x

I used the following versions:
binutils-2.15, gcc-2.7.3, avr-libc-1.0.5. Now build the three components as explained below.

Build the Binutils:

Execute the following commands in the shell prompt to install the Bintuils for AVR.
configure -
Configure the build for AVR and specify the bin directory or install directory.
make - compile the code.
make install - Install in /usr/local/AVR/bin


$ cd binutils-2.15
$ ./configure --prefix=/usr/loca/AVR --target=avr
$ make
$ make install

The /usr/local/AVR/bin directory now contains AVR versions of ld, as, ar and the other binutils executables. Add the /usr/local/AVR/bin directory to your PATH now. You can apply the modification system-wide by adding:

PATH="$PATH:/usr/local/AVR/bin" to the /etc/profile file.

Build the GCC:

$ cd gcc-2.7.3
$ ./configure --prefix=/usr/loca/AVR --target=avr --enable-languages="c,c++" --disbale-nls
$ make
$ make install

Build the AVR Libc:

$ cd avr-libc-1.0.5
$ export PREFIX=/usr/local/AVR
$ sh ./doconf
$ ./domake
$ cd build
$ make install
So, we have installed the avr-gcc cross compiler for the AVR series microcontrollers succesfully..!!

Now after verifying that the PATH variable"/usr/local/AVR/bin" is set system wide( means from anyfolder we can use the avr-gcc and binutils tools), we can start compiling C and C++ files for the AVR.