網頁

2009年10月26日 星期一

CGI debug

Web server will redirect STDIN, STDOUT and STDERR to CGI interface so the following function is used to print out debug messages from C code.

Function 1:
void debug_printf(const char *degmsg, ... )  
 {  
     int old = dup(STDOUT);  
     int ttyfd ;  
     int ret;  
     va_list ap;  
     char msg[512];  
     
     ttyfd = open("/dev/ttyS0", O_RDWR);  
     va_start(ap,degmsg);  
     ret = vsprintf(msg,degmsg,ap);  
     va_end(ap);  
     dup2(ttyfd, STDOUT);  
     close(ttyfd);  
     printf("%s",msg);  
     dup2(old, STDOUT);   }

Function 2:

void debug_printf(const char *degmsg, ... ){  
     va_list ap;  
     int ret;  
     FILE *con_ptr;  
     char msg[512];  
     
     va_start(ap,degmsg);  
     ret = vsprintf(msg,degmsg,ap);  
     va_end(ap);  
     con_ptr = fopen("/dev/ttyS1","w+");;      
     if (!con_ptr) {  
         perror("fopen");  
     }  
     fprintf(con_ptr,"%s",msg);  
     fflush(con_ptr);  
     fclose(con_ptr);  
 }

2009年10月1日 星期四

How to mount JFFS2 image

Use memory to emulate the MTD device
mknod /tmp/mtdblock0 b 31 0
modprobe mtdblock
modprobe mtdram total_size=65536 erase_size=256

modprobe jffs2

dd if=image.jffs2 of=/tmp/mtdblock0

mkdir /mnt/jffs2
mount -t jffs2 /tmp/mtdblock0 /mnt/jffs2