Add mem_load_raw() for loading data from another location in memory.

This will be used by some upcoming changes to loader(8) FDT
handling to allow it to use an FDT provided by an earlier
boot stage the same as an FDT loaded from disk.
This commit is contained in:
Tim Kientzle 2013-02-18 23:13:13 +00:00
parent 5a9ecb5bb2
commit 3e256ed764
2 changed files with 39 additions and 0 deletions

View File

@ -237,6 +237,8 @@ void file_discard(struct preloaded_file *fp);
void file_addmetadata(struct preloaded_file *fp, int type, size_t size, void *p);
int file_addmodule(struct preloaded_file *fp, char *modname, int version,
struct kernel_module **newmp);
/* Load from a buffer in memory. */
struct preloaded_file *mem_load_raw(char *type, char *name, const void *p, size_t len);
/* MI module loaders */
#ifdef __elfN

View File

@ -351,6 +351,7 @@ file_load_dependencies(struct preloaded_file *base_file)
}
return (error);
}
/*
* We've been asked to load (name) as (type), so just suck it in,
* no arguments or anything.
@ -420,6 +421,42 @@ file_loadraw(char *type, char *name)
return(CMD_OK);
}
/*
* Load a chunk of data as if it had been read from a file.
*/
struct preloaded_file *
mem_load_raw(char *type, char *name, const void *p, size_t len)
{
struct preloaded_file *fp;
/* We can't load first */
if ((file_findfile(NULL, NULL)) == NULL) {
command_errmsg = "can't load file before kernel";
return(NULL);
}
if (archsw.arch_loadaddr != NULL)
loadaddr = archsw.arch_loadaddr(LOAD_RAW, name, loadaddr);
archsw.arch_copyin(p, loadaddr, len);
/* Looks OK so far; create & populate control structure */
fp = file_alloc();
fp->f_name = strdup(name);
fp->f_type = strdup(type);
fp->f_args = NULL;
fp->f_metadata = NULL;
fp->f_loader = -1;
fp->f_addr = loadaddr;
fp->f_size = len;
/* recognise space consumption */
loadaddr += len;
/* Add to the list of loaded files */
file_insert_tail(fp);
return fp;
}
/*
* Load the module (name), pass it (argc),(argv), add container file
* to the list of loaded files.