Tuesday, January 8, 2013

BSP

www.linux-arm.org/pub/LinuxKernel/.../aleph-porting.pdf

Files:
up the interrupt controller. Interrupt mask and unmask functions go here too.



arch/arm/kernel/entry-armv.S
Interrupt controller base: /arch/arm/mach-omap2/omap24xx.h
Assigning irq numbers: include/asm/arch/irqs.h

__virt_to_phys() macro in include/asm-arm/arch-XXX/memory.h
(along with corresponding reverse mappings). Normally, this macro
is simply:
phys = virt - PAGE_OFFSET + PHYS_OFFSET
Initialize all memory segments as well: text addr, phys addr, virtual addr, task size, page offset, phy offset, vmalloc start/end, vmalloc offset, data addr. 




arch/arm/mach-XXX/irq.c : You should provide the XXX_init_irq function here. This sets

arch/arm/mach-XXX/mm.c

include/asm/arch/dma.h : Defines for DMA channels, and DMA-able areas of memory.
For machines without DMA, you can just declare 0 DMA
channels as follows:
#define MAX_DMA_ADDRESS 0xffffffff
#define MAX_DMA_CHANNELS 0


define the memory addresses, IOaddresses, and so on: include/asm/arch/hardware.h
include/asm/arch/io.h
include/asm/arch/timex.h



Board support package initializes board specific details and keeps the OS not worried about it.
Although board initialization starts before the booting process itself.

When ARM devices are powered on the 1st software (firmware usually) is executed from ROM and written in assembly code. In many cases this firmware might not run on ARM core and may run in DSP processor, if available.
Above piece of code initializes L1 cache of the primary core (in multicore system) to load 1st bootloader, written in C.
Why L1 is required? Well this is not necessary but many vendors does it. This is to support 1st level bootloader which is written in C. As usual standard, C code program keeps segments: text, bss, data, rodata. And when this bootloader comes in execution, it requires stack segment also (as like any simplest program in C). ROM can't hold stack as it is read only (I guess L1 cache or DRAM is required to hold bss and data segment also). Main job of this 1st level of bootloader is to chainload 2nd level bootloader.




Offset  Handler
 ===============
 00      Reset
 04      Undefined Instruction
 08      Supervisor Call (SVC)
 0C      Prefetch Abort
 10      Data Abort
 14      (Reserved)
 18      Interrupt (IRQ)
 1C      Fast Interrupt (FIQ)



When the exception happens, the processor just starts execution from a specific offset, so usually this table contains single-instruction branches to the complete handlers further in the code. A typical classic vector table looks like following:

00000000   LDR   PC, =Reset
00000004   LDR   PC, =Undef
00000008   LDR   PC, =SVC
0000000C   LDR   PC, =PrefAbort
00000010   LDR   PC, =DataAbort
00000014   NOP
00000018   LDR   PC, =IRQ
0000001C   LDR   PC, =FIQ
At runtime, the vector table can be relocated to 0xFFFF0000, which is often implemented as a tightly-coupled memory range for the fastest exception handling. However, the power-on reset usually begins at 0x00000000 (but in some chips can be set to 0xFFFF0000 by a processor pin).



http://kiranjammula.wordpress.com/



----------------------------

-Initialize CPU speed
-Initialize memory, which includes enabling memory banks, initializing memory configuration registers, and so on
-nitialize serial port (if present on the target)
-Enable instruction/data caches
-Set up stack pointer
-Set up parameter area and construct parameter structures and tags (this is an important step, as boot parameters are used by the kernel in identifying root device, page size, memory size and more)
-Perform POST (Power On Self Test) to identify the devices present and to report any problems
-Provide support for suspend/resume for power management
-Load the kernel to memory if needed
-For arm Linux kernel, before jumping to the kernel, MMU has to be turned off, D-cache should be turned off, register r0 should be set 0, r1 should contain the correct machine number and r2 should point ATAGS.
-Jump to start of kernel.

Wednesday, January 2, 2013

Must know

ELF:

Segments in ELF and how it is loaded:
http://www.tenouk.com/Bufferoverflowc/Bufferoverflow1c.html

http://www.kernel.org/doc/man-pages/online/pages/man5/elf.5.html


Program headers in an ELF binary describe how the binary should be run. The interesting parts are the LOAD headers which load part of the binary into different places in memory. There could be almost arbitrary number of LOAD headers in a binary, but usually the linker puts everything read-only and executable into one and everything read/write into another. There are operating systems which will have read-only data LOAD header, read-write data and read-only executable code for slightly increased security.
Segments here just mean parts of the binary loaded in different places in memory. So basically the different LOAD headers.
Sections is how the data was organized during linking. For various reasons you want to have better granularity organizing things than just data/code. Some data is read-only, it's put in ".rodata" in your example. The code is in ".text", initialized data is in ".data" while data in variables that are zeroed on program start are in ".bss".
The "section to segment mapping" tells you which sections are in which segments (different LOAD headers). So ".text" and ".rodata" are in the first LOAD header (the third program header) and ".data" is in the second LOAD header (fourth program header).
The stack is something that the operating system gives you on execution and it's not described by an ELF binary.
U-Boot:

http://www.scribd.com/doc/56518684/U-Boot-Implementation-Internals
http://www.linux-arm.org/LinuxBootLoader/SMPBoot
http://cache.freescale.com/files/dsp/doc/app_note/AN4173.pdf

DMA:

http://coweb.cc.gatech.edu/sysHackfest/uploads/58/DMA_howto.1.txt
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0424d/index.html

fstab:




fstab - static information about the filesystems


SYNOPSIS
#include <fstab.h>

DESCRIPTION
The  file  fstab  contains  descriptive  information about the various file systems.  fstab is only read by programs, and not written; it is the duty of the system administrator to 
properly create and maintain this file. 


udev:




udev - dynamic device management


DESCRIPTION
udev provides a dynamic device directory containing only the files for actually present devices. It creates or removes device node files in the /dev directory, or it renames 
network interfaces.


Usually udev runs as udevd(8) and receives uevents directly from the kernel if a device is added or removed from the system.

If udev receives a device event, it matches its configured rules against the available device attributes provided in sysfs to identify the device. Rules that match may provide 
additional device information or specify a device node name and multiple symlink names and instruct udev to run additional programs as part of the device event handling.


Wednesday, December 19, 2012

Video for Linux

1st place to understand basic structure of V4L2 interface is here. vivi driver is a sample source which could be used for either testing V4L2 based application or to start developing new driver. More information about vivi could be found here. Driver writer's guide is available here. Once all above links are covered, linux media interface could be looked here to go inside.

Although link is not for current scope, but it is good to have this link as a quick reference for lot of other interfaces.


Other references:
http://www.linuxtv.org/downloads/legacy/video4linux/v4l2dwgNew.html
Good sample to learn: v4l2 loopback-master

Check for
linux/videodev2.h
media/v4l2-ioctl.h
media/v4l2-common.h
http://www.kernel.org/doc/Documentation/video4linux/


Saturday, December 8, 2012

Linux Windowing System

If your system doesn't have windowing system, probably you will be limited to console. You might be working from remote or you are an admin. But if end user is a consumer who is interested to see at-least a minimal GUI, you have to provide windowing system. X windowing system is one of the common windowing system used these days. X works on client server structure. Where server is installed in the system you are interested to interact and client could be anywhere, either local to the system or connected through network. A project developed with really a well thought.

If you have installed server in your system, it is up to the client how to mange the layout. Server just provides the service for windowing and how to put it in screen, this is clients responsibility and interest. Each window on screen is a client of X.


Refer:
http://linuxdevcenter.com/pub/a/linux/2005/08/25/whatisXwindow.html?page=1
http://xwinman.org/
http://en.wikipedia.org/wiki/X_Window_System

Wednesday, November 21, 2012

Modem and linux

Most of the modems are available with USB interface. USB interface is a good option as it supports high speed communication (35MBPS by USB 2.0).  There are certain good utilities available to troubleshoot devices connected to USB interface.
"lsusb" command lists USB devices with device id, vendor id and its description.
To see more details of devices such as driver in use for the device, device class, product name and manufacturer name, etc "usb-devices" is another good utility. Same details could be seen at /sys/kernel/debug/usb/devices.

Coming back to our purpose. Here we will be communicating to modem over serial interface. And so we need a USB to serial converter driver. Once serial data is available we will be seeing the network packet and so will be usb_wwan driver. From above command we can find 3G modem device's vendor id and product id. Lets go to make things working.


$modprobe usbserial vendor=0x<vendor id> product=<product id>
$modprobe usb_wwan option


Now driver lets go to network interface part.
Create node using ip link and bring it up with dhcp client to get ip address.


http://antipastohw.blogspot.in/2012/05/how-to-install-3g4g-cellular-modem-on.html
http://freedune.wordpress.com/2011/06/23/success-with-usb-3g-modems-on-android/

USB modem:

https://wiki.archlinux.org/index.php/USB_3G_Modem
http://www.draisberghof.de/usb_modeswitch/
http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=960

DHCP:

http://www.cyberciti.biz/faq/howto-linux-renew-dhcp-client-ip-address/

Friday, November 16, 2012

Hello JNI

http://marakana.com/forums/android/examples/49.html
I was working on created java native interface for one of my Android app. Its old during Android 2.1 days. Today after couple of years, I tried to create interface again, in my Ubuntu host system, and got some issues. I though better to keep one hello world post for JNI.

Create a project with name of your choice and copy this minimal code in class, lets say in callnative.java


package com.example.ih;

public class callnative {

static {
System.loadLibrary("my_lib");  //to load library
}

public native int add(int x, int y); //calling native function

public native String hello();

}

Go to /workspace/ih/bin path and give below command,

$javah -jni -classpath /home/abhishekkd/workspace/ih/bin/classes com.example.ih.callnative

$cat com_example_ih_callnative.h

You will see a heard file generated something like,


/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_example_ih_callnative */

#ifndef _Included_com_example_ih_callnative
#define _Included_com_example_ih_callnative
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_example_ih_callnative
 * Method:    add
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_com_example_ih_callnative_add
  (JNIEnv *, jobject, jint, jint);

/*
 * Class:     com_example_ih_callnative
 * Method:    hello
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_com_example_ih_callnative_hello
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

Now, implement declared functions,

$gedit hello_lib.c

#include "com_example_ih_callnative.h"

JNIEXPORT jstring JNICALL Java_com_marakana_NativeLib_hello
  (JNIEnv * env, jobject obj) {
return (*env)->NewStringUTF(env, "Hello World!");
}

JNIEXPORT jint JNICALL Java_com_marakana_NativeLib_add
  (JNIEnv * env, jobject obj, jint value1, jint value2) {
return (value1 + value2);
}



Audio System

It is not simple to discuss about audio codec at one page as there are large verity for different purposes and SOC supports. This post is just to trigger one in right direction. Low level understanding is good for architecture such as ARM. For x86, you should directly go to ALSA.

When you are choosing an Audio codec you will be looking for:

Capability -
mono, stereo,  5.1
Number of output lines, number of input lines

Quality -
8kHz to 96kHz ADC audio
8kHz to 96kHz DAC audio
Price -
Depends on above two.

All of above choice depends on the purpose of use such as mobile phone or DOLBI sound system or is it a box for DJ.
You do consider power consumption and signal to noise ratio when you have options.

If we see for media player such as your portable music player or phone, you do consider Capability, you might consider what all are the means of inputs
  • Application/multimedia processor
  • FM
  • Compressed audio codec
  • Bluetooth Modem
Once you have listed your requirement, you are are ready for suitable vendor in market to chose one codec for your self. I will be considering that you are connecting codec direct to application processor and getting raw audio to play.




Have you connected the codec through I2C or SPI (to application processor). You could use UART or I2S, PCI, USB also based on interfaces available through the codec chip or sound card.
You have to write BSP to communicate with the card. Here you will be following datasheet of the product, how to use control lines and passing/getting data to and from the codec to application processor. 
Well, once you have written these codes, now you hare ready to write driver for your kernel. Sound sub-system is already available for you and so you can use API's to develop you application. Alsa good  for Linux and already available in kernel. Just make sure you do proper implementation of your BSP and coupled it with ALSA driver. Now rest is only to play sample app and test it.

Do we need to discuss more on it? There are some good explanation at an introduction to linux audio. Also palying with ALSA utilities, such as alsa mixer, is a good way to learn.

It is good to check official site of driver to get better understanding. 


Links: