Running a C program on mini2440

Am creating a simple Hello World program in C.This is the program

#include<stdio.h>
int main(){
 printf("Hello World\n");
}

saved it as hello.c..Now compiling it for our target or mini2440.

open terminal and change directory to the folder where c program is presnt and issue this command

arm-linux-gcc hello.c -o hello

The arm-linux-gcc command was present bcoz we setup the toolchain early.Now a binary hello will be present in the folder.use file command to know the type of the binary it will suitable for ARM.

Move the bianry to mini2440 using pendrive or sdcard.To see the output execute the binary like this..

./hello
Advertisements

Setting up cross compilation toolchain to compile kernel and vivi for mini 2440

To compile kernel and vivi for our target device (mini2440) we need to  set up a cross compilation environment on our host system.The trick is that we generate binaries for the target(mini2440) on our host system.

So frst we need some packages installed in our system they are

sudo apt-get install build-essential make ncurses gcc g++ libncurses5 libncueses5-dev

After that we need to download some packages

ARM Linux gcc   –  http://www.friendlyarm.net/dl.php?file=arm-linux-gcc-4.3.2.tgz

Cross compiler toolchain   –  http://ftp.arm.linux.org.uk/pub/armlinux/toolchain/cross-2.95.3.tar.bz2

Linux kernel source   –  http://www.friendlyarm.net/dl.php?file=linux-2.6.32.2-mini2440_20110413.tgz

Vivi source  –  http://www.friendlyarm.net/dl.php?file=bootloader_20090728.zip

Now setup cross compiler toolchain and Arm gcc on our system

Configuring cross compiler

tar -xvf cross-2.95.3.tar.bz2
sudo mkdir -p /usr/local/arm
sudo mv 2.95.3/ -v /usr/local/arm/
ls /usr/local/arm/
export PATH=/usr/local/arm/2.95.3/bin:$PATH
echo $PATH

Configuring Arm gcc

tar -xvf arm-linux-gcc-4.3.2.tgz
sudo mv ./usr/local/arm/ /usr/local/arm/
sudo mv /usr/local/arm/arm/4.3.2/ /usr/local/arm/
export PATH=/usr/local/arm/4.3.2/bin:$PATH
echo $PATH

On doing echo $PATH we can see if path variable is set or not

Now compile vivi to generate binary

extract vivi
cd bootloader_20090728/vivi/
cp smdk2440 ./.config
make menuconfig

You may get a error like this

error-Preparing scripts: functionsYour lxdialog utility does not exist

To fix this error we need to give permission to lxdialog

cd scripts/lxdialog/
sudo chmod +x lxdialog
make menuconfig
Load an Alternate config file
make vivi
sudo ../../usbpush/usbpush/usbpush ./vivi

The vivi binary will be generated now on the folder ,Now using usb push utility we can push it to mini2440

Next compiling Linux kernel

cd linux-2.6.32.2/
cp config_mini2440_n35 ./.config
cat .config |grep CPU_S3C2440

Check whether the out put is Y

make menuconfig

An error may occur like this

error –include/linux/compiler-gcc.h:86: linux/compiler-gcc2.h: No such file or directory

make mrproper
make menuconfig

check - system type-->sc32440 machines-->Friendlyarm mini2440 dev board
make
make zImage

make mrproper will eliminate that error and will build necessary dependencies.If everything goes correct you will get an output like this

The zImage is available in this path arch/arm/boot/zImage

Using usbpush push it to mini2440

sudo ../usbpush/usbpush/usbpush arch/arm/boot/zImage

setting up supervivi,kernel & qtopia in mini2440

Download supervivi,zImage,usbpush and qtopia image from

http://www.friendlyarm.net/downloads

These are the files i used

supervivi – http://www.friendlyarm.net/dl.php?file=supervivi_20100818.zip

zImage – http://www.friendlyarm.net/dl.php?file=linux-zImage_20110421.zip

usbpush – http://www.friendlyarm.net/dl.php?file=usbpush.zip

qtopia – http://www.friendlyarm.net/dl.php?file=linux-root_qtopia_qt4_20110305.zip

Extract the usbpush this utility helps us to push the image files from our system to mini2440 target.When we extract we can see one more usbpush folder inside that folder there will be a usbpush binary give executable permission to that binary

sudo chmod +x usbpush/usbpush/usbpush

Get the bootloader using command

sudo minicom

select ” x “  and format the NAND flash

Now the next step is to load supervivi to target board using usbpush.supervivi is the bootloader.

First select ” V

Only after this you should push file from the host system.Push the file like this

sudo ./usbpush/usbpush/usbpush supervivi_20100818/supervivi-128M

If the push is sucessful then the minicom promt will be like this and will be back to the bootloader

and the usbpush prompt will be like this

So vivi is sucessfully installed.Next is zImage, Kernel images generated by the kernel build process are either uncompressed “Image” files or compressed zImage files.here we selects zImage N35 bcoz  MINI2440 with 3.5″ NEC display.

Now we selects ” K ” option to download linux kernel and pushes the extracted zImage

sudo ./usbpush/usbpush/usbpush  linux-zImage_20110421/zImage_N35

After this step you may encounter with this error

Enter your selection: k
USB host is connected. Waiting a download.
Length of file is too big : 2517028 > 2097152
Failed downloading file

If you encounter with this error then you can solve this error like this.First go to the shell of vivi by selecting ” q

Then from supervivi promt type this

Supervivi>part del kernel
Supervivi>part del root
Supervivi>part add kernel 0x00060000 0x00500000 0
Supervivi>part add root 0x00560000 0x40000000 0
Supervivi>part save
Supervivi> part show

Now to get back to our previous menu type menu

Supervivi> menu

Now retry to download zImage with previous steps

Now we need to Download the root yaffs image.YAFFS (Yet Another Flash File System) is now in its second generation and provides a fast robust file system for NAND and NOR Flash. It is widely used with Linux and RTOSs, in consumer devices. It is dual licenced under commercial/GPL terms.

Select ” Y ” to download yaffs image and push the qtopia image file

It will take some time…

Now that we have completed all the steps select “ b ”  to boot the system

Here also you will get an error like this

“error – Kernel panic – not syncing: No init found.  Try passing init= option to kernel” –> this will be the error

To fix this error got to supervivi promt and type this

param set linux_cmd_line "noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0"

After this select boot.Then the board will boot and we will get prompt of friendlyarm

Now calibrate the screen by clicking on the crosshairs shown and you will be taken to qtopia screen by default qtopia will be in chineese in second tab there is a flag symbol select that it chnages the language select english and we are done

Happy Hacking 🙂

Settingup and configuring mini2440 Friendlyarm on ubuntu10.04

The friendlyarm kit am having is mini2440 http://www.friendlyarm.net/products/mini2440

The software and other packages necessary can be downloaded from the official site

http://www.friendlyarm.net/

The first software we need on our ubuntu system in minicom.Minicom is just like hyperterminal.Install minicom first

sudo apt-get install minicom

Now connect mini2440 to our system two connection one from the serial port and next from the Type B USB plug must be made to the system.On the friendly arm board the NAND/NOR switch must be placed in the NOR position

Now invoke minicom from terminal using command

sudo minicom

usually you will get something like this on your terminal

The problem is you need to configure minicom the port etc use the command dmesg this command lists several other messages also so you have to closely observe to which port the board is connected.Here am using serial to usb converter so the port deteced for mine is ttyUSB5 if you connected it to serial port itself it will be different

kill minicom using the command

sudo pkill minicom

then invoke minicom using

sudo minicom -s

It will give a screen like this

select serial port setup and hit enter

there change serial device to the port detected in my case it will be /dev/ttyUSB5 we can edit that by selecting A option.Also double check that both software and hardware flow control must be in NO

Then select save set up as dfl

After that exit from minicom and try our first command

sudo minicom

If everything went correct then you will get a bootloader like this .This is the preinstalled vivi bootloader on memory

Happy Hacking 🙂