移植嵌入式 Boa web server到TI 达芬奇平台

陆续记录移植过程。

1.下载Boa源码

a.到 http://www.boa.org/ 下载boa源码,目前最新版本为:0.94.13
b.在主机上解压下载到的源码压缩包boa-0.94.13.tar.gz,执行:tar xzf boa-0.94.13.tar.gz

2.生成makefile文件

以上步骤解压后的目录为:boa-0.94.13
进入src目录:cd src
运行configure文件:./configure
看看到主机终端有以下信息输出:
creating cache ./config.cache
checking for gunzip... /bin/gunzip
checking for flex... flex
checking for yywrap in -lfl... yes
checking for bison... bison -y
checking for gcc... gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
checking how to run the C preprocessor... gcc -E
checking whether make sets ${MAKE}... yes
checking for dirent.h that defines DIR... yes
checking for opendir in -ldir... no
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for fcntl.h... yes
checking for sys/fcntl.h... yes
checking for limits.h... yes
checking for sys/time.h... yes
checking for sys/select.h... yes
checking for getopt.h... yes
checking for working const... yes
checking for uid_t in sys/types.h... yes
checking for pid_t... yes
checking whether time.h and sys/time.h may both be included... yes
checking whether setvbuf arguments are reversed... no
checking for unistd.h... yes
checking for getpagesize... yes
checking for working mmap... yes
checking for getcwd... yes
checking for strdup... yes
checking for strstr... yes
checking for gethostname... yes
checking for gethostbyname... yes
checking for select... yes
checking for socket... yes
checking for inet_aton... yes
checking for scandir... yes
checking for alphasort... yes
checking for tm.tm_gmtoff... yes
checking for tm.tm_zone... yes
checking for sockaddr_in.sin_len... no
checking compile and link profiling code... no
checking whether to compile and link debugging code... yes
checking whether to link with the Dmalloc memory debugger/profiler... no
checking whether to link with the Electric Fence memory debugger... no
updating cache ./config.cache
creating ./config.status
creating Makefile
creating config.h
可见makefile文件已经成功生成。

3.作编译前的一些修改

主要是为了修正编译过程中会出现的错误
(1)修改 src/compat.h
找到
#define  TIMEZONE_OFFSET(foo)      foo##->tm_gmtoff
修改为
#define  TIMEZONE_OFFSET(foo)      (foo)->tm_gmtoff
如果不作以上修改,编译时会出现以下错误:
util.c:100:1: error: pasting "t" and "->" does not give a valid preprocessing token
(2)修改src/log.c
在函数中void open_logs(void) 注释掉:
        if (dup2(error_log, STDERR_FILENO) == -1) {
            DIE("unable to dup2 the error log");
        }
即改为:
        /*if (dup2(error_log, STDERR_FILENO) == -1) {
            DIE("unable to dup2 the error log");
        }*/
此修改主要是修正运行boa时出现的以下错误:
log.c:73 - unable to dup2 the error log: Bad file descriptor
注:此修改主要是修正将log重定向到log文件出现的错误问题,如果按照以上修改,则没有重定向功能,即没有了错误日志查询,所有的错误信息都会打印在终端控制台上。
boa日志有两部分,为errorlog和access_log,日志文件一般位于var/log/boa/error_log和var/log/boa/access_log(见下文提及的boa.conf),如果这里不对src/log.c文件进行修改,则第一需要下文配置boa.conf中修改errorlog和access_log的路径配置,第二保证boa.conf指定的user和group均对日志所在目录有读写权限。
(3)修改 src/boa.c
在函数static void drop_privs(void)中,
注释掉:
        if (passwdbuf == NULL) {
            DIE("getpwuid");
        }
        if (initgroups(passwdbuf->pw_name, passwdbuf->pw_gid) == -1) {
            DIE("initgroups");
        }
即修改为:
#if 0
        if (passwdbuf == NULL) {
            DIE("getpwuid");
        }
        if (initgroups(passwdbuf->pw_name, passwdbuf->pw_gid) == -1) {
            DIE("initgroups");
        }
#endif
此修改主要防止运行boa时出现的一下错误:
boa.c:211 - getpwuid:No such file or direactory
注释掉
        if (setuid(0) != -1) {
            DIE("icky Linux kernel bug!");
        }
即修改为:
#if 0
        if (setuid(0) != -1) {
            DIE("icky Linux kernel bug!");
        }
#endif
此修改主要防止运行boa时出现的一下错误:
 boa.c:226 - icky Linux kernel bug!: No such file or directory

4.修改makefile

修改步骤2生成的makefile,主要是更改使用嵌入式交叉编译工具链进行编译。修改之前务必在主机上添加必要的环境变量,使得编译boa时,能找到主机上的交叉工具链位置。
CC = gcc 
CPP = gcc -E
修改为:
CC = arm-arago-linux-gnueabi-gcc 
CPP = arm-arago-linux-gnueabi-gcc -E

5.编译

在src目录编译,运行命令:make
没意外的话会在src目录生成boa文件。

6.去除调试信息

步骤5中生成的boa包含调试信息,文件较大,为减少对嵌入式设备的资源消耗,在这里去除其调试信息。
去除调试信息前查看boa信息
ls -l boa
-rwxr-xr-x 1 vincent vincent 208275 2013-05-10 10:51 boa
执行命令去除调试信息;
arm-arago-linux-gnueabi-strip boa
再次查看boa信息
ls -l boa
-rwxr-xr-x 1 vincent vincent 62760 2013-05-10 11:18 boa
OK,boa精简了好多好多。

7.配置与构建

在嵌入式平台根文件系统下建立运行boa时需要的一些目录:
依次新建如下目录
/etc/boa
/etc/boa/www
/etc/boa/www/cgi-bin
将上面编译后生成的boa拷贝到新建的目录/etc/boa下。
将boa源码跟目录下的boa.conf拷贝到新建的目录/etc/boa下。
注:boa.conf的位置是由boa源码中src/defines.h的宏SERVER_ROOT确定的,默认是在etc/boa下,若想存放其他位置,有两种方法,一在编译boa前修改defines.h
二在运行boa时通过-c参数项指定boa.conf文件位置。
修改拷贝后的boa.conf (etc/boa/boa.conf),修改项如下:
(1)修改 User nobody 为:User 0
(2)修改 Group nogroup为:Group 0
PS:以上的修改原则是根据嵌入式linux用户和用户组修改的,一般修改为0没问题,root用户嘛。
(3)修改 ScriptAlias /cgi-bin/    /usr/lib/cgi-bin/
          为:ScriptAlias /cgi-bin/    /etc/boa/www/cgi-bin/
(4)修改DocumentRoot /var/www
         为DocumentRoot /etc/boa/www
(5)修改#ServerName www.your.org.here
          为ServerName www.your.org.here
(6)修改AccessLog /var/log/boa/access_log 和 errorLog /var/log/boa/error_log
          为:AccessLog /你的目录 和 errorLog /你的目录
         并确认你的嵌入式设备的根文件系统有这些目录,如果没有要手动创建,日志文件不用建,运行boa时它会自动建。
注::如果在上面3中未对src/log.c文件修改,则一定要作此步骤修改,如果上面3中修改了src/boa.c则这里只需屏蔽掉即可(就是在前面加#)。

8.运行测试

将一个静态网页重命名为:index.html 拷贝到嵌入式平台根文件系统的/etc/boa/www下。
启动嵌入式设备,运行boa
./etc/boa/boa
如果修改删除了步骤3中的日志重定向问题,则在串口控制台中会看到华丽的启动信息
root@OMAP3EVM:/# [01/Jan/2000:00:13:54 +0000] boa: server version Boa/0.94.13
[01/Jan/2000:00:13:54 +0000] boa: server built May 10 2013 at 13:59:37.
[01/Jan/2000:00:13:54 +0000] boa: starting server pid=611, port 80
如果未修改删除步骤3中的日志重定向,则启动boa时候没有启动信息输出到串口控制台上,可以去cat你的error_log查看启动信息。
ifconfig查看嵌入式设备的IP,及web server IP,
eth0      Link encap:Ethernet  HWaddr 00:24:BA:ED:58:CA  
          inet addr:192.168.188.165  Bcast:192.168.188.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12027 errors:0 dropped:5 overruns:0 frame:0
          TX packets:4822 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4823486 (4.5 MiB)  TX bytes:799473 (780.7 KiB)
          Interrupt:61 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
IP为:192.168.188.165
果断地打开一个PC浏览器,在地址栏输入:http://192.168.188.165没出意外的话应该可以看到上面拷贝到/etc/boa/www的静态网页。







你可能感兴趣的:(移植嵌入式 Boa web server到TI 达芬奇平台)