diff --git a/BUILD.gn b/BUILD.gn index 82c2d797..4402935c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -143,6 +143,7 @@ config("kconfig_config") { "$LITEOS_MENUCONFIG_H", ] asmflags = cflags + cflags_cc = cflags } config("warn_config") { diff --git a/components/fs/fatfs/fatfs.h b/components/fs/fatfs/fatfs.h index 21ad1e7f..6c92fde8 100644 --- a/components/fs/fatfs/fatfs.h +++ b/components/fs/fatfs/fatfs.h @@ -32,28 +32,21 @@ #ifndef _FATFS_H #define _FATFS_H -#include "fcntl.h" #include "dirent.h" -#include "unistd.h" +#include "fatfs_conf.h" +#include "fcntl.h" +#include "fs_config.h" #include "sys/mount.h" #include "sys/stat.h" #include "sys/statfs.h" -#include "fs_config.h" +#include "unistd.h" + #ifdef __cplusplus #if __cplusplus extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -#ifndef FAT_MAX_OPEN_FILES -#define FAT_MAX_OPEN_FILES 50 -#endif /* FAT_MAX_OPEN_FILES */ - -/* Format options */ -#define FMT_FAT 0x01 -#define FMT_FAT32 0x02 -#define FMT_ANY 0x07 - int fatfs_mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data); diff --git a/components/fs/fatfs/fatfs_conf.h b/components/fs/fatfs/fatfs_conf.h new file mode 100644 index 00000000..88127128 --- /dev/null +++ b/components/fs/fatfs/fatfs_conf.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _FATFS_CONF_H +#define _FATFS_CONF_H + +#ifndef FAT_MAX_OPEN_FILES +#define FAT_MAX_OPEN_FILES 50 +#endif /* FAT_MAX_OPEN_FILES */ + +/* Format options */ +#define FMT_FAT 0x01 +#define FMT_FAT32 0x02 +#define FMT_ANY 0x07 + +#endif // _FATFS_CONF_H diff --git a/components/fs/littlefs/lfs_api.h b/components/fs/littlefs/lfs_api.h index b1ff93be..8776f49d 100644 --- a/components/fs/littlefs/lfs_api.h +++ b/components/fs/littlefs/lfs_api.h @@ -39,6 +39,7 @@ #include "errno.h" #include "fs_operations.h" #include "lfs.h" +#include "lfs_conf.h" #include "lfs_util.h" #include "memory.h" #include "pthread.h" @@ -74,20 +75,6 @@ typedef struct { lfs_dir_t dir; } FileDirInfo; -#define LITTLE_FS_MAX_OPEN_FILES 100 -#define LITTLE_FS_STANDARD_NAME_LENGTH 50 -#define LITTLE_FS_MAX_NAME_LEN 255 - -#define MAX_DEF_BUF_NUM 21 -#define MAX_BUFFER_LEN 100 -#define MAX_WRITE_FILE_LEN 500 -#define MAX_READ_FILE_LEN 500 -#define LITTLEFS_MAX_LFN_LEN 255 - -#ifndef LFS_MAX_OPEN_DIRS -#define LFS_MAX_OPEN_DIRS 10 -#endif - LittleFsHandleStruct *GetFreeFd(int *fd); int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags, diff --git a/components/fs/littlefs/lfs_conf.h b/components/fs/littlefs/lfs_conf.h new file mode 100644 index 00000000..f0f785bb --- /dev/null +++ b/components/fs/littlefs/lfs_conf.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LFS_CONF_H +#define _LFS_CONF_H + +#define LITTLE_FS_MAX_OPEN_FILES 100 +#define LITTLE_FS_STANDARD_NAME_LENGTH 50 +#define LITTLE_FS_MAX_NAME_LEN 255 + +#define MAX_DEF_BUF_NUM 21 +#define MAX_WRITE_FILE_LEN 500 +#define MAX_READ_FILE_LEN 500 +#define LITTLEFS_MAX_LFN_LEN 255 + +#ifndef LFS_MAX_OPEN_DIRS +#define LFS_MAX_OPEN_DIRS 10 +#endif + +#endif // _LFS_CONF_H diff --git a/components/fs/vfs/vfs_config.h b/components/fs/vfs/vfs_config.h index e70d722c..f0ad857d 100644 --- a/components/fs/vfs/vfs_config.h +++ b/components/fs/vfs/vfs_config.h @@ -98,14 +98,14 @@ /* max numbers of other descriptors except socket descriptors */ #ifdef LOSCFG_FS_FAT -#include "fatfs.h" +#include "fatfs_conf.h" #define __FAT_NFILE FAT_MAX_OPEN_FILES #else #define __FAT_NFILE 0 #endif #ifdef LOSCFG_FS_LITTLEFS -#include "lfs_api.h" +#include "lfs_conf.h" #define __LFS_NFILE LITTLE_FS_MAX_OPEN_FILES #else #define __LFS_NFILE 0 @@ -123,12 +123,10 @@ #define CONFIG_NQUEUE_DESCRIPTORS 256 -#undef FD_SETSIZE -#define FD_SETSIZE (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS) +#define TIMER_FD_OFFSET (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS) #define CONFIG_NEXPANED_DESCRIPTORS (CONFIG_NTIME_DESCRIPTORS + CONFIG_NQUEUE_DESCRIPTORS) -#define FD_SET_TOTAL_SIZE (FD_SETSIZE + CONFIG_NEXPANED_DESCRIPTORS) -#define TIMER_FD_OFFSET FD_SETSIZE -#define MQUEUE_FD_OFFSET (FD_SETSIZE + CONFIG_NTIME_DESCRIPTORS) +#define FD_SET_TOTAL_SIZE (TIMER_FD_OFFSET + CONFIG_NEXPANED_DESCRIPTORS) +#define MQUEUE_FD_OFFSET (TIMER_FD_OFFSET + CONFIG_NTIME_DESCRIPTORS) /* directory configure */ diff --git a/components/net/lwip-2.1/porting/include/lwip/lwipopts.h b/components/net/lwip-2.1/porting/include/lwip/lwipopts.h index 529f04a8..2449d31b 100644 --- a/components/net/lwip-2.1/porting/include/lwip/lwipopts.h +++ b/components/net/lwip-2.1/porting/include/lwip/lwipopts.h @@ -134,10 +134,6 @@ #define LWIP_NETIF_LOOPBACK 1 #define LWIP_POSIX_SOCKETS_IO_NAMES 0 #define LWIP_RAW 1 -#ifdef LOSCFG_FS_VFS -#include "vfs_config.h" -#define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS -#endif #define LWIP_SO_RCVBUF 1 #define LWIP_SO_RCVTIMEO 1 #define LWIP_SO_SNDTIMEO 1 @@ -234,4 +230,9 @@ // use PBUF_RAM instead of PBUF_POOL in udp_input #define USE_PBUF_RAM_UDP_INPUT 1 +#ifdef LOSCFG_FS_VFS +#include "vfs_config.h" +#define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS +#endif + #endif /* _LWIP_PORTING_LWIPOPTS_H_ */ diff --git a/kal/libc/newlib/BUILD.gn b/kal/libc/newlib/BUILD.gn index 3f7ef337..4e4efc7d 100644 --- a/kal/libc/newlib/BUILD.gn +++ b/kal/libc/newlib/BUILD.gn @@ -37,6 +37,7 @@ kernel_module(module_name) { "porting/src/malloc.c", "porting/src/network/htonl.c", "porting/src/network/htons.c", + "porting/src/network/ntohl.c", "porting/src/network/ntohs.c", "porting/src/other_adapt.c", "porting/src/pthread.c", diff --git a/kal/libc/newlib/porting/include/sys/select.h b/kal/libc/newlib/porting/include/sys/select.h new file mode 100644 index 00000000..e5197a4c --- /dev/null +++ b/kal/libc/newlib/porting/include/sys/select.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ADAPT_SYS_SELECT_H +#define _ADAPT_SYS_SELECT_H + +#ifdef LOSCFG_FS_VFS +#include "vfs_config.h" + +#undef FD_SETSIZE +#define FD_SETSIZE TIMER_FD_OFFSET + +#else + +#undef FD_SETSIZE +#define FD_SETSIZE 1024 + +#endif + +#include_next + +#endif //_ADAPT_SYS_SELECT_H diff --git a/kal/libc/newlib/porting/src/network/ntohl.c b/kal/libc/newlib/porting/src/network/ntohl.c new file mode 100644 index 00000000..cdee459b --- /dev/null +++ b/kal/libc/newlib/porting/src/network/ntohl.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +uint32_t ntohl(uint32_t n) +{ + union { int i; char c; } u = { 1 }; + return u.c ? bswap_32(n) : n; +}