mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-02 14:23:19 +08:00
module developing
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@663 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <dfs_posix.h>
|
||||
#include "string.h"
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
@@ -22,18 +23,21 @@ static char buffer[4096];
|
||||
void run_module(const char* filename)
|
||||
{
|
||||
int fd, length;
|
||||
struct dfs_stat s;
|
||||
|
||||
char *module_name;
|
||||
|
||||
rt_memset(buffer, 0, 4096);
|
||||
fd = open(filename, O_RDONLY, 0);
|
||||
length = read(fd, buffer, 4096);
|
||||
if (length == 0)
|
||||
if (length <= 0)
|
||||
{
|
||||
rt_kprintf("check: read file failed\n");
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
rt_module_load(buffer, filename);
|
||||
rt_kprintf("read %d bytes from file\n", length);
|
||||
module_name = strrchr(filename, '/');
|
||||
rt_module_load(buffer, ++module_name);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
FINSH_FUNCTION_EXPORT(run_module, run module from file);
|
||||
|
||||
+118
-51
File diff suppressed because it is too large
Load Diff
@@ -79,6 +79,11 @@ static void rt_thread_idle_entry(void* parameter)
|
||||
/* release thread's stack */
|
||||
rt_free(thread->stack_addr);
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
/* release thread point in module */
|
||||
if(thread->module_parent != RT_NULL)
|
||||
thread->module_parent->module_thread = RT_NULL;
|
||||
#endif
|
||||
/* delete thread object */
|
||||
rt_object_delete((rt_object_t)thread);
|
||||
}
|
||||
|
||||
+8
-2
@@ -255,9 +255,15 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name)
|
||||
if (IS_PROG(shdr[index]) && IS_AW(shdr[index]))
|
||||
{
|
||||
module->module_data = (rt_uint32_t)ptr;
|
||||
rt_memset(ptr, 0, shdr[index].sh_size);
|
||||
rt_memcpy(ptr, (rt_uint8_t*)elf_module + shdr[index].sh_offset, shdr[index].sh_size);
|
||||
ptr += shdr[index].sh_size;
|
||||
}
|
||||
|
||||
/* load bss section */
|
||||
if (IS_NOPROG(shdr[index]) && IS_AW(shdr[index]))
|
||||
{
|
||||
rt_memset(ptr, 0, shdr[index].sh_size);
|
||||
}
|
||||
}
|
||||
|
||||
/* set module entry */
|
||||
@@ -316,7 +322,7 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name)
|
||||
{
|
||||
/* relocate object in data section */
|
||||
rt_module_arm_relocate(module, rel,
|
||||
(Elf32_Addr)(ptr + sym->st_value),
|
||||
(Elf32_Addr)(module->module_data + sym->st_value),
|
||||
module_addr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,8 +180,14 @@ void rt_object_init(struct rt_object* object, enum rt_object_class_type type, co
|
||||
register rt_base_t temp;
|
||||
struct rt_object_information* information;
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
/* get module object information */
|
||||
information = (rt_current_module != RT_NULL) ?
|
||||
&rt_current_module->module_object[type] : &rt_object_container[type];
|
||||
#else
|
||||
/* get object information */
|
||||
information = &rt_object_container[type];
|
||||
#endif
|
||||
|
||||
/* init object's parameters */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user