提交 56fe036c 编写于 作者: D duangavin123

update 导入OpenHarmony工程

Signed-off-by: Nduangavin123 <duanxichao@huawei.com>
上级 3bc3443d
......@@ -17,7 +17,7 @@
- [Board-Level Driver Adaptation](transplant-chip-board-drive.md)
- [Implementation of APIs at the HAL](transplant-chip-board-hal.md)
- [System Modules](transplant-chip-board-component.md)
- [三方组件适配](transplant-chip-board-bundle.md)
- [Third-party Module Adaptation](transplant-chip-board-bundle.md)
- [XTS](transplant-chip-board-xts.md)
- [FAQ](transplant-chip-faqs.md)
- [Small System SoC Porting Guide](transplant-smallchip.md)
......
# 三方组件适配<a name="EN-US_TOPIC_0000001117478960"></a>
# Third-party Module Adaptation<a name="EN-US_TOPIC_0000001117478960"></a>
如果需要使用third\_party目录下与产品相关的三方组件,可能需要对三方组件进行适配,下面以比较常用的mbedtls为例,介绍下适配步骤,注意本小节中仅介绍如何将适配的代码与OpenHarmony的编译框架融合,不会详细介绍mbedtls本身的原理和适配代码的具体逻辑,这些内容请参考mbedtls官方网站上的适配指南。
To use third-party modules in the **third\_party** directory, you may need to adapt the modules. This section uses mbedTLS as an example to describe how to integrate the adaptation code with the OpenHarmony compilation framework. For the principles of mbedTLS and the specific logic of the adaptation code, see the adaptation guide on the mbedTLS official website.
1. 编写适配层代码
1. <a name="li12446195633211"></a>Write the adaptation layer code.
根据mbedtls官网的适配指南,编写需要的适配层代码,以适配硬件随机数举例,下面的路径都是相对third\_party/mbedtls的路径:
Write the required adaptation layer code based on the mbedTLS adaptation guide. In this example, adaptation of the hardware random number is used for illustration, and the paths are relative to **third\_party/mbedtls**:
1. 拷贝include/mbedtls/config.h到ports目录下,并修改打开MBEDTLS\_ENTROPY\_HARDWARE\_ALT开关。
2. 在ports目录下创建entropy\_poll\_alt.c文件include并实现entropy\_poll.h中的硬件随机数接口
3. 在BUILD.gn中的mbedtls\_sources中增加刚才适配的entropy\_poll\_alt.c的路径
4. 在BIULD.gn中的lite\_library\("mbedtls\_static"\)中增加一行MBEDTLS\_CONFIG\_FILE指定新配置文件的位置
1. Copy the **include/mbedtls/config.h** file to the **ports** directory, and enable **MBEDTLS\_ENTROPY\_HARDWARE\_ALT** in the file.
2. In the **ports** directory, create the **entropy\_poll\_alt.c** file under **include** and implement the hardware random number API in **entropy\_poll.h**.
3. Add the path of the adapted **entropy\_poll\_alt.c** file to **mbedtls\_sources** in the **BUILD.gn** file.
4. Add the line **MBEDTLS\_CONFIG\_FILE** to **lite\_library\("mbedtls\_static"\)** in the **BUILD.gn** file to specify the path of the new configuration file.
```
lite_library("mbedtks_static") {
......@@ -20,38 +20,38 @@
```
注意,上面的修改最好都新建一个config或者新建一个xxx\_alt.c文件来修改,不要直接在原先的代码中修改,侵入式的修改会导致后续版本升级出现大量零散冲突,增加升级维护成本。
You are advised to make the preceding modifications in a new **config.h** file or **_xxx_\_alt.c** file. Do not directly edit the code in the original file. Intrusive modifications may cause a large number of scattered conflicts during subsequent version updates, increasing the update maintenance costs.
2. 制作patch
2. Create a patch.
由于上面的适配是硬件相关的,上库代码时,不能直接放到通用的third\_party/mbedtls目录中,因此需要将上面的修改制作成patch,在编译之前通过打patch的方式注入到代码中。
The preceding adaptation is hardware-specific. Therefore, when uploading code to the library, you cannot directly store the code in the **third\_party/mbedtls** directory. Instead, you need to integrate the preceding modifications into a patch and inject the patch into the code for a build.
1. 首先增加设备的patch配置文件device/<company\>/<board\>/patch.yml
2. 编辑device/<company\>/<board\>/patch.yml,增加要打的patch的信息:
1. Add the patch configuration file **device/<_company_\>/<_board_\>/patch.yml**.
2. In the **device/<_company_\>/<_board_\>/patch.yml** file, add the information about the patch to apply.
```
# 需要打patch的路径,路径均为相对代码根目录的路径
# Path of the patch to apply. This path is relative to the code root directory.
third_party/mbedtls:
# 该路径下需要打的patch存放路径
# Directory in which the patch is stored.
- device/<company>/<board>/third_party/mbedtls/adapter.patch
third_party/wpa_supplicant:
# 当一个路径下有多个patch的时候会依次执行patch
# When there are multiple patches in a path, the patches are executed in sequence.
- device/<company>/<board>/third_party/wpa_supplicant/xxxxx.patch
- device/<company>/<board>/third_party/wpa_supplicant/yyyyy.patch
...
```
3. 制作上述**步骤1**修改的patch并放到对应的目录即可
3. Create a patch file as described in step [1](#li12446195633211) and save it to the corresponding directory.
3. 使用带patch的编译
3. Start a build with the patch.
想要在编译的时候带上patch,其他步骤不变,仅需要在触发编译的时候加上 --patch,例如全编译的命令编程
Add **--patch** when triggering a build. The following is the command for executing a full build with a patch:
```
hb build -f --patch
```
>![](../public_sys-resources/icon-caution.gif) **CAUTION:**
>最后一次打patch的产品信息会被记录,在进行下一次编译操作时,会对上一次的patch进行回退(即执行\`patch -p1 -R < xxx\`),回退patch失败或新增patch失败均会终止编译过程,请解决patch冲突后再次尝试编译。
>The information about the product to which the patch is most recently applied will be recorded. Next time the build is performed, the previous patch is rolled back \(that is, **\`patch -p1 -R < xxx\`** is executed\). If the patch fails to be rolled back or a patch fails to be added, the build process is terminated. In this case, resolve the patch conflict and try again.
......@@ -8,7 +8,7 @@
- **[System Modules](transplant-chip-board-component.md)**
- **[三方组件适配](transplant-chip-board-bundle.md)**
- **[Third-party Module Adaptation](transplant-chip-board-bundle.md)**
- **[XTS](transplant-chip-board-xts.md)**
......
......@@ -7,5 +7,5 @@ Drivers can be classified as platform drivers or device drivers. The platform dr
![](figure/分类.png)
The HDF driver is designed to be used across OSs. The HDF driver framework provides strong support for the driver to achieve this goal. During HDF driver development, you are advised to use only the APIs provided by the HDF driver framework. Otherwise, the driver cannot be used across OSs. Before driver development, familiarize yourself with the [HDF](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/hdf.md).
The Hardware Driver Foundation \(HDF\) is designed to work across OSs. The HDF driver framework provides strong support for drivers to achieve this goal. During HDF driver development, you are advised to use only the APIs provided by the HDF driver framework. Otherwise, the driver cannot be used across OSs. Before driver development, familiarize yourself with the [HDF](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/hdf.md).
......@@ -163,7 +163,7 @@ The WLAN driver is divided into two parts. One of the parts manages WLAN devices
![](figure/hdf_wifi.png)
As shown in [Figure 1](#fig155920160203), the left part manages Wi-Fi devices, and the right part manages WLAN traffic. The HDF WLAN framework abstracts these two parts. The porting process of the driver can be considered as the implementation of the APIs required by the two parts. These APIs are described as follows:
As shown in [Figure 1](#fig155920160203), the part on the left manages WLAN devices, and the part on the right manages WLAN traffic. The HDF WLAN framework abstracts these two parts. The porting process of the driver can be considered as the implementation of the APIs required by the two parts. These APIs are described as follows:
<a name="table1349145511213"></a>
<table><thead align="left"><tr id="row867115517211"><th class="cellrowborder" valign="top" width="17.28172817281728%" id="mcps1.1.4.1.1"><p id="p667255120"><a name="p667255120"></a><a name="p667255120"></a>API</p>
......@@ -178,21 +178,21 @@ As shown in [Figure 1](#fig155920160203), the left part manages Wi-Fi devices,
</td>
<td class="cellrowborder" valign="top" width="39.48394839483948%" headers="mcps1.1.4.1.2 "><p id="p10671551126"><a name="p10671551126"></a><a name="p10671551126"></a>drivers\framework\include\wifi\hdf_wlan_chipdriver_manager.h</p>
</td>
<td class="cellrowborder" valign="top" width="43.23432343234324%" headers="mcps1.1.4.1.3 "><p id="p26725514220"><a name="p26725514220"></a><a name="p26725514220"></a>Factory of the <strong id="b88841282246"><a name="b88841282246"></a><a name="b88841282246"></a>ChipDriver</strong>, which is used to support multiple WLAN ports of a chip.</p>
<td class="cellrowborder" valign="top" width="43.23432343234324%" headers="mcps1.1.4.1.3 "><p id="p26725514220"><a name="p26725514220"></a><a name="p26725514220"></a>Factory of the <strong id="b88841282246"><a name="b88841282246"></a><a name="b88841282246"></a>ChipDriver</strong>, which is used to support multiple WLAN interfaces of a chip.</p>
</td>
</tr>
<tr id="row186810552214"><td class="cellrowborder" valign="top" width="17.28172817281728%" headers="mcps1.1.4.1.1 "><p id="p11686551323"><a name="p11686551323"></a><a name="p11686551323"></a>HdfChipDriver</p>
</td>
<td class="cellrowborder" valign="top" width="39.48394839483948%" headers="mcps1.1.4.1.2 "><p id="p11686551723"><a name="p11686551723"></a><a name="p11686551723"></a>drivers\framework\include\wifi\wifi_module.h</p>
</td>
<td class="cellrowborder" valign="top" width="43.23432343234324%" headers="mcps1.1.4.1.3 "><p id="p26814555217"><a name="p26814555217"></a><a name="p26814555217"></a>Manages a specific WLAN port.</p>
<td class="cellrowborder" valign="top" width="43.23432343234324%" headers="mcps1.1.4.1.3 "><p id="p26814555217"><a name="p26814555217"></a><a name="p26814555217"></a>Manages a specific WLAN interface.</p>
</td>
</tr>
<tr id="row13686559215"><td class="cellrowborder" valign="top" width="17.28172817281728%" headers="mcps1.1.4.1.1 "><p id="p76810555214"><a name="p76810555214"></a><a name="p76810555214"></a>NetDeviceInterFace</p>
</td>
<td class="cellrowborder" valign="top" width="39.48394839483948%" headers="mcps1.1.4.1.2 "><p id="p166818551825"><a name="p166818551825"></a><a name="p166818551825"></a>drivers\framework\include\wifi\net_device.h</p>
</td>
<td class="cellrowborder" valign="top" width="43.23432343234324%" headers="mcps1.1.4.1.3 "><p id="p368195513213"><a name="p368195513213"></a><a name="p368195513213"></a>Communicates with the protocol stack, such as sending data and setting the status of network ports.</p>
<td class="cellrowborder" valign="top" width="43.23432343234324%" headers="mcps1.1.4.1.3 "><p id="p368195513213"><a name="p368195513213"></a><a name="p368195513213"></a>Communicates with the protocol stack, such as sending data and setting the status of network interfaces.</p>
</td>
</tr>
</tbody>
......@@ -312,11 +312,11 @@ The porting procedure is as follows:
</tbody>
</table>
2. Compile a configuration file to describe the chips supported by the driver.
2. Create a configuration file to describe the chips supported by the driver.
Create a chip configuration file in the product configuration directory and save it to the source code path **//vendor/vendor\_name/product\_name/config/wifi/wlan\_chip\_chip\_name.hcs**.
The following is the file template:
The sample code is as follows:
```
root {
......@@ -339,7 +339,7 @@ The porting procedure is as follows:
>Replace the values of **vendor\_name**, **product\_name**, and **chip\_name** in the path and file with the actual names.
>Set **vendorId** and **deviceId** to the actual vendor ID and chip ID, respectively.
3. Compile the configuration file and load the driver.
3. Edit the configuration file and load the driver.
All device information of the product is defined in the source code file **//vendor/vendor\_name/product\_name/config/device\_info/device\_info.hcs**. Modify the file and add configurations to the **device** named **device\_wlan\_chips** in the **host** of the **network** command. The sample code is as follows:
......
# Platform Driver Porting<a name="EN-US_TOPIC_0000001170794079"></a>
Create a platform driver in the source code directory **//device/vendor\_name/soc\_name/drivers**. If there is no repository for the vendor of your SoC, contact [sig-devboard](https://gitee.com/openharmony/community/blob/master/sig/sig-devboard/sig_devboard.md) to create one.
Create a platform driver in the source code directory **//device/vendor\_name/soc\_name/drivers**. If there is no repository for the vendor of your SoC, contact the [device SIG](https://gitee.com/openharmony/community/blob/master/sig/sig-devboard/sig_devboard.md) to create one.
The recommended directory structure is as follows:
......@@ -31,9 +31,9 @@ device
The HDF creates driver models for all platform drivers. The main task of porting platform drivers is to inject instances into the models. You can find the definitions of these models in the source code directory **//drivers/framework/support/platform/include**.
This section uses the GPIO as an example to describe how to port the platform driver. The porting procedure is as follows:
The following uses the GPIO as an example to describe how to port the platform driver:
1. Creating a GPIO driver.
1. Create a GPIO driver.
Create the **soc\_name\_gpio.c** file in the source code directory **//device/vendor\_name/soc\_name/drivers/gpio**. The sample code is as follows:
......@@ -70,7 +70,7 @@ This section uses the GPIO as an example to describe how to port the platform dr
{
// The GpioCntlrFromDevice method obtains the model instance registered in the init method from the abstract device object.
struct GpioCntlr *cntlr = GpioCntlrFromDevice(device);
// Destroy allocations.
// Release resources.
}
struct HdfDriverEntry g_gpioDriverEntry = {
......@@ -85,7 +85,7 @@ This section uses the GPIO as an example to describe how to port the platform dr
2. Create a build entry for the vendor driver.
As described above, **device/vendor\_name/drivers/lite.mk** is the entry for building vendor drivers. We need to start from this entry to build.
As described above, **device/vendor\_name/drivers/lite.mk** is the entry for building vendor drivers. We need to start building from this entry.
```
# File: device/vendor_name/drivers/lite.mk
......@@ -98,7 +98,7 @@ This section uses the GPIO as an example to describe how to port the platform dr
LIB_SUBDIRS += $(LITEOSTOPDIR)/../../device/$(SOC_VENDOR_NAME)/$(SOC_NAME)/drivers/
```
3. Create a build Entry for the SoC driver.
3. Create a build entry for the SoC driver.
```
# File: device/vendor_name/soc_name/drivers/lite.mk
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册