Wednesday, 2 September 2015

Real-Time Sensing on Android


    This layer enables raw H/W access. Android uses linux's input sub system (evdev) for sensor devices.
  • The input sub system is an abstraction layer b/w i/p devices and i/p handlers.
  • The i/p devices capture physical inputs and produces i/p events.
  • The i/p events then go through the i/p core and are dispatched to any subscribed handlers, which in turn make them available through the standard UNIX file interface /dev/input/eventX.
  • Thus, applications can access the raw sensors data as an i/p events by calling POSIX system calls.

    It is a user space layer that interface with the kernel.

  • It polls the i/p events from kernel (/dev/input/eventX) for reading sensor data and provides a unifying H/W interfaces for other user space process.
  • This layer also hides vendor specific details.
  • HAL is loaded into User-Space process as a shared library.

Sensor Service:

    It Uses HAL to access raw sensor data. This layer is in fact part of a system process that starts from system boot time.

Do 2 things-
  • It re formats raw H/W sensor data using application friendly data    structure.
  • It fuses reading from multiple H/W sensors to generate S/W sensors data.

Sensor manager:

    Is an Android library linked to each application at run time.
  • It Provides registration and de registration calls for app implemented event handlers.
  • Once app registers an event handler, sensor Manger's sensor thread reads sensor data from a sensor service.

Android and Kernel source download, building and flashing

Android Source download:

# Create bin directory in home if not present
mkdir ~/bin
# Set path

#Download the Repo tool and ensure that it is executable:
curl > ~/bin/repo
chmod a+x ~/bin/repo Or chmod 0777 ~/bin/repo

# Make working directory. Create an empty directory to hold your working files
cd ~/

# Set Http Post Buffer size
#You may find the default post buffer of your git client is too small to push large details to Gitblit.
Sometimes this cam be observed on your client as hanging during push.
Other times it can be observed by git erroring out with a message like : error: RPC failed; result=52, HTTP code = 0
Use :git config --global http.ppostBuffer 524288000
Places to add this (In any file you can add)
1. ~/.git/config
2. /etc/gitconfig
3. ~/.gitconfig
4. ~/.config/git/config

# Run repo init to bring down the latest version of Repo with all its most recent bug fixes.
You must specify a URL for the manifest, which specifies where the various repositories included in the Android source will be placed within your working directory.
repo init -u

# To check out a branch other than "master", specify it with -b:
repo init -u -b android-5.0.0_r6

# If want to configure by your name/ID use
repo init -u -b android-5.0.0_r6 --config-name yatendra

# To pull down the Android source tree to your working directory from the repositories as specified in the default manifest, run
repo sync

# Using a Local mirror
mkdir -p /usr/local/aosp/mirror
cd /usr/local/aosp/mirror
repo init -u --mirror
repo sync

# Once the mirror is synced, new clients can be created from it. Note that it's important to specify an absolute path:
mkdir -p /usr/local/aosp/master
cd /usr/local/aosp/master
repo init -u /usr/local/aosp/mirror/platform/manifest.git
repo sync

# Finally, to sync a client against the server, the mirror needs to be synced against the server, then the client against the mirror:

cd /usr/local/aosp/mirror
repo sync
cd /usr/local/aosp/master
repo sync

# Note: Copy source as backup in Source directory

# download factory binaries for Device (Without this android will not bring up)
# It will list out all the device with android versions like -
Binaries for Nexus 5 (GSM/LTE) ("hammerhead")

    Android 4.4 (KRT16M)
    Android 4.4.2 (KOT49H)
    Android 4.4.3 (KTU84M)
    Android 4.4.4 (KTU84P)
    Android 4.4.4 Release 2 (KTU84Q)
    Android 5.0 (LRX21O)
    Android 5.1.1 (LMY48B)
# Select android version
# Download all the links related to Devices binaries
# Extract all the .tgz files and execute them in terminal
Press Enter and space till prompt has not come
>> Type "I ACCEPT" if you agree to the terms of the license:
Type "I ACCEPT" then Enter
# It will create the device folder which is needed to bring up android for particular device

Kernel Source download:

#Go to site Search for particular version "android-msm-hammerhead-3.4-lollipop-mr1". Click and Download
#set enviroment variables
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=arm-2010q1/bin/arm-none-linux-gnueabi-

#Set Path for Kernel and Android
#Go to android source folder and export path
#Go to android Kernel folder and export path

Building Sources:
# JDK version should be Proper.

# Check the links manaully
ls -l /etc/alternatives/ja*
# If not set properly you can set JAVA Path as
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_72/
Use update-alternatives for all ja* e.g update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_72/bin/java

After Setting java version just do lunch for android source

# Your source is downloaded and ready for build
Build Kernel:
# go to source directory
make hammerhead_defconfig
make zImage-dtb

Copy zImage-dtb to particular device folder (Here lge/hammerhead-kernel for Nexus5)
cp ${KERNEL_PATH}/arch/arm/boot/zImage-dtb  ${ANDROID_PATH}/device/lge/hammerhead-kernel/

Build Android:
# go to source directory
source build/
lunch aosp_hammerhead-userdebug
> for Nexus 5
make -j4

Flashing device:

adb reboot bootloader
sudo fastboot flash boot boot.img
sudo fastboot flash system system.img
sudo fastboot flash userdata userdata.img
sudo fastboot reboot

Sunday, 5 April 2015

How to make pen drive bootable using windows cmd ?

For windows7 users: 
* Go to “Start” button and click. Write “cmd” then cmd icon will appear on the top of the panel.

* “Right click” on the cmd icon and click “Run as administrator”.

>> It will open the command prompt.

For windows 8 users: 
* Press “Windows key” and press “c”.

* You will see the command prompt icon. “Right click” on the command prompt icon and click “Run as administrator” from the bottom bar.

Now following steps are same for the windows7 and 8 OS. 
* Type “diskpart” inside the command prompt and hit “ENTER”.

>> It will good before going to next step that you should disconnect all other external hard disk, flash/pen drive etc. because accidently these drive can be formatted. So taking precaution is good. Only one pen drive should be connected. Save all the data from the pen drive because it will be formatted in one of the following step.

* After last step type “list disk” inside the command prompt and hit “ENTER”.

>> This will show all disk connected to the system like DISK 0, Disk 1, and so on with “Status”, “Size” , “Free” etc.. We can recognize the pen drive with size. Disk 0 will be the system disk in which the windows OS is installed. Lets Disk 1 is the pen drive (3855MB=4GB). This pen drive is going to be a bootable pen drive.

* Type “select disk 1” inside the command prompt and hit “ENTER”. It will select the disk 1 (pen drive) for all coming steps.

1. - Type “clean” and hit “ENTER”. It will erase all the data from the pen drive.

* Type “create partition primary” and hit “ENTER”. It will create a primary partition in pen drive.

* Type “select partition 1” and hit “ENTER”. It will select the partition created in the last step.

* Type “format fs=ntfs quick” and hit “ENTER”. It will format the pen drive quickly with NTFS file type.

* Type “active” and hit “ENTER”. It will make partition as active for booting after restarting the computer. If this step is missed then computer will not boot from the pen drive.

* Type “exit ” and hit “ENTER” to close the diskpart and close the command prompt window.

* Now the pen drive has become bootable. Now all the files from root of Windows operating system setup DVD or ISO has to copy inside the pen drive root.

So open the Windows setup file from DVD or ISO and copy all file by selecting with “Ctrl+A” and paste it inside the pen drive’s root folder.

After complete copy, the pen drive will be a bootable for Windows 7 and Windows 8 OS completely. You just need to “Restart” your computer. “Restart” your computer. When BIOS screen appears then press “F12” or "F10" Key (Depends on BIOS Settings). It will show the options to boot from CD/DVD drive, hard disk and pen drive. Just scroll down to pen drive and hit “Enter”. Your system will boot from pen drive. Now you can install windows OS.

For more Info refer -

Wednesday, 21 January 2015

What Does Flash BIOS Mean?

Flash BIOS is a term used to describe the process of updating a computer's motherboard. It is usually done to increase compatibility or increase the performance capabilities of a computer. While it become an easier process to perform over the years, some computer experts do not recommend novices attempt it without assistance, as it can permanently damage a computer if done using improper methods.

BIOS Definition -
BIOS stands for Basic Input Output System. It is the firmware program for a computer, and comes pre-installed on all motherboards that are used for home PCs. It is the first things that loads up when a computer is turned on, checking to make sure all the components of a computer are properly running before turning over control of the computer to the operating system. The BIOS of a system can be accessed during the boot process, and is usually done to change the boot order of drives, enable/disable certain hardware components, or tweak things like computer fan speed.

Effects -
All computers come installed with BIOS on their motherboards, but many times during the life cycle of a motherboard the BIOS may be updated. These updates may increase the performance capabilities of a computer, add compatibility for new devices or fix bugs that might have gone unnoticed during the initial release. BIOS updates are motherboard-specific and not universal. One BIOS update for another motherboard will not work for another. Attempting to flash the BIOS of a motherboard with the wrong BIOS can cause serious errors.

Process -
The process of flashing BIOS starts by first getting the updated BIOS. These files can usually be found at the motherboard manufacturer's website. In addition to downloading the new BIOS, a person must also download a special program to flash the BIOS. Many modern motherboards can be flashed while still in Windows. Older motherboards require a user to download special tools that can only be used when booting a computer into DOS. Then special text commands must be entered for the BIOS to be uploaded to the motherboard.

Warning -
If a computer's BIOS is flashed incorrectly, or if something like a power disruptions interrupts the flashing process, it can severely damage a computer-usually making it impossible to properly boot. If a BIOS flash goes wrong a user will usually have to manually open up their computer and change their motherboard's "jumpers." These small switches can be used to undo a BIOS flash and set a computer's BIOS settings back to their factory defaults.

Expert Insight -
While flashing a computer's BIOS has become easier in recent years thanks to Windows tools that can complete the process, it is still something that many computer experts don't advise others do unless absolutely necessary. If a computer is working properly and does not need any BIOS upgrades to be compatible with new hardware or software, then it probably doesn't need to be upgraded at all.

What is VFS (vitual file system) ?

Defined link between operating system kernel and different file systems

supplies application with the system call for the file management
( like open, read ) maintain internal data str and passes appropriate
task to appropraite file system

Provide standard actions ( lseek )

No file system will actually provide lseek

Difference b/w Emulator and Simulator?

Simulator -

write a program that draw the calculator's display and keys and when
user clicks on the keys your progra, does what the old calculator did.

duplicate the behaiour of device

Emulator -

you get a dump of the calculator firmware , then write a program
that loads the firmware and interpret in the sameway the u.p in the
calculator did.

duplicate the inner working of the device.

in emulator s/w platform is created on which the emulated code can be run
in ahost computer having different h/w and a different instr set.

What is patch file and how to create patch file?

To patch a file means to modify it, with the connotation
that the modification is generally small.

The usage comes from the general English usage where a patch
is a small modification (to a piece of cloth, for example).

When it comes to files, a patch is not always a repair.

A patch is a series of instructions that describe how to modify
a file or a set of files.

In the unix world, a patch is usually the output of the diff command,
describing changes in a text file. A patch in this sense describes
the modifications in terms of adding, removing or modifying lines
in the files. The patch utility applies these instructions to modify
a file or set of files.

It tries to be smart about applying multiple patches to the same file,
as the first patch could cause changes that prevent the second one
from being applies because the file is no longer in the expected state.
Because diff and patch strongly base their operation on lines,
they are not well-suited to binary files.

patch file creation and how to patch ?

before doing this, please backup your source code, patch wrongly
will screwup your source code.

how to create patch file?

Patch file is a readable file that created by diff with -c
(context output format).

It doesn’t matter and if you wanna know more, man diff.

To patch the entire folder of source codes(as usually people do)
I do as bellow:

Assume Original source code at folder Tb01, and latest source
code at folder Tb02. And there have multiple sub directories at
Tb01 and Tb02 too.

====> diff -crB Tb01 Tb02 > Tb02.patch

-c context, -r recursive (multiple levels dir), -B is to ignore
Blank Lines.

put -B because blank lines is really useless for patching,
sometimes I need to manually read the patch file to track the changes, \
without -B is really headache.

How to patch?

First of all, please do a dry-run before really patch it.

Bare in mind, patch will be working very specifically.

Let say the version 3 Tb03.patch is use to patch from Tb02,
if you apply patch on Tb01, sometimes it will corrupt your source code.
So, to make sure it works, do a dry run.

Dry-run means a fake-test, do it at the directory of the source code
targeted to patch.

Doing dry-run like this:

====> patch --dry-run -p1 -i Tb02.patch

The success output looks like this:

patching file TbApi.cpp
patching file TbApi.h
patching file TbCard.cpp

The failure ouptut looks like this:

patching file TbCard.cpp
Hunk #2 FAILED at 585.
1 out of 2 hunks FAILED -- saving rejects to file TbCard.cpp.rej
patching file TbCard.h
Hunk #1 FAILED at 57.
Hunk #2 FAILED at 77.
Hunk #3 succeeded at 83 with fuzz 1 (offset -21 lines).

At last, if the dry-run is giving good result,
do this and enjoy the compilation.

====> patch -p1 -i Tb02.patch

Second, if there were files in Tb02 that did not exist in Tb01 and
you want them included in the patch, give diff the -N option:

diff -crBN Tb01 Tb02 > Tb02.patch

Lastly, I’d note that diff and patch really only work with text files.
It can’t deal with jpegs, pdfs, or other binary objects.

This can be a bit of a pain for web and GUI developers.