Exemplo n.º 1
0
int
fdt_load_dtb_file(const char * filename)
{
	struct preloaded_file *bfp, *oldbfp;
	int err;

	debugf("fdt_load_dtb_file(%s)\n", filename);

	oldbfp = file_findfile(NULL, "dtb");

	/* Attempt to load and validate a new dtb from a file. */
	if ((bfp = file_loadraw(filename, "dtb")) == NULL) {
		sprintf(command_errbuf, "failed to load file '%s'", filename);
		return (1);
	}
	if ((err = fdt_load_dtb(bfp->f_addr)) != 0) {
		file_discard(bfp);
		return (err);
	}

	/* A new dtb was validated, discard any previous file. */
	if (oldbfp)
		file_discard(oldbfp);
	return (0);
}
Exemplo n.º 2
0
static int
command_load_geli(int argc, char *argv[])
{
    char	typestr[80];
    char	*cp;
    int		ch, num;

    if (argc < 3) {
	    command_errmsg = "usage is [-n key#] <prov> <file>";
	    return(CMD_ERROR);
    }

    num = 0;
    optind = 1;
    optreset = 1;
    while ((ch = getopt(argc, argv, "n:")) != -1) {
	switch(ch) {
	case 'n':
	    num = strtol(optarg, &cp, 0);
	    if (cp == optarg) {
		    snprintf(command_errbuf, sizeof (command_errbuf),
			"bad key index '%s'", optarg);
		    return(CMD_ERROR);
	    }
	    break;
	case '?':
	default:
	    /* getopt has already reported an error */
	    return(CMD_OK);
	}
    }
    argv += (optind - 1);
    argc -= (optind - 1);
    sprintf(typestr, "%s:geli_keyfile%d", argv[1], num);
    return (file_loadraw(argv[2], typestr, 0, NULL, 1) ? CMD_OK : CMD_ERROR);
}
Exemplo n.º 3
0
static int
multiboot_obj_loadfile(char *filename, u_int64_t dest,
    struct preloaded_file **result)
{
	struct preloaded_file	*mfp, *kfp, *rfp;
	int			 error, mod_num;

	/* See if there's a aout multiboot kernel loaded */
	mfp = file_findfile(NULL, "aout multiboot kernel");
	if (mfp != NULL) {
		/* we have normal kernel loaded, add module */
		rfp = file_loadraw(filename, "module", 0, NULL, 0);
		if (rfp == NULL) {
			printf(
			"Unable to load %s as a multiboot payload module\n",
			filename);
			return (EINVAL);
		}
		rfp->f_size = roundup(rfp->f_size, PAGE_SIZE);
		*result = rfp;
		return (0);
	}

	/* See if there's a multiboot kernel loaded */
	mfp = file_findfile(NULL, "elf multiboot kernel");
	if (mfp == NULL) {
		return (EFTYPE);	/* this allows to check other methods */
	}

	/*
	 * We have a multiboot kernel loaded, see if there's a
	 * kernel loaded also.
	 */
	kfp = file_findfile(NULL, "elf kernel");
	if (kfp == NULL) {
		/*
		 * No kernel loaded, this must be it. The kernel has to
		 * be loaded as a raw file, it will be processed by
		 * Xen and correctly loaded as an ELF file.
		 */
		rfp = file_loadraw(filename, "elf kernel", 0, NULL, 0);
		if (rfp == NULL) {
			printf(
			"Unable to load %s as a multiboot payload kernel\n",
			filename);
			return (EINVAL);
		}

		/* Load kernel metadata... */
		setenv("kernelname", filename, 1);
		error = elf64_load_modmetadata(rfp, rfp->f_addr + rfp->f_size);
		if (error) {
			printf("Unable to load kernel %s metadata error: %d\n",
			    rfp->f_name, error);
			return (EINVAL);
		}

		/*
		 * Save space at the end of the kernel in order to place
		 * the metadata information. We do an approximation of the
		 * max metadata size, this is not optimal but it's probably
		 * the best we can do at this point. Once all modules are
		 * loaded and the size of the metadata is known this
		 * space will be recovered if not used.
		 */
		mod_num = num_modules(rfp);
		rfp->f_size = roundup(rfp->f_size, PAGE_SIZE);
		rfp->f_size += METADATA_RESV_SIZE(mod_num);
		*result = rfp;
	} else {
		/* The rest should be loaded as regular modules */
		error = elf64_obj_loadfile(filename, dest, result);
		if (error != 0) {
			printf("Unable to load %s as an object file, error: %d",
			    filename, error);
			return (error);
		}
	}

	return (0);
}
Exemplo n.º 4
0
static int
command_load(int argc, char *argv[])
{
    char	*typestr;
    int		dofile, dokld, ch, error;
    
    dokld = dofile = 0;
    optind = 1;
    optreset = 1;
    typestr = NULL;
    if (argc == 1) {
	command_errmsg = "no filename specified";
	return (CMD_CRIT);
    }
    while ((ch = getopt(argc, argv, "kt:")) != -1) {
	switch(ch) {
	case 'k':
	    dokld = 1;
	    break;
	case 't':
	    typestr = optarg;
	    dofile = 1;
	    break;
	case '?':
	default:
	    /* getopt has already reported an error */
	    return (CMD_OK);
	}
    }
    argv += (optind - 1);
    argc -= (optind - 1);

    printf("Loading %s...\n", argv[1]);
    /*
     * Request to load a raw file?
     */
    if (dofile) {
	if ((typestr == NULL) || (*typestr == 0)) {
	    command_errmsg = "invalid load type";
	    return (CMD_CRIT);
	}

	if (file_findfile(argv[1], typestr) != NULL) {
		snprintf(command_errbuf, sizeof (command_errbuf),
		    "warning: file '%s' already loaded", argv[1]);
		return (CMD_WARN);
	}

	if (file_loadraw(argv[1], typestr, argc - 2, argv + 2, 1) != NULL)
		return (CMD_OK);

	/* Failing to load mfs_root is never going to end well! */
	if (strcmp("mfs_root", typestr) == 0)
		return (CMD_FATAL);

	return (CMD_ERROR);
    }
    /*
     * Do we have explicit KLD load ?
     */
    if (dokld || file_havepath(argv[1])) {
	error = mod_loadkld(argv[1], argc - 2, argv + 2);
	if (error == EEXIST) {
	    snprintf(command_errbuf, sizeof (command_errbuf),
		"warning: KLD '%s' already loaded", argv[1]);
	    return (CMD_WARN);
	}
	
	return (error == 0 ? CMD_OK : CMD_CRIT);
    }
    /*
     * Looks like a request for a module.
     */
    error = mod_load(argv[1], NULL, argc - 2, argv + 2);
    if (error == EEXIST) {
	snprintf(command_errbuf, sizeof (command_errbuf),
	    "warning: module '%s' already loaded", argv[1]);
	return (CMD_WARN);
    }

    return (error == 0 ? CMD_OK : CMD_CRIT);
}