1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
验证hb set
配置是否正确,输入hb set
能够显示如下图片表示配置正确。
执行hb set
输入项目根目录,并且回车,hb
命令会遍历所有//vendor//
目录下的config.json
,给出可选产品编译选项,config.json
的product_name
用于显示产品名,device_company
和board
用于关联出//device/board//
目录,并且匹配/config.gni
文件,如果能够匹配多个文件,表示该单板适配了多个内核,那么可以根据config.json
的kernel_type
和kernel_version
来唯一匹配config.gni
的kernel_type
和kernel_version
,即可确定了需要编译适配了哪个内核的单板。
选择好产品后,输入回车就会在根目录下自动生成ohos_config.json文件,这里会将要编译的产品信息列出。通过hb env
也可以查看选择出来的预编译环境变量。
内核移植
内核移植需要完成LiteOS-A Kconfig
适配、gn
的编译构建和内核启动最小适配。
详细移植步骤参考:LiteOS -A内核移植
Kconfig适配
在//device/board/bearpi/bearpi_hm_micro/liteos_a/drivers/Kconfig中添加芯片、产品名称、厂商名称相关配置。
source "../../device/soc/st/common/platform/Kconfig"
config PLATFORM
string
default "stm32mp157" if PLATFORM_STM32MP157
config PRODUCT_NAME
string "product name"
default "bearpi_hm_micro" if PRODUCT_BEARPI_HM_MICRO
config DEVICE_COMPANY
string "vendor name"
default "st" if PLATFORM_STM32MP157
config TEE_ENABLE
bool "Enable TEE"
default n
depends on PLATFORM_STM32MP157
help
Enable teeos in platform
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
class="hide-preCode-box">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
在//device/soc/st/common/platform/Kconfig中添加驱动相关配置。
config DRIVERS_MMC
depends on DRIVERS
bool "Enable MMC"
default y
depends on DRIVERS && FS_VFS
help
Answer Y to enable LiteOS support MMC driver.
config DRIVERS_EMMC
depends on DRIVERS_MMC && PLATFORM_STM32MP157
bool "Enable MMC0 support eMMC type"
config DRIVERS_HI3881
bool "Enable Hi3881 Host driver"
default n
depends on DRIVERS_HDF_WIFI
help
Answer Y to enable Hi3881 Host driver.
config HW_RANDOM_ENABLE
depends on DRIVERS_RANDOM
bool "Select hw random"
default y
help
Answer Y to select hw random.
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
class="hide-preCode-box">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
在//vendor/bearpi/bearpi_hm_micro/kernel_configs/debug_tee.config中使能相关配置。
...
LOSCFG_PLATFORM="stm32mp157"
LOSCFG_PRODUCT_NAME="bearpi_hm_micro"
LOSCFG_DEVICE_COMPANY="st"
# LOSCFG_PLATFORM_HI3516DV300 is not set
# LOSCFG_PLATFORM_HI3518EV300 is not set
# LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7 is not set
LOSCFG_PLATFORM_STM32MP157=y
LOSCFG_PRODUCT_BEARPI_HM_MICRO=y
LOSCFG_BOARD_CONFIG_PATH="device/board/bearpi/bearpi_hm_micro/liteos_a/board"
LOSCFG_TEE_ENABLE=y
...
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
gn编译适配
在//device/board/bearpi/bearpi_hm_micro/liteos_a中新建BUILD.gn,添加代码如下,此模块依赖board、drivers、hdf_config。
cmd = "if [ -f $product_path/hdf_config/BUILD.gn ]; then echo true; else echo false; fi"
HAVE_PRODUCT_CONFIG =
exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
group("liteos_a") {
deps = [
"board",
"drivers",
]
if (HAVE_PRODUCT_CONFIG) {
deps += [ "$product_path/hdf_config" ]
} else {
deps += [ "hdf_config" ]
}
}
config("public") {
configs = [
"board:public",
"drivers:public",
]
}
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
class="hide-preCode-box">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
在//device/board/bearpi/bearpi_hm_micro/liteos_a/board中新建BUILD.gn,添加代码如下。将os_adapt.c内核启动相关代码编译进系统。
import("//kernel/liteos_a/liteos.gni")
module_name = "bsp_config"
kernel_module(module_name) {
sources = []
if (defined(LOSCFG_PLATFORM_ADAPT)) {
sources += [ "os_adapt/os_adapt.c" ]
}
}
config("public") {
include_dirs = [ "." ]
include_dirs += [ "include" ]
include_dirs += [ "$LITEOSTOPDIR/drivers/block/disk/include" ]
include_dirs +=
[ "$LITEOSTOPDIR/../../drivers/adapter/khdf/liteos/osal/include" ]
}
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
class="hide-preCode-box">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
在//device/board/bearpi/bearpi_hm_micro/liteos_a/drivers中新建BUILD.gn,添加代码如下,将device/soc/st/common/platform路径下的HDF驱动编译进系统。
import("//drivers/adapter/khdf/liteos/hdf.gni")
group("drivers") {
public_deps = [ "//device/soc/st/common/platform:drivers" ]
}
config("public") {
configs = [ "//device/soc/st/common/platform:public" ]
}
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
在//vendor/bearpi/bearpi_hm_micro/hdf_config中新建BUILD.gn,添加代码如下,将HCS配置文件编译进系统。
module_switch = defined(LOSCFG_DRIVERS_HDF) && !defined(LOSCFG_DRIVERS_HDF_TEST)
module_name = "libhdf_config"
hdf_driver(module_name) {
hcs_sources = [ "hdf.hcs" ]
}
group("hdf_config") {
public_deps = [ ":$module_name" ]
deps = [
"hdf_test",
"hdf_test/hcs_macro_test",
]
}
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
内核启动适配
在//device/board/bearpi/bearpi_hm_micro/liteos_a/board/os_adapt.c中添加以下内核启动相关代码,详细解释参考 LiteOS-A内核移植 。
...
void SystemInit(void)
{
#ifdef LOSCFG_DRIVERS_RANDOM
dprintf("dev random init ...\n");
Mp1xxRngInit();
#endif
#ifdef LOSCFG_DRIVERS_MEM
dprintf("mem dev init ...\n");
extern int mem_dev_register(void);
mem_dev_register();
#endif
dprintf("Date:%s.\n", __DATE__);
dprintf("Time:%s.\n", __TIME__);
#ifdef LOSCFG_DRIVERS_HDF
dprintf("DeviceManagerStart start ...\n");
if (DeviceManagerStart()) {
PRINT_ERR("No drivers need load by hdf manager!");
}
dprintf("DeviceManagerStart end ...\n");
#endif
net_init();
#ifdef LOSCFG_PLATFORM_ROOTFS
dprintf("OsMountRootfs start ...\n");
if (LOS_GetCmdLine()) {
dprintf("get cmdline error!\n");
}
if (LOS_ParseBootargs()) {
dprintf("parse bootargs error!\n");
}
if (OsMountRootfs()) {
dprintf("mount rootfs error!\n");
}
dprintf("OsMountRootfs end ...\n");
#endif
dprintf("Before PLATFORM_UART ...\n");
#ifdef LOSCFG_DRIVERS_HDF_PLATFORM_UART
if (virtual_serial_init(TTY_DEVICE) != 0) {
PRINT_ERR("virtual_serial_init failed");
}
if (system_console_init(SERIAL) != 0) {
PRINT_ERR("system_console_init failed\n");
}
#endif
dprintf("After PLATFORM_UART ...\n");
if (OsUserInitProcess()) {
PRINT_ERR("Create user init process failed!\n");
return;
}
dprintf("cat log shell end\n");
return;
}
...
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
class="hide-preCode-box">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
板级系统移植
SoC芯片平台HDF驱动移植
驱动适配相关文件放置在device/soc/st/common/platform
中,所有的驱动都是通过HDF
机制加载,本章节以GPIO驱动适配为例进行详细说明。
在//device/soc/st/common/platform/gpio/BUILD.gn
文件中,描述了stm32mp1xx gpio
驱动的编译适配。如下:
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO) --- 如果打开HDF的GPIO配置开关,才进行如下编译。
module_name = get_path_info(rebase_path("."), "name")
hdf_driver("hdf_gpio") {
sources = [ "stm32mp1_gpio.c" ] ---gpio驱动源文件。
include_dirs = [ ---依赖的.h路径。
"." ,
"../stm32mp1xx_hal/STM32MP1xx_HAL_Driver/Inc",
]
}
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
在//device/soc/st/common/platform/gpio/stm32mp1_gpio.c
文件中,描述了stm32mp1xx gpio
驱动的源码适配。 首先,按照OpenHarmony
的HDF
驱动框架加载驱动基本适配框架,如下:
struct HdfDriverEntry g_GpioDriverEntry = {
.moduleVersion = 1,
.moduleName = "HDF_PLATFORM_GPIO",
.Bind = GpioDriverBind,
.Init = GpioDriverInit,
.Release = GpioDriverRelease,
};
HDF_INIT(g_GpioDriverEntry); --- 通过HDF_INIT 加载GPIO驱动。
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
在//device/soc/st/stm32mp1xx/sdk_liteos/hdf_config/gpio中添加gpio硬件描述信息文件gpio_config.hcs,在该文件中添加驱动私有配置信息。
root {
platform {
gpio_config {
controller_0x50002000 {
match_attr = "st_stm32mp1_gpio";
groupNum = 11;
bitNum = 16;
gpioRegBase = 0x50002000;
gpioRegStep = 0x1000;
irqRegBase = 0x5000D000;
irqRegStep = 0x400;
}
}
}
}
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
配置产品加载驱动,产品的所有设备信息被定义在源码文件//vendor/bearpi/bearpi_hm_micro/hdf_config/device_info/device_info.hcs中。
平台驱动请添加到platform的host中。
说明: moduleName要与驱动文件中定义的相同,deviceMatchAttr要与驱动私有配置信息文件gpio_config.hcs中定义match_attr的相同。
root {
...
platform :: host {
device_gpio :: device {
device0 :: deviceNode {
policy = 2;
priority = 10;
permission = 0644;
moduleName = "HDF_PLATFORM_GPIO_MANAGER";
serviceName = "HDF_PLATFORM_GPIO_MANAGER";
}
device1 :: deviceNode {
policy = 0;
priority = 10;
permission = 0644;
moduleName = "HDF_PLATFORM_GPIO";
serviceName = "HDF_PLATFORM_GPIO";
deviceMatchAttr = "st_stm32mp1_gpio";
}
}
}
}
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
class="hide-preCode-box">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
完善驱动代码,gpio_config.hcs的配置信息会在GpioDriverInit中加载。
static int32_t GpioDriverInit(struct HdfDeviceObject *device)
{
int32_t ret;
struct Mp1xxGpioCntlr *stm32gpio = &g_Mp1xxGpioCntlr;
dprintf("%s: Enter", __func__);
if (device == NULL || device->property == NULL) {
HDF_LOGE("%s: device or property NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
//获取属性数据
ret = Mp1xxGpioReadDrs(stm32gpio, device->property);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: get gpio device resource fail:%d", __func__, ret);
return ret;
}
...
}
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
class="hide-preCode-box">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
OpenHarmony子系统适配
OpenHarmony
子系统适配只需要在config.json
中增加对应子系统和部件,这样编译系统会将该部件纳入编译目标中。
启动恢复子系统适配
启动恢复子系统需要适配bootstrap_lite
、syspara_lite
、appspawn_lite
、init
四个部件。请在vendor/bearpi/bearpi_hm_micro/config.json
中新增对应的配置选项。
{
"subsystem": "startup",
"components": [
{ "component": "syspara_lite", "features":[] },
{ "component": "bootstrap_lite", "features":[] },
{ "component": "appspawn_lite", "features":[] },
{ "component": "init", "features":[] }
]
},
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
系统启动时会根据//vendor/bearpi/bearpi_hm_micro/init_configs中的启动配置来启动系统。
DFX子系统适配
进行DFX
子系统适配需要添加hilog_featured_lite
、hidumper_lite
部件,直接在config.json
文件配置即可。
{
"subsystem": "hiviewdfx",
"components": [
{ "component": "hilog_featured_lite", "features":[] },
{ "component": "hidumper_lite", "features":[] }
]
},
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
系统服务管理子系统适配
进行系统服务管理子系统适配需要添加samgr_lite
、safwk_lite
、dmsfwk_lite
三个部件,直接在config.json
配置即可。
{
"subsystem": "distributed_schedule",
"components": [
{ "component": "samgr_lite", "features":[] },
{ "component": "safwk_lite", "features":[] },
{ "component": "dmsfwk_lite", "features":[] }
]
},
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
安全子系统适配
进行安全子系统适配需要添加permission_lite
、appverify
、device_auth
、huks
四个部件,直接在config.json
配置即可。
{
"subsystem": "security",
"components": [
{ "component": "permission_lite", "features":[] },
{ "component": "appverify", "features":[] },
{ "component": "device_auth", "features":[] },
{ "component": "huks", "features":
[
"huks_config_file = \"hks_config_small.h\""
]
}
]
},
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
公共基础库子系统适配
进行公共基础库子系统适配需要添加kv_store
、os_dump
两个部件,直接在config.json
配置即可。
{
"subsystem": "utils",
"components": [
{ "component": "kv_store", "features":[] },
{ "component": "os_dump", "features":[] }
]
},
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
图形子系统适配
进行图形子系统适配需要添加graphic_utils
部件,直接在config.json
配置即可。
{
"subsystem": "graphic",
"components": [
{ "component": "graphic_utils",
"features": [ "enable_ohos_graphic_utils_product_config = true"
]
},
{ "component": "graphic_hals", "features":[] },
{ "component": "ui", "features":[ "enable_graphic_font = true","enable_video_component=false"] },
{ "component": "surface", "features":[] },
{ "component": "wms", "features":[] }
]
},
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
graphic
配置文件见 //vendor/bearpi/bearpi_hm_micro/graphic_config/product_graphic_lite_config.h
。
ArkUI开发框架子系统适配
进行ArkUI开发框架子系统适配需要添加ace_engine_lite
部件,直接在config.json
配置即可。
{
"subsystem": "arkui",
"components": [
{
"component": "ace_engine_lite",
"features": [
"enable_ohos_ace_engine_lite_product_config = true"
]
}
]
},
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
ace_engine_lite
部件配置文件见 //vendor/bearpi/bearpi_hm_micro/ace_lite_config/product_acelite_config.h
。
元能力子系统适配
进行元能力子系统适配需要添加aafwk_lite
部件,直接在config.json
配置即可。
{
"subsystem": "aafwk",
"components": [
{
"component": "aafwk_lite",
"features": [
"enable_ohos_appexecfwk_feature_ability = true" --- 支持FA特性,即包含图形能力。
]
}
]
},
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
包管理子系统适配
进行包管理子系统适配需要添加appexecfwk_lite
部件,直接在config.json
配置即可。
{
"subsystem": "appexecfwk",
"components": [
{
"component": "appexecfwk_lite"
}
]
},
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
如果大家想更加深入的学习 OpenHarmony(鸿蒙南向) 开发的全栈内容,不妨可以参考以下相关学习文档进行学习,助你快速提升自己:
搭建开发环境 Windows 开发环境的搭建 Ubuntu 开发环境搭建 Linux 与 Windows 之间的文件共享 ……
构建子系统 启动流程 子系统 分布式任务调度子系统 分布式通信子系统 驱动子系统 ……
写在最后
如果你觉得这篇内容对你还蛮有帮助,我想邀请你帮我三个小忙: 点赞,转发,有你们的 『点赞和评论』,才是我创造的动力。 关注小编,同时可以期待后续文章ing🚀,不定期分享原创知识。 想要获取更多完整鸿蒙最新学习资源,请移步前往小编:https://qr21.cn/FV7h05
data-report-view="{"mod":"1585297308_001","spm":"1001.2101.3001.6548","dest":"https://blog.csdn.net/maniuT/article/details/140857564","extend1":"pc","ab":"new"}">>
id="blogExtensionBox" style="width:400px;margin:auto;margin-top:12px" class="blog-extension-box"> class="blog_extension blog_extension_type2" id="blog_extension">
class="extension_official" data-report-click="{"spm":"1001.2101.3001.6471"}" data-report-view="{"spm":"1001.2101.3001.6471"}">
class="blog_extension_card_left">
class="blog_extension_card_cont">
鸿蒙开发学习资料领取!!!
class="blog_extension_card_cont_r">
微信名片
评论记录:
回复评论: