Boot time optimization on SABRESD or related I.MX6 boards

Hello Readers,

Hope you all have some basic info about Linux kernel configuration, bootloader, filesystem etc… before reading this and it has been useful to you.

 I am using POKY toolchain since YOCTO build environment is prefered by FREESCALE.
TAGS: i.MX6, YOCTO, Linux, Quick Boot, Kernel Configuration, filesystem, bootloader

Step1. Set up environmental variables
$ cd /opt/poky/1.4+snapshot/
$ source environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
$ export ARCH=arm
$ export CROSS_COMPILE=arm-poky-linux-gnueabi-
// $ unset LDFLAGS (use if required).
Step2. Copy Sabresd kernel source tar ball. —Untar
0. Sudo tar –xvf linux-imx.tar –C /home/manjunath/
–Go to directory
1. Cd linux-imx-3.0.35_4.1.10
—set to sabresd default configuration
2. Make mx6qsabresd_defconfig
3. $ make menuconfig
4. $ make uImage
—-insert SD card and copy u-boot
5. $ sudo dd if=u-boot.imx of=/dev/sdc bs=1k seek=1
—-copy uImage
6. $ sudo dd if=arch/arm/boot/uImage of =/dev/sdc bs=1M seek=1
—-Untar filesystem into SD Card
7. $ sudo tar –xvf rootfs.tar –C /media/sdc
Changes made in u-boot, kernel and filesystem
$ setenv bootdelay = -1 ———–i.e. to disable bootdelay. // Don’t do this at the first step.
Kernel Menuconfig —————— (Listed below are all DISABLED features)
  1. General Features
–Standard Kernel features
—-Disable Bug Report
–Kernel .config support
–support for paging of anonymous memory (swap)
–SLUB debug Support
  1. Device Drivers
–MISC Devices
–Hardware Monitoring
–PCIe support —————————-PCIe is initiated by u-boot (may run it as a module afterwards)
—MIPI camera thing –please remove it and load as a module.
  1. Networking Support
–Remove networking as much as possible.
–Wireless LAN —————————-supports all INTEL related wireless drivers.
  1. Kernel Hacking
–Debug Filesystem
–Debug Kernel
  1. Filesystem
–Ext2 and Ext3 related
–MISC Filesystems
—keep only ext4 related (it is the fastest among all filesystems)
  1. Static network
$ /etc/network/interfaces —————disable inet DHCP and enable static ip.
If needs restart (without actual reboot)
$ /etc/init.d/networking start ——– “after changing interface” file.
  1. Disabling AVAHI daemon (if enabled??)
sudo update-rc.d -f avahi-daemon remove
iii.  Go to /etc/init.d and here we can see so many daemons which run at file system boot time, one needs to carefully remove the one’s that are not needed or wasting time.
Statistics and Effects of changes made,
Uboot-1s from minimum 2s
UImage-4s from minimum 6s
Filesystem-3s from minimum 8s     // MAY DEPEND ON FILESYSTEM USING.
UIMAGE SIZE—3.23MB from 4.05MB (if “modules” are made out of recommended “drivers” the size still can be reduced).
For example: MIPI Camera can made a module and run as
$ root@joshi-desktop: insmod mipi.ko or in the init script after boot is over.
Boot time initially recorded was 16s and has been successfully reduced to 8s to 9smaximum with SABRESD Filesystem.
  1. Using uncompressed kernel
Doubles the size and reduces very little time in booting. It does not affect much.
  1. Initialization of level 2 cache
  1. Usage of initramfs and initrd (THIS IS A MUST).

1. Bootloader
2. Kernel
3. Filesystem

Here are some more tricks to make it a QUICK BOOT
1. Remove PCIe
2. Remove Everything related to Network. Just open .config file like

$ linux-source-directory : nano .config

// Half the storage size of Kernel and minimum of 4s will be reduced just by removing Network.

Go to Network section and delete everything related to that.

3. Let as many peripherals as possible be Modules,

For ex:


ii. USB

iii. CAN

iv. PCIe (remember not PCI) etc. These take no part in just booting process.

(Select as <M> instead of <*> in menuconfig.)

I could reduce more than half the size of kernel just by this process.

4. Compile kernel with Printk timestamp.

Go to
–> kernel Hacking  (in menuconfig)
—-> Compile Kernel with time stamp

This in no way helps reduce boot time but it will definitely give you an idea of which process uses most time and how you may reduce the same.

5. Build Filesystem with Bootchart daemon.

This is a little tricky but nonetheless you may try by modifying .bb file in YOCTO environment (Package bootchart2 is available in YOCTO or in BUSYBOX) or just in local.conf file.


You may download the package directly and start using it by CROSS – Compilation.

6. Use Bootgraph

Several articles on how to use bootgraph are there and you may GOOGLE it.

7.  Use Grabserial

Several articles on how to use Grabserial are there and you may GOOGLE it.

8. The most important is GO TO /etc/init.d and swim around all the init files. Try removing each and see what happens?

I am sure you will lot of junk here as well.




Raspberry Pi Face Detection Controlled GPIO (Part 5)

Now we have come to the end of our first project and you may copy and paste the code. At the end you must get an output where anyone’s face detected should toggle the LED.
/*Face detect and control GPIO code starts here*/
#include “opencv2/objdetect/objdetect.hpp”
 #include “opencv2/highgui/highgui.hpp”
 #include “opencv2/imgproc/imgproc.hpp”
 #include <iostream>
 #include <stdio.h>
 using namespace std;
 using namespace cv;
 /** Function Headers */
 void detectAndDisplay( Mat frame );
 /** Global variables */
 String face_cascade_name = “/usr/share/opencv/lbpcascades/lbpcascade_frontalface.xml”;
  CascadeClassifier face_cascade;
  string window_name = “Capture – Face detection”;
 RNG rng(12345);
 /** @function main */
 int main( int argc, const char** argv )
   CvCapture* capture;
   Mat frame;
   //– 1. Load the cascades
   if( !face_cascade.load( face_cascade_name ) ){ printf(“–(!)Error loading\n”); return -1; };
   //– 2. Read the video stream
   capture = cvCaptureFromCAM( -1 );
   cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH,320);
   cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT,240);
        if( capture )
     while( true )
   frame = cvQueryFrame( capture );
   //– 3. Apply the classifier to the frame
       if( !frame.empty() )
       { detectAndDisplay( frame ); }
       { printf(” –(!) No captured frame — Break!”); break; }
       int c = waitKey(10);
       if( (char)c == ‘c’ ) { break; }
   return 0;
/** @function detectAndDisplay */
void detectAndDisplay( Mat frame )
  std::vector<Rect> faces;
 Mat frame_gray;
  cvtColor( frame, frame_gray, CV_BGR2GRAY );
  equalizeHist( frame_gray, frame_gray );
  //– Detect faces
  face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
  for( size_t i = 0; i < faces.size(); i++ )
    Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
    ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
    Mat faceROI = frame_gray( faces[i] );
  system(” gpio mode 0 out”);
  system (” gpio write 0 1″);
  //– Show what you got
  imshow( window_name, frame );
  system (“gpio write 0 0”);
/*Face detect and control GPIO code ends here*/
$ nano CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
find_package( OpenCV REQUIRED )
add_executable( facerec facerec.cpp )
target_link_libraries( facerec ${OpenCV_LIBS} )
 $ ./facerec
If you want to download the binary and the code then click on
I am only able to show you my friend’s face detected while in the background you can see me but i was clicking photo on monitor.
Any ways LED blinking can’t be shown in a still picture. So you may try it yourself. It looks awesome though. 
Now go party somewhere dancing on “That Billie Jean is not my lover“.

Raspberry Pi Face Detection Controlled GPIO (Part 4)

Fourth part would be fantastic experience. Because you gotta be coding.

First let us see video capture. But which are the libraries that can support capturing videos?


Well i am using OPENCV and to have that we need to install that. Very simple.

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get install libopencv-dev

After successful installation we might use OPENCV library and write a CPP code to capture video.

$ mkdir manjunath

$ nano vidcap.cpp

/* Code for video Capture starts here */

#include “opencv2/opencv.hpp”

#include <opencv/cv.h>

#include <opencv2/highgui/highgui.hpp>

#include <opencv2/imgproc/imgproc.hpp>

#include <stdio.h>

#include <iostream>

//includes headers from /usr/include/..

using namespace cv;

using namespace std; //if at all you want to use cout …

int main( int , char**)


CvCapture* capture; //remember same name is going to be used “capture”

Mat frame; //declare container for image frames…

//– 2. Read the video stream

capture = cvCaptureFromCAM( -1 );

// from default camera . If not successful try 1 or 0.

cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH,320);

cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT,240);
// window size for showing video captured.

if( capture )


while( true )


frame = cvQueryFrame( capture );

imshow(“videocapture”, frame); //name the window

int c = waitKey(10);

if( (char)c == ‘c’ ) { break; }



return 0;


/* Code for video Capture ends here */


Now how do you compile this. I am happy with CMAKE. If you don’t know anything of CMAKE please visit my blog else

$ nano CMakeLists.txt

cmake_minimum_required(VERSION 2.8)


find_package( OpenCV REQUIRED )

add_executable( video vidcap.cpp )

target_link_libraries( video ${OpenCV_LIBS} )



$ mkdir build

$ cd build

$ cmake ..

$ make

Now see if everything goes right.

$ ./video //should give you nice and clean video captured from Raspberry Pi camera.

You may ask what’s the difference between Raspivid and our executible. Well there are 2 differences,

  1. Our’s uses OPENCV and Raspivid’s, well GOD Knows.
  1. Our’s is editable and based on this i am going to write my new code which can detect faces.

    Now i am towards the business end. But wait.. my favorite pass time is listening songs so “HERE I AM, THIS IS ME, THERE IS NO WHERE ELSE ON EARTH I WOULD RATHER BE”

Raspberry Pi Face Detection Controlled GPIO (Part 2 and 3)

In the second part we may see how GPIO can be controlled.

Step1: In terminal, Check gpio settings and installation. They must be present by default.

$ gpio -v //for version check

Step 2: Connect LED to any GPIO pin according to configuration, through resistors as shown below.

Step 3: To Check whether LED or connection is fine, short one wire to pin 1 which is VCC.

REMEMBER: Pin 6 should always be grounded.

Step 4: Now in terminal,

$ gpio mode 0 out

$ gpio write 7 1

$ gpio write 7 0

(if you have connected to pin 7).

If everything goes right, you must be able to see LED ON and OFF.

In the third part we shall see if camera is working fine.

Connect Camera as shown. Mine is Revision 1 board and version 1.3 camera. Check yours and connect accordingly.

now say

$ raspi-config

and enable camera. Select and finish.

$ raspistill -o me.jpg

what do you see??? Yep!! it is working and you can see yourself on camera if you have focussed on camera while taking the snap.

So now??? Take a break yar!!! Listen to “BEAUTIFUL STRANGER” by

Raspberry Pi Face Detection Controlled GPIO (Part 1)


It’s almost 2 months i have been working on Raspberry Pi. I wanted to come out with some results unfortunately there were too many hurdles. At the end, i thought i would split my wholesome bully ride to smaller ones. So here’s the first on Face Detection combined with GPIO Control.

Raspberry Pi is an educational embedded kit which can be bought for 2500 INR and it has it’s own Camera which comes for another 2200 INR roughly. So in 5000 rupees this project is possible provided you have few things already.

Required Components,

  1. HDMI (Necessary)
  2. Mouse (optional)
  3. Keyboard (optional)
  4. Ethernet (Necessary)
  5. 5V-3A supply (Necessary)
  6. Raspi CAM (Necessary)
  7. Raspi Board (rev 1 or 2) (Necessary)
  8. Bread Board (Necessary)
  9. LED with suitable Resistors (Necessary)
  10. MALE/FEMALE Connectors (Necessary)
  11. An SD card 8GB/16GB

Step 1: Download Raspberry pi Debian image Wheezy-Raspbian (latest image) from

Step 2: If you are using Linux Machine then First thing first, take the SD card and insert in card reader, run

$ df -h

see your mounted device(card) as /dev/sdc or /dev/sdd.

Step 3: Unmount device

$  umount /dev/sdc1 or /dev/sdd1

Step 4: Flash

$ dd bs=4M if=2014-09-09-wheezy-raspbian.img of=/dev/sdd    // (as in my case)

Now sit back and listen to Eagles-Hotel California, Pink Floyd’s Coming Back to Life, Metallica’s Nothing Else Matters and Jackson’s Beat It.

You may now come back to see if it is flashed.

$ sync

If you are using windows then flash using a “win32diskmanager” tool. It is quite easy just google it if you don’t know or follow this link,

You have a Raspberry Pi up and Running. So part 1 is over.