Beispiel #1
0
int run_help()
{
    int j;
    for(j=0; j<arg_list_count; j++)
    {
        argument& a= arg_list[j];
        gz_out << '\n' << a.name << " - " << a.desc<<"\n";
        show_valid_options(a);
    }
    return 0;
}
Beispiel #2
0
static void process_args(int argc, char **argv)
{
	char *ptr;
	int type = IH_TYPE_INVALID;
	char *datafile = NULL;
	int opt;

	while ((opt = getopt(argc, argv,
			     "a:A:b:c:C:d:D:e:Ef:Fk:K:ln:p:O:rR:qsT:vVx")) != -1) {
		switch (opt) {
		case 'a':
			params.addr = strtoull(optarg, &ptr, 16);
			if (*ptr) {
				fprintf(stderr, "%s: invalid load address %s\n",
					params.cmdname, optarg);
				exit(EXIT_FAILURE);
			}
			break;
		case 'A':
			params.arch = genimg_get_arch_id(optarg);
			if (params.arch < 0) {
				show_valid_options(IH_ARCH);
				usage("Invalid architecture");
			}
			break;
		case 'b':
			if (add_content(IH_TYPE_FLATDT, optarg)) {
				fprintf(stderr,
					"%s: Out of memory adding content '%s'",
					params.cmdname, optarg);
				exit(EXIT_FAILURE);
			}
			break;
		case 'c':
			params.comment = optarg;
			break;
		case 'C':
			params.comp = genimg_get_comp_id(optarg);
			if (params.comp < 0) {
				show_valid_options(IH_COMP);
				usage("Invalid compression type");
			}
			break;
		case 'd':
			params.datafile = optarg;
			params.dflag = 1;
			break;
		case 'D':
			params.dtc = optarg;
			break;
		case 'e':
			params.ep = strtoull(optarg, &ptr, 16);
			if (*ptr) {
				fprintf(stderr, "%s: invalid entry point %s\n",
					params.cmdname, optarg);
				exit(EXIT_FAILURE);
			}
			params.eflag = 1;
			break;
		case 'E':
			params.external_data = true;
			break;
		case 'f':
			datafile = optarg;
			params.auto_its = !strcmp(datafile, "auto");
			/* no break */
		case 'F':
			/*
			 * The flattened image tree (FIT) format
			 * requires a flattened device tree image type
			 */
			params.type = IH_TYPE_FLATDT;
			params.fflag = 1;
			break;
		case 'k':
			params.keydir = optarg;
			break;
		case 'K':
			params.keydest = optarg;
			break;
		case 'l':
			params.lflag = 1;
			break;
		case 'n':
			params.imagename = optarg;
			break;
		case 'O':
			params.os = genimg_get_os_id(optarg);
			if (params.os < 0) {
				show_valid_options(IH_OS);
				usage("Invalid operating system");
			}
			break;
		case 'p':
			params.external_offset = strtoull(optarg, &ptr, 16);
			if (*ptr) {
				fprintf(stderr, "%s: invalid offset size %s\n",
					params.cmdname, optarg);
				exit(EXIT_FAILURE);
			}
			break;
		case 'q':
			params.quiet = 1;
			break;
		case 'r':
			params.require_keys = 1;
			break;
		case 'R':
			/*
			 * This entry is for the second configuration
			 * file, if only one is not enough.
			 */
			params.imagename2 = optarg;
			break;
		case 's':
			params.skipcpy = 1;
			break;
		case 'T':
			type = genimg_get_type_id(optarg);
			if (type < 0) {
				show_valid_options(IH_TYPE);
				usage("Invalid image type");
			}
			break;
		case 'v':
			params.vflag++;
			break;
		case 'V':
			printf("mkimage version %s\n", PLAIN_VERSION);
			exit(EXIT_SUCCESS);
		case 'x':
			params.xflag++;
			break;
		default:
			usage("Invalid option");
		}
	}

	/* The last parameter is expected to be the imagefile */
	if (optind < argc)
		params.imagefile = argv[optind];

	/*
	 * For auto-generated FIT images we need to know the image type to put
	 * in the FIT, which is separate from the file's image type (which
	 * will always be IH_TYPE_FLATDT in this case).
	 */
	if (params.type == IH_TYPE_FLATDT) {
		params.fit_image_type = type ? type : IH_TYPE_KERNEL;
		/* For auto_its, datafile is always 'auto' */
		if (!params.auto_its)
			params.datafile = datafile;
		else if (!params.datafile)
			usage("Missing data file for auto-FIT (use -d)");
	} else if (type != IH_TYPE_INVALID) {
		params.type = type;
	}

	if (!params.imagefile)
		usage("Missing output filename");
}
Beispiel #3
0
int main(int argc, char** argv)
{
	ZT_ENABLE();


	z_zipex x;
	zout << sizeof(x);
	


	//z_trace_enable();
	//___________________________________________________________
	//
	//   Load/Save debug arguments
	//___________________________________________________________

	z_debug_load_save_args(&argc,&argv);

	//___________________________________________________________
	//
	//assign args 
	//___________________________________________________________
	int i;
	for (i=1;i<argc;i++)
	{
		size_t j;
		z_string name;
		z_string val;
		zp_text_parser argp(argv[i]);
		if(argp.test_any_identifier()==zs_matched)
		{
			argp.get_match(name);
			if(argp.test_char('=')==zs_matched)
			{
				argp.test_to_eob();
				argp.get_match(val);
			}
			for(j=0;j<arg_list_count;j++)
			{
				argument& a= arg_list[j];
				if(name==a.name)
				{
					if(a.num_valid_options)
					{
						option* opt=get_option(a,val);
						if(!opt)
						{
							zout<<"\nERROR! Invalid option \"" <<val<<"\" for argument \""<<name<<"\"\n\n";
							show_valid_options(a);
							return -1;
							break;
						}
					}
					a.ref_variable=val;
					break;
				}
			}
			if(j==arg_list_count)
			{
				zout<<"\nERROR! Invalid argument \"" <<name<<"\"\n\n";
				run_help();
				exit(0);
				
			}
		}
	}

	//___________________________________________________________
	//
	//Check Data file
	//___________________________________________________________

	if(g_arg_file_input_data)
	{
		z_file f;
		if(f.open(g_arg_file_input_data,"rb")==-1)
		{
			zout<<"\nERROR! Cannot open \"" <<g_arg_file_input_data<<"\"\n\n";
			return -1;
		}
		f.read_all(g_file_buffer);
		g_arg_data_in=g_file_buffer.c_str();

	}
	//___________________________________________________________
	//
	//Check Class type
	//___________________________________________________________

	if(g_arg_obj_type)
	{


	}
	//___________________________________________________________
	//
	//Check Test Type
	//___________________________________________________________

	option* opt=get_option(arg_list[2],g_arg_test_type);
	if(!opt)
	{
		zout << "Invalid test type  \""<<g_arg_test_type <<"\"\n";
		return -1;
	}
	g_test_type_function_to_run=opt->pfunc;
	if(!g_test_type_function_to_run)
	{
		zout << "No function for  \""<<opt->name <<"\"\n";
		return -1;
	}
	//___________________________________________________________
	//
	//execute operation 
	//___________________________________________________________
	int ret;
	opt=get_option(arg_list[0],g_arg_operation);
	if(!opt)
	{
		ret= run_help();
	}
	else
	{
		opt_func fp=opt->pfunc;
		if(fp)
		{
			ret= (*fp)();
		}
		else
		zout << "No action for "<< g_arg_operation << "\n";
	}
	//char* ax=z_new char[4];
	_CrtDumpMemoryLeaks();
	return ret;

}