|
鴻蒙系統(tǒng)移植操作步驟指引---樹莓派交叉編譯工具鏈配置篇,
本帖最后由 死龍 于 2020-11-13 17:40 編輯
很多朋友對移植鴻蒙存在不少疑惑,其中對交叉編譯工具鏈的配置也完全不清楚。 現(xiàn)在我們來一步步完成樹莓派3上鴻蒙系統(tǒng)的交叉編譯工具鏈配置操作。
首先,我們在命令行中輸入
復制代碼 結(jié)果肯定是失敗的,我們來看看提示。如下圖所示,提示的內(nèi)容是找不到 build/lite/product/rpi3.json 這個文件。 這么說來,編譯腳本第一步就是先定位這個 product 文件夾里的設(shè)置內(nèi)容,然后根據(jù)該文件的設(shè)置布置編譯任務(wù)。
01.png (59.78 KB, 下載次數(shù): 0)
下載附件 保存到相冊
7 小時前 上傳
那我們配置的第一步,就是新建這個文件了
--------------------------------------------------------------------------------------
1、新建 build/lite/product/rpi3.json ,并復制3518的內(nèi)容
我們在這個文件夾新建 build/lite/product/ rpi3.json 文件,并輸入以下內(nèi)容。
- {
- “ohos_version“: “OpenHarmony 1.0“,
- “board“: “rpi3“,
- “kernel“: “l(fā)iteos_a“,
- “compiler“: “arm-none-eabi-gcc“,
- “subsystem“: [
- {
- “name“: “hiviewdfx“,
- “component“: [
- { “name“: “hilog_lite“, “dir“: “//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_static“, “features“:[] },
- { “name“: “hilog_lite“, “dir“: “//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared“, “features“:[] }
- ]
- },
- {
- “name“: “distributedschedule“,
- “component“: [
- { “name“: “samgr_lite“, “dir“: “//foundation/distributedschedule/services/samgr_lite:samgr“, “features“:[] },
- { “name“: “safwk_lite“, “dir“: “//foundation/distributedschedule/services/safwk_lite:safwk_lite“, “features“:[] },
- { “name“: “dtbschedmgr_lite“, “dir“: “//foundation/distributedschedule/services/dtbschedmgr_lite:dtbschedmgr“, “features“:[] }
- ]
- },
- {
- “name“: “security“,
- “component“: [
- { “name“: “hichainsdk_lite“, “dir“: “//base/security/frameworks/hichainsdk_lite:hichainsdk“, “features“:[] },
- { “name“: “iam_lite“, “dir“: “//base/security/services/iam_lite:pms_lite“, “features“:[] },
- { “name“: “app_verify“, “dir“: “//base/security/frameworks/app_verify:verify“, “features“:[] }
- ]
- },
- {
- “name“: “multimedia“,
- “component“: [
- { “name“: “media_lite“, “dir“: “//foundation/multimedia/services/media_lite:media_lite“, “features“:[] }
- ]
- },
- {
- “name“: “startup“,
- “component“: [
- { “name“: “bootstrap_lite“, “dir“: “//base/startup/services/bootstrap_lite/source:bootstrap“, “features“:[] },
- { “name“: “parameter“, “dir“: “//base/startup/frameworks/syspara_lite/parameter:parameter“, “features“:[] },
- { “name“: “token“, “dir“: “//base/startup/frameworks/syspara_lite/token:token“, “features“:[] },
- { “name“: “init_lite“, “dir“: “//base/startup/services/init_lite:init_lite“, “features“:[] },
- { “name“: “appspawn_lite“, “dir“: “//base/startup/services/appspawn_lite:appspawn_lite“, “features“:[] }
- ]
- },
- {
- “name“: “kernel“,
- “component“: [
- { “name“: “l(fā)iteos_a“, “dir“: “//kernel/liteos_a:kernel“, “features“:[] }
- ]
- },
- {
- “name“: “communication“,
- “component“: [
- { “name“: “ipc_lite“, “dir“: “//foundation/communication/frameworks/ipc_lite:liteipc“, “features“:[] },
- { “name“: “softbus_lite“, “dir“: “//foundation/communication/services/softbus_lite:softbus“, “features“:[] },
- { “name“: “wpa_supplicant“, “dir“: “//third_party/wpa_supplicant/wpa_supplicant-2.9:wpa_supplicant“, “features“:[] }
- ]
- },
- {
- “name“: “hdf“,
- “component“: [
- { “name“: “posix“, “dir“: “//drivers/hdf/lite/posix:hdf_posix“, “features“:[] },
- { “name“: “manager“, “dir“: “//drivers/hdf/lite/manager:hdf_manager“, “features“:[] },
- { “name“: “wifi“, “dir“: “//vendor/huawei/hdf/wifi:wifi_firmware“, “features“:[] },
- { “name“: “display“, “dir“: “//vendor/huawei/hdf/display/hdi:hdi_display“, “features“:[] },
- { “name“: “input“, “dir“: “//vendor/huawei/hdf/input/hdi:hdi_input“, “features“:[] }
- ]
- },
- {
- “name“: “appexecfwk“,
- “component“: [
- { “name“: “bundle_lite“, “dir“: “//foundation/appexecfwk/frameworks/bundle_lite:appexecfwk_kits_lite“, “features“:[] },
- { “name“: “bundlemgr_lite“, “dir“: “//foundation/appexecfwk/services/bundlemgr_lite:appexecfwk_services_lite“, “features“:[] }
- ]
- },
- {
- “name“: “utils“,
- “component“: [
- { “name“: “kv_store“, “dir“: “//utils/native/lite/kv_store:kv_store“, “features“:[] }
- ]
- },
- {
- “name“: “vendor“,
- “component“: [
- { “name“: “middleware“, “dir“: “//vendor/hisi/hi35xx/middleware:middleware_source_sdk“, “features“:[] },
- { “name“: “hardware“, “dir“: “//vendor/hisi/hi35xx/hardware:hardware_media_sdk“, “features“:[] }
- ]
- },
- {
- “name“: “test“,
- “component“: [
- { “name“: “xts_act“, “dir“: “//test/xts/acts“, “features“:[] },
- { “name“: “xts_tools“, “dir“: “//test/xts/tools“, “features“:[] },
- { “name“: “test“, “dir“: “//test/developertest:test“, “features“:[] }
- ]
- }
- ],
- “vendor_adapter_dir“: “//vendor/hisi/hi35xx/hi3518ev300/hi3518ev300_adapter“,
- “third_party_dir“: “//third_party“,
- “ohos_product_type“:““,
- “ohos_manufacture“:““,
- “ohos_brand“:““,
- “ohos_market_name“:““,
- “ohos_product_series“:““,
- “ohos_product_model“:““,
- “ohos_software_model“:““,
- “ohos_hardware_model“:““,
- “ohos_hardware_profile“:““,
- “ohos_serial“:““,
- “ohos_bootloader_version“:““,
- “ohos_secure_patch_level“:““,
- “ohos_abi_list“:““
- }
-
復制代碼 說明:板子設(shè)定為rpi3,編譯器設(shè)定為 arm-none-eabi-gcc,并刪掉一些組件
=========
接下來,我們再運行一下編譯命令( python build.py rpi3 )。我們填寫了一個不在原系統(tǒng)里支持的編譯器,運行命令也是會出錯的。果然,提示不支持這個編譯器。
02.png (52.93 KB, 下載次數(shù): 0)
下載附件 保存到相冊
10 小時前 上傳
好的,那第二步的工作就確定了
--------------------------------------------------------------------------------------
2、 編寫 arm-none-eabi-gcc 配置文件 我們先用VScode搜索一下 Error: Unsupport compiler 這個錯誤。然后定位到 build/lite/config.py 這個文件的124行附件。將內(nèi)容修改為以下內(nèi)容 。
- if compiler == “clang“:
- compiler_bin = “clang“
- elif compiler == “arm-none-eabi-gcc“:
- compiler_bin = “arm-none-eabi-gcc“
- elif compiler == “gcc“:
- compiler_bin = “riscv32-unknown-elf-gcc“
- else:
-
復制代碼 新增了編譯器設(shè)置為 arm-none-eabi-gcc 的判斷和執(zhí)行部分
=======
然后我們再次 運行編譯命令 ,又出現(xiàn)了一個新錯誤提示,如下圖。
03.png (169.39 KB, 下載次數(shù): 0)
下載附件 保存到相冊
9 小時前 上傳
好的,這次我們在VScode中搜索 not OHOS compiler , 同樣是在 build/lite/config.py 這個文件的 160行附近找到了對應(yīng)判斷語句。
我們來將對應(yīng)內(nèi)容修改為
- if compiler == \“gcc\“ or compiler == \“arm-none-eabi-gcc\“:
- return True
復制代碼 ======
然后我們再次 運行編譯命令 ,又出現(xiàn)了一個新錯誤提示,如下圖。
04.png (190.15 KB, 下載次數(shù): 0)
下載附件 保存到相冊
9 小時前 上傳
好的,根據(jù)提示缺少的文件,我們新建 build/lite/config/boards/rpi3.gni 文件,并添加以下內(nèi)容。
- # Copyright (c) 2020 Huawei Device Co., Ltd.
- # Licensed under the Apache License, Version 2.0 (the “License“);
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an “AS IS“ BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- board_arch = “armv8-a“
- board_cpu = “cortex-a8“
-
復制代碼 =======
然后我們再次 運行編譯命令 ,又出現(xiàn)了一個新錯誤提示,如下圖。
05.png (255.92 KB, 下載次數(shù): 0)
下載附件 保存到相冊
9 小時前 上傳
然后繼續(xù)新建缺少的文件 build/lite/toolchain/arm-none-eabi-gcc.gni ,添加以下內(nèi)容
- # Copyright (c) 2020 Huawei Device Co., Ltd.
- # Licensed under the Apache License, Version 2.0 (the “License“);
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an “AS IS“ BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ohos_build_compiler_so_strip = “arm-none-eabi-objcopy --strip-all“
- ohos_build_compiler_bin_strip = “arm-none-eabi-objcopy --strip-all“
- template(“arm_none_eabi_gcc_toolchain“) {
- toolchain(target_name) {
- assert(defined(invoker.cc), “clang toolchain must specify a \“cc\“ value“)
- assert(defined(invoker.cxx), “clang toolchain must specify a \“cxx\“ value“)
- assert(defined(invoker.ar), “clang toolchain must specify a \“ar\“ value“)
- assert(defined(invoker.as), “clang toolchain must specify a \“as\“ value“)
- assert(defined(invoker.ld), “clang toolchain must specify a \“l(fā)d\“ value“)
- cc = invoker.cc
- cxx = invoker.cxx
- ar = invoker.ar
- as = invoker.as
- ld = invoker.ld
- need_strip = false
- if(defined(invoker.strip)) {
- strip = invoker.strip
- need_strip = true
- }
- tool(“cc“) {
- command = “$cc {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}“
- description = “arm-none-eabi-gcc {{output}}“
- outputs = [
- “{{source_out_dir}}/{{source_name_part}}.o“,
- ]
- }
- tool(“cxx“) {
- depfile = “{{output}}.d“
- command = “$cxx {{defines}} {{include_dirs}} {{cflags_cc}} -c {{source}} -o {{output}}“
- description = “arm-none-eabi-g++ {{output}}“
- outputs = [
- “{{source_out_dir}}/{{source_name_part}}.o“,
- ]
- }
- tool(“asm“) {
- depfile = “{{output}}.d“
- command = “$as {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}“
- description = “arm-none-eabi-as {{output}}“
- outputs = [
- “{{source_out_dir}}/{{source_name_part}}.o“,
- ]
- }
- tool(“alink“) {
- outfile = “{{output_dir}}/{{target_output_name}}{{output_extension}}“
- rspfile = “{{output}}.rsp“
- rspfile_content = “{{inputs}}“
- command = “$ar -cr {{output}} @\“$rspfile\““
- description = “arm-none-eabi-ar {{output}}“
- outputs = [
- outfile,
- ]
- default_output_dir = “{{root_out_dir}}/libs“
- default_output_extension = “.a“
- output_prefix = “l(fā)ib“
- }
- tool(“solink“) {
- outfile = “{{output_dir}}/{{target_output_name}}{{output_extension}}“
- rspfile = “$outfile.rsp“
- rspfile_content = “{{inputs}}“
- command = “$ld -shared {{ldflags}} {{inputs}} -o $outfile“
- if (need_strip) {
- unstripped_outfile = outfile
- command += “ && $strip“ + “ \“$unstripped_outfile\“ \“$outfile\““
- }
- default_output_extension = “.so“
- description = “SOLINK $outfile“
- default_output_dir = “{{root_out_dir}}“
- output_prefix = “l(fā)ib“
- outputs = [
- outfile
- ]
- }
- tool(“l(fā)ink“) {
- outfile = “{{output_dir}}/bin/{{target_output_name}}{{output_extension}}“
- rspfile = “$outfile.rsp“
- custom_ld_flags = “ “
- command = “$cc {{ldflags}} {{inputs}} $custom_ld_flags -o $outfile“
- if (need_strip) {
- command += “ && $strip $outfile“
- }
- description = “GCC LINK $outfile“
- default_output_dir = “{{root_out_dir}}“
- rspfile_content = “{{inputs}}“
- outputs = [
- outfile
- ]
- }
- tool(“stamp“) {
- if (host_os == “win“) {
- command = “cmd /c type nul > \“{{output}}\““
- } else {
- command = “/usr/bin/touch {{output}}“
- }
- description = “STAMP {{output}}“
- }
- tool(“copy“) {
- command = “cp -afd {{source}} {{output}}“
- description = “COPY {{source}} {{output}}“
- }
- }
- }
復制代碼
================
再運行 編譯命令 ,繼續(xù)查看錯誤輸出,如下圖
06.png (431.76 KB, 下載次數(shù): 0)
下載附件 保存到相冊
7 小時前 上傳
是的,到這一步的時候,提示就有點奇怪了。明明設(shè)置了 arm-none-eabi-gcc ,卻依然提示找 linux_x86_64_clang 。還是老方法,VScode搜索,找到了 build/lite/config/BUILDCONFIG.gn 的 28 行 ,將內(nèi)容修改為:
- if(ohos_kernel_type == “l(fā)iteos_a“) {
- if(target_cpu == “cortex-a8“) {
- set_default_toolchain(“//build/lite/toolchain:linux_arm_none_eabi_gcc“)
- } else {
- set_default_toolchain(“//build/lite/toolchain:linux_x86_64_clang“)
- }
- default_target_configs = [ “//build/lite/config:liteos_a“ ]
復制代碼
同時,build/lite/toolchain/BUILD.gn
文件中似乎也缺少定義,在文件最后添加以下內(nèi)容
- if (ohos_build_compiler == “arm-none-eabi-gcc“) {
- arm_none_eabi_gcc_toolchain(“l(fā)inux_arm_none_eabi_gcc“) {
- ohos_build_compiler_prefix = “arm-none-eabi“
- cc = “${ohos_build_compiler_prefix}-gcc“
- cxx = “${ohos_build_compiler_prefix}-g++“
- ar = “${ohos_build_compiler_prefix}-ar“
- as = “${ohos_build_compiler_prefix}-as“
- ld = cc
- if (ohos_build_type == “release“) {
- strip = “${ohos_build_compiler_prefix}-objcopy --strip-all“
- }
- }
- }
復制代碼 ================
再運行 編譯命令 ,繼續(xù)查看錯誤輸出,如下圖
07.png (324.14 KB, 下載次數(shù): 0)
下載附件 保存到相冊
7 小時前 上傳
好的,到這里,基本上就配置得差不多了,我們看一下 out/rpi3/toolchain.ninja
這個文件,如下圖,gn 工具已經(jīng)正確識別了工具鏈了
08.png (478.13 KB, 下載次數(shù): 0)
下載附件 保存到相冊
7 小時前 上傳
這時候大家可以再仔細檢查一下,編譯命令是否正確,不正確的話就回去修改 build/lite/toolchain/arm-none-eabi-gcc.gni
文件。
===========
樹莓派編譯工具鏈移植暫時就在這里停止先,還未完成 |
|