Build a web server with B0 and uClinux

Source: Internet
Author: User
Tags compact
Build a web server with B0 and uClinux
 
Released on: Views: 195 Author: Xu Ming Source: PLC & fa
 

Keywords: arm uClinux Web Server

1 Introduction
With the rapid development of the Internet in the world, network technology is widely used in a variety of enterprises and industrial systems, more and more information products need to be able to access the Internet through web pages for remote access and control. Embedded Web servers are a hot topic in the study of embedded [1]. They can be widely used in industrial equipment, automated agriculture, information-based household appliances, and remote monitoring and alarm systems. Currently, nearly half of the embedded systems under development use Linux as the embedded operating system, while uClinux is a standard Linux kernel, highly optimized and compact embedded Linux [2]. It retains most of the advantages of Linux and has good portability and excellent network functions. At present, Web Servers Based on Samsung s3.4510b and uClinux have been implemented, but the implementation of Web Servers Based on s3.44b0 and uClinux is rare. In this paper, the network port control chip rtl8da-as is connected to the B0 to achieve hardware design. The software design is realized by compiling the source code of uClinux and Boa Server and compiling the CGI gateway interface program, based on the Boa Server and dynamic web page CGI gateway interface in uClinux, you can enter the IP address of the Development Board in a browser to dynamically access the web page on the Development Board.

2 hardware solution implementation
The core of the arm Development Board designed in this article is Samsung's-bit CPU, which is based on ARM7TDMI [3]. It is one of the 32-bit embedded processors with high cost performance. The B0 chip contains an 8 K high-speed cache device that uses a 66mhz and a single-cycle command processor (ARM7TDMI, 2-channel universal DMA, 2-channel peripheral DMA with external request pins, 2-channel UART with handshake protocol, 11-channel SiO2, 1-channel multi-master IIC-BUS controller, 5 PWM timers, 71 and can be seamlessly connected to common peripheral devices, this simplifies the design of peripheral circuits and reduces product costs, volumes, and power consumption. The self-designed development board in this article uses 16 msdram and 2 mflash memory architecture. The Flash model is sst39vf160, which is mainly used to store BIOS programs, uClinux kernel images, and romfs file systems. SDRAM uses two pieces of hy57v641620 to form a 16 m, 32-bit system primary memory. For peripherals, The cs4334 chip is used for audio extension, and the PDIUSBD12 chip is used to expand a USB interface. The serial port control chip uses the common maxcompute, the network port control chip uses RealTek's rtl8da-as to expand 1 10/100 M Nic device. The Development Board framework 1 is shown below:

Figure 1 Overall Development Board framework
3. Software Design
3.1 transplantation of uClinux on B0
This development board uses uClinux as the operating system. uClinux is specially designed for CPUs without MMU and is suitable for embedded system miniaturization applications. After modifying the standard Linux kernel, uClinux has formed a highly optimized and compact embedded Linux. uClinux retains most of the advantages of Linux: stability, good portability, and excellent network functions, complete support for various file systems and a wide range of standard APIs. In addition, the applications developed on uClinux are highly portable and easy to upgrade. Therefore, uClinux is used as the embedded operating system. The transplantation process for the uClinux kernel on the B0 is as follows:
Compile the source code first, download a uclinuxsource code from the Internet, which is generally a compressed format (tar.gz), decompress it, generate a uClinux-Dist directory under the current directory, enter the uClinux-Dist directory, and then type
(1) make menuconfig
Tools
(2) Make clean clears all compilation results
(3) make Dep sets the file dependency
(4) Make lib_only: Compile the library file
(5) Make user_only compile the application
(6) Make romfs compile the File System
(7) make image to generate an image file
(8) Make completes the entire compilation process
After the compilation is complete, three files are generated under the image, image. Ram, image. Rom, and romfs. IMG. Download image. Rom to 0x0 in the flash of the system board using the TFTP tool through the network port, power on the Command provided by BIOS, and uClinux starts from SDRAM to complete the transplantation process [4-5].
3.2 uClinux-based Web technology implementation
(1) how the Web server works [6-7]
As a data carrier, the web server can transmit local information and data over the network to remote clients who send requests. This is of great significance in the implementation of remote monitoring. The Web server listens to the services of the user end and provides the corresponding services according to the type of user requests. The client uses a web browser to communicate with the Web server. After receiving a request from the user end, the Web server processes the request and returns the required data. A complete HTTP transaction is generally composed of the following four phases:
L The customer establishes a TCP connection with the server;
L The customer sends a request to the server;

L if the request is accepted, the server sends a response, which includes the status code and the desired file;
L close the connection between the customer and the server.
(2) Implementation of Web servers in uClinux
Essentially, a Web server is a program running behind a computer, waiting for various requests from a Web browser. When a request is received, it replies with the requested document or error message. Most Web servers provide backend technologies, such as CGI, which can connect web servers with existing applications to provide interactive activities and information retrieval.
In uClinux, there are three main Web servers: httpd, thttpd, and boa. Httpd [9] is the simplest web server with the weakest function. It does not support authentication or CGI. Both the thttpd Web server and the Boa web server support authentication, CGI, and other functions. This development board selects the Boa web server suitable for embedded applications. Boa is an HTTP server for a single task, with open source code and high performance. The main difference between it and the traditional server is that it is a single process. When receiving a new httpd request, it does not fork a new process to respond, and cannot process each incoming connection, in addition, you cannot copy multiple copies to process multiple connections. It processes all ongoing HTTP connection requests internally, and requests fork new processes only for separate CGI programs, automatic file generation, automatic file decompression, and other requests. It has the advantages of simple code, fast speed, and is suitable for embedded applications. For embedded systems, Web servers are designed to use WWW browsers to allow users to access and control embedded system devices through LAN or WAN. You can write different HTML pages and use CGI technology to complete various flexible and friendly interaction functions. To implement BOA in uClinux, this article makes several modifications to the BOA. conf and mime. types files:
(1) because the root file system is read-only and mkdir cannot be used to create a directory, you must create a directory before compiling the kernel, set the root directory of the Web server to/home/and the root directory of the server document to/home/httpd, place the CGI program that implements the dynamic web page function in the/home/httpd/cgi-bin/directory. These directories are created by modifying the makefile of the development platform. Add home/httpd/cgi-bin in romfs_dirs = bin Dev etc home lib MNT proc USR var. After the preceding kernel compilation steps are completed, the root file system contains the newly created directories.
(2) Specify the root directory path of the web server, go to the uClinux-Dist/user/BOA/src/directory, and modify define. # define server_root/home statement in the H file to specify server_root. Modify boa. CONF file in uClinux-Dist/user/BOA/src/boa. change User nobody, group nogroup to user 0, group 0, document root/var/WWW to DocumentRoot/home/httpd in Conf, and define the directory of the default homepage and CGI program, that is:
Directoryindex index.html, ScriptAlias/cgi-bin // home/httpd/cgi-bin/Mini. type does not need to be modified. Boa. conf and Mini. types must be placed in the root directory of the Web server to put the modified boa. conf and Mini. copy types to uClinux-Dist/romfs/home, modify uClinux-Dist/vendors/Samsung/4510b/inittab, and add BOA to Inet: unknow/bin/inetd: unknown/bin/boa c/home. After this configuration, the root directory of the Web server is/home/httpd. The httpd directory contains files accessible to the Web server, including HTML web pages and jpg images. The files stored in the/home/httpddirectory are exactly the same as those in the website file. In this example, index.html is the default homepage value seen by the remote client when accessing the web server, you can use a hyperlink to link to the/romfs/home/httpd directory and all static webpages in all its subdirectories. To implement dynamic web pages, you can only use CGI, because uClinux currently does not support ASP, PHP, and other technologies. CGI is a universal gateway interface. It is a standard interface for external services of the WWW server host. Generally, the function of a CGI interface is to transmit information between Hypertext and server host applications. Currently, the most popular CGI [10] programming languages are C, Shell, Perl, and Visual Basic. The CGI program is an external program and needs to be compiled into an executable file to run on the server. Its application flowchart 2 shows:

Figure 2 CGI program flowchart

Figure 3 embedded webpage in uClinux

Figure 4 led demo program interface
The browser sends user input data to the Web server, and the Web server sends the data to the CGI program using stdin. After executing the CGI program, some documents storing the data may be accessed, finally, stdout is used to output the HTML result file, which is sent back to the browser by the Web server and displayed to the user.
This article uses the C language to compile the CGI program, compile it into a binary file and put it in the/cgi-bin/directory. Because the CGI directory of the BOA server is configured earlier, scriptAlias/cgi-bin/home/httpd/cgi-bin/, so the CGI program under the/cgi-bin/directory can be correctly executed. After the configuration is complete, re-compile the kernel. When compiling, select the boa option to download the compiled kernel to the Development Board. Start uClinux to complete the IP configuration. After the Boa web server is started, you can browse the Web page through the browser, if you want to automatically start the Boa web server when you start uClinux, you can modify the RC file to go to uClinux-Dist/vendors/Samsung/4510b, add boa c/home/& modification to the running script, re-compile the kernel, and then download it to the Development Board for running. After running uClinux, you can access the webpage. The following uses an example to illustrate how to implement dynamic web page technology in uClinux. First use HTML to compile the embedded web page (3), then click the hyperlink of the LED demo program on the embedded home page to go to the next page of the web page (4 ), the action attribute specifies the CGI program to be used, that is, action =/cgi-bin/led. CGI. The method attribute indicates the submission method used, that is, method = post.
Select the LED check box and click set to control the light-emitting second-level tube on the Development Board. It indicates that the Boa Server in uClinux has run successfully.

4 Conclusion
In this paper, through the implementation of hardware solutions, software design, and the implementation of web technology in uClinux, A Boa Server is implemented based on B0 and uClinux. By starting the boa server on the Development Board, you can enter an IP address on the Development Board in a PC browser to access the embedded static webpage in the Development Board, the dynamic display of the web page is realized, and the running of the BOA server is verified through an experiment using a lamp control example. The embedded web server implemented in this article has a strong universality and can run efficiently on the embedded development platform, with a promising prospect.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.