diff --git a/bsp/frdm-k64f/SConstruct b/bsp/frdm-k64f/SConstruct index d4132b593ca8791cb35cab789487ccf54f0d64be..eb4f3d8eacfbb9451728d85ddabedea5275fc4db 100644 --- a/bsp/frdm-k64f/SConstruct +++ b/bsp/frdm-k64f/SConstruct @@ -30,8 +30,5 @@ Export('rtconfig') # prepare building environment objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False) -# build program -env.Program(TARGET, objs) - -# end building -EndBuilding(TARGET) +# do building +DoBuilding(TARGET, objs) diff --git a/bsp/stm32f40x/Libraries/SConscript b/bsp/stm32f40x/Libraries/SConscript index d23856456a2a77d6cd017b77a0ae54f6aae76924..c83c06b4399cb41932c72763fac7fd7e2d4f2880 100644 --- a/bsp/stm32f40x/Libraries/SConscript +++ b/bsp/stm32f40x/Libraries/SConscript @@ -18,8 +18,8 @@ if rtconfig.CROSS_TOOL == 'gcc': src = src + ['CMSIS/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f4xx.s'] elif rtconfig.CROSS_TOOL == 'keil': src = src + ['CMSIS/ST/STM32F4xx/Source/Templates/arm/startup_stm32f4xx.s'] -# elif rtconfig.CROSS_TOOL == 'iar': - # src = src + ['CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/iar/' + startup_scripts[rtconfig.STM32_TYPE]] +elif rtconfig.CROSS_TOOL == 'iar': + src = src + ['CMSIS/ST/STM32F4xx/Source/Templates/iar/startup_stm32f4xx.s'] path = [cwd + '/STM32F4xx_StdPeriph_Driver/inc', cwd + '/CMSIS/ST/STM32F4xx/Include', diff --git a/bsp/stm32f40x/readme.md b/bsp/stm32f40x/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..e1d0e568207cfdc86333dcd893da1b84a0379b76 --- /dev/null +++ b/bsp/stm32f40x/readme.md @@ -0,0 +1,25 @@ +board info: +STM32F4 discovery +http://www.st.com/internet/evalboard/product/252419.jsp + +note: +in drivers/stm32f4xx_conf.h + /* Redefine the HSE value; it's equal to 8 MHz on the STM32F4-DISCOVERY Kit */ + #define HSE_VALUE ((uint32_t)8000000) + + + + **================= IAR WARNING =================** + + after use `scons --target=iar -s` cmd to product IAR project, you have to add iar link file by hand + + IAR steps: + 1. Project-->Options-->Linker + 2. Config-->Linker Configuration file + 3. select `Override Default`, then select `bsp/stm32f40x/stm32f40x_flash.icf` + 4. rebuild project + + + **TODO** + auto add *.icf by scons script + diff --git a/bsp/stm32f40x/readme.txt b/bsp/stm32f40x/readme.txt deleted file mode 100644 index 7bebe251c66a8eddbf122610225fdd454a622bce..0000000000000000000000000000000000000000 --- a/bsp/stm32f40x/readme.txt +++ /dev/null @@ -1,9 +0,0 @@ -board info: -STM32F4 discovery -http://www.st.com/internet/evalboard/product/252419.jsp - -note: -in drivers/stm32f4xx_conf.h - /* Redefine the HSE value; it's equal to 8 MHz on the STM32F4-DISCOVERY Kit */ - #define HSE_VALUE ((uint32_t)8000000) - diff --git a/bsp/stm32f40x/stm32f40x_flash.icf b/bsp/stm32f40x/stm32f40x_flash.icf new file mode 100644 index 0000000000000000000000000000000000000000..8888d0e081c1c159f538f4ac544f089bf0690742 --- /dev/null +++ b/bsp/stm32f40x/stm32f40x_flash.icf @@ -0,0 +1,33 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x08000000; +/*-Memory Regions-*/ +define symbol __ICFEDIT_region_ROM_start__ = 0x08000000; +define symbol __ICFEDIT_region_ROM_end__ = 0x0807FFFF; +define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; +define symbol __ICFEDIT_region_RAM_end__ = 0x2001FFFF; /*STM32 F446RE*/ +/*-Sizes-*/ +define symbol __ICFEDIT_size_cstack__ = 0x200; +define symbol __ICFEDIT_size_heap__ = 0x000; +/**** End of ICF editor section. ###ICF###*/ + + +define memory mem with size = 4G; +define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; +define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; + +define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; +define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +keep { section FSymTab }; +keep { section VSymTab }; +keep { section .rti_fn* }; +place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; + +place in ROM_region { readonly }; +place in RAM_region { readwrite, block CSTACK, last block HEAP}; diff --git a/bsp/stm32f7-disco/drivers/board.c b/bsp/stm32f7-disco/drivers/board.c index 0553920a4706d3d168e64622cc995c0613f5e01e..02f0acf2e632fa2528171262377f77fcf6a46dc0 100644 --- a/bsp/stm32f7-disco/drivers/board.c +++ b/bsp/stm32f7-disco/drivers/board.c @@ -25,7 +25,7 @@ #include #include "board.h" #include "sram.h" - +#include "drv_mpu.h" /** * @addtogroup STM32 @@ -165,7 +165,7 @@ void HAL_ResumeTick(void) void rt_hw_board_init() { /* Configure the MPU attributes as Write Through */ - //mpu_init(); + mpu_init(); /* Enable the CPU Cache */ CPU_CACHE_Enable(); diff --git a/bsp/stm32f7-disco/drivers/drv_mpu.c b/bsp/stm32f7-disco/drivers/drv_mpu.c index 630e48e2d2f62a76ff0432e0e0ba65ba5751e181..ecf556203b38aecbdf20adf11c7e30c4ca832b84 100644 --- a/bsp/stm32f7-disco/drivers/drv_mpu.c +++ b/bsp/stm32f7-disco/drivers/drv_mpu.c @@ -81,4 +81,4 @@ int mpu_init(void) HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT); return 0; } -INIT_BOARD_EXPORT(mpu_init); +//INIT_BOARD_EXPORT(mpu_init); diff --git a/components/dfs/filesystems/lwip/lwip_netdb.c b/components/dfs/filesystems/lwip/lwip_netdb.c index 68714742514cca0e619dd65ef12ab976cb7c4376..1e14dfb093f112f285db0a8786a416216c235f46 100644 --- a/components/dfs/filesystems/lwip/lwip_netdb.c +++ b/components/dfs/filesystems/lwip/lwip_netdb.c @@ -29,6 +29,7 @@ struct hostent *gethostbyname(const char *name) { return lwip_gethostbyname(name); } +RTM_EXPORT(gethostbyname); int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) @@ -40,6 +41,7 @@ void freeaddrinfo(struct addrinfo *ai) { lwip_freeaddrinfo(ai); } +RTM_EXPORT(freeaddrinfo); int getaddrinfo(const char *nodename, const char *servname, @@ -48,3 +50,4 @@ int getaddrinfo(const char *nodename, { return lwip_getaddrinfo(nodename, servname, hints, res); } +RTM_EXPORT(getaddrinfo); diff --git a/components/dfs/filesystems/lwip/lwip_select.c b/components/dfs/filesystems/lwip/lwip_select.c index 3477b6f1d6eb594b82652c2146a7d527c1b2061f..31d9190cfceb265a8d723c7017ed6f95fc15679d 100644 --- a/components/dfs/filesystems/lwip/lwip_select.c +++ b/components/dfs/filesystems/lwip/lwip_select.c @@ -118,5 +118,6 @@ select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, return result; } +RTM_EXPORT(select); #endif diff --git a/components/dfs/filesystems/lwip/lwip_sockets.c b/components/dfs/filesystems/lwip/lwip_sockets.c index 346ef7b266378b84da6916855cf048a822f79fa8..6b68378f7d82ac992102b284d509b471ea3ecc9e 100644 --- a/components/dfs/filesystems/lwip/lwip_sockets.c +++ b/components/dfs/filesystems/lwip/lwip_sockets.c @@ -32,154 +32,167 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen) { - int new_client = -1; + int new_client = -1; int sock = dfs_lwip_getsocket(s); new_client = lwip_accept(sock, addr, addrlen); - if (new_client != -1) - { - /* this is a new socket, create it in file system fd */ - int fd; - struct dfs_fd *d; - - /* allocate a fd */ - fd = fd_new(); - if (fd < 0) - { - rt_set_errno(-DFS_STATUS_ENOMEM); - lwip_close(sock); - - printf("no fd yet!\n"); - return -1; - } - d = fd_get(fd); - - /* this is a socket fd */ - d->type = FT_SOCKET; - d->path = RT_NULL; - - d->fs = dfs_lwip_get_fs(); - - d->flags = DFS_O_RDWR; /* set flags as read and write */ - d->size = 0; - d->pos = 0; - - /* set socket to the data of dfs_fd */ - d->data = (void*) new_client; - - /* release the ref-count of fd */ - fd_put(d); - + if (new_client != -1) + { + /* this is a new socket, create it in file system fd */ + int fd; + struct dfs_fd *d; + + /* allocate a fd */ + fd = fd_new(); + if (fd < 0) + { + rt_set_errno(-DFS_STATUS_ENOMEM); + lwip_close(sock); + + rt_kprintf("no fd yet!\n"); + return -1; + } + d = fd_get(fd); + + /* this is a socket fd */ + d->type = FT_SOCKET; + d->path = RT_NULL; + + d->fs = dfs_lwip_get_fs(); + + d->flags = DFS_O_RDWR; /* set flags as read and write */ + d->size = 0; + d->pos = 0; + + /* set socket to the data of dfs_fd */ + d->data = (void *) new_client; + + /* release the ref-count of fd */ + fd_put(d); + return fd; - } + } - return new_client; + return new_client; } +RTM_EXPORT(accept); int bind(int s, const struct sockaddr *name, socklen_t namelen) { int sock = dfs_lwip_getsocket(s); - + return lwip_bind(sock, name, namelen); } +RTM_EXPORT(bind); int shutdown(int s, int how) { int sock; - struct dfs_fd *d; + struct dfs_fd *d; - d = fd_get(s); - if (d == RT_NULL) - { - rt_set_errno(-DFS_STATUS_EBADF); - - return -1; - } + d = fd_get(s); + if (d == RT_NULL) + { + rt_set_errno(-DFS_STATUS_EBADF); - sock = dfs_lwip_getsocket(s); + return -1; + } + + sock = dfs_lwip_getsocket(s); if (lwip_shutdown(sock, how) == 0) { - /* socket has been closed, delete it from file system fd */ - fd_put(d); - fd_put(d); - - return 0; + /* socket has been closed, delete it from file system fd */ + fd_put(d); + fd_put(d); + + return 0; } - return -1; + return -1; } +RTM_EXPORT(shutdown); -int getpeername (int s, struct sockaddr *name, socklen_t *namelen) +int getpeername(int s, struct sockaddr *name, socklen_t *namelen) { int sock = dfs_lwip_getsocket(s); return lwip_getpeername(sock, name, namelen); } +RTM_EXPORT(getpeername); -int getsockname (int s, struct sockaddr *name, socklen_t *namelen) +int getsockname(int s, struct sockaddr *name, socklen_t *namelen) { int sock = dfs_lwip_getsocket(s); - + return lwip_getsockname(sock, name, namelen); } +RTM_EXPORT(getsockname); -int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen) +int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) { int sock = dfs_lwip_getsocket(s); - + return lwip_getsockopt(sock, level, optname, optval, optlen); } +RTM_EXPORT(getsockopt); -int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen) +int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) { int sock = dfs_lwip_getsocket(s); - + return lwip_setsockopt(sock, level, optname, optval, optlen); } +RTM_EXPORT(setsockopt); int connect(int s, const struct sockaddr *name, socklen_t namelen) { int sock = dfs_lwip_getsocket(s); - + return lwip_connect(sock, name, namelen); } +RTM_EXPORT(connect); int listen(int s, int backlog) { int sock = dfs_lwip_getsocket(s); - + return lwip_listen(sock, backlog); } +RTM_EXPORT(listen); int recv(int s, void *mem, size_t len, int flags) { int sock = dfs_lwip_getsocket(s); - + return lwip_recv(sock, mem, len, flags); } +RTM_EXPORT(recv); int recvfrom(int s, void *mem, size_t len, int flags, - struct sockaddr *from, socklen_t *fromlen) + struct sockaddr *from, socklen_t *fromlen) { int sock = dfs_lwip_getsocket(s); - + return lwip_recvfrom(sock, mem, len, flags, from, fromlen); } +RTM_EXPORT(recvfrom); int send(int s, const void *dataptr, size_t size, int flags) { int sock = dfs_lwip_getsocket(s); - + return lwip_send(sock, dataptr, size, flags); } +RTM_EXPORT(send); int sendto(int s, const void *dataptr, size_t size, int flags, - const struct sockaddr *to, socklen_t tolen) + const struct sockaddr *to, socklen_t tolen) { int sock = dfs_lwip_getsocket(s); - + return lwip_sendto(sock, dataptr, size, flags, to, tolen); } +RTM_EXPORT(sendto); int socket(int domain, int type, int protocol) { @@ -207,13 +220,13 @@ int socket(int domain, int type, int protocol) d->path = RT_NULL; d->fs = dfs_lwip_get_fs(); - + d->flags = DFS_O_RDWR; /* set flags as read and write */ d->size = 0; d->pos = 0; - + /* set socket to the data of dfs_fd */ - d->data = (void*) sock; + d->data = (void *) sock; } /* release the ref-count of fd */ @@ -221,4 +234,4 @@ int socket(int domain, int type, int protocol) return fd; } - +RTM_EXPORT(socket); diff --git a/components/dfs/filesystems/lwip/sys/socket.h b/components/dfs/filesystems/lwip/sys/socket.h index 5317e05e4ce61e53949feb6ebe3a17d9e32354cf..b9608d97edd5fbfaa4e21c932ea3f015574ede97 100644 --- a/components/dfs/filesystems/lwip/sys/socket.h +++ b/components/dfs/filesystems/lwip/sys/socket.h @@ -29,9 +29,11 @@ extern "C" { #endif +#include #include typedef uint16_t sa_family_t; +typedef uint16_t in_port_t; struct sockaddr_storage { diff --git a/components/dfs/filesystems/romfs/dfs_romfs.c b/components/dfs/filesystems/romfs/dfs_romfs.c index 1dd41b41eb3080324716331346e6d9ad90f48e63..6110d6122783bdb06165864ecc5d8f66585c4d07 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/filesystems/romfs/dfs_romfs.c @@ -96,7 +96,8 @@ struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const ch { if (check_dirent(&dirent[index]) != 0) return RT_NULL; - if (rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) + if (rt_strlen(dirent[index].name) == (subpath_end - subpath) && + rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) { dirent_size = dirent[index].size; diff --git a/components/dfs/include/dfs_def.h b/components/dfs/include/dfs_def.h index e509c4a3da648611f6c9274f867084f9cd87e0ed..0f75a5162b3ffc68d96d6b368cdfe42b15e602bf 100644 --- a/components/dfs/include/dfs_def.h +++ b/components/dfs/include/dfs_def.h @@ -255,6 +255,9 @@ #define DFS_S_IWOTH 00002 #define DFS_S_IXOTH 00001 +#ifdef _MSC_VER +#include +#else struct stat { rt_device_t st_dev; @@ -262,6 +265,7 @@ struct stat rt_uint32_t st_size; rt_time_t st_mtime; }; +#endif struct statfs { diff --git a/components/finsh/SConscript b/components/finsh/SConscript index 8d6729e4a7d8780bd3bfdf68c3553c890c919331..639cbebd4a2dc772fde9f86a0a799d7bbeeb5985 100644 --- a/components/finsh/SConscript +++ b/components/finsh/SConscript @@ -22,8 +22,9 @@ finsh_token.c ''') msh_src = Split(''' -msh_cmd.c msh.c +msh_cmd.c +msh_file.c ''') CPPPATH = [cwd] diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index c42b412f23d1ff903cd154e97607123dda35aa4d..29b22c05c25d6980148b0ed3c69b6557ef28ee1e 100644 --- a/components/finsh/cmd.c +++ b/components/finsh/cmd.c @@ -99,17 +99,17 @@ static long _list_thread(struct rt_list_node *list) else if (thread->stat == RT_THREAD_INIT) rt_kprintf(" init "); else if (thread->stat == RT_THREAD_CLOSE) rt_kprintf(" close "); - ptr = (rt_uint8_t*)thread->stack_addr; + ptr = (rt_uint8_t *)thread->stack_addr; while (*ptr == '#')ptr ++; rt_kprintf(" 0x%08x 0x%08x 0x%08x 0x%08x %03d\n", - thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp), - thread->stack_size, - thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr), - thread->remaining_tick, - thread->error); + thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp), + thread->stack_size, + thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr), + thread->remaining_tick, + thread->error); } - + return 0; } @@ -148,7 +148,7 @@ static long _list_sem(struct rt_list_node *list) sem = (struct rt_semaphore *)(rt_list_entry(node, struct rt_object, list)); if (!rt_list_isempty(&sem->parent.suspend_thread)) { - rt_kprintf("%-8.*s %03d %d:", + rt_kprintf("%-8.*s %03d %d:", RT_NAME_MAX, sem->parent.parent.name, sem->value, @@ -448,7 +448,7 @@ static long _list_device(struct rt_list_node *list) { struct rt_device *device; struct rt_list_node *node; - char * const device_type_str[] = + char *const device_type_str[] = { "Character Device", "Block Device", @@ -464,11 +464,11 @@ static long _list_device(struct rt_list_node *list) "SPI Bus", "SPI Device", "SDIO Bus", - "PM Pseudo Device", + "PM Pseudo Device", "Pipe", "Portal Device", - "Timer Device", - "Miscellaneous Device", + "Timer Device", + "Miscellaneous Device", "Unknown" }; @@ -507,13 +507,13 @@ int list_module(void) list = &rt_object_container[RT_Object_Class_Module].object_list; - rt_kprintf("module name ref\n"); - rt_kprintf("------------ --------\n"); + rt_kprintf("module name ref address \n"); + rt_kprintf("------------ -------- ------------\n"); for (node = list->next; node != list; node = node->next) { module = (struct rt_module *)(rt_list_entry(node, struct rt_object, list)); - rt_kprintf("%-16.*s %-04d\n", - RT_NAME_MAX, module->parent.name, module->nref); + rt_kprintf("%-16.*s %-04d 0x%08x\n", + RT_NAME_MAX, module->parent.name, module->nref, module->module_space); } return 0; @@ -525,13 +525,13 @@ int list_mod_detail(const char *name) { int i; struct rt_module *module; - + /* find module */ if ((module = rt_module_find(name)) != RT_NULL) { /* module has entry point */ if (!(module->parent.flag & RT_MODULE_FLAG_WITHOUTENTRY)) - { + { struct rt_thread *thread; struct rt_list_node *tlist; rt_uint8_t *ptr; @@ -548,15 +548,15 @@ int list_mod_detail(const char *name) else if (thread->stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend"); else if (thread->stat == RT_THREAD_INIT) rt_kprintf(" init "); - ptr = (rt_uint8_t*)thread->stack_addr; + ptr = (rt_uint8_t *)thread->stack_addr; while (*ptr == '#')ptr ++; rt_kprintf(" 0x%08x 0x%08x 0x%08x 0x%08x %03d\n", - thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp), - thread->stack_size, - thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr), - thread->remaining_tick, - thread->error); + thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp), + thread->stack_size, + thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr), + thread->remaining_tick, + thread->error); } /* list sub thread in module */ @@ -607,18 +607,18 @@ int list_mod_detail(const char *name) if (!rt_list_isempty(tlist)) _list_timer(tlist); } - if (module->nsym > 0) - { - rt_kprintf("symbol address \n"); - rt_kprintf("-------- ----------\n"); - - /* list module export symbols */ - for (i=0; insym; i++) - { - rt_kprintf("%s 0x%x\n", - module->symtab[i].name, module->symtab[i].addr); - } - } + if (module->nsym > 0) + { + rt_kprintf("symbol address \n"); + rt_kprintf("-------- ----------\n"); + + /* list module export symbols */ + for (i = 0; i < module->nsym; i++) + { + rt_kprintf("%s 0x%x\n", + module->symtab[i].name, module->symtab[i].addr); + } + } } return 0; @@ -632,16 +632,16 @@ long list(void) struct finsh_syscall_item *syscall_item; struct finsh_sysvar_item *sysvar_item; #endif - + rt_kprintf("--Function List:\n"); { struct finsh_syscall *index; for (index = _syscall_table_begin; - index < _syscall_table_end; - FINSH_NEXT_SYSCALL(index)) + index < _syscall_table_end; + FINSH_NEXT_SYSCALL(index)) { - /* skip the internal command */ - if (strncmp((char*)index->name, "__", 2) == 0) continue; + /* skip the internal command */ + if (strncmp((char *)index->name, "__", 2) == 0) continue; #ifdef FINSH_USING_DESCRIPTION rt_kprintf("%-16s -- %s\n", index->name, index->desc); @@ -664,8 +664,8 @@ long list(void) { struct finsh_sysvar *index; for (index = _sysvar_table_begin; - index < _sysvar_table_end; - FINSH_NEXT_SYSVAR(index)) + index < _sysvar_table_end; + FINSH_NEXT_SYSVAR(index)) { #ifdef FINSH_USING_DESCRIPTION rt_kprintf("%-16s -- %s\n", index->name, index->desc); @@ -682,7 +682,7 @@ long list(void) sysvar_item = sysvar_item->next; } #endif - + return 0; } FINSH_FUNCTION_EXPORT(list, list all symbol in system) @@ -732,12 +732,12 @@ void list_prefix(char *prefix) { struct finsh_syscall *index; for (index = _syscall_table_begin; - index < _syscall_table_end; - FINSH_NEXT_SYSCALL(index)) + index < _syscall_table_end; + FINSH_NEXT_SYSCALL(index)) { - /* skip internal command */ - if (str_is_prefix("__", index->name) == 0) continue; - + /* skip internal command */ + if (str_is_prefix("__", index->name) == 0) continue; + if (str_is_prefix(prefix, index->name) == 0) { if (func_cnt == 0) @@ -807,10 +807,10 @@ void list_prefix(char *prefix) /* checks in system variable */ { - struct finsh_sysvar* index; + struct finsh_sysvar *index; for (index = _sysvar_table_begin; - index < _sysvar_table_end; - FINSH_NEXT_SYSVAR(index)) + index < _sysvar_table_end; + FINSH_NEXT_SYSVAR(index)) { if (str_is_prefix(prefix, index->name) == 0) { diff --git a/components/finsh/msh.c b/components/finsh/msh.c index 6d747b40db1f61a9d6b30e6e0b000796994671ca..bd4b12d9d5fa02eec1bfc71d45912c314e6cce1e 100644 --- a/components/finsh/msh.c +++ b/components/finsh/msh.c @@ -37,7 +37,7 @@ #endif #define RT_FINSH_ARG_MAX 10 -typedef int (*cmd_function_t)(int argc, char** argv); +typedef int (*cmd_function_t)(int argc, char **argv); #ifdef FINSH_USING_MSH #ifdef FINSH_USING_MSH_ONLY @@ -56,7 +56,7 @@ rt_bool_t msh_is_used(void) return __msh_state; } -static int msh_exit(int argc, char** argv) +static int msh_exit(int argc, char **argv) { /* return to finsh shell mode */ __msh_state = RT_FALSE; @@ -74,15 +74,15 @@ static int msh_enter(void) FINSH_FUNCTION_EXPORT_ALIAS(msh_enter, msh, use module shell); #endif -int msh_help(int argc, char** argv) +int msh_help(int argc, char **argv) { rt_kprintf("RT-Thread shell commands:\n"); { struct finsh_syscall *index; for (index = _syscall_table_begin; - index < _syscall_table_end; - FINSH_NEXT_SYSCALL(index)) + index < _syscall_table_end; + FINSH_NEXT_SYSCALL(index)) { if (strncmp(index->name, "__cmd_", 6) != 0) continue; #if defined(FINSH_USING_DESCRIPTION) && defined(FINSH_USING_SYMTAB) @@ -98,7 +98,7 @@ int msh_help(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(msh_help, __cmd_help, RT-Thread shell help.); -static int msh_split(char* cmd, rt_size_t length, char* argv[RT_FINSH_ARG_MAX]) +static int msh_split(char *cmd, rt_size_t length, char *argv[RT_FINSH_ARG_MAX]) { char *ptr; rt_size_t position; @@ -161,13 +161,13 @@ static cmd_function_t msh_get_cmd(char *cmd, int size) cmd_function_t cmd_func = RT_NULL; for (index = _syscall_table_begin; - index < _syscall_table_end; - FINSH_NEXT_SYSCALL(index)) + index < _syscall_table_end; + FINSH_NEXT_SYSCALL(index)) { if (strncmp(index->name, "__cmd_", 6) != 0) continue; - + if (strncmp(&index->name[6], cmd, size) == 0 && - index->name[6 + size] == '\0') + index->name[6 + size] == '\0') { cmd_func = (cmd_function_t)index->func; break; @@ -180,7 +180,7 @@ static cmd_function_t msh_get_cmd(char *cmd, int size) #if defined(RT_USING_MODULE) && defined(RT_USING_DFS) /* Return 0 on module executed. Other value indicate error. */ -int msh_exec_module(const char* cmd_line, int size) +int msh_exec_module(const char *cmd_line, int size) { int ret; int fd = -1; @@ -197,7 +197,7 @@ int msh_exec_module(const char* cmd_line, int size) length = cmd_length + 32; /* allocate program name memory */ - pg_name = (char*) rt_malloc(length); + pg_name = (char *) rt_malloc(length); if (pg_name == RT_NULL) return -RT_ENOMEM; @@ -251,12 +251,21 @@ int msh_exec_module(const char* cmd_line, int size) int system(const char *command) { - return msh_exec_module(command, rt_strlen(command)); + int ret = -RT_ENOMEM; + char *cmd = rt_strdup(command); + + if (cmd) + { + ret = msh_exec(cmd, rt_strlen(cmd)); + rt_free(cmd); + } + + return ret; } RTM_EXPORT(system); #endif -static int _msh_exec_cmd(char* cmd, rt_size_t length, int *retp) +static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp) { int argc; int cmd0_size = 0; @@ -287,12 +296,12 @@ static int _msh_exec_cmd(char* cmd, rt_size_t length, int *retp) return 0; } -int msh_exec(char* cmd, rt_size_t length) +int msh_exec(char *cmd, rt_size_t length) { int cmd_ret; - /* strim the beginning of command */ - while(*cmd == ' ' || *cmd == '\t') + /* strim the beginning of command */ + while (*cmd == ' ' || *cmd == '\t') { cmd++; length--; @@ -318,7 +327,12 @@ int msh_exec(char* cmd, rt_size_t length) #endif #if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR) - /* change to this directory */ + if (msh_exec_script(cmd, length) == 0) + { + return 0; + } + + /* change to this directory */ if (chdir(cmd) == 0) { return 0; @@ -329,7 +343,7 @@ int msh_exec(char* cmd, rt_size_t length) { char *tcmd; tcmd = cmd; - while(*tcmd != ' ' && *tcmd != '\0') + while (*tcmd != ' ' && *tcmd != '\0') { tcmd++; } @@ -355,14 +369,14 @@ static int str_common(const char *str1, const char *str2) #ifdef RT_USING_DFS void msh_auto_complete_path(char *path) { - DIR* dir = RT_NULL; + DIR *dir = RT_NULL; struct dirent *dirent = RT_NULL; char *full_path, *ptr, *index; if (!path) return; - full_path = (char*)rt_malloc(256); + full_path = (char *)rt_malloc(256); if (full_path == RT_NULL) return; /* out of memory */ if (*path != '/') @@ -434,9 +448,9 @@ void msh_auto_complete_path(char *path) /* save dirent name */ strcpy(full_path, dirent->d_name); } - + length = str_common(dirent->d_name, full_path); - + if (length < min_length) { min_length = length; @@ -460,7 +474,7 @@ void msh_auto_complete_path(char *path) rt_kprintf("%s\n", dirent->d_name); } } - + length = index - path; memcpy(index, full_path, min_length); path[length + min_length] = '\0'; @@ -481,7 +495,7 @@ void msh_auto_complete(char *prefix) min_length = 0; name_ptr = RT_NULL; - if (*prefix == '\0') + if (*prefix == '\0') { msh_help(0, RT_NULL); return; @@ -522,7 +536,7 @@ void msh_auto_complete(char *prefix) /* skip finsh shell function */ if (strncmp(index->name, "__cmd_", 6) != 0) continue; - cmd_name = (const char*) &index->name[6]; + cmd_name = (const char *) &index->name[6]; if (strncmp(prefix, cmd_name, strlen(prefix)) == 0) { if (min_length == 0) diff --git a/components/finsh/msh.h b/components/finsh/msh.h index 959170da3dda67f7da6e2b4180412892f04487f6..df497329567ef3418d736b150cb70ee50b132232 100644 --- a/components/finsh/msh.h +++ b/components/finsh/msh.h @@ -33,7 +33,10 @@ #include rt_bool_t msh_is_used(void); -int msh_exec(char* cmd, rt_size_t length); +int msh_exec(char *cmd, rt_size_t length); void msh_auto_complete(char *prefix); +int msh_exec_module(const char *cmd_line, int size); +int msh_exec_script(const char *cmd_line, int size); + #endif diff --git a/components/finsh/msh_cmd.c b/components/finsh/msh_cmd.c index fc6b56cdd1baefde10b3642173bbdae20da2df77..a4b865b02835b254e5afc3674ede81a685a6ae07 100644 --- a/components/finsh/msh_cmd.c +++ b/components/finsh/msh_cmd.c @@ -41,7 +41,7 @@ extern char working_directory[]; #endif -int cmd_ls(int argc, char** argv) +int cmd_ls(int argc, char **argv) { extern void ls(const char *pathname); @@ -53,7 +53,7 @@ int cmd_ls(int argc, char** argv) ls("/"); #endif } - else + else { ls(argv[1]); } @@ -62,7 +62,7 @@ int cmd_ls(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_ls, __cmd_ls, List information about the FILEs.); -int cmd_cp(int argc, char** argv) +int cmd_cp(int argc, char **argv) { void copy(const char *src, const char *dst); @@ -80,7 +80,7 @@ int cmd_cp(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_cp, __cmd_cp, Copy SOURCE to DEST.); -int cmd_mv(int argc, char** argv) +int cmd_mv(int argc, char **argv) { if (argc != 3) { @@ -89,66 +89,66 @@ int cmd_mv(int argc, char** argv) } else { - int fd; - char *dest = RT_NULL; + int fd; + char *dest = RT_NULL; rt_kprintf("%s => %s\n", argv[1], argv[2]); - fd = open(argv[2], O_DIRECTORY, 0); - if (fd >= 0) - { - char *src; - - close(fd); - - /* it's a directory */ - dest = (char*)rt_malloc(DFS_PATH_MAX); - if (dest == RT_NULL) - { - rt_kprintf("out of memory\n"); - return -RT_ENOMEM; - } - - src = argv[1] + rt_strlen(argv[1]); - while (src != argv[1]) - { - if (*src == '/') break; - src --; - } - - rt_snprintf(dest, DFS_PATH_MAX - 1, "%s/%s", argv[2], src); - } - else - { - fd = open(argv[2], O_RDONLY, 0); - if (fd >= 0) - { - close(fd); - - unlink(argv[2]); - } - - dest = argv[2]; - } - - rename(argv[1], dest); - if (dest != RT_NULL && dest != argv[2]) rt_free(dest); + fd = open(argv[2], O_DIRECTORY, 0); + if (fd >= 0) + { + char *src; + + close(fd); + + /* it's a directory */ + dest = (char *)rt_malloc(DFS_PATH_MAX); + if (dest == RT_NULL) + { + rt_kprintf("out of memory\n"); + return -RT_ENOMEM; + } + + src = argv[1] + rt_strlen(argv[1]); + while (src != argv[1]) + { + if (*src == '/') break; + src --; + } + + rt_snprintf(dest, DFS_PATH_MAX - 1, "%s/%s", argv[2], src); + } + else + { + fd = open(argv[2], O_RDONLY, 0); + if (fd >= 0) + { + close(fd); + + unlink(argv[2]); + } + + dest = argv[2]; + } + + rename(argv[1], dest); + if (dest != RT_NULL && dest != argv[2]) rt_free(dest); } return 0; } FINSH_FUNCTION_EXPORT_ALIAS(cmd_mv, __cmd_mv, Rename SOURCE to DEST.); -int cmd_cat(int argc, char** argv) +int cmd_cat(int argc, char **argv) { int index; - extern void cat(const char* filename); + extern void cat(const char *filename); if (argc == 1) { rt_kprintf("Usage: cat [FILE]...\n"); rt_kprintf("Concatenate FILE(s)\n"); - return 0; + return 0; } for (index = 1; index < argc; index ++) @@ -160,7 +160,7 @@ int cmd_cat(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_cat, __cmd_cat, Concatenate FILE(s)); -int cmd_rm(int argc, char** argv) +int cmd_rm(int argc, char **argv) { int index; @@ -168,7 +168,7 @@ int cmd_rm(int argc, char** argv) { rt_kprintf("Usage: rm FILE...\n"); rt_kprintf("Remove (unlink) the FILE(s).\n"); - return 0; + return 0; } for (index = 1; index < argc; index ++) @@ -178,10 +178,10 @@ int cmd_rm(int argc, char** argv) return 0; } -FINSH_FUNCTION_EXPORT_ALIAS(cmd_rm, __cmd_rm, Remove (unlink) the FILE(s).); +FINSH_FUNCTION_EXPORT_ALIAS(cmd_rm, __cmd_rm, Remove(unlink) the FILE(s).); #ifdef DFS_USING_WORKDIR -int cmd_cd(int argc, char** argv) +int cmd_cd(int argc, char **argv) { if (argc == 1) { @@ -196,34 +196,34 @@ int cmd_cd(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_cd, __cmd_cd, Change the shell working directory.); -int cmd_pwd(int argc, char** argv) +int cmd_pwd(int argc, char **argv) { - rt_kprintf("%s\n", working_directory); - return 0; + rt_kprintf("%s\n", working_directory); + return 0; } FINSH_FUNCTION_EXPORT_ALIAS(cmd_pwd, __cmd_pwd, Print the name of the current working directory.); #endif -int cmd_mkdir(int argc, char** argv) +int cmd_mkdir(int argc, char **argv) { - if (argc == 1) - { - rt_kprintf("Usage: mkdir [OPTION] DIRECTORY\n"); - rt_kprintf("Create the DIRECTORY, if they do not already exist.\n"); - } - else - { - mkdir(argv[1], 0); - } - - return 0; + if (argc == 1) + { + rt_kprintf("Usage: mkdir [OPTION] DIRECTORY\n"); + rt_kprintf("Create the DIRECTORY, if they do not already exist.\n"); + } + else + { + mkdir(argv[1], 0); + } + + return 0; } FINSH_FUNCTION_EXPORT_ALIAS(cmd_mkdir, __cmd_mkdir, Create the DIRECTORY.); -int cmd_mkfs(int argc, char** argv) +int cmd_mkfs(int argc, char **argv) { int result = 0; - char* type="elm"; /* use the default file system type as 'fatfs' */ + char *type = "elm"; /* use the default file system type as 'fatfs' */ if (argc == 2) { @@ -234,7 +234,7 @@ int cmd_mkfs(int argc, char** argv) if (strcmp(argv[1], "-t") == 0) { type = argv[2]; - result = dfs_mkfs(type, argv[1]); + result = dfs_mkfs(type, argv[3]); } } else @@ -242,7 +242,7 @@ int cmd_mkfs(int argc, char** argv) rt_kprintf("Usage: mkfs [-t type] device\n"); return 0; } - + if (result != RT_EOK) { rt_kprintf("mkfs failed, result=%d\n", result); @@ -255,17 +255,17 @@ FINSH_FUNCTION_EXPORT_ALIAS(cmd_mkfs, __cmd_mkfs, format disk with file system); #endif #ifdef RT_USING_LWIP -int cmd_ifconfig(int argc, char** argv) +int cmd_ifconfig(int argc, char **argv) { extern void list_if(void); - extern void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr); + extern void set_if(char *netif_name, char *ip_addr, char *gw_addr, char *nm_addr); - if(argc == 1) + if (argc == 1) { list_if(); } - else if(argc == 5) + else if (argc == 5) { rt_kprintf("config : %s\n", argv[1]); rt_kprintf("IP addr: %s\n", argv[2]); @@ -283,22 +283,22 @@ int cmd_ifconfig(int argc, char** argv) FINSH_FUNCTION_EXPORT_ALIAS(cmd_ifconfig, __cmd_ifconfig, list the information of network interfaces); #ifdef RT_LWIP_TCP -int cmd_netstat(int argc, char** argv) +int cmd_netstat(int argc, char **argv) { - extern void list_tcps(void); + extern void list_tcps(void); - list_tcps(); - return 0; + list_tcps(); + return 0; } -FINSH_FUNCTION_EXPORT_ALIAS(cmd_netstat, __cmd_netstat, list the information of TCP/IP); +FINSH_FUNCTION_EXPORT_ALIAS(cmd_netstat, __cmd_netstat, list the information of TCP / IP); #endif #endif /* RT_USING_LWIP */ -int cmd_ps(int argc, char** argv) +int cmd_ps(int argc, char **argv) { extern long list_thread(void); extern int list_module(void); - + #ifdef RT_USING_MODULE if ((argc == 2) && (strcmp(argv[1], "-m") == 0)) list_module(); @@ -309,14 +309,14 @@ int cmd_ps(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_ps, __cmd_ps, List threads in the system.); -int cmd_time(int argc, char** argv) +int cmd_time(int argc, char **argv) { return 0; } FINSH_FUNCTION_EXPORT_ALIAS(cmd_time, __cmd_time, Execute command with time.); #ifdef RT_USING_HEAP -int cmd_free(int argc, char** argv) +int cmd_free(int argc, char **argv) { extern void list_mem(void); extern void list_memheap(void); diff --git a/components/finsh/msh_file.c b/components/finsh/msh_file.c new file mode 100644 index 0000000000000000000000000000000000000000..80012e9bb8ab6b55d91d6ef4a8e1c06c7052b7f4 --- /dev/null +++ b/components/finsh/msh_file.c @@ -0,0 +1,159 @@ +/* + * script for RT-Thread module shell + * + * COPYRIGHT (C) 2013-2015, Shanghai Real-Thread Technology Co., Ltd + * + * This file is part of RT-Thread (http://www.rt-thread.org) + * Maintainer: bernard.xiong + * + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-09-25 Bernard the first verion for FinSH + */ + +#include +#include + +#include "msh.h" + +#if defined(FINSH_USING_MSH) && defined(RT_USING_DFS) +#include + +static int msh_readline(int fd, char *line_buf, int size) +{ + char ch; + int index = 0; + + do + { + if (read(fd, &ch, 1) != 1) + { + /* nothing in this file */ + return 0; + } + } + while (ch == '\n' || ch == '\r'); + + /* set the first character */ + line_buf[index ++] = ch; + + while (index < size) + { + if (read(fd, &ch, 1) == 1) + { + if (ch == '\n' || ch == '\r') + { + line_buf[index] = '\0'; + break; + } + + line_buf[index++] = ch; + } + else + { + line_buf[index] = '\0'; + break; + } + } + + return index; +} + +int msh_exec_script(const char *cmd_line, int size) +{ + int ret; + int fd = -1; + char *pg_name; + int length, cmd_length = 0; + + if (size == 0) return -RT_ERROR; + + /* get the length of command0 */ + while ((cmd_line[cmd_length] != ' ' && cmd_line[cmd_length] != '\t') && cmd_length < size) + cmd_length ++; + + /* get name length */ + length = cmd_length + 32; + + /* allocate program name memory */ + pg_name = (char *) rt_malloc(length); + if (pg_name == RT_NULL) return -RT_ENOMEM; + + /* copy command0 */ + memcpy(pg_name, cmd_line, cmd_length); + pg_name[cmd_length] = '\0'; + + if (strstr(pg_name, ".sh") != RT_NULL || strstr(pg_name, ".SH") != RT_NULL) + { + /* try to open program */ + fd = open(pg_name, O_RDONLY, 0); + + /* search in /bin path */ + if (fd < 0) + { + rt_snprintf(pg_name, length - 1, "/bin/%.*s", cmd_length, cmd_line); + fd = open(pg_name, O_RDONLY, 0); + } + } + + rt_free(pg_name); + if (fd >= 0) + { + /* found script */ + char *line_buf; + int length; + + line_buf = (char *) rt_malloc(RT_CONSOLEBUF_SIZE); + + /* read line by line and then exec it */ + do + { + length = msh_readline(fd, line_buf, RT_CONSOLEBUF_SIZE); + if (length > 0) + { + char ch = '\0'; + int index; + + for (index = 0; index < length; index ++) + { + ch = line_buf[index]; + if (ch == ' ' || ch == '\t') continue; + else break; + } + + if (ch != '#') /* not a comment */ + msh_exec(line_buf, length); + } + } + while (length > 0); + + close(fd); + rt_free(line_buf); + + ret = 0; + } + else + { + ret = -1; + } + + return ret; +} + +#endif diff --git a/components/finsh/shell.c b/components/finsh/shell.c index ce80e4dec21fbe09f3c581cee7c0c4f6b41e26a4..8962a7333f7a682acee9003af71e8cd31fae9e31 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -425,7 +425,7 @@ void finsh_thread_entry(void *parameter) if (rt_device_read(shell->device, 0, &next, 1) == 1) { - if (next == '\0') ch = 'r'; /* linux telnet will issue '\0' */ + if (next == '\0') ch = '\r'; /* linux telnet will issue '\0' */ else ch = next; } else ch = '\r'; diff --git a/components/libc/armlibc/libc_syms.c b/components/libc/armlibc/libc_syms.c new file mode 100644 index 0000000000000000000000000000000000000000..847c48544ac38ab0ee0b2c8eb7d085fa5d710c78 --- /dev/null +++ b/components/libc/armlibc/libc_syms.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include + +#include + +/* some export routines for module */ + +RTM_EXPORT(strstr); +RTM_EXPORT(strlen); +RTM_EXPORT(strchr); +RTM_EXPORT(strcpy); +RTM_EXPORT(strncpy); +RTM_EXPORT(strcmp); +RTM_EXPORT(strncmp); +RTM_EXPORT(strcat); +RTM_EXPORT(strtol); + +RTM_EXPORT(memcpy); +RTM_EXPORT(memcmp); +RTM_EXPORT(memmove); +RTM_EXPORT(memset); +RTM_EXPORT(memchr); + +RTM_EXPORT(toupper); +RTM_EXPORT(atoi); + +RTM_EXPORT(localtime); +RTM_EXPORT(time); + +/* import the full stdio for printf */ +#ifdef __MICROLIB +#error "[RT_USING_LIBC] Please use standard libc but not microlib." +#endif + +RTM_EXPORT(puts); +RTM_EXPORT(printf); diff --git a/components/libc/armlibc/mem_std.c b/components/libc/armlibc/mem_std.c index 6faf86555fd3cb756f31935489d36c81670b44ac..56aa525df2587d0199d6cf40696379d4f83ed5ef 100644 --- a/components/libc/armlibc/mem_std.c +++ b/components/libc/armlibc/mem_std.c @@ -22,18 +22,22 @@ void *malloc(int n) { return rt_malloc(n); } +RTM_EXPORT(malloc); void *realloc(void *rmem, rt_size_t newsize) { return rt_realloc(rmem, newsize); } +RTM_EXPORT(realloc); void *calloc(rt_size_t nelem, rt_size_t elsize) { return rt_calloc(nelem, elsize); } +RTM_EXPORT(calloc); void free(void *rmem) { rt_free(rmem); } +RTM_EXPORT(free); diff --git a/components/libc/newlib/libc_sym.c b/components/libc/newlib/libc_sym.c new file mode 100644 index 0000000000000000000000000000000000000000..48e488f5d8031edd571e7ff75893d59072f0ada5 --- /dev/null +++ b/components/libc/newlib/libc_sym.c @@ -0,0 +1,47 @@ +#include +#include + +#include +#include +#include + +RTM_EXPORT(strcpy); +RTM_EXPORT(strncpy); +RTM_EXPORT(strlen); +RTM_EXPORT(strcat); +RTM_EXPORT(strstr); +RTM_EXPORT(strchr); +RTM_EXPORT(strcmp); +RTM_EXPORT(strtol); +RTM_EXPORT(strtoul); +RTM_EXPORT(strncmp); + +RTM_EXPORT(memcpy); +RTM_EXPORT(memcmp); +RTM_EXPORT(memmove); +RTM_EXPORT(memset); +RTM_EXPORT(memchr); + +RTM_EXPORT(putchar); +RTM_EXPORT(puts); +RTM_EXPORT(printf); +RTM_EXPORT(sprintf); +RTM_EXPORT(snprintf); + +RTM_EXPORT(fwrite); + +#include +RTM_EXPORT(localtime); +RTM_EXPORT(time); + +#include +RTM_EXPORT(longjmp); +RTM_EXPORT(setjmp); + +RTM_EXPORT(exit); +RTM_EXPORT(abort); + +RTM_EXPORT(rand); + +#include +RTM_EXPORT(__assert_func); diff --git a/tools/building.py b/tools/building.py index 5ad6d4e9d2c25cb17df7376678f6c639dc31cbfd..07f5e91fc9ac5ab66229be9a28f1c48a12c41d0d 100644 --- a/tools/building.py +++ b/tools/building.py @@ -267,6 +267,12 @@ def PrepareModuleBuilding(env, root_directory, bsp_directory): global Env global Rtt_Root + # patch for win32 spawn + if env['PLATFORM'] == 'win32': + win32_spawn = Win32Spawn() + win32_spawn.env = env + env['SPAWN'] = win32_spawn.spawn + Env = env Rtt_Root = root_directory @@ -491,37 +497,35 @@ def DoBuilding(target, objects): lst.append(item) return lst - objects = one_list(objects) - - # remove source files with local flags setting - for group in Projects: - if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'): - for source in group['src']: - for obj in objects: - if source.abspath == obj.abspath or (len(obj.sources) > 0 and source.abspath == obj.sources[0].abspath): - objects.remove(obj) - - # re-add the source files to the objects - for group in Projects: + # handle local group + def local_group(group, objects): if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'): CCFLAGS = Env.get('CCFLAGS', '') + group.get('LOCAL_CCFLAGS', '') CPPPATH = Env.get('CPPPATH', ['']) + group.get('LOCAL_CPPPATH', ['']) CPPDEFINES = Env.get('CPPDEFINES', ['']) + group.get('LOCAL_CPPDEFINES', ['']) for source in group['src']: - objects += Env.Object(source, CCFLAGS = CCFLAGS, - CPPPATH = CPPPATH, - CPPDEFINES = CPPDEFINES) + objects.append(Env.Object(source, CCFLAGS = CCFLAGS, + CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)) + + return True + + return False + + objects = one_list(objects) program = None # check whether special buildlib option lib_name = GetOption('buildlib') if lib_name: + objects = [] # remove all of objects # build library with special component for Group in Projects: if Group['name'] == lib_name: lib_name = GroupLibName(Group['name'], Env) - objects = Env.Object(Group['src']) + if not local_group(Group, objects): + objects = Env.Object(Group['src']) + program = Env.Library(lib_name, objects) # add library copy action @@ -529,6 +533,18 @@ def DoBuilding(target, objects): break else: + # remove source files with local flags setting + for group in Projects: + if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'): + for source in group['src']: + for obj in objects: + if source.abspath == obj.abspath or (len(obj.sources) > 0 and source.abspath == obj.sources[0].abspath): + objects.remove(obj) + + # re-add the source files to the objects + for group in Projects: + local_group(group, objects) + program = Env.Program(target, objects) EndBuilding(target, program) diff --git a/tools/keil.py b/tools/keil.py index d1aa5562d7c6d3750058a581c932f0be3a5ce565..599658d983c1d940e1ed192640ab3850c33c2078 100644 --- a/tools/keil.py +++ b/tools/keil.py @@ -34,9 +34,12 @@ from utils import xml_indent fs_encoding = sys.getfilesystemencoding() def _get_filetype(fn): - if fn.rfind('.c') != -1 or fn.rfind('.C') != -1 or fn.rfind('.cpp') != -1: + if fn.rfind('.c') != -1 or fn.rfind('.C') != -1: return 1 + if fn.rfind('.cpp') != -1 or fn.rfined('.cxx') != -1: + return 8 + # assemble file type if fn.rfind('.s') != -1 or fn.rfind('.S') != -1: return 2 @@ -88,131 +91,7 @@ def MDK4AddGroupForFN(ProjectFiles, parent, name, filename, project_path): file_path.text = path.decode(fs_encoding) -def MDK4AddGroup(ProjectFiles, parent, name, files, project_path): - # don't add an empty group - if len(files) == 0: - return - - group = SubElement(parent, 'Group') - group_name = SubElement(group, 'GroupName') - group_name.text = name - - for f in files: - fn = f.rfile() - name = fn.name - path = os.path.dirname(fn.abspath) - - basename = os.path.basename(path) - path = _make_path_relative(project_path, path) - path = os.path.join(path, name) - - files = SubElement(group, 'Files') - file = SubElement(files, 'File') - file_name = SubElement(file, 'FileName') - name = os.path.basename(path) - - if name.find('.cpp') != -1: - obj_name = name.replace('.cpp', '.o') - elif name.find('.c') != -1: - obj_name = name.replace('.c', '.o') - elif name.find('.s') != -1: - obj_name = name.replace('.s', '.o') - elif name.find('.S') != -1: - obj_name = name.replace('.s', '.o') - - if ProjectFiles.count(obj_name): - name = basename + '_' + name - ProjectFiles.append(obj_name) - file_name.text = name.decode(fs_encoding) - file_type = SubElement(file, 'FileType') - file_type.text = '%d' % _get_filetype(name) - file_path = SubElement(file, 'FilePath') - - file_path.text = path.decode(fs_encoding) - -def MDK4Project(target, script): - project_path = os.path.dirname(os.path.abspath(target)) - - project_uvopt = os.path.abspath(target).replace('uvproj', 'uvopt') - if os.path.isfile(project_uvopt): - os.unlink(project_uvopt) - - tree = etree.parse('template.uvproj') - root = tree.getroot() - - out = file(target, 'wb') - out.write('\n') - - CPPPATH = [] - CPPDEFINES = [] - LINKFLAGS = '' - CCFLAGS = '' - ProjectFiles = [] - - # add group - groups = tree.find('Targets/Target/Groups') - if groups is None: - groups = SubElement(tree.find('Targets/Target'), 'Groups') - groups.clear() # clean old groups - for group in script: - group_xml = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path) - - # get each include path - if group.has_key('CPPPATH') and group['CPPPATH']: - if CPPPATH: - CPPPATH += group['CPPPATH'] - else: - CPPPATH += group['CPPPATH'] - - # get each group's definitions - if group.has_key('CPPDEFINES') and group['CPPDEFINES']: - if CPPDEFINES: - CPPDEFINES += group['CPPDEFINES'] - else: - CPPDEFINES += group['CPPDEFINES'] - - # get each group's link flags - if group.has_key('LINKFLAGS') and group['LINKFLAGS']: - if LINKFLAGS: - LINKFLAGS += ' ' + group['LINKFLAGS'] - else: - LINKFLAGS += group['LINKFLAGS'] - - if group.has_key('LIBS') and group['LIBS']: - for item in group['LIBS']: - lib_path = '' - for path_item in group['LIBPATH']: - full_path = os.path.join(path_item, item + '.lib') - if os.path.isfile(full_path): # has this library - lib_path = full_path - - if lib_path != '': - MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path) - - # write include path, definitions and link flags - IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath') - IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in CPPPATH]) - - Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define') - Define.text = ', '.join(set(CPPDEFINES)) - - Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc') - Misc.text = LINKFLAGS - - xml_indent(root) - out.write(etree.tostring(root, encoding='utf-8')) - out.close() - - # copy uvopt file - if os.path.exists('template.uvopt'): - import shutil - shutil.copy2('template.uvopt', 'project.uvopt') - -def MDK5AddGroupForFN(ProjectFiles, parent, name, filename, project_path): - group = SubElement(parent, 'Group') - group_name = SubElement(group, 'GroupName') - group_name.text = name - +def MDK4AddLibToGroup(ProjectFiles, group, name, filename, project_path): name = os.path.basename(filename) path = os.path.dirname (filename) @@ -232,6 +111,8 @@ def MDK5AddGroupForFN(ProjectFiles, parent, name, filename, project_path): obj_name = name.replace('.s', '.o') elif name.find('.S') != -1: obj_name = name.replace('.s', '.o') + else: + obj_name = name if ProjectFiles.count(obj_name): name = basename + '_' + name @@ -243,7 +124,7 @@ def MDK5AddGroupForFN(ProjectFiles, parent, name, filename, project_path): file_path.text = path.decode(fs_encoding) -def MDK5AddGroup(ProjectFiles, parent, name, files, project_path): +def MDK4AddGroup(ProjectFiles, parent, name, files, project_path): # don't add an empty group if len(files) == 0: return @@ -274,8 +155,6 @@ def MDK5AddGroup(ProjectFiles, parent, name, files, project_path): obj_name = name.replace('.s', '.o') elif name.find('.S') != -1: obj_name = name.replace('.s', '.o') - else: - obj_name = name if ProjectFiles.count(obj_name): name = basename + '_' + name @@ -287,16 +166,13 @@ def MDK5AddGroup(ProjectFiles, parent, name, files, project_path): file_path.text = path.decode(fs_encoding) -def MDK5Project(target, script): - project_path = os.path.dirname(os.path.abspath(target)) + return group - project_uvopt = os.path.abspath(target).replace('uvprojx', 'uvoptx') - if os.path.isfile(project_uvopt): - os.unlink(project_uvopt) +# The common part of making MDK4/5 project +def MDK45Project(tree, target, script): + project_path = os.path.dirname(os.path.abspath(target)) - tree = etree.parse('template.uvprojx') root = tree.getroot() - out = file(target, 'wb') out.write('\n') @@ -312,7 +188,31 @@ def MDK5Project(target, script): groups = SubElement(tree.find('Targets/Target'), 'Groups') groups.clear() # clean old groups for group in script: - group_xml = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path) + group_tree = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path) + + # for local CPPPATH/CPPDEFINES + if (group_tree != None) and (group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CCFLAGS')): + GroupOption = SubElement(group_tree, 'GroupOption') + GroupArmAds = SubElement(GroupOption, 'GroupArmAds') + Cads = SubElement(GroupArmAds, 'Cads') + VariousControls = SubElement(Cads, 'VariousControls') + MiscControls = SubElement(VariousControls, 'MiscControls') + if group.has_key('LOCAL_CCFLAGS'): + MiscControls.text = group['LOCAL_CCFLAGS'] + else: + MiscControls.text = ' ' + Define = SubElement(VariousControls, 'Define') + if group.has_key('LOCAL_CPPDEFINES'): + Define.text = ', '.join(set(group['LOCAL_CPPDEFINES'])) + else: + Define.text = ' ' + Undefine = SubElement(VariousControls, 'Undefine') + Undefine.text = ' ' + IncludePath = SubElement(VariousControls, 'IncludePath') + if group.has_key('LOCAL_CPPPATH'): + IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in group['LOCAL_CPPPATH']]) + else: + IncludePath.text = ' ' # get each include path if group.has_key('CPPPATH') and group['CPPPATH']: @@ -344,27 +244,17 @@ def MDK5Project(target, script): lib_path = full_path if lib_path != '': - MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path) - - # remove repeat path - paths = set() - for path in CPPPATH: - inc = _make_path_relative(project_path, os.path.normpath(path)) - paths.add(inc) #.replace('\\', '/') - - paths = [i for i in paths] - paths.sort() - CPPPATH = string.join(paths, ';') - - definitions = [i for i in set(CPPDEFINES)] - CPPDEFINES = string.join(definitions, ', ') + if (group_tree != None): + MDK4AddLibToGroup(ProjectFiles, group_tree, group['name'], lib_path, project_path) + else: + MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path) # write include path, definitions and link flags IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath') - IncludePath.text = CPPPATH + IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in CPPPATH]) Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define') - Define.text = CPPDEFINES + Define.text = ', '.join(set(CPPDEFINES)) Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc') Misc.text = LINKFLAGS @@ -373,6 +263,31 @@ def MDK5Project(target, script): out.write(etree.tostring(root, encoding='utf-8')) out.close() +def MDK4Project(target, script): + template_tree = etree.parse('template.uvproj') + + MDK45Project(template_tree, target, script) + + # remove project.uvopt file + project_uvopt = os.path.abspath(target).replace('uvproj', 'uvopt') + if os.path.isfile(project_uvopt): + os.unlink(project_uvopt) + + # copy uvopt file + if os.path.exists('template.uvopt'): + import shutil + shutil.copy2('template.uvopt', 'project.uvopt') + +def MDK5Project(target, script): + + template_tree = etree.parse('template.uvprojx') + + MDK45Project(template_tree, target, script) + + # remove project.uvopt file + project_uvopt = os.path.abspath(target).replace('uvprojx', 'uvoptx') + if os.path.isfile(project_uvopt): + os.unlink(project_uvopt) # copy uvopt file if os.path.exists('template.uvoptx'): import shutil