Archive for October, 2012

Linux I2C Tutorial: Basics

Tuesday, October 30th, 2012

Introduction

I2c is widely  used on most embedded systems hardware as interconnect between various hardware components.  sensors , thermometers , eeproms are few examples of  devices connected to i2c interface. PC motherboards use I2C to talk to different sensor chips. Those sensors typically report back fan speeds, processor temperatures. This is the first of two part tutorial on i2c , and handling i2c devices on Linux systems. This part we deal with basics of I2c Bus, Devices  and  Communication protocol.

(more…)

Embedded Linux Flash File Systems

Friday, October 26th, 2012

Introduction

Most Embedded systems are equipped to use flash memory for data storage. Nor, Nand, SD cards, Compact flash are few examples of flash memory devices generally found on most consumer electronic devices.  Embedded Linux systems use flash memory for storing boot images and Root file system. Linux kernel provides a specialized subsystem called “Memory Technology Devices” (MTD) which contains collection of device drivers and file systems to initialize, partition, and use flash memory. This is first of series of articles that we intend to present to describe and demonstrate usage of various Embedded Linux  flash file systems . This part we will focus on basics of flash storage technology and a generic understanding of desired features of a file system designed for flash storage

(more…)

Using ‘const’ keyword in C

Tuesday, October 23rd, 2012

Variables are symbols used to identify memory locations of data used by program instructions. High level programming languages provide various data types for reserving memory addresses at compile time to hold different types of data. For example the look at the following code snippet.

(more…)

Embedded Device Driver models

Friday, October 19th, 2012

Device Drivers are software routines that are used to drive various hardware devices connected to a computing platform. Drivers contain routines that perform read/write operations on device control and status registers, they also include interrupt service routine that handles interrupt signals occurring on the device irq. However, driver implementation design strategies are not same, and vary as per the target platform for which driver is being implemented. This document examines driver models for Embedded Device platforms. (more…)

Using Valgrind: Video Tutorial

Saturday, October 13th, 2012

Learning Patterns Continued (Part 4 an ‘observer’)

Saturday, October 13th, 2012

As stated in the first article an observer with a penchant to observe things and learn from it, innately becomes a man with great analysis and decision making skills. They are basically quick at understanding and relating things which help them to learn things faster. But the same quality is also a problem to them.

Problems for an observer

  • They mostly rely on observations, which may not be correct at all times
  • They quickly conclude based on observations and analysis
  • They assume things, which may not be always right
  • They first conclude and then check for correctness

What’s the fix?

One immediate thing that all observers can do is to check how correct they were in the past, if you are an observer you can just look back on your previous analysis and conclusions. If you find that you are mostly right, then that’s great news, but if you feel that you err a lot then you have to seriously worry about it, even making very few but crucial mistakes is also a cause of concern. So let’s see how to fix this and help you overcome your problems.

Normally when you start learning any new subject; you look for a quick read on it, maybe browse across some pointers or preferred sites and then assume or conclude that this is it or this is similar to something that you already knew, and then quickly move on to either practically applying it or concluding about the topic. As mentioned if you often fail at your conclusions then the best and easiest fix is to talk to someone, probably an experimenter, a miner or for that matter anyone who is capable to technically comment on your conclusions, check how they feel about it, do they support your observations or not, do they add to it or do they disagree, if most of them agree with you then you could be right, but if people around feel that you are missing on some points and you may be wrong, then you have to dig deeper using other techniques (further reading, trial and error etc.) to conclude. Now the key motivator here for you to look beyond your general observation skills are the comments and suggestions that you get from your friends, colleagues or subject experts.

So just two things to remember have some experts, experimenters, miners or even perfectionists as your friends and share your conclusions and analysis with them and act if most disagree with your analysis and acquired knowledge. This is by far the simplest way to fix your negative traits

Next article we will look at a ‘miner’

Hope this helps, Cheers

Sajith

Learning patterns continued (part 3, ‘experimenter’)

Thursday, October 11th, 2012

The experimenter

If you are an experimenter you undoubtedly are always busy. You cannot stop your instincts to act immediately when you come across any information, you want to practically test it out, figure it out and explore it out. Well on the onset I can tell you that, very few will have this feature, it is an awesome trait to have. So then what’s the trouble with an experimenter?

The trouble is lack of reading or trying to first understand something in detail and then going for experimenting. Well that is a clear issue, but let’s explore in detail and look at the best proven solution that an experimenter can use to gain significant edge over others.

Key issues with an experimenter

  • Everything is trial and error for you, actually you waste a lot of time using this approach
  • You are a hasty readers, you only try to understand things using practical experiments
  • You practically explore everything, even if just a theoretic understanding of the subject is enough
  • You lack good analysis as you are always engaged in doing something practically

 

What’s the fix?

Can reading more before experimenting help, yes it will, but the trouble is you hate doing it, right. So spending time on things that you are not natural at is a waste of time. Instead what you can do is to make minor changes in the way you do things. Let’s look into it

A great thing to do when you get an assignment or when you want to try something out on your computer, is to distance yourselves from your computer, you can do this by simply moving away and taking a walk. Just as you do this try figuring things out in your mind, this will improve your analytical skills, try to create a mental map of the solution, try to put down your solution in steps, or at least try to make a to do list of how to practically find the solution. During this try to run through your steps and find out what possible errors may come or analyze whether the steps are correct or not, if they are then move on to the next best step and keep repeating this process until you come to some assertion on the steps that would lead to the solution. The steps may also include running through a section of the reading material as well too. This is exactly what you need to do and you would have solved most of your problems in the best possible way.

Next part we will look at an ‘observer’

Read our first part here

That’s it for now, Cheers,

Sajith

Linux system calls: video Tutorial

Tuesday, October 9th, 2012

Video Tutorial On Linux System calls.

Learning patterns continued (part 2)

Friday, October 5th, 2012

Thanks for reading our first article on ‘what is your learning pattern?’ Let’s now go beyond the pros and cons of the different learning patterns that we understood from the first article. In this article we will only focus on a ‘reader’ and help him gain significant edge by understanding some key aspects about his learning pattern.

Why is this important to you?

Understanding the best path to tread for quickly and smartly acquiring knowledge is really important. In this case for a ‘reader’, reading is the native tool that he uses to acquire skills, now the key is to understand what additional skills are most compatible to go along with your natural reading skill and what skills are not. This is where you have to focus all your attention on, ‘what skills go along with your natural skills and what skills do not’, remember that this is far beyond the recommendations that we gave in our first article for a ‘reader’. This would help you to understand how to acquire a certain skill in the best possible way and improve your learning effectiveness.

 The reader

First thing that a reader should understand is that though reading is a precious attribute, if you look closer there is a problem hidden within this attribute, i.e. to crave for more reading and re-reading. Till the advent of information age this problem did not surface much as the content that was available for reading were only limited to published books and papers, but as the information age, which has brought along with it scores and scores of online content which the reader can now use as an alternative resource this problem has surfaced to show some negative effects.

Due to this overwhelming bombardment of online content the reader is never far from getting his eyes off all the new content ever available on the Internet. Now this is where the problem comes, as the material is more, the reader is mostly unfinished reading them and this makes him fall into a loop of reading more and more and certainly more than that is needed, so one term that a reader should be aware of is ‘information overload’.

Problems with information overload

  • It will stuff you with repeated information
  • It will stuff you with unclear, confusing and contradictory information also
  • All available information is not credible
  • You stuff yourselves with unnecessary information
  • You get carried away with reading unrelated or faintly related information
  • You waste valuable time surfing the Internet for unnecessary information
  • You fail to understand which author to believe as you may find their views and perspectives different on the same topic
  • You never know how much is enough for you
  • You may conclude that there is so much to read, and the subject is tougher than you thought
  • Last but not the least, you may feel that information overload is good (excess equals good)

So what a ‘reader’ should be worried of?

No, it’s not information overload, but it’s their own habit, their natural instinct to read, that they should be worried of.

So what skills to adopt to overcome this problem?

You have to look for skills that can negate the ill effects of information overload that you naturally tend to acquire. So let’s understand how to do it.

Define your scope of learning

This is the foremost thing that you need to do, define the scope of what you want to read. Let’s say you want to know about Linux Kernel. Your natural instinct would be to grab a good book on Linux Kernel or surf the Internet to understand what Linux Kernel is. But just before that do a small exercise, grab a piece of paper and first write ‘why and what do you want to know about Linux Kernel’, clearly mention the purpose of it, this will give you an idea of how much important this piece of information is to you at that point in time. Answering this single question will mostly define the scope of learning.

Keep your written scope in front

Second most important thing is to always keep the scope in mind when you start reading, this will help you to stop reading exactly after you get the required information. If you cannot curb your natural instincts then please keep the piece of paper where you defined the scope in front of you, so that it prompts you to stop when you are done.  You can also put a check box against all the information that you want to collect and use them as a tracker to complete your reading step by step.

The power of practice

Understand the power of practice. Now the best way to do that is comparing the amount of satisfaction you derive after reading a piece of information to the amount of satisfaction that you get after implementing what you understood in real. For example compare the amount of satisfaction you get when reading an instruction manual for installing any software to actually installing it in real and seeing it work.

In our next installment we will closely look at an ‘experimenter’

 

That’s it for now, cheers,

Sajith

Android Architecture Essentials

Wednesday, October 3rd, 2012

Android Architecture Essentials  For Android Platform Developers

Introduction

Android is an open software platform intended for use in mobile devices. It all started with Google acquiring a startup firm called Android Inc. in the year 2005. Android Inc. was a startup working towards open software framework targeting mobile platforms. Soon after the acquisition Google started building up a healthy eco-system around android platform that included Handset manufactures, Mobile operators, semiconductor companies, Application software companies.  Though Android was originally envisioned and built for mobile platform; it is quickly making its way as software framework into variety of devices like Tablets, Netbooks, In-car infotainment, Televisions, Gaming consoles and other consumer electronic devices.

This Document introduces Android Architecture and presents various components with in android software framework.  We will look at android framework from platform developer’s point of view.

Components of Android Stack

 

Android Linux Kernel

All Linux based operating system distributions for Desktop, Server, and Enterprise platforms (Ubuntu, Red hat, Novell) use open source Linux kernel   as system software.  Linux kernel community Maintains and releases Linux kernel sources (called “vanilla kernel “).  Linux distributors are free to customize kernel sources as per the needs of target platforms.  Android is no different in this aspect, it uses forked Linux kernel with android specific modifications as its system software component.  Android Linux kernel contains unique facilities like wake locks, Low memory Killer, Binder, ashmem, alarm, logger, pmem, paranoid networking, and RAM console.

All the other components of Android stack rely on Andoid-ified Linux kernel and would not work on vanilla kernel images.  Android Linux kernel sources along with rest of android stack are hosted by Google (https://android.googlesource.com/); there has been a long drawn discussion within Linux kernel Community on merging android patches into mainline vanilla kernel.  Long debates and discussions ended with Linux Torvalds approving the merge with release Version 3.3 of the Linux kernel and is the beginning of the end of isolation between Linux kernel and android projects.

Native Libraries

Android stack hosts a number of native libraries that directly interact with Android Linux kernel to export various kernel facilities to rest of the components. All of these libraries are implemented as shared objects (.so files).  Virtual machines in Android Runtime layer (Dalvik) use Java Native Interface to access these library services.

This layer includes two categories of libraries

  1.  Libraries implemented as part of Android Open Source Project (ASOP)
  2.  Libraries integrated into ASOP from external open source projects.

ASOP libraries include libs like Bionic which includes services from libc.so, libmath.so, libdl.so, libstdc++.so, libthreaddb.so , Android core libs (libui.so, libgui.so, liblog.so, libandoird_runtime.so,  libibinder.so,  libcamera_client.so,  libsystem_server.so,  libandroid_server.so,  libsensorservice.so,  libcameraservice.so,  libutils.so, libsysutils.so,libnetutils.so  ..) dalvik virtual machine libs (libdvm.so, libnativehelper.so), media libs(libmediaplayerservice.so, libmedia.so,..), and Android  OpenGL implementations  (libEGL.so, libETC1.so, libGLESv1_CM.so, libGLESv2.so and others )

Integrated Externals libs include open SSL projects libcypto.so, libssl.so, D-Bus projects libdbus.so, libjpeg.so, sql lite database libsqlite.so and many others.

Hardware Abstraction Layer (HAL)

Under Linux Device drivers are implemented as kernel services. Driver developers can implement driver services either by linking them statically into kernel image during kernel build or load them dynamically as kernel modules when corresponding devices are found.  Linux driver model exposes driver services to applications through special files called “device nodes” located in /dev. Applications and various other user land frameworks like X window system, Alsa sound libs use device files in /dev to interface with required drivers and initiate operations on corresponding hardware.  (Watch more about Linux driver architecture here). Though Android depends on Linux kernel’s hardware abstraction services, its subsystems and libraries do not entirely depend on Linux driver model rather they use services of Hardware Abstraction layer. HAL contains various vendor specific shared libraries that abstract hardware access.

Android Init

When Linux kernel finishes its boot operations it initializes process called init with a process id 1. Init then spawns various service daemons and other startup processes as per pre-defined system configuration. Linux Distributions for desktop generally use System V init; Embedded Linux builds often use busybox provided init. Android uses its own custom init process that starts up Android specific daemons.

Daemons

Following is a partial list of android daemons started by android init

Daemon Description
Vold Volume manager daemon
adbd Adb daemon
Debuggerd Debugger daemon
netd Network manager daemon
System server Android’s system server
D-Bus daemon Dbus messaging daemon
bluetoothd Blutetooth device management deamon
Media server Media server daemon

Android Runtime (The Dalvik virtual machine)

Google has chosen java as programming language and run time environment for Android Applications. Java has always been marketed as “write once, run anywhere.” The capability has largely been made possible by the Java Platform, the foundation of which is the Java Virtual Machine (JVM). Although this goal has largely been met for the Java platform on desktop (JSE) and server (JEE) environments, the mobile Java ecosystem (JME) is a bit more fragmented with various configurations, profiles, and packages causing significant modifications to applications in order to support different devices.  Android uses standard java compiler for compiling application sources into class files but doesn’t use standard java library and standard java runtime. Android java based applications run on Dalvik virtual machine which is implemented to run on platforms with Risc processors with limited memory and battery powered.

 In standard Java environments, Java source code is compiled into Java bytecode, which is stored within .class files. The .class files are read by the JVM at runtime.On the Android platform, Java source code is still compiled into .class files. But after .class files are generated, the “dx” tool is used to convert the .class files into a .dex, or Dalvik Executable, file. Whereas a .class file contains only one class, a .dex file contains multiple classes. It is the .dex file that is executed on the Dalvik VM. The .dex file has been optimized for memory usage and the design is primarily driven by sharing of data. The Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management

The Zygote

Given that the Android application runtime must support a diverse set of devices and that applications must be sandboxed for security, performance, and reliability, to achieve this feat google has designed runtime to allow each and every Android application to run in its own process space, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently.

Since every application runs in its own instance of the VM, VM instances must be able to start quickly when a new application is launched and the memory footprint of the VM must be minimal. Android uses a concept called the Zygote to enable both sharing of code across VM instances and to provide fast startup time of new VM instances.

The Zygote is a VM process that starts at system boot time. When the Zygote process starts, it initializes a Dalvik VM, which preloads and pre-initializes core library classes.

Core java libs

Android does not support default java libraries that are distributed with JDK’s. It instead provides its own set of java library classes for Application developers. Android libraries include a subset of java libraries from open source “Apache harmony” project.  Embedded Android developers do not have much to do with the java library classes.

System Services

Native Linux applications depend on Linux kernel services for access to various resources like memory, device, Processor time, file etc.  Kernel services are important kernel subsystems that handle application resource allocations and perform resource management operations.

Android Applications use system services in a similar way. System services in android are core android subsystems that handle all application system resource requests.  One can assume android system services to be extensions of Linux kernel services; components that we visited earlier like native libraries, startup daemons, HAL have been implemented to support Android system services through JNI interface.

Binder

Android System services are fully object oriented implementations that support remote method invocation. Android stack provides a special interface called Binder through which applications can bind a specific system service and invoke its methods through remote method invocation process.

What  next?

This article introduced android architecture and various important components of it from point of view of platform developer. We will follow up this article with a series of articles on android stack and issues to be addressed by embedded android platform developers.