[v2,2/2] newlib: esp: add dirent.h header file

Message ID 633dfc3db668b04ed654394e180e733875e17f13.camel@espressif.com
State New
Headers
Series None |

Commit Message

Alexey Lapshin Aug. 30, 2024, 9:37 a.m. UTC
  Support dirent in *-esp-* toolchains

---
 newlib/Makefile.am                       |  8 ++--
 newlib/configure                         |  2 +-
 newlib/configure.host                    | 12 ++++--
 newlib/libc/sys/esp/include/sys/dirent.h | 49 ++++++++++++++++++++++++
 4 files changed, 63 insertions(+), 8 deletions(-)
 create mode 100644 newlib/libc/sys/esp/include/sys/dirent.h

-- 
2.43.0
  

Comments

Corinna Vinschen Sept. 2, 2024, 8:20 p.m. UTC | #1
On Aug 30 09:37, Alexey Lapshin wrote:
> Support dirent in *-esp-* toolchains
> 
> ---
>  newlib/Makefile.am                       |  8 ++--
>  newlib/configure                         |  2 +-
>  newlib/configure.host                    | 12 ++++--
>  newlib/libc/sys/esp/include/sys/dirent.h | 49 ++++++++++++++++++++++++
>  4 files changed, 63 insertions(+), 8 deletions(-)
>  create mode 100644 newlib/libc/sys/esp/include/sys/dirent.h

Patchset pushed.

Thanks,
Corinna
  

Patch

diff --git a/newlib/Makefile.am b/newlib/Makefile.am
index 87a7f8597..00088b6c3 100644
--- a/newlib/Makefile.am
+++ b/newlib/Makefile.am
@@ -312,10 +312,10 @@  install-data-local: install-toollibLIBRARIES install-multi $(INSTALL_DATA_LOCAL)
 	     $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/sys/`basename $$i`; \
 	    else true; fi ; \
 	  done ; \
-	  for i in $(srcdir)/libc/machine/$(machine_dir)/include/*.h; do \
-	    if [ -f $$i ]; then \
-	     $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/`basename $$i`; \
-	    else true; fi ; \
+	  for i in $(call rwildcard,$(srcdir)/libc/machine/$(machine_dir)/include/,*.h); do \
+	    f=`echo $$i | sed s:^$(srcdir)/libc/machine/$(machine_dir)/::`; \
+	    $(MKDIR_P) $(DESTDIR)$(tooldir)/`dirname $$f`; \
+	    $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/`dirname $$f`; \
 	  done ; \
 	  for i in $(srcdir)/libc/sys/$(sys_dir)/sys/*.h; do \
 	    if [ -f $$i ]; then \
diff --git a/newlib/configure b/newlib/configure
index cb4747880..e7158c063 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -6263,7 +6263,7 @@  else
 /* end confdefs.h.  */
 #define _LIBM
 // targ-include does not exist yet, use relative path
-#include "../sys/xtensa/include/xtensa/config/core-isa.h"
+#include "../machine/xtensa/include/xtensa/config/core-isa.h"
 #if (!XCHAL_HAVE_FP_SQRT)
 # error "Have not XCHAL_HAVE_FP_SQRT"
 #endif
diff --git a/newlib/configure.host b/newlib/configure.host
index a8a73f9bf..ff2e51275 100644
--- a/newlib/configure.host
+++ b/newlib/configure.host
@@ -446,6 +446,15 @@  case "${host}" in
 	sys_dir=tirtos
 	have_crt0="no"
 	;;
+  *-esp-*)
+	sys_dir=esp
+    have_crt0="no"
+	posix_dir=posix
+	newlib_cflags="${newlib_cflags} -D_NO_GLOB -D_NO_EXECVE -D_NO_GETLOGIN -D_NO_GETPWENT -D_NO_GETUT"
+	newlib_cflags="${newlib_cflags} -D_NO_GETPASS -D_NO_SIGSET -D_NO_WORDEXP -D_NO_POPEN -D_NO_POSIX_SPAWN"
+	newlib_cflags="${newlib_cflags} -DHAVE_FCNTL -DHAVE_BLKSIZE -DHAVE_OPENDIR -DHAVE_RENAME"
+	newlib_cflags="${newlib_cflags} -DGETREENT_PROVIDED -DSIGNAL_PROVIDED"
+	;;
   a29k-*-*)
 	sys_dir=a29khif
 	signal_dir=
@@ -579,9 +588,6 @@  case "${host}" in
   w65-*-*)
 	sys_dir=w65
 	;;
-  xtensa*-*-*)
-	sys_dir=xtensa
-	;;
   z8k-*-coff)
 	sys_dir=z8ksim
 	;;
diff --git a/newlib/libc/sys/esp/include/sys/dirent.h b/newlib/libc/sys/esp/include/sys/dirent.h
new file mode 100644
index 000000000..0e0c2f5fe
--- /dev/null
+++ b/newlib/libc/sys/esp/include/sys/dirent.h
@@ -0,0 +1,49 @@ 
+#ifndef _SYS_DIRENT_H
+#define _SYS_DIRENT_H
+
+#include <sys/cdefs.h>
+#include <sys/_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _INO_T_DECLARED
+typedef	__ino_t ino_t;
+#define	_INO_T_DECLARED
+#endif
+
+struct dirent {
+    ino_t d_ino;            /* file number */
+    __uint8_t d_type;       /* file type, see below */
+    char d_name[255 + 1];   /* zero-terminated file name */
+};
+
+typedef struct {
+    __uint16_t dd_vfs_idx; /*!< VFS index, not to be used by applications */
+    __uint16_t dd_rsv;     /*!< field reserved for future extension */
+    /* remaining fields are defined by VFS implementation */
+} DIR;
+
+#if __BSD_VISIBLE
+#define MAXNAMLEN	 255
+
+/* File types */
+#define	DT_UNKNOWN	 0
+#define	DT_REG		 1
+#define	DT_DIR		 2
+
+/* File types which are not defined for ESP.
+ * But must be present to build libstd++ */
+#define	DT_CHR		 4
+#define	DT_BLK		 6
+#define	DT_FIFO		 8
+#define	DT_LNK		10
+#define	DT_SOCK		12
+#define	DT_WHT		14
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif