Skip to content
Snippets Groups Projects
Commit 89451005 authored by Armin Luntzer's avatar Armin Luntzer
Browse files

modules image: add new function module_read_embedded()

parent eb6d6e2f
Branches
No related tags found
No related merge requests found
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
void module_image_load_embedded(void); void module_image_load_embedded(void);
void *module_lookup_embedded(char *mod_name); void *module_lookup_embedded(char *mod_name);
void *module_lookup_symbol_embedded(char *sym_name); void *module_lookup_symbol_embedded(char *sym_name);
void *module_read_embedded(char *mod_name);
static void kernel_init(void) static void kernel_init(void)
{ {
...@@ -40,7 +40,6 @@ int main(void) ...@@ -40,7 +40,6 @@ int main(void)
module_image_load_embedded(); module_image_load_embedded();
/* look up a kernel symbol */ /* look up a kernel symbol */
printk("%s at %p\n", "printk", lookup_symbol("printk")); printk("%s at %p\n", "printk", lookup_symbol("printk"));
...@@ -48,7 +47,6 @@ int main(void) ...@@ -48,7 +47,6 @@ int main(void)
printk("%s at %p\n", "testmodule.ko", printk("%s at %p\n", "testmodule.ko",
module_lookup_embedded("testmodule.ko")); module_lookup_embedded("testmodule.ko"));
/* to load an arbitrary image, you may upload it via grmon, e.g. /* to load an arbitrary image, you may upload it via grmon, e.g.
* load -binary kernel/test.ko 0xA0000000 * load -binary kernel/test.ko 0xA0000000
* then load it: * then load it:
...@@ -56,7 +54,13 @@ int main(void) ...@@ -56,7 +54,13 @@ int main(void)
*/ */
/* lookup the module containing <symbol> */ /* lookup the module containing <symbol> */
addr = module_lookup_symbol_embedded("somefunction"); /* addr = module_lookup_symbol_embedded("somefunction"); */
/* XXX the image is not necessary aligned properly, so we can't access
* it directly, until we have a MNA trap */
addr = module_read_embedded("testmodule.ko");
if (addr) if (addr)
module_load(&m, addr); module_load(&m, addr);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <kernel/printk.h> #include <kernel/printk.h>
#include <kernel/ar.h> #include <kernel/ar.h>
#include <kernel/kmem.h>
extern unsigned char _binary_modules_image_start __attribute__((weak)); extern unsigned char _binary_modules_image_start __attribute__((weak));
extern unsigned char _binary_modules_image_end __attribute__((weak)); extern unsigned char _binary_modules_image_end __attribute__((weak));
...@@ -31,3 +32,23 @@ void *module_lookup_embedded(char *mod_name) ...@@ -31,3 +32,23 @@ void *module_lookup_embedded(char *mod_name)
{ {
return ar_find_file(&mod_ar, mod_name); return ar_find_file(&mod_ar, mod_name);
} }
void *module_read_embedded(char *mod_name)
{
unsigned int fsize;
void *ptr;
fsize = ar_read_file(&mod_ar, mod_name, NULL);
ptr = kmalloc(fsize);
if (!ptr)
return NULL;
if (!ar_read_file(&mod_ar, mod_name, ptr)) {
kfree(ptr);
return NULL;
}
return ptr;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment