void sendthis(st2205_handle *h, char* what) { int y; y=sendpic(h,what); if (!y) { //p'rhaps a dir? DIR *dir; struct dirent *dp; char fn[2048]; dir=opendir(what); if (dir==NULL) { //Nope :/ printf("Couldn't open %s.\n",what); exit(1); } while ((dp = readdir (dir)) != NULL) { strcpy(fn,what); strcat(fn,"/"); strcat(fn,dp->d_name); sendpic(h,fn); } } }
int main(int argc, char **argv) { st2205_handle *h; char fn[1024]; int y; if (argc<2) { printf("Usage: %s /dev/sdX pic.png\n",argv[0]); exit(0); } h=st2205_open(argv[1]); if (h==NULL) { printf("Open failed!\n"); exit(1); } printf("Found device: %ix%i, %i bpp\n",h->width,h->height,h->bpp); y=sendpic(h,argv[2]); if (!y) { //p'rhaps a dir? DIR *dir; struct dirent *dp; char fn[2048]; dir=opendir(argv[2]); if (dir==NULL) { //Nope :/ printf("Couldn't open %s.\n",argv[2]); exit(1); } while ((dp = readdir (dir)) != NULL) { strcpy(fn,argv[2]); strcat(fn,"/"); strcat(fn,dp->d_name); sendpic(h,fn); } } st2205_close(h); printf("Test done.\n"); }
//This is a debugging routine. Don't EVER mess with the internals of the //st2205_handle like this in a real program! void testpic(st2205_handle *h, char* what) { char c; struct termios term; struct termios oldterm; tcgetattr(0, &oldterm); tcgetattr(0, &term); term.c_lflag &= ~ICANON; tcsetattr(0, TCSANOW, &term); setbuf(stdin, NULL); c='i'; while (c!='q') { //force complete image redraw instead of the optimized //draw-only-whats-changed stuff if (h->oldpix!=NULL) { free(h->oldpix); h->oldpix=NULL; } if (c=='i') { printf(" With this mode, you can find some values for a new specfile.\n"); printf(" u and d moves picture up and down\n"); printf(" l and r moves picture left and right\n"); printf(" t toggles bpp\n"); printf(" i gives this info\n"); printf(" q quits\n"); } else if (c=='u') { h->offy--; } else if (c=='d') { h->offy++; } else if (c=='l') { h->offx--; } else if (c=='r') { h->offx++; } else if (c=='t') { if (h->bpp==12) h->bpp=16; else h->bpp=12; } printf(" pressed\nCurrent settings: offx=%i offy=%i bpp=%i\n",h->offx,h->offy,h->bpp); sendpic(h,what); c=getchar(); } printf("K, bye."); tcsetattr(0, TCSANOW, &oldterm); }
int main(int argc, char** argv) { int f,o; unsigned int x,y; int mode=0; unsigned char *buff; if (argc<2) { printf("Usage:\n%s [-d|-u|-df|-uf|-m|-l] file [device]\n", argv[0]); printf(" -d: dump mem\n"); printf(" -u: upload mem\n"); printf(" -df: dump firmware\n"); printf(" -uf: upload firmware\n"); printf(" -m: set message (10 chars)\n"); printf(" -l: send png- to framebuffer mem (hacked fw only)\n"); printf(" -r: send raw 256 byte code block to $1000 mem and execute (JRK hacked fw only)\n"); printf(" file: file to dump to or upload from\n"); printf(" device: /dev/sdX (default: /dev/sda)\n"); printf("-l accepts directories too, in which case it'll proceed to send every file in the\n"); printf("directory to the LCD.\n"); exit(0); } //check requested command if (strcmp(argv[1],"-u")==0) mode=M_UP; if (strcmp(argv[1],"-d")==0) mode=M_DMP; if (strcmp(argv[1],"-uf")==0) mode=M_FUP; if (strcmp(argv[1],"-df")==0) mode=M_FDMP; if (strcmp(argv[1],"-m")==0) mode=M_MSG; if (strcmp(argv[1],"-l")==0) mode=M_LCD; if (strcmp(argv[1],"-r")==0) mode=M_RAWEXEC; if (mode==0) { printf("Invalid command: %s\n",argv[1]); exit(1); } //open the device if (argc>=4) { f=open(argv[3],O_RDWR|O_DIRECT|O_SYNC); } else { f=open("/dev/sda",O_RDWR|O_DIRECT|O_SYNC); } //check if dev really is a photo-frame if (!is_photoframe(f)) { fprintf(stderr,"No photoframe found there.\n"); exit(1); } //open file, if needed if (mode==M_DMP || mode==M_FDMP) { o=open(argv[2],O_WRONLY|O_TRUNC|O_CREAT,0644); } else if (mode==M_UP || mode==M_FUP) { o=open(argv[2],O_RDONLY); } if (o<0 && mode!=M_MSG && mode!=M_LCD) { fprintf(stderr,"Error opening %s.\n",argv[2]); exit(1); } //Allocate buffer and send a command. Check the result as an extra caution //against non-photoframe devices. buff=malloc_aligned(0x8000); sendcmd(f,1,0,0,0); read_data(f,buff,0x200); if (buff[0]!=8) { printf("Expected response 8 on cmd 1, got 0x%hhx!\n",buff[0]); exit(1); } if (mode==M_DMP) { //dump picture memory //get everything except the last 64K (wraps around to the firmware) //in 32K chunks. for (x=0; x<((2048-64)/32); x++) { sendcmd(f,4,x,0x8000,0); read_data(f,buff,0x8000); write(o,buff,0x8000); fprintf(stderr,"."); } fprintf(stderr,"\n"); printf("Dump: %u pages dumped.\n", x); } else if (mode==M_FDMP) { //Use a trick to get the 64K of firmware: if we request the data starting //at (2M-64K), the data gets read from a mirror of the flash, position 0. for (x=((2048-64)/32); x<(2048/32); x++) { sendcmd(f,4,x,0x8000,0); read_data(f,buff,0x8000); write(o,buff,0x8000); fprintf(stderr,"."); } fprintf(stderr,"\n"); printf("Firmware dumped.\n"); } else if (mode==M_UP) { //send everything except the last 64K (wraps around to the firmware) //in 32K chunks. for (x=0; x<((2048-64)/32); x++) { sendcmd(f,3,x,0x8000,0); y=read(o,buff,0x8000); write_data(f,buff,0x8000); sendcmd(f,2,x,0x8000,0); read_data(f,buff,0x200); if (y!=0x8000) { printf("Premature file end.\n"); x=9999; } fprintf(stderr,"."); } fprintf(stderr,"\n"); printf("Memory uploaded.\n"); } else if (mode==M_FUP) { printf("Firmware update! If unsure, press ctrl-C NOW!\n"); sleep(3); printf("Too late. Commencing firmware update...\n"); for (x=0; x<2; x++) { sendcmd(f,3,x|0x80000000,0x8000,0); y=read(o,buff,0x8000); write_data(f,buff,0x8000); sendcmd(f,2|0x80000000,x,0x8000,0); read_data(f,buff,0x200); sendcmd(f,3,x|0x1f40,0x8000,0); write_data(f,buff,0x8000); if (y!=0x8000) { printf("Premature file end. Hope everything still works OK.\n"); x=9999; } fprintf(stderr,"."); } fprintf(stderr,"\n"); printf("Firmware upgraded. Un- and replug USB connection to restart device.\n"); } else if (mode==M_MSG) { //Debug-feature? A message consisting of 10 bytes can be written to the //lcd. No hacked firmware is necessary for this. sendcmd(f,9,0,0,0); strcpy(buff,argv[2]); write_data(f,buff,0x200); printf("Message written.\n"); } else if (mode==M_LCD) { y=sendpic(f,argv[2],buff); if (!y) { //p'rhaps a dir? DIR *dir; struct dirent *dp; char fn[2048]; dir=opendir(argv[2]); if (dir==NULL) { //Nope :/ printf("Couldn't open %s.\n",argv[2]); exit(1); } while ((dp = readdir (dir)) != NULL) { strcpy(fn,argv[2]); strcat(fn,"/"); strcat(fn,dp->d_name); sendpic(f,fn,buff); } } } else if (mode == M_RAWEXEC ) { int a; FILE * fp = fopen(argv[2], "rb" ); if (!fp) { perror("fopen:"); exit(1); } unsigned char * buf=malloc_aligned(0x200); while(!feof(fp)) { // fill buffer with RTS opcodes memset( buf, 0x60, 512 ); int br = fread( buf, 1, 512, fp ); if (br==0) break; printf("read %d packet\n", br); for(a=0;a<512;a++) printf("%02x ", buf[a]); printf("\n"); lseek(f,0x4600,SEEK_SET); int ret = write(f,buf,512); if (ret != 512) { printf("ret=%d\n", ret ); perror("write"); } else printf("wrote 1*512 byte packet\n"); } fclose( fp ); } exit(0); }