TFTP Boot using u-boot

Posted in Arm stuffs, Unix/Linux with tags , , , , , , , , , , , on January 16, 2013 by UnixmanLinuxboy

I was fiddling around with my newly purchased Beaglebone and wanted to get my hands dirty with kernel hacking and stuff. Since beaglebone is hard-wired to boot off an SD card I found it tedious to shuttle the card between my development laptop and the board.
Enter TFTP boot.
This is a very handy way of booting when you need to recompile your kernel repeatedly and inserting/removing the card from/to board becomes a tedious process. For those who wanted to try out this fantastic way of booting, here is my short howto:

Before I begin, here is snapshot of my development platform:
Host machine: am64 lubuntu 12.10
Tftp software: tftp-hpa 5.2 [client and server]
U-boot: 2013.01-dirty

To install, run: sudo apt-get install tftpd-hpa tftp-hpa

Before we begin, we need to configure the tftpd’s configuration file so edit:

sudo vim /etc/default/tftpd-hpa

After that restart the daemon: sudo service tftpd restart
Now that the server has been setup in our host machine, we may now concentrate on the target system.
Note: The SD card containing MLO and u-boot should always be present in the beaglebone’s slot.
Power up the board and and get to the u-boot prompt:

U-Boot 2013.01-dirty (Jan 16 2013 - 15:36:41)
I2C: ready
DRAM: 256 MiB
WARNING: Caches not enabled
NAND: No NAND device found!!!
0 MiB
*** Warning - readenv() failed, using default environment

musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, bulk combine, bulk split, HB-ISO Rx, HB-ISO Tx, SoftConn)
musb-hdrc: MHDRC RTL version 2.0
musb-hdrc: setup fifo_mode 4
musb-hdrc: 28/31 max ep, 16384/16384 memory
USB Peripheral mode controller at 47401000 using PIO, IRQ 0
musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, bulk combine, bulk split, HB-ISO Rx, HB-ISO Tx, SoftConn)
musb-hdrc: MHDRC RTL version 2.0
musb-hdrc: setup fifo_mode 4
musb-hdrc: 28/31 max ep, 16384/16384 memory
USB Host mode controller at 47401800 using PIO, IRQ 0
Net: cpsw, usb_ether
Hit any key to stop autoboot: 0

Make sure that ethernet cable is plugged into the board and a dhcp server is running in either your host machine or your router.

U-Boot# setenv autoload no
U-Boot# dhcp
link up on port 0, speed 100, full duplex
BOOTP broadcast 1
DHCP client bound to address

Next will be configuring the server-ip [our host machine’s IP], kernel’s command line and the load address

U-Boot# setenv serverip
U-Boot# setenv bootfile uImage
U-Boot# setenv bootargs console=ttyO0,115200 root=/dev/mmcblk0p2 rw rootwait ip=dhcp
U-Boot# tftp 0x80200000 uImage
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server; our IP address is
Filename 'uImage'.
Load address: 0x80200000
Loading: #################################################################
#####################################################T ############
##########################################T #######################
###################################T ########
146.5 KiB/s
Bytes transferred = 3484264 (352a68 hex)
U-Boot# bootm 0x80200000
## Booting kernel from Legacy Image at 80200000 ...
Image Name: Angstrom/3.2.28/beaglebone
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 3484200 Bytes = 3.3 MiB
Load Address: 80008000
Entry Point: 80008000
Verifying Checksum ... OK
Loading Kernel Image ... OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Linux version 3.2.28 (koen@Angstrom-F16-vm-rpm) (gcc version 4.5.4 20120305 (prerelease) (GCC) ) #1 Tue Sep 11 13:08:30 CEST 2012
[ 0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=50c53c7d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] Machine: am335xevm

And voila! It boots!!!!


Problem running U-Boot on QEMU for versatilepb (ARM729EJ-S) ?

Posted in Arm stuffs with tags , , , , , , , , on June 18, 2012 by UnixmanLinuxboy

Qemu is a good emulator to try out and understand system programming without a real hardware.
Versatilepb (arm926ej-s) is supported quite well by Qemu and this article describes to overcome a nasty U-Boot error which I encountered when compiling u-boot for versatilepb.

U-boot version used: u-boot-2012.04.tar.bz2

Compiled using:

make versatilepb_config ARCH=arm CROSS_COMPILE=arm-none-eabi-
make all ARM=arm CROSS_COMPILE=arm-none-eabi-

Running u-boot with QEMU:
qemu-system-arm -M versatilepb -m 128M -nographic -kernel ./u-boot.bin

And I am greeted with this:

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

R00=fffcbf64 R01=ffff0000 R02=00000000 R03=0101c08c
R04=ffff0000 R05=fffcbf64 R06=ffff0000 R07=00000000
R08=008fff78 R09=feff0000 R10=0101c08c R11=00000000
R12=fffcbfdc R13=fffcbf58 R14=ffff07bc R15=ffff07bc
PSR=600001d3 -ZC- A svc32


U-Boot 2012.04 (Jun 18 2012 - 17:54:11)

DRAM: 128 MiB
WARNING: Caches not enabled
Flash: ## Unknown flash on Bank 1 - Size = 0x00000000 = 0 MB
*** failed ***
### ERROR ### Please RESET the board ###
QEMU: Terminated

How to avoid this nasty error you ask?

Answer: Patch include/configs/versatile.h
Add this line


just below

#ifndef __CONFIG_H
#define __CONFIG_H

Recompile and voila!!

Here is the output

U-Boot 2012.04 (Jun 18 2012 - 18:14:08)

DRAM: 128 MiB
WARNING: Caches not enabled
Using default environment

In: serial
Out: serial
Err: serial
Net: SMC91111-0
VersatilePB # help
? - alias for 'help'
base - print or set address offset
bdinfo - print Board Info structure
bootm - boot application image from memory
bootp - boot image via network using BOOTP/TFTP protocol
cmp - memory compare
cp - memory copy
crc32 - checksum calculation
dhcp - boot image via network using DHCP/TFTP protocol
env - environment handling commands
erase - erase FLASH memory
flinfo - print FLASH memory information
go - start application at address 'addr'
help - print command description/usage
iminfo - print header information for application image
loop - infinite loop on address range
md - memory display
mm - memory modify (auto-incrementing address)
mtest - simple RAM read/write test
mw - memory write (fill)
nm - memory modify (constant address)
ping - send ICMP ECHO_REQUEST to network host
printenv- print environment variables
protect - enable or disable FLASH write protection
reset - Perform RESET of the CPU
setenv - set environment variables
tftpboot- boot image via network using TFTP protocol
version - print monitor, compiler and linker version
VersatilePB #

A simple “bare-metal” program (ARM)

Posted in Arm stuffs with tags , , , , , , , , , , , , , , on June 16, 2012 by UnixmanLinuxboy

Caution: Here be dragons!
For those who feel like writing C code with nice and fancy algorithm, this is not for you. This is for them who wants to dig deeper at the core to see how things run and work.
A “bare-metal” program is simplest of all which does not need special services from underlying OS. It is capable enough to run on its own.

Without much ado, lets get it on, shall we?

This tutorial can be used on both real hardware and an emulator. I have used QEMU for this purpose.

Architecture to emulate: ARM926EJ-S
This is well supported by QEMU and has four UART
serial ports. The first serial port (UART0) works
as a terminal when we will use '-nographic' or
'-serial stdio' option in QMEU

Goal: This program will run inside QEMU emulator and will pass few characters to the UART0 which will, then be redirected by QEMU to the standard console.
Note: On real board (ARM926EJ-S) you have to connect to serial port (Minicom).

QEMU, ARM toolchain, little patience and willingness to learn.

Install QEMU on ubuntu:
sudo apt-get install qemu qemu-kvm-extras

Get ARM toolchain from:
ARM toolchain download link

Note: Do not download the installer (it sucks!)
Instead, get the .tar.gz archieve and unpack it your working directory
and set your PATH accordingly.
If you’re using login shell, modify the .bash_profile,
else modify .bashrc.

No interrupt handling and other fancy stuffs.

The code is well-explained and do contact me if you need more information.

The command to run the final binary in QEMU is:
qemu-system-arm -M versatilepb -m 128M -nographic -kernel output.bin

"-M versatilepb" specifies the machine type: Here we are using ARM9 versatile board.
"-nographic" mode tells to redirect UART0 messages to console.

Note: Without the option "-m 128M" QEMU crashes badly. A bug has been already filed regarding this.

Here we go!!!

File: simple-startup.s

/* ===========================================
Start up routines for bare-metal program

.global _Reset
B Reset_Handler /* Reset handler */
B Undefined /* Undefined mode handler */
B SWI /* Software interrupt */
B Prfetch_Abort /* Prefetch abort handler */
B Data_Abort /* Data abort handler */
B IRQ_Handler /* IRQ handler */
B FIQ_Handler /* FIQ handler */

LDR sp, =stack_top /*set up env for C function */
BL simple_init
B .
Undefined: /* do nothing */
B .
SWI: /* do nothing */
B .
Prfetch_Abort: /* do nothing */
B .
Data_Abort: /* do nothing */
B .
IRQ_Handler: /* do nothing */
B .
FIQ_Handler: /* do nothing */
B .

File: simple-init.c

/* Simple Bare metal program init */

/* Note: QEMU model of PL011 serial port ignores the transmit
FIFO capabilities. When writing on a real SOC, the
"Transmit FIFO Full" flag must be checked in UARTFR register
before writing on the UART register*/

volatile unsigned int* const UART0 = (unsigned int*)0x0101F1000;

static void uart_print(const char *s)
while(*s != '') {
*UART0 = (unsigned int)(*s); /* send to UART */

/* Main entry point */
void simple_init()
uart_print("Welcome to Simple bare-metal program\n");
uart_print("If you're running in QEMU, press Ctrl+a\n");
uart_print("and then x to stop me...\n");

File: simple-linker.ld

/* Simple Bare metal program - linker script
* Note: This is written for QEMU
* QEMU loads the kernel address at 0x00010000
* The emulator starts at 0x00000000 and peripheral interrupts
* are disabled at startup.
* The code must be compiled and linked to be placed at
* 0x00010000
* IRQ handling can be ignored.

. = 0x10000;
.startup . : { simple-startup.o(.text) }
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss) }
. = . + 0x1000; /* move by 4kbyte (our stack memory) */
stack_top = .;

Build commands:

arm-none-eabi-as -mcpu=arm926ej-s -g simple-startup.s -o simple-startup.o
arm-none-eabi-gcc -c -mcpu=arm926ej-s -g simple-init.c -o simple-init.o
arm-none-eabi-ld -T simple-linker.ld simple-init.o simple-startup.o -o output.elf
arm-none-eabi-objcopy -O binary output.elf output.bin

And here is the output:

sarbojit@Phrozen:~/timepass/assembly-fun$ qemu-system-arm -M versatilepb -m 128M -nographic -kernel output.bin
Welcome to Simple bare-metal program
If you’re running in QEMU, press Ctrl+a
and then x to stop me…
QEMU: Terminated

Inspired by:

A RALink (rt2x00 / rt2800pci) Wifi chipset and does not seem to work? Read on

Posted in Unix/Linux with tags , , , , , , , , , on June 10, 2012 by UnixmanLinuxboy

There can a lot of reason why the wi-fi card don’t seem to work.

In my Lubuntu 12.04 (kernel 3.2.0-24-generic-pae) it never worked with Network Manager. I chucked nm and installed wicd, after some time, it too, refused to connect me to encrypted network.

So I fired up good ol’ (# cat /proc/kmsg) and lo! What do I see ?

phy0 -> rt2x00queue_write_tx_frame: Error – Dropping frame due to full tx queue 0.
phy0 -> rt2x00queue_write_tx_frame: Error – Dropping frame due to full tx queue 0.
phy0 -> rt2x00queue_write_tx_frame: Error – Dropping frame due to full tx queue 1.
phy0 -> rt2x00queue_write_tx_frame: Error – Dropping frame due to full tx queue 1.
phy0 -> rt2x00queue_write_tx_frame: Error – Dropping frame due to full tx queue 1.
phy0 -> rt2x00queue_write_tx_frame: Error – Dropping frame due to full tx queue 1.
phy0 -> rt2x00queue_write_tx_frame: Error – Dropping frame due to full tx queue 1.
phy0 -> rt2x00queue_write_tx_frame: Error – Dropping frame due to full tx queue 1.

Dear friend, if you face similar logs in your kernel, it is time we get into some bug-banging 😉

Let check against the daily builds of compat-wireless drivers. You can get ’em here 

As of today it is compat-wireless-2012-05-10.tar.bz2 updated 2012-Jun-09 22:38:35

Download this in your box and run the following:

./scripts/driver-select rt2x00
sudo make install


— Now you can reboot your box, or unload your modules and modprobe them.
sudo make unload
sudo modprobe -v rt2800pci


Official instructions are here:


Android repo sync error??

Posted in Android with tags , , , , , on March 21, 2011 by UnixmanLinuxboy

Today I tried re-syncing my gingerbread code to the latest version
so I fired

$ repo sync

And lo! I got the error message:

error: .repo/manifests/: contains uncommitted changes

After a bit of googling and going through the mailing lists, I finally found the solution:

1. Go to ./repo/manifests
2. $ git reset –hard
3. $ repo sync

[Please note that there are two dashes “- -” before ‘hard’]
And I am back in business.

Android Kernel module support. Running a simple hello-world kernel module in Android emulator

Posted in Android with tags , , , , on March 21, 2011 by UnixmanLinuxboy

I was playing with android code and suddenly I thought lets have a small exercise of learning android kernel compilation and loading modules in it.
The following are the steps which I did in order to recompile android kernel for my emulator, write a simple hello world module, compile it, push it to emulator and load it.

Read for some fun? Read on.

Download and compile GingerBread code

Go to and download the source code.
I downloaded the gingerbread branch
repo init -u git:// -b gingerbread
repo sync
and the usual commands to get your platform code…

Note: These days the android kernel source is removed from platform code.
So I need to download the kernel source too.
I went to;a=shortlog;h=refs/heads/android-goldfish-2.6.29 and downloaded the kernel for emulator.

Now, I compiled the platform code. (source /build/ && lunch 1 && make -j2)
Once the platform is built, I started building the linux kernel.

Compile Android kernel with module support

Android kernel, by default do not support loadable modules. So I needed to edit some files.
Here is what I did:

1. make ARCH=arm goldfish_defconfig (This will create our .config)
2. Edit the .config file and searched for the line “CONFIG_MODULES”
It was unset for me and the line looked liked this
# CONFIG_MODULES is not set
I changed the line to CONFIG_MODULES=y, saved and closed the file.
3. Now, I fired the command to build the kernel
make ARCH=arm CROSS_COMPILE=~/timepass/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-

Important: Replace “~/timepass/mydroid” with your KERNEL SOURCE TREE
Note: This command might ask for the following

scripts/kconfig/conf -s arch/arm/Kconfig
* Restart config...
* General setup
Prompt for development and/or incomplete code/drivers (EXPERIMENTAL) [Y/n/?] y
Local version - append to kernel release (LOCALVERSION) []
Automatically append version information to the version string (LOCALVERSION_AUTO) [Y/n/?] y
Support for paging of anonymous memory (swap) (SWAP) [Y/n/?] y
System V IPC (SYSVIPC) [Y/n/?] y
POSIX Message Queues (POSIX_MQUEUE) [N/y/?] n
BSD Process Accounting (BSD_PROCESS_ACCT) [N/y/?] n
Export task/process statistics through netlink (EXPERIMENTAL) (TASKSTATS) [N/y/?] n
Auditing support (AUDIT) [N/y/?] n
Kernel .config support (IKCONFIG) [Y/n/m/?] y
Enable access to .config through /proc/config.gz (IKCONFIG_PROC) [Y/n/?] y
Kernel log buffer size (16 => 64KB, 17 => 128KB) (LOG_BUF_SHIFT) [16] 16
Group CPU scheduler (GROUP_SCHED) [Y/n/?] y
Group scheduling for SCHED_OTHER (FAIR_GROUP_SCHED) [Y/n] y
Group scheduling for SCHED_RR/FIFO (RT_GROUP_SCHED) [Y/n/?] y
Basis for grouping tasks
1. user id (USER_SCHED)
> 2. Control groups (CGROUP_SCHED)
choice[1-2]: 2
Create deprecated sysfs layout for older userspace tools (SYSFS_DEPRECATED_V2) [N/y/?] n
Kernel->user space relay support (formerly relayfs) (RELAY) [N/y/?] n
Namespaces support (NAMESPACES) [Y/?] y
UTS namespace (UTS_NS) [N/y/?] n
IPC namespace (IPC_NS) [N/y/?] n
User namespace (EXPERIMENTAL) (USER_NS) [N/y/?] n
PID Namespaces (EXPERIMENTAL) (PID_NS) [N/y/?] n
Network namespace (NET_NS) [N/y/?] n
Initial RAM filesystem and RAM disk (initramfs/initrd) support (BLK_DEV_INITRD) [Y/n/?] y
Initramfs source file(s) (INITRAMFS_SOURCE) []
Optimize for size (CC_OPTIMIZE_FOR_SIZE) [Y/n/?] y
Default panic timeout (PANIC_TIMEOUT) [0] 0
Enable the Anonymous Shared Memory Subsystem (ASHMEM) [Y/n/?] y
Disable heap randomization (COMPAT_BRK) [Y/n/?] y
Choose SLAB allocator
> 1. SLAB (SLAB)
2. SLUB (Unqueued Allocator) (SLUB)
choice[1-2?]: 1
Profiling support (EXPERIMENTAL) (PROFILING) [N/y/?] n
Kprobes (KPROBES) [N/y/?] (NEW) ---------- I said N here
* Enable loadable module support
Enable loadable module support (MODULES) [Y/n/?] y
Forced module loading (MODULE_FORCE_LOAD) [N/y/?] (NEW) y
Forced module unloading (MODULE_FORCE_UNLOAD) [N/y/?] (NEW) y
Module versioning support (MODVERSIONS) [N/y/?] (NEW) y
Source checksum for all modules (MODULE_SRCVERSION_ALL) [N/y/?] (NEW) y
* Memory Technology Device (MTD) support
Memory Technology Device (MTD) support (MTD) [Y/n/m/?] y
Debugging (MTD_DEBUG) [N/y/?] n
MTD concatenating support (MTD_CONCAT) [N/m/y/?] n
MTD partitioning support (MTD_PARTITIONS) [N/y/?] n
MTD tests support (MTD_TESTS) [N/m/?] (NEW) n
* User Modules And Translation Layers
Direct char device access to MTD devices (MTD_CHAR) [Y/n/m/?] y
Common interface to block layer for MTD 'translation layers' (MTD_BLKDEVS) [Y] y
Caching block device access to MTD devices (MTD_BLOCK) [Y/n/m/?] y
FTL (Flash Translation Layer) support (FTL) [N/m/y/?] n
NFTL (NAND Flash Translation Layer) support (NFTL) [N/m/y/?] n
INFTL (Inverse NAND Flash Translation Layer) support (INFTL) [N/m/y/?] n
Resident Flash Disk (Flash Translation Layer) support (RFD_FTL) [N/m/y/?] n
NAND SSFDC (SmartMedia) read only translation layer (SSFDC) [N/m/y/?] n
Log panic/oops to an MTD buffer (MTD_OOPS) [N/m/y/?] n
* Meilhaus support
Meilhaus support (MEILHAUS) [N/m/?] (NEW) n
* Staging drivers
Staging drivers (STAGING) [Y/n/?] y
Exclude Staging drivers from being built (STAGING_EXCLUDE_BUILD) [N/y/?] n
Line Echo Canceller support (ECHO) [N/m/y/?] n
Data Acquision support (comedi) (COMEDI) [N/m/?] (NEW) n
* Cryptographic API
Cryptographic API (CRYPTO) [Y/?] y
* Crypto core or helper
FIPS 200 compliance (CRYPTO_FIPS) [N/y/?] n
Cryptographic algorithm manager (CRYPTO_MANAGER) [Y/?] y
GF(2^128) multiplication functions (EXPERIMENTAL) (CRYPTO_GF128MUL) [N/m/y/?] n
Null algorithms (CRYPTO_NULL) [N/m/y/?] n
Software async crypto daemon (CRYPTO_CRYPTD) [N/m/y/?] n
Authenc support (CRYPTO_AUTHENC) [Y/?] y
Testing module (CRYPTO_TEST) [N/m/?] (NEW) n
* Authenticated Encryption with Associated Data
CCM support (CRYPTO_CCM) [N/m/y/?] n
GCM/GMAC support (CRYPTO_GCM) [N/m/y/?] n
Sequence Number IV Generator (CRYPTO_SEQIV) [N/m/y/?] n

Once I answered, the compilation continued and now I had a zImage of kernel with loadble module support.

Write and compile a simple hello-world module

At this point I have kernel with module support and compiled platform. So without much ado I fired up the emulator.

export ANDROID_PRODUCT_OUT=~/mydroid/out/
$ ./emulator -system ~/mydroid/out/target/product/generic/system.img -kernel ~/goldfish_kernel/arch/arm/boot/zImage -data ~/mydroid/out/target/product/generic/userdata.img -ramdisk ~/mydroid/out/target/product/generic/ramdisk.img -skindir ~/mydroid/sdk/emulator/skins/ -skin HVGA -verbose -show-kernel

Once emulator is up, I wrote the simple “Hello-world” module: Source is as follows:

1 #include"linux/module.h"
2 #include"linux/kernel.h"
3//replace the "" with angular brackets
4 int init_module(void)
5 {
6 printk(KERN_INFO "Hello android kernel...\n");
7 return 0;
8 }
10 void cleanup_module(void)
11 {
12 printk(KERN_INFO "Goodbye android kernel...\n");
13 }

I saved the file as android_module.c

Kernel modules as we know have to be compiled slightly differently than traditional programs.
My makefile for this simple module is as follows:

1 obj-m += android_module.o
3 all:
4 make -C /home/user/android_goldfish_kernel/goldfish-2.6.29/ M=$(PWD) modules
6 clean:
8 make -C /home/user/android_goldfish_kernel/goldfish-2.6.29/ M=$(PWD) clean

Now we are ready to compile our android kernel module

CROSS_COMPILE=/home/user/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- ARCH=arm make

Once compilation is done, I got android_module.ko

Push the module inside emulator and execute it

I pushed the newly build module inside emulator by:

adb push android_module.ko /data/local

Now that my module is inside the emulator which was already running kernel with module support, I opened a shell by:

adb shell

Inside this emulator shell prompt, I navigated to /data/local and executed
insmod android_module.ko
rmmod android_module

The result is

android_module: module license 'unspecified' taints kernel.
Hello android kernel...
Goodbye android kernel...

If you have any doubt, please feel free to drop a comment here 🙂


Posted in Unix/Linux on March 19, 2011 by UnixmanLinuxboy

ClipGrab is a free GPL’ed software for downloading online videos.
With ClipGrab you can download online clips from many sites with just some clicks and then automatically convert them into “usable” files. This way, you can watch your favourite clips again and again wherever and whenever you like. And since ClipGrab can also save your videos as audio files, you can also put them on your mp3 player if you like.

Which sites are supported by ClipGrab?

At the moment, the following sites are officially supported:

* YouTube
* Clipfish
* Collegehumor
* Dailymotion
* MyVideo
* MySpass
* Sevenload
* Tudou
* Vimeo

Which formats are supported by ClipGrab?

At the moment, ClipGrab supports these formats:

* MPEG4 (video)
* WMV (video)
* OGG Theora (video)
* MP3 (audio only)
* OGG Vorbis (audio only)

Install clipgrab in ubuntu 10.10/10.04/9.10

Open the terminal and run the following commands

sudo add-apt-repository ppa:clipgrab-team/ppa

sudo apt-get update

sudo apt-get install clipgrab