standard-system-porting-guide.md 26.4 KB
Newer Older
D
duangavin123 已提交
1
# Standard System Porting Guide<a name="EN-US_TOPIC_0000001180064129"></a>
D
duangavin123 已提交
2

D
duangavin123 已提交
3 4 5 6
-   [Defining a Development Board](#section132mcpsimp)
    -   [Defining an SoC](#section135mcpsimp)
    -   [Defining a Product](#section145mcpsimp)
    -   [Verifying the Porting](#section163mcpsimp)
D
duangavin123 已提交
7

D
duangavin123 已提交
8 9 10 11
-   [Porting the Kernel](#section171mcpsimp)
    -   [1. Adding a Kernel-built Subsystem to the SoC](#section174mcpsimp)
    -   [2. Building the Kernel](#section182mcpsimp)
    -   [3. Verifying the Porting](#section207mcpsimp)
D
duangavin123 已提交
12

D
duangavin123 已提交
13 14 15 16 17
-   [Porting the HDF Driver](#section210mcpsimp)
    -   [1. LCD](#section212mcpsimp)
    -   [2. Touchscreen](#section229mcpsimp)
    -   [3. WLAN](#section274mcpsimp)
    -   [4. Samples](#section11253153018415)
D
duangavin123 已提交
18 19


D
duangavin123 已提交
20
This 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.
D
duangavin123 已提交
21

D
duangavin123 已提交
22
## Defining a Development Board<a name="section132mcpsimp"></a>
D
duangavin123 已提交
23

D
duangavin123 已提交
24
This 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**.
D
duangavin123 已提交
25

D
duangavin123 已提交
26
### Defining an SoC<a name="section135mcpsimp"></a>
D
duangavin123 已提交
27

D
duangavin123 已提交
28
Create a JSON file named after the SoC name in the  **//productdefine/common/device**  directory and specify the CPU architecture.
D
duangavin123 已提交
29

D
duangavin123 已提交
30
For example, to port  **MySOC**, which uses a 32-bit ARM kernel, configure the file as follows:
D
duangavin123 已提交
31

D
duangavin123 已提交
32 33 34
//productdefine/common/device/MySOC.json

```
D
duangavin123 已提交
35 36 37 38 39 40
{
    "target_os": "ohos",
    "target_cpu": "arm"
}
```

D
duangavin123 已提交
41 42 43 44 45
Currently,  **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**.

### Defining a Product<a name="section145mcpsimp"></a>

Create 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:
D
duangavin123 已提交
46

D
duangavin123 已提交
47 48 49
//productdefine/common/products/MyProduct.json

```
D
duangavin123 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
{
  "product_name": "MyProduct",
  "product_company" : "MyProductVendor",
  "product_device": "MySOC",
  "version": "2.0",
  "type": "standard",
  "parts":{
    "ace:ace_engine_standard":{},
    "ace:napi":{},
    ...
    "xts:phone_tests":{}
  }
}

```
D
duangavin123 已提交
65

D
duangavin123 已提交
66 67
The main configurations are as follows:

D
duangavin123 已提交
68 69 70
1.  **product\_device**: SoC used by the product.
2.  **type**: system level. In this example, set it to  **standard**.
3.  **parts**: subsystem to enable. A subsystem can be treated as an independently built functional block.
D
duangavin123 已提交
71

D
duangavin123 已提交
72
You can find available subsystems in  **//build/subsystem\_config.json**. You can also customize subsystems.
D
duangavin123 已提交
73

D
duangavin123 已提交
74
You 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.
D
duangavin123 已提交
75

D
duangavin123 已提交
76
### Verifying the Porting<a name="section163mcpsimp"></a>
D
duangavin123 已提交
77 78 79

Run the following command to start the build of your product:

D
duangavin123 已提交
80 81 82
```
./build.sh --product-name MyProduct 
```
D
duangavin123 已提交
83

D
duangavin123 已提交
84
After the build is complete, you can view the built OpenHarmony image file in  **//out/ohos-arm-release/packages/phone/images**.
D
duangavin123 已提交
85

D
duangavin123 已提交
86
## Porting the Kernel<a name="section171mcpsimp"></a>
D
duangavin123 已提交
87 88 89

Now, you need to port the Linux kernel to enable it to run successfully.

D
duangavin123 已提交
90
### 1. Adding a Kernel-built Subsystem to the SoC<a name="section174mcpsimp"></a>
D
duangavin123 已提交
91

D
duangavin123 已提交
92
Add the following subsystem configuration to the  **//build/subsystem\_config.json**  file:
D
duangavin123 已提交
93

D
duangavin123 已提交
94
```
D
duangavin123 已提交
95 96 97 98 99 100 101 102
  "MySOCVendor_products": {
    "project": "hmf/MySOCVendor_products",
    "path": "device/MySOCVendor/MySOC/build",
    "name": "MySOCVendor_products",
    "dir": "device/MySOCVendor"
  },
```

D
duangavin123 已提交
103
Then, open the configuration file  **//productdefine/common/products/MyProduct.json**, which is used to define the product, and add the new subsystem to the product.
D
duangavin123 已提交
104

D
duangavin123 已提交
105
### 2. Building the Kernel<a name="section182mcpsimp"></a>
D
duangavin123 已提交
106

D
duangavin123 已提交
107
The 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.
D
duangavin123 已提交
108

D
duangavin123 已提交
109
The 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.
D
duangavin123 已提交
110 111

The recommended directory structure is as follows:
D
duangavin123 已提交
112

D
duangavin123 已提交
113 114
```
├── build
D
duangavin123 已提交
115 116 117 118 119
│ ├── kernel
│ │     ├── linux
│ │           ├──standard_patch_for_4_19.patch // Patch for the Linux kernel 4.19
│ ├── BUILD.gn
│ ├── ohos.build
D
duangavin123 已提交
120 121
```

D
duangavin123 已提交
122
The  **BUILD.gn**  file is the only entry for building the subsystem.
D
duangavin123 已提交
123

D
duangavin123 已提交
124
The expected build result is as follows:
D
duangavin123 已提交
125

D
duangavin123 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
<a name="table193mcpsimp"></a>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry200mcpsimpp0"><a name="entry200mcpsimpp0"></a><a name="entry200mcpsimpp0"></a>Description</p>
</td>
</tr>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry203mcpsimpp0"><a name="entry203mcpsimpp0"></a><a name="entry203mcpsimpp0"></a>Kernel image</p>
</td>
</tr>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry206mcpsimpp0"><a name="entry206mcpsimpp0"></a><a name="entry206mcpsimpp0"></a>Bootloader image</p>
</td>
</tr>
</tbody>
</table>

### 3. Verifying the Porting<a name="section207mcpsimp"></a>
D
duangavin123 已提交
146 147 148

Now start build, and check whether the kernel image is generated as expected.

D
duangavin123 已提交
149 150 151 152 153
## Porting the HDF Driver<a name="section210mcpsimp"></a>

### 1. LCD<a name="section212mcpsimp"></a>

This 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.
D
duangavin123 已提交
154

D
duangavin123 已提交
155
The LCD drivers are stored in the  **//drivers/framework/model/display/driver/panel**  directory.
D
duangavin123 已提交
156

D
duangavin123 已提交
157
-   Create a panel driver.
D
duangavin123 已提交
158

D
duangavin123 已提交
159
In the  **Init**  method of the driver, call  **RegisterPanel**  to register the model instance.
D
duangavin123 已提交
160

D
duangavin123 已提交
161
```
D
duangavin123 已提交
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
int32_t XXXInit(struct HdfDeviceObject *object)
{
    struct PanelData *panel = CreateYourPanel();

    // Register the model instance.
    if (RegisterPanel(panel) != HDF_SUCCESS) {
        HDF_LOGE("%s: RegisterPanel failed", __func__);
        return HDF_FAILURE;
    }
    return HDF_SUCCESS;
}

struct HdfDriverEntry g_xxxxDevEntry = {
    .moduleVersion = 1,
    .moduleName = "LCD_XXXX",
    .Init = XXXInit,
};

HDF_INIT(g_xxxxDevEntry);
```

D
duangavin123 已提交
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.
D
duangavin123 已提交
184

D
duangavin123 已提交
185
```
D
duangavin123 已提交
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
root {
    ...
    display :: host {
        device_lcd :: device {
                deviceN :: deviceNode {
                    policy = 0;
                    priority = 100;
                    preload = 2;
                    moduleName = "LCD_XXXX";
                }
        }
    }
}
```

D
duangavin123 已提交
201
For details about driver development, see  [LCD](../driver/driver-peripherals-lcd-des.md).
D
duangavin123 已提交
202

D
duangavin123 已提交
203
### 2. Touchscreen<a name="section229mcpsimp"></a>
D
duangavin123 已提交
204

D
duangavin123 已提交
205
This 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.
D
duangavin123 已提交
206

D
duangavin123 已提交
207
-   Create a touchscreen driver.
D
duangavin123 已提交
208

D
duangavin123 已提交
209 210 211
Create the  **touch\_ic\_name.c**  file in the directory. Replace  **ic\_name**  with the name of your chip. The file template is as follows:

```
D
duangavin123 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
#include "hdf_touch.h"

static int32_t HdfXXXXChipInit(struct HdfDeviceObject *device)
{
    ChipDevice *tpImpl = CreateXXXXTpImpl();
    if(RegisterChipDevice(tpImpl) != HDF_SUCCESS) {
        ReleaseXXXXTpImpl(tpImpl);
        return HDF_FAILURE;
    }
    return HDF_SUCCESS;
}

struct HdfDriverEntry g_touchXXXXChipEntry = {
    .moduleVersion = 1,
    .moduleName = "HDF_TOUCH_XXXX",
    .Init = HdfXXXXChipInit,
};

HDF_INIT(g_touchXXXXChipEntry);
```

D
duangavin123 已提交
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
Implement the following interfaces in  **ChipDevice**:

<a name="table240mcpsimp"></a>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry247mcpsimpp0"><a name="entry247mcpsimpp0"></a><a name="entry247mcpsimpp0"></a>Description</p>
</td>
</tr>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry250mcpsimpp0"><a name="entry250mcpsimpp0"></a><a name="entry250mcpsimpp0"></a>Initializes a touchscreen.</p>
</td>
</tr>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry253mcpsimpp0"><a name="entry253mcpsimpp0"></a><a name="entry253mcpsimpp0"></a>Detects a touchscreen.</p>
</td>
</tr>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry256mcpsimpp0"><a name="entry256mcpsimpp0"></a><a name="entry256mcpsimpp0"></a>Suspends a touchscreen.</p>
</td>
</tr>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry259mcpsimpp0"><a name="entry259mcpsimpp0"></a><a name="entry259mcpsimpp0"></a>Resumes a touchscreen.</p>
</td>
</tr>
<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>
</td>
<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> &gt; <strong id="b103219389526"><a name="b103219389526"></a><a name="b103219389526"></a>driver</strong> &gt; <strong id="b0459173945212"><a name="b0459173945212"></a><a name="b0459173945212"></a>frameData</strong>.</p>
</td>
</tr>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry265mcpsimpp0"><a name="entry265mcpsimpp0"></a><a name="entry265mcpsimpp0"></a>Upgrades the firmware.</p>
</td>
</tr>
</tbody>
</table>

-   Configure the product and load the 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\_touch\_chip**  to the host named  **input**. Note: The value of  **moduleName**  must be the same as that in the touchscreen driver.
D
duangavin123 已提交
277 278


D
duangavin123 已提交
279
```
D
duangavin123 已提交
280 281 282 283 284 285 286 287 288 289
                deviceN :: deviceNode {
                    policy = 0;
                    priority = 130;
                    preload = 0;
                    permission = 0660;
                    moduleName = "HDF_TOUCH_XXXX";
                    deviceMatchAttr = "touch_XXXX_configs";
                }
```

D
duangavin123 已提交
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
For details about driver development, see  [TOUCHSCREEN](../driver/driver-peripherals-touch-des.md).

### 3. WLAN<a name="section274mcpsimp"></a>

The 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.

**Figure  1**  WLAN chip<a name="fig16997123013494"></a>  
![](figure/wlan-chip.png "wlan-chip")

To support a chip, implement a  **ChipDriver**  for it. The major task is to implement the following interfaces provided by  **HDF\_WLAN\_CORE**  and  **NetDevice**.

<a name="table280mcpsimp"></a>
<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>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry288mcpsimpp0"><a name="entry288mcpsimpp0"></a><a name="entry288mcpsimpp0"></a>Header File</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry289mcpsimpp0"><a name="entry289mcpsimpp0"></a><a name="entry289mcpsimpp0"></a>Description</p>
</td>
</tr>
<tr id="row290mcpsimp"><td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry291mcpsimpp0"><a name="entry291mcpsimpp0"></a><a name="entry291mcpsimpp0"></a>HdfChipDriverFactory</p>
</td>
<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>
</td>
<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>
</td>
</tr>
<tr id="row295mcpsimp"><td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry296mcpsimpp0"><a name="entry296mcpsimpp0"></a><a name="entry296mcpsimpp0"></a>HdfChipDriver</p>
</td>
<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>
</td>
<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>
</td>
</tr>
<tr id="row300mcpsimp"><td class="cellrowborder" valign="top" width="33.33333333333333%"><p id="entry301mcpsimpp0"><a name="entry301mcpsimpp0"></a><a name="entry301mcpsimpp0"></a>NetDeviceInterFace</p>
</td>
<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>
</td>
<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>
</td>
</tr>
</tbody>
</table>
D
duangavin123 已提交
332 333 334

To port a WLAN driver, perform the following steps:

D
duangavin123 已提交
335
1. 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:
D
duangavin123 已提交
336

D
duangavin123 已提交
337
```
D
duangavin123 已提交
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
static int32_t HdfWlanHisiChipDriverInit(struct HdfDeviceObject *device) {
    static struct HdfChipDriverFactory factory = CreateChipDriverFactory();
    struct HdfChipDriverManager *driverMgr = HdfWlanGetChipDriverMgr();
    if (driverMgr->RegChipDriver(&factory) != HDF_SUCCESS) {
        HDF_LOGE("%s fail: driverMgr is NULL!", __func__);
        return HDF_FAILURE;
    }
    return HDF_SUCCESS;
}

struct HdfDriverEntry g_hdfXXXChipEntry = {
    .moduleVersion = 1,
    .Init = HdfWlanXXXChipDriverInit,
    .Release = HdfWlanXXXChipRelease,
    .moduleName = "HDF_WIFI_CHIP_XXX"
};

HDF_INIT(g_hdfXXXChipEntry);
```

D
duangavin123 已提交
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
Create an  **HdfChipDriverFactory**  in the  **CreateChipDriverFactory**. The interfaces are as follows:

<a name="table312mcpsimp"></a>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry319mcpsimpp0"><a name="entry319mcpsimpp0"></a><a name="entry319mcpsimpp0"></a>Description</p>
</td>
</tr>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry322mcpsimpp0"><a name="entry322mcpsimpp0"></a><a name="entry322mcpsimpp0"></a>Indicates the driver name.</p>
</td>
</tr>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry325mcpsimpp0"><a name="entry325mcpsimpp0"></a><a name="entry325mcpsimpp0"></a>Initializes a chip.</p>
</td>
</tr>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry328mcpsimpp0"><a name="entry328mcpsimpp0"></a><a name="entry328mcpsimpp0"></a>Deinitializes a chip.</p>
</td>
</tr>
<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>
</td>
<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>
</td>
</tr>
<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>
</td>
<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>
</td>
</tr>
<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>
</td>
<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>
</td>
</tr>
<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>
</td>
<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>
</td>
</tr>
</tbody>
</table>

Implement the following interfaces in the  **HdfChipDriver**.

<a name="table342mcpsimp"></a>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry349mcpsimpp0"><a name="entry349mcpsimpp0"></a><a name="entry349mcpsimpp0"></a>Description</p>
</td>
</tr>
<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>
</td>
<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>
</td>
</tr>
<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>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="entry355mcpsimpp0"><a name="entry355mcpsimpp0"></a><a name="entry355mcpsimpp0"></a>Deinitializes the current network interface.</p>
</td>
</tr>
<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>
</td>
<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>
</td>
</tr>
<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>
</td>
<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>
</td>
</tr>
<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>
</td>
<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>
</td>
</tr>
</tbody>
</table>
D
duangavin123 已提交
439

D
duangavin123 已提交
440
2. Compile the configuration file to describe the devices supported by the driver.
D
duangavin123 已提交
441

D
duangavin123 已提交
442
Create the chip configuration file  **//vendor/MyProductVendor/MyProduct/config/wifi/wlan\_chip\_chip\_name.hcs**  in the product configuration directory.
D
duangavin123 已提交
443

D
duangavin123 已提交
444
Replace  **MyProductVendor**,  **MyProduct**, and  **chip\_name**  in the path with the actual names.
D
duangavin123 已提交
445 446

The sample code is as follows:
D
duangavin123 已提交
447 448

```
D
duangavin123 已提交
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
root {
    wlan_config {
        chip_name :& chipList {
            chip_name :: chipInst {
                match_attr = "hdf_wlan_chips_chip_name"; /* Configure the matching attribute, which is used to provide the configuration root of the driver.*/
                driverName = "driverName"; /* The value must be the same as that of driverName in HdfChipDriverFactory.*/
                sdio {
                    vendorId = 0x0296;
                    deviceId = [0x5347];
                }
            }
        }
    }
}
```

3. Edit the configuration file and load the driver.

D
duangavin123 已提交
467
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\_wlan\_chips**  to the host named  **network**. Note: The value of  **moduleName**  must be the same as that in the touchscreen driver.
D
duangavin123 已提交
468

D
duangavin123 已提交
469
```
D
duangavin123 已提交
470 471 472 473 474 475 476 477 478 479 480
                deviceN :: deviceNode {
                    policy = 0;
                    preload = 2;
                    moduleName = "HDF_WLAN_CHIPS";
                    deviceMatchAttr = "hdf_wlan_chips_chip_name";
                    serviceName = "driverName";
                }
```

4. Build the driver.

D
duangavin123 已提交
481 482
-   Create a kernel configuration menu. Create a  **Kconfig**  file in the  **//device/MySoCVendor/peripheral**  directory. The file template is as follows:

D
duangavin123 已提交
483 484 485 486 487 488 489 490 491
```
config DRIVERS_WLAN_XXX
    bool "Enable XXX WLAN Host driver"
    default n
    depends on DRIVERS_HDF_WIFI
    help
      Answer Y to enable XXX Host driver. Support chip xxx
```

D
duangavin123 已提交
492 493
Add 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:

D
duangavin123 已提交
494 495 496 497
```
source "../../../../../device/MySoCVendor/peripheral/Kconfig"
```

D
duangavin123 已提交
498 499 500
-   Create a build script.

    Add the following configuration to the end of the  **//drivers/adapter/khdf/linux/model/network/wifi/Makefile**  file:
D
duangavin123 已提交
501 502 503 504 505 506 507


```
HDF_DEVICE_ROOT := $(HDF_DIR_PREFIX)/../device
obj-$(CONFIG_DRIVERS_WLAN_XXX) += $(HDF_DEVICE_ROOT)/MySoCVendor/peripheral/build/standard/
```

D
duangavin123 已提交
508 509 510
When  **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).

### 4. Samples<a name="section11253153018415"></a>
D
duangavin123 已提交
511

D
duangavin123 已提交
512
For details about the porting sample, see the DAYU development board adaptation guide.
D
duangavin123 已提交
513