Skip to content

Add several options to the nuttx target in precommit.py #1207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions config/nuttx/stm32f4dis/.config.travis
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ CONFIG_NETDEVICES=y
#
# CONFIG_NETDEV_LOOPBACK is not set
# CONFIG_NETDEV_TELNET is not set
# CONFIG_NETDEV_MULTINIC is not set
CONFIG_NETDEV_MULTINIC=y
# CONFIG_ARCH_HAVE_NETDEV_STATISTICS is not set
CONFIG_NETDEV_LATEINIT=y

Expand Down Expand Up @@ -1119,7 +1119,7 @@ CONFIG_FAT_MAXFNAME=32
# CONFIG_FAT_DMAMEMORY is not set
# CONFIG_FAT_DIRECT_RETRY is not set
# CONFIG_FS_NXFFS is not set
# CONFIG_FS_ROMFS is not set
CONFIG_FS_ROMFS=y
# CONFIG_FS_TMPFS is not set
# CONFIG_FS_SMARTFS is not set
# CONFIG_FS_BINFS is not set
Expand Down Expand Up @@ -1235,10 +1235,6 @@ CONFIG_HAVE_CXXINITIALIZE=y
# Application Configuration
#

#
# NxWidgets/NxWM
#

#
# Built-In Applications
#
Expand Down Expand Up @@ -1278,10 +1274,10 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024
CONFIG_EXAMPLES_NSH=y
CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
# CONFIG_EXAMPLES_NULL is not set
# CONFIG_EXAMPLES_NX is not set
# CONFIG_EXAMPLES_NXFFS is not set
# CONFIG_EXAMPLES_NXHELLO is not set
# CONFIG_EXAMPLES_NXIMAGE is not set
# CONFIG_EXAMPLES_NX is not set
# CONFIG_EXAMPLES_NXLINES is not set
# CONFIG_EXAMPLES_NXTERM is not set
# CONFIG_EXAMPLES_NXTEXT is not set
Expand All @@ -1293,6 +1289,7 @@ CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
# CONFIG_EXAMPLES_PWM is not set
# CONFIG_EXAMPLES_RFID_READUID is not set
# CONFIG_EXAMPLES_RGBLED is not set
# CONFIG_EXAMPLES_ROMFS is not set
# CONFIG_EXAMPLES_SENDMAIL is not set
# CONFIG_EXAMPLES_SERIALBLASTER is not set
# CONFIG_EXAMPLES_SERIALRX is not set
Expand All @@ -1303,9 +1300,11 @@ CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
# CONFIG_EXAMPLES_SMP is not set
# CONFIG_EXAMPLES_TCPECHO is not set
# CONFIG_EXAMPLES_TELNETD is not set
# CONFIG_EXAMPLES_THTTPD is not set
# CONFIG_EXAMPLES_TIFF is not set
# CONFIG_EXAMPLES_TOUCHSCREEN is not set
# CONFIG_EXAMPLES_UDGRAM is not set
# CONFIG_EXAMPLES_UNIONFS is not set
# CONFIG_EXAMPLES_USBSERIAL is not set
# CONFIG_EXAMPLES_USBTERM is not set
# CONFIG_EXAMPLES_USTREAM is not set
Expand Down Expand Up @@ -1454,6 +1453,19 @@ CONFIG_NSH_FILEIOSIZE=512
# CONFIG_NSH_DISABLESCRIPT is not set
# CONFIG_NSH_DISABLE_ITEF is not set
# CONFIG_NSH_DISABLE_LOOPS is not set
CONFIG_NSH_ROMFSETC=y
# CONFIG_NSH_ROMFSRC is not set
CONFIG_NSH_ROMFSMOUNTPT="/test"
CONFIG_NSH_INITSCRIPT="init.d/rcS"
CONFIG_NSH_ROMFSDEVNO=0
CONFIG_NSH_ROMFSSECTSIZE=64
CONFIG_NSH_DEFAULTROMFS=y
# CONFIG_NSH_ARCHROMFS is not set
# CONFIG_NSH_CUSTOMROMFS is not set
CONFIG_NSH_FATDEVNO=1
CONFIG_NSH_FATSECTSIZE=512
CONFIG_NSH_FATNSECTORS=1024
CONFIG_NSH_FATMOUNTPT="/tmp"

#
# Console Configuration
Expand Down Expand Up @@ -1484,6 +1496,10 @@ CONFIG_NSH_MAX_ROUNDTRIP=20
# CONFIG_NSH_LOGIN is not set
# CONFIG_NSH_CONSOLE_LOGIN is not set

#
# NxWidgets/NxWM
#

#
# Platform-specific Support
#
Expand Down
51 changes: 51 additions & 0 deletions config/nuttx/stm32f4dis/iotjs-memstat.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
diff --git a/src/iotjs_util.c b/src/iotjs_util.c
index 62ca214..dd6a978 100644
--- a/src/iotjs_util.c
+++ b/src/iotjs_util.c
@@ -58,8 +58,18 @@ iotjs_string_t iotjs_file_read(const char* path) {
}


+#define SIZEOF_MM_ALLOCNODE 8
+extern void jmem_heap_stat_alloc(size_t size);
+extern void jmem_heap_stat_free(size_t size);
+
+
char* iotjs_buffer_allocate(size_t size) {
char* buffer = (char*)(calloc(size, sizeof(char)));
+
+ size_t new_size;
+ memcpy(&new_size, (buffer - SIZEOF_MM_ALLOCNODE), sizeof(size_t));
+ jmem_heap_stat_alloc(new_size - SIZEOF_MM_ALLOCNODE);
+
IOTJS_ASSERT(buffer != NULL);
return buffer;
}
@@ -67,11 +77,26 @@ char* iotjs_buffer_allocate(size_t size) {

char* iotjs_buffer_reallocate(char* buffer, size_t size) {
IOTJS_ASSERT(buffer != NULL);
- return (char*)(realloc(buffer, size));
+
+ size_t old_size;
+ memcpy(&old_size, (buffer - SIZEOF_MM_ALLOCNODE), sizeof(size_t));
+ jmem_heap_stat_free(old_size - SIZEOF_MM_ALLOCNODE);
+
+ char* ptr = (char*)(realloc(buffer, size));
+
+ size_t new_size;
+ memcpy(&new_size, (ptr - SIZEOF_MM_ALLOCNODE), sizeof(size_t));
+ jmem_heap_stat_alloc(new_size - SIZEOF_MM_ALLOCNODE);
+
+ return ptr;
}


void iotjs_buffer_release(char* buffer) {
+ size_t size;
+ memcpy(&size, (buffer - SIZEOF_MM_ALLOCNODE), sizeof(size_t));
+ jmem_heap_stat_free(size - SIZEOF_MM_ALLOCNODE);
+
IOTJS_ASSERT(buffer != NULL);
free(buffer);
}
55 changes: 55 additions & 0 deletions config/nuttx/stm32f4dis/jerry-memstat.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
diff --git a/jerry-core/api/jerry.c b/jerry-core/api/jerry.c
index 1032881..88db6a3 100644
--- a/jerry-core/api/jerry.c
+++ b/jerry-core/api/jerry.c
@@ -149,7 +149,7 @@ jerry_init (jerry_init_flag_t flags) /**< combination of Jerry flags */
}

/* Zero out all members. */
- memset (&JERRY_CONTEXT (JERRY_CONTEXT_FIRST_MEMBER), 0, sizeof (jerry_context_t));
+ // memset (&JERRY_CONTEXT (JERRY_CONTEXT_FIRST_MEMBER), 0, sizeof (jerry_context_t));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is commented out?

Copy link
Contributor

@LaszloLango LaszloLango Sep 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to prevent the overflow of the counter. When jerry_init called, the allocated memory is not zero, because the IoT.js did some allocation for the environment. So we should not zero out memory statistics here, because it will cause an overflow after the free function calls.


JERRY_CONTEXT (jerry_init_flags) = flags;

diff --git a/jerry-core/jmem/jmem-heap.c b/jerry-core/jmem/jmem-heap.c
index f15ba90..8154880 100644
--- a/jerry-core/jmem/jmem-heap.c
+++ b/jerry-core/jmem/jmem-heap.c
@@ -113,8 +113,8 @@ JERRY_STATIC_ASSERT (sizeof (jmem_heap_t) <= JMEM_HEAP_SIZE,

#ifdef JMEM_STATS
static void jmem_heap_stat_init (void);
-static void jmem_heap_stat_alloc (size_t num);
-static void jmem_heap_stat_free (size_t num);
+void jmem_heap_stat_alloc (size_t num);
+void jmem_heap_stat_free (size_t num);

#ifndef JERRY_SYSTEM_ALLOCATOR
static void jmem_heap_stat_skip (void);
@@ -580,7 +580,7 @@ jmem_heap_stats_print (void)
{
jmem_heap_stats_t *heap_stats = &JERRY_CONTEXT (jmem_heap_stats);

- JERRY_DEBUG_MSG ("Heap stats:\n"
+ printf ("Heap stats:\n"
" Heap size = %zu bytes\n"
" Allocated = %zu bytes\n"
" Peak allocated = %zu bytes\n"
@@ -632,7 +632,7 @@ jmem_heap_stat_init (void)
/**
* Account allocation
*/
-static void
+void
jmem_heap_stat_alloc (size_t size) /**< Size of allocated block */
{
const size_t aligned_size = (size + JMEM_ALIGNMENT - 1) / JMEM_ALIGNMENT * JMEM_ALIGNMENT;
@@ -658,7 +658,7 @@ jmem_heap_stat_alloc (size_t size) /**< Size of allocated block */
/**
* Account freeing
*/
-static void
+void
jmem_heap_stat_free (size_t size) /**< Size of freed block */
{
const size_t aligned_size = (size + JMEM_ALIGNMENT - 1) / JMEM_ALIGNMENT * JMEM_ALIGNMENT;
105 changes: 105 additions & 0 deletions config/nuttx/stm32f4dis/libtuv-memstat.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
diff --git a/src/unix/fs.c b/src/unix/fs.c
index 4281246..cc0d694 100644
--- a/src/unix/fs.c
+++ b/src/unix/fs.c
@@ -98,7 +98,7 @@
if (cb == NULL) { \
req->path = path; \
} else { \
- req->path = strdup(path); \
+ req->path = uv__strdup(path); \
if (req->path == NULL) { \
uv__req_unregister(loop, req); \
return -ENOMEM; \
diff --git a/src/uv-common.c b/src/uv-common.c
index 813e499..04a7f18 100644
--- a/src/uv-common.c
+++ b/src/uv-common.c
@@ -67,7 +67,6 @@ static uv__allocator_t uv__allocator = {
free,
};

-#if defined(__APPLE__)
char* uv__strdup(const char* s) {
size_t len = strlen(s) + 1;
char* m = uv__malloc(len);
@@ -75,13 +74,29 @@ char* uv__strdup(const char* s) {
return NULL;
return memcpy(m, s, len);
}
-#endif
+
+#define SIZEOF_MM_ALLOCNODE 8
+extern void jmem_heap_stat_alloc (size_t size);
+extern void jmem_heap_stat_free (size_t size);

void* uv__malloc(size_t size) {
- return uv__allocator.local_malloc(size);
+ char* ptr = (char*)uv__allocator.local_malloc(size);
+
+ size_t new_size;
+ memcpy(&new_size, (ptr - SIZEOF_MM_ALLOCNODE), sizeof(size_t));
+ jmem_heap_stat_alloc(new_size - SIZEOF_MM_ALLOCNODE);
+
+ return (void*)ptr;
}

void uv__free(void* ptr) {
+ if (ptr == NULL)
+ return;
+
+ size_t size;
+ memcpy(&size, (char*)ptr - SIZEOF_MM_ALLOCNODE, sizeof(size_t));
+ jmem_heap_stat_free(size);
+
int saved_errno;

/* Libuv expects that free() does not clobber errno. The system allocator
@@ -93,11 +108,31 @@ void uv__free(void* ptr) {
}

void* uv__calloc(size_t count, size_t size) {
- return uv__allocator.local_calloc(count, size);
+ char* ptr = (char*)uv__allocator.local_calloc(count, size);
+
+ size_t new_size;
+ memcpy(&new_size, (ptr - SIZEOF_MM_ALLOCNODE), sizeof(size_t));
+ jmem_heap_stat_alloc(new_size - SIZEOF_MM_ALLOCNODE);
+
+ return (void*)ptr;
}

void* uv__realloc(void* ptr, size_t size) {
- return uv__allocator.local_realloc(ptr, size);
+ if (ptr != NULL) {
+ size_t old_size;
+ memcpy(&old_size, (char*)ptr - SIZEOF_MM_ALLOCNODE, sizeof(size_t));
+ jmem_heap_stat_free(old_size - SIZEOF_MM_ALLOCNODE);
+
+ char* new_ptr = (char*)uv__allocator.local_realloc(ptr, size);
+
+ size_t new_size;
+ memcpy(&new_size, (new_ptr - SIZEOF_MM_ALLOCNODE), sizeof(size_t));
+ jmem_heap_stat_alloc(new_size - SIZEOF_MM_ALLOCNODE);
+
+ return (void*)new_ptr;
+ }
+
+ return uv__malloc(size);
}

uv_buf_t uv_buf_init(char* base, unsigned int len) {
diff --git a/src/uv-common.h b/src/uv-common.h
index 069b5af..a24de69 100644
--- a/src/uv-common.h
+++ b/src/uv-common.h
@@ -239,9 +239,7 @@ void uv__fs_scandir_cleanup(uv_fs_t* req);

/* Allocator prototypes */
void *uv__calloc(size_t count, size_t size);
-#if defined(__APPLE__)
char *uv__strdup(const char* s);
-#endif
void* uv__malloc(size_t size);
void uv__free(void* ptr);
void* uv__realloc(void* ptr, size_t size);
84 changes: 84 additions & 0 deletions config/nuttx/stm32f4dis/nuttx-7.19.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
diff --git a/net/socket/getsockname.c b/net/socket/getsockname.c
index 7bf87c2..79fb7d7 100644
--- a/net/socket/getsockname.c
+++ b/net/socket/getsockname.c
@@ -151,10 +151,29 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
* a single network device and only the network device knows the IP address.
*/

+ if (lipaddr == 0)
+ {
+#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP)
+ outaddr->sin_family = AF_INET;
+ outaddr->sin_addr.s_addr = 0;
+ *addrlen = sizeof(struct sockaddr_in);
+#endif
+
+ return OK;
+ }
+
net_lock();

#ifdef CONFIG_NETDEV_MULTINIC
- /* Find the device matching the IPv4 address in the connection structure */
+ /* Find the device matching the IPv4 address in the connection structure.
+ * NOTE: listening sockets have no ripaddr. Work around is to use the
+ * lipaddr when ripaddr is not available.
+ */
+
+ if (ripaddr == 0)
+ {
+ ripaddr = lipaddr;
+ }

dev = netdev_findby_ipv4addr(lipaddr, ripaddr);
#else
@@ -274,10 +293,29 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
* a single network device and only the network device knows the IP address.
*/

+ if (net_ipv6addr_cmp(lipaddr, g_ipv6_allzeroaddr))
+ {
+#if defined(NET_TCP_HAVE_STACK) || defined(NET_UDP_HAVE_STACK)
+ outaddr->sin6_family = AF_INET6;
+ memcpy(outaddr->sin6_addr.in6_u.u6_addr8, g_ipv6_allzeroaddr, 16);
+ *addrlen = sizeof(struct sockaddr_in6);
+#endif
+
+ return OK;
+ }
+
net_lock();

#ifdef CONFIG_NETDEV_MULTINIC
- /* Find the device matching the IPv6 address in the connection structure */
+ /* Find the device matching the IPv6 address in the connection structure.
+ * NOTE: listening sockets have no ripaddr. Work around is to use the
+ * lipaddr when ripaddr is not available.
+ */
+
+ if (net_ipv6addr_cmp(ripaddr, g_ipv6_allzeroaddr))
+ {
+ ripaddr = lipaddr;
+ }

dev = netdev_findby_ipv6addr(*lipaddr, *ripaddr);
#else
diff --git a/net/socket/listen.c b/net/socket/listen.c
index 0d91ccb..4409a0e 100644
--- a/net/socket/listen.c
+++ b/net/socket/listen.c
@@ -142,7 +142,12 @@ int psock_listen(FAR struct socket *psock, int backlog)
* accept() is called and enables poll()/select() logic.
*/

- tcp_listen(conn);
+ errcode = tcp_listen(conn);
+ if (errcode < 0)
+ {
+ errcode = -errcode;
+ goto errout;
+ }
}
#endif /* CONFIG_NET_TCP */

2 changes: 1 addition & 1 deletion tools/apt-get-install-nuttx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
sudo apt-get update -q
sudo apt-get install -q -y \
autoconf libtool gperf flex bison autoconf2.13 \
cmake libncurses-dev libusb-1.0-0-dev \
cmake libncurses-dev libusb-1.0-0-dev genromfs \
libsgutils2-dev gcc-arm-none-eabi
Loading