You are on page 1of 146

High Performance Low Cost Embedded Systems

Linux Development for MINI2440


20090601

copyright@2007-2009

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. --1-Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

COPYRIGHT STATEMENT
The Chinese version of this manual is copyright Friendly ARM. Acknowledgement is made to Friendly ARM for permission to translate and use the Chinese manuals content (content being images, text, programs and scripts). The content (content being images, text, programs and scripts) of this English manual is copyright Micro Arm Systems, Inc. All rights expressly reserved. Any content of the manual printed or downloaded may not be sold, licensed, transferred, copied or reproduced in whole or in part in any manner or in or on any media to any person without the prior written consent of Micro Arm Systems, Inc. including but not limited to: transmission by any method storage in any medium, system or program display in any form performance hire, lease, rental or loan Requests for permission to reproduce material from this manual should be addressed to Micro Arm Systems, Inc.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. --2-Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Table of Contents
Chapter 1 Introduction...........................................................................................................................................- 5 1.1 About this Document ...............................................................................................................................- 5 Chapter 2 Getting Started with Linux....................................................................................................................- 6 2.1 Booting Sequence ....................................................................................................................................- 6 2.2 Powering Up ............................................................................................................................................- 6 Chapter 3 Setting up Linux Development Environment........................................................................................- 7 3.1 Installing Fedora 9.0 ................................................................................................................................- 7 3.2 Setting up Cross Compile Environment ................................................................................................- 33 Chapter 4 Linux Development.............................................................................................................................- 37 4.1 Hello World............................................................................................................................................- 37 4.1.1 Source Code of Hello World ...................................................................................................- 37 4.1.2 Compiling Hello World ...........................................................................................................- 37 4.1.3 Downloading to and Running Hello World on MINI2440......................................................- 38 4.2 Application Development ......................................................................................................................- 40 4.2.1 Test Program of LED ..................................................................................................................- 40 4.2.2 Test Program of Keyboard ..........................................................................................................- 41 4.2.3 UDP Applications .......................................................................................................................- 43 4.2.4 Using Math Libraries..................................................................................................................- 49 4.2.5 Thread Programming ..................................................................................................................- 50 4.2.6 PIPE Applications.......................................................................................................................- 52 4.2.7 Hello, World in C++................................................................................................................- 56 4.3 Drivers Development.............................................................................................................................- 58 4.3.1 Hello Module ..........................................................................................................................- 58 4.3.2 LED Driver .................................................................................................................................- 63 4.3.3 Keyboard Driver .........................................................................................................................- 67 Chapter 5 Configuring and Compiling a Bootloader...........................................................................................- 72 5.1 Configuring and Compiling VIVI..........................................................................................................- 73 5.2 Configuring and Compiling U-Boot ......................................................................................................- 75 5.2.1 Configuring and Compiling U-Boot ...........................................................................................- 75 5.2.2 Downloading U-Boot to Board...................................................................................................- 76 Chapter 6 Configuring and Compiling a Linux Kernel .......................................................................................- 79 6.1 Configuring and Compiling a Kernel with Default Options..................................................................- 79 6.2 Drivers Source Code..............................................................................................................................- 81 6.3 Customizing Linux Kernel ....................................................................................................................- 82 6.3.1 Configuring CPU ........................................................................................................................- 83 6.3.2 Configuring LCD........................................................................................................................- 85 6.3.3 Configuring Touch Screen ..........................................................................................................- 88 6.3.4 Configuring USB Mouse and Keyboard.....................................................................................- 90 6.3.5 Configuring USB Storage Drive.................................................................................................- 91 6.3.6 Configuring USB Camera...........................................................................................................- 93 Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. --3-Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems


6.3.7 Configuring CMOS Camera .......................................................................................................- 96 6.3.8 Configuring Network Card .........................................................................................................- 98 6.3.9 Configuring Wireless Network Card ........................................................................................- 102 6.3.10 Configuring Sound Card Driver .............................................................................................- 109 6.3.11 Configuring SD/MMC Card Driver........................................................................................- 112 6.3.12 Configuring Watchdog Driver ................................................................................................- 113 6.3.13 Configuring LED Driver.........................................................................................................- 115 6.3.14 Configuring Keyboard Driver.................................................................................................- 115 6.3.15 Configuring PWM Buzzer Driver...........................................................................................- 116 6.3.16 Configuring ADC Driver ........................................................................................................- 117 6.3.17 Configuring Serial Port Driver ...............................................................................................- 118 6.3.18 Configuring RTC Driver.........................................................................................................- 120 6.3.19 Configuring I2C-EEPROM Driver .........................................................................................- 122 6.3.20 Configuring Support for YAFFS2...........................................................................................- 124 6.3.21 Configuring Support for EXT2/VFAT/NFS............................................................................- 129 6.3.22 Making Linux Logo ................................................................................................................- 131 Chapter 7 Building a File System......................................................................................................................- 137 7.1 Building YAFFS2 Root File System....................................................................................................- 137 Chapter 8 Embedded QT Development.............................................................................................................- 138 8.1 Compiling X86 Based Qtopia, Hello, World and Embedded Browser ............................................- 138 8.1.1 Compiling Qt/Embedded ..........................................................................................................- 138 8.1.2 Running Qtopia on a Simulation Platform in PC......................................................................- 138 8.1.3 Compiling Hello, World ........................................................................................................- 139 8.1.4 Running Hello, World ...........................................................................................................- 140 8.2 Compiling ARM Based Qtopia, Hello, World and Embedded Browser ..........................................- 141 8.2.1 Compiling Qt/Embedded ..........................................................................................................- 141 8.2.2 Compiling Hello, World ........................................................................................................- 141 8.2.3 Downloading and Running Hello, World on Board ..............................................................- 142 -

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. --4-Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Chapter 1 Introduction
1.1 About this Document
This document is intended to give some basic introductions to the Linux development for the MINI2440 board. It tries to cover the most important and exciting topics and materials that you may be interested in. It does not and cannot cover everything though. However we wish this manual could open a door to the magic world of Linux development for you and you could enjoy your time with our MINI2440 system.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. --5-Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Chapter 2 Getting Started with Linux


2.1 Booting Sequence
You can select the booting mode by toggling the S2 switch: When toggling the S2 switch to the Nor Flash side the system will be booted from the Nor Flash.When toggling the S2 switch to the Nand Flash side the system will be booted from the Nand Flash. This board is shipped with the S2 switch toggled to the Nand Flash side by default it will be booted from the Nand Flash. Both the Nor Flash and the Nand Flash have been installed with the same BIOS (which supports both types of Flash. The only difference is that the system will have different startup interfaces).

2.2 Powering Up
Make sure the S2 switch is toggled to the Nand Flash side. This package is shipped with a Linux system image. After the system is powered up, you will see one of the following startup interfaces. By connecting to an NEC 3.5-inch screen, you will see the startup interface as below:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. --6-Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Chapter 3 Setting up Linux Development Environment


3.1 Installing Fedora 9.0
Note: users can download a Fedora 9.0 DVD image from http://www.arm9down.cn/linux/fedora9.iso Step1 Insert the first disk in the CDROM/DVD, set the boot sequence to CDROM in the BIOS. After reboot the system, it will prompt the user to the following interface, just press enter.

Step2The system will check the installation disk. It can be ignored, just press Skip to the next step.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. --7-Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step3it enters the graphic interface, click on the Next button.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. --8-Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

Step4set the installation language. In this example, we chose the simplified English.

Step5set the keyboard, in this example, we chose the U.S. key board.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. --9-Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step 6configure the network.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 10 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

In our example, we didnt set it as DHCP, we used a static IP instead, and typed the IP and subnet mask as follows.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 11 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Click on the OK button and go on to set the machine name, gateway and DNS.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 12 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step 7set the time zone. We chose Asia/Shanghai.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 13 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step 8set up the administrators password, i.e. the roots password. root is the super user. It should be at least 6 characters

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 14 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step 9disk partition. We followed the default option. Before do this, please back up disk data.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 15 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Click on Next, it will warn the user that all the data will be deleted. Usually we would do this installation in VMWARE, so we chose Write changes to disk and disk format would begin.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 16 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Here is the format process:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 17 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step 11select the installation type, in this example, we chose customize

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 18 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step 12configure the server item as follows:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 19 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step 13begin installation

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 20 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step14: installation complete.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 21 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step15: after installation completed, click on the reboot button on the page shown in step 14

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 22 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step16: skip this license page and go forward

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 23 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step17: create new users. We ignored user creation and went to the next step.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 24 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Press continue to go on.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 25 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step18: setup date and time. We ignored this and went to the next step.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 26 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step19: confirm hardware information. We just clicked on Finish.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 27 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

On the popup window shown below, just click on the red marked button.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 28 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step 20: on the login page, login as root

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 29 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Input the password we just created for root

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 30 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

When login as root, the following popup window will show up, just click on Continue

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 31 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Below is the interface the user will see after a successful login.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 32 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

3.2 Setting up Cross Compile Environment


A main step to build a development environment in the MINI2440 Linux system is to set up a cross compile environment. The following steps will introduce how to build a compile environment that can compile arm-linux kernels, drivers and applications. From our updated Linux-2.6.29, we use arm-linux-gcc-4.3.2 as our uniform cross compiler. Here are the steps on how we set up this utility. Step 1: copy the compressed file arm-linux-gcc-4.3.2.tgz under the linux\ directory in the shipped CD into a systems directory, e.g tmp\, enter this directory and execute the following commands: #cd \tmp #tar xvzf arm-linux-gcc-4.3.2.tgz C / Note: there is a space after C and C is a capital letter. These commands will install arm-linux-gcc in the /usr/local/arm/4.3.2

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 33 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

. Step 2: run the command below to add the compilers path to system variables: #gedit /root/.bashrc This is to edit the /root/.bashrc file. Append line PATH=$PATH:/usr/local/arm/4.3.2/bin in the opened file, save and exit the file.

export

Logout and login the system again (no need to reboot the system, just go to start-> logout), the above settings will take into effect. Type arm-linux-gcc v, if the messages depicted in the screen shot below appear, it indicates the compile environment has been set up successfully.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 34 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

To configure a 2.95.3 compiler append line export PATH=$PATH:/usr/loca/arm/2.95.3/bin in the /root/.bashrc file.

Logout and login system again, the configurations will be effective, in the command line, type arm-linux-gcc -v, you will see the following messages if it is a successful install.
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 35 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 36 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Chapter 4 Linux Development


This chapter presents some basic examples to show you how to develop and compile Linux programs, download and run on the MINI2440 board. Later on it will go further into some advaced topics like driver and module development, and how to migrate open source software. There are huge amounts of resrouces about Linux development which cannot be covered in detail in this section. But we are trying our best to open a door to the magic world of Linux development for you.

4.1 Hello World 4.1.1 Source Code of Hello World


The source code of Hello World is included in the linux/examples.tgz package of the shipped CD. If a development environment has been set up correctly on your board, the Hello World program can be found in the /opt/FriendlyARM/mini2440/examples/hello directory, the source code is as follows:
Hello, World Source Code: #include <stdio.h> int main(void) { printf("hello, FriendlyARM!\n"); }

4.1.2 Compiling Hello World


Firstly, enter the directory that has the souce code #cd /opt/FriendlyARM/mini2440/examples/hello Then execute the command below or #arm-linux-gcc o hello main.c Run a make file to compile the source code #make An executable will be generated

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 37 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

4.1.3 Downloading to and Running Hello World on MINI2440


There are four usual ways to download a compiled executable to a target board: 1) copy it to a storage media (USB drive) 2) download via FTP 3) download via a serial port 4) run via NFS

(1) Copy it to a Storage Media


Copy the compiled program to a USB drive, mount the drive to the target board and copy the program from the drive to the /bin directory of the board. Step1: Copy the program to a USB drive Plug a USB drive to a PC and execute the following commands #mount /dev/sda1 /mnt ; mount a USB drive #cp hello /mnt ; copy the program to the drive #umount /mnt ; unmount the drive Step2: Copy the program from the drive to a target board Plug the USB drive to a target boards USB host port, the drive will be automatically mounted on the /udisk directory, execute the following commands to run the program #cd /udisk ; mount the USB drive #./hello ; run the program Note: if during this process, the USB drive is manually unplugged, you need to go back to the root directory to run umount /udisk for next auto mount.

(2) Download via FTP


Login a target board via FTP, transfer the compiled program to the board, add the executable mode to the file and run. Firstly, execute the commands shown below in the host PC

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 38 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Then execute the commands shown below on the board

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 39 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

(3)Download via a Serial Port


Please refer to the users manual on how to transfer files via a serial port. Follow that way to transfer the compiled program to a target board. Remember to add the executable mode to the file #chmod +x hello

(4)Run via NFS


It is quite popular to run programs via NFS in Linux. This way saves you time for program download. In this example, the executable is very small, so downloading does not take too much time. However large files could take long to download that is where this method presents its advantage. Please refer to the users manual on how to configure the NFS service and then run the command below. (It is assumed the IP address is 192.168.1.111: #mount t nfs o nolock 192.168.1.1111:/opt/FriendlyARM/mini2440/root_nfs /mnt If mounting succeeds, enter the /mnt directory, copy the program to the opt/FriendlyARM/mini2440/root_nfs directory and run the commands below on the target board. #cd /mnt #./hello

4.2 Application Development 4.2.1 Test Program of LED


Souce code descriptions: Drivers location /opt/FriendlyARM/mini2440/linux-2.6.29/drivers/char Drivers source file mini2440_leds.c Device name /dev/leds Test program /opt/FriendlyARM/mini2440/examples/led Test programs source file led.c Test programs executable Led Note: the LED driver has been compiled into the kernel by default you do not need to load it via insmod. Source Code of the Test Program #include <stdio.h> #include <stdlib.h>
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 40 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems #include <unistd.h> #include <sys/ioctl.h> int main(int argc, char **argv) { int on; int led_no; int fd; /* If either of the two input parameters is invalid, exit the program */ if (argc != 3 || sscanf(argv[1], "%d", &led_no) != 1 || sscanf(argv[2],"%d", &on) != 1 || on < 0 || on > 1 || led_no < 0 || led_no > 3) { fprintf(stderr, "Usage: leds led_no 0|1\n"); exit(1); } /*Open the /dev/leds device file*/ fd = open("/dev/leds", 0); if (fd < 0) { perror("open device leds"); exit(1); } /*command led via system call ioctl */ ioctl(fd, on, led_no); /*close fd*/ close(fd); return 0;
}

The user can follow the procedure in making a hello executable to generate a led executable, download and run it on the target board.

4.2.2 Test Program of Keyboard


Source code descriptions: Drivers location Drivers source file Device name Test program /opt/FriendlyARM/mini2440/linux-2.6.29/drivers/char Mini2440_buttons.c /dev/buttons /opt/FriendlyARM/mini2440/examples/buttons

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 41 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems Test programs source file buttons_test.c Test programs executable buttons Note: the LED driver has been compiled into the kernel by default you do not need to load it via insmod. Source Code: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/select.h> #include <sys/time.h> #include <errno.h> int main(void) { int i; int buttons_fd; int key_value[4]; /*Open device file*/ buttons_fd = open("/dev/buttons", 0); if (buttons_fd < 0) { perror("open device buttons"); exit(1); } for (;;) { fd_set rds; int ret; FD_ZERO(&rds); FD_SET(buttons_fd, &rds); /*Check if it can read data from /dev/buttons by using select */ ret = select(buttons_fd + 1, &rds, NULL, NULL, NULL); /*exit the program if reading has errors*/ if (ret < 0) { perror("select");
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 42 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems exit(1); } if (ret == 0) { printf("Timeout.\n"); } /*reading succeeded*/ else if (FD_ISSET(buttons_fd, &rds)) { /*begin to read data from key typing, note: the key_values data type is the same as what is defined in the driver*/ int ret = read(buttons_fd, key_value, sizeof key_value); if (ret != sizeof key_value) { if (errno != EAGAIN) perror("read buttons\n"); continue; } else { /*pring typed key values*/ for (i = 0; i < 4; i++) printf("K%d %s, key value = 0x%02x\n", i, (key_value[i] & 0x80) ? "released" :\ key_value[i] ? "pressed down" : "", \ key_value[i]); } } } /*close fd*/ close(buttons_fd); return 0; } You can follow the procedure in making a hello executable to generate a buttons executable, download and run it on the target board.

4.2.3 UDP Applications


Source code descriptions: Drivers location /opt/FriendlyARM/mini2440/ linux-2.6.29/drivers/net/ Drivers source file Dm9000.c Major number of this No
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 43 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems device Device name Eth0 (this network device is not located in the /dev directory) Test program /opt/FriendlyARM/mini2440/examples/udptak Test programs source udptalk.c file Test programs udptalk.c executable Note:this program can be compiled to an x86 version and an arm version. TCP/IP provides a connectionless protocol in the transport layer: UDP (User Datagram Protocol). UDP differs greatly from TCP in that UDP is connectionless. So socket programming based on connectionlessness is different from socket programming based on connection. A UDP packet contains both the senders and the receivers addresses. Before sending and receiving data, both sides need to create a datagram socket whose data type is SOCK_DGRAM, by calling the function below: sockfd=socket(AF_INET, SOCK_DGRAM, 0); Because it is unnecessary to establish a connection, the sender can begin sending data right after a socket has been created. The receiver needs to be bound with a port otherwise the sender will not know where to send data. sendto and recvfrom are used for sending and receiving data: int sendto(int s, const void *msg, int len, unsigned int flags, const struct sockaddr *to, int tolen); int recvfrom(int, s, void *buf, int len, unsigned int flags, struct sockaddr *from, int fromlen); Parameter s is a created socket, msg and buf are pointers to the senders buffer and the receivers buffer, len is the length of the buffer, flags is an option flag, here it is not used, and can be set to 0. to and from are senders destination and receivers source, which include the IP address and the port information. tolen is the length of the to socket structure and fromlen is the length of the from socket structure. The return values of these two functions indicate the numbers of bytes the sender sends and the receiver receives. -1 means an error happens. The diagram presented below shows the data flow of a UDP communication

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 44 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

UDPs Communication Diagram The diagram shown above describes a case in which both sides bind their ports and IP addresses. However sometimes, one side might not bind its address or port, and the other side gets its address and port via system calls. In this case, since one side does not know the address or port of the other side (a host has multiple ports, each of them has a different IP), the communication can only be initiated by the one which has not bound its address and port. The other will obtain the senders address and port from the datagram it receives. This communication requires one side to bind its address and port, and can only be started by the other that has not bound its address or port. It is similar to the read() and write() functions, process block also happens when calling the recvfrom() and sendto() functions. But it is a little bit different from TCP in that it is possible to receive a datagram of 0 bytes. Callers can set parameter msg to NULL and len to 0 when calling sendto(). The example below presents some technics in UDP programming (the source code is in the /opt/FriendlyARM/mini2440/examples/udptalk directory): /* * udptalk Example for Matrix V ;Note: this program works for the MINI2440 * * Copyright (C) 2004 capbily - friendly-arm * capbily@hotmail.com */ #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include <stdio.h> #define BUFLEN 255
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 45 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems int main(int argc, char **argv) { struct sockaddr_in peeraddr, /* stores the other sides IP and socket */ localaddr; /* local socket */ int sockfd; char recmsg[BUFLEN+1]; int socklen, n; if(argc!=5){ printf("%s <dest IP address> <dest port> <source IP address> <source port>\n", argv[0]); exit(0); } sockfd = socket(AF_INET, SOCK_DGRAM, 0); if(sockfd<0){ printf("socket creating err in udptalk\n"); exit(1); } socklen = sizeof(struct sockaddr_in); memset(&peeraddr, 0, socklen); peeraddr.sin_family=AF_INET; peeraddr.sin_port=htons(atoi(argv[2])); if(inet_pton(AF_INET, argv[1], &peeraddr.sin_addr)<=0){ printf("Wrong dest IP address!\n"); exit(0); } memset(&localaddr, 0, socklen); localaddr.sin_family=AF_INET; if(inet_pton(AF_INET, argv[3], &localaddr.sin_addr)<=0){ printf("Wrong source IP address!\n"); exit(0); } localaddr.sin_port=htons(atoi(argv[4])); if(bind(sockfd, &localaddr, socklen)<0){ printf("bind local address err in udptalk!\n"); exit(2); } if(fgets(recmsg, BUFLEN, stdin) == NULL) exit(0); if(sendto(sockfd, recmsg, strlen(recmsg), 0, &peeraddr, socklen)<0){ printf("sendto err in udptalk!\n"); exit(3);
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 46 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems } for(;;){ /*recv&send message loop*/ n = recvfrom(sockfd, recmsg, BUFLEN, 0, &peeraddr, &socklen); if(n<0){ printf("recvfrom err in udptalk!\n"); exit(4); }else{ /*Received data */ recmsg[n]=0; printf("peer:%s", recmsg); } if(fgets(recmsg, BUFLEN, stdin) == NULL) exit(0); if(sendto(sockfd, recmsg, strlen(recmsg), 0, &peeraddr, socklen)<0){ printf("sendto err in udptalk!\n"); exit(3); } } } Compile this udptalk.c and run the generated executable. In the /opt/FriendlyARM/mini2440/exampls/udptalk directory, the Makefile will generate two executables, one to be run in a host: x86-udptalk and the other to be run on a target board:arm-udptalk. After commanding make these two files will be compiled. Download arm-udptalk to your target board(the preinstalled Linux doesnt include this application). In this example, the host IP was 192.168.0.1, and the boards IP was 192.168.0.230. Open a terminal in the host PC, type: #./x86-udptalk 192.168.0.230 2000 192.168.0.1 2000 Open a terminal on the board and type: #arm-udptalk 192.168.0.1 2000 192.168.0.230 2000 The screen shot below shows the running result:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 47 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Running x86-udptalk in the host PC

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 48 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Running arm-udptalk on the board

4.2.4 Using Math Libraries


Source code descriptions: Source code location /opt/FriendlyARM/mini2440/examples/math Source file mathtest.c Executable file mathtest Note: to use math functions, you need to include the header file math.h and link the math library libm in compiling. Source Code: #include <stdio.h> #include <stdlib.h> #include <math.h> ; Note: this file should be included int main(void) { double a=8.733243;
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 49 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

printf("sqrt(%f)=%f\n", a, sqrt(a)); return 0; } The contents of the Makefile file: CROSS=arm-linuxall: mathtest #Note: here it uses the math library libm, see the red mark mathtest: $(CROSS)gcc -o mathtest main.c -lm clean: @rm -vf mathtest *.o *~ You can follow the procedure in making a hello executable to generate a mathtest executable, download and run it on your target board.

4.2.5 Thread Programming


Source code descriptions: Source code location /opt/FriendlyARM/mini2440/examples/pthread Source file pthread_test.c Executable file pthread_test Note: to call thread functions, include the header file pthread.h and link the thread library libpthread in compiling Source Code: #include<stddef.h> #include<stdio.h> #include<unistd.h> #include"pthread.h" ; note: include this header file void reader_function(void); void writer_function(void); char buffer; int buffer_has_item=0; pthread_mutex_t mutex; main()
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 50 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems { pthread_t reader; pthread_mutex_init(&mutex,NULL); pthread_create(&reader,NULL,(void*)&reader_function,NULL); writer_function(); } void writer_function(void) { while(1) { pthread_mutex_lock(&mutex); if(buffer_has_item==0) { buffer='a'; printf("make a new item\n"); buffer_has_item=1; } pthread_mutex_unlock(&mutex); } } void reader_function(void) { while(1) { pthread_mutex_lock(&mutex); if(buffer_has_item==1) { buffer='\0'; printf("consume item\n"); buffer_has_item=0; } pthread_mutex_unlock(&mutex); } } The contents of the Makefile file: CROSS=arm-linuxall: pthread #Note: include the thread library libphread here, see the red mark pthread: $(CROSS)gcc -static -o pthread main.c -lpthread
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 51 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

clean: @rm -vf pthread *.o *~ You can follow the procedure in making a hello executable to generate a pthread executable, download and run it on your target board.

4.2.6 PIPE Applications


Source code descriptions: Source code location /opt/FriendlyARM/mini2440/examples/led-player Source file led-player.c Executable file led-player Noteplease refer to the descriptions below After the system is booted, you can command the LED on the board via operations through web pages. This is a good example of IPC (InterProcess Communication) using shared resources. The applications of IPC are as follow: (1) data transfer (2) data sharing (3) event notification (4) resource sharing (5) process control. Linux supports various IPC mechanisms. Signals and PIPEs are two of them. There are many books on IPC programming, and the manual will not go any further here. Commanding the LED on the board can be implemented via IPC, in which the LED is a shared resource, the led-player is a background program. The led-player , on system startup, will create a named pipe /tmp/ led-control(if this named pipe is created by command mknod, then the program should be written differently, and you can try that), then you can monitor the data transfer through the pipe and change the LEDs display mode based on the input parameters (type and period). The leds.cgi is a gateway program which receives character commands form web pages(ping defines a round-robin mode, counter defines a counter mode and stop defines a stop mode; slow defines a period of 0.25m, normal defines a period of 0.125m and fast defines a period of 0.0625m), converts them into numericals and executes the echo command to send the numericals to pipe /tmp/ led-control controling the LED. Below is the source code: Led-players source code: /opt/FriendlyARM/mini2440/examples/led-player/main.c Source Code: #include <stdio.h> #include <stdlib.h> #include <unistd.h>
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 52 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems #include <sys/ioctl.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/select.h> #include <sys/time.h> static int led_fd; static int type = 1; static void push_leds(void) { static unsigned step; unsigned led_bitmap; int i; switch(type) { case 0: if (step >= 6) { step = 0; } if (step < 3) { led_bitmap = 1 << step; } else { led_bitmap = 1 << (6 - step); } break; case 1: if (step > 255) { step = 0; } led_bitmap = step; break; default: led_bitmap = 0; } step++; for (i = 0; i < 4; i++) { ioctl(led_fd, led_bitmap & 1, i); led_bitmap >>= 1; } }
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 53 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems int main(void) { int led_control_pipe; int null_writer_fd; // for read endpoint not blocking when control process exit double period = 0.5; led_fd = open("/dev/leds", 0); if (led_fd < 0) { perror("open device leds"); exit(1); } unlink("/tmp/led-control"); mkfifo("/tmp/led-control", 0666); led_control_pipe = open("/tmp/led-control", O_RDONLY | O_NONBLOCK); if (led_control_pipe < 0) { perror("open control pipe for read"); exit(1); } null_writer_fd = open("/tmp/led-control", O_WRONLY | O_NONBLOCK); if (null_writer_fd < 0) { perror("open control pipe for write"); exit(1); } for (;;) { fd_set rds; struct timeval step; int ret; FD_ZERO(&rds); FD_SET(led_control_pipe, &rds); step.tv_sec = period; step.tv_usec = (period - step.tv_sec) * 1000000L; ret = select(led_control_pipe + 1, &rds, NULL, NULL, &step); if (ret < 0) { perror("select"); exit(1); } if (ret == 0) { push_leds();
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 54 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems } else if (FD_ISSET(led_control_pipe, &rds)) { static char buffer[200]; for (;;) { char c; int len = strlen(buffer); if (len >= sizeof buffer - 1) { memset(buffer, 0, sizeof buffer); break; } if (read(led_control_pipe, &c, 1) != 1) { break; } if (c == '\r') { continue; } if (c == '\n') { int tmp_type; double tmp_period; if (sscanf(buffer,"%d%lf", &tmp_type, &tmp_period) == 2) { type = tmp_type; period = tmp_period; } fprintf(stderr, "type is %d, period is %lf\n", type, period); memset(buffer, 0, sizeof buffer); break; } buffer[len] = c; } } } close(led_fd); return 0; } Use make to compile a led-player executable, and put it in the /sbin directory running as a server. Below is the source code of Leds.cgi(it is /www/leds.cgi in the shipped CD). It is a shell script. It is called by leds.html to execute as an action: #!/bin/sh type=0
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 55 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems period=1 case $QUERY_STRING in *ping*) type=0 ;; *counter*) type=1 ;; *stop*) type=2 ;; esac case $QUERY_STRING in *slow*) period=0.25 ;; *normal*) period=0.125 ;; *fast*) period=0.0625 ;; esac /bin/echo $type $period > /tmp/led-control echo "Content-type: text/html; charset=gb2312" echo /bin/cat led-result.template exit 0

4.2.7 Hello, World in C++


Source code descriptions: Source code location Source file Executable file Note: N/A /opt/FriendlyARM/mini2440/examples/c++ cplus.c++ cplus

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 56 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Source Code: #include <iostream> #include <cstring> using namespace std; class String { private: char *str; public: String(char *s) { int lenght=strlen(s); str = new char[lenght+1]; strcpy(str, s); } ~String() { cout << "Deleting str.\n"; delete[] str; } void display() { cout << str <<endl; } }; int main(void) { String s1="I like FriendlyARM."; cout << "s1="; s1.display(); return 0; double num, ans; cout << "Enter num:"; } You can follow the procedure in making a hello executable to generate a cplus executable, download and run it on the target board.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 57 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

4.3 Drivers Development


The previous chapter presented several examples which should be run in the user mode. This chapter will show you how to develop some basic drivers which run in the kernel mode.

4.3.1 Hello Module


Souce code descriptions: Source code location Source file Major number of this device Device name Test program location Test programs source file Test programs executable Note: N/A /opt/FriendlyARM/mini2440/ linux-2.6.29/drivers/char mini2440_hello_sample.c N/A N/A N/A N/A N/A

The source code of Hello Module is located in the /opt/FriendlyARM/mini2440/ linux-2.6.29/drivers/char directory, the file name is mini2440_hello_module.c, and the source file is presented as below:
#include <linux/kernel.h> #include <linux/module.h> static int __init mini2440_hello_module_init(void) { printk("Hello, Mini2440 module is installed !\n"); return 0; } static void __exit mini2440_hello_module_cleanup(void) { printk("Good-bye, Mini2440 module was removed!\n"); } module_init(mini2440_hello_module_init); module_exit(mini2440_hello_module_cleanup); MODULE_LICENSE("GPL");

The next step is to embed this file into the kernel and compile it.
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 58 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems This step shows how to link this source file into the kernel. In the 2.6 kernel, you need to add a drivers source code into the kernel tree and configure it. Here are the details (Note: the following configurations have been set up in the shipped package, you just need to verify it and compile): Step1: edit the Kconfig file and check the driver option to make it listed in the pop up window after executing make menuconfig Open the linux-2.6.29/drivers/char/Kconfig file, and add the redly marked sections shown below:

Save and exit. Go to the linux-2.6.29 directory and run make menuconfig. Select Device Drivers -> Character devices and you will find the newly added item. Press the space key, it will be marked <M> which means this item will be compiled as a module. Press it a second time, it will turn to <*> which means it will be compiled into the kernel. Here, set it to <M>:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 59 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step2the previous step described how to set an items compile option in the kernel configuration, but the mini2440_hello_module.c file still cannot be compiled into the kernel. To make it work, you need to link the source code to its kernel configuration. Edit the linux-2.6.29/drivers/char/Makefile file as below, save and exit

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 60 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Step3: go back to the root directory of the linux-2.6.29 source code, execute make modules, and a kernel module mini2440_hello_module.ko will be generated: This module compilation has been completed.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 61 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Now it is time to download the program to the target board and run it.

Here we used the rz command to download the mini2440_hello_module.ko to the target board and run: #insmod mini2440_hello_module.ko The module will be loaded; Try the command below, the module will be unloaded: #rmmod mini2440_hello_module.ko Note: To rmmod the module correctly, you need to put the module in the /lib/modules/2.6.29-FriendlyARM directory. The load and unload processes are as below:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 62 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

4.3.2 LED Driver


Source code descriptions: Drivers code location /opt/FriendlyARM/mini2440/linux-2.6.29/drivers/char Drivers source file mini2440_leds.c Major number of the device Led is a misc device, its number will be created automatically Device name /dev/leds Test programs location /opt/FriendlyARM/mini2440/examples/led Test programs source file led.c Test programs executable Led Note:an LED driver has been compiled into the kernel by default, you do not need to insmod it. To write an appropriate driver for a device, you need to learn its hardware, e.g. registers, physical addresses, interrupts and so on. The LED driver described in this section is a simple example. It uses the following hardware resources. A mini2440 board has 4 LEDs LED IO Register CPU Pin LED1 GPB5 K2
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 63 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems LED2 LED3 LED4 GPB6 GPB7 GPB8 L5 K7 K5

To operate an IO, you need to configure its register by calling related functions or macros e.g. s3c2410_gpio_cfgpin Why here is it an S3C2410 one Because Samsungs S3C2440 has almost the same configurations and resources as its S3C2410. Most of the existing Linux versions adopt the same functions and macros definitions. Where are they defined? Since they are closely related to system architectures, they are defined in the linux-2.6.29/arch/arm/mach-s3c2410/include/mach/hardware.h file, and are implemented in the linux-2.6.29/arch/arm/plat-s3c24xx/gpio.c file. Below is a sample file: void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function) { void __iomem *base = S3C24XX_GPIO_BASE(pin); unsigned long mask; unsigned long con; unsigned long flags; if (pin < S3C2410_GPIO_BANKB) { mask = 1 << S3C2410_GPIO_OFFSET(pin); } else { mask = 3 << S3C2410_GPIO_OFFSET(pin)*2; } switch (function) { case S3C2410_GPIO_LEAVE: mask = 0; function = 0; break; case S3C2410_GPIO_INPUT: case S3C2410_GPIO_OUTPUT: case S3C2410_GPIO_SFN2: case S3C2410_GPIO_SFN3: if (pin < S3C2410_GPIO_BANKB) { function -= 1; function &= 1; function <<= S3C2410_GPIO_OFFSET(pin); } else { function &= 3; function <<= S3C2410_GPIO_OFFSET(pin)*2; } } /* modify the specified register wwith IRQs off */
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 64 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems local_irq_save(flags); con = __raw_readl(base + 0x00); con &= ~mask; con |= function; __raw_writel(con, base + 0x00); local_irq_restore(flags); } In fact, you do not need to go very deep into it as long as you know how and when to call these functions. Most of the popular embedded systems have already defined those functions so there is no need for users to create new ones unless they use a CPU whose architecture is not supported by Linux. The following sample code details how s3c2410_gpio_cfgpin gets called. To make s3c2410_gpio_cfgpin work, inaddition you also need to call other helper functions such as misc_register, creating a device function structure with file_operations, loading and exiting a module with module_init and module_exit. The last two are used in the Hello Module example. Some of the functions shown below are not used quite often. You will get more familiar with them as you become more proficient in Linux driver development. Here is the source code: Source code: #include <linux/miscdevice.h> #include <linux/delay.h> #include <asm/irq.h> #include <mach/regs-gpio.h> #include <mach/hardware.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/mm.h> #include <linux/fs.h> #include <linux/types.h> #include <linux/delay.h> #include <linux/moduleparam.h> #include <linux/slab.h> #include <linux/errno.h> #include <linux/ioctl.h> #include <linux/cdev.h> #include <linux/string.h> #include <linux/list.h> #include <linux/pci.h> #include <asm/uaccess.h> #include <asm/atomic.h>
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 65 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems #include <asm/unistd.h> #define DEVICE_NAME "leds"

static unsigned long led_table [] = { S3C2410_GPB5, S3C2410_GPB6, S3C2410_GPB7, S3C2410_GPB8, }; static unsigned int led_cfg_table [] = { S3C2410_GPB5_OUTP, S3C2410_GPB6_OUTP, S3C2410_GPB7_OUTP, S3C2410_GPB8_OUTP, }; static int sbc2440_leds_ioctl( struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { switch(cmd) { case 0: case 1: if (arg > 4) { return -EINVAL; } s3c2410_gpio_setpin(led_table[arg], !cmd); return 0; default: return -EINVAL; } } static struct file_operations dev_fops = { .owner = THIS_MODULE, .ioctl = sbc2440_leds_ioctl, }; static struct miscdevice misc = { .minor = MISC_DYNAMIC_MINOR,
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 66 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems .name = DEVICE_NAME, .fops = &dev_fops, }; static int __init dev_init(void) { int ret; int i; for (i = 0; i < 4; i++) { s3c2410_gpio_cfgpin(led_table[i], led_cfg_table[i]); s3c2410_gpio_setpin(led_table[i], 0); } ret = misc_register(&misc); printk (DEVICE_NAME"\tinitialized\n"); return ret; } static void __exit dev_exit(void) { misc_deregister(&misc); } module_init(dev_init); module_exit(dev_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("FriendlyARM Inc.");

4.3.3 Keyboard Driver


Source code descriptions Drivers source code /opt/FriendlyARM/mini2440/linux-2.6.29/drivers/char location Drivers source file mini2440_buttons.c Major number of the device Misc, the number will be created automatically Device name /dev/buttons Test programs location /opt/FriendlyARM/mini2440/examples/buttons Test programs source file buttons_test.c Test programs executable Buttons Note: this driver has beeb compiled into the kernel by default, there is no need to inmod it. A mini2440 board has the following key resources:
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 67 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems Keys IO Registers K1 GPG0 K2 GPG3 K3 GPG5 K4 GPG6 K5 GPG7 K6 GPG11 Source code: #include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> #include <linux/init.h> #include <linux/delay.h> #include <linux/poll.h> #include <linux/irq.h> #include <asm/irq.h> #include <linux/interrupt.h> #include <asm/uaccess.h> #include <mach/regs-gpio.h> #include <mach/hardware.h> #include <linux/platform_device.h> #include <linux/cdev.h> #include <linux/miscdevice.h> #define DEVICE_NAME buttons Interrupts EINT8 EINT11 EINT13 EINT14 EINT15 EINT19

struct button_irq_desc { int irq; int pin; int pin_setting; int number; char *name; }; static struct button_irq_desc button_irqs [] = { {IRQ_EINT8 , S3C2410_GPG0 , S3C2410_GPG0_EINT8 , 0, "KEY0"}, {IRQ_EINT11, S3C2410_GPG3 , S3C2410_GPG3_EINT11 , 1, "KEY1"}, {IRQ_EINT13, S3C2410_GPG5 , S3C2410_GPG5_EINT13 , 2, "KEY2"}, {IRQ_EINT15, S3C2410_GPG7 , S3C2410_GPG7_EINT15 , 3, "KEY3"}, {IRQ_EINT14, S3C2410_GPG6 , S3C2410_GPG6_EINT14 , 4, "KEY4"}, {IRQ_EINT19, S3C2410_GPG11, S3C2410_GPG11_EINT19, 5, "KEY5"}, }; static volatile char key_values [] = {'0', '0', '0', '0', '0', '0'};
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 68 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems static DECLARE_WAIT_QUEUE_HEAD(button_waitq); static volatile int ev_press = 0; static irqreturn_t buttons_interrupt(int irq, void *dev_id) { struct button_irq_desc *button_irqs = (struct button_irq_desc *)dev_id; int down; // udelay(0); down = !s3c2410_gpio_getpin(button_irqs->pin); if (down != (key_values[button_irqs->number] & 1)) { // Changed key_values[button_irqs->number] = '0' + down; ev_press = 1; wake_up_interruptible(&button_waitq); } return IRQ_RETVAL(IRQ_HANDLED); }

static int s3c24xx_buttons_open(struct inode *inode, struct file *file) { int i; int err; for (i = 0; i < sizeof(button_irqs)/sizeof(button_irqs[0]); i++) { err = request_irq(button_irqs[i].irq, buttons_interrupt, IRQ_TYPE_EDGE_BOTH, button_irqs[i].name, (void *)&button_irqs[i]); if (err) break; } if (err) { i--; for (; i >= 0; i--) { disable_irq(button_irqs[i].irq); free_irq(button_irqs[i].irq, (void *)&button_irqs[i]); } return -EBUSY; } ev_press = 1; return 0; } static int s3c24xx_buttons_close(struct inode *inode, struct file *file) { int i;
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 69 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems for (i = 0; i < sizeof(button_irqs)/sizeof(button_irqs[0]); i++) { free_irq(button_irqs[i].irq, (void *)&button_irqs[i]); } return 0; } static int s3c24xx_buttons_read(struct file *filp, char __user *buff, size_t count, loff_t *offp) { unsigned long err; if (!ev_press) { if (filp->f_flags & O_NONBLOCK) return -EAGAIN; else wait_event_interruptible(button_waitq, ev_press); } ev_press = 0; err = copy_to_user(buff, (const void *)key_values, min(sizeof(key_values), count)); return err ? -EFAULT : min(sizeof(key_values), count); } static unsigned int s3c24xx_buttons_poll( struct file *file, struct poll_table_struct *wait) { unsigned int mask = 0; poll_wait(file, &button_waitq, wait); if (ev_press) mask |= POLLIN | POLLRDNORM; return mask; } static struct file_operations dev_fops = { .owner = THIS_MODULE, .open = s3c24xx_buttons_open, .release = s3c24xx_buttons_close, .read = s3c24xx_buttons_read, .poll = s3c24xx_buttons_poll, }; static struct miscdevice misc = { .minor = MISC_DYNAMIC_MINOR, .name = DEVICE_NAME, .fops = &dev_fops, }; static int __init dev_init(void)
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 70 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems { int ret; ret = misc_register(&misc); printk (DEVICE_NAME"\tinitialized\n"); return ret; } static void __exit dev_exit(void) { misc_deregister(&misc); } module_init(dev_init); module_exit(dev_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("FriendlyARM Inc.");

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 71 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Chapter 5 Configuring and Compiling a Bootloader


Note: all the Linux source code here has passed the compiling by using arm-linux-gcc-4.3.2. In S3C2440/2410 systems, popular bootloaders are: Vivi supported by Samsung, it was originally created by mizi. It is open source, and should be compiled with arm-linux-gcc, but it no longer gets official support now. It is best suited for Samsungs S3C24xx ARM chips. It supports file download via FTP, system boot via NFS and common applications. Supervivi developed and maintained by Friendly Arm, it is based on vivi. Currently Friendly Arm doesnt provide its source code. It keeps vivis functions and integrates extra features such as support for CRAMFS, YAFFS, USB Download and System Booting for Linux, WinCE, uCos and Vxwork. It also enables downloading to and running applications in RAM. In addition, it has a unique feature: system backup and restore and is ready for mass production. It is a very strong and popular bootloader for 2440/2410 systems. U-Boot an open source bootloader dedicated to Linux systems. It should be compiled by arm-linux-gcc, and has strong network functions (Without network, U-Boot almost loses all of its advantages. In 2440/2410 systems, network is facilitated through extention of network chips. This will definitely add to its cost. But USB is integrated and only needs several resistor configurations). It supports download and system startup via NFS. Now U-Boot is very popular and being in great move, but does not support booting from Nand Flash in 2440/2410 systems. Bootloader means to download and boot systems. It is similar to the BIOS in a PC. Most chip vendors provide embedded systems with this program which are very mature and stable. Usually it is unnecessary to create one from scratch. Friendly Arms supervivi is more user friendly and good for mass productions. The following BIOS all have included their source code. Friendly Arm also modified their code making them fit the MINI2440 system. In our tests of these different BIOS, we found that it was very hard for beginners to go through the whole compiling process without difficulties since it requires setting up various configurations and network. Friendly Arms supervivi gives users great benefits letting them focus on development. Users will be able to download to and test programs on a target board easily. It doesnt require users to be very procificent in bootloaders, not does it require advanced knowledge of bootloaders. The section will give a brief introduction to the setup and configurations of some open source BIOS.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 72 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

5.1 Configuring and Compiling VIVI


Note: to compile vivi, you need to install a arm-linux-gcc-4.3.2 cross compiler, please refer to the users manual for more details. If you have uncompressed and installed vivis source code, please follow the steps below otherwise please refer to the users manual for details on how to install the souce code. #cd /opt/FriendlyARM/mini2440/bootloader/vivi #cp fa.config .config #make clean #make menuconfig The following window will pop up:

Just follow the default options, and Exit:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 73 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Choose Yes and enter, run make to compile: #make

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 74 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

A vivi will be generated in the current directory. Download it to a target boards Nand Flash.

5.2 Configuring and Compiling U-Boot


Note: this section only introduces how to configure and compile U-Boot, but details about how to use it are not covered. The U-Boot in the shipped CD has the following features: 1. supports both S3C2410 and S3C2440 2. supports the xmodem protocol 3. supports USB download, and data transfer with PC via dnw 4. supports CS8900 chip 5. supports read and write to the NAND Flash 6. supports system boot from the Nor/Nand Flash 7. supports download and write of the yaffs file system 8. can be downloaded to and run in RAM 9. supports CS8900 and DM9000, but not both in the same system simultaneously; to select the one you want, set it in the include/configs/100ask24x0.h file: #if 0 #define CONFIG_DRIVER_CS8900 1 /* we have a CS8900 on-board */ #define CS8900_BASE 0x19000300 #define CS8900_BUS16 1 /* the Linux driver does accesses as shorts */ #endif #if !defined(CONFIG_DRIVER_CS8900) #define CONFIG_DRIVER_DM9000 1 #define CONFIG_DM9000_USE_16BIT 1 #define CONFIG_DM9000_BASE 0x20000000 #define DM9000_IO 0x20000000 #define DM9000_DATA 0x20000004 #endif Below are detailed steps:

5.2.1 Configuring and Compiling U-Boot


Note: to compile the U-Boot, you need to use an arm-linux-gcc-4.3.2 compiler. If you have uncompressed and installed u-boots source code, please follow the steps below otherwise please refer to the users manual for details on how to install the souce code. #cd /opt/FriendlyARM/mini2440/bootloader/u-boot-1.1.6 #make open24x0_config #make
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 75 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems After the compilation is done, a u-boot.bin will be generated:

5.2.2 Downloading U-Boot to Board


To download a U-Boot to a target board, switch S2 to the Nor Flash side, connect the board to a host PC via USB, open a super terminal in the PC and turn on the boards power:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 76 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select a, run DNW, verify the USB connection is OK, select UsbPort -> Transmit/Restoreand open the generated u-boot.bin file, download and write will be done very soon. Switch the mini2440s boot mode to the Nand Flash, reset or power on the board, the following messages will show up in the opened super terminal. If the board has already been loaded with Linux, U-Boot will auto start the system, otherwise the system will go to the U-Boot main menu (or you can press any key within 3 seconds on system startup):

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 77 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

U-Boots main menu is as follows, you can test its functions. It is similar to a supervivi:

Note: to run U-Boot, you cannot run any supervivis functions in the Nor Flash and should only use U-Boots functions to download and write a Linux kernel and file system. You can search for more information about U-Boot on the internet.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 78 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Chapter 6 Configuring and Compiling a Linux Kernel


To compile a kernel, you need to configure a arm-linux-gcc-4.3.2 cross compiler, please refer to the users manual for setting up a cross compile environment

6.1 Configuring and Compiling a Kernel with Default Options


In order for users to compile a correct kernel that is the same as what is in the shipped CD, we provide various configuration files based on different LCDs: - config_mini2440_n35 for NEC3.5 LCD - config_mini2440_a70 for innolux7 LCD - config_mini2440_vga1024x768 for VGA (1024 x 768)

Run the command below to configure with the default file config_N35: #cp config_mini2440_n35 .config ; note: there is a space after n35 then followed by a .config Then run: #make menuconfig
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 79 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Just simply hit <Exit> and select Yes to save the settings. This will create a configuration file. Execute the command below to start compiling a kernel: #make zImage

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 80 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems After compilation is done, a zImage file will be generated in the arch/arm/boot directory.

6.2 Drivers Source Code


Note: uncompress the kernel source code (a tgz file beginning with linux-2.6.13), you will find the following drivers. The mini2440 system provides 100% workable drivers souce code for linux-2.6.29. Those drivers source code does not need extra libraries. (1)DM9000 Driver linux-2.6.29/drivers/net/dm9000.c (2)Serial Driver(including three serial port drivers 0, 1, 2 which correspond to the devices /dev/ttySAC0, 1, 2) linux-2.6.29/drivers/serial/s3c2410.c (3)RTC Driver linux-2.6.29/drivers/char/s3c2410-rtc.c (4)LED Driver linux-2.6.29/drivers/char/mini2440_leds.c (5)Keyboard Driver linux-2.6.29/drivers/char/mini2440_buttons.c (6)Touch Screen Driver linux-2.6.29/drivers/input/touchscreen/s3c2410_ts.c (7)yaffs File System Source Code Directory linux-2.6.29/fs/yaffs2 (8)USB Mouse and Keyboard Source Code
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 81 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems linux-2.6.29/drivers/usb/usb/hid (9)SD/MMC Card Driver Source Code Directory (it supports 32G SD cards) linux-2.6.29/drivers/mmc (10)Nand Flash Driver linux-2.6.29/drivers/mtd/nand (11)UDA1341 Sound Card Driver Directory linux-2.6.29/sound/soc/s3c24xx (12)LCD Driver linux-2.6.29/drivers/video/s3c2410fb.c (13)USB Storage Driver linux-2.6.29/drivers/usb/storage (14) USB Camera Driver linux-2.6.29/drivers/media/video/gspca (15) I2C-EEPROM Driver linux-2.6.29/drivers/i2c (16) Backlight Driver linux-2.6.29/drivers/video/mini2440_backlight.c (17)PWM Buzzer Driver linux-2.6.29/drivers/char/mini2440_pwm.c (18) Watchdog Driver linux-2.6.29/drivers/watchdog/s3c2410_wdt.c (19) AD Driver linux-2.6.29/drivers/char/mini2440_ad.c (20) CMOS Camera Driver linux-2.6.29/drivers/media/video/s3c2440camif.c (21)USB Wireless Network Driver (TL-WN321G+) linux-2.6.29/drivers/net/wireless/rt2x00 (22)USB to Serial Port linux-2.6.29/drivers/usb/serial/pl2302.c

6.3 Customizing Linux Kernel


In the previous section, the kernel was configured and compiled with default options. Actually the kernel offers various options. This section will present details for some of the most commonly used configurations. This will help users get familiar with the kernel configurations and compilation, and be able to customize the kernel based on their own requirements. Run make menuconfig and enter the main menu.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 82 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

6.3.1 Configuring CPU


In the main menu, select System Type and enter:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 83 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Most of the items are named S3C2410 this is because S3C2410 and S3C2440 have the same structures for most of the registers and addresses. linux-2.6 kernel doesnt differentiate these two CPU settings. If you want to customize the platform settings, you can enter the S3C2440 platform, and check the S3C2400 Machines submenu.

Then you will find there are multiple S3C2440 options.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 84 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

They are specified by the arch/arm/mach-s3c2410/mach-* files. Here the target board is mini2440, it is specified by mach-qq2440.c. In addition this file has a machine code MACH_TYPE, it is defined in arch/arm/tools/mach-types, and for the MINI2440 system it is 782, and it also defines MACH_TYPE in the include/platform/smdk2440.h file in vivi.

6.3.2 Configuring LCD


In the main menu, select Device Drivers and enter:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 85 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select Graphics support, enter and select:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 86 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems Select Backlight and enter:

Select LCD select, enter and select NEC3.5 LCD:

After this setting is done, enter, back to the previous menu and select <Exit> to return to
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 87 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems Device Drivers.

6.3.3 Configuring Touch Screen


Note: if you set VGA1024x768 as your display module, you dont need to configure this item. In the Device Drivers menu select Input device support and enter

Select Touchscreens and enter

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 88 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select <*>Samsung S3C2410 touchscreen input dirver

Select <Exit> to return to Input device support, and select <Exit> to return to Device Drivers

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 89 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

6.3.4 Configuring USB Mouse and Keyboard


In the Device Drivers menu, select the following item and enter:

Select the marked item as follows:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 90 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

This sets up the USB keyboard and mouse, select <Exit> to reurn to the Deice Drivers menu

6.3.5 Configuring USB Storage Drive


Because a USB drive operates via SCSI commands, the kernel needs to include support for SCSI. In the Device Drivers menu, select SCSI device support and enter

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 91 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select the marked item as follows:

Select <Exit> to return to Device Drivers, then select USB support and enter USB support:
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 92 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems Check the following options <*> USB Mass Storage support

Select <Exit> to return to Device Drivers

6.3.6 Configuring USB Camera


In the Device Drivers menu, select Multimedia devices and enter

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 93 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select the marked items and enter Video Capture Adapters:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 94 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems Check the marked item and enter:

Check the marked items and enter GSPCA based webcams:

Check the marked item as follows:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 95 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select <Exit> to return to Device Drivers, then select <Exit> to return to the main menu.

6.3.7 Configuring CMOS Camera


The CMOS camera CAM130 that works with the MINI2440 incorporates the OV9650 chip, please follow the steps below to configure its driver: In the Device Drivers menu, select Multimedia devices and enter:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 96 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select the * marked item and Video capture adapters, enter and check the OV9650 option:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 97 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Note: the driver we wrote for CAM130 belongs to neither the VL4 system nor the V4L2 system. It is just a char device. The purpose is for easy migration.

6.3.8 Configuring Network Card


Before configure the network card driver, you need to configure the network protocol. In the main menu, select Netwoking support and enter

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 98 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select Networking options, enter and check the options below:

In general, just select TCP/IP, but it is recommended to check all the items shown above Exit all the way to the main menu and enter Device Drivers
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 99 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems Select Network device support and enter

Select and enter Ethernet (10 or 100Mbit)

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 100 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select the items below <*> DM9000 support <*> Generic Media Independent Interface device support

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 101 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select <Exit> all the way to return to Device Drivers

6.3.9 Configuring Wireless Network Card


The linux-2.6.29 kernel already has support for various USB wireless network card. Here we chose the TP-Links TL-WN321G+. In the main menu, select Netwoking support and enter:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 102 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Check the wireless option and enter

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 103 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Check the marked items shown below:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 104 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Exit all the way to the main menu and enter Device Drivers. Select Network device support and enter

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 105 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select the Wireless LAN and enter:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 106 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Check the driver for TL-WN321G+

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 107 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 108 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Exit all the way to Device Drivers.

6.3.10 Configuring Sound Card Driver


In the Device Drivers menu, select Sound card supprt and enter

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 109 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Check the marked option and enter:

Select ALSA for Soc audio support and enter:


Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 110 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Check the marked options as follows:

Exit all the way to Device Drivers.


Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 111 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

6.3.11 Configuring SD/MMC Card Driver


In Device Drivers, select and enter MMC/SD/SDIO Card support - - ->, select the items shown below

Check the marked options as follows:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 112 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Exit all the way to Device Drivers.

6.3.12 Configuring Watchdog Driver


In the Device Drivers menu, select Watchdog and enter:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 113 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select the marked item as follows:

Exit all the way to Device Drivers.


Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 114 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

6.3.13 Configuring LED Driver


In Device Drivers, select and enter Character devices - - ->, check the driver options to support LEDs and check the marked item shown below:

6.3.14 Configuring Keyboard Driver


In Device Drivers, select and enter Character devices - - ->, check Buttons

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 115 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

6.3.15 Configuring PWM Buzzer Driver


In Character devices, select and enter Buzzer:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 116 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

6.3.16 Configuring ADC Driver


In Device Drivers, select and enter ADC driver:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 117 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

6.3.17 Configuring Serial Port Driver


In Character devices, select and enter Serial drivers - - ->:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 118 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Check the marked options as follows:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 119 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

6.3.18 Configuring RTC Driver


In Character devices, select the driver support for Real Time Clock as below

Check the marked options as follows:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 120 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Return to the main menu


Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 121 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

6.3.19 Configuring I2C-EEPROM Driver


In the Device Drivers menu, check the I2C support and enter:

Check the items shown below and enter the I2C Hardware Bus support submenu:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 122 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Select S3C2410 I2C Driver:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 123 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

6.3.20 Configuring Support for YAFFS2


In order to use the yaffs2 file system, you need to have nand flash support. In the Device drivers menu, check the marked items below:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 124 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Check the marked items as below

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 125 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems Select the Nand Device Support and enter:

Check the Nand Flash support:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 126 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Return to File systems

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 127 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems Select Miscellaneous filesystems and enter:

Check the marked items below:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 128 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems Exit all the way to File systems.

6.3.21 Configuring Support for EXT2/VFAT/NFS


In File System, select Network File Systems and enter

Check the marked items as follows:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 129 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

To support the FAT32 file system that SD cards and USB drives need, you need to select correspoinding items as follows, and enter DOS/FAT/NT Filesystems:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 130 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems You need to select VFAT which supports FAT32:

Exit all the way to the main menu. So far, this section has gone through most of the commonly used configurations and settings, you will be more proficient in kernel configurations as you go deeper into Linux development and get more experience in practice.

6.3.22 Making Linux Logo


When you start your Linux, you will see a pic like below on the screen:

The above lovely animal is the logo of linux-2.6.29, the letters were added by FriendlyARM. This Linux logo is linux-2.6.29/drivers/video/logo/linux_logo_clut224.ppm.It is a special formatted image file. There are many ways to convert an image file to a logo. FriendlyARM created
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 131 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems an easy tool LogoMaker which is based on Fedora 9 and supports files such as bmp, png, jpg and so on. Please ensure that you have installed the LogoMaker (please refer to the users manual). Type logomaker in a command line to start it. By default, it will show the following picture.

Go to File->Open a picture file or press the shortcut key Ctrl+O to open an image file:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 132 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

The file you select will be loaded in the window:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 133 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Go to File->Convert the picture to a Linux Logo File, or press the shortcut key Crtl+C, a file save window will pop up. You just need to select a destination fold, and the file will be saved as linux_logo_clut224.ppm. You can use this to replace the logo file in the linux-2.6.29/drivers/video/logo directory.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 134 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Go to help->About, you can learn more about it.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 135 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 136 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Chapter 7 Building a File System


7.1 Building YAFFS2 Root File System
Note: please make sure you have installed the tool mkyaffs2image. In this section, we will take root_qtopia.img as an example to present how to make a yaffs2 file system. Enter the /opt/FriendlyARM/mini2440 directory and run the commands below: #cd /opt/FriendlyARM/mini2440 #mkyaffs2image root_qtopia root_qtopia.img

After executing the command a root_qtopia.img image file will be generated in the current directory. Then download and write this image file to a target board.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 137 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Chapter 8 Embedded QT Development


Note: to install Qt/Embedded, you must install Fedaro 9.0 and a cross compiler arm-linux-gcc-4.3.2. Please refer to the users manual for installation details.

8.1 Compiling X86 Based Qtopia, Hello, World and Embedded Browser
It is a complicated process to configure and compile Qt/Embedded. For the sake of users, Friendly Arm has made a build script which includes the whole configuration and compilation details.

8.1.1 Compiling Qt/Embedded


#cd /opt/FriendlyARM/mini2440/x86-qtopia #./build-all (This build process might take as long as 30 minutes) Note: ./build-all will auto compile a complete Qtopia and an embedded browser. Alternatively you can execute ./build and ./build-konq to compile them separately.

8.1.2 Running Qtopia on a Simulation Platform in PC


To run the Qtopia is very simply, just type the command below in the same command line window you will see: #./run

Follow the prompts clicking on run, you will see the following screenshot:
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 138 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

8.1.3 Compiling Hello, World


#cd /opt/FriendlyARM/mini2440/x86-qtopia/hello #./build Executing ./build will generate a hello executable in the /opt/FriendlyARM/mini2440/x86-qtopia/qtopia-2.2.0-FriendlyARM/qtopia/bin directory Note: build is a script. Its content is as follows: #!/bin/bash source /opt/FriendlyARM/mini2440/x86-qtopia/qtopia-2.2.0-FriendlyARM/setQpeEnv qmake -o Makefile -spec /opt/FriendlyARM/mini2440/x86-qtopia/qtopia-2.2.0-FriendlyARM/qtopia/mkspecs/qws/linux-gen eric-g++ *.pro make clean make Comments: source is similar to sh, it executes the setQpeEnv script to set the Qtopia compile environment. Qmake generates a Makefile based on the rules defined in the hello.pro file. The hello.pro file is manually edited. Executing make (which will generate a Makefile) to compile the hello source code. Below is the setQpeEnv file: export QPEDIR=/opt/FriendlyARM/mini2440/x86-qtopia/qtopia-2.2.0-FriendlyARM/qtopia
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 139 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems export QTOPIA_DEPOT_PATH=/opt/FriendlyARM/mini2440/x86-qtopia/qtopia-2.2.0-FriendlyARM/qto pia export QTDIR=/opt/FriendlyARM/mini2440/x86-qtopia/qtopia-2.2.0-FriendlyARM/qt2 export DQTDIR=/opt/FriendlyARM/mini2440/x86-qtopia/qtopia-2.2.0-FriendlyARM/dqt export TMAKEDIR=/opt/FriendlyARM/mini2440/x86-qtopia/qtopia-2.2.0-FriendlyARM/tmake export TMAKEPATH=$TMAKEDIR/lib/qws/linux-generic-g++ export PATH=$QPEDIR/bin:$QTDIR/bin:$DQTDIR/bin:$PATH export LD_LIBRARY_PATH=$QPEDIR/lib:$QTDIR/lib:$DQTDIR/lib:$LD_LIBRARY_PATH

8.1.4 Running Hello, World


After compiling the program, execute ./run you will see the following result.

Note: the run script is as follows:


#!/bin/sh ../qtopia-2.2.0-FriendlyARM/qt2/bin/qvfb -width 240 -height 320 -depth 16 & #export CAMERA_DEVICE=/dev/video1 #qtopia-2.2.0-FrinedlyARM/qt2/bin/qvfb -width 640 -height 480 -depth 16 & Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 140 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems


cd ../qtopia-2.2.0-FriendlyARM/qtopia/image mkdir root 2>/dev/null || true export HOME=$PWD/root cd opt/Qtopia export PATH=$PWD/bin:$PATH export LD_LIBRARY_PATH=$PWD/lib:$LD_LIBARAY_PATH export QTDIR=$PWD export QPEDIR=$PWD export KDEDIR=$PWD/../kde sleep 3 hello qws

To run hello, it firstly starts qvfb, then configures some environmental variables for Qtopia, and finally starts hello.

8.2 Compiling ARM Based Qtopia, Hello, World and Embedded Browser
Note: please compile an ARM based Qtopia with the arm-linux-gcc-4.3.2.tgz in the shipped CD otherwise it may not pass compilation! It is a complicated process to configure and compile Qt/Embedded. For the sake of users, Friendly Arm has made a build script which includes the whole configuration and compilation details.

8.2.1 Compiling Qt/Embedded


#cd /opt/FriendlyARM/mini2440/arm-qtopia #./build-all (This process might takes as long as 30 minutes) #./mktarget (It generates a compressed browser package target_qtopia_konq.tgz) Note: ./build-all will auto compile a complete Qtopia and an embedded browser, and generate compatible Jpeg GIF PNG images. Alternatively, you can execute ./build and ./build-konq to compile them separately.

8.2.2 Compiling Hello, World


#cd /opt/FriendlyARM/mini2440/arm-qtopia #./build
Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 141 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems Running build will generate a makefile, compile and create an executable in the /opt/FriendlyARM/mini2440/arm-qtopia/qtopia-2.2.0-FriendlyARM/qtopia/bin directory. build is a script as follows: #!/bin/bash source /opt/FriendlyARM/mini2440/arm-qtopia/qtopia-2.2.0-FriendlyARM/setQpeEnv qmake -spec /opt/FriendlyARM/mini2440/arm-qtopia/qtopia-2.2.0-FriendlyARM/qtopia/mkspecs/qws/linux-arm -g++ -o Makefile *.pro make clean make Comments: source is similar to sh, it executes the setQpeEnv script to set the Qtopia compile environment. Qmake generates a Makefile based on the rules defined in the hello.pro file. The hello.pro file is manually edited. Executing make (which will generate a Makefile) to compile the hello source code. Below is the setQpeEnv file: export QPEDIR=/opt/FriendlyARM/mini2440/arm-qtopia/qtopia-2.2.0-FriendlyARM/qtopia export QTOPIA_DEPOT_PATH=/opt/FriendlyARM/mini2440/arm-qtopia/qtopia-2.2.0-FriendlyARM/qto pia export QTDIR=/opt/FriendlyARM/mini2440/arm-qtopia/qtopia-2.2.0-FriendlyARM/qt2 export DQTDIR=/opt/FriendlyARM/mini2440/arm-qtopia/qtopia-2.2.0-FriendlyARM/dqt export TMAKEDIR=/opt/FriendlyARM/mini2440/arm-qtopia/qtopia-2.2.0-FriendlyARM/tmake export TMAKEPATH=$TMAKEDIR/lib/qws/linux-arm-g++ export PATH=$QPEDIR/bin:$QTDIR/bin:$DQTDIR/bin:$PATH export LD_LIBRARY_PATH=$QPEDIR/lib:$QTDIR/lib:$DQTDIR/lib:$LD_LIBRARY_PATH

8.2.3 Downloading and Running Hello, World on Board


Copy Files to the Windows Directory Copy the created hello executable to a Windows directory, and the hello/hello.desktop to a Windows directory. Download Files to Board with rz Open a terminal in the target board and run rz to begin receiving files from the host.

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 142 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Click on the mouses right button, select Send Files in the pop up menu, select the hello file and begin to send

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 143 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

In the popup window below, select the hello file and begin to send

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 144 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Download the hello.desktop file to the board. Change the File Mode of the hello File The files downloaded to the board dont have the executable right. Run chmod to add the executable mode to these files and put them in a destination directory #chmod +x hello #mv hello /opt/qtopia/bin #mv hello.desktop /opt/qtopia/apps/Applications

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 145 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

High Performance Low Cost Embedded Systems

Run hello on the Board Reset or power on qtopia, a hello icon will appear. Click on the icon to run it:

Copy right reserved MicroArm Systems, Inc. 1612 2nd Ave. SW PMB#108, Cullman, AL 35055, U.S.A. - - 146 - Website: www.microarmsystems.com Email: service@microarmsystems.com Phone: 1-888-417-9266

You might also like