Sunday, December 13, 2009

GIT Guide --- update

Before your commits make sure you have these variables defined. :)
==================================================
nemesis@nemesis-laptop:~/qemu/qemu$ git config --global user.name "nemesisofstate"
nemesis@nemesis-laptop:~/qemu/qemu$ git config --global user.email "nemesisofstate@gmail.com"


for checkin
========

edit [file]
git add [file]
git commit -m "your-message-here" -s

-s
--signoff

Add Signed-off-by line by the committer at the end of the commit log message.


======================
see your patch

git format-patch origin/master

your messages
===============
git show

gitk ===> graphic tool for git

Send out your patch
================
I use gmail to send my patches ...so u need msmtp for it [http://msmtp.sourceforge.net]. Install the file and configure your ~/.msmtprc file

git-config --global sendemail.smtpserver /usr/local/bin/msmtp

sudo apt-get install git-email

git email-send

e.g
nemesis@nemesis-laptop:~/qemu/qemu$ git send-email 0001-correcting-ARM-CPSR-register-bit-position-comment.patch


HOWTO: Get specific linux kernel headers

On UBUNTU

sudo apt-get install linux-headers-$(uname -r)

Saturday, December 12, 2009

QEMU + U-BOOT

1. Get the U-Boot sources

2. sudo apt-get install qemu-kvm-extras [for qemu-system-arm]
We will compile for ARM (needless to say) target---ARM versatile board (needless again)

[NOTE]: [u-boot-dir]/include/configs contains the default configs for most of the platforms. It almost corresponds to the one in linux kernel sources.

STEPS
=======

1. make versatile_config
2. make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-

make ....make....make...

[NOTE]: Uboot needs the linux with uboot specific headers in order to boot it. This u-boot specific image can be generated using "make uImage".

However this would need mkimage. Where do we get it from---
Easy:)
---- after running make you can find the mkimage in [u-boot-dir]/tools directory.
---- Or get it from sudo apt-get install uboot-mkimage


3. Launch
sudo qemu-system-arm -nographic -m 256 -M versatileab -kernel u-boot.bin

The above command is good if your testing u-boot as a standalone app. However it would be wonderful to have networking between host and target to boot a linux kernel

sudo qemu-system-arm -M versatileab -kernel u-boot -net nic -net tap -nographic -serial stdio

Don't worry about the error message we will get to it.
===================================================
nemesis@nemesis-laptop:~/u-boot-2009.08$ sudo qemu-system-arm -nographic -m 256 -M versatileab -kernel u-boot.bin


U-Boot 2009.08 (Dec 13 2009 - 00:28:50)

DRAM: 0 kB
## Unknown FLASH on Bank 1 - Size = 0x00000000 = 0 MB
Flash: 0 kB
*** Warning - bad CRC, using default environment

In: serial
Out: serial
Err: serial

===================================================

Build linux kernel Image for U-boot



nemesis@nemesis-laptop:~/linux_kernel/linux-2.6.32$ make uImage
CHK include/linux/version.h
make[1]: `include/asm-arm/mach-types.h' is up to date.
CHK include/linux/utsrelease.h
SYMLINK include/asm -> include/asm-arm
CALL scripts/checksyscalls.sh
MKELF scripts/mod/elfconfig.h
HOSTCC scripts/mod/file2alias.o
HOSTCC scripts/mod/modpost.o
scripts/mod/modpost.c: In function ‘get_markers’:
scripts/mod/modpost.c:1562: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result
scripts/mod/modpost.c: In function ‘add_marker’:
scripts/mod/modpost.c:1982: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result
HOSTCC scripts/mod/sumversion.o
HOSTLD scripts/mod/modpost
CHK include/linux/compile.h
GEN lib/crc32table.h
CC lib/crc32.o
LD lib/built-in.o
LD vmlinux.o
MODPOST vmlinux.o
GEN .version
CHK include/linux/compile.h
UPD include/linux/compile.h
CC init/version.o
LD init/built-in.o
LD .tmp_vmlinux1
KSYM .tmp_kallsyms1.S
AS .tmp_kallsyms1.o
LD .tmp_vmlinux2
KSYM .tmp_kallsyms2.S
AS .tmp_kallsyms2.o
LD vmlinux
SYSMAP System.map
SYSMAP .tmp_System.map
OBJCOPY arch/arm/boot/Image
Kernel: arch/arm/boot/Image is ready
GZIP arch/arm/boot/compressed/piggy.gz
AS arch/arm/boot/compressed/piggy.o
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
UIMAGE arch/arm/boot/uImage
Image Name: Linux-2.6.32
Created: Sun Dec 13 02:29:45 2009
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1535396 Bytes = 1499.41 kB = 1.46 MB
Load Address: 00008000
Entry Point: 00008000
Image arch/arm/boot/uImage is ready



GET READY TO BOOT YOUR LINUX KERNEL
======================================

VersatilePB # setenv ipaddr 10.0.2.16
VersatilePB # setenv serverip 10.0.2.15
VersatilePB # ping 10.0.2.15
SMC91111: PHY auto-negotiate timed out
Using MAC Address 52:54:00:12:34:56
host 10.0.2.15 is alive
VersatilePB # tftp 8000 uImage
SMC91111: PHY auto-negotiate timed out
Using MAC Address 52:54:00:12:34:56
TFTP from server 10.0.2.15; our IP address is 10.0.2.16
Filename 'uImage'.
Load address: 0x8000
Loading: T T T T T T T #################################################################
###T #####################################
done
Bytes transferred = 1535460 (176de4 hex)


PROBLEM: There seems to be a bug in the sense that DRAM setting are not correct for versatile.

Switching to Integrator platform. [build uboot and linux image for integrator]
(uboot config =====> integratorcp_config)

nemesis@nemesis-laptop:~/u-boot-2009.08$ sudo qemu-system-arm -kernel u-boot -net nic -net tap -nographic -serial stdio
[sudo] password for nemesis:


U-Boot 2009.08 (Dec 13 2009 - 04:00:17)

DRAM: 128 MB
## Unknown FLASH on Bank 1 - Size = 0x00000000 = 0 MB
Flash: 0 kB
*** Warning - bad CRC, using default environment

In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
Integrator-CP # setenv serverip 10.0.2.15
Integrator-CP # setenv ipaddr 10.0.2.16
Integrator-CP # tftp 8000 uImage
SMC91111: PHY auto-negotiate timed out
Using MAC Address 52:54:00:12:34:56
TFTP from server 10.0.2.15; our IP address is 10.0.2.16
Filename 'uImage'.
Load address: 0x8000
Loading: T T #################################################################
################################
done
Bytes transferred = 1411276 (1588cc hex)
Integrator-CP # bootm
## Booting kernel from Legacy Image at 00008000 ...
Image Name: Linux-2.6.32
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1411212 Bytes = 1.3 MB
Load Address: 00008000
Entry Point: 00008000
XIP Kernel Image ... OK
OK

Starting kernel ...

qemu: fatal: Trying to execute code outside RAM or ROM at 0xfffff1c2

R00=00000000 R01=00000107 R02=00000100 R03=00000002
R04=00fddfc0 R05=00000000 R06=00008000 R07=00000113
R08=00fddfdc R09=010172c0 R10=010176ac R11=00fddced
R12=0100f750 R13=00000000 R14=00008008 R15=fffff1c2
PSR=600001db -ZC- A und32
Aborted
nemesis@nemesis-laptop:~/u-boot-2009.08$

============================================

So far so good...Uboot passes control to linux kernel but the kernel boot does a crash and burn. Will need to solve this one now....



Sunday, December 6, 2009

Busybox

1. Download the source and patches from the busybox website.

http://www.busybox.net/download.html

The version at the time of writing this is 1.14.1.

2. untar the sources to the directory where you will run the build.

3. patch the sources

patch -p0 <>.patch
e.g patch -p0 <>

4. config the busybox using your favourite config method. I prefer to use xconfig.

5. make your day :) -------- run make

6. once the make has run successful , you would want to install the busybox in a seperate directory which you can later ready to use as the rootfs.

make CONFIG_PREFIX=~/busybox/target install

where I am installing busybox in the /home/nemesis/busybox/target directory

7 cd to the install directory

cd ~/busybox/target

8.
There isn't a great deal there

ls -al would return

sbin, bin , usr and linuxrc (a symbolic link to /bin/busybox)



9. Create the dev, dev/pts, etc, etc/init.d, lib, mnt, opt, proc, root, sys, tmp, var, and var/log directories. Also create the device node for the initial console

mkdir dev etc lib mnt opt proc root sys tmp var debug
mkdir etc/init.d
mkdir var/log

sudo mknod dev/console c 5 1
sudo mknod dev/null c 1 3


10. Mount proc and /dev/pts at boot time
===========================

edit /etc/fstab for these filesystems



11. Shared library and library loader
==========================
We still need the
---------- shared libraries (from your toolchain)
---------- library loader (e.g ld-linux.so.3 in the listing below)


nemesis@nemesis-laptop:~/codesourcery/arm-2009q3/arm-none-linux-gnueabi/libc/lib$ ls
ld-2.10.1.so libdl-2.10.1.so libnss_dns.so.2 libresolv-2.10.1.so
ld-linux.so.3 libdl.so.2 libnss_files-2.10.1.so libresolv.so.2
libanl-2.10.1.so libgcc_s.so libnss_files.so.2 librt-2.10.1.so
libanl.so.1 libgcc_s.so.1 libnss_hesiod-2.10.1.so librt.so.1
libBrokenLocale-2.10.1.so libm-2.10.1.so libnss_hesiod.so.2 libSegFault.so
libBrokenLocale.so.1 libmemusage.so libnss_nis-2.10.1.so libthread_db-1.0.so
libc-2.10.1.so libm.so.6 libnss_nisplus-2.10.1.so libthread_db.so.1
libcidn-2.10.1.so libnsl-2.10.1.so libnss_nisplus.so.2 libutil-2.10.1.so
libcidn.so.1 libnsl.so.1 libnss_nis.so.2 libutil.so.1
libcrypt-2.10.1.so libnss_compat-2.10.1.so libpcprofile.so
libcrypt.so.1 libnss_compat.so.2 libpthread-2.10.1.so
libc.so.6 libnss_dns-2.10.1.so libpthread.so.0


--- that's an aweful lot. Copying them indiscriminately will cause our rootfs to be bloated (something we don't want). So just pick what you need. And And And ofcourse strip these libraries :)

nemesis@nemesis-laptop:~/busybox/target/lib$ ~/codesourcery/arm-2009q3/bin/arm-none-linux-gnueabi-strip *


Thats the minimal set for the rootfs


12. Kernel Modules
=================
Now it is time to get our dear modules.

--- go to the kernel build directory
--- issue the following command : make modules

after it has completed successfully , we need to install the modules in our rootfs. Elementary my dear watson!

make INSTALL_MOD_PATH=/path/to/rootfs modules_install

Once we are out of the debugging phase, we would like to strip the modules to slim down.

cd /path/to/rootfs/lib/modules
arm-none-linux-gnueabi-strip `find . –name “*.ko”`




Root File System

Umpteen ways to get this done :-

1. NFS Mounted. [One of the most popular methods ]

2. Initial RAMDISK (Initrd) ====> Will cover this in more detail in a later post

3. JFFS/JFFS2

4. CRAMFS (Read-only)

We will use busybox -- the veritable "Swiss Army Knife" for embedded systems.


Each of these will be explained in seperate posts, starting with Busybox