static int cmd_listformats(const struct command *c, int argc, char *argv[]) { const imgtool_module *mod; fprintf(stdout, "Image formats supported by imgtool:\n\n"); mod = imgtool_find_module(NULL); while(mod) { fprintf(stdout, " %-25s%s\n", mod->name, mod->description); mod = mod->next; } return 0; }
static int cmd_listdriveroptions(const struct command *c, int argc, char *argv[]) { const imgtool_module *mod; const option_guide *opt_guide; const char *opt_spec; mod = imgtool_find_module(argv[0]); if (!mod) goto error; fprintf(stdout, "Driver specific options for module '%s':\n\n", argv[0]); /* list write options */ opt_guide = (const option_guide *) imgtool_get_info_ptr(&mod->imgclass, IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE); opt_spec = imgtool_get_info_string(&mod->imgclass, IMGTOOLINFO_STR_WRITEFILE_OPTSPEC); if (opt_guide) { fprintf(stdout, "Image specific file options (usable on the 'put' command):\n\n"); listoptions(opt_guide, opt_spec); puts("\n"); } else { fprintf(stdout, "No image specific file options\n\n"); } /* list create options */ opt_guide = mod->createimage_optguide; if (opt_guide) { fprintf(stdout, "Image specific creation options (usable on the 'create' command):\n\n"); listoptions(opt_guide, mod->createimage_optspec); puts("\n"); } else { fprintf(stdout, "No image specific creation options\n\n"); } return 0; error: reporterror((imgtoolerr_t)(IMGTOOLERR_MODULENOTFOUND|IMGTOOLERR_SRC_MODULE), c, argv[0], NULL, NULL, NULL, NULL); return -1; }
static int cmd_create(const struct command *c, int argc, char *argv[]) { imgtoolerr_t err; int unnamedargs; const imgtool_module *module; option_resolution *resolution = NULL; module = imgtool_find_module(argv[0]); if (!module) { err = (imgtoolerr_t)(IMGTOOLERR_MODULENOTFOUND | IMGTOOLERR_SRC_MODULE); goto error; } if (module->createimage_optguide && module->createimage_optspec) { resolution = option_resolution_create(module->createimage_optguide, module->createimage_optspec); if (!resolution) { err = IMGTOOLERR_OUTOFMEMORY; goto error; } } unnamedargs = parse_options(argc, argv, 2, 3, resolution, NULL, NULL); if (unnamedargs < 0) return -1; err = imgtool_image_create(module, argv[1], resolution, NULL); if (err) goto error; if (resolution) option_resolution_close(resolution); return 0; error: if (resolution) option_resolution_close(resolution); reporterror(err, c, argv[0], argv[1], NULL, NULL, 0); return -1; }
static int cmd_create(const struct command *c, int argc, char *argv[]) { imgtoolerr_t err; int unnamedargs; const imgtool_module *module; std::unique_ptr<util::option_resolution> resolution; module = imgtool_find_module(argv[0]); if (!module) { err = (imgtoolerr_t)(IMGTOOLERR_MODULENOTFOUND | IMGTOOLERR_SRC_MODULE); goto error; } if (module->createimage_optguide && module->createimage_optspec) { try { resolution.reset(new util::option_resolution(module->createimage_optguide, module->createimage_optspec)); } catch (...) { err = IMGTOOLERR_OUTOFMEMORY; goto error; } } unnamedargs = parse_options(argc, argv, 2, 3, resolution.get(), nullptr, nullptr); if (unnamedargs < 0) return -1; err = imgtool_image_create(module, argv[1], resolution.get(), nullptr); if (err) goto error; return 0; error: reporterror(err, c, argv[0], argv[1], nullptr, nullptr, nullptr); return -1; }
static void node_createimage(struct imgtooltest_state *state, xml_data_node *node) { imgtoolerr_t err; xml_data_node *child_node; xml_attribute_node *attr_node; option_resolution *opts = NULL; const imgtool_module *module; const char *driver; const char *param_name; const char *param_value; attr_node = xml_get_attribute(node, "driver"); if (!attr_node) { error_missingattribute("driver"); return; } driver = attr_node->value; /* does image creation support options? */ module = imgtool_find_module(attr_node->value); if (module && module->createimage_optguide && module->createimage_optspec) opts = option_resolution_create(module->createimage_optguide, module->createimage_optspec); report_message(MSG_INFO, "Creating image (module '%s')", driver); for (child_node = xml_get_sibling(node->child, "param"); child_node; child_node = xml_get_sibling(child_node->next, "param")) { if (!opts) { report_message(MSG_FAILURE, "Cannot specify creation options with this module"); return; } attr_node = xml_get_attribute(child_node, "name"); if (!attr_node) { error_missingattribute("name"); return; } param_name = attr_node->value; attr_node = xml_get_attribute(child_node, "value"); if (!attr_node) { error_missingattribute("value"); return; } param_value = attr_node->value; option_resolution_add_param(opts, param_name, param_value); } err = imgtool_image_create_byname(driver, tempfile_name(), opts, &state->m_image); if (opts) { option_resolution_close(opts); opts = NULL; } if (err) { state->m_failed = 1; report_imgtoolerr(err); return; } err = imgtool_partition_open(state->m_image, 0, &state->m_partition); if (err) { state->m_failed = 1; report_imgtoolerr(err); return; } }
static int cmd_put(const struct command *c, int argc, char *argv[]) { imgtoolerr_t err = IMGTOOLERR_SUCCESS; int i; imgtool_image *image = NULL; imgtool_partition *partition = NULL; const char *filename = NULL; int unnamedargs; filter_getinfoproc filter; const imgtool_module *module; option_resolution *resolution = NULL; const char *fork; const char *new_filename; char **filename_list; int filename_count; int partition_index = 0; const option_guide *writefile_optguide; const char *writefile_optspec; module = imgtool_find_module(argv[0]); if (!module) { err = (imgtoolerr_t)(IMGTOOLERR_MODULENOTFOUND | IMGTOOLERR_SRC_MODULE); goto done; } /* ugh I hate the way this function is set up, this is because the * arguments depend on the partition; something that requires some * rudimentary parsing */ if (argc >= 2) { /* open up the image */ err = imgtool_image_open(module, argv[1], OSD_FOPEN_RW, &image); if (err) goto done; /* open up the partition */ err = imgtool_partition_open(image, partition_index, &partition); if (err) goto done; writefile_optguide = (const option_guide *) imgtool_partition_get_info_ptr(partition, IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE); writefile_optspec = (const char *)imgtool_partition_get_info_ptr(partition, IMGTOOLINFO_STR_WRITEFILE_OPTSPEC); if (writefile_optguide && writefile_optspec) { resolution = option_resolution_create(writefile_optguide, writefile_optspec); if (!resolution) { err = IMGTOOLERR_OUTOFMEMORY; goto done; } } } unnamedargs = parse_options(argc, argv, 4, 0xffff, resolution, &filter, &fork); if (unnamedargs < 0) return -1; /* pick out which args are filenames, and which one is the destination */ new_filename = interpret_filename(argv[unnamedargs - 1]); filename_list = &argv[2]; filename_count = unnamedargs - 3; /* loop through the filenames, and put them */ for (i = 0; i < filename_count; i++) { filename = filename_list[i]; printf("Putting file '%s'...\n", filename); err = imgtool_partition_put_file(partition, new_filename, fork, filename, resolution, filter); if (err) goto done; } done: if (partition) imgtool_partition_close(partition); if (image) imgtool_image_close(image); if (resolution) option_resolution_close(resolution); if (err) reporterror(err, c, argv[0], argv[1], filename, NULL, resolution); return err ? -1 : 0; }