/* The following function is used to malloc a region to save the new parameters */ static bool lcd_resolve_config_file(int fd,char *para_name, void **para_table,uint32_t *para_num) { uint32_t reg=0; uint32_t val=0; uint32_t time=0; char buf[HW_LCD_CONFIGLINE_MAX] = {0}; int lcd_config_line_num=0; int ret=0; off_t fd_seek=0; struct sequence * lcd_config_table = NULL; lcd_config_table = kzalloc( (size_t) (sizeof(struct sequence) * HW_LCD_CONFIG_TABLE_MAX_NUM) , 0); if(NULL == lcd_config_table){ goto kalloc_err; } sys_lseek(fd, (off_t)0, 0); while(NULL != (fget_line(buf, HW_LCD_CONFIGLINE_MAX, fd , &fd_seek))) { reg = 0; val= 0; time =0; ret=sscanf(buf,"{%x,%x,%d},\n",®,&val,&time); if (ret > 0 && lcd_config_line_num<HW_LCD_CONFIG_TABLE_MAX_NUM) { lcd_config_table[lcd_config_line_num].reg= reg; lcd_config_table[lcd_config_line_num].value= val; lcd_config_table[lcd_config_line_num].time= time; lcd_config_line_num++; } else { printk("=== resolve error, ret = %d====\n",ret); goto resolve_err; } } *para_num = lcd_config_line_num; *para_table = lcd_config_table; return TRUE; resolve_err: kfree(lcd_config_table); kalloc_err: para_table = NULL; *para_num = 0 ; return FALSE; }
/*----------------------------------------------------------------------------*/ int nxp_send_file(ASerialPort_t* aPort, ADeviceNXP_t* aDevice) { ALineHEX_t linehex; char hexchk[COUNT_HEXSTR_BUFF]; int linecount, line = 0, error = 0; int count, size = COUNT_HEXSTR_CHAR*sizeof(char); char *buff = malloc(size); FILE *pfile_hex; nxp_hexfunc_t pfunc; /* prepare links! */ linehex.hexstr = hexchk; aDevice->linehex = &linehex; /* get line count and check for error! */ linecount = nxp_check_file(aPort,aDevice); if(linecount<0) return linecount; /* check for verification request */ if(aDevice->do_verify) pfunc = nxp_verify_hex; else pfunc = nxp_device_hex; aDevice->do_verify = 0; /* do the thing! */ pfile_hex = fopen(aDevice->hexfile_name,"rt"); if(!pfile_hex) return HEX_ERROR_FILE; printf("000/%03u\b\b\b\b",linecount); while((count=fget_line(&buff,(int*)&size,pfile_hex))!=-1) { if(size<count) size = count; line++; /* this should be okay! */ nxp_check_hex(buff,&linehex); /* do the requested process */ if((error=pfunc(aPort,aDevice))!=0) break; printf("\b\b\b%03u",line); fflush(stdout); } fclose(pfile_hex); free(buff); printf("\b\b\b \b\b\b\b\b\b\b"); if(error) { printf("Failed @line %d (%d)!\n",line,error); return error; } if(pfunc==nxp_verify_hex) return 0; error = nxp_wait_acknowledge(aPort,aDevice); if(!aDevice->do_acknowledge) { printf("[ACK ERROR] NOT FOUND!\n"); error++; } /* need to get extra ack? */ nxp_wait_acknowledge(aPort,aDevice); return error; }
int batch(char *filename) { FILE *f; int argc; char *argv[32], *saveptr, *aux; int c; char *buffer; uint bufsz; argv[0] = program_invocation_short_name; f = fopen(filename, "r"); if (!f) return -1; bufsz = 1024; buffer = malloc(bufsz * sizeof(char)); while ((c = fget_line(f, &buffer, &bufsz) > 0)) { argc = 1; aux = buffer; while ((aux = strtok_r(aux, " ", &saveptr)) != NULL && argc < 32) { argv[argc++] = aux; aux = NULL; } //Args demais if (aux != NULL && argc == 32) print_error(ARG_ERROR); else { //Remove \n no final c = strlen(argv[argc-1]); if (argv[argc-1][c-1] == '\n') argv[argc-1][c-1] = '\0'; process_args(argc, argv, 1); } } free(buffer); fclose(f); return 0; }
void dump_line_symbols(void) { static int lst_line_number = 1; static int last_src_line = 0; char buf[2048]; unsigned short i, j, start_block, end_block; DirBlockInfo *dbi = main_dir; gp_boolean has_line_num_info = false; int _64k_base; do { _64k_base = gp_getu16(&dbi->dir[COD_DIR_HIGHADDR]); start_block = gp_getu16(&dbi->dir[COD_DIR_LSTTAB]); if (start_block) { end_block = gp_getu16(&dbi->dir[COD_DIR_LSTTAB + 2]); if (!has_line_num_info) { has_line_num_info = true; printf("Line Number Information:\n" " LstLn SrcLn Addr Flags FileName\n" " ----- ----- ------ ----------- ---------------------------------------\n"); } for (j = start_block; j <= end_block; j++) { read_block(temp, j); for (i = 0; i < 84; i++) { unsigned int offset = i * COD_LINE_SYM_SIZE; unsigned char sfile = temp[offset + COD_LS_SFILE]; unsigned char smod = temp[offset + COD_LS_SMOD]; unsigned short sline = gp_getl16(&temp[offset + COD_LS_SLINE]); unsigned short sloc = gp_getl16(&temp[offset + COD_LS_SLOC]); if ((sfile != 0 || smod != 0 || sline != 0 || sloc != 0) && (smod & 4) == 0) { char *source_file_name; if (sfile < number_of_source_files) { source_file_name = source_file_names[sfile]; } else { char buf[128]; snprintf(buf, sizeof(buf), "Bad source file index: %d", sfile); source_file_name = buf; } printf(" %5d %5d %06X %2x %s %-50s\n", lst_line_number++, sline, (_64k_base << 16) | sloc, smod, smod_flags(smod), source_file_name); if ((sfile < number_of_source_files) && (sline != last_src_line)) { if (source_files[sfile] != NULL) { /*fgets(buf, sizeof(buf), source_files[sfile]);*/ fget_line(sline, buf, sizeof(buf), source_files[sfile]); printf("%s", buf); } else { printf("ERROR: Source file \"%s\" does not exist.\n", source_file_names[sfile]); } } } last_src_line = sline; } } /* for */ } /* if */ dbi = dbi->next; } while (dbi != NULL); if (!has_line_num_info) { printf("No line number info.\n"); } putchar('\n'); }
/*----------------------------------------------------------------------------*/ int nxp_check_file(ASerialPort_t* aPort, ADeviceNXP_t* aDevice) { int line = 0, error = 0; int test, count, size = COUNT_HEXSTR_BUFF*sizeof(char); char *buff = malloc(size); FILE *pfile_hex = fopen(aDevice->hexfile_name,"rt"); if(!pfile_hex) { error = HEX_ERROR_FILE; } else { /* check line by line! */ while((count=fget_line(&buff,(int*)&size,pfile_hex))!=-1) { if(size<count) size = count; line++; test = nxp_check_hex(buff,aDevice->linehex); if(test<0) { error = test; break; } else if(aDevice->linehex->lastaddr>=aDevice->flash_size) { error = HEX_ERROR_OVERFLOW; break; } } fclose(pfile_hex); } free(buff); if(error&&aDevice->do_tell_error) { switch(error) { case HEX_ERROR_FILE: printf("Cannot open HEX file '%s'!",aDevice->hexfile_name); break; case HEX_ERROR_LENGTH: printf("HEX string length error @line %d!\n",line); break; case HEX_ERROR_NOCOLON: printf("HEX string no ':' @line %d!\n",line); break; case HEX_ERROR_NOTDATA: printf("HEX record type NOT supported @line %d!\n",line); break; case HEX_ERROR_CHECKSUM: printf("HEX record checksum error @line %d!\n",line); break; case HEX_ERROR_OVERFLOW: printf("HEX record address device overflow @line %d!\n",line); break; default: printf("Failed HEX check @line %d!\n",line); } } return error ? error : line; }