1# Standard System Porting Guide<a name="EN-US_TOPIC_0000001180064129"></a> 2 3- [Defining a Development Board](#section132mcpsimp) 4 - [Defining an SoC](#section135mcpsimp) 5 - [Defining a Product](#section145mcpsimp) 6 - [Verifying the Porting](#section163mcpsimp) 7 8- [Porting the Kernel](#section171mcpsimp) 9 - [1. Adding a Kernel-built Subsystem to the SoC](#section174mcpsimp) 10 - [2. Building the Kernel](#section182mcpsimp) 11 - [3. Verifying the Porting](#section207mcpsimp) 12 13- [Porting the HDF Driver](#section210mcpsimp) 14 - [1. LCD](#section212mcpsimp) 15 - [2. Touchscreen](#section229mcpsimp) 16 - [3. WLAN](#section274mcpsimp) 17 - [4. Samples](#section11253153018415) 18 19 20This document describes the general process for porting a development board, rather than the porting process specific to a System on Chip \(SoC\). In the future, the community will provide more development board porting examples for your reference. 21 22## Defining a Development Board<a name="section132mcpsimp"></a> 23 24This document uses the process of porting a development board named **MyProduct** as an example. This development board is provided by **MyProductVendor** and uses the SoC **MySOC** produced by **MySoCVendor**. 25 26### Defining an SoC<a name="section135mcpsimp"></a> 27 28Create a JSON file named after the SoC name in the **//productdefine/common/device** directory and specify the CPU architecture. 29 30For example, to port **MySOC**, which uses a 32-bit ARM kernel, configure the file as follows: 31 32//productdefine/common/device/MySOC.json 33 34``` 35{ 36 "target_os": "ohos", 37 "target_cpu": "arm" 38} 39``` 40 41Currently, **target\_cpu** can be set to **arm** only. In the future, you can set the value depending on the CPU architecture, such as **arm64**, **riscv**, or **x86**. 42 43### Defining a Product<a name="section145mcpsimp"></a> 44 45Create a JSON file named after the product name in the **//productdefine/common/products** directory. This file is used to describe the SoC used by the product and the required subsystems. Configure the file as follows: 46 47//productdefine/common/products/MyProduct.json 48 49``` 50{ 51 "product_name": "MyProduct", 52 "product_company" : "MyProductVendor", 53 "product_device": "MySOC", 54 "version": "2.0", 55 "type": "standard", 56 "parts":{ 57 "ace:ace_engine_standard":{}, 58 "ace:napi":{}, 59 ... 60 "xts:phone_tests":{} 61 } 62} 63 64``` 65 66The main configurations are as follows: 67 681. **product\_device**: SoC used by the product. 692. **type**: system level. In this example, set it to **standard**. 703. **parts**: subsystem to enable. A subsystem can be treated as an independently built functional block. 71 72You can find available subsystems in **//build/subsystem\_config.json**. You can also customize subsystems. 73 74You are advised to copy the configuration file of Hi3516D V300 and delete the **hisilicon\_products** subsystem, which is used to compile the kernel for Hi3516D V300. 75 76### Verifying the Porting<a name="section163mcpsimp"></a> 77 78Run the following command to start the build of your product: 79 80``` 81./build.sh --product-name MyProduct 82``` 83 84After the build is complete, you can view the built OpenHarmony image file in **//out/ohos-arm-release/packages/phone/images**. 85 86## Porting the Kernel<a name="section171mcpsimp"></a> 87 88Now, you need to port the Linux kernel to enable it to run successfully. 89 90### 1. Adding a Kernel-built Subsystem to the SoC<a name="section174mcpsimp"></a> 91 92Add the following subsystem configuration to the **//build/subsystem\_config.json** file: 93 94``` 95 "MySOCVendor_products": { 96 "project": "hmf/MySOCVendor_products", 97 "path": "device/MySOCVendor/MySOC/build", 98 "name": "MySOCVendor_products", 99 "dir": "device/MySOCVendor" 100 }, 101``` 102 103Then, open the configuration file **//productdefine/common/products/MyProduct.json**, which is used to define the product, and add the new subsystem to the product. 104 105### 2. Building the Kernel<a name="section182mcpsimp"></a> 106 107The OpenHarmony source code provides the Linux kernel 4.19, which is archived in **//kernel/linux-4.19**. This section uses this kernel version as an example to describe how to build the kernel. 108 109The path for building the subsystem is defined when you define the subsystem in the previous step. The path is **//device/MySOCVendor/MySOC/build**. Now, you need to create a build script in this path to instruct the build system to build the kernel. 110 111The recommended directory structure is as follows: 112 113``` 114├── build 115│ ├── kernel 116│ │ ├── linux 117│ │ ├──standard_patch_for_4_19.patch // Patch for the Linux kernel 4.19 118│ ├── BUILD.gn 119│ ├── ohos.build 120``` 121 122The **BUILD.gn** file is the only entry for building the subsystem. 123 124The expected build result is as follows: 125 126<a name="table193mcpsimp"></a> 127<table><tbody><tr id="row198mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry199mcpsimpp0"><a name="entry199mcpsimpp0"></a><a name="entry199mcpsimpp0"></a>File</p> 128</td> 129<td class="cellrowborder" valign="top" width="50%"><p id="entry200mcpsimpp0"><a name="entry200mcpsimpp0"></a><a name="entry200mcpsimpp0"></a>Description</p> 130</td> 131</tr> 132<tr id="row201mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry202mcpsimpp0"><a name="entry202mcpsimpp0"></a><a name="entry202mcpsimpp0"></a>$root_build_dir/packages/phone/images/uImage</p> 133</td> 134<td class="cellrowborder" valign="top" width="50%"><p id="entry203mcpsimpp0"><a name="entry203mcpsimpp0"></a><a name="entry203mcpsimpp0"></a>Kernel image</p> 135</td> 136</tr> 137<tr id="row204mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry205mcpsimpp0"><a name="entry205mcpsimpp0"></a><a name="entry205mcpsimpp0"></a>$root_build_dir/packages/phone/images/uboot</p> 138</td> 139<td class="cellrowborder" valign="top" width="50%"><p id="entry206mcpsimpp0"><a name="entry206mcpsimpp0"></a><a name="entry206mcpsimpp0"></a>Bootloader image</p> 140</td> 141</tr> 142</tbody> 143</table> 144 145### 3. Verifying the Porting<a name="section207mcpsimp"></a> 146 147Now start build, and check whether the kernel image is generated as expected. 148 149## Porting the HDF Driver<a name="section210mcpsimp"></a> 150 151### 1. LCD<a name="section212mcpsimp"></a> 152 153This section describes how to port a Liquid Crystal Display \(LCD\) driver. The hardware driver framework \(HDF\) designs a driver model for the LCD. To support an LCD, you must compile a driver, generate a model instance in the driver, and register the instance. 154 155The LCD drivers are stored in the **//drivers/framework/model/display/driver/panel** directory. 156 157- Create a panel driver. 158 159In the **Init** method of the driver, call **RegisterPanel** to register the model instance. 160 161``` 162int32_t XXXInit(struct HdfDeviceObject *object) 163{ 164 struct PanelData *panel = CreateYourPanel(); 165 166 // Register the model instance. 167 if (RegisterPanel(panel) != HDF_SUCCESS) { 168 HDF_LOGE("%s: RegisterPanel failed", __func__); 169 return HDF_FAILURE; 170 } 171 return HDF_SUCCESS; 172} 173 174struct HdfDriverEntry g_xxxxDevEntry = { 175 .moduleVersion = 1, 176 .moduleName = "LCD_XXXX", 177 .Init = XXXInit, 178}; 179 180HDF_INIT(g_xxxxDevEntry); 181``` 182 183- Configure and load the panel driver. All device information about the product is defined in the **//vendor/MyProductVendor/MyProduct/config/device\_info/device\_info.hcs** file. Modify the file by adding configurations for the device named **device\_lcd** to the host named **display**. Note: The value of **moduleName** must be the same as that in the panel driver. 184 185``` 186root { 187 ... 188 display :: host { 189 device_lcd :: device { 190 deviceN :: deviceNode { 191 policy = 0; 192 priority = 100; 193 preload = 2; 194 moduleName = "LCD_XXXX"; 195 } 196 } 197 } 198} 199``` 200 201For details about driver development, see [LCD](../driver/driver-peripherals-lcd-des.md). 202 203### 2. Touchscreen<a name="section229mcpsimp"></a> 204 205This section describes how to port a touchscreen driver. The touchscreen driver is stored in the **//drivers/framework/model/input/driver/touchscreen** directory. To port a touchscreen driver, register a **ChipDevice** model instance. 206 207- Create a touchscreen driver. 208 209Create the **touch\_ic\_name.c** file in the directory. Replace **ic\_name** with the name of your chip. The file template is as follows: 210 211``` 212#include "hdf_touch.h" 213 214static int32_t HdfXXXXChipInit(struct HdfDeviceObject *device) 215{ 216 ChipDevice *tpImpl = CreateXXXXTpImpl(); 217 if(RegisterChipDevice(tpImpl) != HDF_SUCCESS) { 218 ReleaseXXXXTpImpl(tpImpl); 219 return HDF_FAILURE; 220 } 221 return HDF_SUCCESS; 222} 223 224struct HdfDriverEntry g_touchXXXXChipEntry = { 225 .moduleVersion = 1, 226 .moduleName = "HDF_TOUCH_XXXX", 227 .Init = HdfXXXXChipInit, 228}; 229 230HDF_INIT(g_touchXXXXChipEntry); 231``` 232 233Implement the following interfaces in **ChipDevice**: 234 235<a name="table240mcpsimp"></a> 236<table><tbody><tr id="row245mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry246mcpsimpp0"><a name="entry246mcpsimpp0"></a><a name="entry246mcpsimpp0"></a>Interface</p> 237</td> 238<td class="cellrowborder" valign="top" width="50%"><p id="entry247mcpsimpp0"><a name="entry247mcpsimpp0"></a><a name="entry247mcpsimpp0"></a>Description</p> 239</td> 240</tr> 241<tr id="row248mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry249mcpsimpp0"><a name="entry249mcpsimpp0"></a><a name="entry249mcpsimpp0"></a>int32_t (*Init)(ChipDevice *device)</p> 242</td> 243<td class="cellrowborder" valign="top" width="50%"><p id="entry250mcpsimpp0"><a name="entry250mcpsimpp0"></a><a name="entry250mcpsimpp0"></a>Initializes a touchscreen.</p> 244</td> 245</tr> 246<tr id="row251mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry252mcpsimpp0"><a name="entry252mcpsimpp0"></a><a name="entry252mcpsimpp0"></a>int32_t (*Detect)(ChipDevice *device)</p> 247</td> 248<td class="cellrowborder" valign="top" width="50%"><p id="entry253mcpsimpp0"><a name="entry253mcpsimpp0"></a><a name="entry253mcpsimpp0"></a>Detects a touchscreen.</p> 249</td> 250</tr> 251<tr id="row254mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry255mcpsimpp0"><a name="entry255mcpsimpp0"></a><a name="entry255mcpsimpp0"></a>int32_t (*Suspend)(ChipDevice *device)</p> 252</td> 253<td class="cellrowborder" valign="top" width="50%"><p id="entry256mcpsimpp0"><a name="entry256mcpsimpp0"></a><a name="entry256mcpsimpp0"></a>Suspends a touchscreen.</p> 254</td> 255</tr> 256<tr id="row257mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry258mcpsimpp0"><a name="entry258mcpsimpp0"></a><a name="entry258mcpsimpp0"></a>int32_t (*Resume)(ChipDevice *device)</p> 257</td> 258<td class="cellrowborder" valign="top" width="50%"><p id="entry259mcpsimpp0"><a name="entry259mcpsimpp0"></a><a name="entry259mcpsimpp0"></a>Resumes a touchscreen.</p> 259</td> 260</tr> 261<tr id="row260mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry261mcpsimpp0"><a name="entry261mcpsimpp0"></a><a name="entry261mcpsimpp0"></a>int32_t (*DataHandle)(ChipDevice *device)</p> 262</td> 263<td class="cellrowborder" valign="top" width="50%"><p id="entry262mcpsimpp0"><a name="entry262mcpsimpp0"></a><a name="entry262mcpsimpp0"></a>Reads data from a touchscreen and writes the touch point data to <strong id="b109171435105216"><a name="b109171435105216"></a><a name="b109171435105216"></a>device</strong> > <strong id="b103219389526"><a name="b103219389526"></a><a name="b103219389526"></a>driver</strong> > <strong id="b0459173945212"><a name="b0459173945212"></a><a name="b0459173945212"></a>frameData</strong>.</p> 264</td> 265</tr> 266<tr id="row263mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry264mcpsimpp0"><a name="entry264mcpsimpp0"></a><a name="entry264mcpsimpp0"></a>int32_t (*UpdateFirmware)(ChipDevice *device)</p> 267</td> 268<td class="cellrowborder" valign="top" width="50%"><p id="entry265mcpsimpp0"><a name="entry265mcpsimpp0"></a><a name="entry265mcpsimpp0"></a>Upgrades the firmware.</p> 269</td> 270</tr> 271</tbody> 272</table> 273 274- Configure the product and load the driver. 275 276 All device information about the product is defined in the **//vendor/MyProductVendor/MyProduct/config/device\_info/device\_info.hcs** file. Modify the file by adding configurations for the device named **device\_touch\_chip** to the host named **input**. Note: The value of **moduleName** must be the same as that in the touchscreen driver. 277 278 279``` 280 deviceN :: deviceNode { 281 policy = 0; 282 priority = 130; 283 preload = 0; 284 permission = 0660; 285 moduleName = "HDF_TOUCH_XXXX"; 286 deviceMatchAttr = "touch_XXXX_configs"; 287 } 288``` 289 290For details about driver development, see [TOUCHSCREEN](../driver/driver-peripherals-touch-des.md). 291 292### 3. WLAN<a name="section274mcpsimp"></a> 293 294The WLAN driver is divided into two parts. One of the parts manages WLAN devices, and the other part manages WLAN traffic. HDF WLAN provides abstraction for the two parts. Currently, only the WLAN with the SDIO interface is supported. 295 296**Figure 1** WLAN chip<a name="fig16997123013494"></a> 297 298 299To support a chip, implement a **ChipDriver** for it. The major task is to implement the following interfaces provided by **HDF\_WLAN\_CORE** and **NetDevice**. 300 301<a name="table280mcpsimp"></a> 302<table><tbody><tr id="row286mcpsimp"><td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry287mcpsimpp0"><a name="entry287mcpsimpp0"></a><a name="entry287mcpsimpp0"></a>Interface</p> 303</td> 304<td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry288mcpsimpp0"><a name="entry288mcpsimpp0"></a><a name="entry288mcpsimpp0"></a>Header File</p> 305</td> 306<td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry289mcpsimpp0"><a name="entry289mcpsimpp0"></a><a name="entry289mcpsimpp0"></a>Description</p> 307</td> 308</tr> 309<tr id="row290mcpsimp"><td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry291mcpsimpp0"><a name="entry291mcpsimpp0"></a><a name="entry291mcpsimpp0"></a>HdfChipDriverFactory</p> 310</td> 311<td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="p136856366385"><a name="p136856366385"></a><a name="p136856366385"></a>//drivers/framework/include/wifi/hdf_wlan_chipdriver_manager.h</p> 312</td> 313<td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry294mcpsimpp0"><a name="entry294mcpsimpp0"></a><a name="entry294mcpsimpp0"></a>Factory of the <strong id="b0602182913593"><a name="b0602182913593"></a><a name="b0602182913593"></a>ChipDriver</strong>, which is used to support multiple WLAN interfaces of a chip.</p> 314</td> 315</tr> 316<tr id="row295mcpsimp"><td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry296mcpsimpp0"><a name="entry296mcpsimpp0"></a><a name="entry296mcpsimpp0"></a>HdfChipDriver</p> 317</td> 318<td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="p714312457389"><a name="p714312457389"></a><a name="p714312457389"></a>//drivers/framework/include/wifi/wifi_module.h</p> 319</td> 320<td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry299mcpsimpp0"><a name="entry299mcpsimpp0"></a><a name="entry299mcpsimpp0"></a>Manages a specific WLAN interface. Each WLAN interface corresponds to an <strong id="b1364875755918"><a name="b1364875755918"></a><a name="b1364875755918"></a>HdfChipDriver</strong>.</p> 321</td> 322</tr> 323<tr id="row300mcpsimp"><td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry301mcpsimpp0"><a name="entry301mcpsimpp0"></a><a name="entry301mcpsimpp0"></a>NetDeviceInterFace</p> 324</td> 325<td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="p015815313819"><a name="p015815313819"></a><a name="p015815313819"></a>//drivers/framework/include/net/net_device.h</p> 326</td> 327<td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry304mcpsimpp0"><a name="entry304mcpsimpp0"></a><a name="entry304mcpsimpp0"></a>Communicates with the protocol stack, such as sending data and setting the status of network interfaces.</p> 328</td> 329</tr> 330</tbody> 331</table> 332 333To port a WLAN driver, perform the following steps: 334 3351. Create an HDF driver. You are advised to place the code file in the **//device/MySoCVendor/peripheral/wifi/chip\_name/** directory. The file template is as follows: 336 337``` 338static int32_t HdfWlanHisiChipDriverInit(struct HdfDeviceObject *device) { 339 static struct HdfChipDriverFactory factory = CreateChipDriverFactory(); 340 struct HdfChipDriverManager *driverMgr = HdfWlanGetChipDriverMgr(); 341 if (driverMgr->RegChipDriver(&factory) != HDF_SUCCESS) { 342 HDF_LOGE("%s fail: driverMgr is NULL!", __func__); 343 return HDF_FAILURE; 344 } 345 return HDF_SUCCESS; 346} 347 348struct HdfDriverEntry g_hdfXXXChipEntry = { 349 .moduleVersion = 1, 350 .Init = HdfWlanXXXChipDriverInit, 351 .Release = HdfWlanXXXChipRelease, 352 .moduleName = "HDF_WIFI_CHIP_XXX" 353}; 354 355HDF_INIT(g_hdfXXXChipEntry); 356``` 357 358Create an **HdfChipDriverFactory** in the **CreateChipDriverFactory**. The interfaces are as follows: 359 360<a name="table312mcpsimp"></a> 361<table><tbody><tr id="row317mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry318mcpsimpp0"><a name="entry318mcpsimpp0"></a><a name="entry318mcpsimpp0"></a>Interface</p> 362</td> 363<td class="cellrowborder" valign="top" width="50%"><p id="entry319mcpsimpp0"><a name="entry319mcpsimpp0"></a><a name="entry319mcpsimpp0"></a>Description</p> 364</td> 365</tr> 366<tr id="row320mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry321mcpsimpp0"><a name="entry321mcpsimpp0"></a><a name="entry321mcpsimpp0"></a>const char *driverName</p> 367</td> 368<td class="cellrowborder" valign="top" width="50%"><p id="entry322mcpsimpp0"><a name="entry322mcpsimpp0"></a><a name="entry322mcpsimpp0"></a>Indicates the driver name.</p> 369</td> 370</tr> 371<tr id="row323mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry324mcpsimpp0"><a name="entry324mcpsimpp0"></a><a name="entry324mcpsimpp0"></a>int32_t (*InitChip)(struct HdfWlanDevice *device)</p> 372</td> 373<td class="cellrowborder" valign="top" width="50%"><p id="entry325mcpsimpp0"><a name="entry325mcpsimpp0"></a><a name="entry325mcpsimpp0"></a>Initializes a chip.</p> 374</td> 375</tr> 376<tr id="row326mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry327mcpsimpp0"><a name="entry327mcpsimpp0"></a><a name="entry327mcpsimpp0"></a>int32_t (*DeinitChip)(struct HdfWlanDevice *device)</p> 377</td> 378<td class="cellrowborder" valign="top" width="50%"><p id="entry328mcpsimpp0"><a name="entry328mcpsimpp0"></a><a name="entry328mcpsimpp0"></a>Deinitializes a chip.</p> 379</td> 380</tr> 381<tr id="row329mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry330mcpsimpp0"><a name="entry330mcpsimpp0"></a><a name="entry330mcpsimpp0"></a>void (_ReleaseFactory)(struct HdfChipDriverFactory _factory)</p> 382</td> 383<td class="cellrowborder" valign="top" width="50%"><p id="entry331mcpsimpp0"><a name="entry331mcpsimpp0"></a><a name="entry331mcpsimpp0"></a>Releases the <strong id="b088418304215"><a name="b088418304215"></a><a name="b088418304215"></a>HdfChipDriverFactory</strong> object.</p> 384</td> 385</tr> 386<tr id="row332mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry333mcpsimpp0"><a name="entry333mcpsimpp0"></a><a name="entry333mcpsimpp0"></a>struct HdfChipDriver _(_Build)(struct HdfWlanDevice *device, uint8_t ifIndex)</p> 387</td> 388<td class="cellrowborder" valign="top" width="50%"><p id="entry334mcpsimpp0"><a name="entry334mcpsimpp0"></a><a name="entry334mcpsimpp0"></a>Creates an <strong id="b1253415231438"><a name="b1253415231438"></a><a name="b1253415231438"></a>HdfChipDriver</strong>. In the input parameters, <strong id="b45408231539"><a name="b45408231539"></a><a name="b45408231539"></a>device</strong> indicates the device information, and <strong id="b1154116231432"><a name="b1154116231432"></a><a name="b1154116231432"></a>ifIndex</strong> indicates the sequence number of this interface in the chip.</p> 389</td> 390</tr> 391<tr id="row335mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry336mcpsimpp0"><a name="entry336mcpsimpp0"></a><a name="entry336mcpsimpp0"></a>void (_Release)(struct HdfChipDriver _chipDriver)</p> 392</td> 393<td class="cellrowborder" valign="top" width="50%"><p id="entry337mcpsimpp0"><a name="entry337mcpsimpp0"></a><a name="entry337mcpsimpp0"></a>Releases the <strong id="b155367141846"><a name="b155367141846"></a><a name="b155367141846"></a>HdfChipDriver</strong>.</p> 394</td> 395</tr> 396<tr id="row338mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry339mcpsimpp0"><a name="entry339mcpsimpp0"></a><a name="entry339mcpsimpp0"></a>uint8_t (*GetMaxIFCount)(struct HdfChipDriverFactory *factory)</p> 397</td> 398<td class="cellrowborder" valign="top" width="50%"><p id="entry340mcpsimpp0"><a name="entry340mcpsimpp0"></a><a name="entry340mcpsimpp0"></a>Obtains the maximum number of interfaces supported by the current chip.</p> 399</td> 400</tr> 401</tbody> 402</table> 403 404Implement the following interfaces in the **HdfChipDriver**. 405 406<a name="table342mcpsimp"></a> 407<table><tbody><tr id="row347mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry348mcpsimpp0"><a name="entry348mcpsimpp0"></a><a name="entry348mcpsimpp0"></a>Interface</p> 408</td> 409<td class="cellrowborder" valign="top" width="50%"><p id="entry349mcpsimpp0"><a name="entry349mcpsimpp0"></a><a name="entry349mcpsimpp0"></a>Description</p> 410</td> 411</tr> 412<tr id="row350mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry351mcpsimpp0"><a name="entry351mcpsimpp0"></a><a name="entry351mcpsimpp0"></a>int32_t (*init)(struct HdfChipDriver *chipDriver, NetDevice *netDev)</p> 413</td> 414<td class="cellrowborder" valign="top" width="50%"><p id="entry352mcpsimpp0"><a name="entry352mcpsimpp0"></a><a name="entry352mcpsimpp0"></a>Initializes the current network interface. The <strong id="b936614441419"><a name="b936614441419"></a><a name="b936614441419"></a>NetDeviceInterFace</strong> needs to be provided for the <strong id="b1237215441347"><a name="b1237215441347"></a><a name="b1237215441347"></a>netDev</strong>.</p> 415</td> 416</tr> 417<tr id="row353mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry354mcpsimpp0"><a name="entry354mcpsimpp0"></a><a name="entry354mcpsimpp0"></a>int32_t (*deinit)(struct HdfChipDriver *chipDriver, NetDevice *netDev)</p> 418</td> 419<td class="cellrowborder" valign="top" width="50%"><p id="entry355mcpsimpp0"><a name="entry355mcpsimpp0"></a><a name="entry355mcpsimpp0"></a>Deinitializes the current network interface.</p> 420</td> 421</tr> 422<tr id="row356mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry357mcpsimpp0"><a name="entry357mcpsimpp0"></a><a name="entry357mcpsimpp0"></a>struct HdfMac80211BaseOps *ops</p> 423</td> 424<td class="cellrowborder" valign="top" width="50%"><p id="entry358mcpsimpp0"><a name="entry358mcpsimpp0"></a><a name="entry358mcpsimpp0"></a>Provides the WLAN basic capability interface set.</p> 425</td> 426</tr> 427<tr id="row359mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry360mcpsimpp0"><a name="entry360mcpsimpp0"></a><a name="entry360mcpsimpp0"></a>struct HdfMac80211STAOps *staOps</p> 428</td> 429<td class="cellrowborder" valign="top" width="50%"><p id="entry361mcpsimpp0"><a name="entry361mcpsimpp0"></a><a name="entry361mcpsimpp0"></a>Provides the interface set required for supporting the standalone (STA) mode.</p> 430</td> 431</tr> 432<tr id="row362mcpsimp"><td class="cellrowborder" valign="top" width="50%"><p id="entry363mcpsimpp0"><a name="entry363mcpsimpp0"></a><a name="entry363mcpsimpp0"></a>struct HdfMac80211APOps *apOps</p> 433</td> 434<td class="cellrowborder" valign="top" width="50%"><p id="entry364mcpsimpp0"><a name="entry364mcpsimpp0"></a><a name="entry364mcpsimpp0"></a>Provides the interface set required for supporting the access point (AP) mode.</p> 435</td> 436</tr> 437</tbody> 438</table> 439 4402. Compile the configuration file to describe the devices supported by the driver. 441 442Create the chip configuration file **//vendor/MyProductVendor/MyProduct/config/wifi/wlan\_chip\_chip\_name.hcs** in the product configuration directory. 443 444Replace **MyProductVendor**, **MyProduct**, and **chip\_name** in the path with the actual names. 445 446The sample code is as follows: 447 448``` 449root { 450 wlan_config { 451 chip_name :& chipList { 452 chip_name :: chipInst { 453 match_attr = "hdf_wlan_chips_chip_name"; /* Configure the matching attribute, which is used to provide the configuration root of the driver.*/ 454 driverName = "driverName"; /* The value must be the same as that of driverName in HdfChipDriverFactory.*/ 455 sdio { 456 vendorId = 0x0296; 457 deviceId = [0x5347]; 458 } 459 } 460 } 461 } 462} 463``` 464 4653. Edit the configuration file and load the driver. 466 467All device information about the product is defined in the **//vendor/MyProductVendor/MyProduct/config/device\_info/device\_info.hcs** file. Modify the file by adding configurations for the device named **device\_wlan\_chips** to the host named **network**. Note: The value of **moduleName** must be the same as that in the touchscreen driver. 468 469``` 470 deviceN :: deviceNode { 471 policy = 0; 472 preload = 2; 473 moduleName = "HDF_WLAN_CHIPS"; 474 deviceMatchAttr = "hdf_wlan_chips_chip_name"; 475 serviceName = "driverName"; 476 } 477``` 478 4794. Build the driver. 480 481- Create a kernel configuration menu. Create a **Kconfig** file in the **//device/MySoCVendor/peripheral** directory. The file template is as follows: 482 483``` 484config DRIVERS_WLAN_XXX 485 bool "Enable XXX WLAN Host driver" 486 default n 487 depends on DRIVERS_HDF_WIFI 488 help 489 Answer Y to enable XXX Host driver. Support chip xxx 490``` 491 492Add the following sample code to the end of the **//drivers/adapter/khdf/linux/model/network/wifi/Kconfig** file to add the configuration menu to the kernel: 493 494``` 495source "../../../../../device/MySoCVendor/peripheral/Kconfig" 496``` 497 498- Create a build script. 499 500 Add the following configuration to the end of the **//drivers/adapter/khdf/linux/model/network/wifi/Makefile** file: 501 502 503``` 504HDF_DEVICE_ROOT := $(HDF_DIR_PREFIX)/../device 505obj-$(CONFIG_DRIVERS_WLAN_XXX) += $(HDF_DEVICE_ROOT)/MySoCVendor/peripheral/build/standard/ 506``` 507 508When **DRIVERS\_WLAN\_XXX** is enabled in the kernel, **makefile** in **//device/MySoCVendor/peripheral/build/standard/** is called. For more details, see [WLAN Development](../guide/device-wlan-led-outcontrol.md). 509 510### 4. Samples<a name="section11253153018415"></a> 511 512For details about the porting sample, see the DAYU development board adaptation guide. 513 514