2 * fwdump.c - dump the firmware received by uart to your computers harddisk
3 * use fwbc as a transmitting firmware
5 * author: hackbard@hackdaworld.org
13 #include <sys/types.h>
20 int open_serial_port(char *sdev) {
25 /* open serial device */
33 /* configure the serial device */
37 // input/output baudrate
39 cfsetispeed(&term,B9600);
40 cfsetospeed(&term,B9600);
42 // control options -> 8n1
44 term.c_cflag&=~PARENB; // no parity
45 term.c_cflag&=~CSTOPB; // only 1 stop bit
46 term.c_cflag&=~CSIZE; // no bit mask for data bits
47 term.c_cflag|=CS8; // 8 data bits
49 // line options -> raw input
51 term.c_lflag&=~(ICANON|ECHO|ECHOE|ISIG);
53 // input options -> enable flow control
55 term.c_iflag&=~(IXON|IXOFF|IXANY|INLCR|ICRNL);
61 // more control options -> timeout / flow control
64 term.c_cc[VTIME]=40; // 4 second timeout
65 term.c_cc[VSTART]=0x11;
66 term.c_cc[VSTOP]=0x13;
68 tcsetattr(fd,TCSANOW,&term);
73 int open_dump_file(char *file) {
79 fd=open(file,O_WRONLY|O_CREAT);
87 int main(int argc,char **argv) {
90 unsigned char buf[BUFSIZE];
94 printf("usage: %s <serial port> <dump file> <mem>\n",argv[0]);
98 printf("b: bootoader\n");
102 if((argv[3][0]!='0')&(argv[3][0]!='2')&(argv[3][0]!='b')) {
103 printf("unsupported mem type!\n");
107 sfd=open_serial_port(argv[1]);
109 dfd=open_dump_file(argv[2]);
114 /* send start byte */
116 ret=write(sfd,buf,1);
118 perror("write start byte");
122 /* receive flash content */
124 ret=read(sfd,buf,BUFSIZE);
128 ret=write(dfd,buf+cnt,size-cnt);
130 perror("write to dump file");