顯示具有 programming 標籤的文章。 顯示所有文章
顯示具有 programming 標籤的文章。 顯示所有文章

2010年11月29日 星期一

lighttpd porting


CC="mips-linux-gcc -I/tmp/rootfs/lighttpd/include -L/tmp/rootfs/lighttpd/lib" LD="mips-linux-ld -L/tmp/rootfs/lighttpd/lib" ./configure --target=mips-linux --host=mips-linux --without-zlib --prefix=/tmp/rootfs/lighttpd --without-bzip2 --disable-ipv6 --with-pcre=/tmp/rootfs/lighttpd/lib/

-----------------------------------------------------
設定 lighttpd.conf
  1. document root
    修改lighttpd.conf
    var.server_root = "/tmp/rootfs/www"
    server.port = 1234
    var.conf_dir    = "/tmp/rootfs/etc/lighttpd"
  2. cgi module.
    修改modules.conf
    include "conf.d/cgi.conf"
  3. 修改conf.d/cgi.conf
    cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
                                 ".cgi" => "/tmp/rootfs/www/cgi/ssi",
                                   ".rb"  => "/usr/bin/ruby",
                                   ".erb" => "/usr/bin/eruby",
                                   ".py"  => "/usr/bin/python" )



 在target board edit 「/tmp/rootfs/www/cgi/ssi」如下,and chmod +x.
#!/bin/sh
echo -ne "Content-Type: text/plain\n\n";
echo -ne "Hi there! This is a sample perl program!!!\n";
set

 測試 url: http://172.21.46.138:1234/index.cgi
CONTENT_LENGTH='0'
DOCUMENT_ROOT='/tmp/rootfs/www'
GATEWAY_INTERFACE='CGI/1.1'
HTTP_ACCEPT='text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
HTTP_ACCEPT_CHARSET='UTF-8,*'
HTTP_ACCEPT_ENCODING='gzip,deflate'
HTTP_ACCEPT_LANGUAGE='zh-tw,en-us;q=0.7,en;q=0.3'
HTTP_CACHE_CONTROL='max-age=0'
HTTP_CONNECTION='keep-alive'
HTTP_HOST='172.21.46.138:1234'
HTTP_KEEP_ALIVE='115'
HTTP_USER_AGENT='Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 GTB7.1 (.NET CLR 3.5.30729)'
IFS='  
'
LD_LIBRARY_PATH='/tmp/rootfs/lighttpd/lib'
PATH='/usr/local/bin:/usr/bin:/sbin:/bin'
PPID='797'
PS1='\w \$ '
PS2='> '
PS4='+ '
PWD='/tmp/rootfs/www'
REDIRECT_STATUS='200'
REMOTE_ADDR='172.21.33.212'
REMOTE_PORT='2161'
REQUEST_METHOD='GET'
REQUEST_URI='/index.cgi'
SCRIPT_FILENAME='/tmp/rootfs/www/index.cgi'
SCRIPT_NAME='/index.cgi'
SERVER_ADDR='0.0.0.0'
SERVER_NAME='172.21.46.138'
SERVER_PORT='1234'
SERVER_PROTOCOL='HTTP/1.1'
SERVER_SOFTWARE='lighttpd/1.4.28'
當IE brower URL:http://172.21.46.138:1234/index.cgi 時,lighttpd會根據cgi.conf所設定的副檔名來執行程式(以此為例,真正的執行檔為「/tmp/rootfs/www/cgi/ssi, 而index.cgi這個file實際上可能不存在

但這不是我想要的結果:
所以我做了點小修改: 
  1. 將www/cgi/ssi link到www
    再將原來的ssi rename為ssi.exe
  2. 小改一下cgi.conf
    cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
                                   ".cgi" => "/tmp/rootfs/www/cgi/ssi.exe",
                                   ".asp" => "/tmp/rootfs/www/cgi/ssi.exe",
                                   ".rb"  => "/usr/bin/ruby",
                                   ".erb" => "/usr/bin/eruby",
                                   ".py"  => "/usr/bin/python" )
peter@team-server:www$ tree cgi
cgi
|-- ssi -> ../
`-- ssi.exe


測試一下

http://172.21.46.138:1234/cgi/ssi/index.asp
可以work了!




2010年5月25日 星期二

test popen on NOMMU

popen()是可以work的…


int main(int argc, char *argv[])
{
        int p[2];
        char buf[128];
        FILE *fd;


        if ((fd = popen("ls -l", "r")) == NULL)
                goto sys_out;


        while (fgets(buf, sizeof(buf) - 1, fd))
                printf("[%s]\n", buf);


        return 0;
sys_out:
        perror("sys");
        return 1;
}

2010年4月23日 星期五

gcc cross compiler union compatible issue.



有些platform struct or union 預設為4bytes(一般會預期應該要2bytes)
目前可用
__attribute__((__packed__))來解決
其它的code要小心有沒有類似的問題


typedef union _MACHTTRANSMIT_SETTING
{
        unsigned short word;
        union //short 2 bytes,但有些可能 assign 4 bytes
        {
                unsigned short MCS:7; // MCS
                unsigned short BW:1; //channel bandwidth 20MHz or 40 MHz
                unsigned short ShortGI:1;
                unsigned short STBC:2; //SPACE
                unsigned short rsv:3;
                unsigned short MODE:2; // Use definition MODE_xxx.
        } __attribute__((__packed__))field;
}__attribute__((__packed__)) MACHTTRANSMIT_SETTING, *PMACHTTRANSMIT_SETTING;

int main(int argc, char *argv[])
{
        MACHTTRANSMIT_SETTING m;
        printf("m: %d, m->word:%d@%p\n", sizeof(m), sizeof(m.word), &m.word);
        printf("m: %d, m->:%d@%p\n", sizeof(m), sizeof(m.word), &m.word);
        printf("ok: %d, m->:%d@%p\n", sizeof(m), sizeof(m.field), &m.field);
}
X86
others
peter@team-server:~$ ./a.out
m: 2, m->word:2@0xbff97a32
m: 2, m->:2@0xbff97a32
ok: 2, m->:1@0xbff97a32
/tmp/rootfs # ./a.out
m: 2, m->word:2@0x4261fcd4
m: 2, m->:2@0x4261fcd4
ok: 2, m->:1@0x4261fcd4


2010年4月20日 星期二

how to change default stack size...

方法一:
gcc -Wl,--defsym,__stacksize=0x80000 -o foo foo.c

方法二:

peter@team-server:sbin$ arm-elf-readelf -l foo

Elf file type is EXEC (Executable file)
Entry point 0x37fc
There are 6 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  PHDR           0x000034 0x00000034 0x00000034 0x000c0 0x000c0 R E 0x4
  INTERP         0x0000f4 0x000000f4 0x000000f4 0x00014 0x00014 R   0x1
      [Requesting program interpreter: /lib/ld-uClibc.so.0]
  LOAD           0x000000 0x00000000 0x00000000 0x1f668 0x1f668 R E 0x1000
  LOAD           0x01f668 0x00020668 0x00020668 0x0b718 0x0ba98 RW  0x1000
  DYNAMIC        0x01f67c 0x0002067c 0x0002067c 0x000c8 0x000c8 RW  0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x20000 RWE 0x8 //原來的stack256KB


 Section to Segment mapping:
  Segment Sections...
   00
   01     .interp
   02     .interp .hash .dynsym .dynstr .rel.dyn .rel.plt .init .plt .text .fini .rofixup
   03     .ctors .dtors .jcr .dynamic .data .got .bss
   04     .dynamic
   05
peter@team-server:sbin$
peter@team-server:sbin$ ../../../fdpichdr/fdpichdr -s 0x100000  foo
peter@team-server:sbin$ arm-elf-readelf -l foo

Elf file type is EXEC (Executable file)
Entry point 0x37fc
There are 6 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  PHDR           0x000034 0x00000034 0x00000034 0x000c0 0x000c0 R E 0x4
  INTERP         0x0000f4 0x000000f4 0x000000f4 0x00014 0x00014 R   0x1
      [Requesting program interpreter: /lib/ld-uClibc.so.0]
  LOAD           0x000000 0x00000000 0x00000000 0x1f668 0x1f668 R E 0x1000
  LOAD           0x01f668 0x00020668 0x00020668 0x0b718 0x0ba98 RW  0x1000
  DYNAMIC        0x01f67c 0x0002067c 0x0002067c 0x000c8 0x000c8 RW  0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x100000 RWE 0x8    //現在有1MB

 Section to Segment mapping:
  Segment Sections...
   00
   01     .interp
   02     .interp .hash .dynsym .dynstr .rel.dyn .rel.plt .init .plt .text .fini .rofixup
   03     .ctors .dtors .jcr .dynamic .data .got .bss
   04     .dynamic
   05     .bss

2010年3月4日 星期四

gdb commands

list:
        #list symbols
        (gdb)list


debug multi-process:
        http://www.ibm.com/developerworks/cn/linux/l-cn-gdbmp/index.html
        set follow-fork-mode
        show follow-fork-mode
        http://www.delorie.com/gnu/docs/gdb/gdb_26.html
        set detach-on-fork [on|off]
where

print
        file::variable
        function::variable
        #print x in file f2.c
        (gdb) p 'f2.c'::x