diff options
Diffstat (limited to 'components')
| -rw-r--r-- | components/drivers/cputime/cputimer.c | 5 | ||||
| -rw-r--r-- | components/drivers/include/rtdevice.h | 4 | ||||
| -rw-r--r-- | components/drivers/serial/serial_v2.c | 4 | ||||
| -rw-r--r-- | components/drivers/spi/spi_core.c | 8 | ||||
| -rw-r--r-- | components/drivers/tty/pty.c | 9 | ||||
| -rw-r--r-- | components/drivers/tty/tty.c | 6 | ||||
| -rw-r--r-- | components/lwp/arch/risc-v/rv64/lwp_gcc.S | 10 | ||||
| -rw-r--r-- | components/lwp/lwp_shm.c | 7 | ||||
| -rw-r--r-- | components/lwp/lwp_syscall.c | 105 | ||||
| -rw-r--r-- | components/lwp/lwp_user_mm.c | 11 | ||||
| -rw-r--r-- | components/net/lwip/port/ethernetif.c | 163 | ||||
| -rw-r--r-- | components/net/sal/Kconfig | 5 | ||||
| -rw-r--r-- | components/net/sal/impl/af_inet_lwip.c | 8 |
13 files changed, 325 insertions, 20 deletions
diff --git a/components/drivers/cputime/cputimer.c b/components/drivers/cputime/cputimer.c index 27e64a1354..12be40356e 100644 --- a/components/drivers/cputime/cputimer.c +++ b/components/drivers/cputime/cputimer.c @@ -337,6 +337,8 @@ rt_err_t rt_cputime_sleep(rt_uint64_t tick) /* current context checking */ RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE); + rt_cputimer_init(&cputimer, "cputime_sleep", _cputime_sleep_timeout, thread, 0, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER); + /* disable interrupt */ level = rt_hw_interrupt_disable(); @@ -349,7 +351,6 @@ rt_err_t rt_cputime_sleep(rt_uint64_t tick) /* reset the timeout of thread timer and start it */ if (err == RT_EOK) { - rt_cputimer_init(&cputimer, "cputime_sleep", _cputime_sleep_timeout, thread, 0, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER); rt_cputimer_control(&cputimer, RT_TIMER_CTRL_SET_TIME, &tick); rt_cputimer_start(&cputimer); @@ -359,7 +360,6 @@ rt_err_t rt_cputime_sleep(rt_uint64_t tick) thread->error = -RT_EINTR; rt_schedule(); - rt_cputimer_detach(&cputimer); if (thread->error == -RT_ETIMEOUT) thread->error = RT_EOK; } @@ -368,6 +368,7 @@ rt_err_t rt_cputime_sleep(rt_uint64_t tick) rt_hw_interrupt_enable(level); } + rt_cputimer_detach(&cputimer); return err; } diff --git a/components/drivers/include/rtdevice.h b/components/drivers/include/rtdevice.h index 97acc06e0b..5b1530dbc6 100644 --- a/components/drivers/include/rtdevice.h +++ b/components/drivers/include/rtdevice.h @@ -164,6 +164,10 @@ extern "C" { #include "drivers/rt_dev_bus.h" #endif +#ifdef RT_USING_LCD +#include "drivers/lcd.h" +#endif + #ifdef __cplusplus } #endif diff --git a/components/drivers/serial/serial_v2.c b/components/drivers/serial/serial_v2.c index 9e809048bd..c88df7aabe 100644 --- a/components/drivers/serial/serial_v2.c +++ b/components/drivers/serial/serial_v2.c @@ -296,7 +296,7 @@ static rt_ssize_t rt_serial_update_write_index(struct rt_ringbuffer *rb, * @param size Receive data buffer length. * @return Return the final length of data received. */ -rt_size_t _serial_poll_rx(struct rt_device *dev, +rt_ssize_t _serial_poll_rx(struct rt_device *dev, rt_off_t pos, void *buffer, rt_size_t size) @@ -343,7 +343,7 @@ rt_size_t _serial_poll_rx(struct rt_device *dev, * @param size Transmit data buffer length. * @return Return the final length of data received. */ -rt_size_t _serial_poll_tx(struct rt_device *dev, +rt_ssize_t _serial_poll_tx(struct rt_device *dev, rt_off_t pos, const void *buffer, rt_size_t size) diff --git a/components/drivers/spi/spi_core.c b/components/drivers/spi/spi_core.c index 63b50f265a..fca542d9bb 100644 --- a/components/drivers/spi/spi_core.c +++ b/components/drivers/spi/spi_core.c @@ -95,6 +95,14 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device, device->config.mode = cfg->mode & RT_SPI_MODE_MASK ; device->config.max_hz = cfg->max_hz ; + if (device->cs_pin != PIN_NONE) + { + if (device->config.mode & RT_SPI_CS_HIGH) + rt_pin_write(device->cs_pin, PIN_LOW); + else + rt_pin_write(device->cs_pin, PIN_HIGH); + } + if (device->bus != RT_NULL) { result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER); diff --git a/components/drivers/tty/pty.c b/components/drivers/tty/pty.c index 46a241a715..64e3a41df1 100644 --- a/components/drivers/tty/pty.c +++ b/components/drivers/tty/pty.c @@ -211,6 +211,12 @@ static int ptmx_open(struct dfs_fd *fd) ret = ld->ops->open(fd); } + rt_device_t device = (rt_device_t)fd->vnode->data; + if(fd->vnode->ref_count == 1) + { + ret = rt_device_open(device, fd->flags); + } + return ret; } #ifdef RT_USING_DEVICE_OPS @@ -286,7 +292,8 @@ static int pts_register(struct tty_struct *ptm_drv, struct tty_struct *pts_drv, extern struct termios tty_std_termios; pts_drv->init_termios = tty_std_termios; pts_drv->init_termios.c_cflag = B38400 | CS8 | CREAD; - pts_drv->init_termios.c_lflag |= ICANON; + pts_drv->init_termios.c_lflag |= ECHO | ICANON; + pts_drv->init_termios.c_oflag |= ONLCR; pts_drv->init_termios.__c_ispeed = 38400; pts_drv->init_termios.__c_ospeed = 38400; diff --git a/components/drivers/tty/tty.c b/components/drivers/tty/tty.c index 2a9380f55a..933d5f028b 100644 --- a/components/drivers/tty/tty.c +++ b/components/drivers/tty/tty.c @@ -200,7 +200,7 @@ int __tty_check_change(struct tty_struct *tty, int sig) if (!tty_pgrp) { - LOG_D(tty, "sig=%d, tty->pgrp == -1!\n", sig); + LOG_D("sig=%d, tty->pgrp == -1!\n", sig); } return ret; } @@ -275,7 +275,7 @@ static int tiocsctty(struct tty_struct *tty, int arg) if (current->leader && (current->session == tty->session)) { - return 0; + return 0; } /* @@ -284,7 +284,7 @@ static int tiocsctty(struct tty_struct *tty, int arg) */ if (!current->leader || current->tty) { - return -EPERM; + return -EPERM; } if (tty->session > 0) diff --git a/components/lwp/arch/risc-v/rv64/lwp_gcc.S b/components/lwp/arch/risc-v/rv64/lwp_gcc.S index c54726bc45..3977553dbf 100644 --- a/components/lwp/arch/risc-v/rv64/lwp_gcc.S +++ b/components/lwp/arch/risc-v/rv64/lwp_gcc.S @@ -121,6 +121,16 @@ arch_signal_quit: * routine in user stack */ user_do_signal: + /* prefetch ustack to avoid corrupted status in RESTORE/STORE pair below */ + LOAD t0, FRAME_OFF_SP(sp) + addi t1, t0, -CTX_REG_NR * REGBYTES + LOAD t2, (t0) + li t3, -0x1000 +1: + add t0, t0, t3 + LOAD t2, (t0) + bgt t0, t1, 1b + /** restore and backup kernel sp carefully to avoid leaking */ addi t0, sp, CTX_REG_NR * REGBYTES csrw sscratch, t0 diff --git a/components/lwp/lwp_shm.c b/components/lwp/lwp_shm.c index 8c765fc8c9..51964dd2b8 100644 --- a/components/lwp/lwp_shm.c +++ b/components/lwp/lwp_shm.c @@ -101,7 +101,7 @@ static int _lwp_shmget(size_t key, size_t size, int create) int id = -1; struct lwp_avl_struct *node_key = 0; struct lwp_avl_struct *node_pa = 0; - void *page_addr = 0, *page_addr_p = RT_NULL; + void *page_addr = 0; uint32_t bit = 0; /* try to locate the item with the key in the binary tree */ @@ -134,11 +134,10 @@ static int _lwp_shmget(size_t key, size_t size, int create) { goto err; } - page_addr_p = (void *)((char *)page_addr + PV_OFFSET); /* physical address */ /* initialize the shared memory structure */ p = _shm_ary + id; - p->addr = (size_t)page_addr_p; + p->addr = (size_t)page_addr; p->size = (1UL << (bit + ARCH_PAGE_SHIFT)); p->ref = 0; p->key = key; @@ -236,7 +235,7 @@ static int _lwp_shmrm(int id) return 0; } bit = rt_page_bits(p->size); - rt_pages_free((void *)((char *)p->addr - PV_OFFSET), bit); + rt_pages_free((void *)p->addr, bit); lwp_avl_remove(node_key, &shm_tree_key); node_pa = node_key + 1; lwp_avl_remove(node_pa, &shm_tree_pa); diff --git a/components/lwp/lwp_syscall.c b/components/lwp/lwp_syscall.c index 37459366f5..6b12d929fe 100644 --- a/components/lwp/lwp_syscall.c +++ b/components/lwp/lwp_syscall.c @@ -612,7 +612,7 @@ int sys_fstat(int file, struct stat *buf) { #ifdef ARCH_MM_MMU int ret = -1; - struct stat statbuff; + struct stat statbuff = {0}; if (!lwp_user_accessable((void *)buf, sizeof(struct stat))) { @@ -2575,7 +2575,45 @@ int sys_log(const char* log, int size) int sys_stat(const char *file, struct stat *buf) { int ret = 0; - ret = stat(file, buf); + int err; + size_t len; + size_t copy_len; + char *copy_path; + struct stat statbuff = {0}; + + if (!lwp_user_accessable((void *)buf, sizeof(struct stat))) + { + return -EFAULT; + } + + len = lwp_user_strlen(file, &err); + if (err) + { + return -EFAULT; + } + + copy_path = (char*)rt_malloc(len + 1); + if (!copy_path) + { + return -ENOMEM; + } + + copy_len = lwp_get_from_user(copy_path, (void*)file, len); + if (copy_len == 0) + { + rt_free(copy_path); + return -EFAULT; + } + copy_path[copy_len] = '\0'; + + ret = stat(copy_path, &statbuff); + rt_free(copy_path); + + if (ret == 0) + { + lwp_put_to_user(buf, &statbuff, sizeof statbuff); + } + return (ret < 0 ? GET_ERRNO() : ret); } @@ -4157,6 +4195,67 @@ int sys_getrandom(void *buf, size_t buflen, unsigned int flags) #endif return ret; } + +ssize_t sys_readlink(char* path, char *buf, size_t bufsz) +{ + size_t len, copy_len; + int err; + int fd = -1; + struct dfs_fd *d; + char *copy_path; + + len = lwp_user_strlen(path, &err); + if (err) + { + return -EFAULT; + } + + if (!lwp_user_accessable(buf, bufsz)) + { + return -EINVAL; + } + + copy_path = (char*)rt_malloc(len + 1); + if (!copy_path) + { + return -ENOMEM; + } + + copy_len = lwp_get_from_user(copy_path, path, len); + copy_path[copy_len] = '\0'; + + /* musl __procfdname */ + err = sscanf(copy_path, "/proc/self/fd/%d", &fd); + rt_free(copy_path); + + if (err != 1) + { + LOG_E("readlink: path not is /proc/self/fd/* , call by musl __procfdname()?"); + return -EINVAL; + } + + d = fd_get(fd); + if (!d) + { + return -EBADF; + } + + if (!d->vnode) + { + return -EBADF; + } + + copy_len = strlen(d->vnode->fullpath); + if (copy_len > bufsz) + { + copy_len = bufsz; + } + + bufsz = lwp_put_to_user(buf, d->vnode->fullpath, copy_len); + + return bufsz; +} + int sys_setaffinity(pid_t pid, size_t size, void *set) { if (!lwp_user_accessable(set, sizeof(cpu_set_t))) @@ -4672,7 +4771,7 @@ const static void* func_table[] = SYSCALL_SIGN(sys_setrlimit), SYSCALL_SIGN(sys_setsid), SYSCALL_SIGN(sys_getrandom), - SYSCALL_SIGN(sys_notimpl), // SYSCALL_SIGN(sys_readlink) /* 145 */ + SYSCALL_SIGN(sys_readlink), // SYSCALL_SIGN(sys_readlink) /* 145 */ SYSCALL_USPACE(SYSCALL_SIGN(sys_mremap)), SYSCALL_USPACE(SYSCALL_SIGN(sys_madvise)), SYSCALL_SIGN(sys_sched_setparam), diff --git a/components/lwp/lwp_user_mm.c b/components/lwp/lwp_user_mm.c index 3844a3b189..edda62632d 100644 --- a/components/lwp/lwp_user_mm.c +++ b/components/lwp/lwp_user_mm.c @@ -560,9 +560,12 @@ int lwp_user_accessable(void *addr, size_t size) len = size; } tmp_addr = lwp_v2p(lwp, addr_start); - if (!tmp_addr) + if (tmp_addr == ARCH_MAP_FAILED) { - return 0; + if ((rt_ubase_t)addr_start >= USER_STACK_VSTART && (rt_ubase_t)addr_start < USER_STACK_VEND) + tmp_addr = *(void **)addr_start; + else + return 0; } addr_start = (void *)((char *)addr_start + len); size -= len; @@ -596,7 +599,7 @@ size_t lwp_data_get(struct rt_lwp *lwp, void *dst, void *src, size_t size) len = size; } tmp_src = lwp_v2p(lwp, addr_start); - if (!tmp_src) + if (tmp_src == ARCH_MAP_FAILED) { break; } @@ -636,7 +639,7 @@ size_t lwp_data_put(struct rt_lwp *lwp, void *dst, void *src, size_t size) len = size; } tmp_dst = lwp_v2p(lwp, addr_start); - if (!tmp_dst) + if (tmp_dst == ARCH_MAP_FAILED) { break; } diff --git a/components/net/lwip/port/ethernetif.c b/components/net/lwip/port/ethernetif.c index 9b6dd7c896..4ce432ca6f 100644 --- a/components/net/lwip/port/ethernetif.c +++ b/components/net/lwip/port/ethernetif.c @@ -647,6 +647,169 @@ void eth_device_deinit(struct eth_device *dev) rt_free(netif); } +#ifdef SAL_USING_AF_UNIX /* create loopback netdev */ +static err_t af_unix_eth_netif_device_init(struct netif *netif) +{ + struct eth_device *ethif; + + ethif = (struct eth_device*)netif->state; + if (ethif != RT_NULL) + { + rt_device_t device; + +#ifdef RT_USING_NETDEV + /* network interface device register */ + netdev_add(netif); +#endif /* RT_USING_NETDEV */ + + /* get device object */ + device = (rt_device_t) ethif; + if (rt_device_init(device) != RT_EOK) + { + return ERR_IF; + } + if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK) + { + return ERR_IF; + } + + /* copy device flags to netif flags */ + netif->flags = (ethif->flags & 0xff); + netif->mtu = ETHERNET_MTU; + + /* set output */ + netif->output = etharp_output; + +#if LWIP_IPV6 + netif->output_ip6 = ethip6_output; + netif->ip6_autoconfig_enabled = 1; + netif_create_ip6_linklocal_address(netif, 1); + +#if LWIP_IPV6_MLD + netif->flags |= NETIF_FLAG_MLD6; + + /* + * For hardware/netifs that implement MAC filtering. + * All-nodes link-local is handled by default, so we must let the hardware know + * to allow multicast packets in. + * Should set mld_mac_filter previously. */ + if (netif->mld_mac_filter != NULL) + { + ip6_addr_t ip6_allnodes_ll; + ip6_addr_set_allnodes_linklocal(&ip6_allnodes_ll); + netif->mld_mac_filter(netif, &ip6_allnodes_ll, NETIF_ADD_MAC_FILTER); + } +#endif /* LWIP_IPV6_MLD */ + +#endif /* LWIP_IPV6 */ + + /* set default netif */ + if (netif_default == RT_NULL) + netif_set_default(ethif->netif); + + /* set interface up */ + netif_set_up(ethif->netif); + + + if (ethif->flags & ETHIF_LINK_PHYUP) + { + /* set link_up for this netif */ + netif_set_link_up(ethif->netif); + } + +#ifdef RT_USING_NETDEV + /* network interface device flags synchronize */ + netdev_flags_sync(netif); +#endif /* RT_USING_NETDEV */ + + return ERR_OK; + } + + return ERR_IF; +} + +/* Keep old drivers compatible in RT-Thread */ +rt_err_t af_unix_eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flags) +{ + struct netif* netif; +#if LWIP_NETIF_HOSTNAME +#define LWIP_HOSTNAME_LEN 16 + char *hostname = RT_NULL; + netif = (struct netif*) rt_calloc (1, sizeof(struct netif) + LWIP_HOSTNAME_LEN); +#else + netif = (struct netif*) rt_calloc (1, sizeof(struct netif)); +#endif + if (netif == RT_NULL) + { + rt_kprintf("malloc netif failed\n"); + return -RT_ERROR; + } + + /* set netif */ + dev->netif = netif; + dev->flags = flags; + /* link changed status of device */ + dev->link_changed = 0x00; + /* avoid send the same mail to mailbox */ + dev->rx_notice = 0x00; + dev->parent.type = RT_Device_Class_NetIf; + /* register to RT-Thread device manager */ + rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); + + /* set name */ + netif->name[0] = name[0]; + netif->name[1] = name[1]; + + /* set hw address to 6 */ + netif->hwaddr_len = 6; + /* maximum transfer unit */ + netif->mtu = ETHERNET_MTU; + + /* set linkoutput */ + netif->linkoutput = ethernetif_linkoutput; + + /* get hardware MAC address */ + rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr); + +#if LWIP_NETIF_HOSTNAME + /* Initialize interface hostname */ + hostname = (char *)netif + sizeof(struct netif); + rt_sprintf(hostname, "rtthread_%02x%02x", name[0], name[1]); + netif->hostname = hostname; +#endif /* LWIP_NETIF_HOSTNAME */ + + /* if tcp thread has been started up, we add this netif to the system */ + if (rt_thread_find("tcpip") != RT_NULL) + { +#if LWIP_VERSION_MAJOR == 1U /* v1.x */ + struct ip_addr ipaddr, netmask, gw; +#else /* >= v2.x */ + ip4_addr_t ipaddr, netmask, gw; +#endif /* LWIP_VERSION_MAJOR == 1U */ + + ipaddr.addr = inet_addr("127.0.0.1"); + gw.addr = inet_addr("255.0.0.0"); + netmask.addr = inet_addr("127.0.0.1"); + + netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, af_unix_eth_netif_device_init, tcpip_input); + } + + return RT_EOK; +} + +rt_err_t af_unix_eth_device_init(struct eth_device * dev, const char *name) +{ + rt_uint16_t flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP; + +#if LWIP_IGMP + /* IGMP support */ + flags |= NETIF_FLAG_IGMP; +#endif + + return af_unix_eth_device_init_with_flag(dev, name, flags); +} +#endif /* SAL_USING_AF_UNIX */ + #ifndef LWIP_NO_RX_THREAD rt_err_t eth_device_ready(struct eth_device* dev) { diff --git a/components/net/sal/Kconfig b/components/net/sal/Kconfig index e5395a6631..0197ae544e 100644 --- a/components/net/sal/Kconfig +++ b/components/net/sal/Kconfig @@ -34,6 +34,11 @@ if RT_USING_SAL Enable BSD socket operated by file system API Let BSD socket operated by file system API, such as read/write and involveed in select/poll POSIX APIs. + config SAL_USING_AF_UNIX + bool "Enable support AF_UNIX socket" + default n + default y if RT_USING_SMART + config SAL_SOCKETS_NUM int "the maximum number of sockets" depends on !SAL_USING_POSIX diff --git a/components/net/sal/impl/af_inet_lwip.c b/components/net/sal/impl/af_inet_lwip.c index 401b9001e4..52c1c2cb7d 100644 --- a/components/net/sal/impl/af_inet_lwip.c +++ b/components/net/sal/impl/af_inet_lwip.c @@ -225,11 +225,17 @@ static int inet_getsockname(int socket, struct sockaddr *name, socklen_t *namele int inet_ioctlsocket(int socket, long cmd, void *arg) { + int flags; + switch (cmd) { case F_GETFL: case F_SETFL: - return lwip_fcntl(socket, cmd, (int)(size_t)arg); + flags = (int)(size_t)arg; +#ifdef O_LARGEFILE + flags &= ~O_LARGEFILE; +#endif + return lwip_fcntl(socket, cmd, flags); default: return lwip_ioctl(socket, cmd, arg); |
