提交 25e7ea17 编写于 作者: qiuyiuestc's avatar qiuyiuestc

module developing, application can be run successfully

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@747 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 0c5f6cd9
CLEAN_FILES= *.bin *.map *.axf rtconfig.pyc .sconsign.dblite
clean:
find . \( -name "*.o" -o -name "*.bak" \) -type f -print | xargs rm -f
rm -fr ./build
rm -fr $(CLEAN_FILES)
...@@ -18,16 +18,19 @@ ...@@ -18,16 +18,19 @@
#if defined(RT_USING_FINSH) && defined(RT_USING_MODULE) #if defined(RT_USING_FINSH) && defined(RT_USING_MODULE)
#include <finsh.h> #include <finsh.h>
static char buffer[4096];
void run_module(const char* filename) void run_module(const char* filename)
{ {
int fd, length; int fd, length;
char *module_name; char *module_name;
struct rt_module* module;
struct dfs_stat s;
char *buffer;
rt_memset(buffer, 0, 4096); stat(filename, &s);
buffer = (char *)rt_malloc(s.st_size);
fd = open(filename, O_RDONLY, 0); fd = open(filename, O_RDONLY, 0);
length = read(fd, buffer, 4096); length = read(fd, buffer, s.st_size);
if (length <= 0) if (length <= 0)
{ {
rt_kprintf("check: read file failed\n"); rt_kprintf("check: read file failed\n");
...@@ -36,7 +39,12 @@ void run_module(const char* filename) ...@@ -36,7 +39,12 @@ void run_module(const char* filename)
} }
rt_kprintf("read %d bytes from file\n", length); rt_kprintf("read %d bytes from file\n", length);
module_name = strrchr(filename, '/'); module_name = strrchr(filename, '/');
rt_module_load(buffer, ++module_name); module = rt_module_load((void *)buffer, ++module_name);
if(module != RT_NULL)
{
rt_module_run(module);
}
close(fd); close(fd);
} }
......
...@@ -11,7 +11,7 @@ group['CCFLAGS'] = '' ...@@ -11,7 +11,7 @@ group['CCFLAGS'] = ''
group['CPPPATH'] = [RTT_ROOT + '/components/module/interface'] group['CPPPATH'] = [RTT_ROOT + '/components/module/interface']
group['CPPDEFINES'] = '' group['CPPDEFINES'] = ''
target = 'hello.mo' target = 'basicapp.mo'
# add group to project list # add group to project list
projects.append(group) projects.append(group)
......
#include <rtthread.h> #include <rtthread.h>
#include <interface_help.h> #include <interface_help.h>
extern int rt_application_entry(); extern int rt_application_entry(void);
rt_shell_t ishell = RT_NULL; rt_shell_t ishell = RT_NULL;
int rt_module_entry(const void* shell, void** object_info) int rt_module_entry(const void* shell, void** object_info)
{ {
/* init shell */ /* init shell */
ishell = (rt_shell_t)shell; ishell = (rt_shell_t)shell;
struct rt_module_info *info = (struct rt_module_info*)rt_malloc(sizeof(struct rt_module_info));
rt_kprintf("module entry\n");
struct rt_module_info *info = (struct rt_module_info*)
rt_malloc(sizeof(struct rt_module_info));
info->module_refs = 0; info->module_refs = 0;
info->module_type = RT_Module_Class_APP; info->module_type = RT_Module_Class_APP;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "module.h" #include "module.h"
#include "kservice.h" #include "kservice.h"
#define RT_MODULE_DEBUG /* #define RT_MODULE_DEBUG */
#ifdef RT_USING_MODULE #ifdef RT_USING_MODULE
#define elf_module ((Elf32_Ehdr *)module_ptr) #define elf_module ((Elf32_Ehdr *)module_ptr)
...@@ -262,7 +262,7 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name) ...@@ -262,7 +262,7 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name)
if (IS_PROG(shdr[index]) && IS_AW(shdr[index])) if (IS_PROG(shdr[index]) && IS_AW(shdr[index]))
{ {
data_addr = (rt_uint32_t)ptr; data_addr = (rt_uint32_t)ptr;
rt_kprintf("data section address 0x%x\n", data_addr); /* rt_kprintf("data section address 0x%x\n", data_addr); */
rt_memcpy(ptr, (rt_uint8_t*)elf_module + shdr[index].sh_offset, 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; ptr += shdr[index].sh_size;
} }
...@@ -271,7 +271,7 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name) ...@@ -271,7 +271,7 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name)
if (IS_NOPROG(shdr[index]) && IS_AW(shdr[index])) if (IS_NOPROG(shdr[index]) && IS_AW(shdr[index]))
{ {
bss_addr = (rt_uint32_t)ptr; bss_addr = (rt_uint32_t)ptr;
rt_kprintf("bss section address 0x%x\n", bss_addr); /* rt_kprintf("bss section address 0x%x\n", bss_addr); */
rt_memset(ptr, 0, shdr[index].sh_size); rt_memset(ptr, 0, shdr[index].sh_size);
} }
} }
...@@ -309,7 +309,6 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name) ...@@ -309,7 +309,6 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name)
if((ELF_ST_TYPE(sym->st_info) == STT_SECTION) if((ELF_ST_TYPE(sym->st_info) == STT_SECTION)
|| (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)) || (ELF_ST_TYPE(sym->st_info) == STT_OBJECT))
{ {
rt_kprintf("section name %s\n", shstrab + shdr[sym->st_shndx].sh_name);
if (rt_strncmp(shstrab + shdr[sym->st_shndx].sh_name, ELF_RODATA, 8) == 0) if (rt_strncmp(shstrab + shdr[sym->st_shndx].sh_name, ELF_RODATA, 8) == 0)
{ {
/* relocate rodata section */ /* relocate rodata section */
...@@ -387,7 +386,7 @@ void rt_module_run(struct rt_module* module) ...@@ -387,7 +386,7 @@ void rt_module_run(struct rt_module* module)
{ {
/* application */ /* application */
module->module_thread = rt_thread_create(module->parent.name, module->module_thread = rt_thread_create(module->parent.name,
module->module_entry, RT_NULL, module->module_info->exec_entry, RT_NULL,
512, 90, 10); 512, 90, 10);
module->module_thread->module_parent = module; module->module_thread->module_parent = module;
rt_thread_startup(module->module_thread); rt_thread_startup(module->module_thread);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册