static int create_cmd(int argc, char *argv[])
{
    struct option opts[toc_entries_len + 1];
    unsigned long long toc_flags = 0;
    int i;

    if (argc < 2)
        usage();

    i = fill_common_opts(opts, required_argument);
    add_opt(opts, i, "plat-toc-flags", required_argument,
            OPT_PLAT_TOC_FLAGS);
    add_opt(opts, ++i, NULL, 0, 0);

    while (1) {
        int c, opt_index;

        c = getopt_long(argc, argv, "o:", opts, &opt_index);
        if (c == -1)
            break;

        switch (c) {
        case OPT_TOC_ENTRY: {
            toc_entry_t *toc_entry;

            toc_entry = &toc_entries[opt_index];
            toc_entry->action = DO_PACK;
            toc_entry->action_arg = strdup(optarg);
            if (toc_entry->action_arg == NULL)
                log_err("strdup");
            break;
        }
        case OPT_PLAT_TOC_FLAGS:
            parse_plat_toc_flags(optarg, &toc_flags);
            break;
        default:
            usage();
        }
    }
    argc -= optind;
    argv += optind;

    if (argc == 0)
        usage();

    update_fip();

    pack_images(argv[0], toc_flags);
    free_images();
    return 0;
}
static int update_cmd(int argc, char *argv[])
{
    struct option opts[toc_entries_len + 2];
    char outfile[FILENAME_MAX] = { 0 };
    fip_toc_header_t toc_header = { 0 };
    unsigned long long toc_flags = 0;
    int pflag = 0;
    int i;

    if (argc < 2)
        usage();

    i = fill_common_opts(opts, required_argument);
    add_opt(opts, i, "out", required_argument, 'o');
    add_opt(opts, ++i, "plat-toc-flags", required_argument,
            OPT_PLAT_TOC_FLAGS);
    add_opt(opts, ++i, NULL, 0, 0);

    while (1) {
        int c, opt_index;

        c = getopt_long(argc, argv, "o:", opts, &opt_index);
        if (c == -1)
            break;

        switch (c) {
        case OPT_TOC_ENTRY: {
            toc_entry_t *toc_entry;

            toc_entry = &toc_entries[opt_index];
            toc_entry->action = DO_PACK;
            toc_entry->action_arg = strdup(optarg);
            if (toc_entry->action_arg == NULL)
                log_err("strdup");
            break;
        }
        case OPT_PLAT_TOC_FLAGS: {
            parse_plat_toc_flags(optarg, &toc_flags);
            pflag = 1;
            break;
        }
        case 'o':
            snprintf(outfile, sizeof(outfile), "%s", optarg);
            break;
        default:
            usage();
        }
    }
    argc -= optind;
    argv += optind;

    if (argc == 0)
        usage();

    if (outfile[0] == '\0')
        snprintf(outfile, sizeof(outfile), "%s", argv[0]);

    if (access(outfile, F_OK) == 0)
        parse_fip(argv[0], &toc_header);

    if (pflag)
        toc_header.flags &= ~(0xffffULL << 32);
    toc_flags = (toc_header.flags |= toc_flags);

    update_fip();

    pack_images(outfile, toc_flags);
    free_images();
    return 0;
}
Esempio n. 3
0
static int update_cmd(int argc, char *argv[])
{
	struct option *opts = NULL;
	size_t nr_opts = 0;
	char outfile[PATH_MAX] = { 0 };
	fip_toc_header_t toc_header = { 0 };
	unsigned long long toc_flags = 0;
	unsigned long align = 1;
	int pflag = 0;

	if (argc < 2)
		update_usage();

	opts = fill_common_opts(opts, &nr_opts, required_argument);
	opts = add_opt(opts, &nr_opts, "align", required_argument, OPT_ALIGN);
	opts = add_opt(opts, &nr_opts, "blob", required_argument, 'b');
	opts = add_opt(opts, &nr_opts, "out", required_argument, 'o');
	opts = add_opt(opts, &nr_opts, "plat-toc-flags", required_argument,
	    OPT_PLAT_TOC_FLAGS);
	opts = add_opt(opts, &nr_opts, NULL, 0, 0);

	while (1) {
		int c, opt_index = 0;

		c = getopt_long(argc, argv, "b:o:", opts, &opt_index);
		if (c == -1)
			break;

		switch (c) {
		case OPT_TOC_ENTRY: {
			image_desc_t *desc;

			desc = lookup_image_desc_from_opt(opts[opt_index].name);
			set_image_desc_action(desc, DO_PACK, optarg);
			break;
		}
		case OPT_PLAT_TOC_FLAGS:
			parse_plat_toc_flags(optarg, &toc_flags);
			pflag = 1;
			break;
		case 'b': {
			char name[_UUID_STR_LEN + 1];
			char filename[PATH_MAX] = { 0 };
			uuid_t uuid = { 0 };
			image_desc_t *desc;

			parse_blob_opt(optarg, &uuid,
			    filename, sizeof(filename));

			if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 ||
			    filename[0] == '\0')
				update_usage();

			desc = lookup_image_desc_from_uuid(&uuid);
			if (desc == NULL) {
				uuid_to_str(name, sizeof(name), &uuid);
				desc = new_image_desc(&uuid, name, "blob");
				add_image_desc(desc);
			}
			set_image_desc_action(desc, DO_PACK, filename);
			break;
		}
		case OPT_ALIGN:
			align = get_image_align(optarg);
			break;
		case 'o':
			snprintf(outfile, sizeof(outfile), "%s", optarg);
			break;
		default:
			update_usage();
		}
	}
	argc -= optind;
	argv += optind;
	free(opts);

	if (argc == 0)
		update_usage();

	if (outfile[0] == '\0')
		snprintf(outfile, sizeof(outfile), "%s", argv[0]);

	if (access(argv[0], F_OK) == 0)
		parse_fip(argv[0], &toc_header);

	if (pflag)
		toc_header.flags &= ~(0xffffULL << 32);
	toc_flags = (toc_header.flags |= toc_flags);

	update_fip();

	pack_images(outfile, toc_flags, align);
	return 0;
}