Escolar Documentos
Profissional Documentos
Cultura Documentos
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
. 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
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
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
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
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
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 #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.
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.
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
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
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
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.
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
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.
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
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
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
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
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
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
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 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.");
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
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
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
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
A vivi will be generated in the current directory. Download it to a target boards Nand Flash.
High Performance Low Cost Embedded Systems After the compilation is done, a u-boot.bin will be generated:
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
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
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
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
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.
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
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
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
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.
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.
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
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:
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
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
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
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
This sets up the USB keyboard and mouse, select <Exit> to reurn to the Deice Drivers menu
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
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
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
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:
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
Select <Exit> to return to Device Drivers, then select <Exit> to return to the main menu.
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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:
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
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:
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.
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
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.
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
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
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
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
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
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
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.
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 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
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.
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
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
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
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
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
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