Starlight plan 2.0 Linux kernel adds HDF driver subsystem

Harmonyos technology community 2022-01-26 15:53:54 阅读数:822

starlight plan linux kernel adds

 【 This article is participating in 51CTO HarmonyOS Technology community creator incentive program - Project starlight 2.0】

Preface

HDF The drive subsystem is OpenHarmony One of the important features , Its main function is to implement the driver in the multi-core and multi platform Internet of things environment , Realize one-time drive development , Multi terminal deployment . Before transplantation OHOS3.0 Using the traditional linux drive , Regretful , Today, try to HDF The driver subsystem is added to the compilation framework . Know a few nouns before you start .

HCS(HDF Configuration Source) yes HDF Driver framework configuration description source code ,JSON Storage .

HC-GEN(HDF Configuration Generator) yes HCS Configure the conversion tool , Can be HDF The configuration file HCS Convert to binary HCB

HCB(HDF Configuration Binary) Binary , The driver can use HDF The configuration resolution interface provided by the framework obtains the configuration .

Kernel patching

How to add... To the kernel HDF drive ,linux The following two directories are mainly implemented under the kernel :

drivers\adapter\khdf\linux and drivers\framework

These two directories are added to the kernel compilation through links , The process is as follows

kernel\linux\build\kernel.mk:75

$(hide) cd $(KERNEL_SRC_TMP_PATH) && patch -p1 < $(HDF_PATCH_FILE) && patch -p1 < $(DEVICE_PATCH_FILE)

You can refer to 3516 Of HDF Patch :kernel\linux\patches\linux-5.10\hi3516dv300_patch\hdf.patch

patching file drivers/Kconfig
patching file drivers/Makefile
patching file drivers/hdf/Makefile
patching symbolic link drivers/hdf/framework
patching symbolic link drivers/hdf/khdf
patching symbolic link include/hdf
# Add to linux Patches to the kernel 
drivers/hdf/framework -> /drivers/framework/ # Drive subsystem drive framework 、 Configuration Management 、 Configuration analysis 、 Drive the generic framework model 、 Hardware general platform capability interface, etc 
drivers/hdf/khdf -> /drivers/adapter/khdf/linux/ # stay linux Deploy in the kernel OpenHarmony Drive frame 
drivers/hdf/Makefile # from hdf.patch Provide 
include/hdf -> /drivers/framework/include/ # The header file that drives the framework to provide external capabilities 

Kernel configuration

Just patching is not enough , You have to add... To the compiled configuration file of the kernel HDF Options . The first thing to do is to refer to 3516 Configuration selection for , However, some configurations are found to cause compilation failure . The test found that the following configuration can be compiled successfully .

[*] Enable HDF manager
(2) Set HDF support platform
[*] Enable HDF platform driver
[*] Enable HDF platform mipi dsi driver
[*] Enable HDF platform gpio driver
[*] Enable HDF platform i2c driver
[*] Enable HDF platform watchdog driver
[*] hi35xx pwm driver
[*] Enable HDF platform pwm driver
[*] Enable HDF platform uart driver
[ ] Enable HDF platform sdio driver
[ ] Enable HDF platform emmc driver
[*] Enable HDF platform mmc driver
[*] Enable HDF platform spi driver
[*] Enable HDF platform rtc driver
[*] Enable HDF linux test
[*] Enable HDF Display driver
[ ] Enable HDF Lcdkit driver
[*] Enable HDF Icn9700 driver
[ ] Enable HDF St7789 driver
[*] Enable HDF input driver
[*] Enable HDF tp 5P5 GT911 driver
[*] Enable HDF tp 2P35 FT6236 driver
[ ] Enable HDF wifi
[ ] Enable HDF Bluetooth
[*] Enable HDF sensor driver
[ ] Enable HDF accel sensor driver
[ ] Enable HDF gyro sensor driver
[ ] Enable HDF barometer sensor driver
[ ] Enable HDF hall sensor driver
[*] Enable HDF storage driver
[ ] Enable HDF USB PNP Notify driver
[ ] Enable F_GENERIC driver
[ ] Enable HDF Audio driver
[*] Enable HDF vibrator driver
[*] Enable HDF linear vibrator driver
[ ] Enable HDF dsoftbus driver
CONFIG_DRIVERS_HDF=y
CONFIG_HDF_SUPPORT_LEVEL=2
CONFIG_DRIVERS_HDF_PLATFORM=y
CONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
CONFIG_DRIVERS_HDF_PLATFORM_GPIO=y
CONFIG_DRIVERS_HDF_PLATFORM_I2C=y
CONFIG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
CONFIG_PWM_HI35XX=y
CONFIG_DRIVERS_HDF_PLATFORM_PWM=y
CONFIG_DRIVERS_HDF_PLATFORM_UART=y
# CONFIG_DRIVERS_HDF_PLATFORM_SDIO is not set
# CONFIG_DRIVERS_HDF_PLATFORM_EMMC is not set
CONFIG_DRIVERS_HDF_PLATFORM_MMC=y
CONFIG_DRIVERS_HDF_PLATFORM_SPI=y
CONFIG_DRIVERS_HDF_PLATFORM_RTC=y
CONFIG_DRIVERS_HDF_TEST=y
CONFIG_DRIVERS_HDF_DISP=y
# CONFIG_DRIVERS_HDF_LCDKIT is not set
CONFIG_DRIVERS_HDF_LCD_ICN9700=y
# CONFIG_DRIVERS_HDF_LCD_ST7789 is not set
CONFIG_DRIVERS_HDF_INPUT=y
CONFIG_DRIVERS_HDF_TP_5P5_GT911=y
CONFIG_DRIVERS_HDF_TP_2P35_FT6236=y
# CONFIG_DRIVERS_HDF_WIFI is not set
# CONFIG_DRIVERS_HDF_BT is not set
CONFIG_DRIVERS_HDF_SENSOR=y
# CONFIG_DRIVERS_HDF_SENSOR_ACCEL is not set
# CONFIG_DRIVERS_HDF_SENSOR_GYRO is not set
# CONFIG_DRIVERS_HDF_SENSOR_BAROMETER is not set
# CONFIG_DRIVERS_HDF_SENSOR_HALL is not set
CONFIG_DRIVERS_HDF_STORAGE=y
# CONFIG_DRIVERS_HDF_USB_PNP_NOTIFY is not set
# CONFIG_DRIVERS_HDF_USB_F_GENERIC is not set
# CONFIG_DRIVERS_HDF_AUDIO is not set
CONFIG_DRIVERS_HDF_VIBRATOR=y
CONFIG_DRIVERS_HDF_VIBRATOR_LINEAR=y
# CONFIG_DRIVERS_HDF_DSOFTBUS is not set
# end of Device Drivers

[*] Enable HDF linux test It needs to be set up , If not set CONFIG_DRIVERS_HDF_TEST, There is something wrong with the directory structure , Would report such a mistake .

drivers/hdf/khdf/Makefile:22: PRODUCT_PATH=vendor/raspberrypi/RPI4B
scripts/Makefile.build:44: drivers/hdf/khdf/../../../../vendor/raspberrypi/RPI4B/hdf_config/Makefile: No such file or directory
make[5]: *** No rule to make target 'drivers/hdf/khdf/../../../../vendor/raspberrypi/RPI4B/hdf_config/Makefile'. Stop.
CC [M] drivers/net/wireless/mac80211_hwsim.o
make[4]: *** [scripts/Makefile.build:497: drivers/hdf/khdf/../../../../vendor/raspberrypi/RPI4B/hdf_config] Error 2
make[3]: *** [scripts/Makefile.build:497: drivers/hdf/khdf] Error 2
make[2]: *** [scripts/Makefile.build:497: drivers/hdf] Error 2
make[2]: *** Waiting for unfinished jobs....

below 3 There are options to turn off , Otherwise, the following mistakes will be reported .

[ ] Enable HDF platform sdio driver
[ ] Enable HDF platform emmc driver
[ ] Enable HDF wifi

drivers/../../../../../../drivers/adapter/khdf/linux/platform/sdio/sdio_adapter.o: In function `Hi35xxLinuxSdioRescan': sdio_adapter.c:(.text+0x20): undefined reference to `hisi_sdio_rescan' sdio_adapter.c:(.text+0x34): undefined reference to `himci_get_mmc_host'
drivers/../../../../../../drivers/adapter/khdf/linux/platform/sdio/sdio_adapter.o: In function `Hi35xxLinuxSdioFindFunc': sdio_adapter.c:(.text+0xc84): undefined reference to `himci_get_mmc_host' sdio_adapter.c:(.text+0xc9c): undefined reference to `himci_get_mmc_host'
sdio_adapter.c:(.text+0xcb4): undefined reference to `himci_get_mmc_host' drivers/../../../../../../drivers/adapter/khdf/linux/platform/emmc/emmc_adapter.o: In function `Hi35xxLinuxEmmcBind': emmc_adapter.c:(.text+0x214): undefined reference to `himci_get_mmc_host'
drivers/../../../../../../device/hisilicon/drivers/wifi/driver/hi3881/oal/oal_sdio_host.o: In function `sdio_card_detect_change': oal_sdio_host.c:(.text+0x2ce8): undefined reference to `hisi_sdio_rescan' make[1]: *** [Makefile:1179: vmlinux] Error 1 make[1]: Leaving directory '/home/liangzili/ohos/out/KERNEL_OBJ/kernel/src_tmp/linux-5.10'
make: *** [kernel.mk:80: /home/liangzili/ohos/out/KERNEL_OBJ/kernel/src_tmp/linux-5.10/arch/arm/boot/zImage] Error 2
ninja: build stopped: subcommand failed.

The build process

For the convenience of testing, you can compile the kernel separately , For example, my compilation command is like this .

./build.sh --product-name RPI4B --ccache --build-target raspberrypi_products

You can analyze HDF This part of the compilation process .

linux-5.10\drivers\hdf\Makefile,hdf.patch Will add this Makefile, take khdf Add folder to compile .

obj-$(CONFIG_DRIVERS_HDF) += khdf/

linux-5.10\drivers\hdf\khdf\Makefile

export HDF_ROOT := drivers/hdf
obj-$(CONFIG_DRIVERS_HDF) += osal/
obj-$(CONFIG_DRIVERS_HDF) += network/
obj-$(CONFIG_DRIVERS_HDF) += config/
SUPPORT_LEVEL_STD_H := $(shell [ "$(CONFIG_HDF_SUPPORT_LEVEL)" -ge 2 ] && echo true)
$(warning PRODUCT_PATH=$(PRODUCT_PATH)) # Will check the PRODUCT_PATH Variable
ifeq ($(PRODUCT_PATH),)
$(error PRODUCT_PATH not)
endif
# Here's a note indicating *.hcs The storage path of the configuration file
# for L2+, hcs config should in vendor/product_company/product_name/config/khdf
ifeq ($(SUPPORT_LEVEL_STD_H), true)
SUB_DIR:=khdf/
endif
# HDF test Your configuration will make hcs The directory structure is different , I didn't set up CONFIG_DRIVERS_HDF_TEST Just fall into this pit .
ifeq ($(CONFIG_DRIVERS_HDF), y)
ifeq ($(CONFIG_DRIVERS_HDF_TEST), y)
obj-$(CONFIG_DRIVERS_HDF) += ../../../../$(PRODUCT_PATH)/hdf_config/$(SUB_DIR)/hdf_test/
obj-$(CONFIG_DRIVERS_HDF) += test/
else
obj-$(CONFIG_DRIVERS_HDF) += ../../../../$(PRODUCT_PATH)/hdf_config/$(SUB_DIR)
endif
endif
# ... Then add some compilation directories according to the configuration ...

drivers\adapter\khdf\linux\Makefile: Would call obj-$(CONFIG_DRIVERS_HDF) += ../../../../$(PRODUCT_PATH)/hdf_config/$(SUB_DIR)/hdf_test/ This is a OHOS3.0 default HCS File storage path . Official notes also say , Therefore, the corresponding equipment *.hcs Store in vendor\raspberrypi\RPI4B\hdf_config\khdf Folder , Reference resources 3516 Of vendor\hisilicon\Hi3516DV300\hdf_config\khdf\hdf.hcs That's it .

#include "device_info/device_info.hcs"
#include "platform/i2c_config.hcs"
#include "platform/hi35xx_watchdog_config.hcs"
#include "platform/hi35xx_pwm_config.hcs"
#include "platform/hi35xx_uart_config.hcs"
#include "platform/sdio_config.hcs"
#include "platform/emmc_config.hcs"
#include "platform/hi35xx_spi_config.hcs"
#include "input/input_config.hcs"
#include "wifi/wlan_platform.hcs"
#include "wifi/wlan_chip_hi3881.hcs"
#include "sensor/sensor_config.hcs"
#include "audio/audio_config.hcs"
#include "audio/codec_config.hcs"
#include "audio/dai_config.hcs"
#include "audio/dma_config.hcs"
#include "audio/dsp_config.hcs"
#include "vibrator/vibrator_config.hcs"
#include "vibrator/linear_vibrator_config.hcs"
#include "lcd/lcd_config.hcs"
root {
module = "hisilicon,hi35xx_chip";
}

Reference resources 3516 Of vendor\hisilicon\Hi3516DV300\hdf_config\khdf\Makefile

among :PRODUCT_PATH Source of environment variables :kernel/linux/build/kernel_module_build.sh:42:export PRODUCT_PATH=$4

ifeq ($(LOCAL_HCS_ROOT),)
LOCAL_HCS_ROOT := $(PRODUCT_PATH)
endif
SOURCE_ROOT:=$(abspath ../../../../../)
HC_GEN_DIR := $(abspath $(SOURCE_ROOT)/drivers/framework/tools/hc-gen)
HC_GEN := $(HC_GEN_DIR)/build/hc-gen
LOCAL_HCS_ROOT := $(abspath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
HCS_DIR := $(LOCAL_HCS_ROOT)
ifneq ($(TARGET_BOARD_PLATFORM),)
HCS_DIR := $(LOCAL_HCS_ROOT)/$(TARGET_BOARD_PLATFORM)
else
ifneq ($(CONFIG_ARCH_HI3516DV300),)
HCS_DIR := $(LOCAL_HCS_ROOT)
endif
ifneq ($(CONFIG_ARCH_HI3518EV300),)
HCS_DIR := $(LOCAL_HCS_ROOT)
endif
endif
$(info HCS_DIR = $(HCS_DIR))
HCB_FLAGS := -b -i -a
HCS_OBJ := hdf_hcs_hex.o
HCS_OBJ_SRC := $(subst .o,.c,$(notdir $(HCS_OBJ)))
CONFIG_GEN_HEX_SRC := $(addprefix $(LOCAL_HCS_ROOT)/, $(HCS_OBJ_SRC))
CONFIG_HCS_SRC := $(subst _hcs_hex.o,.hcs,$(addprefix $(HCS_DIR)/, $(HCS_OBJ)))
$(obj)/$(HCS_OBJ): $(CONFIG_GEN_HEX_SRC)
$(Q)$(CC) $(c_flags) -c -o [email protected] $<
$(Q)rm -f $<
$(CONFIG_GEN_HEX_SRC): $(LOCAL_HCS_ROOT)/%_hcs_hex.c: $(HCS_DIR)/%.hcs | $(HC_GEN)
$(Q)echo gen hdf built-in config
$(Q)if [ ! -d $(dir [email protected]) ]; then mkdir -p $(dir [email protected]); fi
$(Q)$(HC_GEN) $(HCB_FLAGS) -o $(subst _hex.c,,$(@)) $<
$(CONFIG_GEN_SRCS): $(CONFIG_OUT_DIR)%.c: $(HCS_DIR)/%.hcs | $(HC_GEN)
$(Q)echo gen hdf driver config
$(Q)if [ ! -d $(dir [email protected]) ]; then mkdir -p $(dir [email protected]); fi
$(Q)$(HC_GEN) -t -o [email protected] $<
$(HC_GEN):
$(HIDE)make -C $(HC_GEN_DIR)
obj-$(CONFIG_DRIVERS_HDF) += $(HCS_OBJ)

View results

After compilation , You can upload the kernel image to the development board , Check it out. HDF Whether the driver framework starts successfully .

Join in HDF front

# ls dev/
__parameters__ hwrng tty1 tty28 tty46 tty7
__trigger__ input tty10 tty29 tty47 tty8
autofs kmsg tty11 tty3 tty48 tty9
binder linux,cma tty12 tty30 tty49 ttyAMA0
block loop-control tty13 tty31 tty5 ttyS0
bus mem tty14 tty32 tty50 ttyprintk
cachefiles memcg tty15 tty33 tty51 unix
char null tty16 tty34 tty52 urandom
console port tty17 tty35 tty53 vchiq
cpuctl ptmx tty18 tty36 tty54 vcs
cpuset pts tty19 tty37 tty55 vcs1
dri random tty2 tty38 tty56 vcsa
fd rawctl tty20 tty39 tty57 vcsa1
freezer snd tty21 tty4 tty58 vcsu
fscklogs stderr tty22 tty40 tty59 vcsu1
full stdin tty23 tty41 tty6 vga_arbiter
gpiochip0 stdout tty24 tty42 tty60 vndbinder
gpiochip1 system tty25 tty43 tty61 watchdog
graphics tty tty26 tty44 tty62 watchdog0
hwbinder tty0 tty27 tty45 tty63 zero

Join in HDF after

# ls dev/
HDF_PLATFORM_I2C_MANAGER loop-control tty24 tty54
HDF_PLATFORM_UART_1 mem tty25 tty55
HDF_TEST memcg tty26 tty56
I2C_TEST null tty27 tty57
__parameters__ port tty28 tty58
__trigger__ ptmx tty29 tty59
autofs pts tty3 tty6
binder random tty30 tty60
block rawctl tty31 tty61
bus sample_service tty32 tty62
cachefiles snd tty33 tty63
char stderr tty34 tty7
console stdin tty35 tty8
cpuctl stdout tty36 tty9
cpuset system tty37 ttyAMA0
dev_mgr tty tty38 ttyS0
dri tty0 tty39 ttyprintk
fd tty1 tty4 unix
freezer tty10 tty40 urandom
fscklogs tty11 tty41 vchiq
full tty12 tty42 vcs
gpiochip0 tty13 tty43 vcs1
gpiochip1 tty14 tty44 vcsa
graphics tty15 tty45 vcsa1
hdf_bl tty16 tty46 vcsu
hdf_input_host tty17 tty47 vcsu1
hdf_misc_vibrator tty18 tty48 vga_arbiter
hdf_sensor_manager_ap tty19 tty49 vndbinder
hwbinder tty2 tty5 watchdog
hwrng tty20 tty50 watchdog0
input tty21 tty51 zero
kmsg tty22 tty52
linux,cma tty23 tty53

It's basically started successfully , Next, consider using HDF Add a device in a new way . To verify HDF Whether the drive frame works normally .

  Want to know more about Hongmeng , Please visit :

 51CTO Hongmeng technology community jointly built with Huawei officials

 https://harmonyos.51cto.com/#bkwz

::: hljs-center

21_9.jpg

:::

copyright:author[Harmonyos technology community],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/01/202201261553513879.html