diff --git a/zh-cn/device-dev/porting/porting-chip-board-lwip.md b/zh-cn/device-dev/porting/porting-chip-board-lwip.md index 4c3ac9f16cd99f5b18de8181c154e910401abb12..5fc2525d714bf76fb6ca9ce1c877d6e7f4449840 100644 --- a/zh-cn/device-dev/porting/porting-chip-board-lwip.md +++ b/zh-cn/device-dev/porting/porting-chip-board-lwip.md @@ -8,41 +8,57 @@ lwIP是一个小型开源的TCP/IP协议栈,LiteOS-M已对开源lwIP做了适 如果需要使用lwIP组件,请按如下步骤适配: -1. 在产品目录下新建一个目录用来存放配置文件,如lwip_adapter。 +1. 在产品目录下新建一个目录用来存放产品的适配文件,如lwip_adapter。 -2. 将kernel/liteos_m/components/net/lwip-2.1/porting目录下的include目录和build.gn复制到步骤1的lwip_adapter目录下。 +2. 在lwip_adapter目录下新建一个目录include,用来存放适配的头文件。 -3. 如果默认配置不能满足产品使用,可根据产品使用情况修改对应的配置,如关闭DHCP功能,将lwip_adapter/include/lwip/lwipopts.h中宏LWIP_DHCP的值由1改为0。 +3. 在include目录下新建目录lwip,并在lwip目录下新建头文件lwipopts.h,代码如下所示,如果默认配置不能满足产品使用,可自行根据产品使用情况修改配置,如关闭DHCP功能。 ``` - //#define LWIP_DHCP 1 - #define LWIP_DHCP 0 + #ifndef _LWIP_ADAPTER_LWIPOPTS_H_ + #define _LWIP_ADAPTER_LWIPOPTS_H_ + + #include_next "lwip/lwipopts.h" + + #undef LWIP_DHCP + #define LWIP_DHCP 0 // 关闭DHCP功能 + + #endif /* _LWIP_ADAPTER_LWIPOPTS_H_ */ ``` -4. 将lwip_adapter/BUILD.gn里的LWIP_PORTING_INCLUDE_DIRS修改为步骤1中lwip_adapter目录下的include路径。 +4. 将kernel/liteos_m/components/net/lwip-2.1/porting目录下的BUILD.gn复制到lwip_adapter目录下,并按如下修改。 ``` - #include_dirs += LWIP_PORTING_INCLUDE_DIRS - include_dirs += "//xxx/lwip_adapter/include" + import("//kernel/liteos_m/liteos.gni") + import("$LITEOSTHIRDPARTY/lwip/lwip.gni") + import("$LITEOSTOPDIR/components/net/lwip-2.1/lwip_porting.gni") + + module_switch = defined(LOSCFG_NET_LWIP_SACK) + module_name = "lwip" + kernel_module(module_name) { + sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES - [ "$LWIPDIR/api/sockets.c" ] + include_dirs = [ "//utils/native/lite/include" ] + } + + #添加新增加的适配头文件路径include + config("public") { + include_dirs = [ "include" ] + LWIP_PORTING_INCLUDE_DIRS + LWIP_INCLUDE_DIRS + } ``` -5. 在产品的配置文件中设置编译lwIP的开关和编译路径,如config.json。 +5. 在产品的配置文件(如config.json)中设置lwIP的编译路径,即步骤4中BUILD.gn的路径。 ``` { "subsystem": "kernel", "components": [ - { "component": "liteos_m", "features":["enable_ohos_kernel_liteos_m_lwip = true", "ohos_kernel_liteos_m_lwip_path = \"//xxx/lwip_adapter:lwip\"" ] } + { "component": "liteos_m", "features":["ohos_kernel_liteos_m_lwip_path = \"//xxx/lwip_adapter\"" ] } ] }, ``` -6. 其他模块需要引用lwIP头文件时,头文件路径应该包含如下两个部分,且顺序不能变。 +6. 在产品的内核编译配置文件中,如kernel_config/debug.config,打开编译lwIP的开关。 ``` - include_dir = [ - "//xxx/lwip_adapter/include", #步骤4里的路径 - "//third_party/lwip/src/include", - ] + LOSCFG_NET_LWIP=y ``` -