/* * Configfile parsing. */ #include #include #include #include #include #include #include #include #include "include.h" #define CFG_FIELD_NUM 10 static np_data np; extern struct nand_oobinfo oob_64[]; const char CFG_FIELD[][30]= { "CPUTYPE", "BUSWIDTH", "ROWCYCLES", "PAGESIZE", "PAGEPERBLOCK", "OOBSIZE", "BADBLOCKPOS", "BADBLOCKPAGE", "ECCTYPE", "[END]", }; np_data * load_cfg(void) { FILE *fp; char line[100]; unsigned short i,j; unsigned int d; if ((fp = fopen("nandprog.cfg", "r"))==NULL) { printf("Can not open configration file!\n"); return 0; } while(!strstr(line, "[NANDPROG]")) //find the nandprog section! { if (feof(fp)) { printf("nand programmer configration file illege!\n"); return 0; } fscanf(fp,"%s",line); } while(1) { if (feof(fp)) { printf("nand programmer configration file illege!\n"); return 0; } fscanf(fp,"%s",line); if (line[0]==';') { line[0]='\0'; continue; } for (i=0;i2048) continue; np.bbp = d; break; } break; case 7: //BADBLOCKPAGE while (!feof(fp)) { fscanf(fp,"%d",&d); if (d>np.ppb) continue; np.bba = d; break; } break; case 8: //ECCTYPE while (!feof(fp)) { fscanf(fp,"%s",line); if (strstr(line,"RS")) { np.et = HARDRS; d = 36; //36 bytes ecc oob_64[4].eccbytes = 36; np.ep = 4; break; } else if (strstr(line,"HM")) { np.et = HARDHM; d = 24; //24 bytes ecc oob_64[4].eccbytes = 24; np.ep = 4; break; } else continue; } while (!feof(fp)) { fscanf(fp,"%s",line); if (strstr(line,"{")) break; } for (j = 0;j < d;j++) { if (feof(fp)) { printf("nand programmer configration file illege!\n"); return 0; } fscanf(fp,"%d",&d); if (d > np.os) { printf("nand programmer configration file illege!\n"); return 0; } oob_64[4].eccpos[j] = d; } while (!feof(fp)) { fscanf(fp,"%s",line); if (strstr(line,"}")) break; } break; case 9: return &np; default: ; } } }