void *thread_connection(void *args) { int connection_socket = ((struct thread_arguments *) args ) -> connection_socket; struct sockaddr_in client_address = ((struct thread_arguments *) args ) -> client_address; struct client_data data = get_client_address(client_address); char buffer[BUFSIZE]; bzero(buffer, BUFSIZE); int status = recv(connection_socket, buffer, BUFSIZE, MSG_DONTWAIT); if (WHITELIST != NULL && check_whitelist(data.ip_address) == NULL) { display_info(data, NULL, "Rejected connection from unknown user."); save_log(NULL, data.ip_address, data.hostname); if (write(connection_socket, "You are not whitelisted!\n", 26) < 0) printf("Error writing on stream socket\n"); close(connection_socket); pthread_exit(NULL); } if (BANLIST != NULL && check_banlist(data.ip_address) != NULL) { display_info(data, NULL, "Rejected connection from banned user."); save_log(NULL, data.ip_address, data.hostname); if (write(connection_socket, "You are banned!\n", 17) < 0) printf("Error writing on stream socket\n"); close(connection_socket); pthread_exit(NULL); } if (check_protocol(buffer) == 1) status = -1; if (status != -1) { char slug[SLUG_SIZE+8]; generate_url(buffer, slug, SLUG_SIZE+8, data); save_log(slug, data.ip_address, data.hostname); char response[strlen(slug) + strlen(DOMAIN) + 2]; snprintf(response, sizeof response, "%s%s\n", DOMAIN, slug); if (write(connection_socket, response, strlen(response)) < 0) printf("Error writing on stream socket\n"); } else { display_info(data, NULL, "Invalid connection."); save_log(NULL, data.ip_address, data.hostname); if (write(connection_socket, "Use netcat.\n", 12) < 0) printf("Error writing on stream socket\n"); } close(connection_socket); pthread_exit(NULL); }
int main(void) { EGLDisplay display; EGLContext context; EGLConfig config; EGLSurface surface; EGLBoolean result; EGLint num_config; static const EGLint attribute_list[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; display = eglGetDisplay(EGL_DEFAULT_DISPLAY); result = eglInitialize(display, NULL, NULL); assert(result != EGL_FALSE); eglBindAPI(EGL_OPENVG_API); result = eglChooseConfig(display, attribute_list, &config, 1, &num_config); assert(result != EGL_FALSE); context = eglCreateContext(display, config, NULL, NULL); assert(context != EGL_NO_CONTEXT); surface = eglCreatePbufferSurface(display, config, NULL); eglMakeCurrent(display, surface, surface, context); display_info("Vendor", VG_VENDOR); display_info("Renderer", VG_RENDERER); display_info("Version", VG_VERSION); display_info("Extensions", VG_EXTENSIONS); eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(display, context); eglTerminate(display); eglReleaseThread(); return 0; }
/* * Print on the screen in a neat fashion all the info we have collected * on a device. */ static int print_info(int skfd, char * ifname, char * args[], int count) { struct wireless_info info; int rc; /* Avoid "Unused parameter" warning */ args = args; count = count; rc = get_info(skfd, ifname, &info); switch(rc) { case 0: /* Success */ /* Display it ! */ display_info(&info, ifname); break; case -ENOTSUP: fprintf(stderr, "%-8.16s no wireless extensions.\n\n", ifname); break; default: fprintf(stderr, "%-8.16s %s\n\n", ifname, strerror(-rc)); } return(rc); }
void display(int flags) { register int i; for (i = 0; i < NUM_PROGRAMS; i++) if (programs[i].updated & flags) display_info(i); }
void *main_rootine(void *param) { time_t t1; time_t t2; WINDOW *info; WINDOW *graph; WINDOW *philo[NB_PHILO + 2]; (void)param; time(&t1); time(&t2); init_display(); while (no_philo_dead() && (t2 - t1 <= TIMEOUT)) { initndisplay_graph(&graph, &info); init_philo_win(philo, graph); display_info(&info); display_philo(philo, 0); time(&t2); } finish(philo); if (no_philo_dead()) ft_putendl(WIN_MESSAGE); else ft_putendl("You lose"); return (NULL); }
static void display() { static DeviceDrawParams draw_params = DeviceDrawParams(); options.session->draw(session_buffer_params(), draw_params); display_info(options.session->progress); }
int display_warn(char *msg) { display_info(msg); clear_cache(); get_keycode(); return SUCCESS; }
int main(int argc, char **argv) { char **subjects, **courses; int *CRNs, count, size; read_courses(&subjects, &courses, &CRNs, &count, &size, argv[COURSE_FILE_ARG]); display_info(subjects, courses, CRNs, count); deallocate(subjects, courses, CRNs, size); return 0; } // main()
int main(int argc, char **argv) { if (argc == 1) { fprintf(stderr, "Usage: opkinfo app1.opk [app2.opk ...]\n"); exit(2); } bool ok = true; for (int i = 1; i < argc; i++) { ok &= display_info(argv[i]); } exit(ok ? 0 : 1); }
int get_stored_region(wifi_region *region_info) { auto int country; auto char data[64]; if((country = regionInfoEErd()) < 0 ) { ifconfig (IF_WIFI0, IFG_WIFI_REGION_INFO, region_info, IFS_END); display_info(region_info); return -1; } return country; }
int shutdown(void) { int ret; display_info("正在关机..."); usleep(100000); sync(); ret = system("shutdown"); if (ret < 0) return FAIL; return SUCCESS; }
void save_to_file(char *slug, char *buffer, struct client_data data) { char *directory = malloc(strlen(BASEDIR) + strlen(slug) + 11 * sizeof(char) + 1 ); snprintf(directory, strlen(BASEDIR) + strlen(slug) + 11 * sizeof(char) + 1, "%s%s%s%s", BASEDIR , "/", slug, "/index.txt"); FILE *fp; fp = fopen(directory, "w"); fprintf(fp, "%s", buffer); fclose(fp); display_info(data, directory, ""); free(directory); }
void if_forest_params(t_dlist **list, t_dlist *link, t_params *p, int total) { t_dlist *new_list; new_list = NULL; if (p->time_modification) *list = sort_modif_time(list, p->time_to_sort); if (p->reverse) ft_dlstrev(list); if (p->recursive && total == 1) add_dirs_to_open(*list, &link, p); if (p->list) display_info(*list, p, total); else display_normal(*list, p); }
int log_out(void) { display_info("正在注销..."); usleep(10000); sync(); memset(&login_user, 0, sizeof(login_user)); memset(&g_ui_stack, 0, sizeof(g_ui_stack)); g_cur_frame_id = 0; g_cur_item_id = 0; g_logout_flag = NEGATIVE; g_shutdown_flag = NEGATIVE; //clear logout/shutdown flag return SUCCESS; }
/* * Print on the screen in a neat fashion all the info we have collected * on a device. */ static void print_info(int skfd, char * ifname) { struct wireless_info info; if(get_info(skfd, ifname, &info) < 0) { fprintf(stderr, "%-8.8s no wireless extensions.\n\n", ifname); return; } /* Display it ! */ display_info(&info, ifname); }
void cmd_erase_nand(const char *arg, void *data, unsigned sz) { int index; u64 offset,size; char msg[256]; index = partition_get_index(arg); if(index == -1){ fastboot_fail_wrapper("partition get index fail"); return; } if(!is_support_erase(index)){ sprintf(msg,"partition '%s' not support erase\n",arg); fastboot_fail_wrapper(msg); return; } offset = partition_get_offset(index); if(offset == (u64)(-1)){ fastboot_fail_wrapper("partition get offset fail"); return; }else{ printf("get offset: 0x%llx\n",offset); } size = partition_get_size(index); if(size == (u64)(-1)){ fastboot_fail_wrapper("partition get size fail"); return; }else{ printf("get size: 0x%llx\n",size); } TIME_START; display_info("erase flash ...."); if(nand_erase(offset,size)!=0){ fastboot_fail_wrapper("failed to erase partition"); return; } fastboot_ok_wrapper("erase flash sucess",sz); return; }
int main(int argc, char *argv[]) { Course *courses; Student *students; int courses_capacity = INITIAL_COURSES_CAPACITY; int courses_actual = 0; int students_capacity = INITIAL_STUDENTS_CAPACITY; int students_actual = 0; read_courses(argv[1], &courses, &courses_capacity, &courses_actual); read_students(argv[2], &students, &students_capacity, &students_actual); display_info(courses, students, courses_actual, students_actual); deallocate_courses(courses); deallocate_students(students, &students_actual); return 0; } // main()
void read_server(int sfd, t_client *client, t_map *map) { char buffer[4096]; int ret; if ((ret = read(sfd, buffer, 4096)) == -1) fprintf(stderr, "Read failed\n"); else { if (ret == 0) exit(EXIT_SUCCESS); buffer[ret - 2] = 0; if (display_info(buffer, client, map)) client->toClient = xstrcat(client->toClient, textcolor(RED, "code unknow", 1)); } }
int main(int ac, char **av) { t_box box; int fd; ft_bzero(&box, sizeof(t_box)); box.color = 0xFFFFFF; if (ac > 2) analyze_args(ac, av, &box); if (ac < 2) error_lem("NO ARGUMENT\n", &box); fd = open(av[ac - 1], O_RDONLY); setup_env(&box, fd); setup_map(&box); display_info(); mlx_hook(box.win, 2, (1L << 0), command, &box); mlx_loop(box.mlx); return (0); }
int download_standard(u32 data_length) { int r; display_info("USB Transferring... "); TIME_START; r = usb_read(download_base, data_length); if ((r < 0) || ((unsigned) r != data_length)) { dprintf(DBG_LV, "Read USB error.\n"); display_speed_info("Read USB error", data_length); fastboot_fail_wrapper("Read USB error"); fastboot_state = STATE_ERROR; return; } download_size = data_length; dprintf(DBG_LV, "read OK. data:0x%x\n", *((int*)download_base)); fastboot_ok_wrapper("USB Transmission OK", data_length); }
// display to screen void Controller::display() { _window.clear(); // _window.setView(_cnvs_view); _canvas.display(_window); // _window.setView(_fixed); // draw menus for (unsigned i = 0; i < _menus.size(); i++) _menus[i]->display(_window); // draw information about the shapes display_info(); // draw shapes // display _window.display(); }
void setup_mesh_faces(t_obj_data *obj_data, t_face_list *face_list) { int i; int *ids; int uv_count; i = 0; obj_data->indice_count = obj_data->face_count * 3; obj_data->indices = (GLushort*)malloc(sizeof(GLushort) * obj_data->indice_count); obj_data->vertices = (t_vertex*)malloc(sizeof(t_vertex) * obj_data->indice_count); uv_count = obj_data->uv_count > 0 ? obj_data->uv_count : 1; ids = (int*)malloc(sizeof(int) * obj_data->vertex_count * uv_count); while (i < obj_data->vertex_count * uv_count) ids[i++] = -1; obj_data->vertex_count = process_data(obj_data, uv_count, face_list, ids); free(ids); display_info(obj_data); }
int main(int argc, char *argv[]) { nf2.device_name = DEFAULT_IFACE; processArgs(argc, argv); if (check_iface(&nf2)) { exit(1); } if (openDescriptor(&nf2)) { exit(1); } nf2_read_info(&nf2); display_info(&nf2); closeDescriptor(&nf2); return 0; }
/** * The robot following/avoid a light and will be stop at a distance predefinited * @global _mode_light_ it must be set */ void go_light_stop(int distance) { int goForward; /* 1=> forward, 0 => STOP, -1 => backward */ int margin; /* The margin used to stop the robot in a aera is function by the stop distance */ int avCells; /* The average value between photo cells */ _go_light_stop_running_ = 1; distance = cmToPhotons(distance); margin = cmToPhotons(_motor_initial_speed_/10); avCells = (analog(photo_left) + analog(photo_right))/2; goForward = 1; while(_go_light_stop_running_ && (goForward != 0)) { int diff; /* Diffference between photos cells */ diff = light_diff(); diff *= _light_environnement_; /* Go more efficiently to the light specifing the environnement */ /* Invert the mode */ if(_mode_light_ == GO_DARK) { diff= -diff; } display_info(); /* Display the difference and values of photo cells */ avCells = (analog(photo_left) + analog(photo_right))/2; /* Refresh the average of cells */ goForward = (avCells > distance+margin) - (avCells < distance-margin); driveb(goForward*_motor_initial_speed_, diff); } /* The robot is on the right position */ stop(); _go_light_stop_running_ = -1; }
int main(int argc, char *argv[]) { DBM *db; datum key, val; int count = 1; if (argc != 2) { printf("%s - dumps mod_dav lock database\n", argv[0]); printf("%s: no database specified (don't include extension)\n", argv[0]); return(-1); } if (CheckFile(argv, ".pag")) return(-1); if (CheckFile(argv, ".dir")) return(-1); db = sdbm_open((char *) argv[1], O_RDONLY | O_BINARY, DAV_FS_MODE_FILE); key = sdbm_firstkey(db); if (key.dsize == 0) { printf("%s: no outstanding locks.\n", argv[0]); } else { while(key.dsize) { printf("[Lock record #%3d]\n", count++); val = sdbm_fetch(db, key); if (display_info(key, val) == -1) return(-1); key = sdbm_nextkey(db); } } sdbm_close(db); exit(0); }
int main(int argc, char **argv) { int c; int err; uint8_t buf[MS_BUF_SIZE]; u32_t pstart, pend, cstart, cend, dstart, dend; int do_dblk_loc, do_panic0; while ((c = getopt_long(argc,argv,"c:d:p:DhvVw", longopts, NULL)) != EOF) switch (c) { case 'c': fprintf(stderr, "-c not implemented yet, defaults to 8192\n"); break; case 'd': fprintf(stderr, "-d not implemented yet, defaults to 0 (rest of partition\n"); break; case 'D': debug++; break; case 'h': usage(argv[0]); break; case 'p': fprintf(stderr, "-c not implemented yet, defaults to 128k\n"); break; case 'v': verbose++; break; case 'V': fprintf(stderr, VERSION); exit(0); break; case 'w': do_write++; break; default: usage(argv[0]); break; } if (optind != argc - 1) usage(argv[0]); if (verbose) fprintf(stderr, VERSION); fx_hard_init(); err = ms_init(argv[optind]); if (err == MS_READONLY) { fprintf(stderr, "mkdblk: %s is read only\n", argv[optind]); err = MS_OK; do_write = 0; } if (err) { fprintf(stderr, "ms_init: %s (0x%x)\n", ms_dsp_err(err), err); exit(1); } err = fx_set_buf(buf); if (err) { fprintf(stderr, "fx_set_buf: %s (0x%x)\n", fx_dsp_err(err), err); exit(1); } err = fx_init(); if (err) { fprintf(stderr, "fx_init: %s (0x%x)\n", fx_dsp_err(err), err); exit(1); } if (!do_write) { display_info(); exit(0); } do_dblk_loc = 1; do_panic0 = !msc.panic0_blk; err = fx_create_contig("PANIC001", " ", panic_size, &pstart, &pend); if (err) { fprintf(stderr, "fx_create_contig: PANIC001: %s (0x%x)\n", fx_dsp_err(err), err); pstart = msc.panic_start; pend = msc.panic_end; do_dblk_loc = 0; } err = fx_create_contig("CNFG0001", " ", config_size, &cstart, &cend); if (err) { fprintf(stderr, "fx_create_contig: CNFG0001: %s (0x%x)\n", fx_dsp_err(err), err); cstart = msc.config_start; cend = msc.config_end; do_dblk_loc = 0; } err = fx_create_contig("DBLK0001", " ", dblk_size, &dstart, &dend); if (err) { fprintf(stderr, "fx_create_contig: DBLK0001: %s (0x%x)\n", fx_dsp_err(err), err); dstart = msc.dblk_start; dend = msc.dblk_end; do_dblk_loc = 0; } if (do_dblk_loc) { fprintf(stderr, "*** writing dblk locator\n"); err = fx_write_locator(pstart, pend, cstart, cend, dstart, dend); if (err) { fprintf(stderr, "fx_write_locator: %s (0x%x)\n", fx_dsp_err(err), err); exit(1); } do_panic0 = 1; /* always write if we wrote the dblk locator */ } if (do_panic0) { fprintf(stderr, "*** writing PANIC0 blk\n"); err = fx_write_panic0(pstart, pend); if (err) { fprintf(stderr, "fx_write_panic: %s (0x%x)\n", fx_dsp_err(err), err); exit(1); } } display_info(); if (!do_dblk_loc && !do_panic0) fprintf(stderr, "*** no changes written\n"); err = fx_set_buf(NULL); if (err) { fprintf(stderr, "fx_set_buf: %s (0x%x)\n", fx_dsp_err(err), err); exit(1); } return(0); }
int main(int argc, char **argv) { TCCState *s; int ret, optind, i; int64_t start_time = 0; s = tcc_new(); optind = tcc_parse_args(s, argc - 1, argv + 1); if (s->do_bench) start_time = getclock_us(); tcc_set_environment(s); if (optind == 0) { help(); return 1; } if (s->option_m) exec_other_tcc(s, argv, s->option_m); if (s->verbose) display_info(s, 0); if (s->print_search_dirs || (s->verbose == 2 && optind == 1)) { tcc_set_output_type(s, TCC_OUTPUT_MEMORY); display_info(s, 1); return 0; } if (s->verbose && optind == 1) return 0; if (s->nb_files == 0) tcc_error("no input files\n"); /* check -c consistency : only single file handled. XXX: checks file type */ if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) { if (s->nb_libraries != 0) tcc_error("cannot specify libraries with -c"); /* accepts only a single input file */ if ((s->nb_files != 1) && s->outfile) { tcc_error("cannot specify multiple files with -c and -o"); } } if (s->output_type == TCC_OUTPUT_PREPROCESS) { if (!s->outfile) { s->ppfp = stdout; } else { s->ppfp = fopen(s->outfile, "w"); if (!s->ppfp) tcc_error("could not write '%s'", s->outfile); } } tcc_set_output_type(s, s->output_type); /* compile or add each files or library */ for(i = ret = 0; i < s->nb_files && ret == 0; i++) { int filetype = *(unsigned char *)s->files[i]; const char *filename = s->files[i] + 1; if (filename[0] == '-' && filename[1] == 'l') { if (tcc_add_library(s, filename + 2) < 0) { tcc_error_noabort("cannot find library 'lib%s'", filename+2); ret = 1; } } else { if (1 == s->verbose) printf("-> %s\n", filename); if (!s->outfile) s->outfile = default_outputfile(s, filename); if (tcc_add_file(s, filename, filetype) < 0) ret = 1; else if (s->output_type == TCC_OUTPUT_OBJ) { ret = !!tcc_output_file(s, s->outfile); if (s->gen_deps && !ret) gen_makedeps(s, s->outfile, s->deps_outfile); if (!ret) { if ((i+1) < s->nb_files) { tcc_delete(s); s = tcc_new(); tcc_parse_args(s, argc - 1, argv + 1); tcc_set_environment(s); if (s->output_type != TCC_OUTPUT_OBJ) tcc_error("interlnal error"); tcc_set_output_type(s, s->output_type); } } } } } if (0 == ret) { if (s->output_type == TCC_OUTPUT_MEMORY) { #ifdef TCC_IS_NATIVE ret = tcc_run(s, argc - 1 - optind, argv + 1 + optind); #else tcc_error_noabort("-run is not available in a cross compiler"); ret = 1; #endif } else if (s->output_type == TCC_OUTPUT_EXE || s->output_type == TCC_OUTPUT_DLL) { ret = !!tcc_output_file(s, s->outfile); if (s->gen_deps && !ret) gen_makedeps(s, s->outfile, s->deps_outfile); } } if (s->do_bench) tcc_print_stats(s, getclock_us() - start_time); tcc_delete(s); return ret; }
void main() { display_info(); char name[50]; int choice,winnings; srand(time(NULL)); char intro[] = "\t\t\tWelcome to JAPA340 Game of Craps feat various characters across different books!\n\n\nPlease enter your name so we may begin\t"; printf("%s",intro); fgets(name,50,stdin); double bankroll=100,noriko=500,lily=100,Yoko=40;//Bankroll printf("Welcome %sLet's enjoy this wonderful game of Craps with Star Lily, Noriko, and Yoko. Press enter to continue:\t",name); getch(); int playagain; bank_problems(); fflush(stdin); printf("\t\t\tAre you aware of the game of craps? Press 1 for Yes or 2 for No:\t"); scanf("%d",&choice); if(choice==2){ printf("\t\t\tPlease check out the wiki page here, press enter when you understand\n"); system("start http://www.wikihow.com/Play-Craps"); getch(); } //printf("Let us begin the game of craps! %sYou're up first!\n",name); while(1) { fflush(stdin); printf("\t\t\t\t\tSelect who you wish to be!\n\t\tPress 1 for Noriko, press 2 for Yoko, press 3 for Lily, press 4 for yourself, press 5 to quit\n"); scanf("%d",&choice); switch(choice) { case 1: winnings=0; winnings = Game(&noriko,"Noriko"); if(winnings!=0)//We won something that isn't bad { bankroll = (double)(bankroll+winnings);//Add up the bank roll and reset the winnnings winnings=0; printf("\nYour bankroll is now at $%.02lf\n\n\n",bankroll);//Tell them how much skrilla they made } results(noriko,winnings); break; case 2: winnings=0; winnings = Game(&Yoko,"Yoko"); if(winnings==0){printf("\n\n\t\t\tBecause of YOUR actions Yoko realized that her marriage was fake\n\n\n");} if(winnings!=0)//We won something that isn't bad { Yoko = (double)(Yoko+winnings);//Add up the bank roll and reset the winnnings winnings=0; printf("\nYour bankroll is now at $%.02lf\n\n\n",Yoko);//Tell them how much skrilla they made } results(Yoko,winnings); break; case 3: winnings=0; winnings = Game(&lily,"Lily"); if(winnings==0){printf("\n\n\t\t\tBecause you lost at craps lily loses an eye to her father\n\n\n");} if(winnings!=0)//We won something that isn't bad { lily = (double)(lily+winnings);//Add up the bank roll and reset the winnnings winnings=0; printf("\nYour bankroll is now at $%.02lf\n\n\n",lily);//Tell them how much skrilla they made } results(lily,winnings); break; case 4: winnings = Game(&bankroll,name);//LETS PLAY THE GAME results(bankroll,winnings); break; case 5: printf("The game will now exit, goodbye %s",name); exit(1); } } }
BOOL read_usb_proc(void *arg) { char msg[128]; u32 bytes_already_read = 0; u32 data_length = *((u32*)arg); u32 bytes_read = 0; int bytes_read_once = 0; u32 bytes_left = 0; dprintf(DBG_DCACHE, "++[%d]Enter read_usb_proc\n", TIME_STAMP); while (bytes_already_read < data_length) { dprintf(DBG_DCACHE, "++[%d]Wait ID:%d cache to write\n", TIME_STAMP, ctx.flipIdxW); event_wait(&(ctx.dual_cache[ctx.flipIdxW].cache_available)); dprintf(DBG_DCACHE, "++[%d]Obtain ID:%d cache to write, \n", TIME_STAMP, ctx.flipIdxW); if(ctx.b_error) { sprintf(msg, "\nError Write?\n"); goto error; } bytes_read = 0; bytes_left = data_length - bytes_already_read; bytes_left = bytes_left >= CACHE_PAGE_SIZE ? CACHE_PAGE_SIZE : bytes_left; dprintf(DBG_DCACHE, "++[%d]READ USB to ID:%d\n", TIME_STAMP, ctx.flipIdxW); while(bytes_left > 0) { bytes_read_once = usb_read(ctx.dual_cache[ctx.flipIdxW].cache_buf + bytes_read, bytes_left); if (bytes_read_once < 0) { abort_engine(&ctx); dprintf(DBG_LV, "Read USB error.\n"); display_info("\nRead USB error\n"); fastboot_state = STATE_ERROR; return FALSE; } bytes_left -= bytes_read_once; bytes_read += bytes_read_once; } ctx.dual_cache[ctx.flipIdxW].content_length = bytes_read; bytes_already_read += bytes_read; dprintf(DBG_DCACHE, "++[%d]Notify ID:%d cache readable\n", TIME_STAMP, ctx.flipIdxW); event_signal(&ctx.dual_cache[ctx.flipIdxW].content_available, SIGNAL_RESCHEDULE); ctx.flipIdxW = cache_shift(ctx.flipIdxW); //change next buffer. display_progress("\rTransfer Data", bytes_already_read, data_length); } if(bytes_already_read != data_length) { dprintf(DBG_LV, "ASSERT error. bytes_already_read != data_length\n"); //cause assert. *((int*)0x00) = 0; } dprintf(DBG_DCACHE, "++[%d]USB read Fin\n", TIME_STAMP); //last package. //must wait for this can write again. event_wait(&(ctx.dual_cache[ctx.flipIdxW].cache_available)); ctx.dual_cache[ctx.flipIdxW].content_length = 0; event_signal(&ctx.dual_cache[ctx.flipIdxW].content_available, SIGNAL_RESCHEDULE); return TRUE; error: dprintf(DBG_LV, msg); display_info(msg); abort_engine(&ctx); return FALSE; }
int write_storage_proc(void *arg) { u8* data = 0; u32 data_len = 0; char msg[128]; u64 image_offset = 0; u32 round = 0; //dprintf(DBG_DCACHE, " --[%d] Enter write_storage_proc \n", TIME_STAMP); for (;;) { dprintf(DBG_DCACHE, " --[%d]Wait ID:%d cache to read, \n", TIME_STAMP, ctx.flipIdxR); event_wait(&(ctx.dual_cache[ctx.flipIdxR].content_available)); dprintf(DBG_DCACHE, " --[%d]Obtain ID:%d cache to read, \n", TIME_STAMP, ctx.flipIdxR); if(ctx.b_error) { sprintf(msg, "\nError USB?\n"); goto error; } //if has something to write if(ctx.dual_cache[ctx.flipIdxR].content_length !=0 || ctx.dual_cache[ctx.flipIdxR].padding_length !=0) { data = (u8*)(ctx.dual_cache[ctx.flipIdxR].cache_buf); data_len = ctx.dual_cache[ctx.flipIdxR].content_length; #ifdef MTK_SECURITY_SW_SUPPORT if(!security_check(&data, &data_len, image_offset, NULL)) { //security error. sprintf(msg, "\nSecurity deny - Err:0x%x \n", sec_error()); goto error; } #endif image_offset += ctx.dual_cache[ctx.flipIdxR].content_length; data -= ctx.dual_cache[ctx.flipIdxR].padding_length; data_len += ctx.dual_cache[ctx.flipIdxR].padding_length; //if data_len==0, secure img tail met. dprintf(DBG_DCACHE, " --[%d]Write ID:%d to EMMC \n", TIME_STAMP, ctx.flipIdxR); #ifdef MTK_SECURITY_SW_SUPPORT if(!write_data(data, data_len, sec_lib_security_get_img_total_size())) #else if(!write_data(data, data_len, 0)) #endif { //error sprintf(msg, "\nWrite data error. \n"); goto error; } } //last package, should return; if (ctx.dual_cache[ctx.flipIdxR].content_length == 0) { dprintf(DBG_DCACHE, " --[%d]Write EMMC Fin\n", TIME_STAMP); data_len = 0; #ifdef MTK_SECURITY_SW_SUPPORT security_check(&data, &data_len, image_offset, NULL); //notify security check that is the end. #endif if(ctx.boot_like_info.is_boot_like_image) { //boot image need download_size to flash. download_size = sto_info.to_write_data_len; //cache using is over, so copy boot image to download_base memcpy(download_base, ctx.boot_like_info.boot_like_image_address, download_size); } event_signal(&ctx.dual_cache[0].cache_available, SIGNAL_RESCHEDULE);//prevent from dead lock. event_signal(&ctx.dual_cache[1].cache_available, SIGNAL_RESCHEDULE); event_signal(&ctx.thr_end_ev, SIGNAL_RESCHEDULE); return 0; } round++; dprintf(DBG_DCACHE, " --[%d]Notify ID:%d cache writeable\n", TIME_STAMP, ctx.flipIdxR); event_signal(&ctx.dual_cache[ctx.flipIdxR].cache_available, SIGNAL_RESCHEDULE); //make this cache writeable again. ctx.flipIdxR = cache_shift(ctx.flipIdxR); //change next buffer. } return 0; error: dprintf(DBG_LV, msg); display_info(msg); abort_engine(&ctx); return (-1); }