Modify the source code file **//vendor/vendor\_name/product\_name/config/device\_info/device\_info.hcs**. Add configurations for the device named **device\_lcd** for the display host.
Modify the source code file **//vendor/vendor_name/product_name/config/device_info/device_info.hcs**. Add configurations for the device named **device\_lcd** for the display host.
This section describes how to port a touchscreen driver. The touchscreen drivers are stored in the source code directory **//drivers/framework/model/input/driver/touchscreen**. To port a touchscreen driver, register a **ChipDevice** model instance with the system.
This section describes how to port a touchscreen driver. The touchscreen drivers are stored in the source code directory **//drivers/hdf_core/framework/model/input/driver/touchscreen**. To port a touchscreen driver, register a **ChipDevice** model instance with the system.
For details about how to develop a touchscreen driver, see [Touchscreen Development Guidelines](../driver/driver-peripherals-touch-des.md).
For details about how to develop a touchscreen driver, see [Touchscreen Development Guidelines](../driver/driver-peripherals-touch-des.md).
1. Create a touchscreen driver.
1. Create a touchscreen driver.
Create the **touch\_ic\_name.c** file in the **touchscreen** directory. Write the following content:
Create the **touch\_ic\_name.c** file in the **touchscreen** directory. Write the following content:
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p93980212554"><a name="p93980212554"></a><a name="p93980212554"></a>Reads data from the device and writes touch point data to <strong id="b576475914217"><a name="b576475914217"></a><a name="b576475914217"></a>device</strong> > <strong id="b976511597218"><a name="b976511597218"></a><a name="b976511597218"></a>driver</strong> > <strong id="b117661559162110"><a name="b117661559162110"></a><a name="b117661559162110"></a>frameData</strong>.</p>
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\_touch\_chip** in the **host** of the **input** command.
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\_touch\_chip** in the **host** of the **input** command.
As shown in Figure 1, 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:
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:
| HdfChipDriverFactory | drivers\hdf_core\framework\include\wifi\hdf_wlan_chipdriver_manager.h | Factory of the ChipDriver, which is used to support multiple WLAN interfaces of a chip. |
</th>
| HdfChipDriver | drivers\hdf_core\framework\include\wifi\wifi_module.h | Manages a specific WLAN interface. |
| NetDeviceInterFace | drivers\hdf_core\framework\include\wifi\net_device.h | Communicates with the protocol stack, such as sending data and setting the status of network interfaces. |
<tdclass="cellrowborder"valign="top"width="43.23432343234324%"headers="mcps1.1.4.1.3 "><pid="p26725514220"><aname="p26725514220"></a><aname="p26725514220"></a>Factory of the <strongid="b88841282246"><aname="b88841282246"></a><aname="b88841282246"></a>ChipDriver</strong>, which is used to support multiple WLAN interfaces of a chip.</p>
<tdclass="cellrowborder"valign="top"width="43.23432343234324%"headers="mcps1.1.4.1.3 "><pid="p26814555217"><aname="p26814555217"></a><aname="p26814555217"></a>Manages a specific WLAN interface.</p>
<tdclass="cellrowborder"valign="top"width="43.23432343234324%"headers="mcps1.1.4.1.3 "><pid="p368195513213"><aname="p368195513213"></a><aname="p368195513213"></a>Communicates with the protocol stack, such as sending data and setting the status of network interfaces.</p>
| struct HdfChipDriver \*(\*Build)(struct HdfWlanDevice \*device, uint8_t ifIndex) | Creates an **HdfChipDriver**. In the input parameters, **device** indicates the device information, and **ifIndex** indicates the sequence number of this interface in the chip. |
</th>
| void (\*Release)(struct HdfChipDriver \*chipDriver) | Releases the chip driver. |
| uint8_t (\*GetMaxIFCount)(struct HdfChipDriverFactory \*factory) | Obtains the maximum number of interfaces supported by the current chip. |
</th>
</tr>
The **Build** method creates an **HdfChipDriver** object that manages the specified network interface. This object needs to provide the following methods:
| int32_t (\*init)(struct HdfChipDriver \*chipDriver, NetDevice \*netDev) | Initializes the current network interface. The **NetDeviceInterFace** needs to be provided for the **netDev**. |
</td>
| int32_t (\*deinit)(struct HdfChipDriver \*chipDriver, NetDevice \*netDev) | Deinitializes the current network interface. |
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p457143320911"><a name="p457143320911"></a><a name="p457143320911"></a>Creates an <strong id="b118260459243"><a name="b118260459243"></a><a name="b118260459243"></a>HdfChipDriver</strong>. In the input parameters, <strong id="b28271845162411"><a name="b28271845162411"></a><a name="b28271845162411"></a>device</strong> indicates the device information, and <strong id="b16827144519241"><a name="b16827144519241"></a><a name="b16827144519241"></a>ifIndex</strong> indicates the sequence number of this interface in the chip.</p>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p14571334915"><a name="p14571334915"></a><a name="p14571334915"></a>Obtains the maximum number of interfaces supported by the current chip.</p>
</td>
</tr>
</tbody>
</table>
The **Build** method creates an **HdfChipDriver** object that manages the specified network interface. This object needs to provide the following methods:
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1310184012103"><a name="p1310184012103"></a><a name="p1310184012103"></a>Initializes the current network interface. The <strong id="b18435181416253"><a name="b18435181416253"></a><a name="b18435181416253"></a>NetDeviceInterFace</strong> needs to be provided for the <strong id="b1543511144251"><a name="b1543511144251"></a><a name="b1543511144251"></a>netDev</strong>.</p>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p810104013106"><a name="p810104013106"></a><a name="p810104013106"></a>Provides the interface set required for supporting the STA mode.</p>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p710184013105"><a name="p710184013105"></a><a name="p710184013105"></a>Provides the interface set required for supporting the AP mode.</p>
</td>
</tr>
</tbody>
</table>
2. Create 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**.
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 sample code is as follows:
```
root {
```
wlan_config {
root {
chip_name :& chipList {
wlan_config {
chip_name :: chipInst {
chip_name :& chipList {
match_attr = "hdf_wlan_chips_chip_name"; /* Indicates the configuration matching attribute, which is used to provide the configuration root of the driver.*/
chip_name :: chipInst {
driverName = "driverName"; /* Indicates the driver name, which must be the same as that of driverName in HdfChipDriverFactory.*/
match_attr = "hdf_wlan_chips_chip_name"; /* Indicates the configuration matching attribute, which is used to provide the configuration root of the driver. */
sdio {
driverName = "driverName"; /* Indicates the driver name, which must be the same as that of driverName in HdfChipDriverFactory.*/
>Set **vendorId** and **deviceId** to the actual vendor ID and chip ID, respectively.
>
> 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. Edit 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:
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:
> Replace **chip\_name** with the actual chip name.
5. Modify the build script to enable the driver to participate in the kernel build.
5. Modify the build script to enable the driver to participate in the kernel build.
Add the following content to the end of the source code file **//device/vendor\_name/drivers/lite.mk**:
Add the following content to the end of the source code file **//device/vendor\_name/drivers/lite.mk**:
```
```
ifeq ($(LOSCFG_DRIVERS_HDF_WIFI_chip_name), y)
ifeq ($(LOSCFG_DRIVERS_HDF_WIFI_chip_name), y)
# After the build is complete, an object named hdf_wlan_chipdriver_chip_name needs to be linked. You are advised to use this name to prevent conflicts.
# After the build is complete, an object named hdf_wlan_chipdriver_chip_name needs to be linked. You are advised to use this name to prevent conflicts.
@@ -19,6 +19,7 @@ You can use the Bootloader provided by the chipset vendor or open-source U-Boot
...
@@ -19,6 +19,7 @@ You can use the Bootloader provided by the chipset vendor or open-source U-Boot
## Adaptation, Building, Burning, and Startup
## Adaptation, Building, Burning, and Startup
1. Prepare the kernel configuration files, especially the chipset-related configuration files.
1. Prepare the kernel configuration files, especially the chipset-related configuration files.
Source code directory of the configuration files: **kernel/linux/config/**
Source code directory of the configuration files: **kernel/linux/config/**
Create a **<*YOUR_CHIP*>_small_defconfig** file, such as **hi3516dv300_small_defconfig**, in the **linux-4.19/arch/arm/configs/** directory. The configuration file can be created by combining the general-purpose **small_common_defconfig** file and chipset-specific configurations.
Create a **<*YOUR_CHIP*>_small_defconfig** file, such as **hi3516dv300_small_defconfig**, in the **linux-4.19/arch/arm/configs/** directory. The configuration file can be created by combining the general-purpose **small_common_defconfig** file and chipset-specific configurations.
...
@@ -48,7 +49,7 @@ You can use the Bootloader provided by the chipset vendor or open-source U-Boot
...
@@ -48,7 +49,7 @@ You can use the Bootloader provided by the chipset vendor or open-source U-Boot
The burning mode varies according to the development board of the chipset. Pay attention to the size of each burnt image and the configuration of the boot parameters. Below is the U-Boot parameter settings of Hi3516D V300:
The burning mode varies according to the development board of the chipset. Pay attention to the size of each burnt image and the configuration of the boot parameters. Below is the U-Boot parameter settings of Hi3516D V300:
@@ -65,16 +66,23 @@ Debug the **init** process, start shell, and run a simple program in the user sp
...
@@ -65,16 +66,23 @@ Debug the **init** process, start shell, and run a simple program in the user sp
Based on the preceding process, the recommended verification procedure is as follows:
Based on the preceding process, the recommended verification procedure is as follows:
1. Create a root file system image.
1. Create a root file system image.
Create a root file system image **rootfs.img** by following instructions in [Building Procedures](../subsystems/subsys-build-all.md). As shown in the preceding figure, the startup process is closely related to the product configuration. You need to complete the following configuration when creating **rootfs.img**:
Create a root file system image **rootfs.img** by following instructions in [Building Procedures](../subsystems/subsys-build-all.md). As shown in the preceding figure, the startup process is closely related to the product configuration. You need to complete the following configuration when creating **rootfs.img**:
- Component configuration
- Component configuration
In the product component configuration file ***vendor*/{*company*}/{*product*}/config.json**, configure the **init** component of the startup subsystem and the **linux_4_1_9** component of the kernel subsystem.
In the product component configuration file ***vendor*/{*company*}/{*product*}/config.json**, configure the **init** component of the startup subsystem and the **linux_4_1_9** component of the kernel subsystem.
- System service configuration
- System service configuration
Modify the system service configuration file ***vendor*/{*company*}/{*product*}/init_configs/init_xxx.cfg** to start the shell service.
Modify the system service configuration file ***vendor*/{*company*}/{*product*}/init_configs/init_xxx.cfg** to start the shell service.
- File system configuration
- File system configuration
In the file system configuration file ***vendor*/{*company*}/{*product*}/fs.yml**, create the **/bin/sh -> mksh** and **/lib/ld-musl-arm.so.1 -> libc.so** soft links. These two files are the shell executable program and the c library on which the executable program depends, respectively.
In the file system configuration file ***vendor*/{*company*}/{*product*}/fs.yml**, create the **/bin/sh -> mksh** and **/lib/ld-musl-arm.so.1 -> libc.so** soft links. These two files are the shell executable program and the c library on which the executable program depends, respectively.
- Startup configuration
- Startup configuration
In the ***vendor*/{*company*}/{*product*}/init_configs/etc** directory, configure startup settings, including the **fstab**, **rsS**, and **S*xxx*** files. Configure the startup settings as needed.
In the ***vendor*/{*company*}/{*product*}/init_configs/etc** directory, configure startup settings, including the **fstab**, **rsS**, and **S*xxx*** files. Configure the startup settings as needed.
After the build is complete, check the **rootfs** content in the product compilation output directory to determine whether the generated **rootfs.img** file meets the expectation.
After the build is complete, check the **rootfs** content in the product compilation output directory to determine whether the generated **rootfs.img** file meets the expectation.
@@ -24,38 +24,38 @@ After learning the compilation framework and setting up the compilation environm
...
@@ -24,38 +24,38 @@ After learning the compilation framework and setting up the compilation environm
The directory structure is as follows: device/{*chipset solution vendor*}/{*development board*}. For example, if you are using the hispark_taurus development board from HiSilicon, create the following directory in the root directory of the code:
The directory structure is as follows: device/{*chipset solution vendor*}/{*development board*}. For example, if you are using the hispark_taurus development board from HiSilicon, create the following directory in the root directory of the code:
```
```
mkdir -p device/hisilicon/hispark_taurus
mkdir -p device/hisilicon/hispark_taurus
```
```
The chipset solution directory tree is as follows:
The chipset solution directory tree is as follows:
```
```
device
device
└── company # Chipset solution vendor
└── company # Chipset solution vendor
└── board # Name of the development board
└── board # Name of the development board
├── BUILD.gn # Build script
├── BUILD.gn # Build script
├── hals # OS device API adaptation
├── hals # OS device API adaptation
├── linux # (Optional) Linux kernel version
├── linux # (Optional) Linux kernel version
│ └── config.gni # Linux build configuration
│ └── config.gni # Linux build configuration
└── liteos_a # (Optional) LiteOS kernel version
└── liteos_a # (Optional) LiteOS kernel version
└── config.gni # LiteOS_A build configuration
└── config.gni # LiteOS_A build configuration
```
```
For example, if you are porting the Linux kernel to the hispark_taurus development board, the directory tree is as follows:
For example, if you are porting the Linux kernel to the hispark_taurus development board, the directory tree is as follows:
```
```
device
device
└── hisilicon
└── hisilicon
└── hispark_taurus
└── hispark_taurus
├── BUILD.gn
├── BUILD.gn
├── hals
├── hals
├── ......
├── ......
└── linux
└── linux
└── config.gni
└── config.gni
```
```
After the directory tree is created, store the source code related to the development board in the **hispark_taurus** directory.
After the directory tree is created, store the source code related to the development board in the **hispark_taurus** directory.
...
@@ -64,63 +64,63 @@ After learning the compilation framework and setting up the compilation environm
...
@@ -64,63 +64,63 @@ After learning the compilation framework and setting up the compilation environm
You can configure the build options in the **config.gni** file described in step 1. The compilation and building framework will then compile all OS components in the user space based on your configuration. The **config.gni** file contains the following key fields:
You can configure the build options in the **config.gni** file described in step 1. The compilation and building framework will then compile all OS components in the user space based on your configuration. The **config.gni** file contains the following key fields:
```
```
kernel_type: Kernel used by the development board, for example, LiteOS_A, LiteOS_M, or Linux.
kernel_type: Kernel used by the development board, for example, LiteOS_A, LiteOS_M, or Linux.
kernel_version: Kernel version used by the development board, for example, 4.19.
kernel_version: Kernel version used by the development board, for example, 4.19.
board_cpu: CPU of the development board, for example, Cortex-A7 or RISCV32.
board_cpu: CPU of the development board, for example, Cortex-A7 or RISCV32.
board_arch: Chipset architecture of the development board, for example, armv7-a or rv32imac.
board_arch: Chipset architecture of the development board, for example, armv7-a or rv32imac.
board_toolchain: Name of the customized build toolchain used by the development board, for example, gcc-arm-none-eabi. If this field is not specified, ohos-clang will be used.
board_toolchain: Name of the customized build toolchain used by the development board, for example, gcc-arm-none-eabi. If this field is not specified, ohos-clang will be used.
board_toolchain_prefix: Prefix of the toolchain, for example, gcc-arm-none-eabi.
board_toolchain_prefix: Prefix of the toolchain, for example, gcc-arm-none-eabi.
board_toolchain_type: Toolchain type. Currently, only GCC and clang are supported.
board_toolchain_type: Toolchain type. Currently, only GCC and clang are supported.
board_cflags: Build options of the .c file configured for the development board.
board_cflags: Build options of the .c file configured for the development board.
board_cxx_flags: Build options of the .cpp file configured for the development board.
board_cxx_flags: Build options of the .cpp file configured for the development board.
board_ld_flags: Linking options configured for the development board.
board_ld_flags: Linking options configured for the development board.
```
```
For HiSilicon's hispark_taurus development board, the content in **device/hisilicon/hispark_taurus/config.gni** is as follows:
For HiSilicon's hispark_taurus development board, the content in **device/hisilicon/hispark_taurus/config.gni** is as follows:
```
```
# Board CPU type, e.g. "cortex-a7", "riscv32".
# Board CPU type, e.g. "cortex-a7", "riscv32".
board_cpu = "cortex-a7"
board_cpu = "cortex-a7"
# Name of the toolchain used for system building
# Name of the toolchain used for system building
# E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang, riscv32-unknown-elf.
# E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang, riscv32-unknown-elf.
# Note: The "ohos-clang" toolchain is used by default. You can also customize the toolchain.
# Note: The "ohos-clang" toolchain is used by default. You can also customize the toolchain.
board_toolchain = "mips-linux-gnu-gcc"
board_toolchain = "mips-linux-gnu-gcc"
# Path where the toolchain is installed, which can be left blank if the installation path has been added to ~/.bashrc.
# Path where the toolchain is installed, which can be left blank if the installation path has been added to ~/.bashrc.
**ohos_version**: operating system version. This parameter is optional.
|board|(Mandatory) Development board name.|
|enable_ramdisk|(Mandatory) Whether to start the RAM disk.|
**device_company**: device manufacturer name. This parameter is required.
|kernel_type|(Optional) Kernel type.|
|kernel_version|(Optional) Kernel version. The values of both **kernel_type** and **kernel_version** are fixed in the standard system.|
**board**: board name. This parameter is required.
|subsystems|(Mandatory) Subsystem to enable. A subsystem can be treated as an independently built functional block.|
|product_company|Device manufacturer name. It is not set in the configuration, but in the directory name, next to the vendor name. It can be accessed from **build.gn script**.|
**enable_ramdisk**: whether to enable the RAM disk. This parameter is required.
**kernel_type**: kernel type. This parameter is optional.
**kernel_version**: kernel version. This parameter is optional. Both **kernel_type** and **kernel_version** are fixed.
**subsystems**: subsystem to enable. A subsystem can be treated as an independently built functional block. This parameter is required.
**product_company**: device manufacturer name. It is not set in the configuration, but in the directory name, next to the vendor name. It can be accessed from **build.gn script**.
You can find predefined subsystems in **//build/subsystem_config.json**. You can also customize subsystems.
You can find predefined subsystems in **//build/subsystem_config.json**. You can also customize subsystems.
...
@@ -89,7 +80,7 @@ Now, you need to port the Linux kernel to enable it to run successfully.
...
@@ -89,7 +80,7 @@ Now, you need to port the Linux kernel to enable it to run successfully.
### Adding a Kernel-built Subsystem to the SoC
### Adding a Kernel-built Subsystem to the SoC
Add the following subsystem configuration to the **//build/subsystem_config.json** file:
Modify the **//build/subsystem_config.json** file to add a subsystem. For example, if **product_name** is **MyProduct**, configure the **//vendor/MyProductVendor/MyProduct/config.json** file as follows:
```
```
...
@@ -126,10 +117,10 @@ The **BUILD.gn** file is the only entry for building the subsystem.
...
@@ -126,10 +117,10 @@ The **BUILD.gn** file is the only entry for building the subsystem.
The expected build result described in the table below.
The expected build result described in the table below.
@@ -140,17 +131,18 @@ Now start build, and check whether the kernel image is generated as expected.
...
@@ -140,17 +131,18 @@ Now start build, and check whether the kernel image is generated as expected.
1. Overview of user-mode boot process
1. Overview of user-mode boot process


When the system is powered on, the kernel loads and starts services and applications as follows:
When the system is powered on, the kernel loads and starts services and applications as follows:
1. The kernel loads the init process, which is specified by **cmdline** of the kernel when the bootloader starts the kernel, for example, **init=/init root/dev/xxx**.
1. The kernel loads the init process, which is specified by **cmdline** of the kernel when the bootloader starts the kernel, for example, **init=/init root/dev/xxx**.
2. After the init process is started, **tmpfs** and **procfs** are mounted and basic **dev** nodes are created to establish a basic root file system.
2. After the init process is started, **tmpfs** and **procfs** are mounted and basic **dev** nodes are created to establish a basic root file system.
3. The init process starts the ueventd process to listen for device hot-swap events in the kernel and creates **dev** nodes for related devices as well as partitions for the block device.
3. The init process starts the ueventd process to listen for device hot-swap events in the kernel and creates **dev** nodes for related devices as well as partitions for the block device.
4. After mounting partitions (**system** and **vendor**) of the block device, the init process scans for the init startup script of each system service and launches the respective service ability (SA).
4. After mounting partitions (**system** and **vendor**) of the block device, the init process scans for the init startup script of each system service and launches the respective service ability (SA).
5. Each SA registers with the samgr process, which serves as the service registration center. The samgr process assigns each SA with an ID, which will be used by an application to access the desired SA.
5. Each SA registers with the samgr process, which serves as the service registration center. The samgr process assigns each SA with an ID, which will be used by an application to access the desired SA.
6. The foundation process implements application lifecycle management. It is a special SA service process that provides the user program management framework and basic services.
6. The foundation process implements application lifecycle management. It is a special SA service process that provides the user program management framework and basic services.
7. The appspawn process directly spawns the application process, eliminating the need for the application to load the JS runtime environment. This reduces the application startup time.
7. The appspawn process directly spawns the application process, eliminating the need for the application to load the JS runtime environment. This reduces the application startup time.
2. init module
2. init module
...
@@ -158,7 +150,7 @@ Now start build, and check whether the kernel image is generated as expected.
...
@@ -158,7 +150,7 @@ Now start build, and check whether the kernel image is generated as expected.
When porting a new chip platform, you need to add the **/vendor/etc/init/init.{hardware}.cfg** file that contains the platform-level initialization configuration. This file is used to implement platform-level initialization, for example, installing the ko driver and configuring information on the related **/proc** nodes.
When porting a new chip platform, you need to add the **/vendor/etc/init/init.{hardware}.cfg** file that contains the platform-level initialization configuration. This file is used to implement platform-level initialization, for example, installing the ko driver and configuring information on the related **/proc** nodes.
The code of the init process is stored in the **//base/startup/init** directory. This process is the first process in the system and does not depend on other processes.
The code of the init process is stored in the **//base/startup/init_lite** directory. This process is the first process in the system and does not depend on other processes.
For details about how to develop the initialization configuration file, see [Startup](../subsystems/subsys-boot-overview.md).
For details about how to develop the initialization configuration file, see [Startup](../subsystems/subsys-boot-overview.md).
...
@@ -170,180 +162,184 @@ Now start build, and check whether the kernel image is generated as expected.
...
@@ -170,180 +162,184 @@ Now start build, and check whether the kernel image is generated as expected.
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.
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.
The LCD drivers are stored in the **//drivers/framework/model/display/driver/panel** directory.
The LCD drivers are stored in the **//drivers/hdf_core/framework/model/display/driver/panel** directory.
- Create a panel driver.
1. Create a panel driver.
In the **Init** method of the driver, call **RegisterPanel** to register the model instance.
In the **Init** method of the driver, call **RegisterPanel** to register the model instance. For example:
```
```
int32_t XXXInit(struct HdfDeviceObject *object)
int32_t XXXInit(struct HdfDeviceObject *object)
{
{
struct PanelData *panel = CreateYourPanel();
struct PanelData *panel = CreateYourPanel();
// Registration
if (RegisterPanel(panel) != HDF_SUCCESS) {
HDF_LOGE("%s: RegisterPanel failed", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
struct HdfDriverEntry g_xxxxDevEntry = {
// Registration
.moduleVersion = 1,
if (RegisterPanel(panel) != HDF_SUCCESS) {
.moduleName = "LCD_XXXX",
HDF_LOGE("%s: RegisterPanel failed", __func__);
.Init = XXXInit,
return HDF_FAILURE;
};
}
return HDF_SUCCESS;
}
HDF_INIT(g_xxxxDevEntry);
struct HdfDriverEntry g_xxxxDevEntry = {
```
.moduleVersion = 1,
.moduleName = "LCD_XXXX",
.Init = XXXInit,
};
- 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.
HDF_INIT(g_xxxxDevEntry);
```
2. 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**.
```
root {
Note: The value of **moduleName** must be the same as that in the panel driver.
...
display :: host {
device_lcd :: device {
deviceN :: deviceNode {
policy = 0;
priority = 100;
preload = 2;
moduleName = "LCD_XXXX";
}
}
}
}
```
For details about driver development, see [LCD](../driver/driver-peripherals-lcd-des.md).
```
root {
...
display :: host {
device_lcd :: device {
deviceN :: deviceNode {
policy = 0;
priority = 100;
preload = 2;
moduleName = "LCD_XXXX";
}
}
}
}
```
For details about driver development, see [LCD](../driver/driver-peripherals-lcd-des.md).
### Touchscreen
### Touchscreen
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.
This section describes how to port a touchscreen driver. The touchscreen driver is stored in the **//drivers/hdf_core/framework/model/input/driver/touchscreen** directory. To port a touchscreen driver, register a **ChipDevice** model instance.
- Create a touchscreen driver.
1. Create a touchscreen driver.
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:
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:
Implement the following interfaces in **ChipDevice**:
| API| Description|
| API| Description|
| -------- | -------- |
| -------- | -------- |
| int32_t (\*Init)(ChipDevice \*device) | Initializes a touchscreen.|
| int32_t (\*Init)(ChipDevice \*device) | Initializes a touchscreen.|
| int32_t (\*Detect)(ChipDevice \*device) | Detects a touchscreen.|
| int32_t (\*Detect)(ChipDevice \*device) | Detects a touchscreen.|
| int32_t (\*Suspend)(ChipDevice \*device) | Suspends a touchscreen.|
| int32_t (\*Suspend)(ChipDevice \*device) | Suspends a touchscreen.|
| int32_t (\*Resume)(ChipDevice \*device) | Resumes a touchscreen.|
| int32_t (\*Resume)(ChipDevice \*device) | Resumes a touchscreen.|
| int32_t (\*DataHandle)(ChipDevice \*device) | Reads data from a touchscreen and writes the touch point data to **device** > **driver** > **frameData**.|
| int32_t (\*DataHandle)(ChipDevice \*device) | Reads data from a touchscreen and writes the touch point data to **device** > **driver** > **frameData**.|
| int32_t (\*UpdateFirmware)(ChipDevice \*device) | Upgrades the firmware.|
| int32_t (\*UpdateFirmware)(ChipDevice \*device) | Upgrades the firmware.|
- Configure the product and load the driver.
2. 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.
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.
```
deviceN :: deviceNode {
```
policy = 0;
deviceN :: deviceNode {
priority = 130;
policy = 0;
preload = 0;
priority = 130;
permission = 0660;
preload = 0;
moduleName = "HDF_TOUCH_XXXX";
permission = 0660;
deviceMatchAttr = "touch_XXXX_configs";
moduleName = "HDF_TOUCH_XXXX";
}
deviceMatchAttr = "touch_XXXX_configs";
```
}
```
For details about driver development, see [Touchscreen](../driver/driver-peripherals-touch-des.md).
For details about driver development, see [Touchscreen](../driver/driver-peripherals-touch-des.md).
### WLAN
### WLAN
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.
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
**Figure 1** 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**.
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**.
| API| Header File| Description|
| API| Header File| Description|
| -------- | -------- | -------- |
| -------- | -------- | -------- |
| HdfChipDriverFactory | //drivers/framework/include/wifi/hdf_wlan_chipdriver_manager.h | Supports multiple WLAN interfaces of a chip.|
| HdfChipDriverFactory | //drivers/hdf_core/framework/include/wifi/hdf_wlan_chipdriver_manager.h | Supports multiple WLAN interfaces of a chip.|
| HdfChipDriver | //drivers/framework/include/wifi/wifi_module.h | Manages a specific WLAN interface. Each WLAN interface corresponds to an **HdfChipDriver**.|
| HdfChipDriver | //drivers/hdf_core/framework/include/wifi/wifi_module.h | Manages a specific WLAN interface. Each WLAN interface corresponds to an **HdfChipDriver**.|
| NetDeviceInterFace | //drivers/framework/include/net/net_device.h | Communicates with the protocol stack, such as sending data and setting the status of network interfaces.|
| NetDeviceInterFace | //drivers/hdf_core/framework/include/net/net_device.h | Communicates with the protocol stack, such as sending data and setting the status of network interfaces.|
To port a WLAN driver, perform the following steps:
To port a WLAN driver, perform the following steps:
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:
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:
if (driverMgr->RegChipDriver(&factory) != HDF_SUCCESS) {
if (driverMgr->RegChipDriver(&factory) != HDF_SUCCESS) {
HDF_LOGE("%s fail: driverMgr is NULL!", __func__);
HDF_LOGE("%s fail: driverMgr is NULL!", __func__);
return HDF_FAILURE;
return HDF_FAILURE;
}
}
return HDF_SUCCESS;
return HDF_SUCCESS;
}
}
struct HdfDriverEntry g_hdfXXXChipEntry = {
struct HdfDriverEntry g_hdfXXXChipEntry = {
.moduleVersion = 1,
.moduleVersion = 1,
.Init = HdfWlanXXXChipDriverInit,
.Init = HdfWlanXXXChipDriverInit,
.Release = HdfWlanXXXChipRelease,
.Release = HdfWlanXXXChipRelease,
.moduleName = "HDF_WIFI_CHIP_XXX"
.moduleName = "HDF_WIFI_CHIP_XXX"
};
};
HDF_INIT(g_hdfXXXChipEntry);
HDF_INIT(g_hdfXXXChipEntry);
```
```
Create an **HdfChipDriverFactory** in the **CreateChipDriverFactory**. The APIs are as follows:
Create an **HdfChipDriverFactory** in the **CreateChipDriverFactory**. The APIs are as follows:
| API| Description|
| -------- | -------- |
| const char \*driverName | Indicates the driver name.|
| int32_t (\*InitChip)(struct HdfWlanDevice \*device) | Initializes a chip.|
| int32_t (\*DeinitChip)(struct HdfWlanDevice \*device) | Deinitializes a chip.|
| void (*ReleaseFactory)(struct HdfChipDriverFactory *factory) | Releases the **HdfChipDriverFactory** object.|
| struct HdfChipDriver *(_Build)(struct HdfWlanDevice \*device, uint8*t ifIndex) | Creates an **HdfChipDriver**. In the input parameters, **device** indicates the device information, and **ifIndex** indicates the sequence number of this interface in the chip.|
| void (*Release)(struct HdfChipDriver *chipDriver) | Releases the **HdfChipDriver**.|
| uint8_t (\*GetMaxIFCount)(struct HdfChipDriverFactory \*factory) | Obtains the maximum number of APIs supported by the current chip.|
Implement the following APIs in the **HdfChipDriver**.
| API| Description|
| API| Description|
| -------- | -------- |
| -------- | -------- |
| int32_t (\*init)(struct HdfChipDriver \*chipDriver, NetDevice \*netDev) | Initializes the current network interface. The **NetDeviceInterFace** needs to be provided for the **netDev**.|
| const char \*driverName | Indicates the driver name.|
| int32_t (\*deinit)(struct HdfChipDriver \*chipDriver, NetDevice \*netDev) | Deinitializes the current network interface.|
| int32_t (\*InitChip)(struct HdfWlanDevice \*device) | Initializes a chip.|
| struct HdfMac80211BaseOps \*ops | Provides the WLAN basic capability interface set.|
| int32_t (\*DeinitChip)(struct HdfWlanDevice \*device) | Deinitializes a chip.|
| struct HdfMac80211STAOps \*staOps | Provides the interface set required for supporting the standalone (STA) mode.|
| void (_ReleaseFactory)(struct HdfChipDriverFactory _factory) | Releases the **HdfChipDriverFactory** object.|
| struct HdfMac80211APOps \*apOps | Provides the interface set required for supporting the access point (AP) mode.|
| struct HdfChipDriver _(_Build)(struct HdfWlanDevice \*device, uint8_t ifIndex) | Creates an **HdfChipDriver**. In the input parameters, **device** indicates the device information, and **ifIndex** indicates the sequence number of this interface in the chip.|
| void (_Release)(struct HdfChipDriver _chipDriver) | Releases the **HdfChipDriver**.|
| uint8_t (\*GetMaxIFCount)(struct HdfChipDriverFactory \*factory) | Obtains the maximum number of APIs supported by the current chip.|
Implement the following APIs in the **HdfChipDriver**.
| API| Description|
| -------- | -------- |
| int32_t (\*init)(struct HdfChipDriver \*chipDriver, NetDevice \*netDev) | Initializes the current network interface. The **NetDeviceInterFace** needs to be provided for the **netDev**.|
| int32_t (\*deinit)(struct HdfChipDriver \*chipDriver, NetDevice \*netDev) | Deinitializes the current network interface.|
| struct HdfMac80211STAOps \*staOps | Provides the interface set required for supporting the standalone (STA) mode.|
| struct HdfMac80211APOps \*apOps | Provides the interface set required for supporting the access point (AP) mode.|
2. Compile the configuration file to describe the devices supported by the driver.
2. Compile the configuration file to describe the devices supported by the driver.
...
@@ -353,65 +349,68 @@ Implement the following APIs in the **HdfChipDriver**.
...
@@ -353,65 +349,68 @@ Implement the following APIs in the **HdfChipDriver**.
The sample code is as follows:
The sample code is as follows:
```
```
root {
root {
wlan_config {
wlan_config {
chip_name :& chipList {
chip_name :& chipList {
chip_name :: chipInst {
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.*/
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.*/
driverName = "driverName"; /* The value must be the same as that of driverName in HdfChipDriverFactory.*/
sdio {
sdio {
vendorId = 0x0296;
vendorId = 0x0296;
deviceId = [0x5347];
deviceId = [0x5347];
}
}
}
}
}
}
}
}
}
}
```
```
3. Edit the configuration file and load the driver.
3. Edit the configuration file 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_wlan_chips** to the host named **network**. Note: The value of **moduleName** must be the same as that in the touchscreen 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_wlan_chips** to the host named **network**.
Note: The value of **moduleName** must be the same as that in the touchscreen driver.
```
```
deviceN :: deviceNode {
deviceN :: deviceNode {
policy = 0;
policy = 0;
preload = 2;
preload = 2;
moduleName = "HDF_WLAN_CHIPS";
moduleName = "HDF_WLAN_CHIPS";
deviceMatchAttr = "hdf_wlan_chips_chip_name";
deviceMatchAttr = "hdf_wlan_chips_chip_name";
serviceName = "driverName";
serviceName = "driverName";
}
}
```
```
4. Build the driver.
4. Build the driver.
- Create a kernel configuration menu. Create a **Kconfig** file in the **//device/MySoCVendor/peripheral** directory. The file template is as follows:
- Create a kernel configuration menu. Create a **Kconfig** file in the **//device/MySoCVendor/peripheral** directory. The file template is as follows:
```
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
```
```
Add the following configuration to the end of the **//drivers/hdf_core/adapter/khdf/linux/model/network/wifi/Kconfig** file:
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
```
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:
When **DRIVERS_WLAN_XXX** is enabled in the kernel, **makefile** in **//device/MySoCVendor/peripheral/build/standard/** is called. For details about the development, see [LED Peripheral Control](../guide/device-wlan-led-control.md).
When **DRIVERS_WLAN_XXX** is enabled in the kernel, **makefile** in **//device/MySoCVendor/peripheral/build/standard/** is called. For details about the development, see [LED Peripheral Control](../guide/device-wlan-led-control.md).