Thursday, September 1, 2011

Custom Linux in BeagleBoard-xM

The golden reference:
    [labbookpages website]
    [Angstrom Linux - BeagleBoardXm]

Step1: Build the toolchain
    Use crosstool-ng
    [crosstool website]
    My version - crosstool-ng-1.9.3 [180 directories, 1227 files]
    Takes nearly 1 hour to build completely.
    At the end a set of executables viz. "arm-unknown-linux-gnueabi-gcc"
    etc. could be seen in the "x-tools/bin" directory.

Step2: Build the U-Boot
    Bootloader boots the system by copying the kernel &
    root file system to memory.
    [U-Boot website]
    [U-Boot Source Code]
    $ cd u-boot-2011.06/
    $ export CROSS_COMPILE=arm-unknown-linux-gnueabi-
    $ export PATH="/files/beagle/x-tools/bin:$PATH"
    $ make distclean [May have to be root]
    $ make omap3_beagle_config
    $ make
    "u-boot.bin" would be obtained in the same folder 'u-boot-2011.06'

Step3: Build the Xloader (MLO)
      [Xloader reference1] [Xloader reference2]

     Why xloader?
          The SRAM size in DM3730 is 64K.
          u-boot binary size is more than this.(~300K)
          x-loader binary size is lesser (~24K)
          Hence Xloader is required as the main loader
          in SRAM, which would download the u-boot image
          to main MDDR SDRAM.(512MB).
    $ git clone git://gitorious.org/x-load-omap3/mainline.git
    $ cd mainline
    $ make distclean
    $ make omap3530beagle_config
          (NOTE: config file updated in mainline
          tree for DM3730 in BeagleBoardXm)
    $ make
      The output would be "x-loader.bin"; which is in
      raw executable format.
      The size and address should be added at the
      image's first 16-bytes for non-XIP devices.
    Use signGP script [signGP Source Code]
    $ ./signGP x-load.bin
    "x-load.bin.ift" file would be created.
    $ mv x-load.bin.ift MLO

Step4: Build the Linux Kernel
    

Step5: Build the root file system


Step6: Create the boot script



Step7: Prepare the microSdCard
    5 files need to be stored in the uSd Card.
          1. MLO (Xloader)
          [ NOTE: This should be copied first to ensure that it is at the
          start of the card. After copying unmount & then re-mount  
          the card. ]
          2. u-boot.bin
          3. boot.scr (Boot script)
          4. uImage (Linux Kernel image)
          5. rootfs.ext2 (Root file system)

    Two partitions are created.
    The first is used to store the boot loader, kernel and root filing system. 
    The second partition can be used for general file storage.

    7.1 Delete existing partitions
     Remove the existing partition tables:

             root@neolappy:/files/beagle/vinchk#
             dd if=/dev/zero of=/dev/mmcblk0 bs=1024 count=1024


    7.2 Create primary partition
       
       root@neolappy:/files/beagle/vinchk# fdisk /dev/mmcblk0
    Device contains neither a valid DOS partition table, nor Sun, 
    SGI or OSF disklabel
    Building a new DOS disklabel with disk identifier 0x58bad9f5.
    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-122784, default 1): (Press Enter)
    Using default value 1
    Last cylinder, +cylinders or +size{K,M,G} (1-122784, default 122784): +64M

    Command (m for help): t
    Selected partition 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

    
7.2 Create the 2nd partition
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 2
    First cylinder (2050-122784, default 2050): (Press Enter)
    Using default value 2050
    Last cylinder, +cylinders or +size{K,M,G} (2050-122784,
    default 122784): (Press Enter)
    Using default value 122784

    Command (m for help): t
    Partition number (1-4): 2
    Hex code (type L to list codes): 83

    Command (m for help):

7.3 Check created partitions & write
    Command (m for help): p

    Disk /dev/mmcblk0: 4023 MB, 4023386112 bytes
    4 heads, 16 sectors/track, 122784 cylinders
    Units = cylinders of 64 * 512 = 32768 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x58bad9f5

   Device          Boot   Start    End       Blocks   Id     System
   /dev/mmcblk0p1   *     1        2049      65560    c      W95 FAT32 (LBA)
   /dev/mmcblk0p2         2050     122784    3863520  83     Linux

    Command (m for help): w
    The partition table has been altered!

   Calling ioctl() to re-read partition table.

   WARNING: Re-reading the partition table failed with error 16:
   Device or    resource busy.
   The kernel still uses the old table. The new table will be used at
   the next reboot or after you run partprobe(8) or kpartx(8)

   WARNING: If you have created or modified any DOS 6.x
   partitions, please see the fdisk manual page for additional
   information.
   Syncing disks.

Partitions: mmcblk0
                            1. mmcblk0p1
                            2. mmcblk0p2

7.4 Create the file systems in the partitions

    Partition1: mkfs.vfat -F 32 -n "boot" /dev/mmcblk0p1
    Partition2: mke2fs -L "files" /dev/mmcblk0p2 
 
    root@neolappy:/files/beagle/vinchk# mkfs.vfat -F 32 -n "boot" /dev/mmcblk0p1
    mkfs.vfat 3.0.9 (31 Jan 2010)
 
    root@neolappy:/files/beagle/vinchk# mke2fs -L "files" /dev/mmcblk0p2 
    mke2fs 1.41.14 (22-Dec-2010)
    Filesystem label=files
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    241920 inodes, 965880 blocks
    48294 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=989855744
    30 block groups
    32768 blocks per group, 32768 fragments per group
    8064 inodes per group
    Superblock backups stored on blocks: 
        	32768, 98304, 163840, 229376, 294912, 819200, 884736

    Writing inode tables: done                            
    Writing superblocks and filesystem accounting information: done

    This filesystem will be automatically checked every 32 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.




Friday, August 19, 2011

what is systems software?

Operating system and utility programs manage computer resources at a low level.
Software is generally divided into:
1. Systems software
2. Applications software

Applications software comprises programs designed for an end user, such as word processors, database systems, and spreadsheet programs.
Systems software includes compilers, loaders, linkers and debuggers.

Tuesday, July 26, 2011

Baudrate issue in Beagleboard Xm

While working with Beagleboard Xm I faced a strange issue related to baud rate.
My setup:
   1. Beagle Board Xm
   2. Acer 4930 Laptop
   3. 5v,3Amps supply for Beagleboard
   4. USB to serial converter. [Detected as /dev/ttyUSB0 - minicom is used on host side]
The issue:
  1. Getting jumbled characters in u-boot menu at times
  2. This continues even if the kernel is up.
Solution:
For u-boot:
Change the current baudrate "setenv baudrate 19200"
Change the baudrate in minicom "CTRL A,Z; O; Serial Port Setup; E; B(Require times for 19200)"
For seeing the kernel messages:
Before booting the kernel set the proper bootargs to be passed.
"setenv bootargs console=ttyS2,19200n8"
NOTE: The kernel boot-up messages could be seen; but the login prompt is not seen due to the issue. Here change back minicom(host side) baud rate to 115200.
Now the login prompt could be seen; but the jumbled character issue would be there.
Still login using the required credentials.
After logging in:
Use the shell command to change baudrate of required serial port
"stty -F /dev/ttyS2 speed 19200"

Sunday, July 24, 2011

BeagleboardXm Experiments

Install "u-boot-tools" also to use mkimage.
#sudo apt-get install u-boot-tools


Start Here with Beagle Board Xm

==================================
Build Root: Download source errors
1. genext2fs -> http://sourceforge.net/projects/genext2fs/files/
2. fakeroot --> http://sources.buildroot.net/
STEPS:
1. make menuconfig
2. Select - Build Options
3. Select - Mirrors and Download locations
4. Set "Primary Download site" as "http://sources.buildroot.net/"
===================================

Thursday, July 14, 2011

How to configure vi for source code browsing?

Install
1. Install ctags
The ctags program which is written by the VIM team is called " Exuberant Ctags" and supports the most features in VIM.Use it.
2. Install cscope
3. Download and place "cscope_maps.vim" plugin in your directory "$HOME/.vim/plugin".
[If the directories are not there, create them using mkdir command]


Create Database for ctags & cscope
In your source code directory:
    1. ctags -RV
    2. cscope -Rvb


How to navigate?
Place cursor on any symbol(function name,variable...) & press the key combinations.
1. ctags:
    CTRL + ], SHIFT + 8, CTRL + T, CTRL + I, CTRL + O
2. cscope
    CTRL + \ + s

Advanced Vi Tutorial

Thursday, June 9, 2011

The questions

C Programming
1. Pointers
2. Bit-arithmetic
3. Basic data structures(list,queue,stack,hash table, array).Data structure selection for different situations: time complexity/memory useage tradeoffs
4. Notions of virtual address and physical address and how pointers can be used to access them
5. Differences between libray calls versus system calls
6. How various commonly used routines like - malloc(), free() , printf() are implemented
7. If you have networking background - get an idea of how typical networking routines like connect(), bin(), recv(), sento(),recvfrom() are implemented.

Operating Systems(linux,unix(bsd),vxWorks)
1. Get an idea of common OS services are implemented
- what is involved in process/task/thread creation
- what is involved in locking or unlocking a semaphore
- what is involved in implementing a sleep() routine
2. If you have networking background, get an idea of how packets traverse the stack from wire to socket buffers through different execution contexts like interrupts and/or tasks and/or tasklets and/or bottom-halfs and/or work-queues and/or processes and/or softirqs and/or ISRs. An idea of what are the typical API used in transition between network stack layers and different contexts of execution.
3. Get and idea of the type of locking to use for a given mutual exclusion requirement- for example when to use semaphore versus spinlock or when to use spinlock versus irq_disable/enable. An idea of locks are eligible for use in which execution contexts.


Architecture(x86/MIPS/PowerPC/ARM/any other 32-bit or 64-bit processor)
1. Differences between virtual memory and physical memory
2. What is segmentation fault or page fault and physical memory
3. what is involved in DMA transfer
4. How is a spinlock implemented - what assembly instructions
5. Differences between 32-bit and 64-bit CPUs and impact of that on software and how software can be designed to be portable.
6. Commonly used compiler flags and optimizations. Impact of this options(+ve or -ve) on program execution.