int fb_execute_queue(usb_handle *usb) { Action *a; char resp[FB_RESPONSE_SZ+1]; int status = 0; a = action_list; if (!a) return status; resp[FB_RESPONSE_SZ] = 0; double start = -1; for (a = action_list; a; a = a->next) { a->start = now(); if (start < 0) start = a->start; if (a->msg) { // fprintf(stderr,"%30s... ",a->msg); fprintf(stderr,"%s...\n",a->msg); } if (a->op == OP_DOWNLOAD) { status = fb_download_data(usb, a->data, a->size); status = a->func(a, status, status ? fb_get_error() : ""); if (status) break; } else if (a->op == OP_COMMAND) { status = fb_command(usb, a->cmd); status = a->func(a, status, status ? fb_get_error() : ""); if (status) break; } else if (a->op == OP_QUERY) { status = fb_command_response(usb, a->cmd, resp); status = a->func(a, status, status ? fb_get_error() : resp); if (status) break; } else if (a->op == OP_NOTICE) { fprintf(stderr,"%s\n",(char*)a->data); } else if (a->op == OP_FORMAT) { status = fb_format(a, usb, (int)a->data); status = a->func(a, status, status ? fb_get_error() : ""); if (status) break; } else if (a->op == OP_DOWNLOAD_SPARSE) { status = fb_download_data_sparse(usb, a->data); status = a->func(a, status, status ? fb_get_error() : ""); if (status) break; } else if (a->op == OP_WAIT_FOR_DISCONNECT) { usb_wait_for_disconnect(usb); } else { die("bogus action"); } } fprintf(stderr,"finished. total time: %.3fs\n", (now() - start)); return status; }
int fb_execute_queue(usb_handle *usb) { Action *a; char resp[FB_RESPONSE_SZ+1]; int status = 0; a = action_list; resp[FB_RESPONSE_SZ] = 0; double start = -1; for (a = action_list; a; a = a->next) { a->start = now(); if (start < 0) start = a->start; if (a->msg) { // fprintf(stderr,"%30s... ",a->msg); fprintf(stderr,"%s...\n",a->msg); } if (a->op == OP_DOWNLOAD) { status = fb_download_data(usb, a->data, a->size); status = a->func(a, status, status ? fb_get_error() : ""); if (status) break; } else if (a->op == OP_COMMAND) { status = fb_command(usb, a->cmd); status = a->func(a, status, status ? fb_get_error() : ""); if (status) { if (strlen(fn_pull) > 0) unlink(fn_pull); if (fd_pull > 0) close(fd_pull); break; } close(fd_pull); } else if (a->op == OP_QUERY) { status = fb_command_response(usb, a->cmd, resp); status = a->func(a, status, status ? fb_get_error() : resp); if (status) break; } else if (a->op == OP_NOTICE) { fprintf(stderr,"%s\n",(char*)a->data); } else if (a->op == OP_FLASH) { status = fb_stream_flash(usb, a->cmd, a->data, a->size); status = a->func(a, status, status ? fb_get_error() : ""); if (status) break; } else { die("bogus action"); } } double split = now() - start; fprintf(stderr,"finished. total time: %.3fs\n", split < 0 ? 0 : split); return status; }
int fb_execute_queue(Transport* transport) { Action *a; char resp[FB_RESPONSE_SZ+1]; int status = 0; a = action_list; if (!a) return status; resp[FB_RESPONSE_SZ] = 0; double start = -1; for (a = action_list; a; a = a->next) { a->start = now(); if (start < 0) start = a->start; if (a->msg) { // fprintf(stderr,"%30s... ",a->msg); fprintf(stderr,"%s...\n",a->msg); } if (a->op == OP_DOWNLOAD) { status = fb_download_data(transport, a->data, a->size); status = a->func(a, status, status ? fb_get_error().c_str() : ""); if (status) break; } else if (a->op == OP_COMMAND) { status = fb_command(transport, a->cmd); status = a->func(a, status, status ? fb_get_error().c_str() : ""); if (status) break; } else if (a->op == OP_QUERY) { status = fb_command_response(transport, a->cmd, resp); status = a->func(a, status, status ? fb_get_error().c_str() : resp); if (status) break; } else if (a->op == OP_NOTICE) { fprintf(stderr,"%s\n",(char*)a->data); } else if (a->op == OP_DOWNLOAD_SPARSE) { status = fb_download_data_sparse(transport, reinterpret_cast<sparse_file*>(a->data)); status = a->func(a, status, status ? fb_get_error().c_str() : ""); if (status) break; } else if (a->op == OP_WAIT_FOR_DISCONNECT) { transport->WaitForDisconnect(); } else { die("bogus action"); } } fprintf(stderr,"finished. total time: %.3fs\n", (now() - start)); return status; }
void fb_execute_queue(usb_handle *usb) { Action *a; char resp[FB_RESPONSE_SZ+1]; int status; a = action_list; resp[FB_RESPONSE_SZ] = 0; double start = -1; for (a = action_list; a; a = a->next) { a->start = now(); if (start < 0) start = a->start; if (a->msg) { // fprintf(stderr,"%30s... ",a->msg); fprintf(stderr,"%s...\n",a->msg); } if (a->op == OP_DOWNLOAD) { status = fb_download_data(usb, a->data, a->size); status = a->func(a, status, status ? fb_get_error() : ""); if (status) break; } else if (a->op == OP_COMMAND) { status = fb_command(usb, a->cmd); status = a->func(a, status, status ? fb_get_error() : ""); if (status) break; } else if (a->op == OP_QUERY) { status = fb_command_response(usb, a->cmd, resp); status = a->func(a, status, status ? fb_get_error() : resp); if (status) break; } else if (a->op == OP_NOTICE) { fprintf(stderr,"%s\n",(char*)a->data); } else { die("bogus action"); } } fprintf(stderr,"finished. total time: %.3fs\n", (now() - start)); }
int fb_format(Action *a, usb_handle *usb, int skip_if_not_supported) { const char *partition = a->cmd; char response[FB_RESPONSE_SZ+1]; int status = 0; struct image_data image; struct generator *generator = NULL; int fd; unsigned i; char cmd[CMD_SIZE]; status = fb_getvar(usb, response, "partition-type:%s", partition); if (status) { if (skip_if_not_supported) { fprintf(stderr, "Erase successful, but not automatically formatting.\n"); fprintf(stderr, "Can't determine partition type.\n"); return 0; } fprintf(stderr,"FAILED (%s)\n", fb_get_error()); return status; } for (i = 0; i < ARRAY_SIZE(generators); i++) { if (!strncmp(generators[i].fs_type, response, FB_RESPONSE_SZ)) { generator = &generators[i]; break; } } if (!generator) { if (skip_if_not_supported) { fprintf(stderr, "Erase successful, but not automatically formatting.\n"); fprintf(stderr, "File system type %s not supported.\n", response); return 0; } fprintf(stderr,"Formatting is not supported for filesystem with type '%s'.\n", response); return -1; } status = fb_getvar(usb, response, "partition-size:%s", partition); if (status) { if (skip_if_not_supported) { fprintf(stderr, "Erase successful, but not automatically formatting.\n"); fprintf(stderr, "Unable to get partition size\n."); return 0; } fprintf(stderr,"FAILED (%s)\n", fb_get_error()); return status; } image.partition_size = strtoll(response, (char **)NULL, 16); generator->generate(&image); if (!image.buffer) { fprintf(stderr,"Cannot generate image.\n"); return -1; } // Following piece of code is similar to fb_queue_flash() but executes // actions directly without queuing fprintf(stderr, "sending '%s' (%lli KB)...\n", partition, image.image_size/1024); status = fb_download_data(usb, image.buffer, image.image_size); if (status) goto cleanup; fprintf(stderr, "writing '%s'...\n", partition); snprintf(cmd, sizeof(cmd), "flash:%s", partition); status = fb_command(usb, cmd); if (status) goto cleanup; cleanup: generator->cleanup(&image); return status; }