赞
踩
2024年1月18日,华为放出HarmonyOS NEXT 鸿蒙星河版开发者预览版本(不是HarmonyOS NEXT版,是HarmonyOS NEXT星河版),首次提到用鸿蒙内核(暂命名)取代了Linux内核。
开源鸿蒙OpenHarmony和华为HarmonyOS是两样东西!华为鸿蒙里面包含非开源代码。因为很多嵌入式产品单价低、利润薄、出货量大,所以我只会跟踪开源鸿蒙OpenHarmony的鸿蒙内核和底层代码,对华为鸿蒙不涉及。
jim@ubuntu:~/OpenHarmony$ ls -a
. build developtools foundation .repo
.. build.py device .gn test
applications build.sh docs kernel third_party
base commonlibrary drivers productdefine vendor
159,898 items, totalling 11.6 GB
当前下载的是单一芯片单一系统类型的代码,总量11G,如果是全量代码,OpenHarmony4.0会有30G。
OpenHarmony有Gitee源码仓库:https://gitee.com/openharmony ,但是和其它简单的Git仓库不一样,它不是通过 git clone xxx 一个命令就能下载全量代码的,而是和安卓类似,需要用到manifest这个顶层仓库,并且通过repo工具把很多个Git仓库的特定版本拉到本地同一个目录。
推荐使用Ubuntu18.04及以上版本,Ubuntu16.04不行,Windows + MSYS2 + MinGW64不行;
安装Ubuntu后把“电源”和“隐私”的设置都改成永远不锁屏,否则一锁屏后下载就会停住,需要退出重新来,容易导致文件冲突;
建议在你创建好的文件夹内打开命令行,如果你在~家目录打开命令行,则下载的源码文件都在家目录下,会和其它文件混在一起,文件夹很多,分辨不出哪个是系统原有的,想再剪切到别的文件就困难了。
进入Ubuntu系统后,在桌面上按鼠标右键,然后点击打开终端这一项,老系统可以按Ctrl + Alt + T打开命令行终端,默认是在~家目录
mkdir ~/openHarmony /* 家目录下新建文件夹 */
cd ~/openHarmony /* 进入新建的文件夹 */
sudo apt-get install git /* 安装Git软件 */
git config --global user.name jimXXX /* 配置Git,输入你自己的名字 */
git config --global user.email jimXXX@163.com /* 配置Git,输入你自己的邮箱 */
git config --global credential.helper store /* 配置Git为自动保存账号密码 */
ssh-keygen -t rsa -C jimXXX@163.com /* 生成Gitee网站要用到的密钥,这里是输入你自己的邮箱,回车三次 */
gedit ~/.ssh/id_rsa.pub /* 复制密钥,复制里面全部的文本内容 */
打开网址 https://gitee.com/ 注册账号,点击齿轮状的设置,点击安全设置中的SSH公钥,将刚刚复制的内容填入到“公钥”这个文本框内,点击确定,输入密码,即添加完Git公钥
mkdir ~/bin sudo apt install curl curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 -o ~/bin/repo chmod a+x ~/bin/repo sudo apt install python3-pip 如果用了Ubuntu老版本系统,如Ubuntu18.04,则还要继续执行下面步骤: sudo apt-get install python3 echo alias python=python3 >> ~/.bashrc source ~/.bashrc python3 --version whereis python3 sudo ln -s /usr/bin/python3 /usr/bin/python pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests 如果使用了Ubuntu16.04及以前的系统,这条命令可能会报错,需要你自己解决 gedit ~/.bashrc 打开桌面~下的.bashrc隐藏文件夹 在最后面加上一句 export PATH=~/bin:$PATH,保存退出 source ~/.bashrc 生效环境变量 echo $PATH 查看环境变量 repo init -u https://gitee.com/openharmony/manifest -b master -m chipsets/niobe407.xml -g ohos:mini 做好下载指定开发板指定芯片源码的准备,我这里是下载ARM Cortex-M内核的Niobe407开发板的STM32F407IGT6芯片 如果下载全量代码,则使用 repo init -u git@github.com:openharmony/manifest.git -b master --no-repo-verify 如果下载QEMU模拟器的代码,则使用 repo init -u https://gitee.com/openharmony/manifest -b master -m chipsets/qemu.xml -g ohos:mini repo sync -c 开始下载,等待时间会比较久 需要设置电脑不待机,如果中途卡住,可以Ctrl + C退出当前命令,并再次repo sync -c继续下载 如果继续下载有冲突,则手动删除有冲突的文件夹后继续使用repo sync -c 你在哪个文件夹路径使用repo init,就会在这个路径形成一个.repo隐藏文件夹,已经下载完的文件夹会在当前目录中出现 sudo apt-get install git-lfs repo forall -c 'git lfs pull' 继续拉取大文件
jim@ubuntu:~/OpenHarmony$ ls -a
. build developtools foundation .repo
.. build.py device .gn test
applications build.sh docs kernel third_party
base commonlibrary drivers productdefine vendor
159,898 items, totalling 11.6 GB
当前下载的是单一芯片单一系统类型的代码,总量11G,如果是全量代码,OpenHarmony4.0会有30G。
编译OpenHarmony源码前先下载源码
确定你要编译哪一块开发板,我这里使用QEMU模拟器虚拟开发板:
下载:安装VMware虚拟机 + Ubuntu发行版系统 + Git软件 + repo软件 + Python
jim@ubuntu:~/openHarmony$ sudo docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_mini:3.2
root@949f932a2f80:/home/openharmony# ls
applications build build.sh developtools docs foundation ohos_config.json prebuilts qemu-run third_party
base build.py commonlibrary device drivers kernel out productdefine test vendor
root@949f932a2f80:/home/openharmony#
python3 build.py -p qemu_mini_system_demo@ohemu
在编译结束后,编译所生成的文件都会被存放在out/{device_name}/目录下,结果镜像输出在out/{device_name}/packages/phone/images/目录下。
如果遇到报错,则解决报错
编译成功后是这样的打印:
[OHOS INFO] [1614/1615] STAMP obj/build/ohos/images/make_images.stamp [OHOS INFO] [1615/1615] STAMP obj/build/core/gn/images.stamp [OHOS INFO] ccache_dir = /root/.ccache, ccache_exec = /usr/bin/ccache [OHOS INFO] -------------------------------------------- [OHOS INFO] ccache summary: [OHOS INFO] ccache version: 3.7.7 [OHOS INFO] cache hit (direct): 0 [OHOS INFO] cache hit (preprocessed): 0 [OHOS INFO] cache miss: 0 [OHOS INFO] hit rate: 0.00% [OHOS INFO] miss rate: 0.00% [OHOS INFO] Cache size (GB): [OHOS INFO] --------------------------------------------- [OHOS INFO] c targets overlap rate statistics [OHOS INFO] subsystem files NO. percentage builds NO. percentage overlap rate [OHOS INFO] hiviewdfx 12 0.8% 12 0.8% 1.00 [OHOS INFO] kernel 902 63.5% 902 63.5% 1.00 [OHOS INFO] security 61 4.3% 61 4.3% 1.00 [OHOS INFO] startup 26 1.8% 26 1.8% 1.00 [OHOS INFO] systemabilitymgr 15 1.1% 15 1.1% 1.00 [OHOS INFO] thirdparty 393 27.7% 393 27.7% 1.00 [OHOS INFO] [OHOS INFO] c overall build overlap rate: 1.00 [OHOS INFO] [OHOS INFO] [OHOS INFO] qemu_mini_system_demo@ohemu build success [OHOS INFO] Cost time: 0:05:47 root@ff38bf1e3e75:/home/openharmony# jim@ubuntu:~/openHarmony/out/arm_mps2_an386/qemu_mini_system_demo$ ls all_parts_host.json build_configs config.h kconfig_files.txt OHOS_Image.bin src_installed_parts.json all_parts_info.json build.log error.log libs OHOS_Image.map src_sa_infos_tmp.json args.gn build.ninja etc NOTICE_FILES OHOS_Image.sym.sorted startup binary_installed_parts.json build.ninja.d gen obj packages thirdparty build.1709259296.3884952.log build.trace.gz hiviewdfx OHOS_Image security toolchain.ninja build.1709259767.6772568.log config.gni kconfig_env.txt OHOS_Image.asm sorted_action_duration.txt jim@ubuntu:~/openHarmony/out/arm_mps2_an386/qemu_mini_system_demo$
生成的系统镜像image是这里面的OHOS_Image文件
如需退出Docker,执行exit命令即可。这个命令会停止当前的Docker容器,并返回到您的操作系统。
下一步就可以把编译好的操作系统在QEMU模拟器中运行起来啦。
OpenHarmony支持hb和build.sh两种编译方式。
python3 -V 查看python版本,如果是3.8以下,则:
python3 -m pip install --user ohos-build
sudo apt-get update && sudo apt-get install binutils binutils-dev git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib gcc-arm-linux-gnueabi libc6-dev-i386 libc6-dev-amd64 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.8 python3-pip ruby genext2fs device-tree-compiler make libffi-dev e2fsprogs pkg-config perl openssl libssl-dev libelf-dev libdwarf-dev u-boot-tools mtd-utils cpio doxygen liblz4-tool openjdk-8-jre gcc g++ texinfo dosfstools mtools default-jre default-jdk libncurses5 apt-utils wget scons python3.8-distutils tar rsync git-core libxml2-dev lib32z-dev grsync xxd libglib2.0-dev libpixman-1-dev kmod jfsutils reiserfsprogs xfsprogs squashfs-tools pcmciautils quota ppp libtinfo-dev libtinfo5 libncurses5-dev libncursesw5 libstdc++6 gcc-arm-none-eabi vim ssh locales libxinerama-dev libxcursor-dev libxrandr-dev libxi-dev
仔细看安装后的信息,如果提示有哪些包未安装成功,则你需要单独安装
sudo apt-get install g++-multilib
已经按前面的流程下载好源码
cd ~/openHarmony 进入到你下载的源码根目录
bash build/prebuilts_download.sh 安装和芯片相关的编译器和二进制工具,全自动的,会下载的同时进行安装,要等待一段时间,有进度条
python3 -m pip install --user build/hb
gedit ~/.bashrc
将 export PATH=~/.local/bin:$PATH 加入到最后一行并保存退出
source ~/.bashrc
hb --help 这个命令执行时可能有报错,有什么错误就解决什么错误,例如用下面方法解决报错
hb set 进行编译设置
jim@ubuntu:~/openHarmony$ hb set
[OHOS INFO] Input code path: .
OHOS Which product do you need? qemu_mini_system_demo
hb build -f 开始编译,有报错则处理报错
出现build success表示编程成功,然后进行烧录,或者直接用QEMU模拟器进行运行。
如果你用hb的方式编译始终出错,那么可以试试使用传统.sh脚本的方式
./build.sh --product-name qemu_mini_system_demo --ccache /* 需要换成你自己开发板的名称,我这里使用的是QEMU模拟器的虚拟开发板 */
检查编译结果。编译完成后,log中显示如下:
如果依然编译有报错,那还可以试试Docker
如果你只是想编译应用程序,那么可以使用DevEco Device Tool
jim@ubuntu:~/openHarmony$ ./qemu-run -e out/arm_mps2_an386/qemu_mini_system_demo/OHOS_Image board: arm_mps2_an386 Enter to start qemu[y/n]:entering kernel init... LfsLowLevelInit: DiskPartition succeed LfsLowLevelInit: PartitionFormat succeed LfsLowLevelInit: mount fs on '/littlefs' succeed LfsLowLevelInit: mkdir '/littlefs' succeed tcpip_init start *************Exception Information************** Type = 11 ThrdPid = 25 Phase = exc in task FaultAddr = 0xabababab Current task info: Task name = (null) Task ID = 25 Task SP = (nil) Task ST = 0x0 Task SS = 0x0 Exception reg dump: PC = 0x2100e62a LR = 0x2101b045 SP = 0x210b18e0 R0 = 0x210a725c R1 = 0x200 R2 = 0x210a725c R3 = 0x2108a9b3 R4 = 0x0 R5 = 0x0 R6 = 0x0 R7 = 0x210b18e8 R8 = 0x0 R9 = 0x0 R10 = 0x0 R11 = 0x0 R12 = 0xc8000000 PriMask = 0x0 xPSR = 0x610f0000 ----- backtrace start ----- backtrace 0 -- lr = 0x21015178 backtrace 1 -- lr = 0x2101b044 backtrace 2 -- lr = 0x210235da backtrace 3 -- lr = 0x210235e2 backtrace 4 -- lr = 0x2102379a ----- backtrace end ----- qemu: fatal: Lockup: can't escalate 3 to HardFault (current priority -1) R00=210b2ad0 R01=2109fa3f R02=210a18f8 R03=6c0da998 R04=00000000 R05=00000060 R06=00000018 R07=210b1708 R08=00000019 R09=000003e8 R10=218ba1e8 R11=00000000 R12=00000000 R13=210b1708 R14=210011db R15=21000fcc XPSR=21030006 --C- T handler s00=00000000 s01=00000000 d00=0000000000000000 s02=00000000 s03=00000000 d01=0000000000000000 s04=00000000 s05=00000000 d02=0000000000000000 s06=00000000 s07=00000000 d03=0000000000000000 s08=00000000 s09=00000000 d04=0000000000000000 s10=00000000 s11=00000000 d05=0000000000000000 s12=00000000 s13=00000000 d06=0000000000000000 s14=00000000 s15=00000000 d07=0000000000000000 s16=00000000 s17=00000000 d08=0000000000000000 s18=00000000 s19=00000000 d09=0000000000000000 s20=00000000 s21=00000000 d10=0000000000000000 s22=00000000 s23=00000000 d11=0000000000000000 s24=00000000 s25=00000000 d12=0000000000000000 s26=00000000 s27=00000000 d13=0000000000000000 s28=00000000 s29=00000000 d14=0000000000000000 s30=00000000 s31=00000000 d15=0000000000000000 FPSCR: 00000000 /home/jim/openHarmony/vendor/ohemu/qemu_mini_system_demo/qemu_run.sh: line 95: 50440 Aborted (core dumped) qemu-system-arm -M mps2-an386 -m 16M -kernel $elf_file $qemu_option -append "root=dev/vda or console=ttyS0" -nographic jim@ubuntu:~/openHarmony$
D:\Program Files\qemu>qemu-system-arm -M mps2-an386 -cpu cortex-m4 -kernel OHOS_Image -serial stdio -nodefaults -nographic qemu-system-arm: warning: nic lan9118.0 has no peer entering kernel init... LfsLowLevelInit: DiskPartition succeed LfsLowLevelInit: PartitionFormat succeed LfsLowLevelInit: mount fs on '/littlefs' succeed LfsLowLevelInit: mkdir '/littlefs' succeed tcpip_init start *************Exception Information************** Type = 11 ThrdPid = 25 Phase = exc in task FaultAddr = 0xabababab Current task info: Task name = (null) Task ID = 25 Task SP = (nil) Task ST = 0x0 Task SS = 0x0 Exception reg dump: PC = 0x2100e62a LR = 0x2101b045 SP = 0x210b18e0 R0 = 0x210a725c R1 = 0x200 R2 = 0x210a725c R3 = 0x2108a9b3 R4 = 0x0 R5 = 0x0 R6 = 0x0 R7 = 0x210b18e8 R8 = 0x0 R9 = 0x0 R10 = 0x0 R11 = 0x0 R12 = 0xc8000000 PriMask = 0x0 xPSR = 0x610f0000 ----- backtrace start ----- backtrace 0 -- lr = 0x21015178 backtrace 1 -- lr = 0x2101b044 backtrace 2 -- lr = 0x210235da backtrace 3 -- lr = 0x210235e2 backtrace 4 -- lr = 0x2102379a ----- backtrace end ----- qemu: fatal: Lockup: can't escalate 3 to HardFault (current priority -1) R00=210b2ad0 R01=2109fa3f R02=210a18f8 R03=6c0da998 R04=00000000 R05=00000060 R06=00000018 R07=210b1708 R08=00000019 R09=000003e8 R10=218ba1e8 R11=00000000 R12=00000000 R13=210b1708 R14=210011db R15=21000fcc XPSR=21030006 --C- T handler s00=00000000 s01=00000000 d00=0000000000000000 s02=00000000 s03=00000000 d01=0000000000000000 s04=00000000 s05=00000000 d02=0000000000000000 s06=00000000 s07=00000000 d03=0000000000000000 s08=00000000 s09=00000000 d04=0000000000000000 s10=00000000 s11=00000000 d05=0000000000000000 s12=00000000 s13=00000000 d06=0000000000000000 s14=00000000 s15=00000000 d07=0000000000000000 s16=00000000 s17=00000000 d08=0000000000000000 s18=00000000 s19=00000000 d09=0000000000000000 s20=00000000 s21=00000000 d10=0000000000000000 s22=00000000 s23=00000000 d11=0000000000000000 s24=00000000 s25=00000000 d12=0000000000000000 s26=00000000 s27=00000000 d13=0000000000000000 s28=00000000 s29=00000000 d14=0000000000000000 s30=00000000 s31=00000000 d15=0000000000000000 FPSCR: 00000000 D:\Program Files\qemu>
jim@ubuntu:~/openHarmony$ tree -a -L 1 . ├── applications ├── base ├── build ├── build.py -> build/build_scripts/build.py ├── build.sh -> build/build_scripts/build.sh ├── commonlibrary ├── developtools ├── device ├── docs ├── drivers ├── foundation ├── .gn -> build/core/gn/dotfile.gn ├── kernel ├── ohos_config.json ├── out ├── prebuilts ├── productdefine ├── qemu ├── qemu-run -> vendor/ohemu/common/qemu-run ├── .repo ├── test ├── third_party └── vendor 18 directories, 5 files jim@ubuntu:~/openHarmony$ tree -a -L 2 . ├── applications │ └── sample ├── base │ ├── global │ ├── hiviewdfx │ ├── iothardware │ ├── powermgr │ ├── security │ ├── sensors │ ├── startup │ └── update ├── build │ ├── build_scripts │ ├── bundle.json │ ├── common │ ├── compile_env_allowlist.json │ ├── compile_standard_whitelist.json │ ├── component_compilation_whitelist.json │ ├── config │ ├── core │ ├── docs │ ├── .git │ ├── .gitattributes │ ├── .gitee │ ├── .gitignore │ ├── gn_helpers.py │ ├── hb │ ├── LICENSE │ ├── lite │ ├── misc │ ├── OAT.xml │ ├── ohos │ ├── ohos.gni │ ├── ohos_system.prop │ ├── ohos_var.gni │ ├── prebuilts_download_config.json │ ├── prebuilts_download.py │ ├── prebuilts_download.sh │ ├── print_python_deps.py │ ├── __pycache__ │ ├── README_zh.md │ ├── rust │ ├── scripts │ ├── subsystem_compoents_whitelist.json │ ├── subsystem_config_example.json │ ├── subsystem_config.json │ ├── templates │ ├── test │ ├── test.gni │ ├── toolchain │ ├── tools │ ├── version.gni │ └── zip.py ├── build.py -> build/build_scripts/build.py ├── build.sh -> build/build_scripts/build.sh ├── commonlibrary │ ├── c_utils │ └── utils_lite ├── developtools │ ├── global_resource_tool │ ├── integration_verification │ ├── packing_tool │ └── syscap_codec ├── device │ └── qemu ├── docs │ ├── CODEOWNERS │ ├── DCO.txt │ ├── docker │ ├── en │ ├── .git │ ├── .gitattributes │ ├── .gitignore │ ├── image.png │ ├── LICENSE │ ├── OAT.xml │ ├── README.md │ ├── README_zh.md │ └── zh-cn ├── drivers │ ├── hdf_core │ ├── liteos │ └── peripheral ├── foundation │ ├── ability │ ├── ai │ ├── arkui │ ├── bundlemanager │ ├── communication │ ├── distributedhardware │ ├── graphic │ ├── multimedia │ ├── systemabilitymgr │ └── window ├── .gn -> build/core/gn/dotfile.gn ├── kernel │ ├── liteos_a │ ├── liteos_m │ └── uniproton ├── ohos_config.json ├── out │ ├── arm_mps2_an386 │ ├── arm_virt │ ├── hb_args │ ├── ohos_config.json │ ├── preloader │ └── sdk ├── prebuilts │ ├── ark_tools │ ├── build-tools │ ├── clang │ ├── cmake │ ├── develop_tools │ ├── gcc │ ├── mingw-w64 │ ├── packing_tool │ ├── python │ └── rustc ├── productdefine │ └── common ├── qemu │ ├── qemu-6.2.0 │ └── qemu-6.2.0.tar.xz ├── qemu-run -> vendor/ohemu/common/qemu-run ├── .repo │ ├── manifests │ ├── manifests.git │ ├── manifest.xml │ ├── project.list │ ├── project-objects │ ├── projects │ ├── repo │ └── .repo_fetchtimes.json ├── test │ ├── ostest │ ├── testfwk │ └── xts ├── third_party │ ├── bounds_checking_function │ ├── cJSON │ ├── cmsis │ ├── curl │ ├── FatFs │ ├── ffmpeg │ ├── FreeBSD │ ├── freetype │ ├── glslang │ ├── gn │ ├── googletest │ ├── harfbuzz │ ├── jerryscript │ ├── jinja2 │ ├── json │ ├── libjpeg-turbo │ ├── libpng │ ├── libunwind │ ├── littlefs │ ├── ltp │ ├── lwip │ ├── lzma │ ├── markupsafe │ ├── mbedtls │ ├── mksh │ ├── mtdev │ ├── musl │ ├── nghttp2 │ ├── NuttX │ ├── openssl │ ├── optimized-routines │ ├── popt │ ├── PyYAML │ ├── qrcodegen │ ├── spirv-headers │ ├── spirv-tools │ ├── sqlite │ ├── toybox │ ├── unity │ ├── vk-gl-cts │ ├── wpa_supplicant │ └── zlib └── vendor └── ohemu 140 directories, 42 files jim@ubuntu:~/openHarmony$
为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:https://qr21.cn/FV7h05
https://qr21.cn/FV7h05
https://qr21.cn/FV7h05
https://qr21.cn/FV7h05
https://qr18.cn/F781PH
https://qr18.cn/F781PH
1.项目开发必备面试题
2.性能优化方向
3.架构方向
4.鸿蒙开发系统底层方向
5.鸿蒙音视频开发方向
6.鸿蒙车载开发方向
7.鸿蒙南向开发方向
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。