Mobile & Embedded System Lab. Dept. of Computer Engineering Kyung Hee Univ.
GoAhead Porting Goahead 웹서버를포팅하기위하여 CD 안의소스를사용 경로 : [CD3]\source\webserver\webs218.tar.gz GoAhead 소스복사및압축해제 ~/working 디렉터리에배포 CD에서제공하는웹서버소스를복사한후에소스를압축해제 ws031202라는디렉터리가생성되고, 그안에들어가면여러가지플랫폼에해당하는디렉터리가각각존재 LINUX 디렉터리로이동 root@ubuntu:# cp /media/sm5-linux-111031/source/webserver/we bs218.tar.gz ~/working root@ubuntu:# cd ~/working root@ubuntu:~/working# tar xzvf webs218.tar.gz root@ubuntu:~/working# cd ws031202/linux/ 2
GoAhead Porting GoAhead 컴파일을위한소스수정 Makefile 을다음과같이수정 root@ubuntu:~/working/ws031202/linux# vi Makefile ------------------------ 다음과같이수정한다 ------------------- -- # 크로스컴파일을하기위해서 컴파일러 와 라이브러리빌더 를추가한다. 14 15 CC=arm-linux-gcc 16 AR=arm-linux-ar 17 # 마지막줄에서 cc를 $(CC) 로바꾼다. 158 $(CC) -c -o $@ $(DEBUG) $(CFLAGS) $(IFLAGS) $< ----------------------- 저장하고종료한다 ----------------------- - 3
GoAhead Porting main.c 파일수정 root@ubuntu:~/working/ws031202/linux# vi main.c -------------------------- 다음과같이수정한다 --------------- ---------- 24 #include <sys/types.h> 25 #include <sys/wait.h> 26 #include <sys/ioctl.h> 27 #include <net/if.h> 129 static int initwebs() 130 { 131 //struct hostent *hp; 132 //struct in_addr intaddr; 133 char host[128], dir[128], webdir[128]; 134 char *cp; 4
GoAhead Porting 154 if (gethostname(host, sizeof(host)) < 0) { 155 error(e_l, E_LOG, T("Can't get hostname")); 156 return -1; 157 } 158 #if 0 159 if ((hp = gethostbyname(host)) == NULL) { 160 error(e_l, E_LOG, T("Can't get host address")); 161 return -1; 162 } 163 memcpy((char *) &intaddr, (char *) hp->h_addr_list[0], 164 (size_t) hp->h_length); 165 #endif 166 int sock, ret; 167 struct ifreq ifr; 168 169 sock = socket(af_inet, SOCK_DGRAM, IPPROTO_UDP); 170 if (sock < 0) { 171 printf("error: get_myipaddr(), socket() failed!!\n"); 172 return -1; 173 } 5
GoAhead Porting 174 strcpy(ifr.ifr_name, "eth0"); 175 ret = ioctl(sock, SIOCGIFADDR, &ifr); 176 if (ret < 0) { 177 printf("error: get_myipaddr(), ioctl() failed!!\n"); 178 close(sock); 179 return -1; 180 } 194 webssetdefaultdir(webdir); 195 //cp = inet_ntoa(intaddr); 196 cp = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)- >sin_addr); 197 asctouni(wbuf, cp, min(strlen(cp) + 1, sizeof(wbuf))); 295 if (*url == '\0' gstrcmp(url, T("/")) == 0) { 296 websredirect(wp, T("index.html")); 297 return 1; 298 } -------------------------- 저장하고종료한다 ------------------------- - 6
GoAhead Porting misc.c 파일수정 root@ubuntu:~/working/ws031202/linux# vi../misc.c ----------------- 다음과같이수정한다 ------------------------ - 61 //static int strnlen(char_t *s, unsigned int n); 62 static void put_char(strbuf_t *buf, char_t c); 63 static void put_string(strbuf_t *buf, char_t *s, int l en, 428 #if 0 429 static int strnlen(char_t *s, unsigned int n) 430 { 431 unsigned int len; 432 433 len = gstrlen(s); 434 return min(len, n); 435 } 436 #endif ------------------ 저장하고종료한다 ------------------------ -- 7
GoAhead Porting GoAhead 컴파일 다음과같이 make 를실행하여컴파일을수행한다음컴파일이완료되어생성된파일들을확인한다. root@ubuntu:~/working/ws031202/linux# make root@ubuntu:~/working/ws031202/linux# ls Makefile libwebs.a main.c main.o webs 위와같이 webs 라는웹서버실행파일과 libwebs.a 라는라이브러리가생성이된다. 인덱스파일작성 (Web 의시작페이지로이용 ) root@ubuntu:~/working/ws031202/linux# vi index.html <html> <head> <title>the First webs test!</title> </head> <body> The first embedded linux web page </body> </html> 8
GoAhead Porting 웹서버실행파일인 webs 와앞에서작성한 index.html 을 /var/lib/tftpboot 디렉터리로복사 root@ubuntu:~/working/ws031202/linux#cp webs index.html /var /lib/tftpboot 타겟보드에서 GoAhead 실행을위한준비작업 실습을위해미리포팅되어있는웹서버파일및디렉터리이름변경 / 에있는 web 디렉터리이름변경 [root@sm5s4210 ~]# ls / ------------------다음과같은메시지가 출력된다 ----------------- bin jffs lost+found sbin tmp dev lib mnt sys usr etc linuxrc proc sysfs var home lost+found root test web [root@sm5s4210 ~]# mv /web/ /web-org 9
GoAhead Porting /bin 에있는 webs 파일이름변경 [root@sm5s4210 ~]# ls /bin/webs ------------------ 다음과같은메시지가출력된다 ----------------- /bin/webs [root@sm5s4210 ~]# mv /bin/webs /bin/webs-org 타겟보드에서 GoAhead 실행을위한준비작업 다음과같이 /web/cgi-bin 디렉터리를생성한다. [root@sm5s4210 ~]# mkdir -p /web/cgi-bin/ 타겟보드에 GoAhead 실행파일및 index.html 다운로드 tftp 를이용해서다운받아온다. [root@sm5s4210 ~]# ifconfig eth0 192.168.0.150 [root@sm5s4210 ~]# tftp r webs g 192.168.0.100 [root@sm5s4210 ~]# tftp r index.html g 192.168.0.100 [root@sm5s4210 ~]# chmod 777 webs [root@sm5s4210 ~]# mv webs /bin/ [root@sm5s4210 ~]# mv index.html /web/ 10
GoAhead Porting 웹서버프로세스종료 웹서버가자동으로실행되도록설정되어있으므로실행되어있는프로세스를종료 [root@sm5s4210 ~]# ps grep webs ------------------ 다음과같은메시지가출력된다 ----------------- 1316 root 1856 S /bin/webs [root@sm5s4210 ~]# kill -9 1316 타겟보드에서 GoAhead 실행 [root@sm5s4210 ~]# webs & 11
GoAhead Test 호스트 PC 의웹브라우저로웹서버에접속 브라우저의주소입력창에 http://192.168.0.150/index.html 을입력하고접속하면 index.html 페이지가뜬다. 12
CGI (Common Gateway Interface) HTTP와같은웹서버와외부응용프로그램과인터페이스를위한표준 기존의 http text는정적인파일형태로존재하지만, CGI 프로그램은실시간실행중인출력 text정보를동적으로변경시킬수있다. CGI 를실행시키는사용자는이실행파일을강제로실행시키는권한을금지한다. CGI 실행파일들은 cgi-bin 이라는특정한디렉토리에서관리된다. 13
CGI (Common Gateway Interface) CGI Programming Language C/C++, Fortran, PERL, TCL, Any Unix Shell, Visual Basic, AppleScript 웹클라이언트 / 서버간의 CGI를이용한데이터흐름 14
CGI (Common Gateway Interface) CGI 를이용하여넘겨주는문서형태 문서전체를 text 로 다른문서의위치를참조할수있도록 <a href="... "> Fill-out form을이용한 CGI 사용자와 registration, order, query 등의인터페이스를추가 여러개의 Form field를가질수있다. Form은보통CGI와연계되어작동된다. <form action="url" method=get> 15
CGI Program CGI 를통해브라우저에서서버로정보를전달하기위한방법을정의 CGI 예제작성 (first.c) root@ubuntu:# mkdir ~/working/web root@ubuntu:# cd ~/working/web/ root@ubuntu:~/working/web# vi first.c ----------------------- 다음과같이수정한다 ----------------------- - #include <stdio.h> int main() { printf("content-type: text/html\n\n"); printf("<html>\n<head><title>the First CGI program</title> </head>\n"); printf("<body>\n<center> It is a CGI program test</center> \n<body>\n </html>"); return 0; } ----------------------- 저장하고종료한다 ------------------------- 16
CGI Program first.c 소스를컴파일 root@ubuntu:~/working/web# arm-linux-gcc o first.cgi first.c first.html 파일을작성 root@ubuntu:~/working/web# vi first.html --------------------- 다음과같이수정한다 -------------------- <html> <head> <title>test CGI PROGRAM!</title> </head> <body><center><a href="cgi-bin/first.cgi">the first CGI PROGRA M!</a> </center> </body> </html> -------------------------- 저장하고종료한다 ------------------- - 17
CGI Program first.cgi 와 first.html 파일을타겟보드에전송 root@ubuntu:~/working/web# cp first.cgi first.html /var/lib/ tftpboot [root@sm5s4210 ~]# tftp r first.html g 192.168.0.100 [root@sm5s4210 ~]# tftp r first.cgi g 192.168.0.100 [root@sm5s4210 ~]# mv first.html /web/ [root@sm5s4210 ~]# mv first.cgi /web/cgi-bin/ 18
CGI Program CGI 예제실행확인 호스트 PC 의웹브라우저에서웹서버에접속 다음그림과같이브라우저를실행시킨후에주소창에 http://192.168.0.150/first.html 을입력하고연결하면 first.html 웹페이지가실행 19
CGI Program 화면에출력된 The first CGI PROGRAM! 을누르면 /web/cgi-bin 에있는 first.cgi 프로그램이동작 20
FND Control: HTML Web 을통한 FND 제어프로그램작성 7segment.html 파일을작성 root@ubuntu:~/working/web# vi 7segment.html <html> <head><title> 7segment cgi program</title></head> <body> <form method=get action="cgi-bin/7segment.cgi"> <p><p><p>7-segment 에표시할십진수를입력하세요. <input type="text" name="value" maxlength="6" siz e="6"> <input type="submit" name="button" value="input"> </form> </body> </html> 21
FND Control: CGI Program 7segment.c 파일을작성 root@ubuntu:~/working/web# vi 7segment.c 001: -------------------------- 다음과같이수정한다 ---------- -------------- 002: /************************************************************ ********** 003: * 7-Segment CGI Program 004: ************************************************************* *********/ 005: 006: #define FPGA_BASEADDRESS 0x05000000 007: #define SEG_GRID_OFFSET 0x30 008: #define SEG_DATA_OFFSET 0x32 009: 010: typedef struct { 011: char name[128]; 012: char val[128]; 22
FND Control: CGI Program 013: }entry; 014: 015: void getword(char *word, char *line, char stop) 016: { 017: int x =0, y = 0; 018: 019: for(x=0;((line[x]) && (line[x]!= stop)); x++) word[x] = line[x]; 020: 021: word[x] = '\0'; 022: if(line[x]) ++x; 023: 024: while(line[y++] = line[x++]); 025: } 026: 027: int sizeofword(char *word) 028: { 029: int i=0; 030: for(i=0;i<10;i++) { 031: if(word[i] == '\0') break; 032: } 033: return i; 23
FND Control: CGI Program 034: } 035: 036: unsigned int Getsegcode(char x) 037: { 038: unsigned int code; 039: switch (x) { 040: case '0' : code = 0xfc; break; 041: case '1' : code = 0x60; break; 042: case '2' : code = 0xda; break; 043: case '3' : code = 0xf2; break; 044: case '4' : code = 0x66; break; 045: case '5' : code = 0xb6; break; 046: case '6' : code = 0xbe; break; 047: case '7' : code = 0xe4; break; 048: case '8' : code = 0xfe; break; 049: case '9' : code = 0xf6; break; 050: case 'a' : 051: case 'A' : code = 0xfa; break; 052: case 'b' : 053: case 'B' : code = 0x3e; break; 054: case 'c' : 055: case 'C' : code = 0x1a; break; 24
FND Control: CGI Program 056: case 'd' : 057: case 'D' : code = 0x7a; break; 058: case 'e' : 059: case 'E' : code = 0x9e; break; 060: case 'f' : 061: case 'F' : code = 0x8e; break; 062: default : code = 0; break; 063: } 064: return code; 065: } 066: 067: int main() 068: { 069: char *cl; 070: int k; 071: unsigned int low = 0,high = 0; 072: entry entries; 073: unsigned short digit[6] = {0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; 074: unsigned short data[6]; 075: int i,j,m; 076: int fd; 077: unsigned short *addr_fpga; 25
FND Control: CGI Program 078: unsigned short *addr_grid, *addr_data; 079: 080: printf("content-type: text/html\n\n"); 081: printf("<html>\n<head><title>7-segment cgi program</title></head>\n"); 082: printf("<body>\n"); 083: 084: if((fd=open("/dev/mem",o_rdwr O_SYNC)) < 0) { 085: printf("mem open fail\n"); 086: exit(1); 087: } 088: 089: addr_fpga= (unsigned short *)mmap(null, 4096, PROT_READ PROT_WRITE, MAP_SHARED, fd, FPGA_BASEADDRESS); 090: addr_grid=addr_fpga+seg_grid_offset/sizeof(unsigned short); 091: addr_data=addr_fpga+seg_data_offset/sizeof(unsigned short); 092: 093: if(addr_grid < 0 addr_data < 0) { 094: close(fd); 095: printf("mmap error\n"); 096: exit(1); 097: } 26
FND Control: CGI Program 098: 099: cl = (char *)getenv("query_string"); 100: getword(entries.name,cl,'='); 101: getword(entries.val,cl,'&'); 102: k = sizeofword(entries.val); 103: 104: for(i=0; i<k; i++) 105: data[(k-i)-1] = Getsegcode(entries.val[i]); 106: 107: for(j=0;j<200;j++) { 108: for(i=0; i<k; i++) { 109: *addr_grid = digit[i]; 110: *addr_data = data[i]; 111: for(m=0;m<65536;m++); 112: } 113: } 114: 115: *addr_grid = ~digit[0]; 116: *addr_data = 0; 117: 27
FND Control: CGI Program 118: munmap(addr_grid, 4096); 119: munmap(addr_data, 4096); 120: close(fd); 121: 122: if( k!= 0) printf("<br><center>7-segment Done<br></center>"); 123: else printf("<br><center>you entered the wrong value!<br></center>"); 124: 125: printf("<hr>"); 126: printf("</body>\n</html>"); 127: return 0; 128: } 28
FND Control with Web Interface FND 제어프로그램컴파일 컴파일후 7segment.html 과 7segment.cgi 를 tftp 를이용해서타겟보드에전송 root@ubuntu:~/working/web# arm-linux-gcc o 7segment.cgi 7segment.c root@ubuntu:~/working/web# cp 7segment.html 7segment.cgi /var/lib/tft pboot [root@sm5s4210 ~]# tftp r 7segment.html g 192.168.0.100 [root@sm5s4210 ~]# tftp r 7segment.cgi g 192.168.0.100 [root@sm5s4210 ~]# mv 7segment.html /web/ [root@sm5s4210 ~]# mv 7segment.cgi /web/cgi-bin/ 29
FND Control with Web Interface FND 제어페이지실행확인 호스트 PC 의웹브라우저로웹서버에접속 웹브라우저를실행시키고주소창에 http://192.168.0.150/ 7segment.html 을입력하고연결하면 7segment.html 웹페이지가실행 30
FND Control with Web Interface 텍스트상자에십진수 6 자리를입력하고 input 버튼을클릭 FND 와 Web 을확인 31