Tuesday, 3 April 2012

HowToUbootScriptcmd

U-boot is a very versatile universal opensource bootloader, a customized version of which is used in VT8500 and WM8505-based devices. It has a built-in mini-shell with some handy commands that can be accessed through a [[serial console]]. Alternatively, required command sequences to e.g. redefine boot parameters and load a custom OS (like the Linux kernel) can be put into a so-called scriptcmd file. This is basically just a plain text script for the U-boot’s shell with just some binary header added to it.
The useful fact is that by default VT8500/WM8505 versions of U-boot will happily execute a scriptcmd file put into a script/ folder on the first partition (FAT) of an SD card, which allows for a simple and non-destructive redefinition of the boot sequence.
Below are the simple steps to take to create your own scriptcmd file (assuming that you have the mkimage program from U-boot tools package installed already).
  • Create a plain text file with the commands you need and call it, for example, script.txt. In the simplest case its contents may be something like this:
setenv bootargs rootwait root=/dev/sda1
fatload mmc 0 0 /script/uImage
bootm 0
The first statement redefines the kernel command line to allow the first partition on a USB drive (/dev/sda1) to be used as a root filesystem. The second one loads /script/uImage from the first partition of the SD card to a memory address 0. The third one executes the Linux kernel uImage that we've just loaded into memory.
  • Generate the final scriptcmd file (the one with a binary header) by issuing a command like this:
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n “My scriptcmd” -d script.txt scriptcmd
  • Put the scriptcmd file together with your kernel uImage to a script/ folder on the first (FAT) partition on an SD card and turn your device on with this card inserted. If everything is OK, your kernel should boot up.

Pthread Example


Set up Ubuntu to use static ip address

 had bit problem when using tftp server to boot NGW100, every time DHCP tend to find a different ip address for my PC, which is not what I wanted;I don’t want to change NGW100 boot args everytime to use different TFTP server or NFS server.
Here is what I do:
If Your Ubuntu System has set to use DHCP, you will want to change it to a static IP address here is simple tip
open the /etc/network/interfaces file.
sudo vi /etc/network/interfaces
If you are using DHCP for your primary network card which is usually eth0, you will see the following lines
auto eth0
iface eth0 inet dhcp
As you can see, it’s using DHCP right now. We are going to change dhcp to static, and then there are a number of options that should add and here is the example and you can change these settings according to your network settings.
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
Restart the neworking service using the following command
sudo /etc/init.d/networking restart
My interfaces file like this:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
        address 192.168.1.59
        netmask 255.255.255.0
        broadcast 192.168.1.255
        network 192.168.1.0
        gateway 192.168.1.2

PThread example
    #include <stdio.h>
    #include <stdlib.h>
    #include <pthread.h>
    void *print_message_function( void *ptr );
    main()
    {
         pthread_t thread1, thread2;
         char *message1 = “Thread 1″;
         char *message2 = “Thread 2″;
         int  iret1, iret2;
        /* Create independent threads each of which will execute function */
         iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1);
         iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2);
         /* Wait till threads are complete before main continues. Unless we  */
         /* wait we run the risk of executing an exit which will terminate   */
         /* the process and all threads before the threads have completed.   */
         pthread_join( thread1, NULL);
         pthread_join( thread2, NULL);
         printf(“Thread 1 returns: %d “,iret1);
         printf(“Thread 2 returns: %d “,iret2);
         exit(0);
    }
    void *print_message_function( void *ptr )
    {
         char *message;
         message = (char *) ptr;
         printf(“%s “, message);
    }

Thursday, 9 February 2012

How To Compile GTK Application For Arm


1. add the following lines to your /etc/apt/sources.list at the bottom

deb http://scratchbox.org/debian/ apophis main
deb http://scratchbox.org/debian/ hathor main


2.

$ sudo apt-get update
$ sudo apt-get install scratchbox-core scratchbox-libs scratchbox-devkit-qemu scratchbox-devkit-debian scratchbox-devkit-doctools scratchbox-devkit-perl scratchbox-toolchain-host-gcc scratchbox-toolchain-cs2007q3-glibc2.5-arm7 scratchbox-toolchain-cs2007q3-glibc2.5-i486  scratchbox-devkit-svn scratchbox-devkit-git scratchbox-devkit-apt-https


3.
run
$ sudo /scratchbox/sbin/sbox_adduser $USER

4.
$/scratchbox/login

5.
after login
$ /scratchbox/login

Welcome to Scratchbox, the cross-compilation toolkit!

Use 'sb-menu' to change your compilation target.

See /scratchbox/doc/ for documentation.

[sbox-FREMANTLE_X86: ~]>

6.
[sbox-FREMANTLE_X86: ~]> sb_menu





a)You will enter the main menu:
Select the Setup option.
b)First it will ask if you want to create a new target or change the configuration of a previously created target:
Select the NEW option.

c)Since we're creating a new target we need to specify a name:

We use "MYTARGET" as the target name in this example.

d)Next, the setup will ask which toolchain should be used to compile programs:
We selected gcc 3.3 that creates binaries for the ARM architecture and links them against glibc 2.3.

e)We can select optional development tools:
At this point we don't need any. Just select the DONE option to proceed.

f)After development kit selection the CPU-transparency method is chosen:
The QEMU emulator is sufficient for our example target, so select 'qemu-arm'.

g)Now the setup is done, but sb-menu asks if we want to extract a rootstrap and/or install system files on the target. Answer no to the rootstrap question but choose to install files.

h)You can install the C-library (and related binaries) provided by the toolchain, some standard config files in /etc, config files required by the selected devkits (we have not selected any) and some target-specific binaries:

i)The default selection is fine, so you can just press enter to install them.

Everything is now ready and we can activate the target by answering yes to the last question.



7.
Now we need to compile gtk packages for building our gtk application



GTK+, or the GIMP Toolkit, is a multi-platform toolkit for creating graphical user interfaces. Offering a complete set of widgets. GTK+ is suitable for projects ranging from small one-off tools to complete application suites.

I have download the below softwares to start with.
atk-1.30.0: http://ftp.gnome.org/pub/GNOME/sources/atk/1.30/atk-1.30.0.tar.bz2

cairo-1.8.10: http://cairographics.org/releases/cairo-1.8.10.tar.gz

DirectFB-1.4.3: http://directfb.org/downloads/Core/DirectFB-1.4/DirectFB-1.4.3.tar.gz

expat-2.0.1: http://sourceforge.net/projects/expat/

fontconfig-2.8.0: http://fontconfig.org/release/fontconfig-2.8.0.tar.gz

freetype-2.3.12: http://sourceforge.net/projects/freetype/files/

glib-2.24.0: http://ftp.gnome.org/pub/gnome/sources/glib/2.24/glib-2.24.0.tar.bz2

gtk+-2.20.1: http://ftp.gnome.org/pub/gnome/sources/gtk+/2.20/gtk+-2.20.1.tar.bz2

jpeg-8b: http://www.ijg.org/files/jpegsrc.v8b.tar.gz

tslib: http://www.zelow.no/floppyfw/download/Development/src/

libpng-1.2.39: http://sourceforge.net/projects/libpng/files/

libxml2-2.7.7: ftp://gd.tuwien.ac.at/pub/libxml/libxml2-2.7.7.tar.gz

pango-1.28.1: http://ftp.gnome.org/pub/gnome/sources/pango/1.28/pango-1.28.1.tar.bz2

pixman-0.18.2: http://cairographics.org/releases/pixman-0.18.2.tar.gz










tiff-3.9.2: http://download.osgeo.org/libtiff/tiff-3.9.2.tar.gz

zlib-1.2.5: http://zlib.net/zlib-1.2.5.tar.gz


With scratchbox and qemu on the host machine cross compiling was straightforward.

Cross compiling order

1) tslib
sb2 ./configure --prefix=/opt/ram
sb2 make install

2) zlib
since glib require zlib
sb2 ./configure --prefix=/opt/ram --shared
sb2 make install

3) glib
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --disable-static --with-html-dir=/tmp/dump
sb2 make install

4) atk
export PKG_CONFIG_PATH=/opt/ram/lib/pkgconfig
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --disable-glibtest
sb2 make install

5) jpeg-8b
sb2 ./configure --prefix=/opt/ram --enable-shared --enable-static
sb2 make install


6) libpng
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram
sb2 make install

7) expat-2.0
sb2 ./configure --prefix=/opt/ram
sb2 make install

8) freetype
sb2 ./configure --prefix=/opt/ram
sb2 make install

9)libxml
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --without-python
sb2 make install

10)freetype-2.3.12
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --with-freetype-config=/opt/ram/bin/freetype-config

11) tiff -- not used gcc 4.3.2
LDFLAGS=-L/opt/arm/gst/lib CPPFLAGS=-I/opt/arm/gst/include/ sb2 ./configure --prefix=/opt/ram --enable-shared
sb2 make install

12) DirectFB
LDFLAGS=-L/opt/arm/gst/lib CPPFLAGS=-I/opt/arm/gst/include/ sb2 ./configure --prefix=/opt/ram --with-gfxdrivers=none --with-inputdrivers=all --enable-png --enable-jpeg --enable-tiff=no --enable-zlib --enable-sdl=no --enable-gif=no --disable-x11
sb2 make install

13) pixman-0.18.2
LDFLAGS=-L/opt/arm/gst/lib CPPFLAGS=-I/opt/arm/gst/include/ sb2 ./configure --prefix=/opt/ram --disable-gtk

14) cairo
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --without-x --disable-xlib --disable-xlib-xrender --enable-directfb --enable-freetype --disable-win32 --enable-pdf --enable-ps --enable-svg --enable-png

15) Pango
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --without-x

16 gtk
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --with-gdktarget=directfb --without-x --without-libtiff --disable-glibtest --disable-cups

Now to compile a simple helloworld.c pro-gramme with these libraries.

export PKG_CONFIG_PATH=/opt/ram/lib/pkgconfig

[arm-linux~]>arm-linux-gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` -Wl,-O1 -Wl,-rpath,/opt/ram/lib

Tuesday, 10 January 2012

Linux Directory Structure (File System Structure) Explained with Examples


Have you wondered why certain programs are located under /bin, or /sbin, or /usr/bin, or /usr/sbin?
For example, less command is located under /usr/bin directory. Why not /bin, or /sbin, or /usr/sbin? What is the different between all these directories?
In this article, let us review the Linux filesystem structures and understand the meaning of individual high-level directories.


1. / – Root

  • Every single file and directory starts from the root directory.
  • Only root user has write privilege under this directory.
  • Please note that /root is root user’s home directory, which is not same as /.

2. /bin – User Binaries

  • Contains binary executables.
  • Common linux commands you need to use in single-user modes are located under this directory.
  • Commands used by all the users of the system are located here.
  • For example: ps, ls, ping, grep, cp.

3. /sbin – System Binaries

  • Just like /bin, /sbin also contains binary executables.
  • But, the linux commands located under this directory are used typically by system aministrator, for system maintenance purpose.
  • For example: iptables, reboot, fdisk, ifconfig, swapon

4. /etc – Configuration Files

  • Contains configuration files required by all programs.
  • This also contains startup and shutdown shell scripts used to start/stop individual programs.
  • For example: /etc/resolv.conf, /etc/logrotate.conf

5. /dev – Device Files

  • Contains device files.
  • These include terminal devices, usb, or any device attached to the system.
  • For example: /dev/tty1, /dev/usbmon0

6. /proc – Process Information

  • Contains information about system process.
  • This is a pseudo filesystem contains information about running process. For example: /proc/{pid} directory contains information about the process with that particular pid.
  • This is a virtual filesystem with text information about system resources. For example: /proc/uptime

7. /var – Variable Files

  • var stands for variable files.
  • Content of the files that are expected to grow can be found under this directory.
  • This includes — system log files (/var/log); packages and database files (/var/lib); emails (/var/mail); print queues (/var/spool); lock files (/var/lock); temp files needed across reboots (/var/tmp);

8. /tmp – Temporary Files

  • Directory that contains temporary files created by system and users.
  • Files under this directory are deleted when system is rebooted.

9. /usr – User Programs

  • Contains binaries, libraries, documentation, and source-code for second level programs.
  • /usr/bin contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For example: at, awk, cc, less, scp
  • /usr/sbin contains binary files for system administrators. If you can’t find a system binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel
  • /usr/lib contains libraries for /usr/bin and /usr/sbin
  • /usr/local contains users programs that you install from source. For example, when you install apache from source, it goes under /usr/local/apache2

10. /home – Home Directories

  • Home directories for all users to store their personal files.
  • For example: /home/john, /home/nikita

11. /boot – Boot Loader Files

  • Contains boot loader related files.
  • Kernel initrd, vmlinux, grub files are located under /boot
  • For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic

12. /lib – System Libraries

  • Contains library files that supports the binaries located under /bin and /sbin
  • Library filenames are either ld* or lib*.so.*
  • For example: ld-2.11.1.so, libncurses.so.5.7

13. /opt – Optional add-on Applications

  • opt stands for optional.
  • Contains add-on applications from individual vendors.
  • add-on applications should be installed under either /opt/ or /opt/ sub-directory.

14. /mnt – Mount Directory

  • Temporary mount directory where sysadmins can mount filesystems.

15. /media – Removable Media Devices

  • Temporary mount directory for removable devices.
  • For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer

16. /srv – Service Data

  • srv stands for service.
  • Contains server specific services related data.
  • For example, /srv/cvs contains CVS related data.

Monday, 9 January 2012

How to Run a C program/Shell script with root privilege

This method for creating a script that runs as root automatically.
  1. Open a text editor, and type up your script:
    #!/bin/sh
    program1
    program2
    ...
  2. Save the file as something.sh.
  3. Open a terminal, and enter the following commands:
    $ su
    [enter password]
    chown root:root something.sh
    chmod 4755 something.sh
    exit
    
  4. Then, finally run it with ./something.sh, and it'll have root access!
...or not. Most likely, you'll get the same error messages that you did before you ran those commands. If your script does actually work,
Take the down part for executing it.

The problem The instructions are fairly straightforward. Create the shell script that you want to execute, and change the owner and group to root (chown root:root). Now comes the command that's supposed to do the magic:
chmod 4755

Except it doesn't. Well, the truth is actually that the setuid bit is disabled on a lot of *nix implementations due the massive security holes it incurs. If the method originally mentioned doesn't work for you, chances are that your Linux distribution has disabled setuid for shell scripts.

The solution(s) One way of solving this problem is to call the shell script from a program that can use the setuid bit. For example, here is how you would accomplish this in a C program:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
   setuid( 0 );
   system( "/path/to/script.sh" );

   return 0;
}

chown root:root runscript
chmod 4755 runscript

Now, you should be able to run it, and you'll see your script being executed with root permissions.
Conclusion With all that said, running shell scripts with setuid isn't very safe, and the distro designers had a pretty good idea of what they were doing when many of them disabled it. If you're running a multiuser Unix environment and security is an asset for you, make sure that your scripts are secure. A single slip can result in the compromising of an entire network. Only use them when absolutely necessary, and make sure you know exactly what you're doing if you do decide to use them.

Wednesday, 28 December 2011

PANDABOARD DOTA


                                        -------------------------------
                                    PANDABOARD DOTA
                                        -------------------------------
building the Kernel:-
---------------------
git clone https://android.googlesource.com/kernel/omap
cd omap
git checkout remotes/origin/android-omap-panda-3.0
make ARCH=arm CROSS_COMPILE=/home/ramchandra/ics/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- mrproper
make ARCH=arm CROSS_COMPILE=/home/ramchandra/ics/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- defconfig panda_defconfig
make uImage

replace the kernel binary image under ics/device/ti/panda from arch/arm/boot/zImage




# From: www.android.com > Partners > Getting the Source
#    http://source.android.com/source/downloading.html

mkdir bin
export PATH=$PWD/bin:$PATH
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > bin/repo
chmod a+x bin/repo
# We want master
mkdir ics
cd ics
repo init -u https://android.googlesource.com/platform/manifest
repo sync



# From http://source.android.com/source/building.html
# and
# device/ti/panda/README

******replace the kernel binary image under device/ti/panda from arch/arm/boot/zImage


source build/envsetup.sh
lunch full_panda-eng
make fastboot



# Fetch the binaries from http://code.google.com/android/nexus/drivers.html#panda and extract it into ics root directory resulting into a "vendor" folder


wget --no-check-certificate https://dl.google.com/dl/android/aosp/imgtec-panda-itl41d-dfebf249.tgz
tar -zxvf imgtec-panda-itl41d-dfebf249.tgz

# accept license

make -j8


# wait a bit



--------------------------------------------------------------------------------------
                        Partitioning the SD-Card
                       --------------------------
Using fdisk /dev/sdX
make the following partitions in the sd card
sdX1 --->boot (64MB)
sdX2 --->system(around 1GB)
sdX3---->cache (64MB)
sdX4---->userdata(256MB)
sdX5---->sdcard(128MB)
sdX6---->our minimal fs (64MB)

sudo mkfs.vfat -F 32 -n "boot" /dev/sdX1
sudo mkfs.ext4 -j -L "system" /dev/sdX2
sudo mkfs.ext4 -j -L "cache" /dev/sdX3
sudo mkfs.ext4 -j -L "userdata" /dev/sdX4
sudo mkfs.ext4 -j -L "sdcard" /dev/sdX5
sudo mkfs.ext4 -j -L "amifs" /dev/sdX6


It will look like this :

Disk /dev/sdb: 3974 MB, 3974103040 bytes
128 heads, 32 sectors/track, 1895 cylinders
Units = cylinders of 4096 * 512 = 2097152 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a10f8

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          66      135136    c  W95 FAT32 (LBA)
Partition 1 does not end on cylinder boundary.
/dev/sdb2              67         322      524288   83  Linux
/dev/sdb3             323         450      262144   83  Linux
/dev/sdb4             451         706      524272   83  Linux
/dev/sdb5             739         770       65520   83  Linux
/dev/sdb6             707         738       65520   83  Linux

Partition table entries are not in disk order

--------------------------------------------------------------------------------------
# copy in the boot


mkdir mnt
sudo mount /dev/sdc1 mnt

sudo cp device/ti/panda/xloader.bin mnt/MLO
sudo cp device/ti/panda/bootloader.bin mnt/u-boot.bin

sudo umount mnt
sync

# Then plug the SD card into the Panda and USB into J18 and power on the unit

sudo ./fastboot devices

sudo fastboot oem format
sudo fastboot flash xloader device/ti/panda/xloader.bin
sudo fastboot flash bootloader device/ti/panda/bootloader.bin

sudo fastboot erase cache

sudo fastboot flash system out/target/product/panda/system.img
sudo fastboot flash userdata out/target/product/panda/userdata.img
sudo fastboot flash boot out/target/product/panda/boot.img


Now your bootable SD-Card is ready , Put your SD-Card in pandaboard :-
----------------------------------------------------------------------


----------------------------------------
THIS IS RUNNING WITH ANDROID FILE SYSTEM.
----------------------------------------
# ./busybox pwd
/

#mkdir new-root
# cd /new-root
#mkdir old-root
# ls
tmp    bin  data  var  linuxrc  media  lib  sys  busybox  mnt  index.html
proc  dev  old-root  boot  ota_arm  usr  sbin  lost+found  etc  home

# pwd
/new-root
# ./busybox pivot_root . old-root
# ./busybox mount none /proc -t proc
# ./busybox mount none /sys -t sysfs
# ./busybox mount none /dev/pts -t devpts


# ./busybox mount
rootfs on / type rootfs (rw)
/dev/root on /old-root type ext4 (rw,relatime,barrier=1,data=ordered)
devtmpfs on /old-root/dev type devtmpfs (rw,relatime,size=471164k,nr_inodes=117791,mode=755)
tmpfs on /old-root/dev type tmpfs (rw,relatime,mode=755)
devpts on /old-root/dev/pts type devpts (rw,relatime,mode=600)
sysfs on /old-root/sys type sysfs (rw,relatime)
none on /old-root/dev/cpuctl type cgroup (rw,relatime,cpu)
/dev/block/mmcblk0p7 on / type ext4 (rw,relatime,barrier=1,data=ordered)
none on /proc type proc (rw,relatime)
none on /sys type sysfs (rw,relatime)
none on /dev/pts type devpts (rw,relatime,mode=600)
# ./busybox umount /old-root/dev/pts
umount: can't umount /old-root/dev/pts: Device or resource busy
# ./busybox umount /old-root/sys
umount: can't umount /old-root/sys: Device or resource busy

# ./busybox umount /old-root/dev/cpuctl
# ./busybox umount /old-root/dev/pts
umount: can't umount /old-root/dev/pts: Device or resource busy
#
#
# ./busybox mount
rootfs on / type rootfs (rw)
/dev/root on /old-root type ext4 (rw,relatime,barrier=1,data=ordered)
devtmpfs on /old-root/dev type devtmpfs (rw,relatime,size=471164k,nr_inodes=117791,mode=755)
tmpfs on /old-root/dev type tmpfs (rw,relatime,mode=755)
devpts on /old-root/dev/pts type devpts (rw,relatime,mode=600)
sysfs on /old-root/sys type sysfs (rw,relatime)
/dev/block/mmcblk0p7 on / type ext4 (rw,relatime,barrier=1,data=ordered)
none on /proc type proc (rw,relatime)
none on /sys type sysfs (rw,relatime)
none on /dev/pts type devpts (rw,relatime,mode=600)




# ./busybox umount -l /old-root/dev
# ./busybox mount
rootfs on / type rootfs (rw)
/dev/root on /old-root type ext4 (rw,relatime,barrier=1,data=ordered)
devtmpfs on /old-root/dev type devtmpfs (rw,relatime,size=471164k,nr_inodes=117791,mode=755)
sysfs on /old-root/sys type sysfs (rw,relatime)
/dev/block/mmcblk0p7 on / type ext4 (rw,relatime,barrier=1,data=ordered)
none on /proc type proc (rw,relatime)
none on /sys type sysfs (rw,relatime)
none on /dev/pts type devpts (rw,relatime,mode=600)

# ./busybox umount -l /old-root/sys
# ./busybox mount
rootfs on / type rootfs (rw)
/dev/root on /old-root type ext4 (rw,relatime,barrier=1,data=ordered)
devtmpfs on /old-root/dev type devtmpfs (rw,relatime,size=471164k,nr_inodes=117791,mode=755)
/dev/block/mmcblk0p7 on / type ext4 (rw,relatime,barrier=1,data=ordered)
none on /proc type proc (rw,relatime)
none on /sys type sysfs (rw,relatime)
none on /dev/pts type devpts (rw,relatime,mode=600)

# ./busybox umount -l /old-root/dev
# ./busybox mount
rootfs on / type rootfs (rw)
/dev/root on /old-root type ext4 (rw,relatime,barrier=1,data=ordered)
/dev/block/mmcblk0p7 on / type ext4 (rw,relatime,barrier=1,data=ordered)
none on /proc type proc (rw,relatime)
none on /sys type sysfs (rw,relatime)
none on /dev/pts type devpts (rw,relatime,mode=600)


# ./busybox umount /old-root
umount: can't umount /old-root: Device or resource busy

# ./busybox umount -l /old-root
# ./busybox mount
rootfs on / type rootfs (rw)
/dev/block/mmcblk0p7 on / type ext4 (rw,relatime,barrier=1,data=ordered)
none on /proc type proc (rw,relatime)
none on /sys type sysfs (rw,relatime)
none on /dev/pts type devpts (rw,relatime,mode=600)

# ./busybox ls /mnt
card   cf     net    ram    ramfs  thumb


#
#

# ./busybox ls
bin         dev         lib         mnt         sbin        var
boot        etc         linuxrc     old-root    sys
busybox     home        lost+found  ota_arm     tmp
data        index.html  media       proc        usr

< we will use ramfs for keeping our downloaded images.>
-------------------------------------------------------

#mkdir /mnt/ramfs
#mount -t ramfs -o size=620MB ramfs /mnt/ramfs
# ./busybox cp ota_arm /mnt/ramfs
# ./busybox cp busybox /mnt/ramfs/busybox
#
#
# pwd
/new-root
# ./busybox ls /mnt/ramfs
busybox        ota_arm
#
# pwd
/new-root

# cd /mnt/ramfs
# pwd
/mnt/ramfs

# ./busybox ls
busybox  ota_arm
# ./ota_arm http://10.0.0.150/system_test.img
Welcome 2

Welcome 2

 ./busybox wget http://10.0.0.150/system_test.img
Connecting to 10.0.0.150 (10.0.0.150:80)
system_test.img      100% |*******************************|   512M 00:00:00 ETA
Welcome#
#
#
#
# ./busybox ls
busybox          ota_arm          system_test.img
# ./busybox dd if=system_test.img of=/dev/mmcblk0p2
1048576+0 records in
1048576+0 records out
# ./busybox rm system_test.img
# ./busybox ls
busybox  ota_arm
# ./ota_arm http://10.0.0.150/boot_test.img

Welcome 2

Welcome 2

 ./busybox wget http://10.0.0.150/boot_test.img
Connecting to 10.0.0.150 (10.0.0.150:80)
boot_test.img        100% |*******************************|   131M 00:00:00 ETA
Welcome#
#
# ./busybox dd if=boot_test.img of=/dev/mmcblk0p1
270272+0 records in
270272+0 records out
#
# ./busybox rm boot_test.img
# ./busybox ls
busybox  ota_arm
# ./ota_arm http://10.0.0.150/userdata_test.img

Welcome 2

Welcome 2

 ./busybox wget http://10.0.0.150/userdata_test.img
Connecting to 10.0.0.150 (10.0.0.150:80)
userdata_test.img    100% |*******************************|   511M 00:00:00 ETA
# ./busybox dd if=userdata_test.img of=/dev/mmcblk0p5
1048544+0 records in
1048544+0 records out
#
#
#
# ./busybox rm /mnt/ramfs/*

# cd ..
# cd ..
# ./busybox umount /mnt/ramfs
# ./busybox mount
rootfs on / type rootfs (rw)
/dev/block/mmcblk0p7 on / type ext4 (rw,relatime,barrier=1,data=ordered)
none on /proc type proc (rw,relatime)
none on /sys type sysfs (rw,relatime)
none on /dev/pts type devpts (rw,relatime,mode=600)
# ./busybox reboot















                                                                                                 9,1           Top

Sunday, 18 December 2011

How to make ICS self bootable SD Card for Pandaboard



If you want to build ICS for Pandaboard, You must use master branch.
I used AOSP local mirror.

~/panda$ mkdir ics
~/panda$ cd ics/
~/panda/ics$ repo init -u /home/kinneko/AOSP/platform/manifest.git
~/panda/ics$ repo sync

Ordinary, you can use AOSP directry, like this.

~/panda/ics$ repo init -u https://android.googlesource.com/platform/manifest.git 

And add binary video drivers.

~/panda/ics$ wget https://dl.google.com/dl/android/aosp/imgtec-panda-itl41d-dfebf249.tgz
~/panda/ics$ tar zxf imgtec-panda-itl41d-dfebf249.tgz
~/panda/ics$ ./extract-imgtec-panda.sh 

Read license, and type "I ACCEPT".

Delete disused files.

~/panda/ics$ rm imgtec-panda-itl41d-dfebf249.tgz extract-imgtec-panda.sh 


Build ICS.

~/panda/ics$ source build/envsetup.sh
including device/samsung/maguro/vendorsetup.sh
including device/samsung/tuna/vendorsetup.sh
including device/ti/panda/vendorsetup.sh
including sdk/bash_completion/adb.bash

~/panda/ics$ lunch full_panda-eng
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.0.1
TARGET_PRODUCT=full_panda
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=ICS_MR0
============================================

~/panda/ics$ time make -j12
(snip)
real 27m22.821s
user 248m39.990s
sys 14m33.140s

The value of "-j" option that may be the number of CPU in your build environment.

Download kernel.

~/panda/ics$ mkdir kernel
~/panda/ics$ cd kernel/
~/panda/ics/kernel$ git clone https://android.googlesource.com/kernel/omap
~/panda/ics/kernel$ cd omap/
~/panda/ics/kernel/omap$ git checkout -b android-omap-panda-3.0 origin/android-omap-panda-3.0
Checking out files: 100% (37523/37523), done.
Branch android-omap-panda-3.0 set up to track remote branch android-omap-panda-3.0 from origin.
Switched to a new branch 'android-omap-panda-3.0'

and build it.
You must add your path of the cross toolchain.

~/panda/ics/kernel/omap$ export ARCH=arm
~/panda/ics/kernel/omap$ export CROSS_COMPILE=arm-none-linux-gnueabi-
~/panda/ics/kernel/omap$ export PATH=/home/kinneko/panda/L27.12.1-P2/build_tools/arm-2010q1/bin:/usr/bin:/bin
~/panda/ics/kernel/omap$ make panda_defconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/lex.zconf.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#
~/panda/ics/kernel/omap$ time make uImage modules -j12
(snip)
  Image arch/arm/boot/uImage is ready
real 1m13.291s
user 10m23.260s
sys 0m44.740s

make rootfs tree.

~/panda/ics/kernel$ cd ../out/target/product/panda/
~/panda/ics/out/target/product/panda$ cp -a root/* rootfs/
~/panda/ics/out/target/product/panda$ cp -a system rootfs/

edit init.rc.

~/panda/ics/out/target/product/panda$ vi rootfs/init.rc

#on fs
# mount mtd partitions
    # Mount /system rw first to give the filesystem a chance to save a checkpoint
#    mount yaffs2 mtd@system /system
#    mount yaffs2 mtd@system /system ro remount
#    mount yaffs2 mtd@userdata /data nosuid nodev
#    mount yaffs2 mtd@cache /cache nosuid nodev

and

    mount rootfs rootfs / rw remount


service console /system/bin/sh
    class core
    console
    disabled
    #user shell
    #group log

edit init.omap4pandaboard.rc.

~/panda/ics/out/target/product/panda$ vi rootfs/init.omap4pandaboard.rc 

#on fs
#       mount ext4 /dev/block/platform/omap/omap_hsmmc.0/by-name/system /system wait ro
#       mount ext4 /dev/block/platform/omap/omap_hsmmc.0/by-name/userdata /data wait noatime nosuid nodev
#       mount ext4 /dev/block/platform/omap/omap_hsmmc.0/by-name/cache /cache wait noatime nosuid nodev

download uboot source codes.

~/panda$ git clone git://git.omapzoom.org/repo/u-boot.git    
Cloning into u-boot...
remote: Counting objects: 140837, done.
remote: Compressing objects: 100% (25115/25115), done.
remote: Total 140837 (delta 114484), reused 140801 (delta 114455)
Receiving objects: 100% (140837/140837), 42.50 MiB | 388 KiB/s, done.
Resolving deltas: 100% (114484/114484), done.

and build it.

~/panda$ cd u-boot/
~/panda/u-boot$ git checkout 601ff71c8d46b5e90e13613974a16d10f2006bb3
Note: checking out '601ff71c8d46b5e90e13613974a16d10f2006bb3'.
(snip)

You must add some short patches.

~/panda$ diff -Naur u-boot.org/include/configs/omap4430panda.h u-boot/include/configs/omap4430panda.h
--- u-boot.org/include/configs/omap4430panda.h 2011-11-22 16:05:02.384622136 +0900
+++ u-boot/include/configs/omap4430panda.h 2011-11-21 17:52:16.169639483 +0900
@@ -133,11 +133,11 @@
 /* Environment information */
 #if defined(CONFIG_4430ZEBU) && !defined(CONFIG_4430ES2)
 /* Give the standard Kernel jump command as boot cmd and without any delay */
-#define CONFIG_BOOTDELAY         0
+#define CONFIG_BOOTDELAY         1
 #define CONFIG_EXTRA_ENV_SETTINGS \
  "bootcmd=go 0x80008000\0"
 #else
-#define CONFIG_BOOTDELAY         0
+#define CONFIG_BOOTDELAY         1

 #endif /*CONFIG_4430ZEBU */

@@ -147,10 +147,9 @@
  " ip=dhcp"
 #else

-#define CONFIG_BOOTARGS "console=ttyO2,115200n8 mem=512M" \
- " init=/init vram=32M omapfb.vram=0:16M androidboot.console=ttyO2"
+#define CONFIG_BOOTARGS "console=ttyO2,115200n8 mem=1G androidboot.console=ttyO2 console=ttyO2,115200n8 mem=512M root=/dev/mmcblk0p3 rw rootdelay=2 init=/init vram=32M omapfb.vram=0:16M androidboot.console=ttyO2"

-#define CONFIG_BOOTCOMMAND "booti mmc0"
+#define CONFIG_BOOTCOMMAND "mmcinit 0;fatload mmc 0 0x80000000 uImage; bootm 0x80000000"

 #endif

Save this to "uboot.patch", and patch it.

~/panda/u-boot$ patch -p1 < uboot.patch
patching file include/configs/omap4430panda.h

Build it.

~/panda/u-boot$ make omap4430panda_config
Configuring for omap4430panda board...
~/panda/u-boot$ make
~/panda/u-boot$ cd ..

Get xloader.

~/panda$ git clone git://git.omapzoom.org/repo/x-loader.git
Cloning into x-loader...
remote: Counting objects: 1593, done.
remote: Compressing objects: 100% (407/407), done.
remote: Total 1593 (delta 1174), reused 1565 (delta 1163)
Receiving objects: 100% (1593/1593), 457.30 KiB | 76 KiB/s, done.
Resolving deltas: 100% (1174/1174), done.
~/panda$ cd x-loader/
~/panda/x-loader$ git checkout c8855fa6b85bd44073bd1b25dbffa99f02cbeeed
Note: checking out 'c8855fa6b85bd44073bd1b25dbffa99f02cbeeed'.

And build it.

~/panda/x-loader$ make omap4430panda_config
rm -f include/config.h include/config.mk
Configuring for omap4430panda board...
echo "/* Generarated file. Do not edit */" >./include/config.h
echo "#include <configs/omap4430panda.h>" >>./include/config.h
MPU at 1GHz revision..
~/panda/x-loader$ make ift
~/panda/x-loader$ cd ..

Fromat SD Card.
I used 2GB Card.
Inceart SD Card to build PC, and seek for device name.

~/panda$ dmesg
[29960.845516]  sdb: sdb1

Delete partitoins.

~/panda$ sudo dd if=/dev/zero of=/dev/sdb bs=1 count=1024
[sudo] password for kinneko:
1024+0 records in
1024+0 records out
1024 bytes (1.0 kB) copied, 0.00346839 s, 295 kB/s

Add three new partitions.
boot, media, rootfs.
"boot" include xloader, uboot and kernel.
"media" is android user space.
"rootfs "include android systems.

~/panda$ sudo fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xdf7c7ae8.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1015, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1015, default 1015): +64M
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (37-1015, default 37):
Using default value 37
Last cylinder, +cylinders or +size{K,M,G} (37-1015, default 1015): +1024M
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (593-1015, default 593):
Using default value 593
Last cylinder, +cylinders or +size{K,M,G} (593-1015, default 1015):
Using default value 1015
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))
Command (m for help): a
Partition number (1-4): 1
Command (m for help): p
Disk /dev/sdb: 1967 MB, 1967128576 bytes
61 heads, 62 sectors/track, 1015 cylinders
Units = cylinders of 3782 * 512 = 1936384 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdf7c7ae8
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          36       68045    c  W95 FAT32 (LBA)
/dev/sdb2              37         592     1051396   83  Linux
/dev/sdb3             593        1015      799893   83  Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.


Format partitions.

~/panda$ sudo mkfs.vfat -F 32 -n "boot" /dev/sdb1
mkfs.vfat 3.0.9 (31 Jan 2010)

~/panda$ sudo mkfs.vfat -F 32 -n "media" /dev/sdb2
mkfs.vfat 3.0.9 (31 Jan 2010)

~/panda$ sudo mkfs.ext4 -j -L "rootfs" /dev/sdb3
mke2fs 1.41.14 (22-Dec-2010)
Filesystem label=rootfs
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
50064 inodes, 199973 blocks
9998 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=205520896
7 block groups
32768 blocks per group, 32768 fragments per group
7152 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840
Writing inode tables: done                          
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Mount and copy files.

~/panda$ sudo mount /dev/sdb1 /media/
~/panda$ sudo cp -r x-loader/MLO /media/
~/panda$ sudo cp -r u-boot/u-boot.bin /media/
~/panda$ sudo cp -r ics/kernel/omap/arch/arm/boot/uImage /media/
~/panda$ ls -al /media/
total 4043
drwxr-xr-x  2 root root     512 Nov 21 18:24 .
drwxr-xr-x 24 root root    4096 Sep  6 19:03 ..
-rwxr-xr-x  1 root root   21604 Nov 21 17:54 MLO
-rwxr-xr-x  1 root root  160528 Nov 21 17:52 u-boot.bin
-rwxr-xr-x  1 root root 3951668 Nov 21 17:16 uImage
~/panda$ sudo umount /media/

~/panda$ sudo mount /dev/sdb3 /media
~/panda$ sudo cp -a ics/out/target/product/panda/rootfs/* /media/
~/panda$ sudo chmod 777 -R /media/
~/panda$ sudo umount /media