嵌入式web server——Goahead移植要点

前言

在嵌入式设备中,在没有液晶显示的状况下,可使用web来访问设备,查看设备的运行状态以及进行参数设置,相似于路由器设置。网上有不少关于各类web server的优劣的评论,在此不讨论,只是介绍其中的Goahead在linux下移植的一些要点。css

 

移植环境

goahead-3.4.9html

arm + linux 2.6,交叉编译器arm-uclibc-gcclinux

 

移植要点

一、把src目录下的certs、utils、goahead-openssl目录都删除掉。git

二、把osdep里面的osdep.h移到外层src去。web

三、把goahead-linux-default-me.h拷到src目录,更名为me.h。浏览器

四、配置me.h,在开头添加两行,表示运行的环境。bash

#define __arm__       1
#define __linux__     1

五、不须要SSL,把me.h中两个宏都置为0。服务器

#define ME_COM_OPENSSL 0
#define ME_COM_SSL 0

六、须要打印更多运行信息,把me.h中把宏ME_GOAHEAD_LOGFILE由stderr:0改成stderr:2。ui

#define ME_GOAHEAD_LOGFILE "stderr:0"
#define ME_GOAHEAD_LOGFILE "stderr:2"

七、setLocalHost中调用gethostbyname多是失败的,致使运行不起来,直接不调用了。this

八、route.txt须要改一下,把route uri=/cgi-bin handler=cgi 改成route uri=/cgi-bin dir=./web handler=cgi,表示cgi-bin目录在web目录下。

九、cgiHandler中要注释掉chdir(dir);,要不找不到cgi-bin下的程序,这样查找cgi程序时使用相对路径。

十、编写makefile,编译出来可执行文件goahead。

CC=arm-uclibc-gcc

#CC=gcc
 
#-Werror

FLAGS = -Wall -fPIC -g -O2 -s -ldl -lm -o
 
SOURCE_FILE = *.c

goahead: $(SOURCE_FILE)

         $(CC) $(FLAGS)  $@  $(SOURCE_FILE)

clean:

         rm -rf goahead

.PHONY: clean

十一、布署,建立目录/mnt/goahead,把编译出来的可执行程序goahead放在此目录下,goahead目录下再建立web目录,此目录存放一些网页相关的内容(如index.html,css,image等),在web目录下再建立cgi-bin目录,用于存放cgi程序。

十二、./goahead执行可看到以下信息表示运行成功

goahead: 1: This system does not have IPv6 support

goahead: 2: Configuration for Embedthis GoAhead

goahead: 2: ---------------------------------------------

goahead: 2: Version:            3.4.9

goahead: 2: BuildType:          Debug

goahead: 2: CPU:                arm

goahead: 2: OS:                 linux

goahead: 2: Host:               0.0.0.0

goahead: 2: Directory:          /mnt/goahead

goahead: 2: Documents:          web

goahead: 2: Configure:          me -d -q -platform linux-x86-default -configure . -with openssl -gen make

goahead: 2: ---------------------------------------------

goahead: 2: Started http://*:80

goahead: 2:

^^^^^^^^^^^ web start successful ^^^^^^^^^^^

1三、在浏览器中输入ip便可看到,请求goahead的cgitest程序时,可见服务器的打印信息goahead: 2: GET /cgi-bin/cgitest HTTP/1.1,浏览器上显示的页面以下图所示。

 

 

附移植到vxworks

因为产品中还有vxworks平台,因此也曾移植到vxworks平台,移植的要点和linux下差很少,把goahead-vxworks-default-me.h复制到src目录下,改成me.h,并加上几个关键的宏定义便可。

#ifndef VXWORKS
    #define VXWORKS 1
#endif
    
#ifndef OS
    #define OS "VXWORKS"
#endif

#ifndef WEBS
    #define WEBS 1
#endif

#ifndef UEMF
    #define UEMF 1
#endif

#ifndef __mips__
    #define __mips__ 1
#endif
相关文章
相关标签/搜索